Adapt game clients to the unified WebSocket input stream.
Replace separate accel/tap push handling with input messages, set_input_stream, and a single set_stream on port 8081. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+32
-57
@@ -79,7 +79,7 @@ func _start_stream() -> void:
|
||||
continue
|
||||
|
||||
var accel_on: bool = ui["accel_cb"].button_pressed
|
||||
_send({"type": "set_accel_stream", "client_id": cid, "enable": accel_on})
|
||||
_send({"type": "set_input_stream", "client_id": cid, "enable": accel_on})
|
||||
if accel_on:
|
||||
want_accel = true
|
||||
|
||||
@@ -97,24 +97,23 @@ func _start_stream() -> void:
|
||||
if tap_on:
|
||||
want_tap = true
|
||||
|
||||
_send({"type": "set_stream", "enable": want_accel, "interval_ms": _interval_ms()})
|
||||
_send({"type": "set_tap_stream", "enable": want_tap, "interval_ms": _interval_ms()})
|
||||
var want_input := want_accel or want_tap
|
||||
_send({"type": "set_stream", "enable": want_input, "interval_ms": _interval_ms()})
|
||||
|
||||
_streaming = true
|
||||
start_stream_btn.disabled = true
|
||||
stop_stream_btn.disabled = false
|
||||
_log("Stream gestartet (accel=%s, tap=%s)" % [want_accel, want_tap])
|
||||
_log("Stream gestartet (input=%s, accel=%s, tap=%s)" % [want_input, want_accel, want_tap])
|
||||
|
||||
|
||||
func _stop_stream() -> void:
|
||||
_send({"type": "set_stream", "enable": false, "interval_ms": _interval_ms()})
|
||||
_send({"type": "set_tap_stream", "enable": false, "interval_ms": _interval_ms()})
|
||||
|
||||
for cid in _client_ui:
|
||||
var ui: Dictionary = _client_ui[cid]
|
||||
if not ui.get("available", false):
|
||||
continue
|
||||
_send({"type": "set_accel_stream", "client_id": cid, "enable": false})
|
||||
_send({"type": "set_input_stream", "client_id": cid, "enable": false})
|
||||
_send({
|
||||
"type": "set_tap_notify",
|
||||
"client_id": cid,
|
||||
@@ -180,7 +179,7 @@ func _populate_clients(clients: Array) -> void:
|
||||
|
||||
var accel_cb := CheckBox.new()
|
||||
accel_cb.text = "Accel Stream"
|
||||
accel_cb.button_pressed = entry.get("accel_stream", false)
|
||||
accel_cb.button_pressed = entry.get("input_stream", false)
|
||||
accel_cb.disabled = not available
|
||||
vbox.add_child(accel_cb)
|
||||
|
||||
@@ -361,7 +360,6 @@ func _populate_clients(clients: Array) -> void:
|
||||
"led_digit_row": led_digit_row,
|
||||
"led_blink_row": led_blink_row,
|
||||
"values_label": values_label,
|
||||
"last_tap": "",
|
||||
}
|
||||
_update_led_fields(cid)
|
||||
|
||||
@@ -406,10 +404,8 @@ func _handle_message(text: String) -> void:
|
||||
_on_hello(data)
|
||||
"client_list":
|
||||
_on_client_list(data)
|
||||
"accel":
|
||||
_on_accel(data)
|
||||
"tap":
|
||||
_on_tap(data)
|
||||
"input":
|
||||
_on_input(data)
|
||||
"led_ring_status":
|
||||
_log("← LED #%s: %s" % [data.get("client_id", "?"), "OK" if data.get("success", false) else data.get("error", "?")])
|
||||
_:
|
||||
@@ -431,9 +427,9 @@ func _on_client_list(data: Dictionary) -> void:
|
||||
_populate_clients(data.get("clients", []))
|
||||
|
||||
|
||||
func _on_accel(data: Dictionary) -> void:
|
||||
func _on_input(data: Dictionary) -> void:
|
||||
if not data.get("success", false):
|
||||
stream_output.text = "accel FEHLER: %s" % data.get("error", "?")
|
||||
stream_output.text = "input FEHLER: %s" % data.get("error", "?")
|
||||
return
|
||||
|
||||
var summary: PackedStringArray = []
|
||||
@@ -445,54 +441,33 @@ func _on_accel(data: Dictionary) -> void:
|
||||
continue
|
||||
|
||||
var ui: Dictionary = _client_ui[cid]
|
||||
var tap_part: String = ui.get("last_tap", "")
|
||||
var lines: PackedStringArray = []
|
||||
if client.get("valid", false):
|
||||
var accel_text := "x=%d y=%d z=%d (age %sms)" % [
|
||||
int(client.get("x", 0)),
|
||||
int(client.get("y", 0)),
|
||||
int(client.get("z", 0)),
|
||||
str(client.get("age_ms", "?")),
|
||||
]
|
||||
ui["values_label"].text = accel_text + ("\n" + tap_part if tap_part else "")
|
||||
summary.append("#%d: %s" % [cid, accel_text])
|
||||
lines.append(
|
||||
"x=%d y=%d z=%d (age %sms)" % [
|
||||
int(client.get("x", 0)),
|
||||
int(client.get("y", 0)),
|
||||
int(client.get("z", 0)),
|
||||
str(client.get("accel_age_ms", "?")),
|
||||
]
|
||||
)
|
||||
|
||||
var tap_kind := str(client.get("tap_kind", "none"))
|
||||
if tap_kind != "none":
|
||||
var tap_text := "tap: %s (age %sms)" % [tap_kind, str(client.get("tap_age_ms", "?"))]
|
||||
lines.append(tap_text)
|
||||
_flash_client_panel(cid)
|
||||
|
||||
if lines.is_empty():
|
||||
ui["values_label"].text = "—"
|
||||
else:
|
||||
ui["values_label"].text = "accel: —" + ("\n" + tap_part if tap_part else "")
|
||||
ui["values_label"].text = "\n".join(lines)
|
||||
summary.append("#%d: %s" % [cid, " · ".join(lines)])
|
||||
|
||||
if summary.is_empty():
|
||||
stream_output.text = "accel (keine gültigen Samples)"
|
||||
stream_output.text = "input (keine Daten)"
|
||||
else:
|
||||
stream_output.text = "accel\n" + "\n".join(summary)
|
||||
|
||||
|
||||
func _on_tap(data: Dictionary) -> void:
|
||||
if not data.get("success", false):
|
||||
return
|
||||
|
||||
var summary: PackedStringArray = []
|
||||
for event in data.get("events", []):
|
||||
if typeof(event) != TYPE_DICTIONARY:
|
||||
continue
|
||||
var cid := int(event.get("client_id", 0))
|
||||
if not _client_ui.has(cid):
|
||||
continue
|
||||
|
||||
var tap_text := "tap: %s (age %sms)" % [str(event.get("kind", "?")), str(event.get("age_ms", "?"))]
|
||||
var ui: Dictionary = _client_ui[cid]
|
||||
ui["last_tap"] = tap_text
|
||||
|
||||
var existing: String = ui["values_label"].text
|
||||
if existing == "—" or existing.begins_with("accel: —"):
|
||||
ui["values_label"].text = tap_text
|
||||
elif "\n" in existing:
|
||||
ui["values_label"].text = existing.split("\n", false, 1)[0] + "\n" + tap_text
|
||||
else:
|
||||
ui["values_label"].text = existing + "\n" + tap_text
|
||||
|
||||
summary.append("#%d: %s" % [cid, tap_text])
|
||||
_flash_client_panel(cid)
|
||||
|
||||
if not summary.is_empty():
|
||||
stream_output.text = "tap\n" + "\n".join(summary)
|
||||
stream_output.text = "input\n" + "\n".join(summary)
|
||||
|
||||
|
||||
func _set_spinbox_enabled(spin: SpinBox, enabled: bool) -> void:
|
||||
|
||||
Reference in New Issue
Block a user