Class: InputTiming

Inherits:
Object
  • Object
show all
Defined in:
lib/messages/input_timing.rb

Overview

InputTiming

Server -> Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_raw) ⇒ InputTiming

Returns a new instance of InputTiming.



12
13
14
15
16
17
18
# File 'lib/messages/input_timing.rb', line 12

def initialize(hash_or_raw)
  if hash_or_raw.instance_of?(Hash)
    init_hash(hash_or_raw)
  else
    init_raw(hash_or_raw)
  end
end

Instance Attribute Details

#intended_tickObject

Returns the value of attribute intended_tick.



10
11
12
# File 'lib/messages/input_timing.rb', line 10

def intended_tick
  @intended_tick
end

#time_leftObject

Returns the value of attribute time_left.



10
11
12
# File 'lib/messages/input_timing.rb', line 10

def time_left
  @time_left
end

Instance Method Details

#init_hash(attr) ⇒ Object



26
27
28
29
# File 'lib/messages/input_timing.rb', line 26

def init_hash(attr)
  @intended_tick = attr[:intended_tick] || 0
  @time_left = attr[:time_left] || 0
end

#init_raw(data) ⇒ Object



20
21
22
23
24
# File 'lib/messages/input_timing.rb', line 20

def init_raw(data)
  u = Unpacker.new(data)
  @intended_tick = u.get_int
  @time_left = u.get_int
end

#to_aObject

basically to_network int array the Server sends to the Client



40
41
42
43
# File 'lib/messages/input_timing.rb', line 40

def to_a
  Packer.pack_int(@intended_tick) +
    Packer.pack_int(@time_left)
end

#to_hObject



31
32
33
34
35
36
# File 'lib/messages/input_timing.rb', line 31

def to_h
  {
    intended_tick: @intended_tick,
    time_left: @time_left
  }
end

#to_sObject



45
46
47
# File 'lib/messages/input_timing.rb', line 45

def to_s
  to_h
end