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
25
game/COOP.md
25
game/COOP.md
|
|
@ -59,6 +59,10 @@ a knock alone doesn't open it) and stays open for 0.4 s after you stop. Talking
|
||||||
distance.
|
distance.
|
||||||
- **Shared:** the shed, upgrades, structures, and the vacation itself. Either player can gather,
|
- **Shared:** the shed, upgrades, structures, and the vacation itself. Either player can gather,
|
||||||
build, repair, buy upgrades, and start the day.
|
build, repair, buy upgrades, and start the day.
|
||||||
|
- **Shops open on your own screen.** By day, walk up to the Supply Shed's counter (or the work
|
||||||
|
area's bench, once you have it) until "[E / X] Shop" (or "Upgrades") shows, and press E / X.
|
||||||
|
- E / X again, Escape / B, walking off, or nightfall closes it.
|
||||||
|
- A weapon you buy goes into your hand.
|
||||||
- **Your pouch is your own.** The materials HUD shows yours.
|
- **Your pouch is your own.** The materials HUD shows yours.
|
||||||
- What you gather goes into your pouch.
|
- What you gather goes into your pouch.
|
||||||
- Only you walking into the Supply Shed banks it: your friend standing there doesn't.
|
- Only you walking into the Supply Shed banks it: your friend standing there doesn't.
|
||||||
|
|
@ -104,6 +108,18 @@ it acts.
|
||||||
Messages that may be lost (snapshots, input) stay under 1,100 bytes. GD-Sync splits datagrams at
|
Messages that may be lost (snapshots, input) stay under 1,100 bytes. GD-Sync splits datagrams at
|
||||||
1,200. Nothing depends on any one of them arriving, and removals are reliable.
|
1,200. Nothing depends on any one of them arriving, and removals are reliable.
|
||||||
|
|
||||||
|
The partner's shops:
|
||||||
|
- **Opening.** The host's copy of the partner's scarecrow trails the partner's own by a few
|
||||||
|
ticks: the input goes out 20 times a second, and the copy eases toward it. So the partner's
|
||||||
|
press of interact waits on the host for up to 0.3 s for that copy to reach a shop's counter,
|
||||||
|
instead of being lost when it was made on arrival. The host then tells the partner's game to
|
||||||
|
open that shop's menu.
|
||||||
|
- **Closing.** Interact again closes the menu on the partner's machine, and that press is never
|
||||||
|
sent.
|
||||||
|
- **Buying.** A purchase goes to the host, which pays it from the partner's pouch and the shed.
|
||||||
|
The partner's game then counts it as bought there, as in solo: a new weapon goes into the
|
||||||
|
partner's hand.
|
||||||
|
|
||||||
### Data use (GD-Sync's allowance)
|
### Data use (GD-Sync's allowance)
|
||||||
|
|
||||||
Online, every byte goes through GD-Sync's servers, and plans are sold by data transfer (the free
|
Online, every byte goes through GD-Sync's servers, and plans are sold by data transfer (the free
|
||||||
|
|
@ -141,12 +157,17 @@ message on both sides.
|
||||||
the partner moving, gathering, and shooting (and its pick of weapon), each player's own pouch
|
the partner moving, gathering, and shooting (and its pick of weapon), each player's own pouch
|
||||||
(gathering, the shed, paying, the shared capacity, goop to the killer, leaving), the host's stabs and
|
(gathering, the shed, paying, the shared capacity, goop to the killer, leaving), the host's stabs and
|
||||||
pumpkin bombs drawn on the partner's farm (harmless there), enemies, loot, and shots arriving, the fall rule
|
pumpkin bombs drawn on the partner's farm (harmless there), enemies, loot, and shots arriving, the fall rule
|
||||||
and Retry, a crowd with dropped packets, message sizes, and either side leaving.
|
and Retry, a crowd with dropped packets, message sizes, and either side leaving. It also covers
|
||||||
|
the partner's shops: the prompt, either shop's menu opening on the partner's farm only and
|
||||||
|
closing on interact, a press the host gets before its copy of the partner is at the counter,
|
||||||
|
and a weapon bought into P2's hand.
|
||||||
- **`game/tools/coop_smoke.gd`** plays a real GD-Sync LAN game between two processes on one
|
- **`game/tools/coop_smoke.gd`** plays a real GD-Sync LAN game between two processes on one
|
||||||
machine. The partner joins by address, since broadcasts don't loop back on every machine;
|
machine. The partner joins by address, since broadcasts don't loop back on every machine;
|
||||||
`--discover` uses the network announcements instead. `--online` plays through GD-Sync's
|
`--discover` uses the network announcements instead. `--online` plays through GD-Sync's
|
||||||
servers (needs the keys): the partner finds the host's lobby in the online list. Give both
|
servers (needs the keys): the partner finds the host's lobby in the online list. Give both
|
||||||
sides the same `--host-name`, so an old lobby from an earlier run isn't picked by mistake.
|
sides the same `--host-name`, so an old lobby from an earlier run isn't picked by mistake. By
|
||||||
|
day the partner opens and closes the Supply Shed's menu with the E key: standing at the
|
||||||
|
counter, then pressing on arrival at a run.
|
||||||
- **`game/tools/net_budget.gd`** measures the traffic for the GD-Sync data allowance: it plays
|
- **`game/tools/net_budget.gd`** measures the traffic for the GD-Sync data allowance: it plays
|
||||||
whole days and nights over a loopback link that packs every message the way GD-Sync does
|
whole days and nights over a loopback link that packs every message the way GD-Sync does
|
||||||
online, and reports what each side sends to the server, by message kind and by phase, plus
|
online, and reports what each side sends to the server, by message kind and by phase, plus
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@ extends Node
|
||||||
## refused (reliable) the partner's game speaks another PROTOCOL
|
## refused (reliable) the partner's game speaks another PROTOCOL
|
||||||
## batch (reliable, each tick with news) events in order: phase changes (with the state),
|
## batch (reliable, each tick with news) events in order: phase changes (with the state),
|
||||||
## the end of the campaign, sounds, toasts for the partner, loot and arrival news,
|
## the end of the campaign, sounds, toasts for the partner, loot and arrival news,
|
||||||
## breaches, fear bursts, gather popups, the workbench; enemies removed
|
## breaches, fear bursts, gather popups, opening a shop's menu (the workbench's, the
|
||||||
|
## shed's), a purchase the partner made (bought: the slot and the upgrade id, so a
|
||||||
|
## new weapon goes into its hand); enemies removed
|
||||||
## state (reliable, at most STATE_HZ, when it changed) the farm state (the phase clock
|
## state (reliable, at most STATE_HZ, when it changed) the farm state (the phase clock
|
||||||
## alone isn't a change: it is in every snapshot)
|
## alone isn't a change: it is in every snapshot)
|
||||||
## loot (reliable, at most LOOT_HZ, when it changed) every item
|
## loot (reliable, at most LOOT_HZ, when it changed) every item
|
||||||
|
|
@ -22,7 +24,8 @@ extends Node
|
||||||
## hello (reliable) its player's name and PROTOCOL
|
## hello (reliable) its player's name and PROTOCOL
|
||||||
## input (unreliable, up to INPUT_HZ when it changed, else every INPUT_KEEPALIVE) its
|
## input (unreliable, up to INPUT_HZ when it changed, else every INPUT_KEEPALIVE) its
|
||||||
## scarecrow's position and facing, held buttons and press counts, aim, build mode,
|
## scarecrow's position and facing, held buttons and press counts, aim, build mode,
|
||||||
## the upgrade menu (RemoteControls, packed bytes)
|
## whether a shop's menu is up (RemoteControls, packed bytes). A press of interact
|
||||||
|
## that closes the partner's own menu stays on its machine (Sender.take_back)
|
||||||
## req (reliable) start the day, start the night early, retry the night, build,
|
## req (reliable) start the day, start the night early, retry the night, build,
|
||||||
## dismantle, buy an upgrade
|
## dismantle, buy an upgrade
|
||||||
## Unreliable messages stay under CoopLink.UNRELIABLE_LIMIT; nothing depends on any single one
|
## Unreliable messages stay under CoopLink.UNRELIABLE_LIMIT; nothing depends on any single one
|
||||||
|
|
@ -45,8 +48,10 @@ signal welcomed
|
||||||
## The wire format: both machines must speak the same one (hello and welcome carry it). 3: #10
|
## The wire format: both machines must speak the same one (hello and welcome carry it). 3: #10
|
||||||
## added a time field and two int32s (the upgrade target/progress) to _put_avatar/_read_avatar's
|
## added a time field and two int32s (the upgrade target/progress) to _put_avatar/_read_avatar's
|
||||||
## per-avatar snapshot record. 4: #16 gave each scarecrow its own pouch (the farm state's
|
## per-avatar snapshot record. 4: #16 gave each scarecrow its own pouch (the farm state's
|
||||||
## resources.partner_pouch, FarmState.VERSION 7).
|
## resources.partner_pouch, FarmState.VERSION 7). 5: #22's partner shops: the "bought" event, the
|
||||||
const PROTOCOL := 4
|
## shed's counter as a snapshot's focus, and the partner's press of interact that closes its own
|
||||||
|
## menu no longer sent (the host keeps a press pending until P2's copy is in reach).
|
||||||
|
const PROTOCOL := 5
|
||||||
const SNAP_EVERY := 4 # physics ticks: 15 Hz
|
const SNAP_EVERY := 4 # physics ticks: 15 Hz
|
||||||
const INPUT_EVERY := 3 # 20 Hz, when it changed
|
const INPUT_EVERY := 3 # 20 Hz, when it changed
|
||||||
## Seconds: the partner's input goes out at least this often, changed or not.
|
## Seconds: the partner's input goes out at least this often, changed or not.
|
||||||
|
|
@ -106,6 +111,8 @@ var _input_age: float = 0.0
|
||||||
var _snap_tick: int = -1
|
var _snap_tick: int = -1
|
||||||
var _structures_json := ""
|
var _structures_json := ""
|
||||||
var _shed_json := ""
|
var _shed_json := ""
|
||||||
|
## Upgrade ids the host bought for this machine's scarecrow, until this farm's state has them.
|
||||||
|
var _bought: Array[String] = []
|
||||||
var _is_welcomed := false
|
var _is_welcomed := false
|
||||||
var _welcome_sent := false
|
var _welcome_sent := false
|
||||||
var _hello_wait: float = 0.0
|
var _hello_wait: float = 0.0
|
||||||
|
|
@ -555,8 +562,11 @@ func _do_request(r: Array) -> void:
|
||||||
if Upgrades.shop_of(c.config, id) == "workbench" and (sim.structures == null or not sim.structures.workbench_available()):
|
if Upgrades.shop_of(c.config, id) == "workbench" and (sim.structures == null or not sim.structures.workbench_available()):
|
||||||
_events.append(["toast", "The work area isn't available", Color(1.0, 0.8, 0.5)])
|
_events.append(["toast", "The work area isn't available", Color(1.0, 0.8, 0.5)])
|
||||||
return
|
return
|
||||||
|
var was := Upgrades.owned(c.state, id)
|
||||||
var text := Upgrades.buy(c, id, sim.structures, a.slot) # paid from P2's pouch, then the shed
|
var text := Upgrades.buy(c, id, sim.structures, a.slot) # paid from P2's pouch, then the shed
|
||||||
_events.append(["toast", text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5)])
|
_events.append(["toast", text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5)])
|
||||||
|
if not was and Upgrades.owned(c.state, id):
|
||||||
|
_events.append(["bought", a.slot, id]) # the buyer's game: a new weapon into its hand
|
||||||
|
|
||||||
|
|
||||||
## Co-op is on for the farm state (after a retry, a new vacation, or a morning).
|
## Co-op is on for the farm state (after a retry, a new vacation, or a morning).
|
||||||
|
|
@ -646,6 +656,19 @@ func _apply_state(d: Dictionary, everything: bool = false) -> void:
|
||||||
sim.shed_panel.refresh()
|
sim.shed_panel.refresh()
|
||||||
if c.state.phase == CampaignController.Phase.MORNING and sim.review_panel != null:
|
if c.state.phase == CampaignController.Phase.MORNING and sim.review_panel != null:
|
||||||
sim.review_panel.refresh()
|
sim.review_panel.refresh()
|
||||||
|
_settle_bought()
|
||||||
|
|
||||||
|
|
||||||
|
## The purchases the host made for this machine's scarecrow that this farm's state has by now
|
||||||
|
## count as bought here (UpgradePanel.confirm_bought: a new weapon goes into its hand). The
|
||||||
|
## "bought" news can come before the farm state that has the upgrade.
|
||||||
|
func _settle_bought() -> void:
|
||||||
|
for id in _bought.duplicate():
|
||||||
|
if Upgrades.owned(sim.campaign.state, id):
|
||||||
|
_bought.erase(id)
|
||||||
|
var panel := sim.shed_panel if Upgrades.shop_of(sim.config, id) == "shed" else sim.upgrade_panel
|
||||||
|
if panel != null:
|
||||||
|
panel.confirm_bought(id)
|
||||||
|
|
||||||
|
|
||||||
func _apply_event(e: Array) -> void:
|
func _apply_event(e: Array) -> void:
|
||||||
|
|
@ -705,6 +728,10 @@ func _apply_event(e: Array) -> void:
|
||||||
"shed":
|
"shed":
|
||||||
if sim.shed_panel != null and c.is_daytime():
|
if sim.shed_panel != null and c.is_daytime():
|
||||||
sim.shed_panel.open()
|
sim.shed_panel.open()
|
||||||
|
"bought":
|
||||||
|
if int(e[1]) == sim.local_avatar.slot:
|
||||||
|
_bought.append(String(e[2]))
|
||||||
|
_settle_bought()
|
||||||
|
|
||||||
|
|
||||||
func _apply_snap(data: PackedByteArray) -> void:
|
func _apply_snap(data: PackedByteArray) -> void:
|
||||||
|
|
@ -794,8 +821,8 @@ func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
|
||||||
elif ch == "" and body.rooted and not sim._menu_open():
|
elif ch == "" and body.rooted and not sim._menu_open():
|
||||||
body.stop_channel()
|
body.stop_channel()
|
||||||
var it := a.interactions
|
var it := a.interactions
|
||||||
it.focus = _gather_node(String(rec["fo"]))
|
it.focus = _focus_node(String(rec["fo"]))
|
||||||
it.gathering = _gather_node(String(rec["ga"])) as GatherNode
|
it.gathering = _focus_node(String(rec["ga"])) as GatherNode
|
||||||
it.gather_elapsed = float(rec["ge"])
|
it.gather_elapsed = float(rec["ge"])
|
||||||
it.repair_target = int(rec["rt"])
|
it.repair_target = int(rec["rt"])
|
||||||
it.repairing = int(rec["rp"])
|
it.repairing = int(rec["rp"])
|
||||||
|
|
@ -805,12 +832,17 @@ func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
|
||||||
it.upgrade_elapsed = float(rec["ue"])
|
it.upgrade_elapsed = float(rec["ue"])
|
||||||
|
|
||||||
|
|
||||||
func _gather_node(node_name: String) -> Node3D:
|
## What a snapshot names as P2's focus (or gathering point) on this farm: a gather point, the
|
||||||
|
## workbench, or the shed's counter, so the local labels show the prompt the host's hands have
|
||||||
|
## (Interactions._process: "[E / X] Shop" at the counter, #22).
|
||||||
|
func _focus_node(node_name: String) -> Node3D:
|
||||||
if node_name == "":
|
if node_name == "":
|
||||||
return null
|
return null
|
||||||
var it := sim.interactions
|
var it := sim.interactions
|
||||||
if it.workbench != null and String(it.workbench.name) == node_name:
|
if it.workbench != null and String(it.workbench.name) == node_name:
|
||||||
return it.workbench
|
return it.workbench
|
||||||
|
if it.shed_counter != null and String(it.shed_counter.name) == node_name:
|
||||||
|
return it.shed_counter
|
||||||
for n in it.nodes:
|
for n in it.nodes:
|
||||||
if String(n.name) == node_name:
|
if String(n.name) == node_name:
|
||||||
return n
|
return n
|
||||||
|
|
@ -908,6 +940,8 @@ func _reset_world() -> void:
|
||||||
## replaced soon; standing still sends little).
|
## replaced soon; standing still sends little).
|
||||||
func _send_input() -> void:
|
func _send_input() -> void:
|
||||||
var a := sim.local_avatar
|
var a := sim.local_avatar
|
||||||
|
if sim._menu_open() and _sender.take_back(&"interact") > 0:
|
||||||
|
_close_menus() # interact again closes it, as in solo; that press never reaches the host
|
||||||
var ui := sim._menu_open()
|
var ui := sim._menu_open()
|
||||||
var rec := _sender.record(a.combat, a.body, sim.build.active, ui, sim.local_frozen)
|
var rec := _sender.record(a.combat, a.body, sim.build.active, ui, sim.local_frozen)
|
||||||
if rec != _last_input or _input_age >= INPUT_KEEPALIVE - 0.001: # (sums of 1/60 fall a hair short)
|
if rec != _last_input or _input_age >= INPUT_KEEPALIVE - 0.001: # (sums of 1/60 fall a hair short)
|
||||||
|
|
@ -922,13 +956,19 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||||
_sender.note(event)
|
_sender.note(event)
|
||||||
|
|
||||||
|
|
||||||
## Either shop's menu closes here on the same rules as solo (Interactions): walking off its
|
## Either shop's menu closes here on the same rules as solo (Interactions): interact again (in
|
||||||
## counter's reach, nightfall, build mode.
|
## _send_input), walking off its counter's reach, nightfall, build mode.
|
||||||
func _close_menu_if_needed() -> void:
|
func _close_menu_if_needed() -> void:
|
||||||
_close_menu(sim.upgrade_panel, sim.interactions.workbench)
|
_close_menu(sim.upgrade_panel, sim.interactions.workbench)
|
||||||
_close_menu(sim.shed_panel, sim.interactions.shed_counter)
|
_close_menu(sim.shed_panel, sim.interactions.shed_counter)
|
||||||
|
|
||||||
|
|
||||||
|
func _close_menus() -> void:
|
||||||
|
for panel: UpgradePanel in [sim.upgrade_panel, sim.shed_panel]:
|
||||||
|
if panel != null:
|
||||||
|
panel.close()
|
||||||
|
|
||||||
|
|
||||||
## counter: Workbench or ShedCounter (both just need global_position and reach).
|
## counter: Workbench or ShedCounter (both just need global_position and reach).
|
||||||
func _close_menu(panel: UpgradePanel, counter) -> void:
|
func _close_menu(panel: UpgradePanel, counter) -> void:
|
||||||
if panel == null or not panel.is_open:
|
if panel == null or not panel.is_open:
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,10 @@ extends Node3D
|
||||||
## RemoteControls (remote), asks the partner's game to open its own upgrade menu
|
## RemoteControls (remote), asks the partner's game to open its own upgrade menu
|
||||||
## (workbench_requested / shed_requested), and leaves the gather labels to the local player's
|
## (workbench_requested / shed_requested), and leaves the gather labels to the local player's
|
||||||
## (show_labels). Each one gathers into, deposits, and pays from its own scarecrow's pouch
|
## (show_labels). Each one gathers into, deposits, and pays from its own scarecrow's pouch
|
||||||
## (kit.slot, ResourceStore): a partner standing in the shed banks only their own pouch.
|
## (kit.slot, ResourceStore): a partner standing in the shed banks only their own pouch. The
|
||||||
|
## host's copy of the partner trails the partner's own machine by a few ticks, so a press of
|
||||||
|
## interact made on arrival at a shop's counter can reach the host while the copy is still out of
|
||||||
|
## reach: it stays pending for PRESS_WINDOW seconds, until a counter in reach takes it (#22).
|
||||||
|
|
||||||
signal gathered(material: String, amount: int, node: GatherNode)
|
signal gathered(material: String, amount: int, node: GatherNode)
|
||||||
signal deposited(moved: Dictionary)
|
signal deposited(moved: Dictionary)
|
||||||
|
|
@ -46,6 +49,8 @@ const LABEL_RANGE := 7.0
|
||||||
const REPAIR_REACH := 1.4
|
const REPAIR_REACH := 1.4
|
||||||
const POPUP_TIME := 1.1
|
const POPUP_TIME := 1.1
|
||||||
const POPUPS := 6
|
const POPUPS := 6
|
||||||
|
## Seconds a partner's press of interact waits (on the host) for its copy to reach a counter.
|
||||||
|
const PRESS_WINDOW := 0.3
|
||||||
|
|
||||||
var config: GameConfig
|
var config: GameConfig
|
||||||
var campaign: CampaignController
|
var campaign: CampaignController
|
||||||
|
|
@ -78,6 +83,8 @@ var upgrade_elapsed: float = 0.0
|
||||||
var _shed: FarmZone
|
var _shed: FarmZone
|
||||||
var _interact_requested := false
|
var _interact_requested := false
|
||||||
var _interact_was_held := false
|
var _interact_was_held := false
|
||||||
|
## Co-op: what's left of the partner's pending press (seconds; 0 = none).
|
||||||
|
var _press_left: float = 0.0
|
||||||
var _denied := false
|
var _denied := false
|
||||||
var _popups: Array[Label3D] = []
|
var _popups: Array[Label3D] = []
|
||||||
var _repair_label: Label3D
|
var _repair_label: Label3D
|
||||||
|
|
@ -158,7 +165,7 @@ func step(dt: float) -> void:
|
||||||
var held := remote.held(&"interact") if remote != null else Input.is_action_pressed("interact")
|
var held := remote.held(&"interact") if remote != null else Input.is_action_pressed("interact")
|
||||||
var pressed := _interact_requested or (held and not _interact_was_held)
|
var pressed := _interact_requested or (held and not _interact_was_held)
|
||||||
if remote != null:
|
if remote != null:
|
||||||
pressed = remote.take(&"interact")
|
pressed = _remote_press(dt)
|
||||||
_interact_requested = false
|
_interact_requested = false
|
||||||
_interact_was_held = held
|
_interact_was_held = held
|
||||||
if not held:
|
if not held:
|
||||||
|
|
@ -172,6 +179,7 @@ func step(dt: float) -> void:
|
||||||
repair_target = -1
|
repair_target = -1
|
||||||
upgrade_target = -1
|
upgrade_target = -1
|
||||||
focus = null
|
focus = null
|
||||||
|
_press_left = 0.0
|
||||||
return
|
return
|
||||||
var p := Vector2(player.global_position.x, player.global_position.z)
|
var p := Vector2(player.global_position.x, player.global_position.z)
|
||||||
if upgrade_panel != null and upgrade_panel.is_open:
|
if upgrade_panel != null and upgrade_panel.is_open:
|
||||||
|
|
@ -261,6 +269,7 @@ func step(dt: float) -> void:
|
||||||
_denied = true
|
_denied = true
|
||||||
message.emit(why, Color(1.0, 0.8, 0.5))
|
message.emit(why, Color(1.0, 0.8, 0.5))
|
||||||
elif focus is Workbench and pressed:
|
elif focus is Workbench and pressed:
|
||||||
|
_press_left = 0.0
|
||||||
if structures != null and structures.is_broken(structures.workbench_id()):
|
if structures != null and structures.is_broken(structures.workbench_id()):
|
||||||
message.emit("Broken -- repair it", Color(1.0, 0.8, 0.5))
|
message.emit("Broken -- repair it", Color(1.0, 0.8, 0.5))
|
||||||
elif not campaign.is_daytime():
|
elif not campaign.is_daytime():
|
||||||
|
|
@ -270,6 +279,7 @@ func step(dt: float) -> void:
|
||||||
elif remote != null:
|
elif remote != null:
|
||||||
workbench_requested.emit()
|
workbench_requested.emit()
|
||||||
elif focus is ShedCounter and pressed:
|
elif focus is ShedCounter and pressed:
|
||||||
|
_press_left = 0.0
|
||||||
if not campaign.is_daytime():
|
if not campaign.is_daytime():
|
||||||
message.emit("The supply shed is for daytime", Color(1.0, 0.8, 0.5))
|
message.emit("The supply shed is for daytime", Color(1.0, 0.8, 0.5))
|
||||||
elif shed_panel != null:
|
elif shed_panel != null:
|
||||||
|
|
@ -286,6 +296,18 @@ func _step_menu(panel: UpgradePanel, counter, p: Vector2, pressed: bool) -> void
|
||||||
var reach: float = counter.reach if counter != null else 0.0
|
var reach: float = counter.reach if counter != null else 0.0
|
||||||
if pressed or not campaign.is_daytime() or at.distance_to(p) > reach + 0.5 or (build != null and build.active):
|
if pressed or not campaign.is_daytime() or at.distance_to(p) > reach + 0.5 or (build != null and build.active):
|
||||||
panel.close()
|
panel.close()
|
||||||
|
_press_left = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
## Co-op, the partner's hands on the host: whether a press of interact is pending. A new one
|
||||||
|
## (RemoteControls.take) waits up to PRESS_WINDOW seconds for a counter in reach to take it
|
||||||
|
## (which clears _press_left), instead of being dropped on the tick it arrives.
|
||||||
|
func _remote_press(dt: float) -> bool:
|
||||||
|
if remote.take(&"interact"):
|
||||||
|
_press_left = PRESS_WINDOW
|
||||||
|
else:
|
||||||
|
_press_left = maxf(_press_left - dt, 0.0)
|
||||||
|
return _press_left > 0.0
|
||||||
|
|
||||||
|
|
||||||
## Why a point can't be gathered right now ("" if it can).
|
## Why a point can't be gathered right now ("" if it can).
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ func release() -> void:
|
||||||
class Sender:
|
class Sender:
|
||||||
var presses := RemoteControls.counts()
|
var presses := RemoteControls.counts()
|
||||||
var _was := 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).
|
## Counts presses from input events (taps between two frames still count).
|
||||||
func note(event: InputEvent) -> void:
|
func note(event: InputEvent) -> void:
|
||||||
|
|
@ -97,17 +99,26 @@ class Sender:
|
||||||
presses[i] += 1
|
presses[i] += 1
|
||||||
_was[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
|
## The input record (RemoteControls.apply): the actions held now (none while frozen: a menu
|
||||||
## is up), every press so far, and the scarecrow.
|
## is up), every press so far, and the scarecrow.
|
||||||
func record(combat: ScarecrowCombat, body: PlayerCharacter, build: bool, ui: bool, frozen: bool) -> PackedByteArray:
|
func record(combat: ScarecrowCombat, body: PlayerCharacter, build: bool, ui: bool, frozen: bool) -> PackedByteArray:
|
||||||
var bits := 0
|
var bits := 0
|
||||||
for i in RemoteControls.ACTIONS.size():
|
for i in RemoteControls.ACTIONS.size():
|
||||||
var down := Input.is_action_pressed(RemoteControls.ACTIONS[i])
|
if _sample(i):
|
||||||
if down:
|
|
||||||
bits |= 1 << i
|
bits |= 1 << i
|
||||||
if _was[i] == 0: # pressed without an event (simulated input)
|
_recorded = presses.duplicate()
|
||||||
presses[i] += 1
|
|
||||||
_was[i] = 1 if down else 0
|
|
||||||
var b := StreamPeerBuffer.new()
|
var b := StreamPeerBuffer.new()
|
||||||
b.put_u8(0 if frozen else bits)
|
b.put_u8(0 if frozen else bits)
|
||||||
for i in RemoteControls.ACTIONS.size():
|
for i in RemoteControls.ACTIONS.size():
|
||||||
|
|
@ -123,3 +134,11 @@ class Sender:
|
||||||
CoopLink.put_angle(b, body.model.rotation.y)
|
CoopLink.put_angle(b, body.model.rotation.y)
|
||||||
b.put_u8(clampi(roundi(body.move_strength() * 100.0), 0, 255))
|
b.put_u8(clampi(roundi(body.move_strength() * 100.0), 0, 255))
|
||||||
return b.data_array
|
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
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ var player: PlayerCharacter
|
||||||
var is_open := false
|
var is_open := false
|
||||||
## Which shop this instance lists ("workbench" or "shed"); set by setup().
|
## Which shop this instance lists ("workbench" or "shed"); set by setup().
|
||||||
var shop := "workbench"
|
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
|
var buy_request: Callable
|
||||||
## The avatar slot of this machine's scarecrow (FarmSim.set_local): what's affordable is its own
|
## The avatar slot of this machine's scarecrow (FarmSim.set_local): what's affordable is its own
|
||||||
## pouch plus the shed.
|
## pouch plus the shed.
|
||||||
|
|
@ -144,6 +145,19 @@ func _buy(id: String) -> void:
|
||||||
if not was and Upgrades.owned(campaign.state, id):
|
if not was and Upgrades.owned(campaign.state, id):
|
||||||
bought.emit(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))
|
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()
|
refresh()
|
||||||
if (_rows[id] as Button).has_focus() and (_rows[id] as Button).disabled:
|
if (_rows[id] as Button).has_focus() and (_rows[id] as Button).disabled:
|
||||||
_close.grab_focus()
|
_close.grab_focus()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ extends RefCounted
|
||||||
## co-op health), requests from the partner (start the day, build, buy), the partner's scarecrow
|
## co-op health), requests from the partner (start the day, build, buy), the partner's scarecrow
|
||||||
## moving, gathering, and shooting on the host (and its pick of weapon), each scarecrow's own
|
## moving, gathering, and shooting on the host (and its pick of weapon), each scarecrow's own
|
||||||
## pouch (#16: gathering, the shed drop-off, paying, one shared capacity, goop to the killer, and
|
## pouch (#16: gathering, the shed drop-off, paying, one shared capacity, goop to the killer, and
|
||||||
## the partner's pouch put in the shed when they leave), the weapons' stabs and
|
## the partner's pouch put in the shed when they leave), the partner's shops (#22: the prompt, the
|
||||||
|
## menus opening on the partner's farm and closing on interact, a press that beats the host's copy
|
||||||
|
## of P2 to the counter, a weapon bought into P2's hand), the weapons' stabs and
|
||||||
## pumpkin bombs (thrown from the off-hand, not with the right click leaving build mode) reaching the replica (drawn there, doing no damage of their own), enemies, loot,
|
## pumpkin bombs (thrown from the off-hand, not with the right click leaving build mode) reaching the replica (drawn there, doing no damage of their own), enemies, loot,
|
||||||
## and shots reaching the replica,
|
## and shots reaching the replica,
|
||||||
## the co-op fall rule (one down is out until morning, both down is Game Over) and Retry, message
|
## the co-op fall rule (one down is out until morning, both down is Game Over) and Retry, message
|
||||||
|
|
@ -38,6 +40,7 @@ func run(p_r: GameTestRunner) -> void:
|
||||||
_quiet_wire()
|
_quiet_wire()
|
||||||
await _partner_moves_and_gathers()
|
await _partner_moves_and_gathers()
|
||||||
_own_pouches()
|
_own_pouches()
|
||||||
|
_shops()
|
||||||
_night()
|
_night()
|
||||||
_partner_shoots()
|
_partner_shoots()
|
||||||
_goop_to_killer()
|
_goop_to_killer()
|
||||||
|
|
@ -291,6 +294,112 @@ func _own_pouches() -> void:
|
||||||
_pump(6)
|
_pump(6)
|
||||||
|
|
||||||
|
|
||||||
|
## #22: the partner's shops. P2 at the supply shed's counter by day sees its prompt, and interact
|
||||||
|
## opens the shed's menu on the partner's farm (the host asks for it), never on the host's; the
|
||||||
|
## host sees P2's menu up. Interact again closes it. A press that reaches the host while its copy
|
||||||
|
## of P2 is still walking up to the counter there isn't lost: it opens the menu once P2 is in reach
|
||||||
|
## (but a press long before doesn't open it later). The same at the work area's bench. A weapon
|
||||||
|
## P2 buys at the shed is paid from P2's pouch and the shed, and goes into P2's hand on both farms.
|
||||||
|
func _shops() -> void:
|
||||||
|
var res := host.campaign.state.resources
|
||||||
|
var counter := client.interactions.shed_counter
|
||||||
|
var bench := client.interactions.workbench
|
||||||
|
r.check(host.campaign.is_daytime() and counter != null and bench != null and host.structures.has_workbench(),
|
||||||
|
"(by day, with the shed's counter and the granted work area on both farms)")
|
||||||
|
host.player.global_position = AWAY
|
||||||
|
var at_counter := counter.global_position + Vector3(0.0, 0.0, 1.2)
|
||||||
|
client.player.global_position = at_counter
|
||||||
|
_pump(20)
|
||||||
|
client.interactions._process(0.0)
|
||||||
|
r.check(host.partner.interactions.focus is ShedCounter and client.interactions.focus == counter and counter._label.visible
|
||||||
|
and counter._label.text.begins_with("[E / X] Shop"),
|
||||||
|
"the partner at the shed's counter sees its prompt ('%s')" % counter._label.text.get_slice("\n", 0))
|
||||||
|
_tap_interact()
|
||||||
|
r.check(client.shed_panel.is_open and not host.shed_panel.is_open and host.partner.remote.ui_open,
|
||||||
|
"interact there opens the shed's menu on the partner's farm, not the host's (the host sees P2's menu up)")
|
||||||
|
_tap_interact()
|
||||||
|
r.check(not client.shed_panel.is_open and not host.partner.remote.ui_open and not host.shed_panel.is_open,
|
||||||
|
"interact again closes it on the partner's farm (and the press doesn't open it again)")
|
||||||
|
# Lag: the press reaches the host along with P2's arrival at the counter, while the host's copy
|
||||||
|
# of P2 is still on its way there (out of reach for a few ticks).
|
||||||
|
var off := counter.global_position + Vector3(0.0, 0.0, 4.5)
|
||||||
|
client.player.global_position = off
|
||||||
|
_pump(20)
|
||||||
|
client.player.global_position = at_counter
|
||||||
|
var taken: int = host.partner.remote._seen[3] # (interact)
|
||||||
|
var taken_at := -1.0 # how far the host's copy of P2 was from the counter when it took the press
|
||||||
|
Input.action_press("interact")
|
||||||
|
for i in 8:
|
||||||
|
_pump() # (the copy moves, then the host's hands take the press)
|
||||||
|
if taken_at < 0.0 and host.partner.remote._seen[3] != taken:
|
||||||
|
var hp := host.partner.body.global_position
|
||||||
|
taken_at = Vector2(hp.x - counter.global_position.x, hp.z - counter.global_position.z).length()
|
||||||
|
Input.action_release("interact")
|
||||||
|
_pump(20)
|
||||||
|
r.check(taken_at > counter.reach and client.shed_panel.is_open and host.partner.remote.ui_open,
|
||||||
|
"a press the host takes while its copy of P2 is still %.1f m from the counter opens the menu once the copy is in reach" % taken_at)
|
||||||
|
client.shed_panel.close()
|
||||||
|
_pump(10)
|
||||||
|
client.player.global_position = off
|
||||||
|
_pump(20)
|
||||||
|
_tap_interact() # well out of reach: nothing to open
|
||||||
|
_pump(30)
|
||||||
|
client.player.global_position = at_counter
|
||||||
|
_pump(30)
|
||||||
|
r.check(not client.shed_panel.is_open and not host.partner.remote.ui_open,
|
||||||
|
"but a press long before P2 got there doesn't open it later")
|
||||||
|
# The work area's bench.
|
||||||
|
var at_bench := bench.global_position + (bench.global_position - host.zones.zone(FarmZone.Kind.WORK_AREA).global_position).normalized() * 1.2
|
||||||
|
client.player.global_position = at_bench
|
||||||
|
_pump(20)
|
||||||
|
client.interactions._process(0.0)
|
||||||
|
r.check(host.partner.interactions.focus is Workbench and client.interactions.focus == bench and bench._label.text.begins_with("[E / X] Upgrades"),
|
||||||
|
"the partner at the work area's bench sees its prompt ('%s')" % bench._label.text.get_slice("\n", 0))
|
||||||
|
_tap_interact()
|
||||||
|
r.check(client.upgrade_panel.is_open and not host.upgrade_panel.is_open and host.partner.remote.ui_open,
|
||||||
|
"interact there opens the work area's menu on the partner's farm, not the host's")
|
||||||
|
_tap_interact()
|
||||||
|
r.check(not client.upgrade_panel.is_open and not host.partner.remote.ui_open, "and interact again closes it")
|
||||||
|
# Buying a weapon at the shed: P2's pouch, then the shed; into P2's hand.
|
||||||
|
var id := "shurikens"
|
||||||
|
var w := ScarecrowCombat.WEAPON_IDS.find(id)
|
||||||
|
var cost: Dictionary = host.config.costs[id]
|
||||||
|
client.player.global_position = at_counter
|
||||||
|
_pump(20)
|
||||||
|
_tap_interact()
|
||||||
|
_empty_pouches() # (P2 banked its pouch walking into the shed: fill it again with the menu up)
|
||||||
|
res.shed = {"wood": 0, "scrap": 0, "straw": 0, "alien_goop": 0}
|
||||||
|
for m: String in cost: # P2 carries all but one of each; the shed has the rest
|
||||||
|
res.pouch_of(1)[m] = int(cost[m]) - 1
|
||||||
|
res.shed[m] = 1
|
||||||
|
res.pouch_of(0)["scrap"] = 3 # P1's, kept
|
||||||
|
_pump(SETTLE)
|
||||||
|
var jingles := int(client.audio.played.get("upgrade", 0))
|
||||||
|
r.check(client.shed_panel.is_open and not (client.shed_panel._rows[id] as Button).disabled and not Upgrades.owned(host.campaign.state, id),
|
||||||
|
"the partner's shed menu offers the %s (P2's pouch and the shed can pay)" % id)
|
||||||
|
client.shed_panel._buy(id)
|
||||||
|
_pump(SETTLE * 2)
|
||||||
|
r.check(Upgrades.owned(host.campaign.state, id) and res.pouch_total(1) == 0 and res.shed_total() == 0 and int(res.pouch_of(0)["scrap"]) == 3,
|
||||||
|
"P2 buys the %s: paid from P2's pouch and the shed, P1's pouch untouched (P1 %s)" % [id, res.pouch_of(0)])
|
||||||
|
r.check(client.combat.weapon == w and host.partner.combat.weapon == w and host.combat.weapon != w,
|
||||||
|
"and it goes into P2's hand on both farms (P1's hand unchanged)")
|
||||||
|
r.check(int(client.audio.played.get("upgrade", 0)) == jingles + 1, "with the purchase's jingle on the partner's side")
|
||||||
|
client.shed_panel.close()
|
||||||
|
host.campaign.state.upgrades.erase(id)
|
||||||
|
_empty_pouches()
|
||||||
|
client.player.global_position = Vector3(0.5, 0.0, 6.0)
|
||||||
|
_pump(SETTLE)
|
||||||
|
r.check(client.combat.weapon == ScarecrowCombat.Weapon.PITCHFORK, "(back to the pitchfork)")
|
||||||
|
|
||||||
|
|
||||||
|
## The partner taps interact: held for a few ticks, then let go, and the news settles.
|
||||||
|
func _tap_interact() -> void:
|
||||||
|
Input.action_press("interact")
|
||||||
|
_pump(4)
|
||||||
|
Input.action_release("interact")
|
||||||
|
_pump(20)
|
||||||
|
|
||||||
|
|
||||||
func _night() -> void:
|
func _night() -> void:
|
||||||
host.campaign.advance_phase()
|
host.campaign.advance_phase()
|
||||||
host.campaign.advance_phase()
|
host.campaign.advance_phase()
|
||||||
|
|
|
||||||
|
|
@ -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,
|
## 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),
|
## 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,
|
## 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
|
## and both play a day and a night with enemies. By day the partner walks up to the supply shed's
|
||||||
## all checked out:
|
## 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=host &
|
||||||
## godot --headless --path . --script res://game/tools/coop_smoke.gd -- --role=join
|
## 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
|
## 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)
|
_check(true, "a partner joined: %s" % sim.coop.partner_name)
|
||||||
await _wait(func() -> bool: return false, 3.0)
|
await _wait(func() -> bool: return false, 3.0)
|
||||||
sim.campaign.begin_day()
|
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()
|
||||||
sim.campaign.advance_phase()
|
sim.campaign.advance_phase()
|
||||||
for i in 24:
|
for i in 24:
|
||||||
|
|
@ -113,6 +118,8 @@ func _run() -> void:
|
||||||
await _finish()
|
await _finish()
|
||||||
return
|
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")
|
_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)
|
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)
|
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")
|
_check(sim.campaign.state.phase == CampaignController.Phase.NIGHT, "the host's nightfall reached the partner")
|
||||||
|
|
@ -132,6 +139,56 @@ func _run() -> void:
|
||||||
_finish()
|
_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:
|
func _screenshot() -> void:
|
||||||
if shot == "":
|
if shot == "":
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue