Added setup folder with needed launch files - Update when new version is ready
This commit is contained in:
1 parent
91b7840535
commit
0dcada4db2
50 files changed
+3753
-11
No files matched your search
@@ -135,7 +135,10 @@ class Room:
|
||||
else:
|
||||
self.state["reward"] = "requested"
|
||||
elif success:
|
||||
self.state["phase"] = {"prepare": "ready", "reset": "idle", "start": "playing"}[command["type"]]
|
||||
self.state["phase"] = {"prepare": "ready", "reset": "waiting" if self.state.get("gate") else "idle", "start": "playing"}[command["type"]]
|
||||
if command["type"] == "prepare" and self.state.pop("auto_start", False):
|
||||
self.state["phase"] = "starting"
|
||||
self.command("start")
|
||||
if command["type"] == "prepare":
|
||||
for action in self.state["mappings"].get("game_activated", []):
|
||||
self.command("output")["action_id"] = action
|
||||
@@ -216,7 +219,24 @@ class Fleet:
|
||||
raise ValueError("Scenario must have unique, nonempty cabinet assignments")
|
||||
# Validate the whole plan before sending anything to any cabinet.
|
||||
for item in assignments: self.validate_assignment(item)
|
||||
by_id = {a["cabinet"]: a for a in assignments}
|
||||
for item in assignments:
|
||||
visited = {item["cabinet"]}
|
||||
source = item.get("activate_after_win", "")
|
||||
while source:
|
||||
if source not in by_id: raise ValueError("Dependency cabinet must be assigned in the same scenario")
|
||||
if source in visited: raise ValueError("Cabinet activation dependencies cannot form a cycle")
|
||||
visited.add(source)
|
||||
source = by_id[source].get("activate_after_win", "")
|
||||
for item in assignments: self.prepare(item, scenario_id)
|
||||
# Bind dependencies to this particular run, never an earlier win.
|
||||
for item in assignments:
|
||||
source = item.get("activate_after_win")
|
||||
if source:
|
||||
room = self.rooms[item["cabinet"]]
|
||||
room.state["gate"] = dict(cabinet=source, session=self.rooms[source].state["session"])
|
||||
room.log("Waiting for " + source + " to win")
|
||||
room.save()
|
||||
elif action == "prepare":
|
||||
cabinet = data.get("cabinet", "cabinet_01")
|
||||
item = dict(cabinet=cabinet, game=data.get("game", "pacman"), mappings={})
|
||||
@@ -226,14 +246,23 @@ class Fleet:
|
||||
else:
|
||||
cabinet = data.get("cabinet", "cabinet_01")
|
||||
if cabinet not in self.rooms: raise ValueError("Unknown cabinet")
|
||||
if action == "start" and self.rooms[cabinet].state.get("gate"):
|
||||
raise ValueError("This cabinet starts automatically after its dependency wins")
|
||||
self.rooms[cabinet].operator(action)
|
||||
if action == "reset":
|
||||
self.rooms[cabinet].state.pop("gate", None)
|
||||
self.rooms[cabinet].state.pop("auto_start", None)
|
||||
self.rooms[cabinet].save()
|
||||
self.advance()
|
||||
return self.snapshot()
|
||||
|
||||
def prepare(self, item, scenario):
|
||||
room = self.rooms[item["cabinet"]]
|
||||
room.state.update(game=item["game"], mappings=item.get("mappings", {}),
|
||||
variant=item.get("variant", "standard"), scenario=scenario)
|
||||
room.operator("prepare")
|
||||
room.state.pop("gate", None)
|
||||
room.state.pop("auto_start", None)
|
||||
room.operator("reset" if item.get("activate_after_win") else "prepare")
|
||||
room.log("Assignment from " + scenario)
|
||||
room.save()
|
||||
|
||||
@@ -241,7 +270,33 @@ class Fleet:
|
||||
cabinet = data.get("cabinet")
|
||||
if data.get("protocol") != 2: raise ValueError("Update cabinet export: controller requires protocol 2")
|
||||
if cabinet not in self.rooms: raise ValueError("Unknown cabinet")
|
||||
return self.rooms[cabinet].poll(data)
|
||||
self.rooms[cabinet].poll(data)
|
||||
self.advance()
|
||||
room = self.rooms[cabinet]
|
||||
return dict(ok=True, session=room.state["session"],
|
||||
commands=[c for c in room.state["commands"] if c["status"] == "queued"])
|
||||
|
||||
def advance(self):
|
||||
# Invalidate descendants when their source is reset/reassigned/restarted.
|
||||
# Iterate to propagate invalidation through longer chains.
|
||||
for _ in self.rooms:
|
||||
for room in self.rooms.values():
|
||||
gate = room.state.get("gate")
|
||||
if not gate: continue
|
||||
source = self.rooms.get(gate["cabinet"])
|
||||
if source is None or source.state["session"] != gate["session"]:
|
||||
room.state.update(session=str(uuid.uuid4()), phase="needs_prepare", commands=[], seen=[], gate=None, auto_start=False)
|
||||
room.log("Dependency session ended; prepare the scenario again")
|
||||
room.save()
|
||||
for room in self.rooms.values():
|
||||
gate = room.state.get("gate")
|
||||
if not gate or room.state["phase"] != "waiting" or not room.online(): continue
|
||||
source = self.rooms[gate["cabinet"]]
|
||||
if source.state["phase"] == "won":
|
||||
room.state.update(phase="preparing", auto_start=True)
|
||||
room.command("prepare")
|
||||
room.log("Activated by " + gate["cabinet"] + " win")
|
||||
room.save()
|
||||
|
||||
|
||||
def handler_for(room, operator_token, cabinet_token):
|
||||
|
||||
Reference in new issue
Block a user