From 48f55b0547122e9a4337515cf7ce5a2b0a9fa989 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:40:21 +0000 Subject: [PATCH] Resolve all Luals warnings --- exp_groups/module/module_exports.lua | 31 +++++++++++--- .../config/expcore/permission_groups.lua | 12 +++--- exp_legacy/module/config/expcore/roles.lua | 8 ++-- .../module/modules/addons/compilatron.lua | 9 ++-- exp_legacy/module/modules/addons/deconlog.lua | 9 +++- .../modules/addons/station-auto-name.lua | 14 +++---- exp_legacy/module/modules/data/statistics.lua | 2 +- exp_legacy/module/modules/gui/bonus.lua | 21 ++++++---- exp_legacy/module/modules/gui/debug/model.lua | 30 ++++++------- exp_legacy/module/modules/gui/playerdata.lua | 6 +-- exp_legacy/module/modules/gui/readme.lua | 2 +- exp_legacy/module/modules/gui/task-list.lua | 42 +++++++++---------- exp_legacy/module/modules/gui/vlayer.lua | 6 +-- .../module/commands/protected_entities.lua | 24 +++++------ 14 files changed, 123 insertions(+), 93 deletions(-) diff --git a/exp_groups/module/module_exports.lua b/exp_groups/module/module_exports.lua index 4b71e78e..037e851c 100644 --- a/exp_groups/module/module_exports.lua +++ b/exp_groups/module/module_exports.lua @@ -30,6 +30,7 @@ end --- Add a player to a permission group, requires edit_permission_group --- @param player LuaPlayer Player to add to the group --- @param group LuaPermissionGroup Group to add the player to +--- @return boolean # True if successful local function add_player_to_group(player, group) return group.add_player(player) end @@ -37,6 +38,7 @@ end --- Add a players to a permission group, requires edit_permission_group --- @param players LuaPlayer[] Players to add to the group --- @param group LuaPermissionGroup Group to add the players to +--- @return boolean # True if successful local function add_players_to_group(players, group) local add_player = group.add_player if not add_player(players[1]) then @@ -57,6 +59,7 @@ local add_players_to_group_async = Async.register(add_players_to_group) --- Gets the permission group proxy with the given name or group ID. --- @param group_name string|uint32 The name or id of the permission group +--- @return ExpGroup? function Groups.get_group(group_name) local group = game.permissions.get_group(group_name) if group == nil then return nil end @@ -67,6 +70,7 @@ end --- Gets the permission group proxy for a players group --- @param player LuaPlayer The player to get the group of +--- @return ExpGroup? function Groups.get_player_group(player) local group = player.permission_group if group == nil then return nil end @@ -77,6 +81,7 @@ end --- Creates a new permission group, requires add_permission_group --- @param group_name string Name of the group to create +--- @return ExpGroup function Groups.new_group(group_name) local group = game.permissions.get_group(group_name) assert(group == nil, "Group already exists with name: " .. group_name) @@ -89,6 +94,7 @@ end --- Get or create a permisison group, must use the group name not the group id --- @param group_name string Name of the group to create +--- @return ExpGroup function Groups.get_or_create(group_name) local group = game.permissions.get_group(group_name) if group then @@ -109,7 +115,7 @@ end --- @param move_to_name string|uint32? The name or id of the permission group to move players to function Groups.destroy_group(group_name, move_to_name) local group = game.permissions.get_group(group_name) - if group == nil then return nil end + if group == nil then return end local players = group.players if #players > 0 then @@ -128,23 +134,30 @@ end --- Add a player to the permission group --- @param player LuaPlayer The player to add to the group function Groups._prototype:add_player(player) - return add_player_to_group(player, self.group) or add_player_to_group_async(player, self.group) + if not add_player_to_group(player, self.group) then + add_player_to_group_async(player, self.group) + end end --- Add players to the permission group --- @param players LuaPlayer[] The player to add to the group function Groups._prototype:add_players(players) - return add_players_to_group(players, self.group) or add_players_to_group_async(players, self.group) + if not add_players_to_group(players, self.group) then + add_players_to_group_async(players, self.group) + end end --- Move all players to another group --- @param other_group ExpGroup The group to move players to, default is the Default group function Groups._prototype:move_players(other_group) - return add_players_to_group(self.group.players, other_group.group) or add_players_to_group_async(self.group.players, other_group.group) + if not add_players_to_group(self.group.players, other_group.group) then + add_players_to_group_async(self.group.players, other_group.group) + end end --- Allow a set of actions for this group --- @param actions defines.input_action[] Actions to allow +--- @return ExpGroup function Groups._prototype:allow_actions(actions) local set_allow = self.group.set_allows_action for _, action in ipairs(actions) do @@ -156,6 +169,7 @@ end --- Disallow a set of actions for this group --- @param actions defines.input_action[] Actions to disallow +--- @return ExpGroup function Groups._prototype:disallow_actions(actions) local set_allow = self.group.set_allows_action for _, action in ipairs(actions) do @@ -167,6 +181,7 @@ end --- Reset the allowed state of all actions --- @param allowed boolean? default true for allow all actions, false to disallow all actions +--- @return ExpGroup function Groups._prototype:reset(allowed) local set_allow = self.group.set_allows_action if allowed == nil then allowed = true end @@ -179,6 +194,7 @@ end --- Returns if the group is allowed a given action --- @param action string|defines.input_action Actions to test +--- @return boolean # True if successful function Groups._prototype:allows(action) if type(action) == "string" then return self.group.allows_action(defines.input_action[action]) @@ -197,6 +213,7 @@ end --- Convert an array of strings into an array of action names --- @param actions_names string[] An array of action names +--- @return defines.input_action[] local function names_to_actions(actions_names) local actions, invalid, invalid_i = {}, {}, 1 for i, action_name in ipairs(actions_names) do @@ -241,6 +258,7 @@ end --- Convert a json string array into an array of input actions --- @param json string A json string representing a string array of actions +--- @return defines.input_action[] function Groups.json_to_actions(json) local tbl = json_to_table(json) assert(tbl, "Invalid Json String") @@ -277,9 +295,10 @@ function Groups._prototype:from_json(json) assert(tbl and type(tbl[1]) == "boolean" and type(tbl[2]) == "table", "Invalid Json String") if tbl[1] then - return self:reset(true):disallow_actions(names_to_actions(tbl[2])) + self:reset(true):disallow_actions(names_to_actions(tbl[2])) + return end - return self:reset(false):allow_actions(names_to_actions(tbl[2])) + self:reset(false):allow_actions(names_to_actions(tbl[2])) end return Groups diff --git a/exp_legacy/module/config/expcore/permission_groups.lua b/exp_legacy/module/config/expcore/permission_groups.lua index 397a619f..b0e972f3 100644 --- a/exp_legacy/module/config/expcore/permission_groups.lua +++ b/exp_legacy/module/config/expcore/permission_groups.lua @@ -5,9 +5,9 @@ -- @config Permission-Groups -- local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event -local Permission_Groups = require("modules.exp_legacy.expcore.permission_groups") --- @dep expcore.permission_groups +local Groups = require("modules.exp_legacy.expcore.permission_groups") --- @dep expcore.permission_groups -Permission_Groups.new_group("Admin") +Groups.new_group("Admin") :allow_all() :disallow{ "add_permission_group", -- admin @@ -24,7 +24,7 @@ Permission_Groups.new_group("Admin") "set_infinity_pipe_filter", } -Permission_Groups.new_group("Trusted") +Groups.new_group("Trusted") :allow_all() :disallow{ "add_permission_group", -- admin @@ -42,7 +42,7 @@ Permission_Groups.new_group("Trusted") "admin_action", -- trusted } -Permission_Groups.new_group("Standard") +Groups.new_group("Standard") :allow_all() :disallow{ "add_permission_group", -- admin @@ -64,7 +64,7 @@ Permission_Groups.new_group("Standard") "set_rocket_silo_send_to_orbit_automated_mode", } -Permission_Groups.new_group("Guest") +Groups.new_group("Guest") :allow_all() :disallow{ "add_permission_group", -- admin @@ -99,7 +99,7 @@ Permission_Groups.new_group("Guest") "flush_opened_entity_specific_fluid", } -Permission_Groups.new_group("Restricted") +Groups.new_group("Restricted") :disallow_all() :allow("write_to_console") diff --git a/exp_legacy/module/config/expcore/roles.lua b/exp_legacy/module/config/expcore/roles.lua index 5cdb0ab3..faf905b6 100644 --- a/exp_legacy/module/config/expcore/roles.lua +++ b/exp_legacy/module/config/expcore/roles.lua @@ -210,8 +210,8 @@ Roles.new_role("Veteran", "Vet") return true else local stats = Statistics:get(player, {}) - local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 - return playTime - afkTime >= hours250 and mapCount >= 25 + local playtime, afk_time, map_count = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 + return playtime - afk_time >= hours250 and map_count >= 25 end end) @@ -259,8 +259,8 @@ Roles.new_role("Regular", "Reg") return true else local stats = Statistics:get(player, {}) - local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 - return playTime - afkTime >= hours15 and mapCount >= 5 + local playtime, afk_time, map_count = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 + return playtime - afk_time >= hours15 and map_count >= 5 end end) diff --git a/exp_legacy/module/modules/addons/compilatron.lua b/exp_legacy/module/modules/addons/compilatron.lua index 5105b898..5aab162e 100644 --- a/exp_legacy/module/modules/addons/compilatron.lua +++ b/exp_legacy/module/modules/addons/compilatron.lua @@ -76,9 +76,12 @@ function Public.add_compilatron(entity, name) end Public.compilatrons[name] = entity - local message = - entity.surface.create_entity - { name = "compi-speech-bubble", text = messages[name][1], position = { 0, 0 }, source = entity } + local message = entity.surface.create_entity{ + name = "compi-speech-bubble", + text = messages[name][1], + position = { 0, 0 }, + source = entity, + } Public.current_messages[name] = { message = message, msg_number = 1 } end diff --git a/exp_legacy/module/modules/addons/deconlog.lua b/exp_legacy/module/modules/addons/deconlog.lua index 5b941c6e..5eac1188 100644 --- a/exp_legacy/module/modules/addons/deconlog.lua +++ b/exp_legacy/module/modules/addons/deconlog.lua @@ -56,7 +56,14 @@ if config.decon_area then local items = e.surface.find_entities_filtered{ area = e.area, force = player.force } if #items > 250 then - print_to_players(true, { "deconlog.decon", player.name, e.surface.name, pos_to_gps_string(e.area.left_top), pos_to_gps_string(e.area.right_bottom), format_number(#items) }) + print_to_players(true, { + "deconlog.decon", + player.name, + e.surface.localised_name, + pos_to_gps_string(e.area.left_top), + pos_to_gps_string(e.area.right_bottom), + format_number(#items, false), + }) end add_log(get_secs() .. "," .. player.name .. ",decon_area," .. e.surface.name .. "," .. pos_to_string(e.area.left_top) .. "," .. pos_to_string(e.area.right_bottom)) diff --git a/exp_legacy/module/modules/addons/station-auto-name.lua b/exp_legacy/module/modules/addons/station-auto-name.lua index aea718d8..cefeeebe 100644 --- a/exp_legacy/module/modules/addons/station-auto-name.lua +++ b/exp_legacy/module/modules/addons/station-auto-name.lua @@ -15,10 +15,10 @@ local directions = { ["SW"] = 0.875, } -local function Angle(entity) +local function get_direction(entity) local angle = math.atan2(entity.position.y, entity.position.x) / math.pi - for direction, requiredAngle in pairs(directions) do - if angle < requiredAngle then + for direction, required_angle in pairs(directions) do + if angle < required_angle then return direction end end @@ -45,14 +45,14 @@ local function station_name_changer(event) return end - local boundingBox = entity.bounding_box + local bounding_box = entity.bounding_box -- expanded box for recourse search: - local bounding2 = { { boundingBox.left_top.x - 100, boundingBox.left_top.y - 100 }, { boundingBox.right_bottom.x + 100, boundingBox.right_bottom.y + 100 } } + local bounding2 = { { bounding_box.left_top.x - 100, bounding_box.left_top.y - 100 }, { bounding_box.right_bottom.x + 100, bounding_box.right_bottom.y + 100 } } -- gets all resources in bounding_box2: local recourses = game.surfaces[1].find_entities_filtered{ area = bounding2, type = "resource" } if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2 local closest_distance - local px, py = boundingBox.left_top.x, boundingBox.left_top.y + local px, py = bounding_box.left_top.x, bounding_box.left_top.y local recourse_closed -- Check which recourse is closest @@ -77,7 +77,7 @@ local function station_name_changer(event) entity.backer_name = config.station_name:gsub("__icon__", "[img=" .. item_type .. "." .. item_name .. "]") :gsub("__item_name__", item_name2) :gsub("__backer_name__", entity.backer_name) - :gsub("__direction__", Angle(entity)) + :gsub("__direction__", get_direction(entity)) :gsub("__x__", math.floor(entity.position.x)) :gsub("__y__", math.floor(entity.position.y)) end diff --git a/exp_legacy/module/modules/data/statistics.lua b/exp_legacy/module/modules/data/statistics.lua index b0a5c38e..08bcb7d5 100644 --- a/exp_legacy/module/modules/data/statistics.lua +++ b/exp_legacy/module/modules/data/statistics.lua @@ -40,7 +40,7 @@ Statistics:on_load(function(player_name, player_statistics) if new_players[player_name] then new_players[player_name] = nil local ctn = player_statistics.MapsPlayed - player_statistics.MapsPlayed = ctn and ctn + 1 or 1 + player_statistics["MapsPlayed"] = ctn and ctn + 1 or 1 end return player_statistics diff --git a/exp_legacy/module/modules/gui/bonus.lua b/exp_legacy/module/modules/gui/bonus.lua index b61790ee..a00670f0 100644 --- a/exp_legacy/module/modules/gui/bonus.lua +++ b/exp_legacy/module/modules/gui/bonus.lua @@ -20,8 +20,11 @@ local function bonus_gui_pts_needed(player) total = total + (disp["bonus_display_" .. k .. "_slider"].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost) end - total = total + - (disp["bonus_display_personal_battery_recharge_slider"].slider_value / config.player_special_bonus["personal_battery_recharge"].cost_scale * config.player_special_bonus["personal_battery_recharge"].cost) + total = total + ( + disp["bonus_display_personal_battery_recharge_slider"].slider_value + / config.player_special_bonus["personal_battery_recharge"].cost_scale + * config.player_special_bonus["personal_battery_recharge"].cost + ) return total end @@ -174,15 +177,15 @@ local bonus_gui_control_reset = disp[s].slider_value = config.player_bonus[v].value if config.player_bonus[v].is_percentage then - disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100) .. " %" + disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100, false) .. " %" else - disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value) + disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value, false) end end local slider = disp["bonus_display_personal_battery_recharge_slider"] slider.slider_value = config.player_special_bonus["personal_battery_recharge"].value - disp[slider.tags.counter].caption = format_number(slider.slider_value) + disp[slider.tags.counter].caption = format_number(slider.slider_value, false) local r = bonus_gui_pts_needed(player) element.parent[bonus_gui_control_pts_n_count.name].caption = r @@ -246,9 +249,9 @@ local bonus_gui_slider = local value = bonus.value if bonus.is_percentage then - value = format_number(value * 100) .. " %" + value = format_number(value * 100, false) .. " %" else - value = format_number(value) + value = format_number(value, false) end local slider = parent.add{ @@ -279,9 +282,9 @@ local bonus_gui_slider = end) :on_value_changed(function(player, element, _event) if element.tags.is_percentage then - element.parent[element.tags.counter].caption = format_number(element.slider_value * 100) .. " %" + element.parent[element.tags.counter].caption = format_number(element.slider_value * 100, false) .. " %" else - element.parent[element.tags.counter].caption = format_number(element.slider_value) + element.parent[element.tags.counter].caption = format_number(element.slider_value, false) end local r = bonus_gui_pts_needed(player) diff --git a/exp_legacy/module/modules/gui/debug/model.lua b/exp_legacy/module/modules/gui/debug/model.lua index 652344e1..77fa6f8f 100644 --- a/exp_legacy/module/modules/gui/debug/model.lua +++ b/exp_legacy/module/modules/gui/debug/model.lua @@ -10,10 +10,10 @@ local rawset = rawset local Public = {} -local luaObject = { "{", nil, ", name = '", nil, "'}" } -local luaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" } -local luaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" } -local luaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" } +local LuaObject = { "{", nil, ", name = '", nil, "'}" } +local LuaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" } +local LuaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" } +local LuaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" } local function get(obj, prop) return obj[prop] @@ -59,25 +59,25 @@ local function inspect_process(item) end if obj_type == "LuaPlayer" then - luaPlayer[2] = item.name or "nil" - luaPlayer[4] = item.index or "nil" + LuaPlayer[2] = item.name or "nil" + LuaPlayer[4] = item.index or "nil" - return concat(luaPlayer) + return concat(LuaPlayer) elseif obj_type == "LuaEntity" then - luaEntity[2] = item.name or "nil" - luaEntity[4] = item.unit_number or "nil" + LuaEntity[2] = item.name or "nil" + LuaEntity[4] = item.unit_number or "nil" - return concat(luaEntity) + return concat(LuaEntity) elseif obj_type == "LuaGuiElement" then local name = item.name - luaGuiElement[2] = gui_names and gui_names[name] or name or "nil" + LuaGuiElement[2] = gui_names and gui_names[name] or name or "nil" - return concat(luaGuiElement) + return concat(LuaGuiElement) else - luaObject[2] = obj_type - luaObject[4] = get_name_safe(item) + LuaObject[2] = obj_type + LuaObject[4] = get_name_safe(item) - return concat(luaObject) + return concat(LuaObject) end end diff --git a/exp_legacy/module/modules/gui/playerdata.lua b/exp_legacy/module/modules/gui/playerdata.lua index 46abcdf9..d1e5baa2 100644 --- a/exp_legacy/module/modules/gui/playerdata.lua +++ b/exp_legacy/module/modules/gui/playerdata.lua @@ -19,7 +19,7 @@ local label_width = { local short_time_format = ExpUtil.format_time_factory_locale{ format = "short", coefficient = 3600, hours = true, minutes = true } local function format_number_n(n) - return format_number(math.floor(n)) .. string.format("%.2f", n % 1):sub(2) + return format_number(math.floor(n), false) .. string.format("%.2f", n % 1):sub(2) end local PlayerStats = PlayerData.Statistics @@ -96,7 +96,7 @@ local pd_data_set = for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do local child = PlayerData.Statistics[stat_name] local metadata = child.metadata - local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0) + local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0, false) label(disp, label_width["name"], metadata.name or { "exp-statistics." .. stat_name }, metadata.tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }) label(disp, label_width["count"], { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name) end @@ -119,7 +119,7 @@ local function pd_update(table, player_name) elseif metadata.stringify then value = metadata.stringify(value or 0) else - value = format_number(value or 0) + value = format_number(value or 0, false) end table[stat_name].caption = { "readme.data-format", value, metadata.unit or "" } end diff --git a/exp_legacy/module/modules/gui/readme.lua b/exp_legacy/module/modules/gui/readme.lua index e48c7e89..77139ba8 100644 --- a/exp_legacy/module/modules/gui/readme.lua +++ b/exp_legacy/module/modules/gui/readme.lua @@ -372,7 +372,7 @@ define_tab({ "readme.data-tab" }, { "readme.data-tooltip" }, if metadata.stringify then value = metadata.stringify(value) else - value = format_number(value or 0) + value = format_number(value or 0, false) end Gui.centered_label(statistics, 150, metadata.name or { "exp-statistics." .. name }, metadata.tooltip or { "exp-statistics." .. name .. "-tooltip" }) Gui.centered_label(statistics, 130, { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. name .. "-tooltip" }) diff --git a/exp_legacy/module/modules/gui/task-list.lua b/exp_legacy/module/modules/gui/task-list.lua index 525a9e82..5ee310a4 100644 --- a/exp_legacy/module/modules/gui/task-list.lua +++ b/exp_legacy/module/modules/gui/task-list.lua @@ -144,12 +144,11 @@ local subfooter_frame = style = "subfooter_frame", } end - ):style - { - padding = 5, - use_header_filler = false, - horizontally_stretchable = true, - } + ):style{ + padding = 5, + use_header_filler = false, + horizontally_stretchable = true, + } --- Label element preset @@ -351,22 +350,21 @@ local task_message_textfield = name = Gui.unique_static_name, type = "text-box", text = "", - }:style - { - maximal_width = 268, - minimal_height = 100, - horizontally_stretchable = true, - } + }:style{ + maximal_width = 268, + minimal_height = 100, + horizontally_stretchable = true, + } :on_text_changed( function(player, element, _) - local isEditing = PlayerIsEditing:get(player) - local isCreating = PlayerIsCreating:get(player) + local is_editing = PlayerIsEditing:get(player) + local is_creating = PlayerIsCreating:get(player) local valid = string.len(element.text) > 5 - if isCreating then + if is_creating then element.parent.actions[task_create_confirm_button.name].enabled = valid - elseif isEditing then + elseif is_editing then element.parent.actions[task_edit_confirm_button.name].enabled = valid end end @@ -676,8 +674,8 @@ PlayerSelected:on_update( local task_list_element = frame.container.scroll.task_list local view_flow = frame.container.view local edit_flow = frame.container.edit - local isEditing = PlayerIsEditing:get(player) - local isCreating = PlayerIsCreating:get(player) + local is_editing = PlayerIsEditing:get(player) + local is_creating = PlayerIsCreating:get(player) -- If the selection has an previous state re-enable the button list element if prev_state then @@ -692,12 +690,12 @@ PlayerSelected:on_update( update_task_view_footer(player, curr_state) -- If a player is creating then remove the creation dialogue - if isCreating then + if is_creating then PlayerIsCreating:set(player, false) end -- Depending on if the player is currently editing change the current task edit footer to the current task - if isEditing then + if is_editing then update_task_edit_footer(player, curr_state) Tasks.set_editing(prev_state, player.name, nil) Tasks.set_editing(curr_state, player.name, true) @@ -756,8 +754,8 @@ local function role_update_event(event) local has_permission = check_player_permissions(player) local add_new_task_element = container.header.alignment[add_new_task.name] add_new_task_element.visible = has_permission - local isCreating = PlayerIsCreating:get(player) - if isCreating and not has_permission then + local is_creating = PlayerIsCreating:get(player) + if is_creating and not has_permission then PlayerIsCreating:set(player, false) end end diff --git a/exp_legacy/module/modules/gui/vlayer.lua b/exp_legacy/module/modules/gui/vlayer.lua index 9047a6a2..926af2b6 100644 --- a/exp_legacy/module/modules/gui/vlayer.lua +++ b/exp_legacy/module/modules/gui/vlayer.lua @@ -487,14 +487,14 @@ Event.on_nth_tick(config.update_tick_gui, function(_) local vlayer_display = { [vlayer_gui_display_item_solar_count.name] = { val = (items_alloc["solar-panel"] / math.max(items["solar-panel"], 1)), - cap = format_number(items_alloc["solar-panel"]) .. " / " .. format_number(items["solar-panel"]), + cap = format_number(items_alloc["solar-panel"], false) .. " / " .. format_number(items["solar-panel"], false), }, [vlayer_gui_display_item_accumulator_count.name] = { val = (items_alloc["accumulator"] / math.max(items["accumulator"], 1)), - cap = format_number(items_alloc["accumulator"]) .. " / " .. format_number(items["accumulator"]), + cap = format_number(items_alloc["accumulator"], false) .. " / " .. format_number(items["accumulator"], false), }, [vlayer_gui_display_signal_remaining_surface_area_count.name] = { - cap = format_number(stats.remaining_surface_area), + cap = format_number(stats.remaining_surface_area, false), }, [vlayer_gui_display_signal_sustained_count.name] = { cap = format_energy(stats.energy_sustained, "W"), diff --git a/exp_scenario/module/commands/protected_entities.lua b/exp_scenario/module/commands/protected_entities.lua index 97a9f0ee..59626dd6 100644 --- a/exp_scenario/module/commands/protected_entities.lua +++ b/exp_scenario/module/commands/protected_entities.lua @@ -18,8 +18,8 @@ local EntityProtection = require("modules.exp_legacy.modules.control.protection" local format_string = string.format local floor = math.floor -local SelectionName_Entity = "ExpCommand_ProtectEntity" -local SelectionName_Area = "ExpCommand_ProtectArea" +local SelectionNameEntity = "ExpCommand_ProtectEntity" +local SelectionNameArea = "ExpCommand_ProtectArea" local renders = {} --- @type table> Stores all renders for a player Storage.register({ @@ -95,11 +95,11 @@ end Commands.new("protect-entity", { "exp-commands_protection.description-entity" }) :add_aliases{ "pe" } :register(function(player) - if Selection.is_selecting(player, SelectionName_Entity) then + if Selection.is_selecting(player, SelectionNameEntity) then Selection.stop(player) return Commands.status.success{ "exp-commands_protection.exit-entity" } else - Selection.start(player, SelectionName_Entity) + Selection.start(player, SelectionNameEntity) return Commands.status.success{ "exp-commands_protection.enter-entity" } end end) @@ -108,17 +108,17 @@ Commands.new("protect-entity", { "exp-commands_protection.description-entity" }) Commands.new("protect-area", { "exp-commands_protection.description-area" }) :add_aliases{ "pa" } :register(function(player) - if Selection.is_selecting(player, SelectionName_Entity) then + if Selection.is_selecting(player, SelectionNameEntity) then Selection.stop(player) return Commands.status.success{ "exp-commands_protection.exit-area" } else - Selection.start(player, SelectionName_Entity) + Selection.start(player, SelectionNameEntity) return Commands.status.success{ "exp-commands_protection.enter-area" } end end) --- When an area is selected to add protection to entities -Selection.on_selection(SelectionName_Entity, function(event) +Selection.on_selection(SelectionNameEntity, function(event) --- @cast event EventData.on_player_selected_area local player = game.players[event.player_index] for _, entity in ipairs(event.entities) do @@ -130,7 +130,7 @@ Selection.on_selection(SelectionName_Entity, function(event) end) --- When an area is selected to remove protection from entities -Selection.on_alt_selection(SelectionName_Entity, function(event) +Selection.on_alt_selection(SelectionNameEntity, function(event) --- @cast event EventData.on_player_alt_selected_area local player = game.players[event.player_index] for _, entity in ipairs(event.entities) do @@ -142,7 +142,7 @@ Selection.on_alt_selection(SelectionName_Entity, function(event) end) --- When an area is selected to add protection to the area -Selection.on_selection(SelectionName_Area, function(event) +Selection.on_selection(SelectionNameArea, function(event) --- @cast event EventData.on_player_selected_area local surface = event.surface local area = expand_area(event.area) @@ -160,7 +160,7 @@ Selection.on_selection(SelectionName_Area, function(event) end) --- When an area is selected to remove protection from the area -Selection.on_alt_selection(SelectionName_Area, function(event) +Selection.on_alt_selection(SelectionNameArea, function(event) --- @cast event EventData.on_player_alt_selected_area local surface = event.surface local area = expand_area(event.area) @@ -177,7 +177,7 @@ end) --- When selection starts show all protected entities and protected areas local function on_player_selection_start(event) - if event.selection ~= SelectionName_Entity and event.selection ~= SelectionName_Area then return end + if event.selection ~= SelectionNameEntity and event.selection ~= SelectionNameArea then return end local player = game.players[event.player_index] local surface = player.surface -- Allow remote view renders[player.index] = {} @@ -211,7 +211,7 @@ end --- When selection ends hide protected entities and protected areas local function on_player_selection_end(event) - if event.selection ~= SelectionName_Entity and event.selection ~= SelectionName_Area then return end + if event.selection ~= SelectionNameEntity and event.selection ~= SelectionNameArea then return end for _, render in pairs(renders[event.player_index]) do if render.valid then render.destroy() end end