Skip to content

Commit

Permalink
Merge pull request #213 from Sharparam/feature/ghost-fixes
Browse files Browse the repository at this point in the history
Fix some issues
  • Loading branch information
Tetlanesh authored Nov 22, 2024
2 parents d645119 + 13507d5 commit 9393075
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
57 changes: 29 additions & 28 deletions cybersyn/scripts/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,6 @@ local function handle_close(e)
end
end
end
---@param e EventData.on_gui_selection_state_changed
local function handle_drop_down(e)
local element = e.element
if not element then return end
local comb = storage.to_comb[element.tags.id]
if not comb or not comb.valid then return end

set_visibility(element.parent.parent.parent.parent, element.selected_index)

if element.selected_index == 1 then
set_comb_operation(comb, MODE_PRIMARY_IO)
elseif element.selected_index == 2 then
set_comb_operation(comb, MODE_DEPOT)
elseif element.selected_index == 3 then
set_comb_operation(comb, MODE_REFUELER)
elseif element.selected_index == 4 then
set_comb_operation(comb, MODE_SECONDARY_IO)
elseif element.selected_index == 5 then
set_comb_operation(comb, MODE_WAGON)
else
return
end

combinator_update(storage, comb)

update_allow_list_section(e.player_index, comb.unit_number)
end
---@param e EventData.on_gui_switch_state_changed
local function handle_pr_switch(e)
local element = e.element
Expand Down Expand Up @@ -246,7 +219,7 @@ end

local function get_allow_list_section(player_index)
local player = game.get_player(player_index)
if player.opened.name == "cybersyn-comnator" then
if player.opened.name == COMBINATOR_NAME then
return player.opened.frame.vflow.bottom_allowlist
end
end
Expand All @@ -271,6 +244,34 @@ local function update_allow_list_section(player_index, comb_unit_number)
end
end

---@param e EventData.on_gui_selection_state_changed
local function handle_drop_down(e)
local element = e.element
if not element then return end
local comb = storage.to_comb[element.tags.id]
if not comb or not comb.valid then return end

set_visibility(element.parent.parent.parent.parent, element.selected_index)

if element.selected_index == 1 then
set_comb_operation(comb, MODE_PRIMARY_IO)
elseif element.selected_index == 2 then
set_comb_operation(comb, MODE_DEPOT)
elseif element.selected_index == 3 then
set_comb_operation(comb, MODE_REFUELER)
elseif element.selected_index == 4 then
set_comb_operation(comb, MODE_SECONDARY_IO)
elseif element.selected_index == 5 then
set_comb_operation(comb, MODE_WAGON)
else
return
end

combinator_update(storage, comb)

update_allow_list_section(e.player_index, comb.unit_number)
end

---@param e EventData.on_gui_checked_state_changed
local function handle_setting_flip(e)
local element = e.element
Expand Down
20 changes: 14 additions & 6 deletions cybersyn/scripts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,15 @@ end

---@param map_data MapData
---@param comb LuaEntity
function on_combinator_broken(map_data, comb)
---@param skip_gui_events boolean?
function on_combinator_broken(map_data, comb, skip_gui_events)
--NOTE: we do not check for wagon manifest combinators and update their stations, it is assumed they will be lazy deleted later
---@type uint
local comb_id = comb.unit_number

gui_entity_destroyed(comb_id, false)
if not skip_gui_events then
gui_entity_destroyed(comb_id, false)
end

local out = map_data.to_output[comb_id]

Expand Down Expand Up @@ -437,11 +440,16 @@ function on_combinator_broken(map_data, comb)
map_data.to_comb_params[comb_id] = nil
end

function on_combinator_ghost_broken(map_data, comb)
---@param map_data MapData
---@param comb LuaEntity
---@param skip_gui_events boolean?
function on_combinator_ghost_broken(map_data, comb, skip_gui_events)
---@type uint
local comb_id = comb.unit_number

gui_entity_destroyed(comb_id, true)
if not skip_gui_events then
gui_entity_destroyed(comb_id, true)
end

map_data.to_comb[comb_id] = nil
map_data.to_comb_params[comb_id] = nil
Expand Down Expand Up @@ -496,10 +504,10 @@ function combinator_update(map_data, comb, reset_display)
if old_params ~= nil and params.operation ~= old_params.operation then
--NOTE: This is rather dangerous, we may need to actually implement operation changing
if is_ghost then
on_combinator_ghost_broken(map_data, comb)
on_combinator_ghost_broken(map_data, comb, true)
on_combinator_ghost_built(map_data, comb)
else
on_combinator_broken(map_data, comb)
on_combinator_broken(map_data, comb, true)
on_combinator_built(map_data, comb)
-- If anyone actually needs notification of changed ghosts, perhaps a new event can be added for that
interface_raise_combinator_changed(comb, old_params)
Expand Down

0 comments on commit 9393075

Please sign in to comment.