No more warnings

This commit is contained in:
Cooldude2606
2024-09-28 03:46:14 +01:00
parent 32a8ba8f3a
commit 3145f7e904
43 changed files with 215 additions and 177 deletions

View File

@@ -43,7 +43,7 @@
}, "pascal_case"], }, "pascal_case"],
"function_param_name_style": [{ "function_param_name_style": [{
"type" : "pattern", "type" : "pattern",
"param": "_?_?(\\w+)", "param": "_?_?(\\w+)?",
"$1": "snake_case" "$1": "snake_case"
}], }],
"function_name_style": [{ "function_name_style": [{
@@ -61,7 +61,10 @@
"param": "_?_?(\\w+)", "param": "_?_?(\\w+)",
"$1": "snake_case" "$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" ], "module_name_style": [ "pascal_case", "snake_case" ],
"require_module_name_style": [ "pascal_case", "snake_case" ], "require_module_name_style": [ "pascal_case", "snake_case" ],
"class_name_style": "pascal_case", "class_name_style": "pascal_case",

View File

@@ -536,6 +536,7 @@ function Commands._prototype:register(callback)
local function command_callback(event) local function command_callback(event)
event.name = self.name event.name = self.name
local success, traceback = xpcall(Commands._event_handler, debug.traceback, event) 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 if not success and not traceback:find("Command does not support rcon usage") then
local _, msg = Commands.status.internal_error(event.tick) local _, msg = Commands.status.internal_error(event.tick)
Commands.error(msg) Commands.error(msg)
@@ -618,7 +619,7 @@ function Commands._event_handler(event)
local player = nil -- nil represents the server until the command is called local player = nil -- nil represents the server until the command is called
if event.player_index then if event.player_index then
player = game.get_player(event.player_index) player = game.players[event.player_index]
end end
-- Check if the player is allowed to use the command -- Check if the player is allowed to use the command

View File

@@ -8,12 +8,28 @@ return {
{ "warnings.received", "" }, { "warnings.received", "" },
{ "warnings.received", { "warnings.pre-kick" } }, { "warnings.received", { "warnings.pre-kick" } },
function(player, by_player_name, number_of_warnings) 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, end,
{ "warnings.received", { "warnings.pre-pre-ban" } }, { "warnings.received", { "warnings.pre-pre-ban" } },
{ "warnings.received", { "warnings.pre-ban" } }, { "warnings.received", { "warnings.pre-ban" } },
function(player, by_player_name, number_of_warnings) 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, end,
}, },
script_warning_cool_down = 30, --- @setting script_warning_cool_down time for a script warning (given by script) to be removed (in minutes) script_warning_cool_down = 30, --- @setting script_warning_cool_down time for a script warning (given by script) to be removed (in minutes)

View File

@@ -4,11 +4,13 @@
-- this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development -- this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development
local _xpcall = xpcall local _xpcall = xpcall
--- @diagnostic disable
xpcall = function(func, error_handler, ...) xpcall = function(func, error_handler, ...)
local rtn = { _xpcall(func, error_handler, ...) } local rtn = { _xpcall(func, error_handler, ...) }
if not rtn[1] then error(rtn[2]) end if not rtn[1] then error(rtn[2]) end
return table.unpack(rtn) return table.unpack(rtn)
end end
--- @diagnostic enable
log("[START] -----| Explosive Gaming Scenario Loader |-----") log("[START] -----| Explosive Gaming Scenario Loader |-----")
log("[INFO] Setting up lua environment") log("[INFO] Setting up lua environment")
@@ -16,6 +18,7 @@ log("[INFO] Setting up lua environment")
-- Require the global overrides -- Require the global overrides
require("modules.exp_legacy.overrides.table") -- Adds alot more functions to the table module 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 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 _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 -- Please go to config/file_loader.lua to edit the files that are loaded

View File

@@ -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 colour = Common.type_check(colour, "table") and colour or Colours[colour] ~= Colours.white and Colours[colour] or Colours.white
player = player or game.player player = player or game.player
-- converts the value to a string -- 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, "table") or type(value) == "userdata" then
if Common.type_check(value.__self, "userdata") or type(value) == "userdata" then if Common.type_check(value.__self, "userdata") or type(value) == "userdata" then
-- value is userdata -- 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 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 -- value is a locale string
returnAsString = value string_return = value
elseif getmetatable(value) ~= nil and not tostring(value):find("table: 0x") then elseif getmetatable(value) ~= nil and not tostring(value):find("table: 0x") then
-- value has a tostring meta method -- value has a tostring meta method
returnAsString = tostring(value) string_return = tostring(value)
else else
-- value is a table -- value is a table
returnAsString = table.inspect(value, { depth = 5, indent = " ", newline = "\n" }) string_return = table.inspect(value, { depth = 5, indent = " ", newline = "\n" })
end end
elseif Common.type_check(value, "function") then elseif Common.type_check(value, "function") then
-- value is a function -- value is a function
returnAsString = "Cant Display Functions" string_return = "Cant Display Functions"
else else
returnAsString = tostring(value) string_return = tostring(value)
end end
-- returns to the player or the server -- returns to the player or the server
if player then 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 if not player then error("Invalid Player given to player_return", 2) end
-- plays a nice sound that is different to normal message sound -- plays a nice sound that is different to normal message sound
player.play_sound{ path = "utility/scenario_message" } player.play_sound{ path = "utility/scenario_message" }
player.print(returnAsString, colour) player.print(string_return, colour)
else else
rcon.print(returnAsString) rcon.print(string_return)
end end
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 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 local minutes, seconds = max_minutes - math.floor(max_hours) * 60, max_seconds - math.floor(max_minutes) * 60
-- Handles overflow of disabled denominations -- 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 if not options.days then
rtn_hours = rtn_hours + rtn_days * 24 rtn_hours = rtn_hours + rtn_days * 24
end end
@@ -496,10 +500,10 @@ function Common.format_time(ticks, options)
local div = options.string and " " or "time-format.simple-format-tagged" local div = options.string and " " or "time-format.simple-format-tagged"
if options.time then if options.time then
div = options.string and ":" or "time-format.simple-format-div" div = options.string and ":" or "time-format.simple-format-div"
suffix = false -- suffix = false -- Can't get the types to work
end end
-- Adds formatting -- Adds formatting
if suffix ~= false then if not options.time then -- Can't get the types to work
if options.string then if options.string then
-- format it as a string -- format it as a string
local long = suffix == "" local long = suffix == ""

View File

@@ -158,8 +158,8 @@ local trace = debug.traceback
--- Save datastores in the global table --- Save datastores in the global table
Storage.register(Data, function(tbl) Storage.register(Data, function(tbl)
Data = tbl Data = tbl
for datastoreName, datastore in pairs(Datastores) do for name, datastore in pairs(Datastores) do
datastore.data = Data[datastoreName] datastore.data = Data[name]
end end
end) end)
@@ -174,7 +174,7 @@ DatastoreManager.metatable = {
} }
--[[-- Make a new datastore connection, if a connection already exists then it is returned --[[-- 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 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 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 @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 local ExampleData = Datastore.connect('ExampleData', true) -- saveToDisk
]] ]]
function DatastoreManager.connect(datastoreName, saveToDisk, autoSave, propagateChanges) function DatastoreManager.connect(datastore_name, save_to_disk, autosave, propagate_changes)
if Datastores[datastoreName] then return Datastores[datastoreName] end if Datastores[datastore_name] then return Datastores[datastore_name] end
if package.lifecycle ~= package.lifecycle_stage.control then if package.lifecycle ~= package.lifecycle_stage.control then
-- Only allow this function to be called during the control stage -- Only allow this function to be called during the control stage
error("New datastore connection can not be created during runtime", 2) error("New datastore connection can not be created during runtime", 2)
end end
local new_datastore = { local new_datastore = {
name = datastoreName, name = datastore_name,
value_name = datastoreName, value_name = datastore_name,
auto_save = autoSave or false, auto_save = autosave or false,
save_to_disk = saveToDisk or false, save_to_disk = save_to_disk or false,
propagate_changes = propagateChanges or false, propagate_changes = propagate_changes or false,
serializer = false, serializer = false,
parent = false, parent = false,
children = {}, children = {},
@@ -205,28 +205,28 @@ function DatastoreManager.connect(datastoreName, saveToDisk, autoSave, propagate
data = {}, data = {},
} }
Data[datastoreName] = new_datastore.data Data[datastore_name] = new_datastore.data
Datastores[datastoreName] = new_datastore Datastores[datastore_name] = new_datastore
return setmetatable(new_datastore, DatastoreManager.metatable) return setmetatable(new_datastore, DatastoreManager.metatable)
end end
--[[-- Make a new datastore that stores its data inside of another one --[[-- 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 datastore_name 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 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 @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 @usage-- Setting up a datastore which stores its data inside of another datastore
local BarData = Datastore.combine('ExampleData', 'Bar') local BarData = Datastore.combine('ExampleData', 'Bar')
]] ]]
function DatastoreManager.combine(datastoreName, subDatastoreName) function DatastoreManager.combine(datastore_name, subdatastore_name)
local datastore = assert(Datastores[datastoreName], "Datastore not found " .. tostring(datastoreName)) local datastore = assert(Datastores[datastore_name], "Datastore not found " .. tostring(datastore_name))
return datastore:combine(subDatastoreName) return datastore:combine(subdatastore_name)
end end
--[[-- Ingest the result from a request, this is used through a rcon interface to sync data --[[-- 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 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 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 @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') Datastore.ingest('request', 'ExampleData', 'TestKey', 'Foo')
]] ]]
function DatastoreManager.ingest(action, datastoreName, key, valueJson) function DatastoreManager.ingest(action, datastore_name, key, value_json)
local datastore = assert(Datastores[datastoreName], "Datastore ingest error, Datastore not found " .. tostring(datastoreName)) 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(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)) assert(type(key) == "string", "Datastore ingest error, Key is not a string got: " .. type(key))
if action == "remove" then if action == "remove" then
datastore:raw_set(key) datastore:raw_set(key)
elseif action == "message" then elseif action == "message" then
local success, value = pcall(game.json_to_table, valueJson) local success, value = pcall(game.json_to_table, value_json)
if not success or value == nil then value = tonumber(valueJson) or valueJson end if not success or value == nil then value = tonumber(value_json) or value_json end
datastore:raise_event("on_message", key, value) datastore:raise_event("on_message", key, value)
elseif action == "propagate" or action == "request" then elseif action == "propagate" or action == "request" then
local success, value = pcall(game.json_to_table, valueJson) local success, value = pcall(game.json_to_table, value_json)
if not success or value == nil then value = tonumber(valueJson) or valueJson end if not success or value == nil then value = tonumber(value_json) or value_json end
local old_value = datastore:raw_get(key) local old_value = datastore:raw_get(key)
value = datastore:raise_event("on_load", key, value, old_value) value = datastore:raise_event("on_load", key, value, old_value)
datastore:set(key, value) datastore:set(key, value)
@@ -255,7 +255,7 @@ function DatastoreManager.ingest(action, datastoreName, key, valueJson)
end end
--[[-- Debug, Use to get all datastores, or return debug info on a datastore --[[-- 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 @usage-- Get all the datastores
local datastores = Datastore.debug() local datastores = Datastore.debug()
@@ -264,9 +264,9 @@ local datastores = Datastore.debug()
local debug_info = Datastore.debug('ExampleData') local debug_info = Datastore.debug('ExampleData')
]] ]]
function DatastoreManager.debug(datastoreName) function DatastoreManager.debug(datastore_name)
if not datastoreName then return Datastores end if not datastore_name then return Datastores end
local datastore = assert(Datastores[datastoreName], "Datastore not found " .. tostring(datastoreName)) local datastore = assert(Datastores[datastore_name], "Datastore not found " .. tostring(datastore_name))
return datastore:debug() return datastore:debug()
end end
@@ -279,8 +279,8 @@ local ExampleData = Datastore.connect('ExampleData')
ExampleData:set_serializer(Datastore.name_serializer) ExampleData:set_serializer(Datastore.name_serializer)
]] ]]
function DatastoreManager.name_serializer(rawKey) function DatastoreManager.name_serializer(raw_key)
return rawKey.name return raw_key.name
end end
----- Datastore Internal ----- Datastore Internal
@@ -328,7 +328,7 @@ end
local value = self:raw_get('TestKey') local value = self:raw_get('TestKey')
]] ]]
function Datastore:raw_get(key, fromChild) function Datastore:raw_get(key, from_child)
local data = self.data local data = self.data
if self.parent then if self.parent then
data = self.parent:raw_get(key, true) data = self.parent:raw_get(key, true)
@@ -336,7 +336,7 @@ function Datastore:raw_get(key, fromChild)
end end
local value = data[key] local value = data[key]
if value ~= nil then return value end if value ~= nil then return value end
if fromChild then value = {} end if from_child then value = {} end
data[key] = value data[key] = value
return value return value
end end
@@ -367,10 +367,10 @@ local function serialize_error(err) error("An error ocurred in a datastore seria
key = self:serialize(key) key = self:serialize(key)
]] ]]
function Datastore:serialize(rawKey) function Datastore:serialize(raw_key)
if type(rawKey) == "string" then return rawKey end if type(raw_key) == "string" then return raw_key end
assert(self.serializer, "Datastore does not have a serializer and received non string key") 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 return success and key or nil
end end
@@ -398,7 +398,7 @@ end
-- @section datastore-local -- @section datastore-local
--[[-- Create a new datastore which is stores its data inside of this datastore --[[-- 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 @treturn table The new datastore that was created inside of this datastore
@usage-- Add a new sub datastore @usage-- Add a new sub datastore
@@ -406,10 +406,10 @@ local ExampleData = Datastore.connect('ExampleData')
local BarData = ExampleData:combine('Bar') local BarData = ExampleData:combine('Bar')
]] ]]
function Datastore:combine(subDatastoreName) function Datastore:combine(subdatastore_name)
local new_datastore = DatastoreManager.connect(self.name .. "." .. subDatastoreName) local new_datastore = DatastoreManager.connect(self.name .. "." .. subdatastore_name)
self.children[subDatastoreName] = new_datastore self.children[subdatastore_name] = new_datastore
new_datastore.value_name = subDatastoreName new_datastore.value_name = subdatastore_name
new_datastore.serializer = self.serializer new_datastore.serializer = self.serializer
new_datastore.auto_save = self.auto_save new_datastore.auto_save = self.auto_save
new_datastore.parent = self new_datastore.parent = self
@@ -442,9 +442,9 @@ local ExampleData = Datastore.connect('ExampleData')
ExampleData:set_default('Foo') ExampleData:set_default('Foo')
]] ]]
function Datastore:set_default(value, allowSet) function Datastore:set_default(value, allow_set)
self.default = value self.default = value
self.allow_set_to_default = allowSet self.allow_set_to_default = allow_set
end end
--[[-- Set metadata tags on this datastore which can be accessed by other scripts --[[-- Set metadata tags on this datastore which can be accessed by other scripts

View File

@@ -133,10 +133,10 @@ local Event = _C.opt_require("modules/exp_legacy/utils/event")
if Roles and Event then if Roles and Event then
Event.add(Roles.events.on_role_assigned, function(e) 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) end)
Event.add(Roles.events.on_role_unassigned, function(e) 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)
end end

View File

@@ -226,6 +226,7 @@ function Gui._prototype_element:triggers_events(element)
element.tags = { ExpGui_event_triggers = { self.uid } } element.tags = { ExpGui_event_triggers = { self.uid } }
return element return element
elseif not tags.ExpGui_event_triggers then elseif not tags.ExpGui_event_triggers then
--- @diagnostic disable-next-line: name-style-check
tags.ExpGui_event_triggers = { self.uid } tags.ExpGui_event_triggers = { self.uid }
elseif table.array_contains(tags.ExpGui_event_triggers, self.uid) then 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") error("Element::triggers_events called multiple times on the same element with the same definition")

View File

@@ -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 Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Async = require("modules/exp_util/async") local Async = require("modules/exp_util/async")
local Permissions_Groups = { local PermissionsGroups = {
groups = {}, -- store for the different groups that are created groups = {}, -- store for the different groups that are created
_prototype = {}, -- stores functions that are used on group instances _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) Async.register(function(permission_group, player)
permission_group.add_player(player) permission_group.add_player(player)
end) 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 -- Async function to remove players from permission groups
local remove_from_permission_group_async = local remove_from_permission_group_async =
Async.register(function(permission_group, player) Async.register(function(permission_group, player)
permission_group.remove_player(player) permission_group.remove_player(player)
end) 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. --- Getters.
-- Functions that get permission groups -- Functions that get permission groups
@@ -58,15 +58,15 @@ Permissions_Groups.remove_from_permission_group_async = remove_from_permission_g
Groups.new_group('Admin') Groups.new_group('Admin')
]] ]]
function Permissions_Groups.new_group(name) function PermissionsGroups.new_group(name)
local group = setmetatable({ local group = setmetatable({
name = name, name = name,
actions = {}, actions = {},
allow_all_actions = true, allow_all_actions = true,
}, { }, {
__index = Permissions_Groups._prototype, __index = PermissionsGroups._prototype,
}) })
Permissions_Groups.groups[name] = group PermissionsGroups.groups[name] = group
return group return group
end end
@@ -78,8 +78,8 @@ end
local admin_group = Groups.get_group_by_name('Admin') local admin_group = Groups.get_group_by_name('Admin')
]] ]]
function Permissions_Groups.get_group_by_name(name) function PermissionsGroups.get_group_by_name(name)
return Permissions_Groups.groups[name] return PermissionsGroups.groups[name]
end end
--[[-- Returns the group that a player is in --[[-- Returns the group that a player is in
@@ -90,12 +90,12 @@ end
local group = Groups.get_group_from_player(game.player) 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) player = Game.get_player_from_any(player)
if not player then return end if not player then return end
local group = player.permission_group local group = player.permission_group
if group then if group then
return Permissions_Groups.groups[group.name] return PermissionsGroups.groups[group.name]
end end
end end
@@ -109,8 +109,8 @@ end
Groups.reload_permissions() Groups.reload_permissions()
]] ]]
function Permissions_Groups.reload_permissions() function PermissionsGroups.reload_permissions()
for _, group in pairs(Permissions_Groups.groups) do for _, group in pairs(PermissionsGroups.groups) do
group:create() group:create()
end end
end end
@@ -124,9 +124,9 @@ end
Groups.set_player_group(game.player, 'Admin') 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) 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 if not group or not player then return false end
group:add_player(player) group:add_player(player)
return true return true
@@ -145,7 +145,7 @@ end
group:set_action('toggle_map_editor', false) 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] local input_action = defines.input_action[action]
if input_action == nil then input_action = action end if input_action == nil then input_action = action end
assert(type(input_action) == "number", tostring(action) .. " is not a valid input action") 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 if type(actions) ~= "table" then
actions = { actions } actions = { actions }
end end
@@ -188,7 +188,7 @@ group:disallow{
} }
]] ]]
function Permissions_Groups._prototype:disallow(actions) function PermissionsGroups._prototype:disallow(actions)
if type(actions) ~= "table" then if type(actions) ~= "table" then
actions = { actions } actions = { actions }
end end
@@ -206,7 +206,7 @@ end
group:allow_all() group:allow_all()
]] ]]
function Permissions_Groups._prototype:allow_all() function PermissionsGroups._prototype:allow_all()
self.allow_all_actions = true self.allow_all_actions = true
return self return self
end end
@@ -218,7 +218,7 @@ end
group:disallow_all() group:disallow_all()
]] ]]
function Permissions_Groups._prototype:disallow_all() function PermissionsGroups._prototype:disallow_all()
self.allow_all_actions = false self.allow_all_actions = false
return self return self
end end
@@ -231,7 +231,7 @@ end
local allowed = group:is_allowed('write_to_console') 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 if type(action) == "string" then
action = defines.input_action[action] action = defines.input_action[action]
end end
@@ -253,10 +253,10 @@ end
group:create() group:create()
]] ]]
function Permissions_Groups._prototype:create() function PermissionsGroups._prototype:create()
local group = self:get_raw() local group = self:get_raw()
if not group then if not group then
group = game.permissions.create_group(self.name) group = game.permissions.create_group(self.name) --[[@as LuaPermissionGroup]]
end end
for _, action in pairs(defines.input_action) do for _, action in pairs(defines.input_action) do
group.set_allows_action(action, self:is_allowed(action)) group.set_allows_action(action, self:is_allowed(action))
@@ -272,7 +272,7 @@ end
local permission_group = group:get_raw() local permission_group = group:get_raw()
]] ]]
function Permissions_Groups._prototype:get_raw() function PermissionsGroups._prototype:get_raw()
return game.permissions.get_group(self.name) return game.permissions.get_group(self.name)
end end
@@ -284,7 +284,7 @@ end
group:add_player(game.player) 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) player = Game.get_player_from_any(player)
local group = self:get_raw() local group = self:get_raw()
if not group or not player then return false end if not group or not player then return false end
@@ -300,7 +300,7 @@ end
group:remove_player(game.player) 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) player = Game.get_player_from_any(player)
local group = self:get_raw() local group = self:get_raw()
if not group or not player then return false end 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) local online_players = group:get_players(true)
]] ]]
function Permissions_Groups._prototype:get_players(online) function PermissionsGroups._prototype:get_players(online)
local players = {} local players = {}
local group = self:get_raw() local group = self:get_raw()
if group then if group then
@@ -344,7 +344,7 @@ end
group:print('Hello, World!') group:print('Hello, World!')
]] ]]
function Permissions_Groups._prototype:print(message) function PermissionsGroups._prototype:print(message)
local players = self:get_players(true) local players = self:get_players(true)
for _, player in pairs(players) do for _, player in pairs(players) do
player.print(message) player.print(message)
@@ -355,7 +355,7 @@ end
-- when the game starts it will make the permission groups -- when the game starts it will make the permission groups
Event.on_init(function() Event.on_init(function()
Permissions_Groups.reload_permissions() PermissionsGroups.reload_permissions()
end) end)
return Permissions_Groups return PermissionsGroups

