Task #22: the joining player can open the store
Cause: the open path itself worked. A real two-process run with an E key event opened the shed's menu when P2 stood at the counter. What failed in play was reach: - The partner's game never showed the counter's "[E / X] Shop" prompt. CoopSession._gather_node resolved only the workbench and gather points, so P2's replicated focus was null at the counter. P2 couldn't tell where the 2.2 m reach around the counter's invisible point was. - The host took P2's press on the first tick after the input record arrived, before its copy of P2 had eased to the position in that same record. It dropped the press silently if the lagging copy was out of reach. Walking in at 5 or 9 m/s and pressing E at 2.1 m (inside the reach on P2's screen) failed 3/3. The host's copy was 2.31-2.66 m out. Fixes: - The snapshot's focus now resolves the ShedCounter (_focus_node), so the prompt shows. - The host keeps a partner's interact press pending for 0.3 s (Interactions.PRESS_WINDOW) until a counter in reach takes it. - Interact while the partner's shop menu is open closes it on the partner's machine, and that press is taken back (RemoteControls.Sender.take_back), so the host never reopens it. - When the host completes P2's "buy", it sends a "bought" event. Once P2's farm state has the upgrade, the partner's panel emits bought (UpgradePanel.confirm_bought). As in solo, the new weapon goes into P2's hand and the jingle plays. Still paid from P2's pouch, then the shed. - CoopSession.PROTOCOL 4 -> 5. Tests: test_coop _shops covers both shops opening on the client only, the prompt, interact closing, a press taken while the host's copy is 3.8 m out still opening, an early press not opening later, and a client weapon buy paid from P2's pouch and the shed and equipped on both farms. coop_smoke now opens and closes the shed by day with E key events, both standing and on arrival at a run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
287b6ac6cc
commit
315e6890f7
7 changed files with 305 additions and 23 deletions
|
|
@ -89,6 +89,8 @@ func release() -> void:
|
|||
class Sender:
|
||||
var presses := RemoteControls.counts()
|
||||
var _was := RemoteControls.counts()
|
||||
## The press counts in the last record.
|
||||
var _recorded := RemoteControls.counts()
|
||||
|
||||
## Counts presses from input events (taps between two frames still count).
|
||||
func note(event: InputEvent) -> void:
|
||||
|
|
@ -97,17 +99,26 @@ class Sender:
|
|||
presses[i] += 1
|
||||
_was[i] = 1
|
||||
|
||||
## Takes back the presses of an action made since the last record, so they never reach the
|
||||
## host: this machine used them itself (interact closing the partner's own shop menu, #22).
|
||||
## Returns how many there were.
|
||||
func take_back(action: StringName) -> int:
|
||||
var i := RemoteControls.ACTIONS.find(action)
|
||||
if i < 0:
|
||||
return 0
|
||||
_sample(i)
|
||||
var n := presses[i] - _recorded[i]
|
||||
presses[i] = _recorded[i]
|
||||
return n
|
||||
|
||||
## The input record (RemoteControls.apply): the actions held now (none while frozen: a menu
|
||||
## is up), every press so far, and the scarecrow.
|
||||
func record(combat: ScarecrowCombat, body: PlayerCharacter, build: bool, ui: bool, frozen: bool) -> PackedByteArray:
|
||||
var bits := 0
|
||||
for i in RemoteControls.ACTIONS.size():
|
||||
var down := Input.is_action_pressed(RemoteControls.ACTIONS[i])
|
||||
if down:
|
||||
if _sample(i):
|
||||
bits |= 1 << i
|
||||
if _was[i] == 0: # pressed without an event (simulated input)
|
||||
presses[i] += 1
|
||||
_was[i] = 1 if down else 0
|
||||
_recorded = presses.duplicate()
|
||||
var b := StreamPeerBuffer.new()
|
||||
b.put_u8(0 if frozen else bits)
|
||||
for i in RemoteControls.ACTIONS.size():
|
||||
|
|
@ -123,3 +134,11 @@ class Sender:
|
|||
CoopLink.put_angle(b, body.model.rotation.y)
|
||||
b.put_u8(clampi(roundi(body.move_strength() * 100.0), 0, 255))
|
||||
return b.data_array
|
||||
|
||||
## Whether action i is held now; a press without an input event (simulated input) counts.
|
||||
func _sample(i: int) -> bool:
|
||||
var down := Input.is_action_pressed(RemoteControls.ACTIONS[i])
|
||||
if down and _was[i] == 0:
|
||||
presses[i] += 1
|
||||
_was[i] = 1 if down else 0
|
||||
return down
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue