Files
Jeff Luke 41ef12f954 Add Pac-Man power-on flow and document Odin integration
- Add a four-second arcade-style boot sequence followed by the
  Character / Nickname introduction.
- Separate cabinet power-on from RFID credit and player Start.
- Add operator Power on control and cabinet power-state reporting.
- Prevent repeated power commands from restarting boot or gameplay.
- Ignore RFID scans received before the cabinet is ready.
- Add power-state, RFID, controller, and GPIO feedback regression tests.

- Expand the master walkthrough with export, packaging, file transfer,
  fresh-Pi setup, RFID compilation, and end-to-end testing instructions.
- Correct tester hardware documentation: BCM23/J20 drives an LED;
  physical buttons connect through a separate I2C1 input board.
- Document operator-triggered power-on as the current test workflow
  and retain the temporary 2.4 configuration compatibility notes.
- Record successful physical testing of power-on, RFID credit,
  and player Start.

- Add an Odin integration README describing the proposed Rust/NATS
  bridge, shared messages, Flutter GM interface, autopilot sequencing,
  hardware ownership, and Starfish SSH-management role.
- Define migration milestones and information needed from the
  framework owner; link the integration guide from the root README.

Validation: 69 controller tests, 10 GPIO tests, Pac-Man power/RFID
checks, managed-cabinet lifecycle checks, and visual screen inspection.
2026-10-17 18:47:26 -07:00

171 lines
7.3 KiB
GDScript

