Document on_snapshot
This commit is contained in:
parent
c185d1a6b2
commit
32c3eb4919
7
docs/v0.0.1/classes/Snapshot.md
Normal file
7
docs/v0.0.1/classes/Snapshot.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Snapshot
|
||||||
|
|
||||||
|
### @game_tick [Integer]
|
||||||
|
### @items [Array#SnapItem]
|
||||||
|
|
||||||
|
SnapItem can be any of the [event classes](../../../lib/snapshot/events/)
|
||||||
|
or any of the [item classes](../../../lib/snapshot/items/).
|
|
@ -143,16 +143,26 @@ client.connect('localhost', 8303, detach: false)
|
||||||
|
|
||||||
### <a name="on_snapshot"></a> #on_snapshot(&block)
|
### <a name="on_snapshot"></a> #on_snapshot(&block)
|
||||||
|
|
||||||
**Parameter: block [Block |[context](../classes/Context.md)|]**
|
**Parameter: block [Block |[context](../classes/Context.md), [Snapshot](../classes/Snapshot.md)|]**
|
||||||
|
|
||||||
TODO: generated documentation
|
context.message is nil but the block takes a second argument of type [Snapshot](../classes/Snapshot.md)
|
||||||
|
|
||||||
|
By default when a snapshot is received the `GameClient::ack_game_tick` and `GameClient::pred_game_tick`
|
||||||
|
variables are updated. Those are crucial for a healthy connection to the server. So only call `context.cancel`
|
||||||
|
if you know what you are doing
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
```ruby
|
```ruby
|
||||||
client = TeeworldsClient.new
|
client = TeeworldsClient.new
|
||||||
|
|
||||||
client.on_snapshot do |context|
|
client.on_snapshot do |_, snapshot|
|
||||||
# TODO: generated documentation
|
snapshot.items.each do |item|
|
||||||
|
next unless item.instance_of?(NetObj::Character)
|
||||||
|
|
||||||
|
p item.to_h
|
||||||
|
# => {:id=>0, :tick=>372118, :x=>1584, :y=>369, :vel_x=>0, :vel_y=>0, :angle=>0, :direction=>0, :jumped=>0, :hooked_player=>-1, :hook_state=>0, :hook_tick=>0, :hook_x=>1584, :hook_y=>369, :hook_dx=>0, :hook_dy=>0, :health=>0, :armor=>0, :ammo_count=>0, :weapon=>1, :emote=>0, :attack_tick=>0, :triggered_events=>0}
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
client.connect('localhost', 8303, detach: false)
|
client.connect('localhost', 8303, detach: false)
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Snapshot
|
||||||
attr_accessor :game_tick, :items
|
attr_accessor :game_tick, :items
|
||||||
|
|
||||||
def initialize(items)
|
def initialize(items)
|
||||||
|
@game_tick = 0
|
||||||
@items = items
|
@items = items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue