Fix start, join, formatting, and locale issues

This commit is contained in:
Cooldude2606
2024-11-14 23:59:22 +00:00
parent 48f55b0547
commit 9aee1c425f
29 changed files with 168 additions and 135 deletions

View File

@@ -38,27 +38,37 @@ function Commands.lock_system_commands(player_name)
end end
--- Get a list of all players who have system commands unlocked --- Get a list of all players who have system commands unlocked
function Commands.get_system_command_players() function Commands.get_system_players()
return table.get_keys(system_players) return table.get_keys(system_players)
end end
--- Check if a player is a system user
function Commands.is_system_player(player_name)
return system_players[player_name] or false
end
--- Stops a command from be used by any one --- Stops a command from be used by any one
--- @param command_name string The name of the command to disable --- @param command_name string The name of the command to disable
function Commands.disable(command_name) function Commands.disable_command(command_name)
disabled_commands[command_name] = true disabled_commands[command_name] = true
end end
--- Allows a command to be used again after disable was used --- Allows a command to be used again after disable was used
--- @param command_name string The name of the command to enable --- @param command_name string The name of the command to enable
function Commands.enable(command_name) function Commands.enable_command(command_name)
disabled_commands[command_name] = nil disabled_commands[command_name] = nil
end end
--- Get a list of all players who have system commands unlocked --- Get a list of all disabled commands_help
function Commands.get_disabled_commands() function Commands.get_disabled_commands()
return table.get_keys(disabled_commands) return table.get_keys(disabled_commands)
end end
--- Check if a player is a system user
function Commands.is_disabled_command(command_name)
return disabled_commands[command_name] or false
end
--- If a command has the flag "character_only" then the command can only be used outside of remote view --- If a command has the flag "character_only" then the command can only be used outside of remote view
authorities.character_only = authorities.character_only =
add(function(player, command) add(function(player, command)
@@ -89,7 +99,7 @@ authorities.admin_only =
end end
end) end)
--- If a command has the flag "system_only" then only rcon connections can use the command --- If a command has the flag "system_only" then only rcon and system users can use the command
authorities.system_only = authorities.system_only =
add(function(player, command) add(function(player, command)
if command.flags.system_only and not system_players[player.name] then if command.flags.system_only and not system_players[player.name] then
@@ -99,10 +109,10 @@ authorities.system_only =
end end
end) end)
--- If Commands.disable was called then no one can use the command --- If Commands.disable_command was called then only rcon and system users can use the command
authorities.disabled = authorities.disabled =
add(function(player, command) add(function(player, command)
if disabled_commands[command.name] then if disabled_commands[command.name] and not system_players[player.name] then
return deny{ "exp-commands-authorities.disabled" } return deny{ "exp-commands-authorities.disabled" }
else else
return allow() return allow()

View File

@@ -86,6 +86,7 @@ Commands.new("_rcon", { "exp-commands_rcon.description" })
if compile_error then if compile_error then
return Commands.status.invalid_input(compile_error) return Commands.status.invalid_input(compile_error)
else else
--- @cast invocation -nil
local success, rtn = xpcall(invocation, debug.traceback) local success, rtn = xpcall(invocation, debug.traceback)
if success == false then if success == false then
return Commands.status.error(rtn) return Commands.status.error(rtn)

View File

@@ -395,7 +395,7 @@ end
-- The prototype definition for command objects -- The prototype definition for command objects
local function assert_command_mutable(command) local function assert_command_mutable(command)
if not Commands.registered_commands[command.name] then if Commands.registered_commands[command.name] then
error("Command cannot be modified after being registered.", 3) error("Command cannot be modified after being registered.", 3)
end end
end end

View File

@@ -28,7 +28,6 @@ return {
"modules.addons.nukeprotect", "modules.addons.nukeprotect",
"modules.addons.inserter", "modules.addons.inserter",
"modules.addons.miner", "modules.addons.miner",
"modules.addons.lawnmower",
"modules.addons.logging", "modules.addons.logging",
-- Control -- Control

View File

@@ -22,6 +22,7 @@ end)
Roles.new_role("System", "SYS") Roles.new_role("System", "SYS")
:set_permission_group("Default", true) :set_permission_group("Default", true)
:set_flag("is_admin") :set_flag("is_admin")
:set_flag("is_system")
:set_flag("is_spectator") :set_flag("is_spectator")
:set_flag("report-immune") :set_flag("report-immune")
:set_flag("instant-respawn") :set_flag("instant-respawn")
@@ -31,14 +32,15 @@ Roles.new_role("Senior Administrator", "SAdmin")
:set_permission_group("Admin") :set_permission_group("Admin")
:set_custom_color{ r = 233, g = 63, b = 233 } :set_custom_color{ r = 233, g = 63, b = 233 }
:set_flag("is_admin") :set_flag("is_admin")
:set_flag("is_system")
:set_flag("is_spectator") :set_flag("is_spectator")
:set_flag("report-immune") :set_flag("report-immune")
:set_flag("instant-respawn") :set_flag("instant-respawn")
:set_parent("Administrator") :set_parent("Administrator")
:allow{ :allow{
"command/interface", "command/_rcon",
"command/debug", "command/debug",
"command/toggle-cheat-mode", "command/set-cheat-mode",
"command/research-all", "command/research-all",
} }
@@ -54,7 +56,6 @@ Roles.new_role("Administrator", "Admin")
"gui/warp-list/bypass-proximity", "gui/warp-list/bypass-proximity",
"gui/warp-list/bypass-cooldown", "gui/warp-list/bypass-cooldown",
"command/connect-all", "command/connect-all",
"command/collectdata",
} }
Roles.new_role("Moderator", "Mod") Roles.new_role("Moderator", "Mod")
@@ -71,21 +72,29 @@ Roles.new_role("Moderator", "Mod")
"command/repair", "command/repair",
"command/kill/always", "command/kill/always",
"command/clear-tag/always", "command/clear-tag/always",
"command/go-to-spawn/always", "command/spawn/always",
"command/clear-reports", "command/clear-reports",
"command/clear-warnings", "command/clear-warnings",
"command/clear-script-warnings",
"command/clear-last-warnings",
"command/clear-inventory", "command/clear-inventory",
-- 'command/bonus', "command/kill-enemies",
"gui/bonus", "command/remove-enemies",
--'command/bonus',
"command/home", "command/home",
"command/home-set", "command/set-home",
"command/home-get", "command/get-home",
"command/return", "command/return",
"command/connect-player", "command/connect-player",
"command/set-bot-queue",
"command/set-game-speed",
"command/set-friendly-fire",
"command/set-always-day",
"command/set-pollution-enabled",
"command/clear-pollution",
"gui/rocket-info/toggle-active", "gui/rocket-info/toggle-active",
"gui/rocket-info/remote_launch", "gui/rocket-info/remote_launch",
"command/toggle-friendly-fire", "gui/bonus",
"command/toggle-always-day",
"fast-tree-decon", "fast-tree-decon",
} }
@@ -98,15 +107,15 @@ Roles.new_role("Trainee", "TrMod")
:set_parent("Veteran") :set_parent("Veteran")
:allow{ :allow{
"command/admin-chat", "command/admin-chat",
"command/admin-marker",
"command/goto", "command/goto",
"command/teleport", "command/teleport",
"command/bring", "command/bring",
"command/give-warning", "command/create-warning",
"command/get-warnings", "command/get-warnings",
"command/get-reports", "command/get-reports",
"command/protect-entity", "command/protect-entity",
"command/protect-area", "command/protect-area",
"command/protect-tag",
"command/jail", "command/jail",
"command/unjail", "command/unjail",
"command/kick", "command/kick",
@@ -114,17 +123,10 @@ Roles.new_role("Trainee", "TrMod")
"command/spectate", "command/spectate",
"command/follow", "command/follow",
"command/search", "command/search",
"command/search-online",
"command/search-amount", "command/search-amount",
"command/search-recent", "command/search-recent",
"command/search-online", "command/clear-blueprints",
"command/personal-battery-recharge",
"command/pollution-off",
"command/pollution-clear",
"command/bot-queue-get",
"command/bot-queue-set",
"command/game-speed",
"command/kill-biters",
"command/remove-biters",
"gui/playerdata", "gui/playerdata",
} }
@@ -164,11 +166,11 @@ Roles.new_role("Sponsor", "Spon")
:allow{ :allow{
"gui/rocket-info/toggle-active", "gui/rocket-info/toggle-active",
"gui/rocket-info/remote_launch", "gui/rocket-info/remote_launch",
-- 'command/bonus',
"gui/bonus", "gui/bonus",
--"command/bonus",
"command/home", "command/home",
"command/home-set", "command/set-home",
"command/home-get", "command/get-home",
"command/return", "command/return",
"fast-tree-decon", "fast-tree-decon",
} }
@@ -182,8 +184,8 @@ Roles.new_role("Supporter", "Sup")
"command/tag-color", "command/tag-color",
"command/jail", "command/jail",
"command/unjail", "command/unjail",
"command/join-message", "command/set-join-message",
"command/join-message-clear", "command/remove-join-message",
} }
Roles.new_role("Partner", "Part") Roles.new_role("Partner", "Part")
@@ -203,7 +205,10 @@ Roles.new_role("Veteran", "Vet")
:set_parent("Member") :set_parent("Member")
:allow{ :allow{
"command/chat-bot", "command/chat-bot",
"command/last-location", "command/clear-ground-items",
"command/clear-blueprints-radius",
"command/set-trains-to-automatic",
"command/set-auto-research",
} }
:set_auto_assign_condition(function(player) :set_auto_assign_condition(function(player)
if player.online_time >= hours10 then if player.online_time >= hours10 then
@@ -226,18 +231,14 @@ Roles.new_role("Member", "Mem")
"gui/task-list/edit", "gui/task-list/edit",
"gui/warp-list/add", "gui/warp-list/add",
"gui/warp-list/edit", "gui/warp-list/edit",
"command/save-quickbar", "gui/surveillance",
"gui/vlayer-edit", "gui/vlayer-edit",
"command/save-quickbar",
"command/vlayer-info", "command/vlayer-info",
"command/personal-logistic", "command/personal-logistic",
"command/auto-research",
"command/set-trains-to-automatic",
"command/lawnmower", "command/lawnmower",
"command/waterfill", "command/waterfill",
"command/artillery-target-remote", "command/artillery",
"command/clear-item-on-ground",
"command/clear-blueprint",
"gui/surveillance",
} }
local hours3, hours15 = 3 * 216000, 15 * 60 local hours3, hours15 = 3 * 216000, 15 * 60
@@ -248,7 +249,7 @@ Roles.new_role("Regular", "Reg")
:allow{ :allow{
"command/kill", "command/kill",
"command/rainbow", "command/rainbow",
"command/go-to-spawn", "command/spawn",
"command/me", "command/me",
"standard-decon", "standard-decon",
"bypass-entity-protection", "bypass-entity-protection",
@@ -271,15 +272,14 @@ local default = Roles.new_role("Guest", "")
:allow{ :allow{
"command/tag", "command/tag",
"command/tag-clear", "command/tag-clear",
"command/search-help", "command/commands",
"command/list-roles", "command/get-role",
"command/find-on-map", "command/locate",
"command/report", "command/create-report",
"command/ratio", "command/ratio",
"command/server-ups", "command/server-ups",
"command/save-data", "command/save-data",
"command/preference", "command/data-preference",
"command/set-preference",
"command/connect", "command/connect",
"gui/player-list", "gui/player-list",
"gui/rocket-info", "gui/rocket-info",

View File

@@ -12,7 +12,7 @@ local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep m
local Warnings = require("modules.exp_legacy.modules.control.warnings") --- @dep modules.control.warnings local Warnings = require("modules.exp_legacy.modules.control.warnings") --- @dep modules.control.warnings
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
local Colors = require("modules/exp_util/include/color") local Colors = require("modules/exp_util/include/color")
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common local format_player_name = ExpUtil.format_player_name_locale
local SelectedPlayer, SelectedAction local SelectedPlayer, SelectedAction
local function set_datastores(player, action) local function set_datastores(player, action)
@@ -91,7 +91,7 @@ local report_player = new_button("utility/spawn_flag", { "player-list.report-pla
:on_click(function(player) :on_click(function(player)
local selected_player_name = get_action_player_name(player) local selected_player_name = get_action_player_name(player)
if Reports.is_reported(selected_player_name, player.name) then if Reports.is_reported(selected_player_name, player.name) then
player.print({ "expcom-report.already-reported" }, Colors.orange_red) player.print({ "exp-commands_report.already-reported" }, Colors.orange_red)
else else
SelectedAction:set(player, "command/report") SelectedAction:set(player, "command/report")
end end
@@ -100,8 +100,8 @@ local report_player = new_button("utility/spawn_flag", { "player-list.report-pla
local function report_player_callback(player, reason) local function report_player_callback(player, reason)
local selected_player_name, selected_player_color = get_action_player_name(player) local selected_player_name, selected_player_color = get_action_player_name(player)
local by_player_name_color = format_player_name(player) local by_player_name_color = format_player_name(player)
game.print{ "expcom-report.non-admin", selected_player_color, reason } game.print{ "exp-commands_reports.response", selected_player_color, reason }
Roles.print_to_roles_higher("Trainee", { "expcom-report.admin", selected_player_color, by_player_name_color, reason }) Roles.print_to_roles_higher("Trainee", { "exp-commands_reports.response-admin", selected_player_color, by_player_name_color, reason })
Reports.report_player(selected_player_name, player.name, reason) Reports.report_player(selected_player_name, player.name, reason)
end end
@@ -115,7 +115,7 @@ local warn_player = new_button("utility/spawn_flag", { "player-list.warn-player"
local function warn_player_callback(player, reason) local function warn_player_callback(player, reason)
local selected_player_name, selected_player_color = get_action_player_name(player) local selected_player_name, selected_player_color = get_action_player_name(player)
local by_player_name_color = format_player_name(player) local by_player_name_color = format_player_name(player)
game.print{ "expcom-warnings.received", selected_player_color, by_player_name_color, reason } game.print{ "exp-commands_warnings.create", selected_player_color, by_player_name_color, reason }
Warnings.add_warning(selected_player_name, player.name, reason) Warnings.add_warning(selected_player_name, player.name, reason)
end end
@@ -125,7 +125,7 @@ local jail_player = new_button("utility/multiplayer_waiting_icon", { "player-lis
:on_click(function(player) :on_click(function(player)
local selected_player_name, selected_player_color = get_action_player_name(player) local selected_player_name, selected_player_color = get_action_player_name(player)
if Jail.is_jailed(selected_player_name) then if Jail.is_jailed(selected_player_name) then
player.print({ "expcom-jail.already-jailed", selected_player_color }, Colors.orange_red) player.print({ "exp-commands_jail.already-jailed", selected_player_color }, Colors.orange_red)
else else
SelectedAction:set(player, "command/jail") SelectedAction:set(player, "command/jail")
end end
@@ -134,7 +134,7 @@ local jail_player = new_button("utility/multiplayer_waiting_icon", { "player-lis
local function jail_player_callback(player, reason) local function jail_player_callback(player, reason)
local selected_player_name, selected_player_color = get_action_player_name(player) local selected_player_name, selected_player_color = get_action_player_name(player)
local by_player_name_color = format_player_name(player) local by_player_name_color = format_player_name(player)
game.print{ "expcom-jail.give", selected_player_color, by_player_name_color, reason } game.print{ "exp-commands_jail.jailed", selected_player_color, by_player_name_color, reason }
Jail.jail_player(selected_player_name, player.name, reason) Jail.jail_player(selected_player_name, player.name, reason)
end end

View File

@@ -3,15 +3,6 @@
-- all files which are loaded (including the config files) are present in ./config/file_loader.lua -- all files which are loaded (including the config files) are present in ./config/file_loader.lua
-- 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
--- @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("[START] -----| Explosive Gaming Scenario Loader |-----")
log("[INFO] Setting up lua environment") log("[INFO] Setting up lua environment")

View File

@@ -15,6 +15,7 @@ left-button-tooltip=Hide all open windows.
[expcore-data] [expcore-data]
description-preference=Allows you to set/get your data saving preference. description-preference=Allows you to set/get your data saving preference.
description-data=Writes all your player data to a file on your computer. description-data=Writes all your player data to a file on your computer.
arg-option=One of "All", "Statistics", "Settings", "Required"
set-preference=You data saving preference has been set to __1__. Existing data will not be effected until you rejoin. set-preference=You data saving preference has been set to __1__. Existing data will not be effected until you rejoin.
get-preference=You data saving preference is __1__. Use /set-preference to change this. Use /save-data to get a local copy of your data. get-preference=You data saving preference is __1__. Use /set-preference to change this. Use /save-data to get a local copy of your data.
get-data=Your player data has been writen to file, location: factorio/script_output/expgaming_player_data.json get-data=Your player data has been writen to file, location: factorio/script_output/expgaming_player_data.json

View File

@@ -23,6 +23,9 @@ end)
local speech_bubble_async = local speech_bubble_async =
Async.register(function(data) Async.register(function(data)
--- @cast data { ent: LuaEntity, name: string, msg_number: number }
if not data.ent.valid then return end
local message = local message =
data.ent.surface.create_entity{ data.ent.surface.create_entity{
name = "compi-speech-bubble", name = "compi-speech-bubble",

View File

@@ -6,7 +6,7 @@ local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Storage = require("modules/exp_util/storage") --- @dep utils.global local Storage = require("modules/exp_util/storage") --- @dep utils.global
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
local Protection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection local Protection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common local format_player_name = ExpUtil.format_player_name_locale
--- Stores how many times the repeat violation was triggered --- Stores how many times the repeat violation was triggered
local repeat_count = {} local repeat_count = {}

View File

@@ -5,7 +5,7 @@ local ExpUtil = require("modules/exp_util")
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common local format_player_name = ExpUtil.format_player_name_locale
--- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters --- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters
local function reporter_playtime(_, by_player_name, _) local function reporter_playtime(_, by_player_name, _)

View File

@@ -8,7 +8,7 @@ local ExpUtil = require("modules/exp_util")
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands local Commands = require("modules/exp_commands") --- @dep expcore.commands
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external
local format_number = require("util").format_number --- @dep util local format_number = require("util").format_number --- @dep util
@@ -193,9 +193,9 @@ define_tab({ "readme.commands-tab" }, { "readme.commands-tooltip" },
commands.style.cell_padding = 0 commands.style.cell_padding = 0
-- Add the rules to the table -- Add the rules to the table
for name, command in pairs(Commands.get(player)) do for name, command in pairs(Commands.list_for_player(player)) do
Gui.centered_label(commands, 120, name) Gui.centered_label(commands, 120, name)
Gui.centered_label(commands, 450, command.help) Gui.centered_label(commands, 450, command.description)
end end
return container return container

View File

@@ -395,7 +395,7 @@ local vlayer_gui_control_build =
Selection.stop(player) Selection.stop(player)
else else
Selection.start(player, SelectionConvertArea) Selection.start(player, SelectionConvertArea)
player.print{ "expcom-waterfill.entered-area-selection" } player.print{ "exp-commands_waterfill.entered-area-selection" }
end end
vlayer_gui_list_refresh(player) vlayer_gui_list_refresh(player)

View File

@@ -13,11 +13,19 @@ local authorities = {}
--- If a command has the flag "character_only" then the command can only be used outside of remote view --- If a command has the flag "character_only" then the command can only be used outside of remote view
authorities.exp_permission = authorities.exp_permission =
add(function(player, command) add(function(player, command)
if not player_allowed(player, command.flags.exp_permission or ("command/" .. command)) then if not player_allowed(player, command.flags.exp_permission or ("command/" .. command.name)) then
return deny{ "exp-commands-authorities_role.deny" } return deny{ "exp-commands-authorities_role.deny" }
else else
return allow() return allow()
end end
end) end)
Roles.define_flag_trigger("is_system", function(player, state)
if state then
Commands.unlock_system_commands(player.name)
else
Commands.lock_system_commands(player.name)
end
end)
return authorities return authorities

View File

@@ -5,8 +5,9 @@ Adds a command that allows viewing and changing the construction queue limits
local Commands = require("modules/exp_commands") local Commands = require("modules/exp_commands")
--- Get / Set the current values for the bot queue --- Get / Set the current values for the bot queue
Commands.new("bot-queue", { "exp-commands_bot-queue.description" }) Commands.new("set-bot-queue", { "exp-commands_bot-queue.description" })
:optional("amount", { "exp-commands_bot-queue.arg-amount" }, Commands.types.integer_range(1, 20)) :optional("amount", { "exp-commands_bot-queue.arg-amount" }, Commands.types.integer_range(1, 20))
:add_aliases{ "bot-queue" }
:add_flags{ "admin_only" } :add_flags{ "admin_only" }
:register(function(player, amount) :register(function(player, amount)
if amount then if amount then

View File

@@ -52,7 +52,7 @@ end
--- Connect to a different server --- Connect to a different server
Commands.new("connect", { "exp-commands_connect.description" }) Commands.new("connect", { "exp-commands_connect.description" })
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string) :argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
:optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean) :optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean)
:add_aliases{ "join" } :add_aliases{ "join" }
:register(function(player, server, is_address) :register(function(player, server, is_address)
--- @cast server string --- @cast server string
@@ -72,7 +72,7 @@ Commands.new("connect", { "exp-commands_connect.description" })
Commands.new("connect-player", { "exp-commands_connect.description-player" }) Commands.new("connect-player", { "exp-commands_connect.description-player" })
:argument("player", { "exp-commands_connect.arg-player" }, Commands.types.player_online) :argument("player", { "exp-commands_connect.arg-player" }, Commands.types.player_online)
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string) :argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
:optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean) :optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean)
:add_flags{ "admin_only" } :add_flags{ "admin_only" }
:register(function(player, other_player, server, is_address) :register(function(player, other_player, server, is_address)
--- @cast other_player LuaPlayer --- @cast other_player LuaPlayer
@@ -92,7 +92,7 @@ Commands.new("connect-player", { "exp-commands_connect.description-player" })
--- Connect all players to a different server --- Connect all players to a different server
Commands.new("connect-all", { "exp-commands_connect.description-all" }) Commands.new("connect-all", { "exp-commands_connect.description-all" })
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string) :argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
:optional("is-address", { "exp-commands_connect.is-address" }, Commands.types.boolean) :optional("is-address", { "exp-commands_connect.arg-is-address" }, Commands.types.boolean)
:add_flags{ "admin_only" } :add_flags{ "admin_only" }
:register(function(player, server, is_address) :register(function(player, server, is_address)
--- @cast server string --- @cast server string

View File

@@ -92,28 +92,28 @@ local function remove_render(player, key)
end end
--- Toggles entity protection selection --- Toggles entity protection selection
Commands.new("protect-entity", { "exp-commands_protection.description-entity" }) Commands.new("protect-entity", { "exp-commands_entity-protection.description-entity" })
:add_aliases{ "pe" } :add_aliases{ "pe" }
:register(function(player) :register(function(player)
if Selection.is_selecting(player, SelectionNameEntity) then if Selection.is_selecting(player, SelectionNameEntity) then
Selection.stop(player) Selection.stop(player)
return Commands.status.success{ "exp-commands_protection.exit-entity" } return Commands.status.success{ "exp-commands_entity-protection.exit-entity" }
else else
Selection.start(player, SelectionNameEntity) Selection.start(player, SelectionNameEntity)
return Commands.status.success{ "exp-commands_protection.enter-entity" } return Commands.status.success{ "exp-commands_entity-protection.enter-entity" }
end end
end) end)
--- Toggles area protection selection --- Toggles area protection selection
Commands.new("protect-area", { "exp-commands_protection.description-area" }) Commands.new("protect-area", { "exp-commands_entity-protection.description-area" })
:add_aliases{ "pa" } :add_aliases{ "pa" }
:register(function(player) :register(function(player)
if Selection.is_selecting(player, SelectionNameEntity) then if Selection.is_selecting(player, SelectionNameEntity) then
Selection.stop(player) Selection.stop(player)
return Commands.status.success{ "exp-commands_protection.exit-area" } return Commands.status.success{ "exp-commands_entity-protection.exit-area" }
else else
Selection.start(player, SelectionNameEntity) Selection.start(player, SelectionNameEntity)
return Commands.status.success{ "exp-commands_protection.enter-area" } return Commands.status.success{ "exp-commands_entity-protection.enter-area" }
end end
end) end)
@@ -126,7 +126,7 @@ Selection.on_selection(SelectionNameEntity, function(event)
show_protected_entity(player, entity) show_protected_entity(player, entity)
end end
player.print({ "exp-commands_protection.protected-entities", #event.entities }, Commands.print_settings.default) player.print({ "exp-commands_entity-protection.protected-entities", #event.entities }, Commands.print_settings.default)
end) end)
--- When an area is selected to remove protection from entities --- When an area is selected to remove protection from entities
@@ -138,7 +138,7 @@ Selection.on_alt_selection(SelectionNameEntity, function(event)
remove_render(player, get_entity_key(entity)) remove_render(player, get_entity_key(entity))
end end
player.print({ "exp-commands_protection.unprotected-entities", #event.entities }, Commands.print_settings.default) player.print({ "exp-commands_entity-protection.unprotected-entities", #event.entities }, Commands.print_settings.default)
end) end)
--- When an area is selected to add protection to the area --- When an area is selected to add protection to the area
@@ -150,13 +150,13 @@ Selection.on_selection(SelectionNameArea, function(event)
local player = game.players[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 contains_area(next_area, area) then if contains_area(next_area, area) then
return player.print({ "exp-commands_protection.already-protected" }, Commands.print_settings.error) return player.print({ "exp-commands_entity-protection.already-protected" }, Commands.print_settings.error)
end end
end end
EntityProtection.add_area(surface, area) EntityProtection.add_area(surface, area)
show_protected_area(player, surface, area) show_protected_area(player, surface, area)
player.print({ "exp-commands_protection.protected-area" }, Commands.print_settings.default) player.print({ "exp-commands_entity-protection.protected-area" }, Commands.print_settings.default)
end) end)
--- When an area is selected to remove protection from the area --- When an area is selected to remove protection from the area
@@ -169,7 +169,7 @@ Selection.on_alt_selection(SelectionNameArea, function(event)
for _, next_area in pairs(areas) do for _, next_area in pairs(areas) do
if contains_area(area, next_area) then if contains_area(area, next_area) then
EntityProtection.remove_area(surface, next_area) EntityProtection.remove_area(surface, next_area)
player.print({ "exp-commands_protection.unprotected-area" }, Commands.print_settings.default) player.print({ "exp-commands_entity-protection.unprotected-area" }, Commands.print_settings.default)
remove_render(player, get_area_key(next_area)) remove_render(player, get_area_key(next_area))
end end
end end
@@ -222,7 +222,7 @@ end
--- When there is a repeat offence print it in chat --- When there is a repeat offence print it in chat
local function on_repeat_violation(event) local function on_repeat_violation(event)
Roles.print_to_roles_higher("Regular", { Roles.print_to_roles_higher("Regular", {
"exp-commands_protection.repeat-offence", "exp-commands_entity-protection.repeat-offence",
format_player_name(event.player_index), format_player_name(event.player_index),
event.entity.localised_name, event.entity.localised_name,
event.entity.position.x, event.entity.position.x,

View File

@@ -18,17 +18,17 @@ Storage.register({
end) end)
--- Toggle admin marker mode, can only be applied to yourself --- Toggle admin marker mode, can only be applied to yourself
local cmd_protected_tag = local cmd_protect_tag =
Commands.new("protected-tag", { "exp-commands_protected-tags.description" }) Commands.new("protect-tag", { "exp-commands_tag-protection.description" })
:add_aliases{ "ptag" } :add_aliases{ "ptag" }
:add_flags{ "admin_only" } :add_flags{ "admin_only" }
:register(function(player) :register(function(player)
if active_players[player.index] then if active_players[player.index] then
active_players[player.index] = nil active_players[player.index] = nil
return Commands.status.success{ "exp-commands_protected-tags.exit" } return Commands.status.success{ "exp-commands_tag-protection.exit" }
else else
active_players[player.index] = true active_players[player.index] = true
return Commands.status.success{ "exp-commands_protected-tags.enter" } return Commands.status.success{ "exp-commands_tag-protection.enter" }
end end
end) end)
@@ -47,7 +47,7 @@ local function on_chart_tag_added(event)
local tag = event.tag local tag = event.tag
local player = game.players[event.player_index] local player = game.players[event.player_index]
map_tags[tag.force.name .. tag.tag_number] = true map_tags[tag.force.name .. tag.tag_number] = true
player.print{ "exp-commands_protected-tags.create" } player.print{ "exp-commands_tag-protection.create" }
end end
--- Stop a tag from being edited or removed --- Stop a tag from being edited or removed
@@ -60,7 +60,7 @@ local function on_chart_tag_removed_or_modified(event)
-- Check if the player is in protected mode, and inform them that it was protected -- Check if the player is in protected mode, and inform them that it was protected
if active_players[event.player_index] then if active_players[event.player_index] then
player.print{ "exp-commands_protected-tags.edit" } player.print{ "exp-commands_tag-protection.edit" }
return return
end end
@@ -92,12 +92,12 @@ local function on_chart_tag_removed_or_modified(event)
map_tags[new_tag.force.name .. new_tag.tag_number] = true map_tags[new_tag.force.name .. new_tag.tag_number] = true
end end
if Commands.player_has_permission(player, cmd_protected_tag) then if Commands.player_has_permission(player, cmd_protect_tag) then
-- Player is not in protected mode, but has access to the command -- Player is not in protected mode, but has access to the command
player.print({ "exp-commands_protected-tags.revert-has-access", cmd_protected_tag.name }, Commands.print_settings.error) player.print({ "exp-commands_tag-protection.revert-has-access", cmd_protect_tag.name }, Commands.print_settings.error)
else else
--- Player does not have access to protected mode --- Player does not have access to protected mode
player.print({ "exp-commands_protected-tags.revert-no-access" }, Commands.print_settings.error) player.print({ "exp-commands_tag-protection.revert-no-access" }, Commands.print_settings.error)
end end
end end

View File

@@ -52,7 +52,7 @@ local function next_color(color, step)
end end
--- Sends an rainbow message in the chat --- Sends an rainbow message in the chat
Commands.new("rainbow", { "exp-commands_rainbow" }) Commands.new("rainbow", { "exp-commands_rainbow.description" })
:argument("message", { "exp-commands_rainbow.arg-message" }, Commands.types.string) :argument("message", { "exp-commands_rainbow.arg-message" }, Commands.types.string)
:enable_auto_concatenation() :enable_auto_concatenation()
:register(function(player, message) :register(function(player, message)

View File

@@ -4,23 +4,23 @@ Adds a command to calculate the number of machines needed to fulfil a desired pr
local Commands = require("modules/exp_commands") local Commands = require("modules/exp_commands")
Commands.new("ratio", { "exp-command_ratio.description" }) Commands.new("ratio", { "exp-commands_ratio.description" })
:optional("items-per-second", { "exp-command_ratio.arg-items-per-second" }, Commands.types.number) :optional("items-per-second", { "exp-commands_ratio.arg-items-per-second" }, Commands.types.number)
:register(function(player, items_per_second) :register(function(player, items_per_second)
--- @cast items_per_second number? --- @cast items_per_second number?
local machine = player.selected local machine = player.selected
if not machine then if not machine then
return Commands.status.error{ "exp-command_ratio.not-selecting" } return Commands.status.error{ "exp-commands_ratio.not-selecting" }
end end
if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then
return Commands.status.error{ "exp-command_ratio.not-selecting" } return Commands.status.error{ "exp-commands_ratio.not-selecting" }
end end
local recipe = machine.get_recipe() local recipe = machine.get_recipe()
if not recipe then if not recipe then
return Commands.status.error{ "exp-command_ratio.not-selecting" } return Commands.status.error{ "exp-commands_ratio.not-selecting" }
end end
local products = recipe.products local products = recipe.products
@@ -34,7 +34,7 @@ Commands.new("ratio", { "exp-command_ratio.description" })
for _, ingredient in ipairs(ingredients) do for _, ingredient in ipairs(ingredients) do
Commands.print{ Commands.print{
ingredient.type == "item" and "exp-command_ratio.item-out" or "exp-command_ratio.fluid-out", ingredient.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out",
math.round(ingredient.amount * crafts_per_second, 3), math.round(ingredient.amount * crafts_per_second, 3),
ingredient.name ingredient.name
} }
@@ -42,13 +42,13 @@ Commands.new("ratio", { "exp-command_ratio.description" })
for i, product in ipairs(products) do for i, product in ipairs(products) do
Commands.print{ Commands.print{
product.type == "item" and "exp-command_ratio.item-out" or "exp-command_ratio.fluid-out", product.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out",
math.round(product.amount * crafts_per_second, 3), math.round(product.amount * crafts_per_second, 3),
product.name product.name
} }
end end
if amount_of_machines ~= 1 then if amount_of_machines ~= 1 then
Commands.print{ "exp-command_ratio.machine-count", amount_of_machines } Commands.print{ "exp-commands_ratio.machine-count", amount_of_machines }
end end
end) end)

View File

@@ -125,7 +125,7 @@ end
Commands.new("search", { "exp-commands_search.description-search" }) Commands.new("search", { "exp-commands_search.description-search" })
:argument("item", { "exp-commands_search.arg-item" }, parse_item) :argument("item", { "exp-commands_search.arg-item" }, parse_item)
:enable_auto_concatenation() :enable_auto_concatenation()
:add_aliases{ "s" } :add_aliases{ "si" } -- cant use /s
:register(function(player, item) :register(function(player, item)
--- @cast item LuaItemPrototype --- @cast item LuaItemPrototype
local results = search_players(game.players, item) local results = search_players(game.players, item)
@@ -172,7 +172,7 @@ end
Commands.new("search-recent", { "exp-commands_search.description-recent" }) Commands.new("search-recent", { "exp-commands_search.description-recent" })
:argument("item", { "exp-commands_search.arg-item" }, parse_item) :argument("item", { "exp-commands_search.arg-item" }, parse_item)
:enable_auto_concatenation() :enable_auto_concatenation()
:add_aliases{ "sr" } -- cant use /sc :add_aliases{ "sr" }
:register(function(player, item) :register(function(player, item)
--- @cast item LuaItemPrototype --- @cast item LuaItemPrototype
local results = search_players(game.players, item) local results = search_players(game.players, item)

View File

@@ -17,12 +17,12 @@ Commands.new("spectate", { "exp-commands_spectate.description-spectate" })
--- Enters follow mode for the caller, following the given player. --- Enters follow mode for the caller, following the given player.
Commands.new("follow", { "exp-commands_spectate.description-follow" }) Commands.new("follow", { "exp-commands_spectate.description-follow" })
:argument("player", { "exp-command_spectate.arg-player" }, Commands.types.player_online) :argument("player", { "exp-commands_spectate.arg-player" }, Commands.types.player_online)
:add_aliases{ "f" } :add_aliases{ "f" }
:register(function(player, other_player) :register(function(player, other_player)
--- @cast other_player LuaPlayer --- @cast other_player LuaPlayer
if player == other_player then if player == other_player then
return Commands.status.invalid_input{ "exp-command_spectate.follow-self" } return Commands.status.invalid_input{ "exp-commands_spectate.follow-self" }
else else
Spectate.start_follow(player, other_player) Spectate.start_follow(player, other_player)
end end

View File

@@ -71,7 +71,7 @@ Commands.new("clear-blueprints", { "exp-commands_surface.description-blueprints"
--- Clear all blueprints in a radius around you --- Clear all blueprints in a radius around you
Commands.new("clear-blueprints-radius", { "exp-commands_surface.description-radius" }) Commands.new("clear-blueprints-radius", { "exp-commands_surface.description-radius" })
:argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 1000)) :argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 100))
:register(function(player, radius) :register(function(player, radius)
--- @cast radius number --- @cast radius number
local player_name = format_player_name(player) local player_name = format_player_name(player)

View File

@@ -59,7 +59,7 @@ Commands.new("goto", { "exp-commands_teleport.description-goto" })
--- Teleport to spawn --- Teleport to spawn
Commands.new("spawn", { "exp-commands_teleport.description-spawn" }) Commands.new("spawn", { "exp-commands_teleport.description-spawn" })
:optional("player", { "exp-commands_teleport.arg-player-spawn" }, Commands.types.player_alive) :optional("player", { "exp-commands_teleport.arg-player-from" }, Commands.types.player_alive)
:defaults{ :defaults{
player = function(player) player = function(player)
if player.character and player.character.health > 0 then if player.character and player.character.health > 0 then

View File

@@ -4,9 +4,9 @@ local event_handler = require("event_handler")
local add = event_handler.add_lib local add = event_handler.add_lib
--- Command Extensions --- Command Extensions
require("modules.exp_scenario/commands/_authorities") require("modules/exp_scenario/commands/_authorities")
require("modules.exp_scenario/commands/_rcon") require("modules/exp_scenario/commands/_rcon")
require("modules.exp_scenario/commands/_types") require("modules/exp_scenario/commands/_types")
--- Commands with events --- Commands with events
add(require("modules/exp_scenario/commands/protected_entities")) add(require("modules/exp_scenario/commands/protected_entities"))
@@ -16,7 +16,7 @@ add(require("modules/exp_scenario/commands/research"))
--- Commands --- Commands
require("modules/exp_scenario/commands/admin_chat") require("modules/exp_scenario/commands/admin_chat")
require("modules/exp_scenario/commands/artillery") require("modules/exp_scenario/commands/artillery")
require("modules/exp_scenario/commands/bot_queues") require("modules/exp_scenario/commands/bot_queue")
require("modules/exp_scenario/commands/cheat") require("modules/exp_scenario/commands/cheat")
require("modules/exp_scenario/commands/clear_inventory") require("modules/exp_scenario/commands/clear_inventory")
require("modules/exp_scenario/commands/connect") require("modules/exp_scenario/commands/connect")

View File

@@ -17,7 +17,7 @@ enter=Entered artillery selection mode.
exit=Existed artillery selection mode. exit=Existed artillery selection mode.
[exp-commands_bot-queue] [exp-commands_bot-queue]
description-get=Get / Set the construction bot queue limits. description=Get / Set the construction bot queue limits.
arg-amount=Multiple of default value to set the queues to. arg-amount=Multiple of default value to set the queues to.
get=Bot queue is __1__ successful attempts and __2__ failed attempts. get=Bot queue is __1__ successful attempts and __2__ failed attempts.
set=__1__ set the bot queue to __2__ successful attempts and __3__ failed attempts. set=__1__ set the bot queue to __2__ successful attempts and __3__ failed attempts.
@@ -29,7 +29,7 @@ description-friendly-fire=Set friendly fire for your force, or another force.
description-research-all=Research all technology for your force, or another force. description-research-all=Research all technology for your force, or another force.
description-clear-pollution=Clear pollution from your current surface, or another surface. description-clear-pollution=Clear pollution from your current surface, or another surface.
description-pollution-enabled=Set polution enabled state for this game. description-pollution-enabled=Set polution enabled state for this game.
description=game-speed=Set or get the current game speed. description-game-speed=Set or get the current game speed.
arg-state=State to set, default is to toggle the current value. arg-state=State to set, default is to toggle the current value.
arg-player=Player to toggle cheat mode for. arg-player=Player to toggle cheat mode for.
arg-force-friendly-fire=Force to research all technology for. arg-force-friendly-fire=Force to research all technology for.
@@ -62,7 +62,7 @@ same-server=You are already connected to the server: __1__
offline=You cannot connect as the server is currently offline: __1__ offline=You cannot connect as the server is currently offline: __1__
none-matching=No servers were found with that name, if you used an address please append true to the end of your command. none-matching=No servers were found with that name, if you used an address please append true to the end of your command.
[expcom-debug] [exp-commands_debug]
description=Opens the debug gui. description=Opens the debug gui.
[exp-commands_enemy] [exp-commands_enemy]
@@ -115,7 +115,7 @@ description=Sends an action message in the chat.
arg-action=Action you want to perform. arg-action=Action you want to perform.
response=* __1__ __2__ * response=* __1__ __2__ *
[expcom-protection] [exp-commands_entity-protection]
description-entity=Toggles entity protection selection, hold shift to remove protection description-entity=Toggles entity protection selection, hold shift to remove protection
description-area=Toggles area protection selection, hold shift to remove protection description-area=Toggles area protection selection, hold shift to remove protection
enter-entity-selection=Entered entity selection, select entites to protect, hold shift to remove protection. enter-entity-selection=Entered entity selection, select entites to protect, hold shift to remove protection.
@@ -129,7 +129,7 @@ protected-area=This area is now protected.
unprotected-area=This area is now unprotected. unprotected-area=This area is now unprotected.
repeat-offence=__1__ has removed __2__ at [gps=__3__,__4__] repeat-offence=__1__ has removed __2__ at [gps=__3__,__4__]
[exp-commands_protected-tags] [exp-commands_tag-protection]
description=Toggles protected tag mode, edit and create protected map tags. description=Toggles protected tag mode, edit and create protected map tags.
exit=You have left protected tag mode, any new tags will not be protected. exit=You have left protected tag mode, any new tags will not be protected.
enter=You have entered protected tag mode, any new tags will be protected. enter=You have entered protected tag mode, any new tags will be protected.
@@ -183,14 +183,14 @@ removed-all=__1__ has has all of their reports removed by __2__.
removed=__1__ has a report removed by __2__. removed=__1__ has a report removed by __2__.
[exp-commands_research] [exp-commands_research]
description-ares=Sets research to be automatically queued. description=Sets research to be automatically queued.
arg-state=State to set, default is to toggle. arg-state=State to set, default is to toggle.
auto-research=__1__ set auto research to __2__ auto-research=__1__ set auto research to __2__
queue=[color=255, 255, 255] Research added to queue - [technology=__1__] - __2__[/color] queue=[color=255, 255, 255] Research added to queue - [technology=__1__] - __2__[/color]
[exp-commands_roles] [exp-commands_roles]
description-assign-role=Assigns a role to a player. description-assign=Assigns a role to a player.
description-unassign-role=Unassigns a role from a player. description-unassign=Unassigns a role from a player.
description-get=Get all roles that a player has, if no player provided it lists all roles. description-get=Get all roles that a player has, if no player provided it lists all roles.
arg-player-assign=Player to assign the role to. arg-player-assign=Player to assign the role to.
arg-player-unassign=Player to unassign the role from. arg-player-unassign=Player to unassign the role from.
@@ -207,6 +207,7 @@ description-online=Display online players sorted by the quantity of an item held
description-amount=Display players sorted by the quantity of an item held. description-amount=Display players sorted by the quantity of an item held.
description-recent=Display players who hold an item sorted by join time. description-recent=Display players who hold an item sorted by join time.
invalid-item=No item was found with internal name __1__; try using rich text selection. invalid-item=No item was found with internal name __1__; try using rich text selection.
arg-item=Item to search for.
no-results=No players have [item=__1__] no-results=No players have [item=__1__]
title=Players found with [item=__1__]: title=Players found with [item=__1__]:
result=\n__1__) __2__ has __3__ items. (__4__) result=\n__1__) __2__ has __3__ items. (__4__)
@@ -222,7 +223,7 @@ description-items=Clear all items on the ground.
description-blueprints=Clear all blueprints. description-blueprints=Clear all blueprints.
description-radius=Clear all blueprints in an radius around you. description-radius=Clear all blueprints in an radius around you.
arg-surface=Surface to clear on, default all. arg-surface=Surface to clear on, default all.
arg-radis=Radius to clear. arg-radius=Radius to clear.
items-surface=__1__ cleared all items on the ground of __2__. items-surface=__1__ cleared all items on the ground of __2__.
items-all=__1__ cleared all items on the ground for all surfaces. items-all=__1__ cleared all items on the ground for all surfaces.
blueprints-surface=__1__ cleared all blueprints on __2__. blueprints-surface=__1__ cleared all blueprints on __2__.
@@ -241,7 +242,7 @@ description-bring=Teleports a player to you.
description-goto=Teleports you to a player. description-goto=Teleports you to a player.
description-spawn=Teleport to spawn description-spawn=Teleport to spawn
arg-player-teleport=Player to teleport, if target is not given then you are teleported to this player. arg-player-teleport=Player to teleport, if target is not given then you are teleported to this player.
arg-player-from=Player to teleported. arg-player-from=Player to teleport.
arg-player-to=Player who is the target. arg-player-to=Player who is the target.
unavailable=They was a problem teleporting you, likely no position found, please try again later. unavailable=They was a problem teleporting you, likely no position found, please try again later.
same-player=Player can not be teleported to themselves. same-player=Player can not be teleported to themselves.
@@ -259,7 +260,7 @@ description-clear-script=Clears all script warnings from a player.
description-clear-last=Clears the last warning from a player. description-clear-last=Clears the last warning from a player.
arg-player-create=Player to give the warning to. arg-player-create=Player to give the warning to.
arg-player-get=Player to get the warning of, if not given all players are returned. arg-player-get=Player to get the warning of, if not given all players are returned.
arg-player=clear=Player to clear the warnings of. arg-player-clear=Player to clear the warnings of.
arg-reason=Reason the user is receiving a warning. arg-reason=Reason the user is receiving a warning.
create=__1__ received a warning from __2__ for __3__. create=__1__ received a warning from __2__ for __3__.
player-title=__1__ has __2__ warnings and __3__/__4__ script warnings. player-title=__1__ has __2__ warnings and __3__/__4__ script warnings.

View File

@@ -8,8 +8,18 @@ local _require = require
-- This replace function is used to avoid additional lines in stack traces during control stage -- This replace function is used to avoid additional lines in stack traces during control stage
local function replace() local function replace()
require = function(path) require = function(path)
--- @cast path string
if package.lifecycle == package.lifecycle_stage.runtime then if package.lifecycle == package.lifecycle_stage.runtime then
return loaded[path] or loaded[path:gsub(".", "/")] or error("Can only require files at runtime that have been required in the control stage.", 2) local replaced = path:gsub("%.", "/")
if not replaced:match("^__(.-)__") then
replaced = "__level__/" .. replaced
end
if not replaced:match(".lua$") then
replaced = replaced .. ".lua"
end
return loaded[path]
or loaded[replaced]
or error("Can only require files at runtime that have been required in the control stage.", 2)
else else
return _require(path) return _require(path)
end end

View File

@@ -2,6 +2,10 @@
Adds some commonly used functions used in many modules Adds some commonly used functions used in many modules
]] ]]
-- Make sure these are loaded first so locals below work
require("modules/exp_util/include/math")
require("modules/exp_util/include/table")
local type = type local type = type
local assert = assert local assert = assert
local getmetatable = getmetatable local getmetatable = getmetatable
@@ -158,7 +162,7 @@ end
function ExpUtil.get_function_name(func, raw) function ExpUtil.get_function_name(func, raw)
local debug_info = getinfo(func, "Sn") local debug_info = getinfo(func, "Sn")
local safe_source = debug_info.source:find("@__level__") local safe_source = debug_info.source:find("@__level__")
local file_name = safe_source == 1 and debug_info.short_src:sub(10, -5) or debug_info.source local file_name = safe_source == 1 and debug_info.source:sub(12, -5) or debug_info.source
local func_name = debug_info.name or debug_info.linedefined local func_name = debug_info.name or debug_info.linedefined
if raw then return file_name .. ":" .. func_name end if raw then return file_name .. ":" .. func_name end
return "<" .. file_name .. ":" .. func_name .. ">" return "<" .. file_name .. ":" .. func_name .. ">"
@@ -192,21 +196,25 @@ end
--- @return LocalisedString # The formatted version of the value --- @return LocalisedString # The formatted version of the value
--- @return boolean # True if value is a locale string, nil otherwise --- @return boolean # True if value is a locale string, nil otherwise
function ExpUtil.safe_value(value) function ExpUtil.safe_value(value)
if type(value) == "table" then local _type = type(value)
if _type == "table" then
local v1 = value[1] local v1 = value[1]
local str = tostring(value) local str = tostring(value)
if type(v1) == "string" and not v1:find("%s") if type(v1) == "string" and not v1:find("%s")
and (v1 == "" or v1 == "?" or v1:find(".+[.].+")) then and (v1 == "" or v1 == "?" or v1:find(".+[.].+"))
and #value <= 20 then
return value, true -- locale string return value, true -- locale string
elseif str ~= "table" then elseif str ~= "table" then
return str, false -- has __tostring metamethod return str, false -- has __tostring metamethod
else -- plain table else -- plain table
return value, false return value, false
end end
elseif type(value) == "function" then -- function elseif _type == "function" then -- function
return "<function:" .. ExpUtil.get_function_name(value, true) .. ">", false return "<function:" .. ExpUtil.get_function_name(value, true) .. ">", false
else -- not: table or function elseif _type == "thread" or _type == "userdata" then -- unsafe value
return tostring(value), false return tostring(value), false
else -- already safe value
return value, false
end end
end end

View File

@@ -45,7 +45,7 @@ local my_metatable = Storage.register_metatable("MyMetaTable", {
]] ]]
local ExpUtil = require("modules/exp_util/common") local ExpUtil = require("modules/exp_util")
--- @class ExpUtil_Storage --- @class ExpUtil_Storage
local Storage = { local Storage = {