View File

@@ -107,23 +107,23 @@ end)
--- Remove data that the player doesnt want to have stored --- Remove data that the player doesnt want to have stored
PlayerData:on_save(function(player_name, player_data) PlayerData:on_save(function(player_name, player_data)
local dataPreference = DataSavingPreference:get(player_name) local data_preference = DataSavingPreference:get(player_name)
dataPreference = PreferenceEnum[dataPreference] data_preference = PreferenceEnum[data_preference]
if dataPreference == PreferenceEnum.All then if data_preference == PreferenceEnum.All then
player_data.valid = nil player_data.valid = nil
return player_data return player_data
end end
local saved_player_data = { PlayerRequired = player_data.PlayerRequired, DataSavingPreference = PreferenceEnum[dataPreference] } local saved_player_data = { PlayerRequired = player_data.PlayerRequired, DataSavingPreference = PreferenceEnum[data_preference] }
if dataPreference <= PreferenceEnum.Settings then saved_player_data.PlayerSettings = player_data.PlayerSettings end if data_preference <= PreferenceEnum.Settings then saved_player_data["PlayerSettings"] = player_data.PlayerSettings end
if dataPreference <= PreferenceEnum.Statistics then saved_player_data.PlayerStatistics = player_data.PlayerStatistics end if data_preference <= PreferenceEnum.Statistics then saved_player_data["PlayerStatistics"] = player_data.PlayerStatistics end
return saved_player_data return saved_player_data
end) end)
--- Display your data preference when your data loads --- Display your data preference when your data loads
DataSavingPreference:on_load(function(player_name, dataPreference) DataSavingPreference:on_load(function(player_name, data_preference)
game.players[player_name].print{ "expcore-data.get-preference", dataPreference or DataSavingPreference.default } game.players[player_name].print{ "expcore-data.get-preference", data_preference or DataSavingPreference.default }
end) end)
--- Load player data when they join --- Load player data when they join

