Skip to content

Commit

Permalink
Mtn: fix more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkiz committed Oct 27, 2024
1 parent a8f2db5 commit d3ce9d2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion maps/mountain_fortress_v3/basic_markets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
42 changes: 35 additions & 7 deletions maps/mountain_fortress_v3/icw/linked_chests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' }
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions maps/mountain_fortress_v3/locomotive/friendly_pet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion maps/mountain_fortress_v3/mystical_chest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions maps/mountain_fortress_v3/stateful/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
5 changes: 2 additions & 3 deletions maps/mountain_fortress_v3/stateful/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions modules/check_fullness.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions utils/datastore/quickbar_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions utils/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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.
Expand Down

0 comments on commit d3ce9d2

Please sign in to comment.