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:
Forrest 2026-10-06 13:47:52 -04:00
parent 287b6ac6cc
commit 315e6890f7
7 changed files with 305 additions and 23 deletions

View file

@ -18,7 +18,8 @@ var player: PlayerCharacter
var is_open := false
## Which shop this instance lists ("workbench" or "shed"); set by setup().
var shop := "workbench"
## Co-op partner: ask the host to buy (upgrade id); the result comes back as a message.
## Co-op partner: ask the host to buy (upgrade id); the result comes back as a message, and a
## purchase that went through as confirm_bought.
var buy_request: Callable
## The avatar slot of this machine's scarecrow (FarmSim.set_local): what's affordable is its own
## pouch plus the shed.
@ -144,6 +145,19 @@ func _buy(id: String) -> void:
if not was and Upgrades.owned(campaign.state, id):
bought.emit(id)
message.emit(text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5))
_after_buy(id)
## Co-op partner: the host bought id for this machine's scarecrow (buy_request), and this
## machine's farm state has it now. It counts as bought here, as a purchase in solo does (bought:
## a new weapon goes into this scarecrow's hand, the jingle plays) (#22).
func confirm_bought(id: String) -> void:
bought.emit(id)
if is_open and _rows.has(id):
_after_buy(id)
func _after_buy(id: String) -> void:
refresh()
if (_rows[id] as Button).has_focus() and (_rows[id] as Button).disabled:
_close.grab_focus()