View File

@@ -200,8 +200,8 @@ function Roles.debug()
for index, role_name in ipairs(Roles.config.order) do for index, role_name in ipairs(Roles.config.order) do
local role = Roles.config.roles[role_name] local role = Roles.config.roles[role_name]
local color = role.custom_color or Colours.white local color = role.custom_color or Colours.white
color = string.format("[color=%d, %d, %d]", color.r, color.g, color.b) 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, index, serpent.line(role)) output = output .. string.format("\n%s %s) %s[/color]", color_str, index, serpent.line(role))
end end
return output return output
@@ -341,7 +341,6 @@ local role = Roles.get_player_highest_role(game.player)
]] ]]
function Roles.get_player_highest_role(player) function Roles.get_player_highest_role(player)
local roles = Roles.get_player_roles(player) local roles = Roles.get_player_roles(player)
if not roles then return end
local highest local highest
for _, role in ipairs(roles) do for _, role in ipairs(roles) do
if not highest or role.index < highest.index then if not highest or role.index < highest.index then

View File

@@ -60,7 +60,7 @@ end)
--- Remove the screen gui if it is present --- Remove the screen gui if it is present
Event.add(defines.events.on_player_joined_game, function(event) 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"] local frame = player.gui.screen["afk-kick"]
if frame and frame.valid then frame.destroy() end if frame and frame.valid then frame.destroy() end
end) end)

