More snap item support
This commit is contained in:
parent
dd714e51aa
commit
ad7ef13926
24
lib/snapshot/events/damage.rb
Normal file
24
lib/snapshot/events/damage.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_event_base'
|
||||
|
||||
class NetEvent
|
||||
class Damage < SnapEventBase
|
||||
attr_accessor :client_id, :angle, :health_ammount, :armor_amount, :self
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
client_id
|
||||
angle
|
||||
health_ammount
|
||||
armor_amount
|
||||
self
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETEVENTTYPE_DAMAGE
|
||||
end
|
||||
end
|
||||
end
|
20
lib/snapshot/events/death.rb
Normal file
20
lib/snapshot/events/death.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_event_base'
|
||||
|
||||
class NetEvent
|
||||
class Death < SnapEventBase
|
||||
attr_accessor :client_id
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
client_id
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETEVENTTYPE_DEATH
|
||||
end
|
||||
end
|
||||
end
|
16
lib/snapshot/events/explosion.rb
Normal file
16
lib/snapshot/events/explosion.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetEvent
|
||||
class Explosion < SnapEventBase
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = []
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETEVENTTYPE_EXPLOSION
|
||||
end
|
||||
end
|
||||
end
|
16
lib/snapshot/events/hammer_hit.rb
Normal file
16
lib/snapshot/events/hammer_hit.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetEvent
|
||||
class HammerHit < SnapEventBase
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = []
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETEVENTTYPE_HAMMERHIT
|
||||
end
|
||||
end
|
||||
end
|
16
lib/snapshot/events/spawn.rb
Normal file
16
lib/snapshot/events/spawn.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetEvent
|
||||
class Spawn < SnapEventBase
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = []
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETEVENTTYPE_SPAWN
|
||||
end
|
||||
end
|
||||
end
|
22
lib/snapshot/items/client_info.rb
Normal file
22
lib/snapshot/items/client_info.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class ClientInfo < SnapItemBase
|
||||
attr_accessor :local, :team
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
local
|
||||
team
|
||||
]
|
||||
super
|
||||
raise 'ClientInfo includes strings that is not supported yet'
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_DE_CLIENTINFO
|
||||
end
|
||||
end
|
||||
end
|
22
lib/snapshot/items/flag.rb
Normal file
22
lib/snapshot/items/flag.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class Flag < SnapItemBase
|
||||
attr_accessor :x, :y, :team
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
x
|
||||
y
|
||||
team
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_FLAG
|
||||
end
|
||||
end
|
||||
end
|
24
lib/snapshot/items/game_data_flag.rb
Normal file
24
lib/snapshot/items/game_data_flag.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class GameDataFlag < SnapItemBase
|
||||
attr_accessor :flag_carrier_red, :flag_carrier_blue,
|
||||
:flag_drop_tick_red, :flag_drop_tick_blue
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
flag_carrier_red
|
||||
flag_carrier_blue
|
||||
flag_drop_tick_red
|
||||
flag_drop_tick_blue
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_GAMEDATAFLAG
|
||||
end
|
||||
end
|
||||
end
|
21
lib/snapshot/items/game_data_team.rb
Normal file
21
lib/snapshot/items/game_data_team.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class GameDataTeam < SnapItemBase
|
||||
attr_accessor :teamscore_red, :teamscore_blue
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
teamscore_red
|
||||
teamscore_blue
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_GAMEDATATEAM
|
||||
end
|
||||
end
|
||||
end
|
24
lib/snapshot/items/laser.rb
Normal file
24
lib/snapshot/items/laser.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class Laser < SnapItemBase
|
||||
attr_accessor :x, :y, :from_x, :from_y, :start_tick
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
x
|
||||
y
|
||||
from_x
|
||||
from_y
|
||||
start_tick
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_LASER
|
||||
end
|
||||
end
|
||||
end
|
22
lib/snapshot/items/pickup.rb
Normal file
22
lib/snapshot/items/pickup.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class Pickup < SnapItemBase
|
||||
attr_accessor :x, :y, :type
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
x
|
||||
y
|
||||
type
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_PICKUP
|
||||
end
|
||||
end
|
||||
end
|
32
lib/snapshot/items/player_input.rb
Normal file
32
lib/snapshot/items/player_input.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class PlayerInput < SnapItemBase
|
||||
attr_accessor :direction, :target_x, :target_y,
|
||||
:jump, :fire, :hook,
|
||||
:player_flags, :wanted_weapon,
|
||||
:next_weapon, :prev_weapon
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
direction
|
||||
target_x
|
||||
target_y
|
||||
jump
|
||||
fire
|
||||
hook
|
||||
player_flags
|
||||
wanted_weapon
|
||||
next_weapon
|
||||
prev_weapon
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_PLAYERINPUT
|
||||
end
|
||||
end
|
||||
end
|
23
lib/snapshot/items/spectator_info.rb
Normal file
23
lib/snapshot/items/spectator_info.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../snap_item_base'
|
||||
|
||||
class NetObj
|
||||
class SpectatorInfo < SnapItemBase
|
||||
attr_accessor :spec_mode, :spectator_id, :x, :y
|
||||
|
||||
def initialize(hash_or_raw)
|
||||
@field_names = %i[
|
||||
spec_mode
|
||||
spectator_id
|
||||
x
|
||||
y
|
||||
]
|
||||
super
|
||||
end
|
||||
|
||||
def self.match_type?(type)
|
||||
type == NETOBJTYPE_SPECTATORINFO
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,9 +2,22 @@
|
|||
|
||||
require_relative 'items/game_data'
|
||||
require_relative 'items/character'
|
||||
require_relative 'items/player_info'
|
||||
require_relative 'items/projectile'
|
||||
require_relative 'items/pickup'
|
||||
require_relative 'items/flag'
|
||||
require_relative 'items/game_data_team'
|
||||
require_relative 'items/game_data_flag'
|
||||
require_relative 'items/player_input'
|
||||
require_relative 'items/laser'
|
||||
require_relative 'items/player_info'
|
||||
require_relative 'items/spectator_info'
|
||||
require_relative 'items/client_info'
|
||||
require_relative 'events/sound_world'
|
||||
require_relative 'events/explosion'
|
||||
require_relative 'events/spawn'
|
||||
require_relative 'events/damage'
|
||||
require_relative 'events/death'
|
||||
require_relative 'events/hammer_hit'
|
||||
require_relative '../packer'
|
||||
|
||||
class SnapshotUnpacker
|
||||
|
@ -93,16 +106,42 @@ class SnapshotUnpacker
|
|||
id_parsed = u.parsed.last
|
||||
while item_type
|
||||
obj = nil
|
||||
if NetObj::GameData.match_type?(item_type)
|
||||
if NetObj::PlayerInput.match_type?(item_type)
|
||||
obj = NetObj::PlayerInput.new(u)
|
||||
elsif NetObj::Projectile.match_type?(item_type)
|
||||
obj = NetObj::Projectile.new(u)
|
||||
elsif NetObj::Laser.match_type?(item_type)
|
||||
obj = NetObj::Laser.new(u)
|
||||
elsif NetObj::Pickup.match_type?(item_type)
|
||||
obj = NetObj::Pickup.new(u)
|
||||
elsif NetObj::Flag.match_type?(item_type)
|
||||
obj = NetObj::Flag.new(u)
|
||||
elsif NetObj::GameData.match_type?(item_type)
|
||||
obj = NetObj::GameData.new(u)
|
||||
elsif NetObj::GameDataTeam.match_type?(item_type)
|
||||
obj = NetObj::GameDataTeam.new(u)
|
||||
elsif NetObj::GameDataFlag.match_type?(item_type)
|
||||
obj = NetObj::GameDataFlag.new(u)
|
||||
elsif NetObj::Character.match_type?(item_type)
|
||||
obj = NetObj::Character.new(u)
|
||||
elsif NetObj::PlayerInfo.match_type?(item_type)
|
||||
obj = NetObj::PlayerInfo.new(u)
|
||||
elsif NetObj::Projectile.match_type?(item_type)
|
||||
obj = NetObj::Projectile.new(u)
|
||||
elsif NetObj::SpectatorInfo.match_type?(item_type)
|
||||
obj = NetObj::SpectatorInfo.new(u)
|
||||
elsif NetObj::ClientInfo.match_type?(item_type)
|
||||
obj = NetObj::ClientInfo.new(u)
|
||||
elsif NetEvent::Explosion.match_type?(item_type)
|
||||
obj = NetEvent::Explosion.new(u)
|
||||
elsif NetEvent::SoundWorld.match_type?(item_type)
|
||||
obj = NetEvent::SoundWorld.new(u)
|
||||
elsif NetEvent::Spawn.match_type?(item_type)
|
||||
obj = NetEvent::Spawn.new(u)
|
||||
elsif NetEvent::Damage.match_type?(item_type)
|
||||
obj = NetEvent::Damage.new(u)
|
||||
elsif NetEvent::Death.match_type?(item_type)
|
||||
obj = NetEvent::Death.new(u)
|
||||
elsif NetEvent::HammerHit.match_type?(item_type)
|
||||
obj = NetEvent::HammerHit.new(u)
|
||||
elsif @verbose
|
||||
puts "no match #{item_type}"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue