Merge task #22: the joining player can open the store
The client now shows the "[E / X] Shop" prompt (ShedCounter resolved in
_focus_node); the host holds a partner's interact press up to 0.3 s for
its lagging copy to reach a counter instead of silently dropping it;
interact closes the partner's menu; a partner's purchase equips on its
own slot ("bought" event). PROTOCOL 5.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
02b990d362
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