From d3ce9d24cb39b0cee901e4c9618e638cad9cc6a0 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sun, 27 Oct 2024 09:21:16 +0100 Subject: [PATCH] Mtn: fix more bugs --- maps/mountain_fortress_v3/basic_markets.lua | 2 +- .../icw/linked_chests.lua | 42 +++++++++++++++---- .../locomotive/friendly_pet.lua | 1 + maps/mountain_fortress_v3/mystical_chest.lua | 2 +- maps/mountain_fortress_v3/stateful/main.lua | 2 + maps/mountain_fortress_v3/stateful/table.lua | 5 +-- modules/check_fullness.lua | 5 +++ utils/datastore/quickbar_data.lua | 4 +- utils/gui.lua | 6 ++- 9 files changed, 53 insertions(+), 16 deletions(-) diff --git a/maps/mountain_fortress_v3/basic_markets.lua b/maps/mountain_fortress_v3/basic_markets.lua index a5b76806d..51b149a78 100644 --- a/maps/mountain_fortress_v3/basic_markets.lua +++ b/maps/mountain_fortress_v3/basic_markets.lua @@ -49,7 +49,7 @@ local this = { }, ['equipment'] = { ['solar-panel-equipment'] = { value = 240, rarity = 3 }, - ['fusion-reactor-equipment'] = { value = 9000, rarity = 7 }, + ['fission-reactor-equipment'] = { value = 9000, rarity = 7 }, ['energy-shield-equipment'] = { value = 400, rarity = 6 }, ['energy-shield-mk2-equipment'] = { value = 4000, rarity = 8 }, ['battery-equipment'] = { value = 160, rarity = 2 }, diff --git a/maps/mountain_fortress_v3/icw/linked_chests.lua b/maps/mountain_fortress_v3/icw/linked_chests.lua index f6e1b9b97..c725b3391 100644 --- a/maps/mountain_fortress_v3/icw/linked_chests.lua +++ b/maps/mountain_fortress_v3/icw/linked_chests.lua @@ -17,6 +17,7 @@ local player_frame_name = Where.player_frame_name local chest_converter_frame_for_player_name = Gui.uid_name() local convert_chest_to_linked = Gui.uid_name() local item_name_frame_name = Gui.uid_name() +local close_name = Gui.uid_name() local module_name = '[Linked Chests] ' local deepcopy = table.deepcopy @@ -575,15 +576,15 @@ local function gui_opened(event) return end + local inside_frame, close_button local frame = player.gui.center[tostring(unit_number)] if not frame or not frame.valid then - frame = - player.gui.center.add { - type = 'frame', - caption = 'Linked chest', - direction = 'vertical', - name = tostring(unit_number) - } + frame, inside_frame, close_button = Gui.add_main_frame_with_toolbar(player, 'center', tostring(unit_number), nil, close_name, 'Linked chest') + end + + if close_button then + inside_frame.name = 'inside_frame' + Gui.set_data(close_button, tostring(unit_number)) end local controls = frame.add { type = 'flow', direction = 'horizontal' } @@ -1283,12 +1284,39 @@ Event.add( end ) +Gui.on_click( + close_name, + function (event) + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + local element = event.element + local data = Gui.get_data(element) + if not data then + return + end + + local frame = player.gui.center[data] + if frame and frame.valid then + Gui.destroy(frame) + end + + Where.remove_camera_frame(player) + this.linked_gui[player.name] = nil + end +) + Gui.on_click( item_name_frame_name, function (event) local player = game.get_player(event.player_index) local player_data = this.linked_gui[player.name] local element = event.element + if not element or not element.valid then + return + end + if not player_data then Gui.remove_data_recursively(element) return diff --git a/maps/mountain_fortress_v3/locomotive/friendly_pet.lua b/maps/mountain_fortress_v3/locomotive/friendly_pet.lua index fe4619ff1..620fcfa57 100644 --- a/maps/mountain_fortress_v3/locomotive/friendly_pet.lua +++ b/maps/mountain_fortress_v3/locomotive/friendly_pet.lua @@ -39,6 +39,7 @@ end local function shoo(event) local icw_locomotive = Public.get('icw_locomotive') + if not icw_locomotive then return end local loco_surface = icw_locomotive.surface if not loco_surface or not loco_surface.valid then diff --git a/maps/mountain_fortress_v3/mystical_chest.lua b/maps/mountain_fortress_v3/mystical_chest.lua index 01e7415a6..573bbd299 100644 --- a/maps/mountain_fortress_v3/mystical_chest.lua +++ b/maps/mountain_fortress_v3/mystical_chest.lua @@ -67,7 +67,7 @@ local item_worths = { ['power-armor'] = 4096, ['power-armor-mk2'] = 32768, ['solar-panel-equipment'] = 256, - ['fusion-reactor-equipment'] = 8192, + ['fission-reactor-equipment'] = 8192, ['energy-shield-equipment'] = 512, ['energy-shield-mk2-equipment'] = 4096, ['battery-equipment'] = 128, diff --git a/maps/mountain_fortress_v3/stateful/main.lua b/maps/mountain_fortress_v3/stateful/main.lua index 67189df6a..f435f7131 100644 --- a/maps/mountain_fortress_v3/stateful/main.lua +++ b/maps/mountain_fortress_v3/stateful/main.lua @@ -199,6 +199,8 @@ Event.add( launch_item.actual = launch_item.actual + 1 end end + rocket_inventory.clear() + rocket_inventory.insert({ name = 'space-science-pack', count = 200 }) end ) diff --git a/maps/mountain_fortress_v3/stateful/table.lua b/maps/mountain_fortress_v3/stateful/table.lua index 0d54d9b2a..9e8d2789d 100644 --- a/maps/mountain_fortress_v3/stateful/table.lua +++ b/maps/mountain_fortress_v3/stateful/table.lua @@ -1568,11 +1568,10 @@ function Public.reset_stateful(refresh_gui, clear_buffs) } end if not this.objectives.launch_item or (this.objectives_completed ~= nil and this.objectives_completed.launch_item) then - local item = get_random_handcrafted_item() this.objectives.launch_item = { actual = 0, - expected = scale(1, 50), - name = item.name + expected = scale(1, 500), + name = 'raw-fish' } end if not this.objectives.research_level_selection or (this.objectives_completed ~= nil and this.objectives_completed.research_level_selection) then diff --git a/modules/check_fullness.lua b/modules/check_fullness.lua index 77b29d8e5..c3b3efc98 100644 --- a/modules/check_fullness.lua +++ b/modules/check_fullness.lua @@ -36,6 +36,11 @@ local function compute_fullness(player, position) if not player.mining_state.mining then return false end + + if player.controller_type == defines.controllers.remote then + return + end + local warn_player = is_player_warned(player) local free_slots = player.get_main_inventory().count_empty_stacks() local inventory_size = #player.get_main_inventory() diff --git a/utils/datastore/quickbar_data.lua b/utils/datastore/quickbar_data.lua index d9268b8e1..5fef6032d 100644 --- a/utils/datastore/quickbar_data.lua +++ b/utils/datastore/quickbar_data.lua @@ -56,7 +56,7 @@ local function apply_logistic_network(player, saved_data) for i, slot in pairs(saved_data) do if slot and slot.name and check_if_item_exists(slot.name) then local item_stack = { min = slot.min, max = slot.max, value = { comparator = "=", name = slot.name, quality = "normal", type = slot.type or nil } } - old_section.set_slot(i, item_stack) + pcall(old_section.set_slot, i, item_stack) end end end @@ -73,7 +73,7 @@ local function apply_logistic_network(player, saved_data) for i, slot in pairs(slots) do if slot and slot.name and check_if_item_exists(slot.name) then local item_stack = { min = slot.min, max = slot.max, value = { comparator = "=", name = slot.name, quality = "normal", type = slot.type or nil } } - new_section.set_slot(i, item_stack) + pcall(new_section.set_slot, i, item_stack) end end end diff --git a/utils/gui.lua b/utils/gui.lua index 0c33db4a7..192d89d9f 100644 --- a/utils/gui.lua +++ b/utils/gui.lua @@ -281,8 +281,10 @@ function Public.add_main_frame_with_toolbar(player, align, set_frame_name, set_s end end + local close_button + if close_main_frame_name then - titlebar.add { + close_button = titlebar.add { type = 'sprite-button', name = close_main_frame_name, style = 'frame_action_button', @@ -304,7 +306,7 @@ function Public.add_main_frame_with_toolbar(player, align, set_frame_name, set_s name = 'inside_frame' } - return main_frame, inside_frame + return main_frame, inside_frame, close_button end -- Removes data associated with LuaGuiElement and its children recursively.