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
|
|
@ -2,8 +2,9 @@ extends SceneTree
|
|||
## Co-op over real GD-Sync (LAN mode, peer to peer on this machine): run two of these at once,
|
||||
## a host and a partner. Each loads the game (main.tscn, with its own save and settings files),
|
||||
## the host starts a vacation and opens a lobby, the partner finds it on the network and joins,
|
||||
## and both play a day and a night with enemies. Each prints what it saw and exits 0 when it
|
||||
## all checked out:
|
||||
## and both play a day and a night with enemies. By day the partner walks up to the supply shed's
|
||||
## counter, and E (a key event, as a keyboard sends it) opens the shed's menu there and E again
|
||||
## closes it (#22). Each prints what it saw and exits 0 when it all checked out:
|
||||
## godot --headless --path . --script res://game/tools/coop_smoke.gd -- --role=host &
|
||||
## godot --headless --path . --script res://game/tools/coop_smoke.gd -- --role=join
|
||||
## Options: --seconds=N how long to play once joined (default 20); --discover makes the partner
|
||||
|
|
@ -78,7 +79,11 @@ func _run() -> void:
|
|||
_check(true, "a partner joined: %s" % sim.coop.partner_name)
|
||||
await _wait(func() -> bool: return false, 3.0)
|
||||
sim.campaign.begin_day()
|
||||
await _wait(func() -> bool: return false, 2.0)
|
||||
for visit: String in ["standing at the counter", "on arrival"]: # the partner's _shop
|
||||
_check(await _wait(func() -> bool: return sim.partner != null and sim.partner.remote.ui_open, 20.0),
|
||||
"P2 opened the shed's menu by day, %s (the host saw P2's menu up)" % visit)
|
||||
_check(await _wait(func() -> bool: return sim.partner == null or not sim.partner.remote.ui_open, 10.0), "and closed it")
|
||||
await _wait(func() -> bool: return false, 1.0)
|
||||
sim.campaign.advance_phase()
|
||||
sim.campaign.advance_phase()
|
||||
for i in 24:
|
||||
|
|
@ -113,6 +118,8 @@ func _run() -> void:
|
|||
await _finish()
|
||||
return
|
||||
_check(main.screen == Main.Screen.PLAYING and sim.replica and sim.local_avatar.slot == 1, "joined: playing P2 on a replica of the host's farm")
|
||||
await _wait(func() -> bool: return sim.campaign.is_daytime(), 30.0)
|
||||
await _shop(sim)
|
||||
sim.player.global_position = Vector3(4.0, 0.0, -8.0)
|
||||
await _wait(func() -> bool: return sim.campaign.state.phase == CampaignController.Phase.NIGHT, 30.0)
|
||||
_check(sim.campaign.state.phase == CampaignController.Phase.NIGHT, "the host's nightfall reached the partner")
|
||||
|
|
@ -132,6 +139,56 @@ func _run() -> void:
|
|||
_finish()
|
||||
|
||||
|
||||
## The partner's shop (#22): P2 walks up to the supply shed's counter by day, and E (a key event,
|
||||
## as a player's keyboard sends it) opens the shed's menu; E again closes it. Then E pressed on
|
||||
## arrival, still walking in at run speed just inside the counter's reach: the host's copy of P2
|
||||
## isn't in reach yet when the press gets there, and it opens all the same.
|
||||
func _shop(sim: FarmSim) -> void:
|
||||
var counter := sim.interactions.shed_counter
|
||||
sim.player.global_position = counter.global_position + Vector3(0.0, 0.0, 1.2)
|
||||
_check(await _wait(func() -> bool: return sim.interactions.focus == counter and counter._label.text.begins_with("[E / X] Shop"), 3.0),
|
||||
"P2 at the shed's counter: its prompt shows ('%s')" % counter._label.text.get_slice("\n", 0))
|
||||
await _key(KEY_E)
|
||||
_check(await _wait(func() -> bool: return sim.shed_panel.is_open, 4.0), "E there opens the shed's menu")
|
||||
await _wait(func() -> bool: return false, 0.5)
|
||||
await _key(KEY_E)
|
||||
_check(await _wait(func() -> bool: return not sim.shed_panel.is_open, 4.0), "E again closes it")
|
||||
var way := Vector3(1.0, 0.0, 1.0).normalized()
|
||||
var d := 6.0
|
||||
sim.player.global_position = counter.global_position + way * d
|
||||
await _wait(func() -> bool: return false, 1.0)
|
||||
var pressed := false
|
||||
while d > 1.2: # 5 m/s, as the scarecrow runs; E at 2.1 m (the reach is 2.2)
|
||||
await physics_frame
|
||||
d = maxf(d - 5.0 / 60.0, 1.2)
|
||||
sim.player.global_position = counter.global_position + way * d
|
||||
if not pressed and d <= 2.1:
|
||||
pressed = true
|
||||
Input.parse_input_event(_key_event(KEY_E, true))
|
||||
await _wait(func() -> bool: return false, 0.05)
|
||||
Input.parse_input_event(_key_event(KEY_E, false))
|
||||
_check(await _wait(func() -> bool: return sim.shed_panel.is_open, 4.0), "E on arrival, still walking in at run speed, opens it too")
|
||||
await _wait(func() -> bool: return false, 0.5)
|
||||
await _key(KEY_E)
|
||||
_check(await _wait(func() -> bool: return not sim.shed_panel.is_open, 4.0), "(and E closes it)")
|
||||
await _wait(func() -> bool: return false, 1.0)
|
||||
|
||||
|
||||
## A key pressed and let go (input events, through the GUI and every _unhandled_input, as a
|
||||
## player's keyboard sends them).
|
||||
func _key(physical: Key) -> void:
|
||||
for down in [true, false]:
|
||||
Input.parse_input_event(_key_event(physical, down))
|
||||
await _wait(func() -> bool: return false, 0.12)
|
||||
|
||||
|
||||
static func _key_event(physical: Key, down: bool) -> InputEventKey:
|
||||
var e := InputEventKey.new()
|
||||
e.physical_keycode = physical
|
||||
e.pressed = down
|
||||
return e
|
||||
|
||||
|
||||
func _screenshot() -> void:
|
||||
if shot == "":
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue