Skip to content

Commit

Permalink
fa-info: fix: properly announce ghosts as entity ghost of x
Browse files Browse the repository at this point in the history
  • Loading branch information
ahicks92 committed Nov 26, 2024
1 parent 2f18e3b commit 83d1835
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions scripts/fa-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ local function ent_info_facing(ctx)

if
(ent.prototype.is_building and ent.supports_direction)
or (ent.name == "entity-ghost" and ent.ghost_prototype.is_building and ent.ghost_prototype.supports_direction)
or (ent.type == "entity-ghost" and ent.ghost_prototype.is_building and ent.ghost_prototype.supports_direction)
then
effective_direction = FaUtils.direction_lookup(ent.direction)
if ent.type == "generator" then
Expand Down Expand Up @@ -293,18 +293,6 @@ local function ent_info_resource(ctx)
end
end

---@param ctx fa.Info.EntInfoContext
local function ent_info_ghost(ctx)
local ent = ctx.ent
if ent.name == "entity-ghost" then
ctx.message:fragment({
"fa.ent-info-ghost",
Localising.get_localised_name_with_fallback(ent.ghost_prototype),
Localising.get_localised_name_with_fallback(ent.prototype),
})
end
end

---@param ctx fa.Info.EntInfoContext
local function ent_info_rail(ctx)
local ent = ctx.ent
Expand Down Expand Up @@ -1006,8 +994,17 @@ function mod.ent_info(pindex, ent, is_scanner)
cursor_pos = { x = players[pindex].cursor_pos.x, y = players[pindex].cursor_pos.y },
}

ctx.message:fragment(Localising.get_localised_name_with_fallback(ent))

-- We need to special case ghosts, so that we can fold the "x of y" in, e.g.
-- "entity ghost of transport belt".
if ent.type == "entity-ghost" or ent.type == "tile-ghost" then
ctx.message:fragment({
"fa.ent-info-ghost",
Localising.get_localised_name_with_fallback(ent),
Localising.get_localised_name_with_fallback(ent.ghost_prototype),
})
else
ctx.message:fragment(Localising.get_localised_name_with_fallback(ent))
end
local function run_handler(handler, nolist)
handler(ctx)
if not nolist then ctx.message:list_item() end
Expand Down Expand Up @@ -1038,7 +1035,6 @@ function mod.ent_info(pindex, ent, is_scanner)
run_handler(ent_info_pole_neighbors, true)

run_handler(ent_info_resource)
run_handler(ent_info_ghost)
run_handler(ent_info_rail)
run_handler(ent_info_character)
run_handler(ent_info_character_corpse)
Expand Down

0 comments on commit 83d1835

Please sign in to comment.