Class: GameMachine::Clients::TestClientProxy
- Inherits:
-
Object
- Object
- GameMachine::Clients::TestClientProxy
- Includes:
- RSpec::Matchers
- Defined in:
- lib/game_machine/clients/test_client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #actual ⇒ Object
- #actual=(actual) ⇒ Object
- #clear ⇒ Object
- #client ⇒ Object
- #ctx ⇒ Object
- #ctx=(ctx) ⇒ Object
- #do_expect(found, not_found, component) ⇒ Object
- #entity_with_component(component, wait = 0.100, &blk) ⇒ Object
-
#initialize(name, client) ⇒ TestClientProxy
constructor
A new instance of TestClientProxy.
- #name ⇒ Object
- #ref ⇒ Object
- #send_to_server(client_message) ⇒ Object
- #should_receive_component(component, wait = 0.20, &blk) ⇒ Object
- #stop ⇒ Object
- #wait_for_ctx ⇒ Object
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
#config ⇒ Object (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
#actual ⇒ Object
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 |
#clear ⇒ Object
67 68 69 |
# File 'lib/game_machine/clients/test_client.rb', line 67 def clear actual.clear end |
#client ⇒ Object
31 32 33 |
# File 'lib/game_machine/clients/test_client.rb', line 31 def client @data[:client] end |
#ctx ⇒ Object
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 |
#name ⇒ Object
35 36 37 |
# File 'lib/game_machine/clients/test_client.rb', line 35 def name @data[:name] end |
#ref ⇒ Object
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.send_to_server(.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 |
#stop ⇒ Object
50 51 52 53 |
# File 'lib/game_machine/clients/test_client.rb', line 50 def stop ref.tell('stop') client.shutdown end |
#wait_for_ctx ⇒ Object
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 |