extends Node
const VERSION := "arcade-cabinet-2.4"
var cabinet_id := "cabinet_01"
var database: ProjectDatabase = preload("res://data/project_database.tres")
var cabinet: CabinetProfile
var connection: Node
var game: ArcadeGame
var session := ""
var phase := "idle"
var boot := ""
var reports: Array[Dictionary] = []
var outcomes: Dictionary = {}
var busy := false
var executing := false
var event_number := 0
var notice: Label
var test_win_remaining := -1.0
func _process(delta: float) -> void:
if phase != "playing" or test_win_remaining < 0.0 or game == null: return
test_win_remaining -= delta
if test_win_remaining <= 0.0:
test_win_remaining = -1.0
game.win_game()
func _ready() -> void:
var config := ConfigFile.new()
config.load("user://arcade_network.cfg")
cabinet_id = str(config.get_value("network", "cabinet_id", cabinet_id))
for arg in OS.get_cmdline_user_args():
if arg.begins_with("--cabinet="): cabinet_id = arg.trim_prefix("--cabinet=")
for definition in database.cabinets:
if str(definition.cabinet_id) == cabinet_id: cabinet = definition
boot = Crypto.new().generate_random_bytes(16).hex_encode()
# Remote mode must never also run the launcher's local reward mapping.
RoomRuntime.active_assignment = null
HardwareManager.active_cabinet = null
connection = preload("res://core/network/room_connection.gd").new()
add_child(connection)
connection.configure("cabinet")
var layer := CanvasLayer.new()
add_child(layer)
notice = Label.new()
notice.text = "Waiting for the room operator"
notice.position = Vector2(30, 1000)
notice.add_theme_font_size_override("font_size", 22)
layer.add_child(notice)
var timer := Timer.new()
timer.wait_time = .5
timer.timeout.connect(poll)
add_child(timer)
timer.start()
poll()
func poll() -> void:
if busy or executing: return
busy = true
if game != null and phase in ["ready", "powered_off", "booting"] and game.has_method("receive_device_feedback") and HardwareManager.real_gpio and HardwareManager.client != null:
game.receive_device_feedback(HardwareManager.client.get_feedback())
var sent := reports.duplicate(true)
var result: Dictionary = await connection.post("/cabinet/poll", {
"cabinet": cabinet_id, "protocol": 2, "boot": boot, "version": VERSION,
"features": ["assignment_config_v1", "device_feedback_v1", "rfid_credit_v1", "pacman_power_v1"],
"feedback": HardwareManager.client.get_feedback() if HardwareManager.real_gpio and HardwareManager.client != null else {},
"gpio": "real" if HardwareManager.real_gpio else "simulation", "reports": sent,
})
busy = false
if result.has("error"):
notice.text = "Room connection unavailable — waiting to reconnect"
return
for report in sent: reports.erase(report)
if str(result.get("session", "")) != session:
session = str(result.get("session", ""))
outcomes.clear()
reports.clear()
unload()
phase = "idle"
for command in result.get("commands", []):
executing = true
await execute(command)
executing = false
notice.text = "Waiting for the room operator" if game == null else ""
func unload() -> void:
test_win_remaining = -1.0
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
if is_instance_valid(game):
remove_child(game)
game.queue_free()
game = null
func event(name: String) -> void:
if name == "started" and game != null:
test_win_remaining = float(game.run_config.get("test_auto_win_seconds", -1.0))
elif name in ["won", "lost"]:
test_win_remaining = -1.0
event_number += 1
reports.append({"kind": "event", "id": boot + ":" + str(event_number), "session": session, "event": name})
phase = {"started": "playing", "won": "won", "lost": "lost"}.get(name, phase)
if name in ["won", "lost"] and game != null:
game.set_process_unhandled_input(false)
game.set_process_input(false)
func acknowledge(command: Dictionary, ok: bool, detail: String) -> void:
var report := {"kind": "ack", "id": command.id, "session": session, "ok": ok, "detail": detail}
outcomes[command.id] = report
reports.append(report)
func execute(command: Dictionary) -> void:
if command.get("session") != session: return
if outcomes.has(command.id):
reports.append(outcomes[command.id])
return
match command.get("type"):
"prepare":
var definition: GameDefinition
for entry in database.games:
if str(entry.game_id) == str(command.get("game", "pacman")): definition = entry
if definition == null or cabinet == null or not definition.can_run_on(cabinet):
acknowledge(command, false, "Game is missing or incompatible with this cabinet")
return
if command.get("variant", "standard") != "standard":
acknowledge(command, false, "Unsupported game variant")
return
unload()
game = definition.scene.instantiate()
if str(definition.game_id) == "missile_command": game.set("relative_mouse_aim", true)
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if str(definition.game_id) in ["missile_command", "tempest"] else Input.MOUSE_MODE_VISIBLE
add_child(game)
if game.has_signal("power_state_changed"):
game.power_state_changed.connect(_power_changed)
game.configure(command.get("game_config", {}).duplicate(true))
if game.has_method("receive_device_feedback") and HardwareManager.client != null:
game.receive_device_feedback(HardwareManager.client.get_feedback())
game.game_started.connect(func(): event("started"))
game.game_won.connect(func(): event("won"))
game.game_lost.connect(func(): event("lost"))
phase = {"off": "powered_off", "booting": "booting", "ready": "ready"}.get(str(game.get("power_state")), "ready") if game.has_signal("power_state_changed") else "ready"
acknowledge(command, true, definition.display_name + " loaded: " + phase)
"power_on":
var ok: bool = game != null and phase == "powered_off" and game.has_method("power_on") and game.power_on()
acknowledge(command, ok, "Power-on requested" if ok else "Cabinet is not powered off")
"start":
var ok: bool = game != null and phase == "ready" and game.start_game()
acknowledge(command, ok, "Game started" if ok else "Cabinet was not ready")
"reset":
unload()
phase = "idle"
acknowledge(command, true, "Game unloaded; cabinet idle")
"reward", "output":
if (command.type == "reward" and phase != "won") or not HardwareManager.real_gpio or cabinet == null or cabinet.hardware_config == null:
acknowledge(command, false, "Reward requires a win and real GPIO mode")
return
var action := cabinet.hardware_config.get_action(StringName(command.get("action_id", "coin_release")))
if action == null:
acknowledge(command, false, "Hardware action is not defined on this cabinet")
return
var ok: bool = await HardwareManager.client.send({
"controller": str(cabinet.hardware_config.controller_id), "pin": action.gpio_pin,
"mode": "pulse" if action.action_type == HardwareAction.ActionType.PULSE_OUTPUT else "set", "active_high": action.active_high, "duration_ms": action.pulse_duration_ms,
"request_id": command.id,
})
acknowledge(command, ok, "GPIO bridge accepted pulse; delivery unconfirmed" if ok else "GPIO failed or acknowledgement lost; inspect cabinet")
_:
acknowledge(command, false, "Unsupported command")
func _power_changed(state: String) -> void:
if state == "off": return # prepare acknowledgement establishes this state
phase = "booting" if state == "booting" else "ready"
event("power_booting" if state == "booting" else "power_ready")