ceml 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/ceml.gemspec +1 -1
  3. data/lib/ceml/driver.rb +38 -25
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.5
data/ceml.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ceml}
8
- s.version = "0.5.4"
8
+ s.version = "0.5.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Edelman"]
data/lib/ceml/driver.rb CHANGED
@@ -8,50 +8,63 @@ end
8
8
 
9
9
  module CEML
10
10
  class Driver
11
- LOCATIONS = {}
11
+
12
12
  PLAYERS = {}
13
13
  INCIDENTS = {}
14
- JUST_SAID = {}
15
-
16
- def start(script, id = rand(36**10).to_s(36))
17
- x = CEML::Incident.new script, id
18
- INCIDENTS[id] = x
19
- PLAYERS[id] = []
14
+ def with_incident(id, script = nil)
15
+ id ||= rand(36**10).to_s(36)
16
+ PLAYERS[id] ||= []
17
+ INCIDENTS[id] ||= CEML::Incident.new script, id if script
18
+ raise "no incident #{id}" unless INCIDENTS[id]
19
+ yield INCIDENTS[id], PLAYERS[id] if block_given?
20
20
  id
21
21
  end
22
22
 
23
- def player_said(incident_id, player, what)
24
- JUST_SAID[player[:id]] = what
25
- puts "Said #{what.inspect}"
23
+ LOCATIONS = {}
24
+ def ping script, candidate
25
+ LOCATIONS[script] ||= []
26
+ script.post candidate, LOCATIONS[script]
27
+ LOCATIONS[script].delete_if do |loc|
28
+ next unless loc.cast
29
+ with_incident nil, script do |incident, players|
30
+ loc.cast.each{ |guy| subpost incident, players, guy.initial_state }
31
+ end
32
+ end
26
33
  end
27
34
 
28
- def run(incident_id)
29
- INCIDENTS[incident_id].run(PLAYERS[incident_id]) do |player, meth, what|
30
- meth = "player_#{meth}"
31
- send(meth, incident_id, player, what) if respond_to? meth
32
- end
35
+ def start(script, id = nil)
36
+ with_incident(id, script)
33
37
  end
34
38
 
35
39
  def post incident_id, player
40
+ with_incident incident_id do |incident, players|
41
+ subpost incident, players, player
42
+ end
43
+ end
44
+
45
+ def subpost incident, players, player
36
46
  player_id = player[:id]
37
47
  player[:roles] = Set.new([*player[:roles] || []])
38
48
  player[:roles] << :agents
39
- if existing_player = PLAYERS[incident_id].find{ |p| p[:id] == player_id }
49
+ if existing_player = players.find{ |p| p[:id] == player_id }
40
50
  existing_player[:roles] += player.delete :roles
41
51
  existing_player.update player
42
52
  else
43
- PLAYERS[incident_id] << player
53
+ players << player
44
54
  end
45
- run incident_id
55
+ run incident, players
46
56
  end
47
57
 
48
- def ping script, candidate
49
- LOCATIONS[script] ||= []
50
- script.post candidate, LOCATIONS[script]
51
- LOCATIONS[script].delete_if do |loc|
52
- next unless loc.cast
53
- iid = start(script)
54
- loc.cast.each{ |guy| post iid, guy.initial_state }
58
+ JUST_SAID = {}
59
+ def player_said(incident_id, player, what)
60
+ JUST_SAID[player[:id]] = what
61
+ puts "Said #{what.inspect}"
62
+ end
63
+
64
+ def run(incident, players)
65
+ incident.run(players) do |player, meth, what|
66
+ meth = "player_#{meth}"
67
+ send(meth, incident.id, player, what) if respond_to? meth
55
68
  end
56
69
  end
57
70
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 4
9
- version: 0.5.4
8
+ - 5
9
+ version: 0.5.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Edelman