View File

@@ -63,6 +63,7 @@ end
Event.add(defines.events.on_player_died, function(event) Event.add(defines.events.on_player_died, function(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
local corpse = player.surface.find_entity("character-corpse", player.position) 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 if config.use_chests_as_bodies then
local items = corpse.get_inventory(defines.inventory.character_corpse) local items = corpse.get_inventory(defines.inventory.character_corpse)
local chest = move_items(items, corpse.surface, corpse.position) local chest = move_items(items, corpse.surface, corpse.position)

View File

@@ -44,7 +44,7 @@ if config.decon_area then
return return
end 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 if Roles.player_has_flag(player, "deconlog-bypass") then
return return
@@ -63,7 +63,7 @@ end
if config.built_entity then if config.built_entity then
Event.add(defines.events.on_built_entity, function(e) Event.add(defines.events.on_built_entity, function(e)
if not e.player_index then return end 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 if Roles.player_has_flag(player, "deconlog-bypass") then
return return
end end
@@ -74,7 +74,7 @@ end
if config.mined_entity then if config.mined_entity then
Event.add(defines.events.on_player_mined_entity, function(e) 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 if Roles.player_has_flag(player, "deconlog-bypass") then
return return
end end
@@ -85,11 +85,11 @@ end
if config.fired_rocket then if config.fired_rocket then
Event.add(defines.events.on_player_ammo_inventory_changed, function(e) 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 if Roles.player_has_flag(player, "deconlog-bypass") then
return return
end 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] local item = ammo_inv[player.character.selected_gun_index]
if not item or not item.valid or not item.valid_for_read then if not item or not item.valid or not item.valid_for_read then
return return
@@ -102,12 +102,12 @@ end
if config.fired_explosive_rocket then if config.fired_explosive_rocket then
Event.add(defines.events.on_player_ammo_inventory_changed, function(e) 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 if Roles.player_has_flag(player, "deconlog-bypass") then
return return
end 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] local item = ammo_inv[player.character.selected_gun_index]
if not item or not item.valid or not item.valid_for_read then if not item or not item.valid or not item.valid_for_read then
@@ -121,13 +121,13 @@ end
if config.fired_nuke then if config.fired_nuke then
Event.add(defines.events.on_player_ammo_inventory_changed, function(e) 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 if Roles.player_has_flag(player, "deconlog-bypass") then
return return
end 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] local item = ammo_inv[player.character.selected_gun_index]
if not item or not item.valid or not item.valid_for_read then if not item or not item.valid or not item.valid_for_read then

View File

@@ -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) local item_entity = event.entity.surface.find_entity("item-on-ground", event.entity.drop_position)
if item_entity then 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 if controllers_with_inventory[player.controller_type] then
player.mine_entity(item_entity) player.mine_entity(item_entity)

View File

@@ -7,7 +7,7 @@ local move_items_stack = _C.move_items_stack --- @dep expcore.common
local function clear_items(event) local function clear_items(event)
local player = game.players[event.player_index] 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) move_items_stack(inv)
inv.clear() inv.clear()
end end

View File

@@ -26,7 +26,7 @@ end
for _, inventory in ipairs(config.inventories) do for _, inventory in ipairs(config.inventories) do
if #inventory.items > 0 then if #inventory.items > 0 then
Event.add(inventory.event, function(event) 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 if player and player.valid then
check_items(player, inventory.inventory) check_items(player, inventory.inventory)
end end

View File

@@ -15,7 +15,7 @@ end)
--- When a protection is triggered increment their counter and jail if needed --- When a protection is triggered increment their counter and jail if needed
Event.add(Protection.events.on_repeat_violation, function(event) 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 -- Increment the counter
if repeat_count[player.index] then if repeat_count[player.index] then

View File

@@ -16,7 +16,7 @@ local function reporter_playtime(_, by_player_name, _)
end end
Event.add(Reports.events.on_player_reported, function(event) 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) local total_playtime = Reports.count_reports(player, reporter_playtime)
-- player less than 30 min -- player less than 30 min

View File

@@ -62,12 +62,13 @@ local function spawn_turrets()
-- Makes a new turret if it is not found -- Makes a new turret if it is not found
if not turret or not turret.valid then if not turret or not turret.valid then
turret = surface.create_entity{ name = "gun-turret", position = pos, force = "spawn" } turret = surface.create_entity{ name = "gun-turret", position = pos, force = "spawn" }
if not turret then return end
protect_entity(turret) protect_entity(turret)
end end
-- Adds ammo to the turret -- Adds ammo to the turret
local inv = turret.get_inventory(defines.inventory.turret_ammo) 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 } inv.insert{ name = config.turrets.ammo_type, count = 10 }
end end
end end

View File

@@ -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 --- 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) Event.add(defines.events.on_chart_tag_added, function(event)
if not event.player_index then return end 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 if not admins[player.name] then return end
local tag = event.tag local tag = event.tag
markers[tag.force.name .. tag.tag_number] = true 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 --- Listen for players leaving the game, leave admin mode to avoid unexpected admin markers
Event.add(defines.events.on_player_left_game, function(event) Event.add(defines.events.on_player_left_game, function(event)
if not event.player_index then return end 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 admins[player.name] = nil
end) end)
@@ -58,7 +58,7 @@ local function maintain_tag(event)
local tag = event.tag local tag = event.tag
if not event.player_index then return end if not event.player_index then return end
if not markers[tag.force.name .. tag.tag_number] 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 if player.admin then
-- Player is admin, tell them it was an admin marker -- Player is admin, tell them it was an admin marker
Commands.print({ "expcom-admin-marker.edit" }, nil, player) Commands.print({ "expcom-admin-marker.edit" }, nil, player)

View File

@@ -33,7 +33,7 @@ end
--- when an area is selected to add protection to the area --- when an area is selected to add protection to the area
Selection.on_selection(SelectionArtyArea, function(event) Selection.on_selection(SelectionArtyArea, function(event)
local area = aabb_align_expand(event.area) 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 if player == nil then
return return

View File

@@ -63,7 +63,7 @@ Commands.new_command("connect", { "expcom-connect.description" }, "Connect to an
server_id = new_server_id server_id = new_server_id
end end
Async(request_connection, player, server_id, true) request_connection_async(player, server_id, true)
end) end)
--- Connect a player to a different server --- Connect a player to a different server

View File

@@ -27,6 +27,7 @@ Commands.new_command("search-help", { "expcom-chelp.description" }, "Searches fo
local player_index = player and player.index or 0 local player_index = player and player.index or 0
-- if keyword is a number then treat it as page number -- if keyword is a number then treat it as page number
if tonumber(keyword) then if tonumber(keyword) then
--- @diagnostic disable-next-line: param-type-mismatch
page = math.floor(tonumber(keyword)) page = math.floor(tonumber(keyword))
keyword = "" keyword = ""
end end

View File

@@ -88,6 +88,7 @@ Commands.new_command("interface", { "expcom-interface.description" }, "Sends an
-- Compile the invocation with the custom _env value -- Compile the invocation with the custom _env value
local invocation_func, compile_error = load(invocation, "interface", nil, _env) local invocation_func, compile_error = load(invocation, "interface", nil, _env)
if compile_error then return Commands.error(compile_error) end if compile_error then return Commands.error(compile_error) end
--- @cast invocation_func -nil
-- Run the invocation -- Run the invocation
local success, rtn = pcall(invocation_func) local success, rtn = pcall(invocation_func)

View File

@@ -28,9 +28,9 @@ local function aabb_point_enclosed(point, aabb)
end end
--- Test if an aabb is inside another aabb --- Test if an aabb is inside another aabb
local function aabb_area_enclosed(aabbOne, aabbTwo) local function aabb_area_enclosed(aabb_one, aabb_two)
return aabb_point_enclosed(aabbOne.left_top, aabbTwo) return aabb_point_enclosed(aabb_one.left_top, aabb_two)
and aabb_point_enclosed(aabbOne.right_bottom, aabbTwo) and aabb_point_enclosed(aabb_one.right_bottom, aabb_two)
end end
--- Align an aabb to the grid by expanding it --- Align an aabb to the grid by expanding it
@@ -89,8 +89,8 @@ end
--- Remove a render object for a player --- Remove a render object for a player
local function remove_render(player, key) local function remove_render(player, key)
local render = renders[player.index][key] local render = renders[player.index][key] --[[@as LuaRenderObject]]
if render and rendering.is_valid(render) then rendering.destroy(render) end if render and render.valid then render.destroy() end
renders[player.index][key] = nil renders[player.index][key] = nil
end 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 --- When an area is selected to add protection to entities
Selection.on_selection(SelectionProtectEntity, function(event) 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 for _, entity in ipairs(event.entities) do
EntityProtection.add_entity(entity) EntityProtection.add_entity(entity)
show_protected_entity(player, entity) show_protected_entity(player, entity)
@@ -133,7 +133,7 @@ end)
--- When an area is selected to remove protection from entities --- When an area is selected to remove protection from entities
Selection.on_alt_selection(SelectionProtectEntity, function(event) 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 for _, entity in ipairs(event.entities) do
EntityProtection.remove_entity(entity) EntityProtection.remove_entity(entity)
remove_render(player, get_entity_key(entity)) remove_render(player, get_entity_key(entity))
@@ -146,7 +146,7 @@ end)
Selection.on_selection(SelectionProtectArea, function(event) Selection.on_selection(SelectionProtectArea, function(event)
local area = aabb_align_expand(event.area) local area = aabb_align_expand(event.area)
local areas = EntityProtection.get_areas(event.surface) 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 for _, next_area in pairs(areas) do
if aabb_area_enclosed(area, next_area) then if aabb_area_enclosed(area, next_area) then
return player.print{ "expcom-protection.already-protected" } return player.print{ "expcom-protection.already-protected" }
@@ -162,7 +162,7 @@ end)
Selection.on_alt_selection(SelectionProtectArea, function(event) Selection.on_alt_selection(SelectionProtectArea, function(event)
local area = aabb_align_expand(event.area) local area = aabb_align_expand(event.area)
local areas = EntityProtection.get_areas(event.surface) 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 for _, next_area in pairs(areas) do
if aabb_area_enclosed(next_area, area) then if aabb_area_enclosed(next_area, area) then
EntityProtection.remove_area(event.surface, next_area) EntityProtection.remove_area(event.surface, next_area)
@@ -175,7 +175,7 @@ end)
--- When selection starts show all protected entities and protected areas --- When selection starts show all protected entities and protected areas
Event.add(Selection.events.on_player_selection_start, function(event) Event.add(Selection.events.on_player_selection_start, function(event)
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end 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 local surface = player.surface
renders[player.index] = {} renders[player.index] = {}
-- Show protected entities -- Show protected entities
@@ -206,8 +206,8 @@ end)
--- When selection ends hide protected entities and protected areas --- When selection ends hide protected entities and protected areas
Event.add(Selection.events.on_player_selection_end, function(event) Event.add(Selection.events.on_player_selection_end, function(event)
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end
for _, id in pairs(renders[event.player_index]) do for _, render in pairs(renders[event.player_index]) do
if rendering.is_valid(id) then rendering.destroy(id) end if render.valid then render.destroy() end
end end
renders[event.player_index] = nil renders[event.player_index] = nil

View File

@@ -35,7 +35,7 @@ Commands.new_command("waterfill", { "expcom-waterfill.description" }, "Change ti
--- When an area is selected to add protection to the area --- When an area is selected to add protection to the area
Selection.on_selection(SelectionConvertArea, function(event) Selection.on_selection(SelectionConvertArea, function(event)
local area = aabb_align_expand(event.area) 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 if not player then
return return

View File

@@ -155,7 +155,7 @@ end
--- Raise events for protected entities --- Raise events for protected entities
Event.add(defines.events.on_pre_player_mined_item, function(event) Event.add(defines.events.on_pre_player_mined_item, function(event)
local entity = event.entity 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 -- Check if the player should be ignored
if config.ignore_admins and player.admin then return end 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 if entity.last_user == nil or entity.last_user.index == player.index then return end

View File

@@ -146,13 +146,13 @@ end
--- Stop selection if the selection tool is removed from the cursor --- Stop selection if the selection tool is removed from the cursor
Event.add(defines.events.on_player_cursor_stack_changed, function(event) 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 if player.cursor_stack.is_selection_tool then return end
Selection.stop(player) Selection.stop(player)
end) end)
--- Stop selection after an event such as death or leaving the game --- Stop selection after an event such as death or leaving the game
local function stop_after_event(event) local function stop_after_event(event)
local player = game.get_player(event.player_index) local player = game.players[event.player_index]
Selection.stop(player) Selection.stop(player)
end end

View File

@@ -46,10 +46,10 @@ function Tasks.add_task(force_name, player_name, task_title, task_body)
force_tasks._uid = force_tasks._uid + 1 force_tasks._uid = force_tasks._uid + 1
-- Get the existing tasks for this force -- 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 if not task_ids then
task_ids = {} task_ids = {}
force_tasks[force_name] = task_ids force_tasks[force_name] = task_ids --[[@as any]]
end end
-- Insert the task id into the forces tasks -- Insert the task id into the forces tasks

View File

@@ -17,7 +17,7 @@ CustomMessages:on_load(function(player_name, player_message)
local player = game.players[player_name] local player = game.players[player_name]
local custom_message = player_message or config[player_name] local custom_message = player_message or config[player_name]
if custom_message then if custom_message then
game.print(custom_message, player.color) game.print(custom_message, { color = player.color })
else else
player.print{ "join-message.greet", { "links.discord" } } player.print{ "join-message.greet", { "links.discord" } }
end end

View File

@@ -185,7 +185,7 @@ Event.on_nth_tick(60, function()
table.insert(force_research, { table.insert(force_research, {
name = research.name, name = research.name,
level = research.level, level = research.level,
progress = force.get_saved_technology_progress(research) or 0, progress = force.technologies[research.name].saved_progress
}) })
end end

View File

@@ -41,10 +41,10 @@ lib.collect_other = function()
local other = lib.data.output[force.name].other or {} local other = lib.data.output[force.name].other or {}
other.evolution = { other.evolution = {
evolution_factor = force.evolution_factor, evolution_factor = force.get_evolution_factor(game.surfaces[1]),
evolution_factor_by_pollution = force.evolution_factor_by_pollution, evolution_factor_by_pollution = force.get_evolution_factor_by_pollution(game.surfaces[1]),
evolution_factor_by_time = force.evolution_factor_by_time, evolution_factor_by_time = force.get_evolution_factor_by_time(game.surfaces[1]),
evolution_factor_by_killing_spawners = force.evolution_factor_by_killing_spawners, evolution_factor_by_killing_spawners = force.get_evolution_factor_by_killing_spawners(game.surfaces[1]),
} }
for k, v in pairs(other) do for k, v in pairs(other) do
lib.data.output[force.name].other[k] = v lib.data.output[force.name].other[k] = v

View File

@@ -78,7 +78,7 @@ local entity_toggle =
element.style = "shortcut_bar_button_green" element.style = "shortcut_bar_button_green"
end end
-- Correct the button size -- Correct the button size
local style = element.style local style = element.style --[[@as LuaStyle]]
style.padding = -2 style.padding = -2
style.height = 22 style.height = 22
style.width = 22 style.width = 22
@@ -147,7 +147,7 @@ local toggle_item_button =
element.style = "shortcut_bar_button_green" element.style = "shortcut_bar_button_green"
end end
-- Correct the button size -- Correct the button size
local style = element.style local style = element.style --[[@as LuaStyle]]
style.right_margin = -3 style.right_margin = -3
style.padding = -2 style.padding = -2
style.height = 32 style.height = 32
@@ -322,7 +322,7 @@ local function entity_build(event)
if not entity_settings.enabled then return end if not entity_settings.enabled then return end
-- Get the inventory of the player -- 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 } local text_position = { x = entity.position.x, y = entity.position.y }
-- Loop over all possible items to insert into the entity -- Loop over all possible items to insert into the entity

View File

@@ -109,7 +109,7 @@ end
--- when an area is selected to add protection to the area --- when an area is selected to add protection to the area
Selection.on_selection(SelectionModuleArea, function(event) Selection.on_selection(SelectionModuleArea, function(event)
local area = aabb_align_expand(event.area) 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 frame = Gui.get_left_element(player, module_container)
local scroll_table = frame.container.scroll.table local scroll_table = frame.container.scroll.table

View File

@@ -400,7 +400,7 @@ SelectedPlayer:on_update(function(player_name, selected_player)
style = "tool_button" style = "tool_button"
end end
element.style = style element.style = style
local element_style = element.style local element_style = element.style --[[@as LuaStyle]]
element_style.padding = -2 element_style.padding = -2
element_style.width = 8 element_style.width = 8
element_style.height = 14 element_style.height = 14

View File

@@ -14,7 +14,7 @@ local format_time = _C.format_time --- @dep expcore.common
local format_number = require("util").format_number --- @dep util local format_number = require("util").format_number --- @dep util
local tabs = {} local tabs = {}
local function Tab(caption, tooltip, element_define) local function define_tab(caption, tooltip, element_define)
tabs[#tabs + 1] = { caption, tooltip, element_define } tabs[#tabs + 1] = { caption, tooltip, element_define }
end end
@@ -111,7 +111,7 @@ local join_server =
--- Content area for the welcome tab --- Content area for the welcome tab
-- @element welcome_content -- @element welcome_content
Tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, define_tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" },
Gui.element(function(_, parent) 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" } 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 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 --- Content area for the rules tab
-- @element rules_content -- @element rules_content
Tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, define_tab({ "readme.rules-tab" }, { "readme.rules-tooltip" },
Gui.element(function(_, parent) Gui.element(function(_, parent)
local container = parent.add{ type = "flow", direction = "vertical" } local container = parent.add{ type = "flow", direction = "vertical" }
@@ -160,7 +160,7 @@ Tab({ "readme.rules-tab" }, { "readme.rules-tooltip" },
container.add{ type = "flow" } container.add{ type = "flow" }
-- Add a table for the rules -- 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 = "bordered_table"
rules.style.cell_padding = 4 rules.style.cell_padding = 4
@@ -174,7 +174,7 @@ Tab({ "readme.rules-tab" }, { "readme.rules-tooltip" },
--- Content area for the commands tab --- Content area for the commands tab
-- @element commands_content -- @element commands_content
Tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, define_tab({ "readme.commands-tab" }, { "readme.commands-tooltip" },
Gui.element(function(_, parent) Gui.element(function(_, parent)
local container = parent.add{ type = "flow", direction = "vertical" } local container = parent.add{ type = "flow", direction = "vertical" }
local player = Gui.get_player_from_element(parent) local player = Gui.get_player_from_element(parent)
@@ -186,7 +186,7 @@ Tab({ "readme.commands-tab" }, { "readme.commands-tooltip" },
container.add{ type = "flow" } container.add{ type = "flow" }
-- Add a table for the commands -- 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 = "bordered_table"
commands.style.cell_padding = 0 commands.style.cell_padding = 0
@@ -201,7 +201,7 @@ Tab({ "readme.commands-tab" }, { "readme.commands-tooltip" },
--- Content area for the servers tab --- Content area for the servers tab
-- @element servers_content -- @element servers_content
Tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, define_tab({ "readme.servers-tab" }, { "readme.servers-tooltip" },
Gui.element(function(_, parent) Gui.element(function(_, parent)
local container = parent.add{ type = "flow", direction = "vertical" } 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 --- Content area for the servers tab
-- @element backers_content -- @element backers_content
Tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, define_tab({ "readme.backers-tab" }, { "readme.backers-tooltip" },
Gui.element(function(_, parent) Gui.element(function(_, parent)
local container = parent.add{ type = "flow", direction = "vertical" } 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 --- Content area for the player data tab
-- @element commands_content -- @element commands_content
Tab({ "readme.data-tab" }, { "readme.data-tooltip" }, define_tab({ "readme.data-tab" }, { "readme.data-tooltip" },
Gui.element(function(_, parent) Gui.element(function(_, parent)
local container = parent.add{ type = "flow", direction = "vertical" } local container = parent.add{ type = "flow", direction = "vertical" }
local player = Gui.get_player_from_element(parent) local player = Gui.get_player_from_element(parent)

View File

@@ -74,7 +74,7 @@ end
--- When an area is selected to add protection to the area --- When an area is selected to add protection to the area
Selection.on_selection(SelectionConvertArea, function(event) Selection.on_selection(SelectionConvertArea, function(event)
local area = aabb_align_expand(event.area) 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 if not player then
return nil return nil
@@ -99,7 +99,7 @@ Selection.on_selection(SelectionConvertArea, function(event)
local e = entities[1] local e = entities[1]
local e_pos = { x = string.format("%.1f", e.position.x), y = string.format("%.1f", e.position.y) } 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 if not e.get_inventory(defines.inventory.chest).is_empty() then
player.print{ "vlayer.steel-chest-empty" } player.print{ "vlayer.steel-chest-empty" }

View File

@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
-- luacheck:ignore global table -- luacheck:ignore global table
local random = math.random local random = math.random
local floor = math.floor local floor = math.floor
@@ -270,7 +271,7 @@ end
-- @param x one comparator operand -- @param x one comparator operand
-- @param y the other comparator operand -- @param y the other comparator operand
-- @return true if x logically comes before y in a list, false otherwise -- @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 tx = type(x)
local ty = type(y) local ty = type(y)
if tx == ty then if tx == ty then
@@ -307,7 +308,7 @@ function table.get_values(tbl, sorted, as_string)
end end
end end
if sorted then if sorted then
table.sort(valueset, sortFunc) table.sort(valueset, sort_func)
end end
return valueset return valueset
end end
@@ -333,7 +334,7 @@ function table.get_keys(tbl, sorted, as_string)
end end
end end
if sorted then if sorted then
table.sort(keyset, sortFunc) table.sort(keyset, sort_func)
end end
return keyset return keyset
end end

View File

@@ -74,7 +74,7 @@ local function handler_factory(event_name)
return function(element_name, handler) return function(element_name, handler)
Event.add(defines.events[event_name], function(event) Event.add(defines.events[event_name], function(event)
if event.element and event.element.valid and event.element.name == element_name then 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) handler(event)
end end
end) end)

View File

@@ -204,15 +204,15 @@ end
-- @param[opt] tableAsJson If table values should be returned as json -- @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 -- @param[opt] maxLineCount If table newline count exceeds provided then it will be inlined
-- @return The formated version of the value -- @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) local formatted, is_locale_string = Common.safe_value(value)
if type(formatted) == "table" and not is_locale_string then 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) local success, rtn = pcall(game.table_to_json, value)
if success then return rtn end if success then return rtn end
end end
local rtn = table.inspect(value, { depth = 5, indent = " ", newline = "\n", process = Common.safe_value }) 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 }) return table.inspect(value, { depth = 5, indent = "", newline = "", process = Common.safe_value })
end end
return formatted 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 local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60
-- Calculate rhw units to be displayed -- 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) 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.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.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end
if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end
--- @diagnostic enable: cast-local-type
end end
local rtn = {} 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 local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60
-- Calculate rhw units to be displayed -- 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) 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.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.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end
if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end
--- @diagnostic enable: cast-local-type
end end
local rtn = {} 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.hours then rtn[#rtn + 1] = rtn_hours end
if units.minutes then rtn[#rtn + 1] = rtn_minutes end if units.minutes then rtn[#rtn + 1] = rtn_minutes end
if units.seconds then rtn[#rtn + 1] = rtn_seconds end if units.seconds then rtn[#rtn + 1] = rtn_seconds end
--- @diagnostic disable-next-line: cast-local-type
join = { "colon" } join = { "colon" }
elseif format == "short" then elseif format == "short" then
-- Example 12d 34h 56m or --d --h --m -- 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] } rtn[#rtn] = { "", { "and" }, " ", rtn[#rtn] }
end end
local joined = { "" } local joined = { "" } --[[@as any]]
for k, v in ipairs(rtn) do for k, v in ipairs(rtn) do
joined[2 * k] = v joined[2 * k] = v
joined[2 * k + 1] = join joined[2 * k + 1] = join --[[@as any]]
end end
return joined return joined

View File

@@ -5,20 +5,20 @@
@usage-- Show player chat message in world @usage-- Show player chat message in world
local function on_console_chat(event) 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) FloatingText.print_as_player(player, event.message)
end end
@usage-- Show player tags above their characters @usage-- Show player tags above their characters
local function on_player_respawned(event) 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) FloatingText.create_tag_as_player(player, player.tag)
end end
@usage-- Show placed an entity in alt mode @usage-- Show placed an entity in alt mode
local function on_built_entity(event) local function on_built_entity(event)
local entity = event.created_entity 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) FloatingText.create_tag_above_entity(entity, player.name, player.color, true)
end end

View File

@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
-- luacheck:ignore global table -- luacheck:ignore global table
local random = math.random local random = math.random
@@ -259,7 +260,7 @@ end
-- @param x one comparator operand -- @param x one comparator operand
-- @param y the other comparator operand -- @param y the other comparator operand
-- @return true if x logically comes before y in a list, false otherwise -- @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 tx = type(x)
local ty = type(y) local ty = type(y)
if tx == ty then if tx == ty then
@@ -296,7 +297,7 @@ function table.get_values(tbl, sorted, as_string)
end end
end end
if sorted then if sorted then
table.sort(valueset, sortFunc) table.sort(valueset, sort_func)
end end
return valueset return valueset
end end
@@ -322,7 +323,7 @@ function table.get_keys(tbl, sorted, as_string)
end end
end end
if sorted then if sorted then
table.sort(keyset, sortFunc) table.sort(keyset, sort_func)
end end
return keyset return keyset
end end