targeting: say what you are about to hit or throw at
Both aiming modes announced their name and then went silent, so there was no way to know what the arrow keys were pointing at. Prompted by "it says targetting, melee, but when I press the arrow keys it does not tell me what I am currently selecting." They look like a pair and are not, which is the whole shape of the fix. Throw has a real free-roaming cursor on level.cursorX/cursorY, so its descriptor is ingame_observe plus one clause: whether the tile is a legal target. That clause is recomputed from level.FoV, level.interactableArea and level.canThrowOnCell rather than read off the state's targetAllowed upvalue, because ingame_targeting_throw.lua:228 sets targetAllowed false for the whole 0.3s cursor glide and only the animation's onFinish restores it -- and mid-glide is exactly when we speak, so it would have said "blocked" on every single move. The same class of trap as the examine-cursor popup lag, and the same answer: read the model, not the view. Melee has no cursor and no target state at all. ingame_targeting_melee.lua:184-195 takes one direction key and fires the callback in that same keypress, so nothing is ever "currently selected" and there is no focus for a read() to return. Its descriptor speaks only on entry, listing the eight adjacent tiles -- which are precisely the legal targets, the game's rule being Chebyshev <= 1. Arrows still commit immediately; the game plays as it did. A two-step confirm cursor was considered and rejected for that reason. That entry line is surroundings.scan()'s sentence, so scan() splits into describeNeighbours() returning the text and scan() speaking it. onOpen grows the ability to be a function rather than a fixed string, since the neighbours differ every time. menus.selfTest needed a branch for a descriptor with neither read nor probe -- melee is the first -- or it would index a nil probe and take the whole self test down with it, which is the one report that must never fail quietly. Neither mode is reachable by its key in the prologue: b is filtered out by the room's level.allowedActions, and t falls through to gotoInventory() when there is nothing throwable. Found that by writing the testbed block as keypresses and watching it land in the inventory. It now drives both states directly, borrowing levelWindow, hpbar and levelDescriptionWindow off the ingame state's upvalues the way gotoAction would pass them. 129 testbed checks, 0 failures. The throw block asserts the focus text CHANGED across a cursor move rather than merely being non-nil, which is the assertion that would have caught the targetAllowed mistake had it been made. Still unverified against real content: only "can throw" has been heard, not "blocked", "out of range" or "no line of sight". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
5778e86e8e
commit
fd06961af5
@@ -1377,6 +1377,132 @@ local function scenario()
|
||||
check("left examine mode", currentState() == "ingame",
|
||||
"got " .. currentState())
|
||||
end
|
||||
|
||||
-- Targeting. Both modes used to announce their name and then go silent,
|
||||
-- which left no way to know what you were about to hit or throw at.
|
||||
--
|
||||
-- Neither mode is reachable by its key here. The prologue room restricts
|
||||
-- level.allowedActions, so `b` (hit) never resolves an action; and with
|
||||
-- nothing throwable in the pack, `t` falls through to gotoInventory()
|
||||
-- (states/ingame.lua:986-990). So drive both states directly, borrowing the
|
||||
-- views from the ingame state exactly as gotoAction would pass them
|
||||
-- (states/ingame.lua:133-151).
|
||||
local function targetingParams()
|
||||
local ingameTable = menus.getStateTable("ingame")
|
||||
if not ingameTable then
|
||||
return nil
|
||||
end
|
||||
|
||||
local params = {
|
||||
range = 5,
|
||||
callback = function() end,
|
||||
levelWindow = menus.getAnyUpvalue(ingameTable, "levelWindow"),
|
||||
hpbar = menus.getAnyUpvalue(ingameTable, "hpbar"),
|
||||
levelDescriptionWindow =
|
||||
menus.getAnyUpvalue(ingameTable, "levelDescriptionWindow"),
|
||||
}
|
||||
|
||||
if not (params.levelWindow and params.hpbar
|
||||
and params.levelDescriptionWindow) then
|
||||
return nil
|
||||
end
|
||||
|
||||
return params
|
||||
end
|
||||
|
||||
if currentState() == "ingame" then
|
||||
local params = targetingParams()
|
||||
if params then
|
||||
params.actionName = "hit"
|
||||
pcall(require("states").switch, "ingame_targeting_melee", params)
|
||||
wait(10)
|
||||
else
|
||||
print("[testbed] could not harvest ingame views for melee targeting")
|
||||
end
|
||||
|
||||
if currentState() == "ingame_targeting_melee" then
|
||||
check("entered melee targeting", true)
|
||||
|
||||
-- Melee has no cursor: one direction key picks AND commits. So the
|
||||
-- descriptor speaks on entry only, and we must not press an arrow
|
||||
-- here -- that would swing at something and perturb the run.
|
||||
local descriptor = menus.loadDescriptor("ingame_targeting_melee")
|
||||
local spoken = descriptor and descriptor.onOpen and descriptor.onOpen()
|
||||
|
||||
check("melee targeting describes the adjacent tiles on entry",
|
||||
type(spoken) == "string" and spoken ~= "",
|
||||
"onOpen=" .. tostring(spoken))
|
||||
|
||||
if type(spoken) == "string" then
|
||||
local missing
|
||||
for _, dir in ipairs({"north-east", "east", "south-east",
|
||||
"south", "south-west", "west", "north-west"}) do
|
||||
if not spoken:find(dir, 1, true) then
|
||||
missing = dir
|
||||
break
|
||||
end
|
||||
end
|
||||
check("melee entry scan covers all eight directions",
|
||||
missing == nil, "missing " .. tostring(missing)
|
||||
.. " in " .. tostring(spoken))
|
||||
end
|
||||
|
||||
press("escape", "leave melee targeting")
|
||||
wait(10)
|
||||
check("left melee targeting", currentState() == "ingame",
|
||||
"got " .. currentState())
|
||||
else
|
||||
print("[testbed] melee targeting not reachable here (skipped), state="
|
||||
.. currentState())
|
||||
end
|
||||
end
|
||||
|
||||
if currentState() == "ingame" then
|
||||
local params = targetingParams()
|
||||
if params then
|
||||
params.actionName = "throw"
|
||||
pcall(require("states").switch, "ingame_targeting_throw", params)
|
||||
wait(10)
|
||||
else
|
||||
print("[testbed] could not harvest ingame views for throw targeting")
|
||||
end
|
||||
|
||||
if currentState() == "ingame_targeting_throw" then
|
||||
check("entered throw targeting", true)
|
||||
|
||||
local first = focusText()
|
||||
check("throw targeting speaks the cursor tile",
|
||||
first ~= nil and first ~= "",
|
||||
"focus=" .. tostring(first))
|
||||
|
||||
-- The validity clause is the whole point of targeting as opposed to
|
||||
-- examining, so assert it specifically rather than just "some text".
|
||||
check("throw targeting says whether the tile is a legal target",
|
||||
first ~= nil and (first:find("can throw", 1, true)
|
||||
or first:find("blocked", 1, true)
|
||||
or first:find("out of range", 1, true)
|
||||
or first:find("no line of sight", 1, true)) ~= nil,
|
||||
"focus=" .. tostring(first))
|
||||
|
||||
press("right", "throw: cursor east")
|
||||
local afterMove = focusText()
|
||||
|
||||
-- Not merely "it said something": the cursor glides for 0.3s, so a
|
||||
-- descriptor that read the popup (or the state's targetAllowed
|
||||
-- upvalue) would report the PREVIOUS tile here.
|
||||
check("throw targeting tracks the cursor on the frame it moves",
|
||||
afterMove ~= nil and afterMove ~= first,
|
||||
"before=" .. tostring(first) .. " after=" .. tostring(afterMove))
|
||||
|
||||
press("escape", "leave throw targeting")
|
||||
wait(10)
|
||||
check("left throw targeting", currentState() == "ingame",
|
||||
"got " .. currentState())
|
||||
else
|
||||
print("[testbed] throw targeting not reachable here (skipped), state="
|
||||
.. currentState())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print(string.format("[testbed] === %d checks, %d failures ===", checks, failures))
|
||||
|
||||
Reference in New Issue
Block a user