ceml 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/ceml.gemspec +1 -1
- data/lib/ceml/driver.rb +38 -25
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.5
|
data/ceml.gemspec
CHANGED
data/lib/ceml/driver.rb
CHANGED
@@ -8,50 +8,63 @@ end
|
|
8
8
|
|
9
9
|
module CEML
|
10
10
|
class Driver
|
11
|
-
|
11
|
+
|
12
12
|
PLAYERS = {}
|
13
13
|
INCIDENTS = {}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
INCIDENTS[id]
|
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
|
-
|
24
|
-
|
25
|
-
|
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
|
29
|
-
|
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 =
|
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
|
-
|
53
|
+
players << player
|
44
54
|
end
|
45
|
-
run
|
55
|
+
run incident, players
|
46
56
|
end
|
47
57
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|