Narrow positions and bounding boxes at the boundary

Values read back from the game always use the named members, so they
are narrowed once where they enter a function rather than at each use.

`LuaControl.force` is a ForceID union, so reading a force only method
off it needs the cast the rest of the repo already uses.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:43 +00:00
co-authored by Claude Opus 5
parent 3f46055b70
commit a4213dadf5
3 changed files with 27 additions and 18 deletions
+15 -9
View File
@@ -42,12 +42,14 @@ end
--- @param options FlyingText.create_above_entity_param
function FlyingText.create_above_entity(options)
local entity = assert(options.target_entity, "A target entity is required")
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
local size_y = bounding_box.left_top.y - bounding_box.right_bottom.y
local position = entity.position --[[@as MapPosition.struct]]
local offset = options.offset or { x = 0, y = 0 }
options.position = {
x = offset.x + entity.position.x,
y = offset.y + entity.position.y + size_y * 0.25,
x = offset.x + position.x,
y = offset.y + position.y + size_y * 0.25,
}
FlyingText.create(options)
@@ -62,12 +64,14 @@ end
function FlyingText.create_above_player(options)
local player = assert(options.target_player, "A target player is required")
local entity = player.character; if not entity then return end
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
local size_y = bounding_box.left_top.y - bounding_box.right_bottom.y
local position = entity.position --[[@as MapPosition.struct]]
local offset = options.offset or { x = 0, y = 0 }
options.position = {
x = offset.x + entity.position.x,
y = offset.y + entity.position.y + size_y * 0.25,
x = offset.x + position.x,
y = offset.y + position.y + size_y * 0.25,
}
FlyingText.create(options)
@@ -82,13 +86,15 @@ end
function FlyingText.create_as_player(options)
local player = assert(options.target_player, "A target player is required")
local entity = player.character; if not entity then return end
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
local size_y = bounding_box.left_top.y - bounding_box.right_bottom.y
local position = entity.position --[[@as MapPosition.struct]]
local offset = options.offset or { x = 0, y = 0 }
options.color = player.chat_color
options.position = {
x = offset.x + entity.position.x,
y = offset.y + entity.position.y + size_y * 0.25,
x = offset.x + position.x,
y = offset.y + position.y + size_y * 0.25,
}
FlyingText.create(options)