harvest/game/tests/mobile/prompts_test.gd
Forrest 9f4a1895bd #36: prompts in touch words
Prompts (game/scripts/prompts.gd) holds every key-naming prompt: on a phone
(MobilePort.active()) it says each in touch words, elsewhere exactly the old
string. World labels drop the key (Gather, Repair, Upgrade to, Upgrades, Shop),
the build ghost says Place / Dismantle, the build bar's line is
"Place · Rotate · Dismantle · Done" and its slots drop the number keys, the
cutscenes say "Hold to skip" / "Tap to skip", the tip footer says
"× hides tips", and the tutorial's tips and the first morning's sign name the
thumbs (sides from TouchSticks), Use, Build, Place, Fear, Bomb, Patch, the
hotbar, and the backpack. MobilePort gains the `forced` test override.
game/tests/mobile/prompts_test.gd checks every phone string and that the
desktop strings are byte for byte as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 14:30:26 -04:00

206 lines
12 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends RefCounted
## #36: the prompts in touch words (Prompts). On a phone (MobilePort.forced = 1) every prompt
## that names a key says it in touch words: the world labels, the build ghost and the build bar,
## the cutscenes' skip hints, the tutorial's tips and their footer, and the first morning's sign,
## with no key, mouse, or gamepad name left and the sticks' sides filled in. The tutorial, the
## build bar, the workbench, the shed counter, and the morning sign show them. On desktop
## (forced = 0) each is byte for byte the string the game showed before #36 (copied here as
## literals from the code as it was).
## Words a touch prompt must not have: keys, mouse and gamepad buttons (a lone capital letter,
## but A and I, which are words too), sticks (touch says thumbs), sprinting (#46), and a
## {placeholder} left unfilled.
const KEY_WORDS := "\\[|\\]|\\bLMB\\b|\\bRMB\\b|\\bRT\\b|\\bLT\\b|\\bLB\\b|\\bRB\\b|\\bSpace\\b|\\bEnter\\b|Backspace|[Mm]ouse" \
+ "|\\bTab\\b|\\bkeys?\\b|d-pad|\\b[B-HJ-Z]\\b|[Ss]print|\\bShift\\b|\\bstick\\b|[Pp]ress|[Cc]lick|\\{|\\}"
var t
var tree: SceneTree
var campaign: CampaignController
func run(p_t) -> void:
t = p_t
tree = Engine.get_main_loop() as SceneTree
campaign = CampaignController.new()
tree.root.add_child(campaign)
campaign.set_physics_process(false)
MobilePort.forced = 1
_phone()
await _phone_screens()
MobilePort.forced = 0
_desktop()
await _desktop_screens()
MobilePort.forced = -1
campaign.free()
func _phone() -> void:
t.check(Prompts.touch() and MobilePort.active(), "forced to a phone, the prompts are in touch words")
var move := Prompts.move_side()
var attack := Prompts.attack_side()
t.check(move == ("right" if TouchSticks.MOVE_ON_RIGHT else "left") and attack != move and attack in ["left", "right"],
"the move stick is on the %s, the attack stick on the %s (TouchSticks)" % [move, attack])
var want := {
"gather": [Prompts.gather(), "Gather"],
"repair": [Prompts.repair("6 wood"), "Repair (6 wood)"],
"upgrade": [Prompts.upgrade_to(2, "4 scrap, 2 straw"), "Upgrade to L2 (4 scrap, 2 straw)"],
"workbench": [Prompts.upgrades(), "Upgrades"],
"shed counter": [Prompts.shop(), "Shop"],
"build ghost": [Prompts.build_place(), "Place"],
"dismantle": [Prompts.dismantle(), "Dismantle"],
"build bar": [Prompts.build_help(), "Place · Rotate · Dismantle · Done"],
"build slot": [Prompts.build_slot(1, "Fence"), "Fence"],
"intro skip": [Prompts.intro_skip(), "Hold to skip"],
"return skip": [Prompts.return_skip(), "Tap to skip"],
"tip footer": [Prompts.tip_footer(), "Tip · × hides tips"],
"tip move": [Prompts.tip("move"),
"Move with your %s thumb: touch the %s half of the screen and slide. You're the scarecrow: keep the farm safe until the farmers are back." % [move, move]],
"tip gather": [Prompts.tip("gather"), "Hold Use at a dead tree, the haystacks, or the scrap heap to gather wood, straw, and scrap."],
"tip store": [Prompts.tip("store"),
"Your pouch only holds so much (tap the backpack to see what's in it): walk onto the barn's apron (the Supply Shed) to store what you carry."],
"tip build": [Prompts.tip("build"),
"Build (by day): tap Build, pick a fence, put your %s thumb where it goes, then tap Place. Aliens have to break through fences." % attack],
"tip dusk": [Prompts.tip("dusk"), "Dusk: aliens come at nightfall, from every side of the farm."],
"tip shoot": [Prompts.tip("shoot"),
"Your %s thumb aims and attacks: slide it toward an alien to stab with your pitchfork. The supply shed sells a corn shooter (tap the hotbar to switch); more weapons arrive there over the days, like pumpkin bombs for your off-hand (Bomb throws one)." % attack],
"tip fear": [Prompts.tip("fear"), "Crowded? Tap Fear to scare off everything nearby, and they drop what they carry."],
"tip recover": [Prompts.tip("recover"), "Something was dropped! Walk over it to bring it home. A dropped animal follows you back to the pen."],
"tip patch": [Prompts.tip("patch"), "Hurt? Hold Patch to patch up with straw. Health carries over to the next night."],
"sign day": [Prompts.sign_day(),
"By day, gather wood, scrap, and straw (hold Use), store them at the barn, and build defenses (tap Build). There's more to gather off the farm, to the north, east, and south."],
"sign night": [Prompts.sign_night(),
"At night, stab aliens with your pitchfork (%s thumb), scare them off (Fear), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons on the hotbar), and more weapons arrive there over the days." % attack],
}
for k: String in want:
t.check(want[k][0] == want[k][1], "phone, %s: '%s'" % [k, want[k][0]])
var keys := RegEx.create_from_string(KEY_WORDS)
var named: Array[String] = []
for k: String in want:
var m := keys.search(want[k][0])
if m != null:
named.append("%s ('%s')" % [k, m.get_string()])
t.check(named.is_empty(), "no touch prompt names a key, a mouse or gamepad button, or sprinting %s" % [named])
var tips := 0
for id: String in Tutorial.TEXT:
tips += 1 if Prompts.tip(id) != "" else 0
t.check(tips == Tutorial.TEXT.size() and Prompts.TOUCH_TIPS.keys().all(func(id: String) -> bool: return Tutorial.TEXT.has(id)),
"every tip has its wording on phones (%d of %d), and every touch tip is a tutorial tip" % [tips, Tutorial.TEXT.size()])
var font := Sketch.font()
var fallback := font is FontFile and (font as FontFile).allow_system_fallback
t.check(font.has_char(0xD7) or fallback, "the HUD font draws the tip footer's × (has it: %s; system fallback: %s)" % [font.has_char(0xD7), fallback])
## On a phone, what the tutorial, the build bar, the workbench, the shed counter, and the first
## morning's sign show.
func _phone_screens() -> void:
var tut := Tutorial.new()
tree.root.add_child(tut)
tut._show("gather")
t.check(tut._hint.text == "Tip · × hides tips" and tut._text.text == Prompts.tip("gather") and tut._text.text.begins_with("Hold Use"),
"the tip box (phone): '%s' over '%s'" % [tut._text.text, tut._hint.text])
tut.free()
var bar := BuildHud.new()
t.check(bar.help_text() == "Place · Rotate · Dismantle · Done", "the build bar's line (phone): '%s'" % bar.help_text())
bar.free()
var labels := await _labels()
t.check(labels[0].begins_with("Upgrades\n") and labels[1].begins_with("Shop\n"),
"the workbench and the shed counter by day (phone): '%s', '%s'" % [labels[0].get_slice("\n", 0), labels[1].get_slice("\n", 0)])
var sign := await _sign()
t.check(sign.size() == 3 and sign[1] == Prompts.sign_day() and sign[2] == Prompts.sign_night() and sign[1].contains("(hold Use)"),
"the first morning's sign (phone) tells the day and the night in touch words")
func _desktop() -> void:
t.check(not Prompts.touch() and not MobilePort.active(), "forced to desktop, the prompts are as before")
var want := {
# interactions.gd
"gather": [Prompts.gather(), "[E / X] Gather"],
"repair": [Prompts.repair("6 wood"), "[E / X] Repair (%s)" % "6 wood"],
"upgrade": [Prompts.upgrade_to(2, "4 scrap, 2 straw"), "[E / X] Upgrade to L%d (%s)" % [2, "4 scrap, 2 straw"]],
# workbench.gd, shed_counter.gd
"workbench": [Prompts.upgrades(), "[E / X] Upgrades"],
"shed counter": [Prompts.shop(), "[E / X] Shop"],
# build_mode.gd
"build ghost": [Prompts.build_place(), "[LMB / RT] Build"],
"dismantle": [Prompts.dismantle(), "[RMB / B] Dismantle"],
# build_hud.gd
"build bar": [Prompts.build_help(), "LMB / RT build · Z C / d-pad rotate · 1-4 / Tab pick · RMB / B dismantle or leave"],
"build slot": [Prompts.build_slot(3, "Turret"), "%d %s" % [3, "Turret"]],
# opening_intro.gd, farmers_return.gd
"intro skip": [Prompts.intro_skip(), "Hold [Space / Enter / A] to skip"],
"return skip": [Prompts.return_skip(), "[Space / Enter / A] skip"],
# tutorial.gd
"tip footer": [Prompts.tip_footer(), "Tip · [Backspace / Back] hide tips"],
"tip move": [Prompts.tip("move"), "Move with [W A S D] or the left stick. You're the scarecrow: keep the farm safe until the farmers are back."],
"tip gather": [Prompts.tip("gather"), "Hold [E / X] at a dead tree, the haystacks, or the scrap heap to gather wood, straw, and scrap."],
"tip store": [Prompts.tip("store"), "Your pouch only holds so much ([I] shows what's in it): walk onto the barn's apron (the Supply Shed) to store what you carry."],
"tip build": [Prompts.tip("build"), "Press [B / d-pad up] to build. Pick a fence [1], place it with left mouse / RT. Aliens have to break through fences."],
"tip dusk": [Prompts.tip("dusk"), "Dusk: aliens come at nightfall, from every side of the farm."],
"tip shoot": [Prompts.tip("shoot"), "Aim with the mouse or the right stick and hold left mouse / RT to stab with your pitchfork. The supply shed sells a corn shooter (switch with [Tab / the number keys]); more weapons arrive there over the days, like pumpkin bombs for your off-hand (throw them with [right mouse / LT])."],
"tip fear": [Prompts.tip("fear"), "Crowded? [Q / LB] Fear scares off everything nearby, and they drop what they carry."],
"tip recover": [Prompts.tip("recover"), "Something was dropped! Walk over it to bring it home. A dropped animal follows you back to the pen."],
"tip patch": [Prompts.tip("patch"), "Hurt? Hold [F / Y] to patch up with straw. Health carries over to the next night."],
# review_panel.gd
"sign day": [Prompts.sign_day(), "By day, gather wood, scrap, and straw (hold E), store them at the barn, and build defenses (B). There's more to gather off the farm, to the north, east, and south."],
"sign night": [Prompts.sign_night(), "At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons with Tab or the number keys), and more weapons arrive there over the days."],
}
var changed: Array[String] = []
for k: String in want:
if want[k][0] != want[k][1]:
changed.append("%s: '%s'" % [k, want[k][0]])
t.check(changed.is_empty(), "desktop: all %d prompts are byte for byte as before %s" % [want.size(), changed])
## On desktop, what the same screens show.
func _desktop_screens() -> void:
var tut := Tutorial.new()
tree.root.add_child(tut)
tut._show("move")
t.check(tut._hint.text == "Tip · [Backspace / Back] hide tips"
and tut._text.text == "Move with [W A S D] or the left stick. You're the scarecrow: keep the farm safe until the farmers are back.",
"the tip box (desktop) is as before")
tut.free()
var bar := BuildHud.new()
t.check(bar.help_text() == "LMB / RT build · Z C / d-pad rotate · 1-4 / Tab pick · RMB / B dismantle or leave",
"the build bar's line (desktop) is as before")
bar.free()
var labels := await _labels()
t.check(labels[0].begins_with("[E / X] Upgrades\n") and labels[1].begins_with("[E / X] Shop\n"),
"the workbench and the shed counter by day (desktop) are as before")
var sign := await _sign()
var nights := campaign.config.campaign_nights
t.check("\n".join(sign) == "\n".join([
"Keep the farm safe for %d nights until they come home: the crops, the animals in the pen, and the supplies in the shed." % nights,
"By day, gather wood, scrap, and straw (hold E), store them at the barn, and build defenses (B). There's more to gather off the farm, to the north, east, and south.",
"At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons with Tab or the number keys), and more weapons arrive there over the days.",
]), "the first morning's sign (desktop) is as before")
## The workbench's and the shed counter's labels, focused by day.
func _labels() -> Array[String]:
campaign.new_campaign()
campaign.begin_day()
var bench := Workbench.new()
var counter := ShedCounter.new()
tree.root.add_child(bench)
tree.root.add_child(counter)
await tree.process_frame
bench.show_state(campaign, true, true)
counter.show_state(campaign, true, true)
var out: Array[String] = [bench._label.text, counter._label.text]
bench.free()
counter.free()
return out
## The first morning's sign: its introduction's lines.
func _sign() -> PackedStringArray:
campaign.new_campaign()
var panel := ReviewPanel.new()
tree.root.add_child(panel)
panel.campaign = campaign
panel.refresh()
var lines := panel._intro.text.split("\n") if panel.visible and panel._intro.visible else PackedStringArray()
await tree.process_frame # its deferred focus
panel.free()
return lines