Class: GameMachine::Clients::TestClientProxy

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/game_machine/clients/test_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, client) ⇒ TestClientProxy

Returns a new instance of TestClientProxy.



8
9
10
11
12
13
# File 'lib/game_machine/clients/test_client.rb', line 8

def initialize(name,client)
  @data = java.util.concurrent.ConcurrentHashMap.new
  @data[:name] = name
  @data[:client] = client
  @data[:actual] = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/game_machine/clients/test_client.rb', line 6

def config
  @config
end

Instance Method Details

#actualObject



27
28
29
# File 'lib/game_machine/clients/test_client.rb', line 27

def actual
  @data[:actual]
end

#actual=(actual) ⇒ Object



23
24
25
# File 'lib/game_machine/clients/test_client.rb', line 23

def actual=(actual)
  @data[:actual] = actual
end

#clearObject



67
68
69
# File 'lib/game_machine/clients/test_client.rb', line 67

def clear
  actual.clear
end

#clientObject



31
32
33
# File 'lib/game_machine/clients/test_client.rb', line 31

def client
  @data[:client]
end

#ctxObject



19
20
21
# File 'lib/game_machine/clients/test_client.rb', line 19

def ctx
  @data[:ctx]
end

#ctx=(ctx) ⇒ Object



15
16
17
# File 'lib/game_machine/clients/test_client.rb', line 15

def ctx=(ctx)
  @data[:ctx] = ctx
end

#do_expect(found, not_found, component) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/game_machine/clients/test_client.rb', line 59

def do_expect(found,not_found,component)
  unless found
    found = not_found
  end
  expect(found).to eq(component)
  actual.clear
end

#entity_with_component(component, wait = 0.100, &blk) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/game_machine/clients/test_client.rb', line 71

def entity_with_component(component,wait=0.100,&blk)
  found = false
  10.times do
    actual.each do |entity|
      if entity.component_names.include?(component)
        yield entity if block_given?
        found = entity
      end
    end
    return found if found
    sleep wait
  end
  found
end

#nameObject



35
36
37
# File 'lib/game_machine/clients/test_client.rb', line 35

def name
  @data[:name]
end

#refObject



46
47
48
# File 'lib/game_machine/clients/test_client.rb', line 46

def ref
  TestClient.find(name)
end

#send_to_server(client_message) ⇒ Object



55
56
57
# File 'lib/game_machine/clients/test_client.rb', line 55

def send_to_server(client_message)
  client.send_to_server(client_message.to_byte_array,ctx)
end

#should_receive_component(component, wait = 0.20, &blk) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/game_machine/clients/test_client.rb', line 86

def should_receive_component(component,wait=0.20, &blk)
  actual ||= []
  blk.call
  called = false
  found = nil
  not_found = []
  10.times do
    not_found = []
    actual.each do |entity|
      if entity.component_names.include?(component)
        called = true
        found = component
      else
        not_found += entity.component_names
      end
    end
    if called
      do_expect(found,not_found,component)
      return
    end
    sleep wait
  end
end

#stopObject



50
51
52
53
# File 'lib/game_machine/clients/test_client.rb', line 50

def stop
  ref.tell('stop')
  client.shutdown
end

#wait_for_ctxObject



39
40
41
42
43
44
# File 'lib/game_machine/clients/test_client.rb', line 39

def wait_for_ctx
  loop do
    @data[:ctx] = TestClient.find(name).ask('ctx',20)
    return if @data[:ctx]
  end
end