Skip to content

Commit

Permalink
Fix description not working on combinator ghosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharparam committed Nov 6, 2024
1 parent e14eab7 commit 4329fa0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 2.2.2
Date: 2024-11-06
Bugfixes:
- Fix description not working on combinator ghosts.
---------------------------------------------------------------------------------------------------
Version: 2.2.1
Date: 2024-11-06
Bugfixes:
Expand Down
9 changes: 9 additions & 0 deletions src/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ script.on_event(defines.events.on_built_entity, function(event)
log:debug(entity.name, "[", entity.unit_number, "] built by ", pname)
local disable = settings.get_player_settings(player)[constants.SETTINGS.DISABLE_BUILT].value
local combinator = CybersynCombinator:new(entity, true)
if event.tags and event.tags.description then
combinator:set_description(event.tags.description --[[@as string]])
end
if not disable then return end
combinator:disable()
log:debug(entity.name, "[", entity.unit_number, "] disabled due to per-player setting")
Expand All @@ -129,6 +132,9 @@ local function on_script_raised_built_or_revive(event)
disable = settings.global[constants.SETTINGS.DISABLE_NONPLAYER_BUILT].value == true
end
local combinator = CybersynCombinator:new(entity, true)
if event.tags and event.tags.description then
combinator:set_description(event.tags.description --[[@as string]])
end
if not disable then return end
combinator:disable()
log:debug(entity.name, "[", entity.unit_number, "] disabled due to per-player or global setting")
Expand All @@ -150,6 +156,9 @@ script.on_event(defines.events.on_robot_built_entity, function(event)
disable = settings.global[constants.SETTINGS.DISABLE_NONPLAYER_BUILT].value == true
end
local combinator = CybersynCombinator:new(entity, true)
if event.tags and event.tags.description then
combinator:set_description(event.tags.description --[[@as string]])
end
if not disable then return end
combinator:disable()
log:debug(entity.name, "[", entity.unit_number, "] disabled due to per-player or global setting")
Expand Down
28 changes: 28 additions & 0 deletions src/scripts/combinator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ end
function CC:enable() self:set_enabled(true) end
function CC:disable() self:set_enabled(false) end

function CC:is_ghost()
return self.entity.name == "entity-ghost"
end

--- @return string
function CC:get_description()
if not self:is_ghost() then return self.entity.combinator_description end
if not self.entity.tags then
self.entity.tags = { description = "" }
end
return self.entity.tags.description or "" --[[@as string]]
end

--- @param description string
function CC:set_description(description)
if not self:is_ghost() then
self.entity.combinator_description = description
return
end
if self.entity.tags then
local tags = self.entity.tags
tags.description = description
self.entity.tags = tags
else
self.entity.tags = { description = description }
end
end

--- @param id integer
--- @return LuaLogisticSection? section
function CC:get_or_create_section(id)
Expand Down
25 changes: 19 additions & 6 deletions src/scripts/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,10 @@ end
local function confirm_description(player_index, close)
local state = get_player_state(player_index)
if not state then return end
state.entity.combinator_description = state.description_edit.textfield.text
state.description_label.caption = state.entity.combinator_description
local has_description = state.entity.combinator_description and state.entity.combinator_description ~= ""
local description = state.description_edit.textfield.text
state.combinator:set_description(description)
state.description_label.caption = description
local has_description = description ~= ""
state.add_description_button.visible = not has_description
state.description_header.visible = has_description
state.description_scroll.visible = has_description
Expand Down Expand Up @@ -1373,7 +1374,7 @@ local function create_description_edit(player_index, state)
style_mods = {
horizontally_stretchable = true
},
text = state.combinator.entity.combinator_description or "",
text = state.combinator:get_description(),
icon_selector = true
},
{
Expand Down Expand Up @@ -1893,7 +1894,19 @@ local function create_window(player, entity)
}
}

local has_description = entity.combinator_description and entity.combinator_description ~= ""
---@type string
local description

if entity.name == "entity-ghost" then
if not entity.tags then
entity.tags = { description = "" }
end
description = entity.tags.description or "" --[[@as string]]
else
description = entity.combinator_description
end

local has_description = description ~= ""

local description_container = {
type = "flow",
Expand Down Expand Up @@ -1948,7 +1961,7 @@ local function create_window(player, entity)
{
type = "label",
name = "description_label",
caption = entity.combinator_description,
caption = description,
style_mods = {
horizontally_squashable = false,
-- horizontally_stretchable = true,
Expand Down

0 comments on commit 4329fa0

Please sign in to comment.