Add on_tick hook

This commit is contained in:
ChillerDragon 2023-09-17 19:50:09 +02:00
parent e606226dea
commit a5d24cb2c6
4 changed files with 25 additions and 0 deletions

View file

@ -82,3 +82,5 @@ Version v0.0.4
[#send_enter_game](classes/TeeworldsClient.md#send_enter_game)
[#send_input(input = {})](classes/TeeworldsClient.md#send_input)
[#on_tick(&block)](classes/TeeworldsClient.md#on_tick)

View file

@ -632,3 +632,16 @@ loop do
prev_weapon: 0)
end
```
### <a name="on_tick"></a> #on_tick(&block)
**Parameter: TODO**
**Example:**
```ruby
client = TeeworldsClient.new
# TODO: generated documentation
client.on_tick(&block)
client.connect('localhost', 8303, detach: false)
```

View file

@ -38,6 +38,10 @@ class GameClient
context
end
def on_tick
call_hook(:tick, nil)
end
def on_auth_on
return if call_hook(:auth_on, Context.new(nil)).nil?

View file

@ -40,6 +40,7 @@ class TeeworldsClient
auth_off: [],
rcon_cmd_add: [],
rcon_cmd_rem: [],
tick: [],
maplist_entry_add: [],
maplist_entry_rem: []
}
@ -76,6 +77,10 @@ class TeeworldsClient
@rcon_authed
end
def on_tick(&block)
@hooks[:tick].push(block)
end
def on_auth_on(&block)
@hooks[:auth_on].push(block)
end
@ -466,6 +471,7 @@ class TeeworldsClient
puts 'retrying connection ...'
end
end
@game_client.on_tick
return unless pck
data = pck.first