From 3145f7e9043b0f07f7c0c008dd041b28b152cb1f Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sat, 28 Sep 2024 03:46:14 +0100 Subject: [PATCH] No more warnings --- .luarc.json | 7 +- exp_commands/module/module_exports.lua | 3 +- exp_legacy/module/config/warnings.lua | 20 ++++- exp_legacy/module/control.lua | 3 + exp_legacy/module/expcore/common.lua | 28 ++++--- exp_legacy/module/expcore/datastore.lua | 84 +++++++++---------- exp_legacy/module/expcore/gui/_require.lua | 4 +- exp_legacy/module/expcore/gui/prototype.lua | 1 + .../module/expcore/permission_groups.lua | 58 ++++++------- exp_legacy/module/expcore/player_data.lua | 16 ++-- exp_legacy/module/expcore/roles.lua | 5 +- exp_legacy/module/modules/addons/afk-kick.lua | 2 +- .../module/modules/addons/death-logger.lua | 1 + exp_legacy/module/modules/addons/deconlog.lua | 18 ++-- exp_legacy/module/modules/addons/inserter.lua | 2 +- .../module/modules/addons/inventory-clear.lua | 2 +- .../module/modules/addons/nukeprotect.lua | 2 +- .../module/modules/addons/protection-jail.lua | 2 +- .../module/modules/addons/report-jail.lua | 2 +- .../module/modules/addons/spawn-area.lua | 3 +- .../module/modules/commands/admin-markers.lua | 6 +- .../module/modules/commands/artillery.lua | 2 +- .../module/modules/commands/connect.lua | 2 +- exp_legacy/module/modules/commands/help.lua | 1 + .../module/modules/commands/interface.lua | 1 + .../module/modules/commands/protection.lua | 24 +++--- .../module/modules/commands/waterfill.lua | 2 +- .../module/modules/control/protection.lua | 2 +- .../module/modules/control/selection.lua | 4 +- exp_legacy/module/modules/control/tasks.lua | 4 +- exp_legacy/module/modules/data/greetings.lua | 2 +- .../module/modules/graftorio/forcestats.lua | 2 +- .../module/modules/graftorio/general.lua | 8 +- exp_legacy/module/modules/gui/autofill.lua | 6 +- exp_legacy/module/modules/gui/module.lua | 2 +- exp_legacy/module/modules/gui/player-list.lua | 2 +- exp_legacy/module/modules/gui/readme.lua | 18 ++-- exp_legacy/module/modules/gui/vlayer.lua | 4 +- exp_legacy/module/overrides/table.lua | 7 +- exp_legacy/module/utils/gui.lua | 2 +- exp_util/module/common.lua | 15 ++-- exp_util/module/floating_text.lua | 6 +- exp_util/module/include/table.lua | 7 +- 43 files changed, 215 insertions(+), 177 deletions(-) diff --git a/.luarc.json b/.luarc.json index 21171f6f..eaed9d20 100644 --- a/.luarc.json +++ b/.luarc.json @@ -43,7 +43,7 @@ }, "pascal_case"], "function_param_name_style": [{ "type" : "pattern", - "param": "_?_?(\\w+)", + "param": "_?_?(\\w+)?", "$1": "snake_case" }], "function_name_style": [{ @@ -61,7 +61,10 @@ "param": "_?_?(\\w+)", "$1": "snake_case" }], - "global_variable_name_style": "upper_snake_case", + "global_variable_name_style": [{ + "type": "ignore", + "param": ["_VERSION"] + }, "snake_case", "upper_snake_case" ], "module_name_style": [ "pascal_case", "snake_case" ], "require_module_name_style": [ "pascal_case", "snake_case" ], "class_name_style": "pascal_case", diff --git a/exp_commands/module/module_exports.lua b/exp_commands/module/module_exports.lua index 90c13fb6..3b3e866a 100644 --- a/exp_commands/module/module_exports.lua +++ b/exp_commands/module/module_exports.lua @@ -536,6 +536,7 @@ function Commands._prototype:register(callback) local function command_callback(event) event.name = self.name local success, traceback = xpcall(Commands._event_handler, debug.traceback, event) + --- @cast traceback string if not success and not traceback:find("Command does not support rcon usage") then local _, msg = Commands.status.internal_error(event.tick) Commands.error(msg) @@ -618,7 +619,7 @@ function Commands._event_handler(event) local player = nil -- nil represents the server until the command is called if event.player_index then - player = game.get_player(event.player_index) + player = game.players[event.player_index] end -- Check if the player is allowed to use the command diff --git a/exp_legacy/module/config/warnings.lua b/exp_legacy/module/config/warnings.lua index 3684a088..e098dc2f 100644 --- a/exp_legacy/module/config/warnings.lua +++ b/exp_legacy/module/config/warnings.lua @@ -8,12 +8,28 @@ return { { "warnings.received", "" }, { "warnings.received", { "warnings.pre-kick" } }, function(player, by_player_name, number_of_warnings) - game.kick_player(player, { "warnings.received", by_player_name, number_of_warnings, { "warnings.kick" } }) + local str = { + "You received a warning from ", + by_player_name, + ". You have ", + number_of_warnings, + " warnings. You were kicked for having too many warnings; you may rejoin if you wish.", + } + game.kick_player(player, table.concat(str, "")) -- Does not support locale strings + -- game.kick_player(player, { "warnings.received", by_player_name, number_of_warnings, { "warnings.kick" } }) end, { "warnings.received", { "warnings.pre-pre-ban" } }, { "warnings.received", { "warnings.pre-ban" } }, function(player, by_player_name, number_of_warnings) - game.ban_player(player, { "warnings.received", by_player_name, number_of_warnings, { "warnings.ban", { "links.website" } } }) + local str = { + "You received a warning from ", + by_player_name, + ". You have ", + number_of_warnings, + " warnings. You were banned for having too many warnings; visit https://www.explosivegaming.nl to request a ban appeal.", + } + game.kick_player(player, table.concat(str, "")) -- Does not support locale strings + -- game.ban_player(player, { "warnings.received", by_player_name, number_of_warnings, { "warnings.ban", { "links.website" } } }) end, }, script_warning_cool_down = 30, --- @setting script_warning_cool_down time for a script warning (given by script) to be removed (in minutes) diff --git a/exp_legacy/module/control.lua b/exp_legacy/module/control.lua index 6dbed200..361d37f9 100644 --- a/exp_legacy/module/control.lua +++ b/exp_legacy/module/control.lua @@ -4,11 +4,13 @@ -- this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development local _xpcall = xpcall +--- @diagnostic disable xpcall = function(func, error_handler, ...) local rtn = { _xpcall(func, error_handler, ...) } if not rtn[1] then error(rtn[2]) end return table.unpack(rtn) end +--- @diagnostic enable log("[START] -----| Explosive Gaming Scenario Loader |-----") log("[INFO] Setting up lua environment") @@ -16,6 +18,7 @@ log("[INFO] Setting up lua environment") -- Require the global overrides require("modules.exp_legacy.overrides.table") -- Adds alot more functions to the table module storage.version = require("modules.exp_legacy.overrides.version") -- The current version for exp gaming scenario +--- @diagnostic disable-next-line _C = require("modules.exp_legacy.expcore.common") -- _C is used to store lots of common functions expected to be used -- Please go to config/file_loader.lua to edit the files that are loaded diff --git a/exp_legacy/module/expcore/common.lua b/exp_legacy/module/expcore/common.lua index 9e36490c..cfa14407 100644 --- a/exp_legacy/module/expcore/common.lua +++ b/exp_legacy/module/expcore/common.lua @@ -398,26 +398,26 @@ function Common.player_return(value, colour, player) colour = Common.type_check(colour, "table") and colour or Colours[colour] ~= Colours.white and Colours[colour] or Colours.white player = player or game.player -- converts the value to a string - local returnAsString + local string_return if Common.type_check(value, "table") or type(value) == "userdata" then if Common.type_check(value.__self, "userdata") or type(value) == "userdata" then -- value is userdata - returnAsString = "Cant Display Userdata" + string_return = "Cant Display Userdata" elseif Common.type_check(value[1], "string") and string.find(value[1], ".+[.].+") and not string.find(value[1], "%s") then -- value is a locale string - returnAsString = value + string_return = value elseif getmetatable(value) ~= nil and not tostring(value):find("table: 0x") then -- value has a tostring meta method - returnAsString = tostring(value) + string_return = tostring(value) else -- value is a table - returnAsString = table.inspect(value, { depth = 5, indent = " ", newline = "\n" }) + string_return = table.inspect(value, { depth = 5, indent = " ", newline = "\n" }) end elseif Common.type_check(value, "function") then -- value is a function - returnAsString = "Cant Display Functions" + string_return = "Cant Display Functions" else - returnAsString = tostring(value) + string_return = tostring(value) end -- returns to the player or the server if player then @@ -426,9 +426,9 @@ function Common.player_return(value, colour, player) if not player then error("Invalid Player given to player_return", 2) end -- plays a nice sound that is different to normal message sound player.play_sound{ path = "utility/scenario_message" } - player.print(returnAsString, colour) + player.print(string_return, colour) else - rcon.print(returnAsString) + rcon.print(string_return) end end @@ -469,7 +469,11 @@ function Common.format_time(ticks, options) local days, hours = max_days, max_hours - math.floor(max_days) * 24 local minutes, seconds = max_minutes - math.floor(max_hours) * 60, max_seconds - math.floor(max_minutes) * 60 -- Handles overflow of disabled denominations - local rtn_days, rtn_hours, rtn_minutes, rtn_seconds = math.floor(days), math.floor(hours), math.floor(minutes), math.floor(seconds) + local rtn_days, rtn_hours, rtn_minutes, rtn_seconds = + math.floor(days) --[[@as string | number | table]], + math.floor(hours) --[[@as string | number | table]], + math.floor(minutes) --[[@as string | number | table]], + math.floor(seconds) --[[@as string | number | table]] if not options.days then rtn_hours = rtn_hours + rtn_days * 24 end @@ -496,10 +500,10 @@ function Common.format_time(ticks, options) local div = options.string and " " or "time-format.simple-format-tagged" if options.time then div = options.string and ":" or "time-format.simple-format-div" - suffix = false + -- suffix = false -- Can't get the types to work end -- Adds formatting - if suffix ~= false then + if not options.time then -- Can't get the types to work if options.string then -- format it as a string local long = suffix == "" diff --git a/exp_legacy/module/expcore/datastore.lua b/exp_legacy/module/expcore/datastore.lua index 27b5d278..25119be3 100644 --- a/exp_legacy/module/expcore/datastore.lua +++ b/exp_legacy/module/expcore/datastore.lua @@ -158,8 +158,8 @@ local trace = debug.traceback --- Save datastores in the global table Storage.register(Data, function(tbl) Data = tbl - for datastoreName, datastore in pairs(Datastores) do - datastore.data = Data[datastoreName] + for name, datastore in pairs(Datastores) do + datastore.data = Data[name] end end) @@ -174,7 +174,7 @@ DatastoreManager.metatable = { } --[[-- Make a new datastore connection, if a connection already exists then it is returned -@tparam string datastoreName The name that you want the new datastore to have, this can not have any whitespace +@tparam string datastore_name The name that you want the new datastore to have, this can not have any whitespace @tparam[opt=false] boolean saveToDisk When set to true, using the save method with write the data to datastore.pipe @tparam[opt=false] boolean autoSave When set to true, using any method which modifies data will cause the data to be saved @tparam[opt=false] boolean propagateChanges When set to true, using the save method will send the data to all other connected servers @@ -184,19 +184,19 @@ DatastoreManager.metatable = { local ExampleData = Datastore.connect('ExampleData', true) -- saveToDisk ]] -function DatastoreManager.connect(datastoreName, saveToDisk, autoSave, propagateChanges) - if Datastores[datastoreName] then return Datastores[datastoreName] end +function DatastoreManager.connect(datastore_name, save_to_disk, autosave, propagate_changes) + if Datastores[datastore_name] then return Datastores[datastore_name] end if package.lifecycle ~= package.lifecycle_stage.control then -- Only allow this function to be called during the control stage error("New datastore connection can not be created during runtime", 2) end local new_datastore = { - name = datastoreName, - value_name = datastoreName, - auto_save = autoSave or false, - save_to_disk = saveToDisk or false, - propagate_changes = propagateChanges or false, + name = datastore_name, + value_name = datastore_name, + auto_save = autosave or false, + save_to_disk = save_to_disk or false, + propagate_changes = propagate_changes or false, serializer = false, parent = false, children = {}, @@ -205,28 +205,28 @@ function DatastoreManager.connect(datastoreName, saveToDisk, autoSave, propagate data = {}, } - Data[datastoreName] = new_datastore.data - Datastores[datastoreName] = new_datastore + Data[datastore_name] = new_datastore.data + Datastores[datastore_name] = new_datastore return setmetatable(new_datastore, DatastoreManager.metatable) end --[[-- Make a new datastore that stores its data inside of another one -@tparam string datastoreName The name of the datastore that will contain the data for the new datastore -@tparam string subDatastoreName The name of the new datastore, this name will also be used as the key inside the parent datastore +@tparam string datastore_name The name of the datastore that will contain the data for the new datastore +@tparam string subdatastore_name The name of the new datastore, this name will also be used as the key inside the parent datastore @treturn table The new datastore connection that can be used to access and modify data in the datastore @usage-- Setting up a datastore which stores its data inside of another datastore local BarData = Datastore.combine('ExampleData', 'Bar') ]] -function DatastoreManager.combine(datastoreName, subDatastoreName) - local datastore = assert(Datastores[datastoreName], "Datastore not found " .. tostring(datastoreName)) - return datastore:combine(subDatastoreName) +function DatastoreManager.combine(datastore_name, subdatastore_name) + local datastore = assert(Datastores[datastore_name], "Datastore not found " .. tostring(datastore_name)) + return datastore:combine(subdatastore_name) end --[[-- Ingest the result from a request, this is used through a rcon interface to sync data @tparam string action The action that should be done, can be: remove, message, propagate, or request -@tparam string datastoreName The name of the datastore that should have the action done to it +@tparam string datastore_name The name of the datastore that should have the action done to it @tparam string key The key of that datastore that is having the action done to it @tparam string valueJson The json string for the value being ingested, remove does not require a value @@ -234,20 +234,20 @@ end Datastore.ingest('request', 'ExampleData', 'TestKey', 'Foo') ]] -function DatastoreManager.ingest(action, datastoreName, key, valueJson) - local datastore = assert(Datastores[datastoreName], "Datastore ingest error, Datastore not found " .. tostring(datastoreName)) +function DatastoreManager.ingest(action, datastore_name, key, value_json) + local datastore = assert(Datastores[datastore_name], "Datastore ingest error, Datastore not found " .. tostring(datastore_name)) assert(type(action) == "string", "Datastore ingest error, Action is not a string got: " .. type(action)) assert(type(key) == "string", "Datastore ingest error, Key is not a string got: " .. type(key)) if action == "remove" then datastore:raw_set(key) elseif action == "message" then - local success, value = pcall(game.json_to_table, valueJson) - if not success or value == nil then value = tonumber(valueJson) or valueJson end + local success, value = pcall(game.json_to_table, value_json) + if not success or value == nil then value = tonumber(value_json) or value_json end datastore:raise_event("on_message", key, value) elseif action == "propagate" or action == "request" then - local success, value = pcall(game.json_to_table, valueJson) - if not success or value == nil then value = tonumber(valueJson) or valueJson end + local success, value = pcall(game.json_to_table, value_json) + if not success or value == nil then value = tonumber(value_json) or value_json end local old_value = datastore:raw_get(key) value = datastore:raise_event("on_load", key, value, old_value) datastore:set(key, value) @@ -255,7 +255,7 @@ function DatastoreManager.ingest(action, datastoreName, key, valueJson) end --[[-- Debug, Use to get all datastores, or return debug info on a datastore -@tparam[opt] string datastoreName The name of the datastore to get the debug info of +@tparam[opt] string datastore_name The name of the datastore to get the debug info of @usage-- Get all the datastores local datastores = Datastore.debug() @@ -264,9 +264,9 @@ local datastores = Datastore.debug() local debug_info = Datastore.debug('ExampleData') ]] -function DatastoreManager.debug(datastoreName) - if not datastoreName then return Datastores end - local datastore = assert(Datastores[datastoreName], "Datastore not found " .. tostring(datastoreName)) +function DatastoreManager.debug(datastore_name) + if not datastore_name then return Datastores end + local datastore = assert(Datastores[datastore_name], "Datastore not found " .. tostring(datastore_name)) return datastore:debug() end @@ -279,8 +279,8 @@ local ExampleData = Datastore.connect('ExampleData') ExampleData:set_serializer(Datastore.name_serializer) ]] -function DatastoreManager.name_serializer(rawKey) - return rawKey.name +function DatastoreManager.name_serializer(raw_key) + return raw_key.name end ----- Datastore Internal @@ -328,7 +328,7 @@ end local value = self:raw_get('TestKey') ]] -function Datastore:raw_get(key, fromChild) +function Datastore:raw_get(key, from_child) local data = self.data if self.parent then data = self.parent:raw_get(key, true) @@ -336,7 +336,7 @@ function Datastore:raw_get(key, fromChild) end local value = data[key] if value ~= nil then return value end - if fromChild then value = {} end + if from_child then value = {} end data[key] = value return value end @@ -367,10 +367,10 @@ local function serialize_error(err) error("An error ocurred in a datastore seria key = self:serialize(key) ]] -function Datastore:serialize(rawKey) - if type(rawKey) == "string" then return rawKey end +function Datastore:serialize(raw_key) + if type(raw_key) == "string" then return raw_key end assert(self.serializer, "Datastore does not have a serializer and received non string key") - local success, key = xpcall(self.serializer, serialize_error, rawKey) + local success, key = xpcall(self.serializer, serialize_error, raw_key) return success and key or nil end @@ -398,7 +398,7 @@ end -- @section datastore-local --[[-- Create a new datastore which is stores its data inside of this datastore -@tparam string subDatastoreName The name of the datastore that will have its data stored in this datastore +@tparam string subdatastore_name The name of the datastore that will have its data stored in this datastore @treturn table The new datastore that was created inside of this datastore @usage-- Add a new sub datastore @@ -406,10 +406,10 @@ local ExampleData = Datastore.connect('ExampleData') local BarData = ExampleData:combine('Bar') ]] -function Datastore:combine(subDatastoreName) - local new_datastore = DatastoreManager.connect(self.name .. "." .. subDatastoreName) - self.children[subDatastoreName] = new_datastore - new_datastore.value_name = subDatastoreName +function Datastore:combine(subdatastore_name) + local new_datastore = DatastoreManager.connect(self.name .. "." .. subdatastore_name) + self.children[subdatastore_name] = new_datastore + new_datastore.value_name = subdatastore_name new_datastore.serializer = self.serializer new_datastore.auto_save = self.auto_save new_datastore.parent = self @@ -442,9 +442,9 @@ local ExampleData = Datastore.connect('ExampleData') ExampleData:set_default('Foo') ]] -function Datastore:set_default(value, allowSet) +function Datastore:set_default(value, allow_set) self.default = value - self.allow_set_to_default = allowSet + self.allow_set_to_default = allow_set end --[[-- Set metadata tags on this datastore which can be accessed by other scripts diff --git a/exp_legacy/module/expcore/gui/_require.lua b/exp_legacy/module/expcore/gui/_require.lua index ab2ca4ec..1b0c47af 100644 --- a/exp_legacy/module/expcore/gui/_require.lua +++ b/exp_legacy/module/expcore/gui/_require.lua @@ -133,10 +133,10 @@ local Event = _C.opt_require("modules/exp_legacy/utils/event") if Roles and Event then Event.add(Roles.events.on_role_assigned, function(e) - Gui.update_top_flow(game.get_player(e.player_index)) + Gui.update_top_flow(game.players[e.player_index]) end) Event.add(Roles.events.on_role_unassigned, function(e) - Gui.update_top_flow(game.get_player(e.player_index)) + Gui.update_top_flow(game.players[e.player_index]) end) end diff --git a/exp_legacy/module/expcore/gui/prototype.lua b/exp_legacy/module/expcore/gui/prototype.lua index f6cfcfbf..0f4e3936 100644 --- a/exp_legacy/module/expcore/gui/prototype.lua +++ b/exp_legacy/module/expcore/gui/prototype.lua @@ -226,6 +226,7 @@ function Gui._prototype_element:triggers_events(element) element.tags = { ExpGui_event_triggers = { self.uid } } return element elseif not tags.ExpGui_event_triggers then + --- @diagnostic disable-next-line: name-style-check tags.ExpGui_event_triggers = { self.uid } elseif table.array_contains(tags.ExpGui_event_triggers, self.uid) then error("Element::triggers_events called multiple times on the same element with the same definition") diff --git a/exp_legacy/module/expcore/permission_groups.lua b/exp_legacy/module/expcore/permission_groups.lua index 5f97821f..fd74fc6f 100644 --- a/exp_legacy/module/expcore/permission_groups.lua +++ b/exp_legacy/module/expcore/permission_groups.lua @@ -27,7 +27,7 @@ local Game = require("modules.exp_legacy.utils.game") --- @dep utils.game local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Async = require("modules/exp_util/async") -local Permissions_Groups = { +local PermissionsGroups = { groups = {}, -- store for the different groups that are created _prototype = {}, -- stores functions that are used on group instances } @@ -37,14 +37,14 @@ local add_to_permission_group_async = Async.register(function(permission_group, player) permission_group.add_player(player) end) -Permissions_Groups.add_to_permission_group_async = add_to_permission_group_async +PermissionsGroups.add_to_permission_group_async = add_to_permission_group_async -- Async function to remove players from permission groups local remove_from_permission_group_async = Async.register(function(permission_group, player) permission_group.remove_player(player) end) -Permissions_Groups.remove_from_permission_group_async = remove_from_permission_group_async +PermissionsGroups.remove_from_permission_group_async = remove_from_permission_group_async --- Getters. -- Functions that get permission groups @@ -58,15 +58,15 @@ Permissions_Groups.remove_from_permission_group_async = remove_from_permission_g Groups.new_group('Admin') ]] -function Permissions_Groups.new_group(name) +function PermissionsGroups.new_group(name) local group = setmetatable({ name = name, actions = {}, allow_all_actions = true, }, { - __index = Permissions_Groups._prototype, + __index = PermissionsGroups._prototype, }) - Permissions_Groups.groups[name] = group + PermissionsGroups.groups[name] = group return group end @@ -78,8 +78,8 @@ end local admin_group = Groups.get_group_by_name('Admin') ]] -function Permissions_Groups.get_group_by_name(name) - return Permissions_Groups.groups[name] +function PermissionsGroups.get_group_by_name(name) + return PermissionsGroups.groups[name] end --[[-- Returns the group that a player is in @@ -90,12 +90,12 @@ end local group = Groups.get_group_from_player(game.player) ]] -function Permissions_Groups.get_group_from_player(player) +function PermissionsGroups.get_group_from_player(player) player = Game.get_player_from_any(player) if not player then return end local group = player.permission_group if group then - return Permissions_Groups.groups[group.name] + return PermissionsGroups.groups[group.name] end end @@ -109,8 +109,8 @@ end Groups.reload_permissions() ]] -function Permissions_Groups.reload_permissions() - for _, group in pairs(Permissions_Groups.groups) do +function PermissionsGroups.reload_permissions() + for _, group in pairs(PermissionsGroups.groups) do group:create() end end @@ -124,9 +124,9 @@ end Groups.set_player_group(game.player, 'Admin') ]] -function Permissions_Groups.set_player_group(player, group) +function PermissionsGroups.set_player_group(player, group) player = Game.get_player_from_any(player) - group = Permissions_Groups.get_group_by_name(group) + group = PermissionsGroups.get_group_by_name(group) if not group or not player then return false end group:add_player(player) return true @@ -145,7 +145,7 @@ end group:set_action('toggle_map_editor', false) ]] -function Permissions_Groups._prototype:set_action(action, state) +function PermissionsGroups._prototype:set_action(action, state) local input_action = defines.input_action[action] if input_action == nil then input_action = action end assert(type(input_action) == "number", tostring(action) .. " is not a valid input action") @@ -163,7 +163,7 @@ group:allow{ } ]] -function Permissions_Groups._prototype:allow(actions) +function PermissionsGroups._prototype:allow(actions) if type(actions) ~= "table" then actions = { actions } end @@ -188,7 +188,7 @@ group:disallow{ } ]] -function Permissions_Groups._prototype:disallow(actions) +function PermissionsGroups._prototype:disallow(actions) if type(actions) ~= "table" then actions = { actions } end @@ -206,7 +206,7 @@ end group:allow_all() ]] -function Permissions_Groups._prototype:allow_all() +function PermissionsGroups._prototype:allow_all() self.allow_all_actions = true return self end @@ -218,7 +218,7 @@ end group:disallow_all() ]] -function Permissions_Groups._prototype:disallow_all() +function PermissionsGroups._prototype:disallow_all() self.allow_all_actions = false return self end @@ -231,7 +231,7 @@ end local allowed = group:is_allowed('write_to_console') ]] -function Permissions_Groups._prototype:is_allowed(action) +function PermissionsGroups._prototype:is_allowed(action) if type(action) == "string" then action = defines.input_action[action] end @@ -253,10 +253,10 @@ end group:create() ]] -function Permissions_Groups._prototype:create() +function PermissionsGroups._prototype:create() local group = self:get_raw() if not group then - group = game.permissions.create_group(self.name) + group = game.permissions.create_group(self.name) --[[@as LuaPermissionGroup]] end for _, action in pairs(defines.input_action) do group.set_allows_action(action, self:is_allowed(action)) @@ -272,7 +272,7 @@ end local permission_group = group:get_raw() ]] -function Permissions_Groups._prototype:get_raw() +function PermissionsGroups._prototype:get_raw() return game.permissions.get_group(self.name) end @@ -284,7 +284,7 @@ end group:add_player(game.player) ]] -function Permissions_Groups._prototype:add_player(player) +function PermissionsGroups._prototype:add_player(player) player = Game.get_player_from_any(player) local group = self:get_raw() if not group or not player then return false end @@ -300,7 +300,7 @@ end group:remove_player(game.player) ]] -function Permissions_Groups._prototype:remove_player(player) +function PermissionsGroups._prototype:remove_player(player) player = Game.get_player_from_any(player) local group = self:get_raw() if not group or not player then return false end @@ -319,7 +319,7 @@ local online_players = group:get_players() local online_players = group:get_players(true) ]] -function Permissions_Groups._prototype:get_players(online) +function PermissionsGroups._prototype:get_players(online) local players = {} local group = self:get_raw() if group then @@ -344,7 +344,7 @@ end group:print('Hello, World!') ]] -function Permissions_Groups._prototype:print(message) +function PermissionsGroups._prototype:print(message) local players = self:get_players(true) for _, player in pairs(players) do player.print(message) @@ -355,7 +355,7 @@ end -- when the game starts it will make the permission groups Event.on_init(function() - Permissions_Groups.reload_permissions() + PermissionsGroups.reload_permissions() end) -return Permissions_Groups +return PermissionsGroups diff --git a/exp_legacy/module/expcore/player_data.lua b/exp_legacy/module/expcore/player_data.lua index c7c60b17..1df12c5f 100644 --- a/exp_legacy/module/expcore/player_data.lua +++ b/exp_legacy/module/expcore/player_data.lua @@ -107,23 +107,23 @@ end) --- Remove data that the player doesnt want to have stored PlayerData:on_save(function(player_name, player_data) - local dataPreference = DataSavingPreference:get(player_name) - dataPreference = PreferenceEnum[dataPreference] - if dataPreference == PreferenceEnum.All then + local data_preference = DataSavingPreference:get(player_name) + data_preference = PreferenceEnum[data_preference] + if data_preference == PreferenceEnum.All then player_data.valid = nil return player_data end - local saved_player_data = { PlayerRequired = player_data.PlayerRequired, DataSavingPreference = PreferenceEnum[dataPreference] } - if dataPreference <= PreferenceEnum.Settings then saved_player_data.PlayerSettings = player_data.PlayerSettings end - if dataPreference <= PreferenceEnum.Statistics then saved_player_data.PlayerStatistics = player_data.PlayerStatistics end + local saved_player_data = { PlayerRequired = player_data.PlayerRequired, DataSavingPreference = PreferenceEnum[data_preference] } + if data_preference <= PreferenceEnum.Settings then saved_player_data["PlayerSettings"] = player_data.PlayerSettings end + if data_preference <= PreferenceEnum.Statistics then saved_player_data["PlayerStatistics"] = player_data.PlayerStatistics end return saved_player_data end) --- Display your data preference when your data loads -DataSavingPreference:on_load(function(player_name, dataPreference) - game.players[player_name].print{ "expcore-data.get-preference", dataPreference or DataSavingPreference.default } +DataSavingPreference:on_load(function(player_name, data_preference) + game.players[player_name].print{ "expcore-data.get-preference", data_preference or DataSavingPreference.default } end) --- Load player data when they join diff --git a/exp_legacy/module/expcore/roles.lua b/exp_legacy/module/expcore/roles.lua index 8bb93f74..0f0a4c26 100644 --- a/exp_legacy/module/expcore/roles.lua +++ b/exp_legacy/module/expcore/roles.lua @@ -200,8 +200,8 @@ function Roles.debug() for index, role_name in ipairs(Roles.config.order) do local role = Roles.config.roles[role_name] local color = role.custom_color or Colours.white - color = string.format("[color=%d, %d, %d]", color.r, color.g, color.b) - output = output .. string.format("\n%s %s) %s[/color]", color, index, serpent.line(role)) + local color_str = string.format("[color=%d, %d, %d]", color.r, color.g, color.b) + output = output .. string.format("\n%s %s) %s[/color]", color_str, index, serpent.line(role)) end return output @@ -341,7 +341,6 @@ local role = Roles.get_player_highest_role(game.player) ]] function Roles.get_player_highest_role(player) local roles = Roles.get_player_roles(player) - if not roles then return end local highest for _, role in ipairs(roles) do if not highest or role.index < highest.index then diff --git a/exp_legacy/module/modules/addons/afk-kick.lua b/exp_legacy/module/modules/addons/afk-kick.lua index fa62fd36..5dd3bffe 100644 --- a/exp_legacy/module/modules/addons/afk-kick.lua +++ b/exp_legacy/module/modules/addons/afk-kick.lua @@ -60,7 +60,7 @@ end) --- Remove the screen gui if it is present Event.add(defines.events.on_player_joined_game, function(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] local frame = player.gui.screen["afk-kick"] if frame and frame.valid then frame.destroy() end end) diff --git a/exp_legacy/module/modules/addons/death-logger.lua b/exp_legacy/module/modules/addons/death-logger.lua index 0865b38e..94baec8d 100644 --- a/exp_legacy/module/modules/addons/death-logger.lua +++ b/exp_legacy/module/modules/addons/death-logger.lua @@ -63,6 +63,7 @@ end Event.add(defines.events.on_player_died, function(event) local player = game.players[event.player_index] local corpse = player.surface.find_entity("character-corpse", player.position) + if not corpse or not corpse.valid then return end if config.use_chests_as_bodies then local items = corpse.get_inventory(defines.inventory.character_corpse) local chest = move_items(items, corpse.surface, corpse.position) diff --git a/exp_legacy/module/modules/addons/deconlog.lua b/exp_legacy/module/modules/addons/deconlog.lua index 3f3a4298..2f78ca0e 100644 --- a/exp_legacy/module/modules/addons/deconlog.lua +++ b/exp_legacy/module/modules/addons/deconlog.lua @@ -44,7 +44,7 @@ if config.decon_area then return end - local player = game.get_player(e.player_index) + local player = game.players[e.player_index] if Roles.player_has_flag(player, "deconlog-bypass") then return @@ -63,7 +63,7 @@ end if config.built_entity then Event.add(defines.events.on_built_entity, function(e) if not e.player_index then return end - local player = game.get_player(e.player_index) + local player = game.players[e.player_index] if Roles.player_has_flag(player, "deconlog-bypass") then return end @@ -74,7 +74,7 @@ end if config.mined_entity then Event.add(defines.events.on_player_mined_entity, function(e) - local player = game.get_player(e.player_index) + local player = game.players[e.player_index] if Roles.player_has_flag(player, "deconlog-bypass") then return end @@ -85,11 +85,11 @@ end if config.fired_rocket then Event.add(defines.events.on_player_ammo_inventory_changed, function(e) - local player = game.get_player(e.player_index) + local player = game.players[e.player_index] if Roles.player_has_flag(player, "deconlog-bypass") then return end - local ammo_inv = player.get_inventory(defines.inventory.character_ammo) + local ammo_inv = player.get_inventory(defines.inventory.character_ammo) --- @cast ammo_inv -nil local item = ammo_inv[player.character.selected_gun_index] if not item or not item.valid or not item.valid_for_read then return @@ -102,12 +102,12 @@ end if config.fired_explosive_rocket then Event.add(defines.events.on_player_ammo_inventory_changed, function(e) - local player = game.get_player(e.player_index) + local player = game.players[e.player_index] if Roles.player_has_flag(player, "deconlog-bypass") then return end - local ammo_inv = player.get_inventory(defines.inventory.character_ammo) + local ammo_inv = player.get_inventory(defines.inventory.character_ammo) --- @cast ammo_inv -nil local item = ammo_inv[player.character.selected_gun_index] if not item or not item.valid or not item.valid_for_read then @@ -121,13 +121,13 @@ end if config.fired_nuke then Event.add(defines.events.on_player_ammo_inventory_changed, function(e) - local player = game.get_player(e.player_index) + local player = game.players[e.player_index] if Roles.player_has_flag(player, "deconlog-bypass") then return end - local ammo_inv = player.get_inventory(defines.inventory.character_ammo) + local ammo_inv = player.get_inventory(defines.inventory.character_ammo) --- @cast ammo_inv -nil local item = ammo_inv[player.character.selected_gun_index] if not item or not item.valid or not item.valid_for_read then diff --git a/exp_legacy/module/modules/addons/inserter.lua b/exp_legacy/module/modules/addons/inserter.lua index 39fe4d82..a9380051 100644 --- a/exp_legacy/module/modules/addons/inserter.lua +++ b/exp_legacy/module/modules/addons/inserter.lua @@ -14,7 +14,7 @@ Event.add(defines.events.on_player_mined_entity, function(event) local item_entity = event.entity.surface.find_entity("item-on-ground", event.entity.drop_position) if item_entity then - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] if controllers_with_inventory[player.controller_type] then player.mine_entity(item_entity) diff --git a/exp_legacy/module/modules/addons/inventory-clear.lua b/exp_legacy/module/modules/addons/inventory-clear.lua index de761baf..79a469fc 100644 --- a/exp_legacy/module/modules/addons/inventory-clear.lua +++ b/exp_legacy/module/modules/addons/inventory-clear.lua @@ -7,7 +7,7 @@ local move_items_stack = _C.move_items_stack --- @dep expcore.common local function clear_items(event) local player = game.players[event.player_index] - local inv = player.get_main_inventory() + local inv = player.get_main_inventory() --- @cast inv -nil move_items_stack(inv) inv.clear() end diff --git a/exp_legacy/module/modules/addons/nukeprotect.lua b/exp_legacy/module/modules/addons/nukeprotect.lua index cc17ccdb..e1ed1b6e 100644 --- a/exp_legacy/module/modules/addons/nukeprotect.lua +++ b/exp_legacy/module/modules/addons/nukeprotect.lua @@ -26,7 +26,7 @@ end for _, inventory in ipairs(config.inventories) do if #inventory.items > 0 then Event.add(inventory.event, function(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] if player and player.valid then check_items(player, inventory.inventory) end diff --git a/exp_legacy/module/modules/addons/protection-jail.lua b/exp_legacy/module/modules/addons/protection-jail.lua index 1f0f3bec..8e9fec80 100644 --- a/exp_legacy/module/modules/addons/protection-jail.lua +++ b/exp_legacy/module/modules/addons/protection-jail.lua @@ -15,7 +15,7 @@ end) --- When a protection is triggered increment their counter and jail if needed Event.add(Protection.events.on_repeat_violation, function(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] -- Increment the counter if repeat_count[player.index] then diff --git a/exp_legacy/module/modules/addons/report-jail.lua b/exp_legacy/module/modules/addons/report-jail.lua index 811f30d7..e0fc4ca8 100644 --- a/exp_legacy/module/modules/addons/report-jail.lua +++ b/exp_legacy/module/modules/addons/report-jail.lua @@ -16,7 +16,7 @@ local function reporter_playtime(_, by_player_name, _) end Event.add(Reports.events.on_player_reported, function(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] local total_playtime = Reports.count_reports(player, reporter_playtime) -- player less than 30 min diff --git a/exp_legacy/module/modules/addons/spawn-area.lua b/exp_legacy/module/modules/addons/spawn-area.lua index b70b683a..439c047b 100644 --- a/exp_legacy/module/modules/addons/spawn-area.lua +++ b/exp_legacy/module/modules/addons/spawn-area.lua @@ -62,12 +62,13 @@ local function spawn_turrets() -- Makes a new turret if it is not found if not turret or not turret.valid then turret = surface.create_entity{ name = "gun-turret", position = pos, force = "spawn" } + if not turret then return end protect_entity(turret) end -- Adds ammo to the turret local inv = turret.get_inventory(defines.inventory.turret_ammo) - if inv.can_insert{ name = config.turrets.ammo_type, count = 10 } then + if inv and inv.can_insert{ name = config.turrets.ammo_type, count = 10 } then inv.insert{ name = config.turrets.ammo_type, count = 10 } end end diff --git a/exp_legacy/module/modules/commands/admin-markers.lua b/exp_legacy/module/modules/commands/admin-markers.lua index 54cd992a..34232aac 100644 --- a/exp_legacy/module/modules/commands/admin-markers.lua +++ b/exp_legacy/module/modules/commands/admin-markers.lua @@ -39,7 +39,7 @@ Commands.new_command("admin-marker", { "expcom-admin-marker.description" }, "Tog --- Listen for new map markers being added, add admin marker if done by player in admin mode Event.add(defines.events.on_chart_tag_added, function(event) if not event.player_index then return end - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] if not admins[player.name] then return end local tag = event.tag markers[tag.force.name .. tag.tag_number] = true @@ -49,7 +49,7 @@ end) --- Listen for players leaving the game, leave admin mode to avoid unexpected admin markers Event.add(defines.events.on_player_left_game, function(event) if not event.player_index then return end - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] admins[player.name] = nil end) @@ -58,7 +58,7 @@ local function maintain_tag(event) local tag = event.tag if not event.player_index then return end if not markers[tag.force.name .. tag.tag_number] then return end - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] if player.admin then -- Player is admin, tell them it was an admin marker Commands.print({ "expcom-admin-marker.edit" }, nil, player) diff --git a/exp_legacy/module/modules/commands/artillery.lua b/exp_legacy/module/modules/commands/artillery.lua index cd252559..7890ed53 100644 --- a/exp_legacy/module/modules/commands/artillery.lua +++ b/exp_legacy/module/modules/commands/artillery.lua @@ -33,7 +33,7 @@ end --- when an area is selected to add protection to the area Selection.on_selection(SelectionArtyArea, function(event) local area = aabb_align_expand(event.area) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] if player == nil then return diff --git a/exp_legacy/module/modules/commands/connect.lua b/exp_legacy/module/modules/commands/connect.lua index e61fbd16..a23f444c 100644 --- a/exp_legacy/module/modules/commands/connect.lua +++ b/exp_legacy/module/modules/commands/connect.lua @@ -63,7 +63,7 @@ Commands.new_command("connect", { "expcom-connect.description" }, "Connect to an server_id = new_server_id end - Async(request_connection, player, server_id, true) + request_connection_async(player, server_id, true) end) --- Connect a player to a different server diff --git a/exp_legacy/module/modules/commands/help.lua b/exp_legacy/module/modules/commands/help.lua index b35a4b12..4d62ea58 100644 --- a/exp_legacy/module/modules/commands/help.lua +++ b/exp_legacy/module/modules/commands/help.lua @@ -27,6 +27,7 @@ Commands.new_command("search-help", { "expcom-chelp.description" }, "Searches fo local player_index = player and player.index or 0 -- if keyword is a number then treat it as page number if tonumber(keyword) then + --- @diagnostic disable-next-line: param-type-mismatch page = math.floor(tonumber(keyword)) keyword = "" end diff --git a/exp_legacy/module/modules/commands/interface.lua b/exp_legacy/module/modules/commands/interface.lua index 7b3ecafb..f75cd947 100644 --- a/exp_legacy/module/modules/commands/interface.lua +++ b/exp_legacy/module/modules/commands/interface.lua @@ -88,6 +88,7 @@ Commands.new_command("interface", { "expcom-interface.description" }, "Sends an -- Compile the invocation with the custom _env value local invocation_func, compile_error = load(invocation, "interface", nil, _env) if compile_error then return Commands.error(compile_error) end + --- @cast invocation_func -nil -- Run the invocation local success, rtn = pcall(invocation_func) diff --git a/exp_legacy/module/modules/commands/protection.lua b/exp_legacy/module/modules/commands/protection.lua index 78127b2e..6602d97c 100644 --- a/exp_legacy/module/modules/commands/protection.lua +++ b/exp_legacy/module/modules/commands/protection.lua @@ -28,9 +28,9 @@ local function aabb_point_enclosed(point, aabb) end --- Test if an aabb is inside another aabb -local function aabb_area_enclosed(aabbOne, aabbTwo) - return aabb_point_enclosed(aabbOne.left_top, aabbTwo) - and aabb_point_enclosed(aabbOne.right_bottom, aabbTwo) +local function aabb_area_enclosed(aabb_one, aabb_two) + return aabb_point_enclosed(aabb_one.left_top, aabb_two) + and aabb_point_enclosed(aabb_one.right_bottom, aabb_two) end --- Align an aabb to the grid by expanding it @@ -89,8 +89,8 @@ end --- Remove a render object for a player local function remove_render(player, key) - local render = renders[player.index][key] - if render and rendering.is_valid(render) then rendering.destroy(render) end + local render = renders[player.index][key] --[[@as LuaRenderObject]] + if render and render.valid then render.destroy() end renders[player.index][key] = nil end @@ -122,7 +122,7 @@ Commands.new_command("protect-area", { "expcom-protection.description-pa" }, "To --- When an area is selected to add protection to entities Selection.on_selection(SelectionProtectEntity, function(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] for _, entity in ipairs(event.entities) do EntityProtection.add_entity(entity) show_protected_entity(player, entity) @@ -133,7 +133,7 @@ end) --- When an area is selected to remove protection from entities Selection.on_alt_selection(SelectionProtectEntity, function(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] for _, entity in ipairs(event.entities) do EntityProtection.remove_entity(entity) remove_render(player, get_entity_key(entity)) @@ -146,7 +146,7 @@ end) Selection.on_selection(SelectionProtectArea, function(event) local area = aabb_align_expand(event.area) local areas = EntityProtection.get_areas(event.surface) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] for _, next_area in pairs(areas) do if aabb_area_enclosed(area, next_area) then return player.print{ "expcom-protection.already-protected" } @@ -162,7 +162,7 @@ end) Selection.on_alt_selection(SelectionProtectArea, function(event) local area = aabb_align_expand(event.area) local areas = EntityProtection.get_areas(event.surface) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] for _, next_area in pairs(areas) do if aabb_area_enclosed(next_area, area) then EntityProtection.remove_area(event.surface, next_area) @@ -175,7 +175,7 @@ end) --- When selection starts show all protected entities and protected areas Event.add(Selection.events.on_player_selection_start, function(event) if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] local surface = player.surface renders[player.index] = {} -- Show protected entities @@ -206,8 +206,8 @@ end) --- When selection ends hide protected entities and protected areas Event.add(Selection.events.on_player_selection_end, function(event) if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end - for _, id in pairs(renders[event.player_index]) do - if rendering.is_valid(id) then rendering.destroy(id) end + for _, render in pairs(renders[event.player_index]) do + if render.valid then render.destroy() end end renders[event.player_index] = nil diff --git a/exp_legacy/module/modules/commands/waterfill.lua b/exp_legacy/module/modules/commands/waterfill.lua index 74a6ceb5..a403ee19 100644 --- a/exp_legacy/module/modules/commands/waterfill.lua +++ b/exp_legacy/module/modules/commands/waterfill.lua @@ -35,7 +35,7 @@ Commands.new_command("waterfill", { "expcom-waterfill.description" }, "Change ti --- When an area is selected to add protection to the area Selection.on_selection(SelectionConvertArea, function(event) local area = aabb_align_expand(event.area) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] if not player then return diff --git a/exp_legacy/module/modules/control/protection.lua b/exp_legacy/module/modules/control/protection.lua index a0ad50c7..4f0d5c95 100644 --- a/exp_legacy/module/modules/control/protection.lua +++ b/exp_legacy/module/modules/control/protection.lua @@ -155,7 +155,7 @@ end --- Raise events for protected entities Event.add(defines.events.on_pre_player_mined_item, function(event) local entity = event.entity - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] -- Check if the player should be ignored if config.ignore_admins and player.admin then return end if entity.last_user == nil or entity.last_user.index == player.index then return end diff --git a/exp_legacy/module/modules/control/selection.lua b/exp_legacy/module/modules/control/selection.lua index dba2353b..21c8ddd7 100644 --- a/exp_legacy/module/modules/control/selection.lua +++ b/exp_legacy/module/modules/control/selection.lua @@ -146,13 +146,13 @@ end --- Stop selection if the selection tool is removed from the cursor Event.add(defines.events.on_player_cursor_stack_changed, function(event) - local player = game.get_player(event.player_index) --- @cast player -nil + local player = game.players[event.player_index] --- @cast player -nil if player.cursor_stack.is_selection_tool then return end Selection.stop(player) end) --- Stop selection after an event such as death or leaving the game local function stop_after_event(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] Selection.stop(player) end diff --git a/exp_legacy/module/modules/control/tasks.lua b/exp_legacy/module/modules/control/tasks.lua index 9489a955..6a03a089 100644 --- a/exp_legacy/module/modules/control/tasks.lua +++ b/exp_legacy/module/modules/control/tasks.lua @@ -46,10 +46,10 @@ function Tasks.add_task(force_name, player_name, task_title, task_body) force_tasks._uid = force_tasks._uid + 1 -- Get the existing tasks for this force - local task_ids = force_tasks[force_name] + local task_ids = force_tasks[force_name] --[[@as table?]] if not task_ids then task_ids = {} - force_tasks[force_name] = task_ids + force_tasks[force_name] = task_ids --[[@as any]] end -- Insert the task id into the forces tasks diff --git a/exp_legacy/module/modules/data/greetings.lua b/exp_legacy/module/modules/data/greetings.lua index 3bd720e5..fd157a95 100644 --- a/exp_legacy/module/modules/data/greetings.lua +++ b/exp_legacy/module/modules/data/greetings.lua @@ -17,7 +17,7 @@ CustomMessages:on_load(function(player_name, player_message) local player = game.players[player_name] local custom_message = player_message or config[player_name] if custom_message then - game.print(custom_message, player.color) + game.print(custom_message, { color = player.color }) else player.print{ "join-message.greet", { "links.discord" } } end diff --git a/exp_legacy/module/modules/graftorio/forcestats.lua b/exp_legacy/module/modules/graftorio/forcestats.lua index 48941fce..a515869a 100644 --- a/exp_legacy/module/modules/graftorio/forcestats.lua +++ b/exp_legacy/module/modules/graftorio/forcestats.lua @@ -185,7 +185,7 @@ Event.on_nth_tick(60, function() table.insert(force_research, { name = research.name, level = research.level, - progress = force.get_saved_technology_progress(research) or 0, + progress = force.technologies[research.name].saved_progress }) end diff --git a/exp_legacy/module/modules/graftorio/general.lua b/exp_legacy/module/modules/graftorio/general.lua index 4a9f84e5..440cedc0 100644 --- a/exp_legacy/module/modules/graftorio/general.lua +++ b/exp_legacy/module/modules/graftorio/general.lua @@ -41,10 +41,10 @@ lib.collect_other = function() local other = lib.data.output[force.name].other or {} other.evolution = { - evolution_factor = force.evolution_factor, - evolution_factor_by_pollution = force.evolution_factor_by_pollution, - evolution_factor_by_time = force.evolution_factor_by_time, - evolution_factor_by_killing_spawners = force.evolution_factor_by_killing_spawners, + evolution_factor = force.get_evolution_factor(game.surfaces[1]), + evolution_factor_by_pollution = force.get_evolution_factor_by_pollution(game.surfaces[1]), + evolution_factor_by_time = force.get_evolution_factor_by_time(game.surfaces[1]), + evolution_factor_by_killing_spawners = force.get_evolution_factor_by_killing_spawners(game.surfaces[1]), } for k, v in pairs(other) do lib.data.output[force.name].other[k] = v diff --git a/exp_legacy/module/modules/gui/autofill.lua b/exp_legacy/module/modules/gui/autofill.lua index 2e0eb005..46dcfb99 100644 --- a/exp_legacy/module/modules/gui/autofill.lua +++ b/exp_legacy/module/modules/gui/autofill.lua @@ -78,7 +78,7 @@ local entity_toggle = element.style = "shortcut_bar_button_green" end -- Correct the button size - local style = element.style + local style = element.style --[[@as LuaStyle]] style.padding = -2 style.height = 22 style.width = 22 @@ -147,7 +147,7 @@ local toggle_item_button = element.style = "shortcut_bar_button_green" end -- Correct the button size - local style = element.style + local style = element.style --[[@as LuaStyle]] style.right_margin = -3 style.padding = -2 style.height = 32 @@ -322,7 +322,7 @@ local function entity_build(event) if not entity_settings.enabled then return end -- Get the inventory of the player - local player_inventory = player.get_main_inventory() + local player_inventory = player.get_main_inventory() --- @cast player_inventory -nil local text_position = { x = entity.position.x, y = entity.position.y } -- Loop over all possible items to insert into the entity diff --git a/exp_legacy/module/modules/gui/module.lua b/exp_legacy/module/modules/gui/module.lua index 8bf531de..cd93e53c 100644 --- a/exp_legacy/module/modules/gui/module.lua +++ b/exp_legacy/module/modules/gui/module.lua @@ -109,7 +109,7 @@ end --- when an area is selected to add protection to the area Selection.on_selection(SelectionModuleArea, function(event) local area = aabb_align_expand(event.area) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] local frame = Gui.get_left_element(player, module_container) local scroll_table = frame.container.scroll.table diff --git a/exp_legacy/module/modules/gui/player-list.lua b/exp_legacy/module/modules/gui/player-list.lua index e4ad676c..72dc8a18 100644 --- a/exp_legacy/module/modules/gui/player-list.lua +++ b/exp_legacy/module/modules/gui/player-list.lua @@ -400,7 +400,7 @@ SelectedPlayer:on_update(function(player_name, selected_player) style = "tool_button" end element.style = style - local element_style = element.style + local element_style = element.style --[[@as LuaStyle]] element_style.padding = -2 element_style.width = 8 element_style.height = 14 diff --git a/exp_legacy/module/modules/gui/readme.lua b/exp_legacy/module/modules/gui/readme.lua index 2db8fc59..9892735a 100644 --- a/exp_legacy/module/modules/gui/readme.lua +++ b/exp_legacy/module/modules/gui/readme.lua @@ -14,7 +14,7 @@ local format_time = _C.format_time --- @dep expcore.common local format_number = require("util").format_number --- @dep util local tabs = {} -local function Tab(caption, tooltip, element_define) +local function define_tab(caption, tooltip, element_define) tabs[#tabs + 1] = { caption, tooltip, element_define } end @@ -111,7 +111,7 @@ local join_server = --- Content area for the welcome tab -- @element welcome_content -Tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, +define_tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, Gui.element(function(_, parent) local server_details = { name = "ExpGaming S0 - Local", welcome = "Failed to load description: disconnected from external api.", reset_time = "Non Set", branch = "Unknown" } if External.valid() then server_details = External.get_current_server() end @@ -149,7 +149,7 @@ Tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, --- Content area for the rules tab -- @element rules_content -Tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, +define_tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, Gui.element(function(_, parent) local container = parent.add{ type = "flow", direction = "vertical" } @@ -160,7 +160,7 @@ Tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, container.add{ type = "flow" } -- Add a table for the rules - local rules = Gui.scroll_table(container, scroll_height, 1) + local rules = Gui.scroll_table(container, scroll_height, 1) --[[@as LuaGuiElement]] rules.style = "bordered_table" rules.style.cell_padding = 4 @@ -174,7 +174,7 @@ Tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, --- Content area for the commands tab -- @element commands_content -Tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, +define_tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, Gui.element(function(_, parent) local container = parent.add{ type = "flow", direction = "vertical" } local player = Gui.get_player_from_element(parent) @@ -186,7 +186,7 @@ Tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, container.add{ type = "flow" } -- Add a table for the commands - local commands = Gui.scroll_table(container, scroll_height, 2) + local commands = Gui.scroll_table(container, scroll_height, 2) --[[@as LuaGuiElement]] commands.style = "bordered_table" commands.style.cell_padding = 0 @@ -201,7 +201,7 @@ Tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, --- Content area for the servers tab -- @element servers_content -Tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, +define_tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, Gui.element(function(_, parent) local container = parent.add{ type = "flow", direction = "vertical" } @@ -245,7 +245,7 @@ Tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, --- Content area for the servers tab -- @element backers_content -Tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, +define_tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, Gui.element(function(_, parent) local container = parent.add{ type = "flow", direction = "vertical" } @@ -309,7 +309,7 @@ Tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, --- Content area for the player data tab -- @element commands_content -Tab({ "readme.data-tab" }, { "readme.data-tooltip" }, +define_tab({ "readme.data-tab" }, { "readme.data-tooltip" }, Gui.element(function(_, parent) local container = parent.add{ type = "flow", direction = "vertical" } local player = Gui.get_player_from_element(parent) diff --git a/exp_legacy/module/modules/gui/vlayer.lua b/exp_legacy/module/modules/gui/vlayer.lua index f9f11dec..2af11cef 100644 --- a/exp_legacy/module/modules/gui/vlayer.lua +++ b/exp_legacy/module/modules/gui/vlayer.lua @@ -74,7 +74,7 @@ end --- When an area is selected to add protection to the area Selection.on_selection(SelectionConvertArea, function(event) local area = aabb_align_expand(event.area) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] if not player then return nil @@ -99,7 +99,7 @@ Selection.on_selection(SelectionConvertArea, function(event) local e = entities[1] local e_pos = { x = string.format("%.1f", e.position.x), y = string.format("%.1f", e.position.y) } - local e_circ = e.circuit_connected_entities + local e_circ = {} -- e.circuit_connected_entities --- TODO use new circuit api if not e.get_inventory(defines.inventory.chest).is_empty() then player.print{ "vlayer.steel-chest-empty" } diff --git a/exp_legacy/module/overrides/table.lua b/exp_legacy/module/overrides/table.lua index 98f92988..f4266773 100644 --- a/exp_legacy/module/overrides/table.lua +++ b/exp_legacy/module/overrides/table.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: duplicate-set-field -- luacheck:ignore global table local random = math.random local floor = math.floor @@ -270,7 +271,7 @@ end -- @param x one comparator operand -- @param y the other comparator operand -- @return true if x logically comes before y in a list, false otherwise -local function sortFunc(x, y) -- sorts tables with mixed index types. +local function sort_func(x, y) -- sorts tables with mixed index types. local tx = type(x) local ty = type(y) if tx == ty then @@ -307,7 +308,7 @@ function table.get_values(tbl, sorted, as_string) end end if sorted then - table.sort(valueset, sortFunc) + table.sort(valueset, sort_func) end return valueset end @@ -333,7 +334,7 @@ function table.get_keys(tbl, sorted, as_string) end end if sorted then - table.sort(keyset, sortFunc) + table.sort(keyset, sort_func) end return keyset end diff --git a/exp_legacy/module/utils/gui.lua b/exp_legacy/module/utils/gui.lua index 49245e8e..7ea8347b 100644 --- a/exp_legacy/module/utils/gui.lua +++ b/exp_legacy/module/utils/gui.lua @@ -74,7 +74,7 @@ local function handler_factory(event_name) return function(element_name, handler) Event.add(defines.events[event_name], function(event) if event.element and event.element.valid and event.element.name == element_name then - event.player = game.get_player(event.player_index) + event.player = game.players[event.player_index] handler(event) end end) diff --git a/exp_util/module/common.lua b/exp_util/module/common.lua index dccd5f0f..fe78b8f5 100644 --- a/exp_util/module/common.lua +++ b/exp_util/module/common.lua @@ -204,15 +204,15 @@ end -- @param[opt] tableAsJson If table values should be returned as json -- @param[opt] maxLineCount If table newline count exceeds provided then it will be inlined -- @return The formated version of the value -function Common.format_any(value, tableAsJson, maxLineCount) +function Common.format_any(value, as_json, max_line_count) local formatted, is_locale_string = Common.safe_value(value) if type(formatted) == "table" and not is_locale_string then - if tableAsJson then + if as_json then local success, rtn = pcall(game.table_to_json, value) if success then return rtn end end local rtn = table.inspect(value, { depth = 5, indent = " ", newline = "\n", process = Common.safe_value }) - if maxLineCount == nil or select(2, rtn:gsub("\n", "")) < maxLineCount then return rtn end + if max_line_count == nil or select(2, rtn:gsub("\n", "")) < max_line_count then return rtn end return table.inspect(value, { depth = 5, indent = "", newline = "", process = Common.safe_value }) end return formatted @@ -234,10 +234,12 @@ function Common.format_time(ticks, format, units) local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60 -- Calculate rhw units to be displayed + --- @diagnostic disable: cast-local-type rtn_days, rtn_hours, rtn_minutes, rtn_seconds = floor(days), floor(hours), floor(minutes), floor(seconds) if not units.days then rtn_hours = rtn_hours + rtn_days * 24 end if not units.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end + --- @diagnostic enable: cast-local-type end local rtn = {} @@ -282,10 +284,12 @@ function Common.format_locale_time(ticks, format, units) local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60 -- Calculate rhw units to be displayed + --- @diagnostic disable: cast-local-type rtn_days, rtn_hours, rtn_minutes, rtn_seconds = floor(days), floor(hours), floor(minutes), floor(seconds) if not units.days then rtn_hours = rtn_hours + rtn_days * 24 end if not units.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end + --- @diagnostic enable: cast-local-type end local rtn = {} @@ -296,6 +300,7 @@ function Common.format_locale_time(ticks, format, units) if units.hours then rtn[#rtn + 1] = rtn_hours end if units.minutes then rtn[#rtn + 1] = rtn_minutes end if units.seconds then rtn[#rtn + 1] = rtn_seconds end + --- @diagnostic disable-next-line: cast-local-type join = { "colon" } elseif format == "short" then -- Example 12d 34h 56m or --d --h --m @@ -313,10 +318,10 @@ function Common.format_locale_time(ticks, format, units) rtn[#rtn] = { "", { "and" }, " ", rtn[#rtn] } end - local joined = { "" } + local joined = { "" } --[[@as any]] for k, v in ipairs(rtn) do joined[2 * k] = v - joined[2 * k + 1] = join + joined[2 * k + 1] = join --[[@as any]] end return joined diff --git a/exp_util/module/floating_text.lua b/exp_util/module/floating_text.lua index b531b162..d278e1fe 100644 --- a/exp_util/module/floating_text.lua +++ b/exp_util/module/floating_text.lua @@ -5,20 +5,20 @@ @usage-- Show player chat message in world local function on_console_chat(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] FloatingText.print_as_player(player, event.message) end @usage-- Show player tags above their characters local function on_player_respawned(event) - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] FloatingText.create_tag_as_player(player, player.tag) end @usage-- Show placed an entity in alt mode local function on_built_entity(event) local entity = event.created_entity - local player = game.get_player(event.player_index) + local player = game.players[event.player_index] FloatingText.create_tag_above_entity(entity, player.name, player.color, true) end diff --git a/exp_util/module/include/table.lua b/exp_util/module/include/table.lua index 82a5049b..6e3a1a0c 100644 --- a/exp_util/module/include/table.lua +++ b/exp_util/module/include/table.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: duplicate-set-field -- luacheck:ignore global table local random = math.random @@ -259,7 +260,7 @@ end -- @param x one comparator operand -- @param y the other comparator operand -- @return true if x logically comes before y in a list, false otherwise -local function sortFunc(x, y) -- sorts tables with mixed index types. +local function sort_func(x, y) -- sorts tables with mixed index types. local tx = type(x) local ty = type(y) if tx == ty then @@ -296,7 +297,7 @@ function table.get_values(tbl, sorted, as_string) end end if sorted then - table.sort(valueset, sortFunc) + table.sort(valueset, sort_func) end return valueset end @@ -322,7 +323,7 @@ function table.get_keys(tbl, sorted, as_string) end end if sorted then - table.sort(keyset, sortFunc) + table.sort(keyset, sort_func) end return keyset end