Documentation refactor
This commit is contained in:
parent
8b6a867525
commit
6275508a18
|
@ -38,4 +38,4 @@ client.connect('localhost', 8303, detach: false)
|
|||
|
||||
## Documentation
|
||||
|
||||
Checkout [docs/v0.0.1.md](docs/v0.0.1.md) for a full library documentation.
|
||||
Checkout [docs/v0.0.1/READE.md](docs/v0.0.1/README.md) for a full library documentation.
|
||||
|
|
36
docs/v0.0.1/README.md
Normal file
36
docs/v0.0.1/README.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
# teeworlds_network
|
||||
|
||||
Version v0.0.1
|
||||
|
||||
## Classes
|
||||
|
||||
### [ChatMessage](classes/ChatMessage.md)
|
||||
|
||||
### [Context](classes/Context.md)
|
||||
|
||||
### [Player](classes/Player.md)
|
||||
|
||||
### [TeeworldsClient](classes/TeeworldsClient.md)
|
||||
|
||||
[#on_snapshot(&block)](classes/TeeworldsClient.md#on_snapshot)
|
||||
|
||||
[#on_rcon_line(&block)](classes/TeeworldsClient.md#on_rcon_line)
|
||||
|
||||
[#on_disconnect(&block)](classes/TeeworldsClient.md#on_disconnect)
|
||||
|
||||
[#on_connected(&block)](classes/TeeworldsClient.md#on_connected)
|
||||
|
||||
[#on_client_info(&block)](classes/TeeworldsClient.md#on_client_info)
|
||||
|
||||
[#on_chat(&block)](classes/TeeworldsClient.md#on_chat)
|
||||
|
||||
[#on_map_change(&block)](classes/TeeworldsClient.md#on_map_change)
|
||||
|
||||
[#on_client_drop(&block)](classes/TeeworldsClient.md#on_client_drop)
|
||||
|
||||
[#connect(ip, port, options)](classes/TeeworldsClient.md#connect)
|
||||
|
||||
[#send_chat(str)](classes/TeeworldsClient.md#send_chat)
|
||||
|
||||
|
||||
|
7
docs/v0.0.1/classes/ChatMessage.md
Normal file
7
docs/v0.0.1/classes/ChatMessage.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# ChatMessage
|
||||
|
||||
### @mode [Integer]
|
||||
### @client_id [Integer]
|
||||
### @target_id [Integer]
|
||||
### @message [Integer]
|
||||
### @author [[Player](../classes/Player.md)]
|
62
docs/v0.0.1/classes/Context.md
Normal file
62
docs/v0.0.1/classes/Context.md
Normal file
|
@ -0,0 +1,62 @@
|
|||
# Context
|
||||
|
||||
This class is the callback context.
|
||||
When you hook into methods using a ``on_*`` method you can access its context.
|
||||
This gives you the ability to read and modify the data before the default behavior processes it.
|
||||
Or skip the default behavior and implement your own logic.
|
||||
|
||||
### #cancle
|
||||
|
||||
Call the ``cancle()`` on the context object to not run any default code for that event.
|
||||
|
||||
```ruby
|
||||
client.on_map_change do |context|
|
||||
# do nothing when a map change packet comes in
|
||||
# skips the send ready packet code
|
||||
context.cancle
|
||||
end
|
||||
```
|
||||
|
||||
### @client [[TeeworldsClient](../classes/TeeworldsClient.md)]
|
||||
|
||||
Access the network client to send packets.
|
||||
|
||||
**Example:**
|
||||
|
||||
Reimplement your on on_connected logic and cancle the default one
|
||||
|
||||
```ruby
|
||||
client.on_connected do |ctx|
|
||||
ctx.client.send_msg_start_info
|
||||
ctx.cancle
|
||||
end
|
||||
```
|
||||
|
||||
### @data [Hash]
|
||||
|
||||
This hash holds all the current data. They keys might vary depending on the current context.
|
||||
You can read and write those values. If you set an unused key the program will panic.
|
||||
|
||||
**Example:**
|
||||
|
||||
Here an example to see what keys you are given for a client info event.
|
||||
|
||||
```ruby
|
||||
client = TeeworldsClient.new
|
||||
|
||||
client.on_client_info do |context|
|
||||
p context.data.keys
|
||||
# [:player, :chunk]
|
||||
end
|
||||
```
|
||||
|
||||
Here an example to modify all incoming player info to rename all player objects to yee.
|
||||
Which is a bit weird but shows the power of the modding api.
|
||||
|
||||
```ruby
|
||||
client = TeeworldsClient.new
|
||||
|
||||
client.on_client_info do |context|
|
||||
context.data[:player].name = 'yee'
|
||||
end
|
||||
```
|
11
docs/v0.0.1/classes/Player.md
Normal file
11
docs/v0.0.1/classes/Player.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Player
|
||||
|
||||
### @id [Integer]
|
||||
### @local [Integer]
|
||||
### @team [Integer]
|
||||
### @name [String]
|
||||
### @clan [String]
|
||||
### @country [Integer]
|
||||
### @skin_parts [Array#String]
|
||||
### @skin_custom_colors [Array#Integer]
|
||||
### @skin_colors [Array#Integer]
|
|
@ -1,93 +1,8 @@
|
|||
# Classes
|
||||
# TeeworldsClient
|
||||
|
||||
## Player
|
||||
### <a name="on_snapshot"></a> #on_snapshot(&block)
|
||||
|
||||
### @id [Integer]
|
||||
### @local [Integer]
|
||||
### @team [Integer]
|
||||
### @name [String]
|
||||
### @clan [String]
|
||||
### @country [Integer]
|
||||
### @skin_parts [Array#String]
|
||||
### @skin_custom_colors [Array#Integer]
|
||||
### @skin_colors [Array#Integer]
|
||||
|
||||
## ChatMessage
|
||||
|
||||
### @mode [Integer]
|
||||
### @client_id [Integer]
|
||||
### @target_id [Integer]
|
||||
### @message [Integer]
|
||||
### @author [[Player](#player)]
|
||||
|
||||
## Context
|
||||
|
||||
This class is the callback context.
|
||||
When you hook into methods using a ``on_*`` method you can access its context.
|
||||
This gives you the ability to read and modify the data before the default behavior processes it.
|
||||
Or skip the default behavior and implement your own logic.
|
||||
|
||||
### #cancle
|
||||
|
||||
Call the ``cancle()`` on the context object to not run any default code for that event.
|
||||
|
||||
```ruby
|
||||
client.on_map_change do |context|
|
||||
# do nothing when a map change packet comes in
|
||||
# skips the send ready packet code
|
||||
context.cancle
|
||||
end
|
||||
```
|
||||
|
||||
### @client [[TeeworldsClient](#teeworldsclient)]
|
||||
|
||||
Access the network client to send packets.
|
||||
|
||||
**Example:**
|
||||
|
||||
Reimplement your on on_connected logic and cancle the default one
|
||||
|
||||
```ruby
|
||||
client.on_connected do |ctx|
|
||||
ctx.client.send_msg_start_info
|
||||
ctx.cancle
|
||||
end
|
||||
```
|
||||
|
||||
### @data [Hash]
|
||||
|
||||
This hash holds all the current data. They keys might vary depending on the current context.
|
||||
You can read and write those values. If you set an unused key the program will panic.
|
||||
|
||||
**Example:**
|
||||
|
||||
Here an example to see what keys you are given for a client info event.
|
||||
|
||||
```ruby
|
||||
client = TeeworldsClient.new
|
||||
|
||||
client.on_client_info do |context|
|
||||
p context.data.keys
|
||||
# [:player, :chunk]
|
||||
end
|
||||
```
|
||||
|
||||
Here an example to modify all incoming player info to rename all player objects to yee.
|
||||
Which is a bit weird but shows the power of the modding api.
|
||||
|
||||
```ruby
|
||||
client = TeeworldsClient.new
|
||||
|
||||
client.on_client_info do |context|
|
||||
context.data[:player].name = 'yee'
|
||||
end
|
||||
```
|
||||
|
||||
## TeeworldsClient
|
||||
|
||||
### #on_snapshot(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
|
||||
|
@ -102,9 +17,9 @@ end
|
|||
client.connect('localhost', 8303, detach: true)
|
||||
```
|
||||
|
||||
### #on_rcon_line(&block)
|
||||
### <a name="on_rcon_line"></a> #on_rcon_line(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
|
||||
|
@ -119,9 +34,9 @@ end
|
|||
client.connect('localhost', 8303, detach: true)
|
||||
```
|
||||
|
||||
### #on_disconnect(&block)
|
||||
### <a name="on_disconnect"></a> #on_disconnect(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
|
||||
|
@ -136,9 +51,9 @@ end
|
|||
client.connect('localhost', 8303, detach: true)
|
||||
```
|
||||
|
||||
### #on_connected(&block)
|
||||
### <a name="on_connected"></a> #on_connected(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
|
||||
|
@ -153,9 +68,9 @@ end
|
|||
client.connect('localhost', 8303, detach: true)
|
||||
```
|
||||
|
||||
### #on_client_info(&block)
|
||||
### <a name="on_client_info"></a> #on_client_info(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
|
||||
|
@ -170,12 +85,12 @@ end
|
|||
client.connect('localhost', 8303, detach: true)
|
||||
```
|
||||
|
||||
### #on_chat(&block)
|
||||
### <a name="on_chat"></a> #on_chat(&block)
|
||||
|
||||
**Parameter: block [Block |[ChatMessage](#chatmessage)|]**
|
||||
**Parameter: block [Block |[ChatMessage](../classes/ChatMessage.md)|]**
|
||||
|
||||
Takes a block that will be called when the client receives a chat message.
|
||||
The block takes one parameter of type [ChatMessage](#chatmessage).
|
||||
The block takes one parameter of type [ChatMessage](../classes/ChatMessage.md).
|
||||
|
||||
**Example:**
|
||||
|
||||
|
@ -188,9 +103,9 @@ end
|
|||
|
||||
client.connect('localhost', 8303, detach: true)
|
||||
```
|
||||
### #on_map_change(&block)
|
||||
### <a name="on_map_change"></a> #on_map_change(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
Takes a block that will be called when the client receives a map change packet.
|
||||
|
||||
|
@ -210,13 +125,13 @@ end
|
|||
client.connect('localhost', 8303, detach: true)
|
||||
```
|
||||
|
||||
### #on_client_drop(&block)
|
||||
### <a name="on_client_drop"></a> #on_client_drop(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
Takes a block that will be called when the client receives a client drop packet.
|
||||
|
||||
Context:
|
||||
Context.data:
|
||||
|
||||
```ruby
|
||||
[
|
||||
|
@ -240,7 +155,7 @@ end
|
|||
```
|
||||
|
||||
|
||||
### connect(ip, port, options)
|
||||
### <a name="connect"></a> #connect(ip, port, options)
|
||||
|
||||
**Parameter: ip [String]**
|
||||
|
||||
|
@ -269,7 +184,7 @@ client.connect('localhost', 8303, detach: false)
|
|||
```
|
||||
|
||||
|
||||
### send_chat(str)
|
||||
### <a name="send_chat"></a> #send_chat(str)
|
||||
|
||||
**Parameter: str [String]**
|
||||
|
|
@ -35,7 +35,7 @@ function add_hook_doc() {
|
|||
echo "Error: failed to generate docs! File not found $mdfile"
|
||||
exit 1
|
||||
fi
|
||||
class_ln="$(grep -n "## $ruby_class" "$mdfile" | cut -d':' -f1)"
|
||||
class_ln="$(grep -n "^# $ruby_class" "$mdfile" | cut -d':' -f1)"
|
||||
class_ln="$((class_ln+1))"
|
||||
if [ "$class_ln" == "" ]
|
||||
then
|
||||
|
@ -56,10 +56,14 @@ function add_hook_doc() {
|
|||
tmpdoc="$tmpdir/doc.md"
|
||||
{
|
||||
head -n "$class_ln" "$mdfile"
|
||||
# the ancor tag is a hack to allow linking
|
||||
# methods using #hook_name
|
||||
# because we want to put junk after the hook name
|
||||
# for example the parameters
|
||||
cat <<- EOF
|
||||
### #$hook(&block)
|
||||
### <a name="$hook"></a> #$hook(&block)
|
||||
|
||||
**Parameter: block [Block |[context](#context)|]**
|
||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
||||
|
||||
TODO: generated documentation
|
||||
|
||||
|
@ -111,7 +115,7 @@ function check_file() {
|
|||
echo -n "[*] checking hook: $hook"
|
||||
# check documentation
|
||||
local mdfile
|
||||
mdfile="docs/$version.md"
|
||||
mdfile="docs/$version/classes/$ruby_class.md"
|
||||
if [ ! -f "$mdfile" ]
|
||||
then
|
||||
echo "ERROR: documentation not found $mdfile"
|
||||
|
|
Loading…
Reference in a new issue