teeworlds_network/lib/snapshot/builder.rb

31 lines
684 B
Ruby
Raw Normal View History

2024-02-21 06:18:01 +00:00
# frozen_string_literal: true
require_relative 'snapshot'
class SnapshotBuilder
def initialize
@data_size = 0
@num_items = 0
2024-02-21 10:46:01 +00:00
# @type items [Array<SnapItemBase>]
2024-02-21 06:18:01 +00:00
@items = []
end
##
# insert new snap item into the snap
#
# https://chillerdragon.github.io/teeworlds-protocol/07/snap_items.html
#
2024-02-21 10:46:01 +00:00
# @param id [Integer] Id of the snap item. For characters that is the ClientID.
# Not to be confused with the type
# @param item [SnapItemBase] Snap item instance. Holding type and payload.
def new_item(id, item)
item.id = id
2024-02-21 06:18:01 +00:00
@items.push(item)
end
# @return [Snapshot]
def finish
2024-02-21 10:46:01 +00:00
Snapshot.new(@items)
2024-02-21 06:18:01 +00:00
end
end