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
@@ -0,0 +1,91 @@
|
||||
-- states/ingame_targeting_throw.lua — the ranged targeting cursor.
|
||||
--
|
||||
-- Same shape, and same reasoning, as accessibility/states/ingame_observe.lua:
|
||||
-- read level.cursorX/cursorY straight off the level model each frame rather than
|
||||
-- listening to the game's cursor popup. The popup is refreshed from the cursor
|
||||
-- animation's completion callback (`onFinish`), so relaying it would put every
|
||||
-- announcement a keypress behind. animations/moveCursor.lua assigns cursorX/Y in
|
||||
-- its constructor, so polling is correct on the frame the key is pressed.
|
||||
--
|
||||
-- The extra job here over examine mode is saying whether the tile is a LEGAL
|
||||
-- target, which is the whole point of being in this state.
|
||||
|
||||
local describe = require("accessibility.describe")
|
||||
|
||||
-- Recompute validity from the level rather than reading the state's own
|
||||
-- `targetAllowed` upvalue.
|
||||
--
|
||||
-- Why: states/ingame_targeting_throw.lua:228 sets targetAllowed = false for the
|
||||
-- duration of the 0.3s cursor glide and only the animation's onFinish restores
|
||||
-- it. We speak on the frame the key is pressed, i.e. mid-glide, so that upvalue
|
||||
-- would report "blocked" for every single move. The three inputs the game
|
||||
-- itself uses (:86-89) are all public fields, so recomputing is both cheap and
|
||||
-- honest.
|
||||
local function validity(level, x, y)
|
||||
if not level.interactableArea then
|
||||
return nil
|
||||
end
|
||||
|
||||
if not (level.FoV and level.FoV[x] and level.FoV[x][y]) then
|
||||
return "no line of sight"
|
||||
end
|
||||
|
||||
if not (level.interactableArea[x] and level.interactableArea[x][y]) then
|
||||
return "out of range"
|
||||
end
|
||||
|
||||
local ok, throwable = pcall(level.canThrowOnCell, x, y)
|
||||
if ok and not throwable then
|
||||
return "blocked"
|
||||
end
|
||||
|
||||
return "can throw"
|
||||
end
|
||||
|
||||
return {
|
||||
read = function()
|
||||
local ok, world = pcall(require, "models.world")
|
||||
if not ok or not world.currentLevel then
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
local level = world.currentLevel
|
||||
local x, y = level.cursorX, level.cursorY
|
||||
|
||||
if type(x) ~= "number" or type(y) ~= "number" then
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
local player = level.playerActor
|
||||
local px = player and player.x
|
||||
local py = player and player.y
|
||||
|
||||
-- Terse: in combat the target's name, its legality and how far away it is
|
||||
-- are what matter; the scenery adjectives are noise.
|
||||
--
|
||||
-- Described without an origin so that describe.tile does not append the
|
||||
-- offset itself -- the validity belongs between the two, giving
|
||||
-- "rat, can throw, 3 tiles north-east".
|
||||
local previousVerbosity = describe.verbosity
|
||||
describe.verbosity = "terse"
|
||||
local okTile, text = pcall(describe.tile, level, x, y)
|
||||
describe.verbosity = previousVerbosity
|
||||
|
||||
if not okTile or not text or text == "" then
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
local parts = {text}
|
||||
|
||||
local state = validity(level, x, y)
|
||||
if state then
|
||||
parts[#parts + 1] = state
|
||||
end
|
||||
|
||||
if px and py then
|
||||
parts[#parts + 1] = describe.offset(x - px, y - py)
|
||||
end
|
||||
|
||||
return table.concat(parts, ", "), x .. "," .. y
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user