From 292c1a1b68d9de78e5543d1e2358330ceb3766ec Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sat, 28 Sep 2024 01:56:54 +0100 Subject: [PATCH] Update all code styles --- .luarc.json | 5 + exp_commands/module/commands/data_types.lua | 26 +- exp_commands/module/commands/help.lua | 71 +- exp_commands/module/commands/ipc.lua | 26 +- .../commands/permission_authorities.lua | 42 +- exp_commands/module/commands/rcon.lua | 53 +- exp_commands/module/commands/sudo.lua | 26 +- exp_commands/module/module_exports.lua | 169 +-- exp_groups/module/control.lua | 206 +-- exp_groups/module/module_exports.lua | 320 ++--- exp_legacy/module/config/_file_loader.lua | 184 +-- exp_legacy/module/config/advanced_start.lua | 64 +- exp_legacy/module/config/afk_kick.lua | 12 +- exp_legacy/module/config/bonus.lua | 64 +- exp_legacy/module/config/chat_reply.lua | 170 +-- exp_legacy/module/config/compilatron.lua | 36 +- exp_legacy/module/config/death_logger.lua | 20 +- exp_legacy/module/config/deconlog.lua | 12 +- exp_legacy/module/config/discord_alerts.lua | 42 +- .../config/expcore/command_auth_admin.lua | 4 +- .../config/expcore/command_auth_roles.lua | 4 +- .../config/expcore/command_color_parse.lua | 6 +- .../config/expcore/command_general_parse.lua | 64 +- .../config/expcore/command_role_parse.lua | 27 +- .../expcore/command_runtime_disable.lua | 4 +- .../config/expcore/permission_groups.lua | 180 +-- exp_legacy/module/config/expcore/roles.lua | 646 +++++----- exp_legacy/module/config/graftorio.lua | 10 +- exp_legacy/module/config/gui/autofill.lua | 191 +-- .../module/config/gui/player_list_actions.lua | 202 +-- exp_legacy/module/config/gui/rockets.lua | 40 +- exp_legacy/module/config/gui/science.lua | 16 +- exp_legacy/module/config/gui/tasks.lua | 12 +- exp_legacy/module/config/gui/warps.lua | 54 +- exp_legacy/module/config/inventory_clear.lua | 4 +- exp_legacy/module/config/join_messages.lua | 10 +- exp_legacy/module/config/lawnmower.lua | 2 +- exp_legacy/module/config/logging.lua | 43 +- exp_legacy/module/config/miner.lua | 2 +- exp_legacy/module/config/module.lua | 156 +-- exp_legacy/module/config/nukeprotect.lua | 64 +- .../module/config/personal_logistic.lua | 1125 +++++++++-------- .../module/config/pollution_grading.lua | 6 +- exp_legacy/module/config/popup_messages.lua | 12 +- .../module/config/preset_player_colours.lua | 56 +- .../module/config/preset_player_quickbar.lua | 2 +- exp_legacy/module/config/protection.lua | 14 +- exp_legacy/module/config/repair.lua | 20 +- exp_legacy/module/config/research.lua | 114 +- exp_legacy/module/config/scorched_earth.lua | 184 +-- exp_legacy/module/config/spawn_area.lua | 358 +++--- .../module/config/station_auto_name.lua | 4 +- exp_legacy/module/config/statistics.lua | 30 +- exp_legacy/module/config/vlayer.lua | 114 +- exp_legacy/module/config/warnings.lua | 26 +- exp_legacy/module/control.lua | 28 +- exp_legacy/module/expcore/commands.lua | 157 +-- exp_legacy/module/expcore/common.lua | 376 +++--- exp_legacy/module/expcore/datastore.lua | 108 +- exp_legacy/module/expcore/external.lua | 45 +- exp_legacy/module/expcore/gui/_require.lua | 15 +- .../module/expcore/gui/core_defines.lua | 94 +- exp_legacy/module/expcore/gui/defines.lua | 321 ++--- .../module/expcore/gui/helper_functions.lua | 2 +- exp_legacy/module/expcore/gui/left_flow.lua | 25 +- exp_legacy/module/expcore/gui/prototype.lua | 47 +- exp_legacy/module/expcore/gui/top_flow.lua | 72 +- .../module/expcore/permission_groups.lua | 43 +- exp_legacy/module/expcore/player_data.lua | 79 +- exp_legacy/module/expcore/roles.lua | 169 +-- .../module/modules/addons/advanced-start.lua | 22 +- exp_legacy/module/modules/addons/afk-kick.lua | 16 +- .../module/modules/addons/chat-popups.lua | 7 +- .../module/modules/addons/chat-reply.lua | 22 +- .../module/modules/addons/compilatron.lua | 46 +- .../module/modules/addons/damage-popups.lua | 17 +- .../module/modules/addons/death-logger.lua | 34 +- exp_legacy/module/modules/addons/deconlog.lua | 156 +-- .../module/modules/addons/discord-alerts.lua | 212 ++-- exp_legacy/module/modules/addons/fagc.lua | 10 +- exp_legacy/module/modules/addons/inserter.lua | 22 +- .../module/modules/addons/lawnmower.lua | 64 +- exp_legacy/module/modules/addons/logging.lua | 33 +- exp_legacy/module/modules/addons/miner.lua | 45 +- .../module/modules/addons/nukeprotect.lua | 62 +- .../modules/addons/pollution-grading.lua | 6 +- .../module/modules/addons/protection-jail.lua | 12 +- .../module/modules/addons/report-jail.lua | 8 +- .../module/modules/addons/scorched-earth.lua | 32 +- .../module/modules/addons/spawn-area.lua | 68 +- .../modules/addons/station-auto-name.lua | 71 +- .../module/modules/addons/tree-decon.lua | 59 +- .../module/modules/commands/admin-chat.lua | 27 +- .../module/modules/commands/admin-markers.lua | 50 +- .../module/modules/commands/artillery.lua | 40 +- .../module/modules/commands/bot-queue.lua | 32 +- .../module/modules/commands/cheat-mode.lua | 64 +- .../modules/commands/clear-inventory.lua | 22 +- .../module/modules/commands/connect.lua | 92 +- exp_legacy/module/modules/commands/debug.lua | 8 +- exp_legacy/module/modules/commands/enemy.lua | 38 +- exp_legacy/module/modules/commands/find.lua | 16 +- .../module/modules/commands/friendly-fire.lua | 20 +- exp_legacy/module/modules/commands/help.lua | 129 +- exp_legacy/module/modules/commands/home.lua | 90 +- .../module/modules/commands/interface.lua | 98 +- exp_legacy/module/modules/commands/jail.lua | 58 +- exp_legacy/module/modules/commands/kill.lua | 44 +- .../module/modules/commands/last-location.lua | 14 +- exp_legacy/module/modules/commands/me.lua | 14 +- .../module/modules/commands/pollution.lua | 46 +- .../module/modules/commands/protection.lua | 83 +- .../module/modules/commands/rainbow.lua | 52 +- exp_legacy/module/modules/commands/ratio.lua | 131 +- exp_legacy/module/modules/commands/repair.lua | 64 +- .../module/modules/commands/reports.lua | 127 +- .../module/modules/commands/research.lua | 28 +- exp_legacy/module/modules/commands/roles.lua | 104 +- exp_legacy/module/modules/commands/search.lua | 97 +- exp_legacy/module/modules/commands/spawn.lua | 51 +- .../module/modules/commands/spectate.lua | 37 +- exp_legacy/module/modules/commands/speed.lua | 16 +- .../modules/commands/surface-clearing.lua | 40 +- .../module/modules/commands/teleport.lua | 86 +- exp_legacy/module/modules/commands/train.lua | 22 +- exp_legacy/module/modules/commands/vlayer.lua | 14 +- .../module/modules/commands/warnings.lua | 100 +- .../module/modules/commands/waterfill.lua | 46 +- exp_legacy/module/modules/control/jail.lua | 28 +- .../module/modules/control/production.lua | 106 +- .../module/modules/control/protection.lua | 13 +- exp_legacy/module/modules/control/reports.lua | 13 +- exp_legacy/module/modules/control/rockets.lua | 38 +- .../module/modules/control/selection.lua | 18 +- .../module/modules/control/spectate.lua | 65 +- exp_legacy/module/modules/control/tasks.lua | 12 +- exp_legacy/module/modules/control/vlayer.lua | 120 +- .../module/modules/control/warnings.lua | 55 +- exp_legacy/module/modules/control/warps.lua | 54 +- exp_legacy/module/modules/data/alt-view.lua | 8 +- exp_legacy/module/modules/data/bonus.lua | 34 +- exp_legacy/module/modules/data/greetings.lua | 36 +- exp_legacy/module/modules/data/language.lua | 8 +- .../module/modules/data/personal-logistic.lua | 63 +- .../module/modules/data/player-colours.lua | 27 +- exp_legacy/module/modules/data/quickbar.lua | 53 +- exp_legacy/module/modules/data/statistics.lua | 79 +- exp_legacy/module/modules/data/tag.lua | 76 +- .../module/modules/factorio-control.lua | 80 +- .../module/modules/graftorio/forcestats.lua | 306 ++--- .../module/modules/graftorio/general.lua | 70 +- .../module/modules/graftorio/require.lua | 34 +- .../module/modules/graftorio/statics.lua | 47 +- exp_legacy/module/modules/gui/autofill.lua | 464 ++++--- exp_legacy/module/modules/gui/bonus.lua | 397 +++--- .../module/modules/gui/debug/_g_view.lua | 16 +- .../module/modules/gui/debug/event_view.lua | 40 +- .../gui/debug/expcore_datastore_view.lua | 30 +- .../modules/gui/debug/expcore_gui_view.lua | 24 +- .../module/modules/gui/debug/global_view.lua | 26 +- .../module/modules/gui/debug/main_view.lua | 14 +- exp_legacy/module/modules/gui/debug/model.lua | 65 +- .../module/modules/gui/debug/package_view.lua | 35 +- .../modules/gui/debug/redmew_global_view.lua | 24 +- exp_legacy/module/modules/gui/landfill.lua | 109 +- exp_legacy/module/modules/gui/module.lua | 194 ++- exp_legacy/module/modules/gui/player-list.lua | 327 +++-- exp_legacy/module/modules/gui/playerdata.lua | 210 +-- exp_legacy/module/modules/gui/production.lua | 189 ++- exp_legacy/module/modules/gui/readme.lua | 686 +++++----- exp_legacy/module/modules/gui/research.lua | 425 +++---- exp_legacy/module/modules/gui/rocket-info.lua | 865 ++++++------- .../module/modules/gui/science-info.lua | 306 +++-- exp_legacy/module/modules/gui/server-ups.lua | 50 +- .../module/modules/gui/surveillance.lua | 244 ++-- exp_legacy/module/modules/gui/task-list.lua | 630 ++++----- exp_legacy/module/modules/gui/toolbar.lua | 346 ++--- exp_legacy/module/modules/gui/vlayer.lua | 552 ++++---- exp_legacy/module/modules/gui/warp-list.lua | 799 ++++++------ exp_legacy/module/overrides/table.lua | 54 +- exp_legacy/module/overrides/version.lua | 8 +- exp_legacy/module/utils/event.lua | 11 +- exp_legacy/module/utils/game.lua | 7 +- exp_legacy/module/utils/gui.lua | 20 +- exp_util/module/async.lua | 152 +-- exp_util/module/common.lua | 185 +-- exp_util/module/floating_text.lua | 36 +- exp_util/module/include/color.lua | 288 ++--- exp_util/module/include/inspect.lua | 195 +-- exp_util/module/include/math.lua | 2 +- exp_util/module/include/package.lua | 10 +- exp_util/module/include/require.lua | 18 +- exp_util/module/include/table.lua | 53 +- exp_util/module/storage.lua | 12 +- 194 files changed, 9817 insertions(+), 9703 deletions(-) diff --git a/.luarc.json b/.luarc.json index 3fd4d7ec..bce928b0 100644 --- a/.luarc.json +++ b/.luarc.json @@ -36,6 +36,11 @@ "param": "_?_?(\\w+)", "$1": "snake_case" }], + "module_local_name_style": [{ + "type" : "pattern", + "param": "_?_?(\\w+)", + "$1": "snake_case" + }, "pascal_case"], "function_param_name_style": [{ "type" : "pattern", "param": "_?_?(\\w+)", diff --git a/exp_commands/module/commands/data_types.lua b/exp_commands/module/commands/data_types.lua index 6158cef5..5e29fc68 100644 --- a/exp_commands/module/commands/data_types.lua +++ b/exp_commands/module/commands/data_types.lua @@ -45,7 +45,7 @@ end) add("string-options", function(input, _, options) local option = ExpUtil.auto_complete(options, input) if option == nil then - return invalid{"exp-commands-parse.string-options", table.concat(options, ", ")} + return invalid{ "exp-commands-parse.string-options", table.concat(options, ", ") } else return valid(option) end @@ -55,7 +55,7 @@ end) add("string-key", function(input, _, map) local option = ExpUtil.auto_complete(map, input, true) if option == nil then - return invalid{"exp-commands-parse.string-options", table.concat(table.get_keys(map), ", ")} + return invalid{ "exp-commands-parse.string-options", table.concat(table.get_keys(map), ", ") } else return valid(option) end @@ -64,7 +64,7 @@ end) --- A string with a maximum length, takes one argument which is the maximum length of a string add("string-max-length", function(input, _, maximum) if input:len() > maximum then - return invalid{"exp-commands-parse.string-max-length", maximum} + return invalid{ "exp-commands-parse.string-max-length", maximum } else return valid(input) end @@ -74,7 +74,7 @@ end) add("number", function(input) local number = tonumber(input) if number == nil then - return invalid{"exp-commands-parse.number"} + return invalid{ "exp-commands-parse.number" } else return valid(number) end @@ -84,7 +84,7 @@ end) add("integer", function(input) local number = tonumber(input) if number == nil then - return invalid{"exp-commands-parse.number"} + return invalid{ "exp-commands-parse.number" } else return valid(math.floor(number)) end @@ -96,7 +96,7 @@ add("number-range", function(input, _, minimum, maximum) if not success then return status, number elseif number < minimum or number > maximum then - return invalid{"exp-commands-parse.number-range", minimum, maximum} + return invalid{ "exp-commands-parse.number-range", minimum, maximum } else return valid(number) end @@ -108,7 +108,7 @@ add("integer-range", function(input, _, minimum, maximum) if not success then return status, number elseif number < minimum or number > maximum then - return invalid{"exp-commands-parse.number-range", minimum, maximum} + return invalid{ "exp-commands-parse.number-range", minimum, maximum } else return valid(number) end @@ -118,7 +118,7 @@ end) add("player", function(input) local player = game.get_player(input) if player == nil then - return invalid{"exp-commands-parse.player", input} + return invalid{ "exp-commands-parse.player", input } else return valid(player) end @@ -130,7 +130,7 @@ add("player-online", function(input) if not success then return status, player elseif player.connected == false then - return invalid{"exp-commands-parse.player-online"} + return invalid{ "exp-commands-parse.player-online" } else return valid(player) end @@ -142,7 +142,7 @@ add("player-alive", function(input) if not success then return status, player elseif player.character == nil or player.character.health <= 0 then - return invalid{"exp-commands-parse.player-alive"} + return invalid{ "exp-commands-parse.player-alive" } else return valid(player) end @@ -152,7 +152,7 @@ end) add("force", function(input) local force = game.forces[input] if force == nil then - return invalid{"exp-commands-parse.force"} + return invalid{ "exp-commands-parse.force" } else return valid(force) end @@ -162,7 +162,7 @@ end) add("surface", function(input) local surface = game.surfaces[input] if surface == nil then - return invalid{"exp-commands-parse.surface"} + return invalid{ "exp-commands-parse.surface" } else return valid(surface) end @@ -172,7 +172,7 @@ end) add("color", function(input) local color = ExpUtil.auto_complete(Commands.color, input, true) if color == nil then - return invalid{"exp-commands-parse.color"} + return invalid{ "exp-commands-parse.color" } else return valid(color) end diff --git a/exp_commands/module/commands/help.lua b/exp_commands/module/commands/help.lua index 6573bfd0..c2e55a42 100644 --- a/exp_commands/module/commands/help.lua +++ b/exp_commands/module/commands/help.lua @@ -34,7 +34,7 @@ local function format_as_pages(commands, page_size) page_length = 1 end - local aliases = #command.aliases > 0 and {"exp-commands-help.aliases", table.concat(command.aliases, ", ")} or "" + local aliases = #command.aliases > 0 and { "exp-commands-help.aliases", table.concat(command.aliases, ", ") } or "" pages[current_page][page_length] = { "exp-commands-help.format", command.name, command.description, command.help, aliases } end @@ -42,40 +42,41 @@ local function format_as_pages(commands, page_size) end Commands.new("commands", "List and search all commands for a keyword") -:add_aliases{ "chelp", "helpp" } -:argument("keyword", "string") -:optional("page", "integer") -:defaults{ page = 1 } -:register(function(player, keyword, page) - keyword = keyword:lower() - local pages, found - local cache = search_cache[player.index] - if cache and cache.keyword == keyword then - -- Cached value found, no search is needed - pages = cache.pages - found = cache.found - else - -- No cached value, so a search needs to be done - local commands = Commands.search_for_player(keyword, player) - pages, found = format_as_pages(commands, PAGE_SIZE) - search_cache[player.index] = { keyword = keyword, pages = pages, found = found } - end + :add_aliases{ "chelp", "helpp" } + :argument("keyword", "string") + :optional("page", "integer") + :defaults{ page = 1 } + :register(function(player, keyword, page) + keyword = keyword:lower() + local pages, found + local cache = search_cache[player.index] + if cache and cache.keyword == keyword then + -- Cached value found, no search is needed + pages = cache.pages + found = cache.found + else + -- No cached value, so a search needs to be done + local commands = Commands.search_for_player(keyword, player) + pages, found = format_as_pages(commands, PAGE_SIZE) + search_cache[player.index] = { keyword = keyword, pages = pages, found = found } + end - -- Error if no pages found - if found == 0 then - return Commands.status.success{ "exp-commands-help.no-results" } - end + -- Error if no pages found + if found == 0 then + return Commands.status.success{ "exp-commands-help.no-results" } + end - local page_data = pages[page] - if page_data == nil then - -- Page number was out of range for this search - return Commands.status.invalid_input{"exp-commands-help.out-of-range", page, #pages } - end + local page_data = pages[page] + if page_data == nil then + -- Page number was out of range for this search + return Commands.status.invalid_input{ "exp-commands-help.out-of-range", page, #pages } + end - -- Print selected page to the player - Commands.print{ "exp-commands-help.header", keyword == '' and '' or keyword } - for _, command in pairs(page_data) do - Commands.print(command) - end - return Commands.status.success{ "exp-commands-help.footer", found, page, #pages } -end) + -- Print selected page to the player + Commands.print{ "exp-commands-help.header", keyword == "" and "" or keyword } + for _, command in pairs(page_data) do + Commands.print(command) + end + + return Commands.status.success{ "exp-commands-help.footer", found, page, #pages } + end) diff --git a/exp_commands/module/commands/ipc.lua b/exp_commands/module/commands/ipc.lua index 7a8ef0df..bdcaefb3 100644 --- a/exp_commands/module/commands/ipc.lua +++ b/exp_commands/module/commands/ipc.lua @@ -10,16 +10,16 @@ local Commands = require("modules/exp_commands") local Clustorio = require("modules/clusterio/api") Commands.new("_ipc", "Send an IPC message on the selected channel") -:add_flags{ "system_only" } -:enable_auto_concatenation() -:argument("channel", "string") -:argument("message", "string") -:register(function(_, channel, message) - local tbl = game.json_to_table(message) - if tbl == nil then - return Commands.status.invalid_input("Invalid json string") - else - Clustorio.send_json(channel, tbl) - return Commands.status.success() - end -end) + :add_flags{ "system_only" } + :enable_auto_concatenation() + :argument("channel", "string") + :argument("message", "string") + :register(function(_, channel, message) + local tbl = game.json_to_table(message) + if tbl == nil then + return Commands.status.invalid_input("Invalid json string") + else + Clustorio.send_json(channel, tbl) + return Commands.status.success() + end + end) diff --git a/exp_commands/module/commands/permission_authorities.lua b/exp_commands/module/commands/permission_authorities.lua index 5dc5d90f..55088d6e 100644 --- a/exp_commands/module/commands/permission_authorities.lua +++ b/exp_commands/module/commands/permission_authorities.lua @@ -60,32 +60,32 @@ end --- If a command has the flag "admin_only" then only admins can use the command# permission_authorities.admin_only = -add(function(player, command) - if command.flags.admin_only and not player.admin then - return deny{"exp-commands-permissions.admin-only"} - else - return allow() - end -end) + add(function(player, command) + if command.flags.admin_only and not player.admin then + return deny{ "exp-commands-permissions.admin-only" } + else + return allow() + end + end) --- If a command has the flag "system_only" then only rcon connections can use the command permission_authorities.system_only = -add(function(player, command) - if command.flags.system_only and not system_players[player.name] then - return deny{"exp-commands-permissions.system-only"} - else - return allow() - end -end) + add(function(player, command) + if command.flags.system_only and not system_players[player.name] then + return deny{ "exp-commands-permissions.system-only" } + else + return allow() + end + end) --- If Commands.disable was called then no one can use the command permission_authorities.disabled = -add(function(_, command) - if disabled_commands[command.name] then - return deny{"exp-commands-permissions.disabled"} - else - return allow() - end -end) + add(function(_, command) + if disabled_commands[command.name] then + return deny{ "exp-commands-permissions.disabled" } + else + return allow() + end + end) return permission_authorities diff --git a/exp_commands/module/commands/rcon.lua b/exp_commands/module/commands/rcon.lua index d7273f75..cea218b3 100644 --- a/exp_commands/module/commands/rcon.lua +++ b/exp_commands/module/commands/rcon.lua @@ -31,10 +31,15 @@ rcon_statics.ipc = Clustorio.send_json --- Some common callback values which are useful when a player uses the command function rcon_callbacks.player(player) return player end + function rcon_callbacks.surface(player) return player and player.surface end + function rcon_callbacks.force(player) return player and player.force end + function rcon_callbacks.position(player) return player and player.position end + function rcon_callbacks.entity(player) return player and player.selected end + function rcon_callbacks.tile(player) return player and player.surface.get_tile(player.position) end --- The rcon env is saved between command runs to prevent desyncs @@ -55,28 +60,28 @@ function Commands.add_rcon_callback(name, callback) end Commands.new("_rcon", "Execute arbitrary code within a custom environment") -:add_flags{ "system_only" } -:enable_auto_concatenation() -:argument("invocation", "string") -:register(function(player, invocation_string) - -- Construct the environment the command will run within - local env = setmetatable({}, { __index = rcon_env, __newindex = rcon_env }) - for name, callback in pairs(rcon_callbacks) do - local _, rtn = pcall(callback, player.index > 0 and player or nil) - rawset(env, name, rtn) - end - - -- Compile and run the invocation string - local invocation, compile_error = load(invocation_string, "rcon-invocation", "t", env) - if compile_error then - return Commands.status.invalid_input(compile_error) - else - local success, rtn = xpcall(invocation, debug.traceback) - if success == false then - local err = rtn:gsub('%.%.%..-/temp/currently%-playing/', '') - return Commands.status.error(err) - else - return Commands.status.success(rtn) + :add_flags{ "system_only" } + :enable_auto_concatenation() + :argument("invocation", "string") + :register(function(player, invocation_string) + -- Construct the environment the command will run within + local env = setmetatable({}, { __index = rcon_env, __newindex = rcon_env }) + for name, callback in pairs(rcon_callbacks) do + local _, rtn = pcall(callback, player.index > 0 and player or nil) + rawset(env, name, rtn) end - end -end) + + -- Compile and run the invocation string + local invocation, compile_error = load(invocation_string, "rcon-invocation", "t", env) + if compile_error then + return Commands.status.invalid_input(compile_error) + else + local success, rtn = xpcall(invocation, debug.traceback) + if success == false then + local err = rtn:gsub("%.%.%..-/temp/currently%-playing/", "") + return Commands.status.error(err) + else + return Commands.status.success(rtn) + end + end + end) diff --git a/exp_commands/module/commands/sudo.lua b/exp_commands/module/commands/sudo.lua index 51d7afea..917e7f6a 100644 --- a/exp_commands/module/commands/sudo.lua +++ b/exp_commands/module/commands/sudo.lua @@ -10,16 +10,16 @@ System command to execute a command as another player using their permissions (e local Commands = require("modules/exp_commands") Commands.new("_sudo", "Run a command as another player") -:add_flags{ "system_only" } -:enable_auto_concatenation() -:argument("player", "player") -:argument("command", "string-key", Commands.registered_commands) -:argument("arguments", "string") -:register(function(_, player, command, parameter) - return Commands._event_handler{ - name = command.name, - tick = game.tick, - player_index = player.index, - parameter = parameter - } -end) + :add_flags{ "system_only" } + :enable_auto_concatenation() + :argument("player", "player") + :argument("command", "string-key", Commands.registered_commands) + :argument("arguments", "string") + :register(function(_, player, command, parameter) + return Commands._event_handler{ + name = command.name, + tick = game.tick, + player_index = player.index, + parameter = parameter, + } + end) diff --git a/exp_commands/module/module_exports.lua b/exp_commands/module/module_exports.lua index de5fb6f9..90c13fb6 100644 --- a/exp_commands/module/module_exports.lua +++ b/exp_commands/module/module_exports.lua @@ -70,34 +70,34 @@ local Commands = { Commands._metatable = { __index = Commands._prototype, - __class = "ExpCommand" + __class = "ExpCommand", } Commands.player_server = setmetatable({ - index = 0, - color = Color.white, - chat_color = Color.white, - name = "", - tag = "", - connected = true, - admin = true, - afk_time = 0, - online_time = 0, - last_online = 0, - spectator = true, - show_on_map = false, - valid = true, - object_name = "LuaPlayer" + index = 0, + color = Color.white, + chat_color = Color.white, + name = "", + tag = "", + connected = true, + admin = true, + afk_time = 0, + online_time = 0, + last_online = 0, + spectator = true, + show_on_map = false, + valid = true, + object_name = "LuaPlayer", }, { - __index = function(_, key) - if key == "__self" or type(key) == "number" then return nil end - Commands.error("Command does not support rcon usage, requires reading player." .. key) - error("Command does not support rcon usage, requires reading player." .. key) - end, - __newindex = function(_, key) - Commands.error("Command does not support rcon usage, requires reading player." .. key) - error("Command does not support rcon usage, requires setting player." .. key) - end + __index = function(_, key) + if key == "__self" or type(key) == "number" then return nil end + Commands.error("Command does not support rcon usage, requires reading player." .. key) + error("Command does not support rcon usage, requires reading player." .. key) + end, + __newindex = function(_, key) + Commands.error("Command does not support rcon usage, requires reading player." .. key) + error("Command does not support rcon usage, requires setting player." .. key) + end, }) --- Status Returns. @@ -107,34 +107,34 @@ Commands.player_server = setmetatable({ --- Used to signal success from a command, data type parser, or permission authority -- @tparam[opt] LocaleString|string msg An optional message to be included when a command completes (only has an effect in command callbacks) function Commands.status.success(msg) - return Commands.status.success, msg or {'exp-commands.success'} + return Commands.status.success, msg or { "exp-commands.success" } end --- Used to signal an error has occurred in a command, data type parser, or permission authority -- For data type parsers and permission authority, an error return will prevent the command from being executed -- @tparam[opt] LocaleString|string msg An optional error message to be included in the output, a generic message is used if not provided function Commands.status.error(msg) - return Commands.status.error, {'exp-commands.error', msg or {'exp-commands.error-default'}} + return Commands.status.error, { "exp-commands.error", msg or { "exp-commands.error-default" } } end --- Used to signal the player is unauthorised to use a command, primarily used by permission authorities but can be used in a command callback -- For permission authorities, an error return will prevent the command from being executed -- @tparam[opt] LocaleString|string msg An optional error message to be included in the output, a generic message is used if not provided function Commands.status.unauthorised(msg) - return Commands.status.unauthorised, msg or {'exp-commands.unauthorized', msg or {'exp-commands.unauthorized-default'}} + return Commands.status.unauthorised, msg or { "exp-commands.unauthorized", msg or { "exp-commands.unauthorized-default" } } end --- Used to signal the player provided invalid input to an command, primarily used by data type parsers but can be used in a command callback -- For data type parsers, an error return will prevent the command from being executed -- @tparam[opt] LocaleString|string msg An optional error message to be included in the output, a generic message is used if not provided function Commands.status.invalid_input(msg) - return Commands.status.invalid_input, msg or {'exp-commands.invalid-input'} + return Commands.status.invalid_input, msg or { "exp-commands.invalid-input" } end --- Used to signal an internal error has occurred, this is reserved for internal use -- @tparam LocaleString|string msg A message detailing the error which has occurred, will be logged and outputted function Commands.status.internal_error(msg) - return Commands.status.internal_error, {'exp-commands.internal-error', msg} + return Commands.status.internal_error, { "exp-commands.internal-error", msg } end local valid_command_status = {} -- Hashmap lookup for testing if a status is valid @@ -207,7 +207,7 @@ end -- @treturn string The data type passed as the first argument function Commands.add_data_type(data_type, parser) if Commands.data_types[data_type] then - error("Data type \""..tostring(data_type).."\" already has a parser registered", 2) + error("Data type \"" .. tostring(data_type) .. "\" already has a parser registered", 2) end Commands.data_types[data_type] = parser return data_type @@ -231,12 +231,12 @@ function Commands.parse_data_type(data_type, input, ...) if type(data_type) == "function" then parser = data_type elseif parser == nil then - return false, Commands.status.internal_error, {"exp-commands.internal-error" , "Data type \""..tostring(data_type).."\" does not have a registered parser"} + return false, Commands.status.internal_error, { "exp-commands.internal-error", "Data type \"" .. tostring(data_type) .. "\" does not have a registered parser" } end local status, parsed = parser(input, ...) if status == nil then - return Commands.status.internal_error, {"exp-commands.internal-error" , "Parser for data type \""..tostring(data_type).."\" returned a nil value"} + return Commands.status.internal_error, { "exp-commands.internal-error", "Parser for data type \"" .. tostring(data_type) .. "\" returned a nil value" } elseif valid_command_status[status] then if status ~= Commands.status.success then return false, status, parsed -- error_type, error_msg @@ -279,7 +279,7 @@ local function search_commands(keyword, custom_commands) -- Search all custom commands for name, command in pairs(custom_commands) do - local search = string.format('%s %s %s', name, command.help, table.concat(command.aliases, ' ')) + local search = string.format("%s %s %s", name, command.help, table.concat(command.aliases, " ")) if search:lower():match(keyword) then rtn[name] = command end @@ -287,13 +287,13 @@ local function search_commands(keyword, custom_commands) -- Search all game commands for name, description in pairs(commands.game_commands) do - local search = string.format('%s %s', name, description) + local search = string.format("%s %s", name, description) if search:lower():match(keyword) then rtn[name] = { name = name, help = description, description = "", - aliases = {} + aliases = {}, } end end @@ -322,8 +322,8 @@ end -- @tparam Color color The color that the message should be -- @treturn string The string which can be printed to game chat function Commands.set_chat_message_color(message, color) - local color_tag = math.round(color.r, 3)..', '..math.round(color.g, 3)..', '..math.round(color.b, 3) - return string.format('[color=%s]%s[/color]', color_tag, message) + local color_tag = math.round(color.r, 3) .. ", " .. math.round(color.g, 3) .. ", " .. math.round(color.b, 3) + return string.format("[color=%s]%s[/color]", color_tag, message) end --- Set the color of a locale message using rich text chat @@ -331,8 +331,8 @@ end -- @tparam Color color The color that the message should be -- @treturn LocaleString The locale string which can be printed to game chat function Commands.set_locale_chat_message_color(message, color) - local color_tag = math.round(color.r, 3)..', '..math.round(color.g, 3)..', '..math.round(color.b, 3) - return {'color-tag', color_tag, message} + local color_tag = math.round(color.r, 3) .. ", " .. math.round(color.g, 3) .. ", " .. math.round(color.b, 3) + return { "color-tag", color_tag, message } end --- Get a string representing the name of the given player in their chat colour @@ -341,8 +341,8 @@ end function Commands.format_player_name(player) local player_name = player and player.name or "" local player_color = player and player.chat_color or Color.white - local color_tag = math.round(player_color.r, 3)..', '..math.round(player_color.g, 3)..', '..math.round(player_color.b, 3) - return string.format('[color=%s]%s[/color]', color_tag, player_name) + local color_tag = math.round(player_color.r, 3) .. ", " .. math.round(player_color.g, 3) .. ", " .. math.round(player_color.b, 3) + return string.format("[color=%s]%s[/color]", color_tag, player_name) end --- Get a locale string representing the name of the given player in their chat colour @@ -351,8 +351,8 @@ end function Commands.format_locale_player_name(player) local player_name = player and player.name or "" local player_color = player and player.chat_color or Color.white - local color_tag = math.round(player_color.r, 3)..', '..math.round(player_color.g, 3)..', '..math.round(player_color.b, 3) - return {'color-tag', color_tag, player_name} + local color_tag = math.round(player_color.r, 3) .. ", " .. math.round(player_color.g, 3) .. ", " .. math.round(player_color.b, 3) + return { "color-tag", color_tag, player_name } end --- Print a message to the user of a command, accepts any value and will print in a readable and safe format @@ -366,14 +366,14 @@ function Commands.print(message, color, sound) else local formatted = ExpUtil.format_any(message, nil, 20) player.print(formatted, color or Color.white) - player.play_sound{ path = sound or 'utility/scenario_message' } + player.play_sound{ path = sound or "utility/scenario_message" } end end --- Print an error message to the user of a command, accepts any value and will print in a readable and safe format -- @tparam any message The message / value to be printed function Commands.error(message) - return Commands.print(message, Color.orange_red, 'utility/wire_pickup') + return Commands.print(message, Color.orange_red, "utility/wire_pickup") end --- Command Prototype @@ -382,7 +382,7 @@ end --- This is a default callback that should never be called local function default_command_callback() - return Commands.status.internal_error('No callback registered') + return Commands.status.internal_error("No callback registered") end --- Returns a new command object, this will not register the command to the game @@ -393,7 +393,7 @@ function Commands.new(name, help) ExpUtil.assert_argument_type(name, "string", 1, "name") ExpUtil.assert_argument_type(help, "string", 2, "help") if Commands.registered_commands[name] then - error("Command is already defined at: "..Commands.registered_commands[name].defined_at, 2) + error("Command is already defined at: " .. Commands.registered_commands[name].defined_at, 2) end return setmetatable({ @@ -414,7 +414,7 @@ end local function get_parser(data_type) local rtn = Commands.data_types[data_type] if rtn == nil then - error("Unknown data type: "..tostring(data_type), 3) + error("Unknown data type: " .. tostring(data_type), 3) end return data_type, rtn end @@ -434,7 +434,7 @@ function Commands._prototype:argument(name, data_type, ...) optional = false, data_type = data_type, data_type_parser = get_parser(data_type), - parse_args = {...} + parse_args = { ... }, } return self end @@ -450,7 +450,7 @@ function Commands._prototype:optional(name, data_type, ...) optional = true, data_type = data_type, data_type_parser = get_parser(data_type), - parse_args = {...} + parse_args = { ... }, } return self end @@ -459,22 +459,24 @@ end -- @tparam table defaults A table who's keys are the argument names and values are the defaults or function which returns a default -- @treturn Command The command object to allow chaining method calls function Commands._prototype:defaults(defaults) - local matched = {} - for _, argument in ipairs(self.arguments) do - if defaults[argument.name] then - if not argument.optional then - error("Attempting to set default value for required argument: " .. argument.name) - end - argument.default = defaults[argument.name] - matched[argument.name] = true - end - end - -- Check that there are no extra values in the table - for name in pairs(defaults) do - if not matched[name] then - error("No argument with name: " .. name) + local matched = {} + for _, argument in ipairs(self.arguments) do + if defaults[argument.name] then + if not argument.optional then + error("Attempting to set default value for required argument: " .. argument.name) + end + argument.default = defaults[argument.name] + matched[argument.name] = true end end + + -- Check that there are no extra values in the table + for name in pairs(defaults) do + if not matched[name] then + error("No argument with name: " .. name) + end + end + return self end @@ -489,6 +491,7 @@ function Commands._prototype:add_flags(flags) self.flags[name] = value end end + return self end @@ -500,6 +503,7 @@ function Commands._prototype:add_aliases(aliases) for index, alias in ipairs(aliases) do self.aliases[start_index + index] = alias end + return self end @@ -520,11 +524,12 @@ function Commands._prototype:register(callback) local description = {} for index, argument in pairs(self.arguments) do if argument.optional then - description[index] = "["..argument.name.."]" + description[index] = "[" .. argument.name .. "]" else - description[index] = "<"..argument.name..">" + description[index] = "<" .. argument.name .. ">" end end + self.description = table.concat(description, " ") -- Callback which is called by the game engine @@ -539,7 +544,7 @@ function Commands._prototype:register(callback) end -- Registers the command under its own name - local help = {'exp-commands.command-help', self.description, self.help} + local help = { "exp-commands.command-help", self.description, self.help } commands.add_command(self.name, help, command_callback) -- Registers the command under its aliases @@ -554,42 +559,42 @@ end --- Log that a command was attempted and its outcome (error / success) local function log_command(comment, command, player, args, detail) - local player_name = player and player.name or '' - ExpUtil.write_json('log/commands.log', { + local player_name = player and player.name or "" + ExpUtil.write_json("log/commands.log", { comment = comment, detail = detail, player_name = player_name, command_name = command.name, - args = args + args = args, }) end --- Extract the arguments from a string input string local function extract_arguments(raw_input, max_args, auto_concat) - -- nil check when no input given - if raw_input == nil then return {} end + -- nil check when no input given + if raw_input == nil then return {} end -- Extract quoted arguments local quoted_arguments = {} local input_string = raw_input:gsub('"[^"]-"', function(word) - local no_spaces = word:gsub('%s', '%%s') + local no_spaces = word:gsub("%s", "%%s") quoted_arguments[no_spaces] = word:sub(2, -2) - return ' '..no_spaces..' ' + return " " .. no_spaces .. " " end) -- Extract all arguments local index = 0 local arguments = {} - for word in input_string:gmatch('%S+') do + for word in input_string:gmatch("%S+") do index = index + 1 if index > max_args then -- concat the word onto the last argument if auto_concat == false then return nil -- too many args, exit early elseif quoted_arguments[word] then - arguments[max_args] = arguments[max_args]..' "'..quoted_arguments[word]..'"' + arguments[max_args] = arguments[max_args] .. ' "' .. quoted_arguments[word] .. '"' else - arguments[max_args] = arguments[max_args]..' '..word + arguments[max_args] = arguments[max_args] .. " " .. word end else -- new argument to be added @@ -608,7 +613,7 @@ end function Commands._event_handler(event) local command = Commands.registered_commands[event.name] if command == nil then - error("Command not recognised: "..event.name) + error("Command not recognised: " .. event.name) end local player = nil -- nil represents the server until the command is called @@ -626,20 +631,20 @@ function Commands._event_handler(event) -- Check the edge case of parameter being nil if command.min_arg_count > 0 and event.parameter == nil then log_command("Too few arguments", command, player, event.parameter, { minimum = command.min_arg_count, maximum = command.max_arg_count }) - return Commands.error{'exp-commands.invalid-usage', command.name, command.description} + return Commands.error{ "exp-commands.invalid-usage", command.name, command.description } end -- Get the arguments for the command, returns nil if there are too many arguments local raw_arguments = extract_arguments(event.parameter, command.max_arg_count, command.auto_concat) if raw_arguments == nil then log_command("Too many arguments", command, player, event.parameter, { minimum = command.min_arg_count, maximum = command.max_arg_count }) - return Commands.error{'exp-commands.invalid-usage', command.name, command.description} + return Commands.error{ "exp-commands.invalid-usage", command.name, command.description } end -- Check the minimum number of arguments is fullfiled if #raw_arguments < command.min_arg_count then log_command("Too few arguments", command, player, event.parameter, { minimum = command.min_arg_count, maximum = command.max_arg_count }) - return Commands.error{'exp-commands.invalid-usage', command.name, command.description} + return Commands.error{ "exp-commands.invalid-usage", command.name, command.description } end -- Parse the arguments, optional arguments will attempt to use a default if provided @@ -659,7 +664,7 @@ function Commands._event_handler(event) local success, status, parsed = Commands.parse_data_type(argument.data_type_parser, input, player, table.unpack(argument.parse_args)) if success == false then log_command("Input parse failed", command, player, event.parameter, { status = valid_command_status[status], index = index, argument = argument, reason = parsed }) - return Commands.error{'exp-commands.invalid-argument', argument.name, parsed} + return Commands.error{ "exp-commands.invalid-argument", argument.name, parsed } else arguments[index] = parsed end diff --git a/exp_groups/module/control.lua b/exp_groups/module/control.lua index ac13cb12..af956afc 100644 --- a/exp_groups/module/control.lua +++ b/exp_groups/module/control.lua @@ -4,122 +4,124 @@ local Groups = require("modules/exp_groups") local pending_updates = {} Global.register(pending_updates, function(tbl) - pending_updates = tbl + pending_updates = tbl end) local function on_permission_group_added(event) - if not event.player_index then return end - pending_updates[event.group.name] = { - created = true, - sync_all = true, - tick = event.tick, - permissions = {}, - players = {}, - } + if not event.player_index then return end + pending_updates[event.group.name] = { + created = true, + sync_all = true, + tick = event.tick, + permissions = {}, + players = {}, + } end local function on_permission_group_deleted(event) - if not event.player_index then return end - local existing = pending_updates[event.group_name] - pending_updates[event.group_name] = nil - if not existing or not existing.created then - clusterio_api.send_json("exp_groups-permission_group_delete", { - group = event.group_name, - }) - end + if not event.player_index then return end + local existing = pending_updates[event.group_name] + pending_updates[event.group_name] = nil + if not existing or not existing.created then + clusterio_api.send_json("exp_groups-permission_group_delete", { + group = event.group_name, + }) + end end local function on_permission_group_edited(event) - if not event.player_index then return end - local pending = pending_updates[event.group.name] - if not pending then - pending = { - tick = event.tick, - permissions = {}, - players = {}, - } - pending_updates[event.group.name] = pending - end - pending.tick = event.tick + if not event.player_index then return end + local pending = pending_updates[event.group.name] + if not pending then + pending = { + tick = event.tick, + permissions = {}, + players = {}, + } + pending_updates[event.group.name] = pending + end + pending.tick = event.tick - if event.type == "add-permission" then - if not pending.sync_all then - pending.permissions[event.action] = true - end - elseif event.type == "remove-permission" then - if not pending.sync_all then - pending.permissions[event.action] = false - end - elseif event.type == "enable-all" then - pending.sync_all = true - elseif event.type == "disable-all" then - pending.sync_all = true - elseif event.type == "add-player" then - local player = game.get_player(event.other_player_index) --- @cast player -nil - pending.players[player.name] = true - elseif event.type == "remove-player" then - local player = game.get_player(event.other_player_index) --- @cast player -nil - pending.players[player.name] = nil - elseif event.type == "rename" then - pending.created = true - pending.sync_all = true - local old = pending_updates[event.old_name] - if old then pending.players = old.players end - on_permission_group_deleted{ - tick = event.tick, player_index = event.player_index, group_name = event.old_name - } - end + if event.type == "add-permission" then + if not pending.sync_all then + pending.permissions[event.action] = true + end + elseif event.type == "remove-permission" then + if not pending.sync_all then + pending.permissions[event.action] = false + end + elseif event.type == "enable-all" then + pending.sync_all = true + elseif event.type == "disable-all" then + pending.sync_all = true + elseif event.type == "add-player" then + local player = game.get_player(event.other_player_index) --- @cast player -nil + pending.players[player.name] = true + elseif event.type == "remove-player" then + local player = game.get_player(event.other_player_index) --- @cast player -nil + pending.players[player.name] = nil + elseif event.type == "rename" then + pending.created = true + pending.sync_all = true + local old = pending_updates[event.old_name] + if old then pending.players = old.players end + on_permission_group_deleted{ + tick = event.tick, player_index = event.player_index, group_name = event.old_name, + } + end end local function send_updates() - local tick = game.tick - 600 -- 10 Seconds - local done = {} - for group_name, pending in pairs(pending_updates) do - if pending.tick < tick then - done[group_name] = true - if pending.sync_all then - clusterio_api.send_json("exp_groups-permission_group_create", { - group = group_name, defiantion = Groups.get_group(group_name):to_json(true) - }) - else - if next(pending.players) then - clusterio_api.send_json("exp_groups-permission_group_edit", { - type = "assign_players", group = group_name, changes = table.get_keys(pending.players) - }) - end - local add, remove = {}, {} - for permission, state in pairs(pending.permissions) do - if state then - add[#add + 1] = permission - else - remove[#remove + 1] = permission - end - end - if next(add) then - clusterio_api.send_json("exp_groups-permission_group_edit", { - type = "add_permissions", group = group_name, changes = Groups.actions_to_names(add) - }) - end - if next(remove) then - clusterio_api.send_json("exp_groups-permission_group_edit", { - type = "remove_permissions", group = group_name, changes = Groups.actions_to_names(remove) - }) - end - end - end - end - for group_name in pairs(done) do - pending_updates[group_name] = nil - end + local tick = game.tick - 600 -- 10 Seconds + local done = {} + for group_name, pending in pairs(pending_updates) do + if pending.tick < tick then + done[group_name] = true + if pending.sync_all then + clusterio_api.send_json("exp_groups-permission_group_create", { + group = group_name, defiantion = Groups.get_group(group_name):to_json(true), + }) + else + if next(pending.players) then + clusterio_api.send_json("exp_groups-permission_group_edit", { + type = "assign_players", group = group_name, changes = table.get_keys(pending.players), + }) + end + local add, remove = {}, {} + for permission, state in pairs(pending.permissions) do + if state then + add[#add + 1] = permission + else + remove[#remove + 1] = permission + end + end + + if next(add) then + clusterio_api.send_json("exp_groups-permission_group_edit", { + type = "add_permissions", group = group_name, changes = Groups.actions_to_names(add), + }) + end + if next(remove) then + clusterio_api.send_json("exp_groups-permission_group_edit", { + type = "remove_permissions", group = group_name, changes = Groups.actions_to_names(remove), + }) + end + end + end + end + + for group_name in pairs(done) do + pending_updates[group_name] = nil + end end return { - events = { - [defines.events.on_permission_group_added] = on_permission_group_added, - [defines.events.on_permission_group_deleted] = on_permission_group_deleted, - [defines.events.on_permission_group_edited] = on_permission_group_edited, - }, - on_nth_tick = { - [300] = send_updates, - } + events = { + [defines.events.on_permission_group_added] = on_permission_group_added, + [defines.events.on_permission_group_deleted] = on_permission_group_deleted, + [defines.events.on_permission_group_edited] = on_permission_group_edited, + }, + on_nth_tick = { + [300] = send_updates, + }, } diff --git a/exp_groups/module/module_exports.lua b/exp_groups/module/module_exports.lua index 2b759062..8cc5d6fc 100644 --- a/exp_groups/module/module_exports.lua +++ b/exp_groups/module/module_exports.lua @@ -3,46 +3,47 @@ local Async = require("modules/exp_util/async") --- Top level module table, contains event handlers and public methods local Groups = {} ----@class ExpGroup ----@field group LuaPermissionGroup The permission group for this group proxy +--- @class ExpGroup +--- @field group LuaPermissionGroup The permission group for this group proxy Groups._prototype = {} Groups._metatable = { - __index = setmetatable(Groups._prototype, { - __index = function(self, key) - return self.group[key] - end - }), - __class = "ExpGroup" + __index = setmetatable(Groups._prototype, { + __index = function(self, key) + return self.group[key] + end, + }), + __class = "ExpGroup", } local action_to_name = {} for name, action in pairs(defines.input_action) do - action_to_name[action] = name + action_to_name[action] = name end --- Async Functions -- These are required to allow bypassing edit_permission_group --- Add a player to a permission group, requires edit_permission_group ----@param player LuaPlayer Player to add to the group ----@param group LuaPermissionGroup Group to add the player to +--- @param player LuaPlayer Player to add to the group +--- @param group LuaPermissionGroup Group to add the player to local function add_player_to_group(player, group) - return group.add_player(player) + return group.add_player(player) end --- Add a players to a permission group, requires edit_permission_group ----@param players LuaPlayer[] Players to add to the group ----@param group LuaPermissionGroup Group to add the players to +--- @param players LuaPlayer[] Players to add to the group +--- @param group LuaPermissionGroup Group to add the players to local function add_players_to_group(players, group) - local add_player = group.add_player - if not add_player(players[1]) then - return false - end - for i = 2, #players do - add_player(players[i]) - end - return true + local add_player = group.add_player + if not add_player(players[1]) then + return false + end + for i = 2, #players do + add_player(players[i]) + end + + return true end -- Async will bypass edit_permission_group but takes at least one tick @@ -52,225 +53,230 @@ local add_players_to_group_async = Async.register(add_players_to_group) --- Static methods for gettings, creating and removing permission groups --- Gets the permission group proxy with the given name or group ID. ----@param group_name string|uint32 The name or id of the permission group +--- @param group_name string|uint32 The name or id of the permission group function Groups.get_group(group_name) - local group = game.permissions.get_group(group_name) - if group == nil then return nil end - return setmetatable({ - group = group - }, Groups._metatable) + local group = game.permissions.get_group(group_name) + if group == nil then return nil end + return setmetatable({ + group = group, + }, Groups._metatable) end --- Gets the permission group proxy for a players group ----@param player LuaPlayer The player to get the group of +--- @param player LuaPlayer The player to get the group of function Groups.get_player_group(player) - local group = player.permission_group - if group == nil then return nil end - return setmetatable({ - group = group - }, Groups._metatable) + local group = player.permission_group + if group == nil then return nil end + return setmetatable({ + group = group, + }, Groups._metatable) end --- Creates a new permission group, requires add_permission_group ----@param group_name string Name of the group to create +--- @param group_name string Name of the group to create function Groups.new_group(group_name) - local group = game.permissions.get_group(group_name) - assert(group == nil, "Group already exists with name: " .. group_name) - group = game.permissions.create_group(group_name) - assert(group ~= nil, "Requires permission add_permission_group") - return setmetatable({ - group = group - }, Groups._metatable) + local group = game.permissions.get_group(group_name) + assert(group == nil, "Group already exists with name: " .. group_name) + group = game.permissions.create_group(group_name) + assert(group ~= nil, "Requires permission add_permission_group") + return setmetatable({ + group = group, + }, Groups._metatable) end --- Get or create a permisison group, must use the group name not the group id ----@param group_name string Name of the group to create +--- @param group_name string Name of the group to create function Groups.get_or_create(group_name) - local group = game.permissions.get_group(group_name) - if group then - return setmetatable({ - group = group - }, Groups._metatable) - else - group = game.permissions.create_group(group_name) - assert(group ~= nil, "Requires permission add_permission_group") - return setmetatable({ - group = group - }, Groups._metatable) - end + local group = game.permissions.get_group(group_name) + if group then + return setmetatable({ + group = group, + }, Groups._metatable) + else + group = game.permissions.create_group(group_name) + assert(group ~= nil, "Requires permission add_permission_group") + return setmetatable({ + group = group, + }, Groups._metatable) + end end --- Destory a permission group, moves all players to default group ----@param group_name string|uint32 The name or id of the permission group to destroy ----@param move_to_name string|uint32? The name or id of the permission group to move players to +--- @param group_name string|uint32 The name or id of the permission group to destroy +--- @param move_to_name string|uint32? The name or id of the permission group to move players to function Groups.destroy_group(group_name, move_to_name) - local group = game.permissions.get_group(group_name) - if group == nil then return nil end + local group = game.permissions.get_group(group_name) + if group == nil then return nil end - local players = group.players - if #players > 0 then - local move_to = game.permissions.get_group(move_to_name or "Default") - for _, player in ipairs(players) do - player.permission_group = move_to - end - end + local players = group.players + if #players > 0 then + local move_to = game.permissions.get_group(move_to_name or "Default") + for _, player in ipairs(players) do + player.permission_group = move_to + end + end - local success = group.destroy() - assert(success, "Requires permission delete_permission_group") + local success = group.destroy() + assert(success, "Requires permission delete_permission_group") end --- Prototype methods for modifying and working with permission groups --- Add a player to the permission group ----@param player LuaPlayer The player to add to the group +--- @param player LuaPlayer The player to add to the group function Groups._prototype:add_player(player) - return add_player_to_group(player, self.group) or add_player_to_group_async(player, self.group) + return add_player_to_group(player, self.group) or add_player_to_group_async(player, self.group) end --- Add players to the permission group ----@param players LuaPlayer[] The player to add to the group +--- @param players LuaPlayer[] The player to add to the group function Groups._prototype:add_players(players) - return add_players_to_group(players, self.group) or add_players_to_group_async(players, self.group) + return add_players_to_group(players, self.group) or add_players_to_group_async(players, self.group) end --- Move all players to another group ----@param other_group ExpGroup The group to move players to, default is the Default group +--- @param other_group ExpGroup The group to move players to, default is the Default group function Groups._prototype:move_players(other_group) - return add_players_to_group(self.group.players, other_group.group) or add_players_to_group_async(self.group.players, other_group.group) + return add_players_to_group(self.group.players, other_group.group) or add_players_to_group_async(self.group.players, other_group.group) end --- Allow a set of actions for this group ----@param actions defines.input_action[] Actions to allow +--- @param actions defines.input_action[] Actions to allow function Groups._prototype:allow_actions(actions) - local set_allow = self.group.set_allows_action - for _, action in ipairs(actions) do - set_allow(action, true) - end - return self + local set_allow = self.group.set_allows_action + for _, action in ipairs(actions) do + set_allow(action, true) + end + + return self end --- Disallow a set of actions for this group ----@param actions defines.input_action[] Actions to disallow +--- @param actions defines.input_action[] Actions to disallow function Groups._prototype:disallow_actions(actions) - local set_allow = self.group.set_allows_action - for _, action in ipairs(actions) do - set_allow(action, false) - end - return self + local set_allow = self.group.set_allows_action + for _, action in ipairs(actions) do + set_allow(action, false) + end + + return self end --- Reset the allowed state of all actions ----@param allowed boolean? default true for allow all actions, false to disallow all actions +--- @param allowed boolean? default true for allow all actions, false to disallow all actions function Groups._prototype:reset(allowed) - local set_allow = self.group.set_allows_action - if allowed == nil then allowed = true end - for _, action in pairs(defines.input_action) do - set_allow(action, allowed) - end - return self + local set_allow = self.group.set_allows_action + if allowed == nil then allowed = true end + for _, action in pairs(defines.input_action) do + set_allow(action, allowed) + end + + return self end --- Returns if the group is allowed a given action ----@param action string|defines.input_action Actions to test +--- @param action string|defines.input_action Actions to test function Groups._prototype:allows(action) - if type(action) == "string" then - return self.group.allows_action(defines.input_action[action]) - end - return self.group.allows_action(action) + if type(action) == "string" then + return self.group.allows_action(defines.input_action[action]) + end + return self.group.allows_action(action) end --- Print a message to all players in the group function Groups._prototype:print(...) - for _, player in ipairs(self.group.players) do - player.print(...) - end + for _, player in ipairs(self.group.players) do + player.print(...) + end end --- Static and Prototype methods for use with IPC --- Convert an array of strings into an array of action names ----@param actions_names string[] An array of action names +--- @param actions_names string[] An array of action names local function names_to_actions(actions_names) - local actions, invalid, invalid_i = {}, {}, 1 - for i, action_name in ipairs(actions_names) do - local action = defines.input_action[action_name] - if action then - actions[i] = action - else - invalid[invalid_i] = i - invalid_i = invalid_i + 1 - end - end + local actions, invalid, invalid_i = {}, {}, 1 + for i, action_name in ipairs(actions_names) do + local action = defines.input_action[action_name] + if action then + actions[i] = action + else + invalid[invalid_i] = i + invalid_i = invalid_i + 1 + end + end - local last = #actions - for _, i in ipairs(invalid) do - actions[i] = actions[last] - last = last - 1 - end + local last = #actions + for _, i in ipairs(invalid) do + actions[i] = actions[last] + last = last - 1 + end - return actions + return actions end --- Get the action names from the action numbers function Groups.actions_to_names(actions) - local names = {} - for i, action in ipairs(actions) do - names[i] = action_to_name[action] - end - return names + local names = {} + for i, action in ipairs(actions) do + names[i] = action_to_name[action] + end + + return names end --- Get all input actions that are defined function Groups.get_actions_json() - local rtn, rtn_i = {}, 1 - for name in pairs(defines.input_action) do - rtn[rtn_i] = name - rtn_i = rtn_i + 1 - end - return game.table_to_json(rtn) + local rtn, rtn_i = {}, 1 + for name in pairs(defines.input_action) do + rtn[rtn_i] = name + rtn_i = rtn_i + 1 + end + + return game.table_to_json(rtn) end --- Convert a json string array into an array of input actions ----@param json string A json string representing a string array of actions +--- @param json string A json string representing a string array of actions function Groups.json_to_actions(json) - local tbl = game.json_to_table(json) - assert(tbl, "Invalid Json String") - ---@cast tbl string[] - return names_to_actions(tbl) + local tbl = game.json_to_table(json) + assert(tbl, "Invalid Json String") + --- @cast tbl string[] + return names_to_actions(tbl) end --- Returns the shortest defination of the allowed actions -- The first value of the return can be passed to :reset function Groups._prototype:to_json(raw) - local allow, disallow = {}, {} - local allow_i, disallow_i = 1, 1 - local allows = self.group.allows_action - for name, action in pairs(defines.input_action) do - if allows(action) then - allow[allow_i] = name - allow_i = allow_i + 1 - else - disallow[disallow_i] = name - disallow_i = disallow_i + 1 - end - end + local allow, disallow = {}, {} + local allow_i, disallow_i = 1, 1 + local allows = self.group.allows_action + for name, action in pairs(defines.input_action) do + if allows(action) then + allow[allow_i] = name + allow_i = allow_i + 1 + else + disallow[disallow_i] = name + disallow_i = disallow_i + 1 + end + end - if allow_i >= disallow_i then - return raw and {true, disallow} or game.table_to_json{ true, disallow } - end - return raw and {false, allow} or game.table_to_json{ false, allow } + if allow_i >= disallow_i then + return raw and { true, disallow } or game.table_to_json{ true, disallow } + end + return raw and { false, allow } or game.table_to_json{ false, allow } end --- Restores this group to the state given in a json string ----@param json string The json string to restore from +--- @param json string The json string to restore from function Groups._prototype:from_json(json) - local tbl = game.json_to_table(json) - assert(tbl and type(tbl[1]) == "boolean" and type(tbl[2]) == "table", "Invalid Json String") + local tbl = game.json_to_table(json) + assert(tbl and type(tbl[1]) == "boolean" and type(tbl[2]) == "table", "Invalid Json String") - if tbl[1] then - return self:reset(true):disallow_actions(names_to_actions(tbl[2])) - end - return self:reset(false):allow_actions(names_to_actions(tbl[2])) + if tbl[1] then + return self:reset(true):disallow_actions(names_to_actions(tbl[2])) + end + return self:reset(false):allow_actions(names_to_actions(tbl[2])) end return Groups diff --git a/exp_legacy/module/config/_file_loader.lua b/exp_legacy/module/config/_file_loader.lua index fab383e8..8e7bf22a 100644 --- a/exp_legacy/module/config/_file_loader.lua +++ b/exp_legacy/module/config/_file_loader.lua @@ -4,109 +4,109 @@ -- core files should be required by modules and not be present in this list; -- @config File-Loader return { - --'example.file_not_loaded', - 'modules.factorio-control', -- base factorio free play scenario - 'expcore.player_data', -- must be loaded first to register event handlers + -- 'example.file_not_loaded', + "modules.factorio-control", -- base factorio free play scenario + "expcore.player_data", -- must be loaded first to register event handlers --- Game Commands - 'modules.commands.debug', - 'modules.commands.me', - 'modules.commands.kill', - 'modules.commands.admin-chat', - 'modules.commands.admin-markers', - 'modules.commands.teleport', - 'modules.commands.cheat-mode', - 'modules.commands.ratio', - 'modules.commands.interface', - 'modules.commands.help', - 'modules.commands.roles', - 'modules.commands.rainbow', - 'modules.commands.clear-inventory', - 'modules.commands.jail', - 'modules.commands.repair', - 'modules.commands.reports', - 'modules.commands.spawn', - 'modules.commands.warnings', - 'modules.commands.find', - 'modules.commands.home', - 'modules.commands.connect', - 'modules.commands.last-location', - 'modules.commands.protection', - 'modules.commands.spectate', - 'modules.commands.search', - 'modules.commands.bot-queue', - 'modules.commands.speed', - 'modules.commands.pollution', - 'modules.commands.train', - 'modules.commands.friendly-fire', - 'modules.commands.research', - 'modules.commands.vlayer', - 'modules.commands.enemy', - 'modules.commands.waterfill', - 'modules.commands.artillery', - 'modules.commands.surface-clearing', + "modules.commands.debug", + "modules.commands.me", + "modules.commands.kill", + "modules.commands.admin-chat", + "modules.commands.admin-markers", + "modules.commands.teleport", + "modules.commands.cheat-mode", + "modules.commands.ratio", + "modules.commands.interface", + "modules.commands.help", + "modules.commands.roles", + "modules.commands.rainbow", + "modules.commands.clear-inventory", + "modules.commands.jail", + "modules.commands.repair", + "modules.commands.reports", + "modules.commands.spawn", + "modules.commands.warnings", + "modules.commands.find", + "modules.commands.home", + "modules.commands.connect", + "modules.commands.last-location", + "modules.commands.protection", + "modules.commands.spectate", + "modules.commands.search", + "modules.commands.bot-queue", + "modules.commands.speed", + "modules.commands.pollution", + "modules.commands.train", + "modules.commands.friendly-fire", + "modules.commands.research", + "modules.commands.vlayer", + "modules.commands.enemy", + "modules.commands.waterfill", + "modules.commands.artillery", + "modules.commands.surface-clearing", --- Addons - 'modules.addons.chat-popups', - 'modules.addons.damage-popups', - 'modules.addons.death-logger', - 'modules.addons.advanced-start', - 'modules.addons.spawn-area', - 'modules.addons.compilatron', - 'modules.addons.scorched-earth', - 'modules.addons.pollution-grading', - 'modules.addons.station-auto-name', - 'modules.addons.discord-alerts', - 'modules.addons.chat-reply', - 'modules.addons.tree-decon', - 'modules.addons.afk-kick', - 'modules.addons.report-jail', - 'modules.addons.protection-jail', - 'modules.addons.deconlog', - 'modules.addons.nukeprotect', - 'modules.addons.inserter', - 'modules.addons.miner', - 'modules.addons.lawnmower', - 'modules.addons.logging', + "modules.addons.chat-popups", + "modules.addons.damage-popups", + "modules.addons.death-logger", + "modules.addons.advanced-start", + "modules.addons.spawn-area", + "modules.addons.compilatron", + "modules.addons.scorched-earth", + "modules.addons.pollution-grading", + "modules.addons.station-auto-name", + "modules.addons.discord-alerts", + "modules.addons.chat-reply", + "modules.addons.tree-decon", + "modules.addons.afk-kick", + "modules.addons.report-jail", + "modules.addons.protection-jail", + "modules.addons.deconlog", + "modules.addons.nukeprotect", + "modules.addons.inserter", + "modules.addons.miner", + "modules.addons.lawnmower", + "modules.addons.logging", -- Control - 'modules.control.vlayer', + "modules.control.vlayer", --- Data - 'modules.data.statistics', - 'modules.data.player-colours', - 'modules.data.greetings', - 'modules.data.quickbar', - 'modules.data.alt-view', - 'modules.data.tag', + "modules.data.statistics", + "modules.data.player-colours", + "modules.data.greetings", + "modules.data.quickbar", + "modules.data.alt-view", + "modules.data.tag", -- 'modules.data.bonus', - 'modules.data.personal-logistic', - 'modules.data.language', + "modules.data.personal-logistic", + "modules.data.language", --- GUI - 'modules.gui.readme', - 'modules.gui.rocket-info', - 'modules.gui.science-info', - 'modules.gui.autofill', - 'modules.gui.warp-list', - 'modules.gui.task-list', - 'modules.gui.player-list', - 'modules.gui.server-ups', - 'modules.gui.bonus', - 'modules.gui.vlayer', - 'modules.gui.research', - 'modules.gui.module', - 'modules.gui.landfill', - 'modules.gui.production', - 'modules.gui.playerdata', - 'modules.gui.surveillance', - 'modules.graftorio.require', -- graftorio - 'modules.gui.toolbar', -- must be loaded last to register toolbar handlers + "modules.gui.readme", + "modules.gui.rocket-info", + "modules.gui.science-info", + "modules.gui.autofill", + "modules.gui.warp-list", + "modules.gui.task-list", + "modules.gui.player-list", + "modules.gui.server-ups", + "modules.gui.bonus", + "modules.gui.vlayer", + "modules.gui.research", + "modules.gui.module", + "modules.gui.landfill", + "modules.gui.production", + "modules.gui.playerdata", + "modules.gui.surveillance", + "modules.graftorio.require", -- graftorio + "modules.gui.toolbar", -- must be loaded last to register toolbar handlers --- Config Files - 'config.expcore.command_auth_admin', -- commands tagged with admin_only are blocked for non admins - 'config.expcore.command_auth_roles', -- commands must be allowed via the role config - 'config.expcore.command_runtime_disable', -- allows commands to be enabled and disabled during runtime - 'config.expcore.permission_groups', -- loads some predefined permission groups - 'config.expcore.roles', -- loads some predefined roles + "config.expcore.command_auth_admin", -- commands tagged with admin_only are blocked for non admins + "config.expcore.command_auth_roles", -- commands must be allowed via the role config + "config.expcore.command_runtime_disable", -- allows commands to be enabled and disabled during runtime + "config.expcore.permission_groups", -- loads some predefined permission groups + "config.expcore.roles", -- loads some predefined roles } diff --git a/exp_legacy/module/config/advanced_start.lua b/exp_legacy/module/config/advanced_start.lua index 78b2d2bd..9209126c 100644 --- a/exp_legacy/module/config/advanced_start.lua +++ b/exp_legacy/module/config/advanced_start.lua @@ -73,58 +73,58 @@ end ]] return { - skip_intro=true, --- @setting skip_intro skips the intro given in the default factorio free play scenario - skip_victory=true, --- @setting skip_victory will skip the victory screen when a rocket is launched - disable_base_game_silo_script=true, --- @setting disable_base_game_silo_script will not load the silo script at all - research_queue_from_start=true, --- @setting research_queue_from_start when true the research queue is useable from the start - friendly_fire=false, --- @setting friendly_fire weather players will be able to attack each other on the same force - enemy_expansion=false, --- @setting enemy_expansion a catch all for in case the map settings file fails to load - chart_radius=10*32, --- @setting chart_radius the number of tiles that will be charted when the map starts + skip_intro = true, --- @setting skip_intro skips the intro given in the default factorio free play scenario + skip_victory = true, --- @setting skip_victory will skip the victory screen when a rocket is launched + disable_base_game_silo_script = true, --- @setting disable_base_game_silo_script will not load the silo script at all + research_queue_from_start = true, --- @setting research_queue_from_start when true the research queue is useable from the start + friendly_fire = false, --- @setting friendly_fire weather players will be able to attack each other on the same force + enemy_expansion = false, --- @setting enemy_expansion a catch all for in case the map settings file fails to load + chart_radius = 10 * 32, --- @setting chart_radius the number of tiles that will be charted when the map starts items = { --- @setting items items and there condition for being given -- ['item-name'] = function(amount_made, production_stats, player) return end -- 0 means no items given -- Plates - ['iron-plate']=scale_amount_made(100, 10, 10), - ['copper-plate']=scale_amount_made(100, 0, 8), - ['steel-plate']=scale_amount_made(100, 0, 4), + ["iron-plate"] = scale_amount_made(100, 10, 10), + ["copper-plate"] = scale_amount_made(100, 0, 8), + ["steel-plate"] = scale_amount_made(100, 0, 4), -- Secondary Items - ['electronic-circuit']=scale_amount_made(1000, 0, 6), - ['iron-gear-wheel']=scale_amount_made(1000, 0, 6), + ["electronic-circuit"] = scale_amount_made(1000, 0, 6), + ["iron-gear-wheel"] = scale_amount_made(1000, 0, 6), -- Starting Items - ['burner-mining-drill']=cutoff_time(10*minutes, 4, 0), - ['stone-furnace']=cutoff_time(10*minutes, 4, 0), + ["burner-mining-drill"] = cutoff_time(10 * minutes, 4, 0), + ["stone-furnace"] = cutoff_time(10 * minutes, 4, 0), -- Armor - ['light-armor']=cutoff_amount_made_unless(5, 0,1,'heavy-armor',5), - ['heavy-armor']=cutoff_amount_made(5, 0,1), + ["light-armor"] = cutoff_amount_made_unless(5, 0, 1, "heavy-armor", 5), + ["heavy-armor"] = cutoff_amount_made(5, 0, 1), -- Weapon - ['pistol']=cutoff_amount_made_unless(0, 1, 1,'submachine-gun',5), - ['submachine-gun']=cutoff_amount_made(5, 0, 1), + ["pistol"] = cutoff_amount_made_unless(0, 1, 1, "submachine-gun", 5), + ["submachine-gun"] = cutoff_amount_made(5, 0, 1), -- Ammo - ['firearm-magazine']=cutoff_amount_made_unless(100, 10, 0,'piercing-rounds-magazine', 100), - ['piercing-rounds-magazine']=cutoff_amount_made(100, 0, 10), + ["firearm-magazine"] = cutoff_amount_made_unless(100, 10, 0, "piercing-rounds-magazine", 100), + ["piercing-rounds-magazine"] = cutoff_amount_made(100, 0, 10), --[[ ['construction-robot']=scale_amount_made(1, 10, 1) ]] }, armor = { - enable=false, - main = 'modular-armor', + enable = false, + main = "modular-armor", item = { { - equipment='solar-panel-equipment', - count=16 + equipment = "solar-panel-equipment", + count = 16, }, { - equipment='belt-immunity-equipment', - count=1 + equipment = "belt-immunity-equipment", + count = 1, }, { - equipment='battery-equipment', - count=2 + equipment = "battery-equipment", + count = 2, }, { - equipment='personal-roboport-equipment', - count=1 + equipment = "personal-roboport-equipment", + count = 1, }, - } - } + }, + }, } diff --git a/exp_legacy/module/config/afk_kick.lua b/exp_legacy/module/config/afk_kick.lua index d0be3e1b..c401af08 100644 --- a/exp_legacy/module/config/afk_kick.lua +++ b/exp_legacy/module/config/afk_kick.lua @@ -1,9 +1,9 @@ return { admin_as_active = true, --- @setting admin_as_active When true admins will be treated as active regardless of afk time trust_as_active = true, --- @setting trust_as_active When true trusted players (by playtime) will be treated as active regardless of afk time - active_role = 'Veteran', --- @setting active_role When not nil a player with this role will be treated as active regardless of afk time - afk_time = 3600*10, --- @setting afk_time The time in ticks that must pass for a player to be considered afk - kick_time = 3600*30, --- @setting kick_time The time in ticks that must pass without any active players for all players to be kicked - trust_time = 3600*60*10, --- @setting trust_time The time in ticks that a player must be online for to count as trusted - update_time = 3600*30, --- @setting update_time How often in ticks the script checks for active players -} \ No newline at end of file + active_role = "Veteran", --- @setting active_role When not nil a player with this role will be treated as active regardless of afk time + afk_time = 3600 * 10, --- @setting afk_time The time in ticks that must pass for a player to be considered afk + kick_time = 3600 * 30, --- @setting kick_time The time in ticks that must pass without any active players for all players to be kicked + trust_time = 3600 * 60 * 10, --- @setting trust_time The time in ticks that a player must be online for to count as trusted + update_time = 3600 * 30, --- @setting update_time How often in ticks the script checks for active players +} diff --git a/exp_legacy/module/config/bonus.lua b/exp_legacy/module/config/bonus.lua index ff665d4c..7c9289a4 100644 --- a/exp_legacy/module/config/bonus.lua +++ b/exp_legacy/module/config/bonus.lua @@ -17,79 +17,79 @@ return { = 480 ]] pts = { - base = 260 + base = 260, }, gui_display_width = { half = 150, label = 70, slider = 180, - count = 50 + count = 50, }, conversion = { - ['cmms'] = 'character_mining_speed_modifier', - ['crs'] = 'character_running_speed_modifier', - ['ccs'] = 'character_crafting_speed_modifier', - ['cisb'] = 'character_inventory_slots_bonus', - ['chb'] = 'character_health_bonus', - ['crdb'] = 'character_reach_distance_bonus', + ["cmms"] = "character_mining_speed_modifier", + ["crs"] = "character_running_speed_modifier", + ["ccs"] = "character_crafting_speed_modifier", + ["cisb"] = "character_inventory_slots_bonus", + ["chb"] = "character_health_bonus", + ["crdb"] = "character_reach_distance_bonus", --[[ ['cpdb'] = 'character_item_pickup_distance_bonus' ]] }, player_special_bonus_rate = 300, player_special_bonus = { - ['personal_battery_recharge'] = { + ["personal_battery_recharge"] = { -- 1 MW value = 6, max = 12, scale = 1, cost_scale = 4, cost = 40, - is_percentage = false - } + is_percentage = false, + }, }, player_bonus = { - ['character_mining_speed_modifier'] = { + ["character_mining_speed_modifier"] = { value = 3, max = 6, scale = 0.5, cost_scale = 1, cost = 10, - is_percentage = true + is_percentage = true, }, - ['character_running_speed_modifier'] = { + ["character_running_speed_modifier"] = { value = 1.5, max = 3, scale = 0.25, cost_scale = 1, cost = 60, - is_percentage = true + is_percentage = true, }, - ['character_crafting_speed_modifier'] = { + ["character_crafting_speed_modifier"] = { value = 8, max = 16, scale = 1, cost_scale = 1, cost = 4, - is_percentage = true + is_percentage = true, }, - ['character_inventory_slots_bonus'] = { + ["character_inventory_slots_bonus"] = { value = 100, max = 200, scale = 10, cost_scale = 10, cost = 2, - is_percentage = false + is_percentage = false, }, - ['character_health_bonus'] = { + ["character_health_bonus"] = { value = 200, max = 400, scale = 50, cost_scale = 50, cost = 4, - is_percentage = false + is_percentage = false, }, - ['character_reach_distance_bonus'] = { + ["character_reach_distance_bonus"] = { value = 12, max = 24, scale = 2, @@ -97,9 +97,9 @@ return { cost = 1, is_percentage = false, combined_bonus = { - 'character_resource_reach_distance_bonus', - 'character_build_distance_bonus' - } + "character_resource_reach_distance_bonus", + "character_build_distance_bonus", + }, }, --[[ ['character_item_pickup_distance_bonus'] = { @@ -190,29 +190,29 @@ return { is_percentage = false }, ]] - ['worker_robots_battery_modifier'] = { + ["worker_robots_battery_modifier"] = { value = 1, max = 1, scale = 1, cost_scale = 1, cost = 1, - is_percentage = false + is_percentage = false, }, - ['worker_robots_storage_bonus'] = { + ["worker_robots_storage_bonus"] = { value = 1, max = 1, scale = 1, cost_scale = 1, cost = 1, - is_percentage = false + is_percentage = false, }, - ['following_robots_lifetime_modifier'] = { + ["following_robots_lifetime_modifier"] = { value = 1, max = 1, scale = 1, cost_scale = 1, cost = 1, - is_percentage = false + is_percentage = false, }, --[[ ['character_item_pickup_distance_bonus'] = { @@ -316,5 +316,5 @@ return { is_percentage = false } ]] - } + }, } diff --git a/exp_legacy/module/config/chat_reply.lua b/exp_legacy/module/config/chat_reply.lua index d57534d4..12397432 100644 --- a/exp_legacy/module/config/chat_reply.lua +++ b/exp_legacy/module/config/chat_reply.lua @@ -5,13 +5,13 @@ local ExpUtil = require("modules/exp_util") local Async = require("modules/exp_util/async") local send_message_async = -Async.register(function(player, message) - if player == true then - game.print(message) - else - player.print(message) - end -end) + Async.register(function(player, message) + if player == true then + game.print(message) + else + player.print(message) + end + end) local afk_time_units = { minutes = true, @@ -22,107 +22,109 @@ local afk_time_units = { return { allow_command_prefix_for_messages = true, --- @setting allow_command_prefix_for_messages when true any message trigger will print to all player when prefixed messages = { --- @setting messages will trigger when ever the word is said - ['discord'] = {'info.discord'}, - ['expgaming'] = {'info.website'}, - ['website'] = {'info.website'}, - ['status'] = {'info.status'}, - ['github'] = {'info.github'}, - ['patreon'] = {'info.patreon'}, - ['donate'] = {'info.patreon'}, - ['command'] = {'info.custom-commands'}, - ['commands'] = {'info.custom-commands'}, - ['softmod'] = {'info.softmod'}, - ['script'] = {'info.softmod'}, - ['loop'] = {'chat-bot.loops'}, - ['rhd'] = {'info.lhd'}, - ['lhd'] = {'info.lhd'}, - ['roundabout'] = {'chat-bot.loops'}, - ['roundabouts'] = {'chat-bot.loops'}, - ['redmew'] = {'info.redmew'}, - ['afk'] = function(player, _is_command) + ["discord"] = { "info.discord" }, + ["expgaming"] = { "info.website" }, + ["website"] = { "info.website" }, + ["status"] = { "info.status" }, + ["github"] = { "info.github" }, + ["patreon"] = { "info.patreon" }, + ["donate"] = { "info.patreon" }, + ["command"] = { "info.custom-commands" }, + ["commands"] = { "info.custom-commands" }, + ["softmod"] = { "info.softmod" }, + ["script"] = { "info.softmod" }, + ["loop"] = { "chat-bot.loops" }, + ["rhd"] = { "info.lhd" }, + ["lhd"] = { "info.lhd" }, + ["roundabout"] = { "chat-bot.loops" }, + ["roundabouts"] = { "chat-bot.loops" }, + ["redmew"] = { "info.redmew" }, + ["afk"] = function(player, _is_command) local max = player for _, next_player in pairs(game.connected_players) do if max.afk_time < next_player.afk_time then max = next_player end end - return {'chat-bot.afk', max.name, ExpUtil.format_locale_time(max.afk_time, "long", afk_time_units)} + + return { "chat-bot.afk", max.name, ExpUtil.format_locale_time(max.afk_time, "long", afk_time_units) } end, - ['players'] = function(_player, _is_command) - return {'chat-bot.players', #game.players} + ["players"] = function(_player, _is_command) + return { "chat-bot.players", #game.players } end, - ['online'] = function(_player, _is_command) - return {'chat-bot.players-online', #game.connected_players} + ["online"] = function(_player, _is_command) + return { "chat-bot.players-online", #game.connected_players } end, - ['r!verify'] = function(player, _is_command) - return {'chat-bot.verify', player.name} + ["r!verify"] = function(player, _is_command) + return { "chat-bot.verify", player.name } end, }, command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins - command_permission = 'command/chat-bot', --- @setting command_permission the permission used to allow command prefixes - command_prefix = '!', --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above) + command_permission = "command/chat-bot", --- @setting command_permission the permission used to allow command prefixes + command_prefix = "!", --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above) commands = { --- @setting commands will trigger only when command prefix is given - ['dev'] = {'chat-bot.not-real-dev'}, - ['blame'] = function(player, _is_command) - local names = {'Cooldude2606', 'arty714', 'badgamernl', 'mark9064', 'aldldl', 'Drahc_pro', player.name} + ["dev"] = { "chat-bot.not-real-dev" }, + ["blame"] = function(player, _is_command) + local names = { "Cooldude2606", "arty714", "badgamernl", "mark9064", "aldldl", "Drahc_pro", player.name } for _, next_player in pairs(game.connected_players) do names[#names + 1] = next_player.name end - return {'chat-bot.blame', table.get_random_dictionary_entry(names)} + + return { "chat-bot.blame", table.get_random_dictionary_entry(names) } end, - ['magic'] = {'chat-bot.magic'}, - ['aids'] = {'chat-bot.aids'}, - ['riot'] = {'chat-bot.riot'}, - ['lenny'] = {'chat-bot.lenny'}, - ['hodor'] = function(_player, _is_command) - local options = {'?', '.', '!', '!!!'} - return {'chat-bot.hodor', table.get_random_dictionary_entry(options)} + ["magic"] = { "chat-bot.magic" }, + ["aids"] = { "chat-bot.aids" }, + ["riot"] = { "chat-bot.riot" }, + ["lenny"] = { "chat-bot.lenny" }, + ["hodor"] = function(_player, _is_command) + local options = { "?", ".", "!", "!!!" } + return { "chat-bot.hodor", table.get_random_dictionary_entry(options) } end, - ['evolution'] = function(_player, _is_command) - return {'chat-bot.current-evolution', string.format('%.2f', game.forces['enemy'].evolution_factor)} + ["evolution"] = function(_player, _is_command) + return { "chat-bot.current-evolution", string.format("%.2f", game.forces["enemy"].evolution_factor) } end, - ['makepopcorn'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(true, {'chat-bot.reply', {'chat-bot.get-popcorn-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.get-popcorn-2', player.name}}) + ["makepopcorn"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(true, { "chat-bot.reply", { "chat-bot.get-popcorn-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-popcorn-2", player.name } }) end, - ['passsomesnaps'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(player, {'chat-bot.reply', {'chat-bot.get-snaps-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.get-snaps-2', player.name}}) - send_message_async:start_after(timeout*(math.random()+0.5), true, {'chat-bot.reply', {'chat-bot.get-snaps-3', player.name}}) + ["passsomesnaps"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(player, { "chat-bot.reply", { "chat-bot.get-snaps-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-snaps-2", player.name } }) + send_message_async:start_after(timeout * (math.random() + 0.5), true, { "chat-bot.reply", { "chat-bot.get-snaps-3", player.name } }) end, - ['makecocktail'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(true, {'chat-bot.reply', {'chat-bot.get-cocktail-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.get-cocktail-2', player.name}}) - send_message_async:start_after(timeout*(math.random()+0.5), true, {'chat-bot.reply', {'chat-bot.get-cocktail-3', player.name}}) + ["makecocktail"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(true, { "chat-bot.reply", { "chat-bot.get-cocktail-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-cocktail-2", player.name } }) + send_message_async:start_after(timeout * (math.random() + 0.5), true, { "chat-bot.reply", { "chat-bot.get-cocktail-3", player.name } }) end, - ['makecoffee'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(true, {'chat-bot.reply', {'chat-bot.make-coffee-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.make-coffee-2', player.name}}) + ["makecoffee"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(true, { "chat-bot.reply", { "chat-bot.make-coffee-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.make-coffee-2", player.name } }) end, - ['orderpizza'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(true, {'chat-bot.reply', {'chat-bot.order-pizza-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.order-pizza-2', player.name}}) - send_message_async:start_after(timeout*(math.random()+0.5), true, {'chat-bot.reply', {'chat-bot.order-pizza-3', player.name}}) + ["orderpizza"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(true, { "chat-bot.reply", { "chat-bot.order-pizza-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.order-pizza-2", player.name } }) + send_message_async:start_after(timeout * (math.random() + 0.5), true, { "chat-bot.reply", { "chat-bot.order-pizza-3", player.name } }) end, - ['maketea'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(true, {'chat-bot.reply', {'chat-bot.make-tea-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.make-tea-2', player.name}}) + ["maketea"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(true, { "chat-bot.reply", { "chat-bot.make-tea-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.make-tea-2", player.name } }) end, - ['meadplease'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(true, {'chat-bot.reply', {'chat-bot.get-mead-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.get-mead-2', player.name}}) + ["meadplease"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(true, { "chat-bot.reply", { "chat-bot.get-mead-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-mead-2", player.name } }) end, - ['passabeer'] = function(player, _is_command) - local timeout = math.floor(180*(math.random()+0.5)) - send_message_async(true, {'chat-bot.reply', {'chat-bot.get-beer-1'}}) - send_message_async:start_after(timeout, true, {'chat-bot.reply', {'chat-bot.get-beer-2', player.name}}) - end - } + ["passabeer"] = function(player, _is_command) + local timeout = math.floor(180 * (math.random() + 0.5)) + send_message_async(true, { "chat-bot.reply", { "chat-bot.get-beer-1" } }) + send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-beer-2", player.name } }) + end, + }, } diff --git a/exp_legacy/module/config/compilatron.lua b/exp_legacy/module/config/compilatron.lua index c7730089..933b5571 100644 --- a/exp_legacy/module/config/compilatron.lua +++ b/exp_legacy/module/config/compilatron.lua @@ -2,22 +2,22 @@ -- @config Compilatron return { - message_cycle=60*15, --- @setting message_cycle 15 seconds default, how often (in ticks) the messages will cycle - locations={ --- @setting locations defines the spawn locations for all compilatrons - ['Spawn']={x=0,y=0} + message_cycle = 60 * 15, --- @setting message_cycle 15 seconds default, how often (in ticks) the messages will cycle + locations = { --- @setting locations defines the spawn locations for all compilatrons + ["Spawn"] = { x = 0, y = 0 }, }, - messages={ --- @setting messages the messages that each one will say, must be same name as its location - ['Spawn']={ - {'info.website'}, - {'info.read-readme'}, - {'info.discord'}, - {'info.softmod'}, - {'info.redmew'}, - {'info.custom-commands'}, - {'info.status'}, - {'info.lhd'}, - {'info.github'}, - {'info.patreon'}, - } - } -} \ No newline at end of file + messages = { --- @setting messages the messages that each one will say, must be same name as its location + ["Spawn"] = { + { "info.website" }, + { "info.read-readme" }, + { "info.discord" }, + { "info.softmod" }, + { "info.redmew" }, + { "info.custom-commands" }, + { "info.status" }, + { "info.lhd" }, + { "info.github" }, + { "info.patreon" }, + }, + }, +} diff --git a/exp_legacy/module/config/death_logger.lua b/exp_legacy/module/config/death_logger.lua index 19095ade..2a923df2 100644 --- a/exp_legacy/module/config/death_logger.lua +++ b/exp_legacy/module/config/death_logger.lua @@ -4,13 +4,13 @@ -- @config Death-Logger return { - --WIP_allow_teleport_to_body_command=false, -- allows use of /return-to-body which teleports you to your last death - --WIP_allow_collect_bodies_command=false, -- allows use of /collect-body which returns all your items to you and removes the body - use_chests_as_bodies=false, --- @setting use_chests_as_bodies weather items should be moved into a chest when a player dies - auto_collect_bodies=true, --- @setting auto_collect_bodies enables items being returned to the spawn point in chests upon corpse expiring - show_map_markers=true, --- @setting show_map_markers shows markers on the map where bodies are - include_time_of_death=true, --- @setting include_time_of_death weather to include the time of death on the map marker - map_icon=nil, --- @setting map_icon the icon that the map marker shows; nil means no icon; format as a SingleID - show_light_at_corpse=true, --- @setting show_light_at_corpse if a light should be rendered at the corpse - show_line_to_corpse=true --- @setting show_line_to_corpse if a line should be rendered from you to your corpse -} \ No newline at end of file + -- WIP_allow_teleport_to_body_command=false, -- allows use of /return-to-body which teleports you to your last death + -- WIP_allow_collect_bodies_command=false, -- allows use of /collect-body which returns all your items to you and removes the body + use_chests_as_bodies = false, --- @setting use_chests_as_bodies weather items should be moved into a chest when a player dies + auto_collect_bodies = true, --- @setting auto_collect_bodies enables items being returned to the spawn point in chests upon corpse expiring + show_map_markers = true, --- @setting show_map_markers shows markers on the map where bodies are + include_time_of_death = true, --- @setting include_time_of_death weather to include the time of death on the map marker + map_icon = nil, --- @setting map_icon the icon that the map marker shows; nil means no icon; format as a SingleID + show_light_at_corpse = true, --- @setting show_light_at_corpse if a light should be rendered at the corpse + show_line_to_corpse = true, --- @setting show_line_to_corpse if a line should be rendered from you to your corpse +} diff --git a/exp_legacy/module/config/deconlog.lua b/exp_legacy/module/config/deconlog.lua index b7fd5ab6..c55dba24 100644 --- a/exp_legacy/module/config/deconlog.lua +++ b/exp_legacy/module/config/deconlog.lua @@ -2,10 +2,10 @@ -- @config Deconlog return { - decon_area = true, ---@setting decon_area whether to log when an area is being deconstructed - built_entity = true, ---@setting built_entity whether to log when an entity is built - mined_entity = true, ---@setting mined_entity whether to log when an entity is mined - fired_rocket = true, ---@setting fired_nuke whether to log when a rocket is fired - fired_explosive_rocket = true, ---@setting fired_nuke whether to log when a explosive rocket is fired - fired_nuke = true, ---@setting fired_nuke whether to log when a nuke is fired + decon_area = true, --- @setting decon_area whether to log when an area is being deconstructed + built_entity = true, --- @setting built_entity whether to log when an entity is built + mined_entity = true, --- @setting mined_entity whether to log when an entity is mined + fired_rocket = true, --- @setting fired_nuke whether to log when a rocket is fired + fired_explosive_rocket = true, --- @setting fired_nuke whether to log when a explosive rocket is fired + fired_nuke = true, --- @setting fired_nuke whether to log when a nuke is fired } diff --git a/exp_legacy/module/config/discord_alerts.lua b/exp_legacy/module/config/discord_alerts.lua index 2a5a7537..11dfb6a8 100644 --- a/exp_legacy/module/config/discord_alerts.lua +++ b/exp_legacy/module/config/discord_alerts.lua @@ -2,24 +2,24 @@ -- @config Discord-Alerts return { - show_playtime=true, - entity_protection=true, - player_reports=true, - player_warnings=true, - player_bans=true, - player_mutes=true, - player_kicks=true, - player_promotes=false, - player_jail=true, - ['config']=true, - ['purge']=true, - ['c']=true, - ['command']=true, - ['silent-command']=true, - ['measured-command']=true, - ['banlist']=true, - ['permissions']=true, - ['editor']=true, - ['cheat']=true, - ['open']=false -} \ No newline at end of file + show_playtime = true, + entity_protection = true, + player_reports = true, + player_warnings = true, + player_bans = true, + player_mutes = true, + player_kicks = true, + player_promotes = false, + player_jail = true, + ["config"] = true, + ["purge"] = true, + ["c"] = true, + ["command"] = true, + ["silent-command"] = true, + ["measured-command"] = true, + ["banlist"] = true, + ["permissions"] = true, + ["editor"] = true, + ["cheat"] = true, + ["open"] = false, +} diff --git a/exp_legacy/module/config/expcore/command_auth_admin.lua b/exp_legacy/module/config/expcore/command_auth_admin.lua index 65fa57bb..be582f44 100644 --- a/exp_legacy/module/config/expcore/command_auth_admin.lua +++ b/exp_legacy/module/config/expcore/command_auth_admin.lua @@ -11,9 +11,9 @@ Commands.add_authenticator(function(player, command, tags, reject) if player.admin then return true else - return reject{'command-auth.admin-only'} + return reject{ "command-auth.admin-only" } end else return true end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/config/expcore/command_auth_roles.lua b/exp_legacy/module/config/expcore/command_auth_roles.lua index 9c792ab5..388c6e18 100644 --- a/exp_legacy/module/config/expcore/command_auth_roles.lua +++ b/exp_legacy/module/config/expcore/command_auth_roles.lua @@ -6,9 +6,9 @@ local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles -- luacheck:ignore 212/tags Commands.add_authenticator(function(player, command, tags, reject) - if Roles.player_allowed(player,'command/'..command) then + if Roles.player_allowed(player, "command/" .. command) then return true else return reject() end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/config/expcore/command_color_parse.lua b/exp_legacy/module/config/expcore/command_color_parse.lua index 5c55e6bd..0066c3d6 100644 --- a/exp_legacy/module/config/expcore/command_color_parse.lua +++ b/exp_legacy/module/config/expcore/command_color_parse.lua @@ -4,12 +4,12 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands local Colours = require("modules/exp_util/include/color") -Commands.add_parse('color',function(input, _, reject) +Commands.add_parse("color", function(input, _, reject) if not input then return end local color = Colours[input] if not color then - return reject{'expcore-commands.reject-color'} + return reject{ "expcore-commands.reject-color" } else return input end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/config/expcore/command_general_parse.lua b/exp_legacy/module/config/expcore/command_general_parse.lua index 42568b5b..0eded247 100644 --- a/exp_legacy/module/config/expcore/command_general_parse.lua +++ b/exp_legacy/module/config/expcore/command_general_parse.lua @@ -22,121 +22,121 @@ see ./expcore/commands.lua for more details local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands -- luacheck:ignore 212/player -Commands.add_parse('boolean',function(input, player) +Commands.add_parse("boolean", function(input, player) if not input then return end -- nil check input = input:lower() - if input == 'yes' - or input == 'y' - or input == 'true' - or input == '1' then + if input == "yes" + or input == "y" + or input == "true" + or input == "1" then return true else return false end end) -Commands.add_parse('string-options',function(input, player, reject, options) +Commands.add_parse("string-options", function(input, player, reject, options) if not input then return end -- nil check local option = _C.auto_complete(options, input) - return option or reject{'expcore-commands.reject-string-options', table.concat(options, ', ')} + return option or reject{ "expcore-commands.reject-string-options", table.concat(options, ", ") } end) -Commands.add_parse('string-max-length',function(input, player, reject, max_length) +Commands.add_parse("string-max-length", function(input, player, reject, max_length) if not input then return end -- nil check local length = input:len() if length > max_length then - return reject{'expcore-commands.reject-string-max-length',max_length} + return reject{ "expcore-commands.reject-string-max-length", max_length } else return input end end) -Commands.add_parse('number',function(input, player, reject) +Commands.add_parse("number", function(input, player, reject) if not input then return end -- nil check local number = tonumber(input) if not number then - return reject{'expcore-commands.reject-number'} + return reject{ "expcore-commands.reject-number" } else return number end end) -Commands.add_parse('integer',function(input, player, reject) +Commands.add_parse("integer", function(input, player, reject) if not input then return end -- nil check local number = tonumber(input) if not number then - return reject{'expcore-commands.reject-number'} + return reject{ "expcore-commands.reject-number" } else return math.floor(number) end end) -Commands.add_parse('number-range',function(input, player, reject, range_min, range_max) - local number = Commands.parse('number',input, player, reject) +Commands.add_parse("number-range", function(input, player, reject, range_min, range_max) + local number = Commands.parse("number", input, player, reject) if not number then return end -- nil check if number < range_min or number > range_max then - return reject{'expcore-commands.reject-number-range',range_min, range_max} + return reject{ "expcore-commands.reject-number-range", range_min, range_max } else return number end end) -Commands.add_parse('integer-range',function(input, player, reject, range_min, range_max) - local number = Commands.parse('integer',input, player, reject) +Commands.add_parse("integer-range", function(input, player, reject, range_min, range_max) + local number = Commands.parse("integer", input, player, reject) if not number then return end -- nil check if number < range_min or number > range_max then - return reject{'expcore-commands.reject-number-range',range_min, range_max} + return reject{ "expcore-commands.reject-number-range", range_min, range_max } else return number end end) -Commands.add_parse('player',function(input, player, reject) +Commands.add_parse("player", function(input, player, reject) if not input then return end -- nil check local input_player = game.players[input] if not input_player then - return reject{'expcore-commands.reject-player',input} + return reject{ "expcore-commands.reject-player", input } else return input_player end end) -Commands.add_parse('player-online',function(input, player, reject) - local input_player = Commands.parse('player',input, player, reject) +Commands.add_parse("player-online", function(input, player, reject) + local input_player = Commands.parse("player", input, player, reject) if not input_player then return end -- nil check if not input_player.connected then - return reject{'expcore-commands.reject-player-online'} + return reject{ "expcore-commands.reject-player-online" } else return input_player end end) -Commands.add_parse('player-alive',function(input, player, reject) - local input_player = Commands.parse('player-online',input, player, reject) +Commands.add_parse("player-alive", function(input, player, reject) + local input_player = Commands.parse("player-online", input, player, reject) if not input_player then return end -- nil check if not input_player.character or not input_player.character.health or input_player.character.health <= 0 then - return reject{'expcore-commands.reject-player-alive'} + return reject{ "expcore-commands.reject-player-alive" } else return input_player end end) -Commands.add_parse('force',function(input, player, reject) +Commands.add_parse("force", function(input, player, reject) if not input then return end -- nil check local force = game.forces[input] if not force then - return reject{'expcore-commands.reject-force'} + return reject{ "expcore-commands.reject-force" } else return force end end) -Commands.add_parse('surface',function(input, player, reject) +Commands.add_parse("surface", function(input, player, reject) if not input then return end local surface = game.surfaces[input] if not surface then - return reject{'expcore-commands.reject-surface'} + return reject{ "expcore-commands.reject-surface" } else return surface end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/config/expcore/command_role_parse.lua b/exp_legacy/module/config/expcore/command_role_parse.lua index 0e6adee2..ce23f053 100644 --- a/exp_legacy/module/config/expcore/command_role_parse.lua +++ b/exp_legacy/module/config/expcore/command_role_parse.lua @@ -13,42 +13,43 @@ local auto_complete = _C.auto_complete --- @dep expcore.common require("modules.exp_legacy.config.expcore.command_general_parse") -- luacheck:ignore 212/player -Commands.add_parse('role',function(input, player, reject) +Commands.add_parse("role", function(input, player, reject) if not input then return end local roles = Roles.config.order local rev_roles = {} - for i=#roles, 1,-1 do + for i = #roles, 1, -1 do table.insert(rev_roles, roles[i]) end + local role = auto_complete(rev_roles, input) role = Roles.get_role_by_name(role) if not role then - return reject{'expcore-role.reject-role'} + return reject{ "expcore-role.reject-role" } else return role end end) -Commands.add_parse('player-role',function(input, player, reject) - local input_player = Commands.parse('player',input, player, reject) +Commands.add_parse("player-role", function(input, player, reject) + local input_player = Commands.parse("player", input, player, reject) if not input_player then return end -- nil check local player_highest = Roles.get_player_highest_role(player) local input_player_highest = Roles.get_player_highest_role(input_player) if player_highest.index < input_player_highest.index then return input_player else - return reject{'expcore-roles.reject-player-role'} + return reject{ "expcore-roles.reject-player-role" } end end) -Commands.add_parse('player-role-online',function(input, player, reject) - local input_player = Commands.parse('player-role',input, player, reject) +Commands.add_parse("player-role-online", function(input, player, reject) + local input_player = Commands.parse("player-role", input, player, reject) if not input_player then return end -- nil check - return Commands.parse('player-online',input_player.name, player, reject) + return Commands.parse("player-online", input_player.name, player, reject) end) -Commands.add_parse('player-role-alive',function(input, player, reject) - local input_player = Commands.parse('player-role',input, player, reject) +Commands.add_parse("player-role-alive", function(input, player, reject) + local input_player = Commands.parse("player-role", input, player, reject) if not input_player then return end -- nil check - return Commands.parse('player-alive',input_player.name, player, reject) -end) \ No newline at end of file + return Commands.parse("player-alive", input_player.name, player, reject) +end) diff --git a/exp_legacy/module/config/expcore/command_runtime_disable.lua b/exp_legacy/module/config/expcore/command_runtime_disable.lua index 47061dcd..65cec329 100644 --- a/exp_legacy/module/config/expcore/command_runtime_disable.lua +++ b/exp_legacy/module/config/expcore/command_runtime_disable.lua @@ -25,8 +25,8 @@ end -- luacheck:ignore 212/player 212/tags Commands.add_authenticator(function(player, command, tags, reject) if disabled_commands[command] then - return reject{'command-auth.command-disabled'} + return reject{ "command-auth.command-disabled" } else return true end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/config/expcore/permission_groups.lua b/exp_legacy/module/config/expcore/permission_groups.lua index 33779577..3aff936a 100644 --- a/exp_legacy/module/config/expcore/permission_groups.lua +++ b/exp_legacy/module/config/expcore/permission_groups.lua @@ -4,102 +4,102 @@ -- then use :allow{} and :disallow{} to specify certain actions to allow/disallow -- @config Permission-Groups ---local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event +-- local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event local Permission_Groups = require("modules.exp_legacy.expcore.permission_groups") --- @dep expcore.permission_groups -Permission_Groups.new_group('Admin') -:allow_all() -:disallow{ - 'add_permission_group', -- admin - 'delete_permission_group', - 'edit_permission_group', - 'import_permissions_string', - 'map_editor_action', - 'toggle_map_editor', - 'change_multiplayer_config', - 'set_heat_interface_mode', - 'set_heat_interface_temperature', - 'set_infinity_container_filter_item', - 'set_infinity_container_remove_unfiltered_items', - 'set_infinity_pipe_filter' -} +Permission_Groups.new_group("Admin") + :allow_all() + :disallow{ + "add_permission_group", -- admin + "delete_permission_group", + "edit_permission_group", + "import_permissions_string", + "map_editor_action", + "toggle_map_editor", + "change_multiplayer_config", + "set_heat_interface_mode", + "set_heat_interface_temperature", + "set_infinity_container_filter_item", + "set_infinity_container_remove_unfiltered_items", + "set_infinity_pipe_filter", + } -Permission_Groups.new_group('Trusted') -:allow_all() -:disallow{ - 'add_permission_group', -- admin - 'delete_permission_group', - 'edit_permission_group', - 'import_permissions_string', - 'map_editor_action', - 'toggle_map_editor', - 'change_multiplayer_config', - 'set_heat_interface_mode', - 'set_heat_interface_temperature', - 'set_infinity_container_filter_item', - 'set_infinity_container_remove_unfiltered_items', - 'set_infinity_pipe_filter', - 'admin_action' -- trusted -} +Permission_Groups.new_group("Trusted") + :allow_all() + :disallow{ + "add_permission_group", -- admin + "delete_permission_group", + "edit_permission_group", + "import_permissions_string", + "map_editor_action", + "toggle_map_editor", + "change_multiplayer_config", + "set_heat_interface_mode", + "set_heat_interface_temperature", + "set_infinity_container_filter_item", + "set_infinity_container_remove_unfiltered_items", + "set_infinity_pipe_filter", + "admin_action", -- trusted + } -Permission_Groups.new_group('Standard') -:allow_all() -:disallow{ - 'add_permission_group', -- admin - 'delete_permission_group', - 'edit_permission_group', - 'import_permissions_string', - 'map_editor_action', - 'toggle_map_editor', - 'change_multiplayer_config', - 'set_heat_interface_mode', - 'set_heat_interface_temperature', - 'set_infinity_container_filter_item', - 'set_infinity_container_remove_unfiltered_items', - 'set_infinity_pipe_filter', - 'admin_action', -- trusted - 'change_programmable_speaker_alert_parameters', -- standard - 'drop_item', - 'change_rocket_silo_mode' -} +Permission_Groups.new_group("Standard") + :allow_all() + :disallow{ + "add_permission_group", -- admin + "delete_permission_group", + "edit_permission_group", + "import_permissions_string", + "map_editor_action", + "toggle_map_editor", + "change_multiplayer_config", + "set_heat_interface_mode", + "set_heat_interface_temperature", + "set_infinity_container_filter_item", + "set_infinity_container_remove_unfiltered_items", + "set_infinity_pipe_filter", + "admin_action", -- trusted + "change_programmable_speaker_alert_parameters", -- standard + "drop_item", + "change_rocket_silo_mode", + } -Permission_Groups.new_group('Guest') -:allow_all() -:disallow{ - 'add_permission_group', -- admin - 'delete_permission_group', - 'edit_permission_group', - 'import_permissions_string', - 'map_editor_action', - 'toggle_map_editor', - 'change_multiplayer_config', - 'set_heat_interface_mode', - 'set_heat_interface_temperature', - 'set_infinity_container_filter_item', - 'set_infinity_container_remove_unfiltered_items', - 'set_infinity_pipe_filter', - 'admin_action', -- trusted - 'change_programmable_speaker_alert_parameters', -- standard - 'drop_item', - 'change_rocket_silo_mode', - 'change_programmable_speaker_parameters', -- guest - 'change_train_stop_station', - --'deconstruct', - 'remove_cables', - 'remove_train_station', - 'reset_assembling_machine', - 'rotate_entity', - --'use_artillery_remote', -- not in 2.0 - 'launch_rocket', - 'cancel_research', - --'activate_cut', -- not in 2.0 - 'flush_opened_entity_fluid', - 'flush_opened_entity_specific_fluid' -} +Permission_Groups.new_group("Guest") + :allow_all() + :disallow{ + "add_permission_group", -- admin + "delete_permission_group", + "edit_permission_group", + "import_permissions_string", + "map_editor_action", + "toggle_map_editor", + "change_multiplayer_config", + "set_heat_interface_mode", + "set_heat_interface_temperature", + "set_infinity_container_filter_item", + "set_infinity_container_remove_unfiltered_items", + "set_infinity_pipe_filter", + "admin_action", -- trusted + "change_programmable_speaker_alert_parameters", -- standard + "drop_item", + "change_rocket_silo_mode", + "change_programmable_speaker_parameters", -- guest + "change_train_stop_station", + -- 'deconstruct', + "remove_cables", + "remove_train_station", + "reset_assembling_machine", + "rotate_entity", + -- 'use_artillery_remote', -- not in 2.0 + "launch_rocket", + "cancel_research", + -- 'activate_cut', -- not in 2.0 + "flush_opened_entity_fluid", + "flush_opened_entity_specific_fluid", + } -Permission_Groups.new_group('Restricted') -:disallow_all() -:allow('write_to_console') +Permission_Groups.new_group("Restricted") + :disallow_all() + :allow("write_to_console") --[[ These events are used until a role system is added to make it easier for our admins diff --git a/exp_legacy/module/config/expcore/roles.lua b/exp_legacy/module/config/expcore/roles.lua index 9c3a893f..5cdb0ab3 100644 --- a/exp_legacy/module/config/expcore/roles.lua +++ b/exp_legacy/module/config/expcore/roles.lua @@ -6,362 +6,362 @@ local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep ex local Statistics = PlayerData.Statistics --- Role flags that will run when a player changes roles -Roles.define_flag_trigger('is_admin',function(player,state) +Roles.define_flag_trigger("is_admin", function(player, state) player.admin = state end) -Roles.define_flag_trigger('is_spectator',function(player,state) +Roles.define_flag_trigger("is_spectator", function(player, state) player.spectator = state end) -Roles.define_flag_trigger('is_jail',function(player,state) +Roles.define_flag_trigger("is_jail", function(player, state) if player.character then player.character.active = not state end end) --- Admin Roles -Roles.new_role('System','SYS') -:set_permission_group('Default', true) -:set_flag('is_admin') -:set_flag('is_spectator') -:set_flag('report-immune') -:set_flag('instant-respawn') -:set_allow_all() +Roles.new_role("System", "SYS") + :set_permission_group("Default", true) + :set_flag("is_admin") + :set_flag("is_spectator") + :set_flag("report-immune") + :set_flag("instant-respawn") + :set_allow_all() -Roles.new_role('Senior Administrator','SAdmin') -:set_permission_group('Admin') -:set_custom_color{r=233,g=63,b=233} -:set_flag('is_admin') -:set_flag('is_spectator') -:set_flag('report-immune') -:set_flag('instant-respawn') -:set_parent('Administrator') -:allow{ - 'command/interface', - 'command/debug', - 'command/toggle-cheat-mode', - 'command/research-all' -} +Roles.new_role("Senior Administrator", "SAdmin") + :set_permission_group("Admin") + :set_custom_color{ r = 233, g = 63, b = 233 } + :set_flag("is_admin") + :set_flag("is_spectator") + :set_flag("report-immune") + :set_flag("instant-respawn") + :set_parent("Administrator") + :allow{ + "command/interface", + "command/debug", + "command/toggle-cheat-mode", + "command/research-all", + } -Roles.new_role('Administrator','Admin') -:set_permission_group('Admin') -:set_custom_color{r=233,g=63,b=233} -:set_flag('is_admin') -:set_flag('is_spectator') -:set_flag('report-immune') -:set_flag('instant-respawn') -:set_parent('Moderator') -:allow{ - 'gui/warp-list/bypass-proximity', - 'gui/warp-list/bypass-cooldown', - 'command/connect-all', - 'command/collectdata' -} +Roles.new_role("Administrator", "Admin") + :set_permission_group("Admin") + :set_custom_color{ r = 233, g = 63, b = 233 } + :set_flag("is_admin") + :set_flag("is_spectator") + :set_flag("report-immune") + :set_flag("instant-respawn") + :set_parent("Moderator") + :allow{ + "gui/warp-list/bypass-proximity", + "gui/warp-list/bypass-cooldown", + "command/connect-all", + "command/collectdata", + } -Roles.new_role('Moderator','Mod') -:set_permission_group('Admin') -:set_custom_color{r=0,g=170,b=0} -:set_flag('is_admin') -:set_flag('is_spectator') -:set_flag('report-immune') -:set_flag('instant-respawn') -:set_parent('Trainee') -:allow{ - 'command/assign-role', - 'command/unassign-role', - 'command/repair', - 'command/kill/always', - 'command/clear-tag/always', - 'command/go-to-spawn/always', - 'command/clear-reports', - 'command/clear-warnings', - 'command/clear-inventory', - -- 'command/bonus', - 'gui/bonus', - 'command/home', - 'command/home-set', - 'command/home-get', - 'command/return', - 'command/connect-player', - 'gui/rocket-info/toggle-active', - 'gui/rocket-info/remote_launch', - 'command/toggle-friendly-fire', - 'command/toggle-always-day', - 'fast-tree-decon' -} +Roles.new_role("Moderator", "Mod") + :set_permission_group("Admin") + :set_custom_color{ r = 0, g = 170, b = 0 } + :set_flag("is_admin") + :set_flag("is_spectator") + :set_flag("report-immune") + :set_flag("instant-respawn") + :set_parent("Trainee") + :allow{ + "command/assign-role", + "command/unassign-role", + "command/repair", + "command/kill/always", + "command/clear-tag/always", + "command/go-to-spawn/always", + "command/clear-reports", + "command/clear-warnings", + "command/clear-inventory", + -- 'command/bonus', + "gui/bonus", + "command/home", + "command/home-set", + "command/home-get", + "command/return", + "command/connect-player", + "gui/rocket-info/toggle-active", + "gui/rocket-info/remote_launch", + "command/toggle-friendly-fire", + "command/toggle-always-day", + "fast-tree-decon", + } -Roles.new_role('Trainee','TrMod') -:set_permission_group('Admin') -:set_custom_color{r=0,g=170,b=0} -:set_flag('is_admin') -:set_flag('is_spectator') -:set_flag('report-immune') -:set_parent('Veteran') -:allow{ - 'command/admin-chat', - 'command/admin-marker', - 'command/goto', - 'command/teleport', - 'command/bring', - 'command/give-warning', - 'command/get-warnings', - 'command/get-reports', - 'command/protect-entity', - 'command/protect-area', - 'command/jail', - 'command/unjail', - 'command/kick', - 'command/ban', - 'command/spectate', - 'command/follow', - 'command/search', - 'command/search-amount', - 'command/search-recent', - 'command/search-online', - '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' -} +Roles.new_role("Trainee", "TrMod") + :set_permission_group("Admin") + :set_custom_color{ r = 0, g = 170, b = 0 } + :set_flag("is_admin") + :set_flag("is_spectator") + :set_flag("report-immune") + :set_parent("Veteran") + :allow{ + "command/admin-chat", + "command/admin-marker", + "command/goto", + "command/teleport", + "command/bring", + "command/give-warning", + "command/get-warnings", + "command/get-reports", + "command/protect-entity", + "command/protect-area", + "command/jail", + "command/unjail", + "command/kick", + "command/ban", + "command/spectate", + "command/follow", + "command/search", + "command/search-amount", + "command/search-recent", + "command/search-online", + "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", + } --- Trusted Roles -Roles.new_role('Board Member','Board') -:set_permission_group('Trusted') -:set_custom_color{r=247,g=246,b=54} -:set_flag('is_spectator') -:set_flag('report-immune') -:set_flag('instant-respawn') -:set_parent('Sponsor') -:allow{ - 'command/goto', - 'command/repair', - 'command/spectate', - 'command/follow', - 'gui/playerdata' -} +Roles.new_role("Board Member", "Board") + :set_permission_group("Trusted") + :set_custom_color{ r = 247, g = 246, b = 54 } + :set_flag("is_spectator") + :set_flag("report-immune") + :set_flag("instant-respawn") + :set_parent("Sponsor") + :allow{ + "command/goto", + "command/repair", + "command/spectate", + "command/follow", + "gui/playerdata", + } -Roles.new_role('Senior Backer','Backer') -:set_permission_group('Trusted') -:set_custom_color{r=238,g=172,b=44} -:set_flag('is_spectator') -:set_flag('report-immune') -:set_flag('instant-respawn') -:set_parent('Sponsor') -:allow{ -} +Roles.new_role("Senior Backer", "Backer") + :set_permission_group("Trusted") + :set_custom_color{ r = 238, g = 172, b = 44 } + :set_flag("is_spectator") + :set_flag("report-immune") + :set_flag("instant-respawn") + :set_parent("Sponsor") + :allow{ + } -Roles.new_role('Sponsor','Spon') -:set_permission_group('Trusted') -:set_custom_color{r=238,g=172,b=44} -:set_flag('is_spectator') -:set_flag('report-immune') -:set_flag('instant-respawn') -:set_parent('Supporter') -:allow{ - 'gui/rocket-info/toggle-active', - 'gui/rocket-info/remote_launch', - -- 'command/bonus', - 'gui/bonus', - 'command/home', - 'command/home-set', - 'command/home-get', - 'command/return', - 'fast-tree-decon' -} +Roles.new_role("Sponsor", "Spon") + :set_permission_group("Trusted") + :set_custom_color{ r = 238, g = 172, b = 44 } + :set_flag("is_spectator") + :set_flag("report-immune") + :set_flag("instant-respawn") + :set_parent("Supporter") + :allow{ + "gui/rocket-info/toggle-active", + "gui/rocket-info/remote_launch", + -- 'command/bonus', + "gui/bonus", + "command/home", + "command/home-set", + "command/home-get", + "command/return", + "fast-tree-decon", + } -Roles.new_role('Supporter','Sup') -:set_permission_group('Trusted') -:set_custom_color{r=230,g=99,b=34} -:set_flag('is_spectator') -:set_parent('Veteran') -:allow{ - 'command/tag-color', - 'command/jail', - 'command/unjail', - 'command/join-message', - 'command/join-message-clear' -} +Roles.new_role("Supporter", "Sup") + :set_permission_group("Trusted") + :set_custom_color{ r = 230, g = 99, b = 34 } + :set_flag("is_spectator") + :set_parent("Veteran") + :allow{ + "command/tag-color", + "command/jail", + "command/unjail", + "command/join-message", + "command/join-message-clear", + } -Roles.new_role('Partner','Part') -:set_permission_group('Trusted') -:set_custom_color{r=140,g=120,b=200} -:set_flag('is_spectator') -:set_parent('Veteran') -:allow{ - 'command/jail', - 'command/unjail' -} +Roles.new_role("Partner", "Part") + :set_permission_group("Trusted") + :set_custom_color{ r = 140, g = 120, b = 200 } + :set_flag("is_spectator") + :set_parent("Veteran") + :allow{ + "command/jail", + "command/unjail", + } -local hours10, hours250 = 10*216000, 250*60 -Roles.new_role('Veteran','Vet') -:set_permission_group('Trusted') -:set_custom_color{r=140,g=120,b=200} -:set_parent('Member') -:allow{ - 'command/chat-bot', - 'command/last-location' -} -:set_auto_assign_condition(function(player) - if player.online_time >= hours10 then - return true - else - local stats = Statistics:get(player, {}) - local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 - return playTime - afkTime >= hours250 and mapCount >= 25 - end -end) +local hours10, hours250 = 10 * 216000, 250 * 60 +Roles.new_role("Veteran", "Vet") + :set_permission_group("Trusted") + :set_custom_color{ r = 140, g = 120, b = 200 } + :set_parent("Member") + :allow{ + "command/chat-bot", + "command/last-location", + } + :set_auto_assign_condition(function(player) + if player.online_time >= hours10 then + return true + else + local stats = Statistics:get(player, {}) + local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 + return playTime - afkTime >= hours250 and mapCount >= 25 + end + end) --- Standard User Roles -Roles.new_role('Member','Mem') -:set_permission_group('Standard') -:set_custom_color{r=24,g=172,b=188} -:set_flag('deconlog-bypass') -:set_parent('Regular') -:allow{ - 'gui/task-list/add', - 'gui/task-list/edit', - 'gui/warp-list/add', - 'gui/warp-list/edit', - 'command/save-quickbar', - 'gui/vlayer-edit', - 'command/vlayer-info', - 'command/personal-logistic', - 'command/auto-research', - 'command/set-trains-to-automatic', - 'command/lawnmower', - 'command/waterfill', - 'command/artillery-target-remote', - 'command/clear-item-on-ground', - 'command/clear-blueprint', - 'gui/surveillance' -} +Roles.new_role("Member", "Mem") + :set_permission_group("Standard") + :set_custom_color{ r = 24, g = 172, b = 188 } + :set_flag("deconlog-bypass") + :set_parent("Regular") + :allow{ + "gui/task-list/add", + "gui/task-list/edit", + "gui/warp-list/add", + "gui/warp-list/edit", + "command/save-quickbar", + "gui/vlayer-edit", + "command/vlayer-info", + "command/personal-logistic", + "command/auto-research", + "command/set-trains-to-automatic", + "command/lawnmower", + "command/waterfill", + "command/artillery-target-remote", + "command/clear-item-on-ground", + "command/clear-blueprint", + "gui/surveillance", + } -local hours3, hours15 = 3*216000, 15*60 -Roles.new_role('Regular','Reg') -:set_permission_group('Standard') -:set_custom_color{r=79,g=155,b=163} -:set_parent('Guest') -:allow{ - 'command/kill', - 'command/rainbow', - 'command/go-to-spawn', - 'command/me', - 'standard-decon', - 'bypass-entity-protection', - 'bypass-nukeprotect' -} -:set_auto_assign_condition(function(player) - if player.online_time >= hours3 then - return true - else - local stats = Statistics:get(player, {}) - local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 - return playTime - afkTime >= hours15 and mapCount >= 5 - end -end) +local hours3, hours15 = 3 * 216000, 15 * 60 +Roles.new_role("Regular", "Reg") + :set_permission_group("Standard") + :set_custom_color{ r = 79, g = 155, b = 163 } + :set_parent("Guest") + :allow{ + "command/kill", + "command/rainbow", + "command/go-to-spawn", + "command/me", + "standard-decon", + "bypass-entity-protection", + "bypass-nukeprotect", + } + :set_auto_assign_condition(function(player) + if player.online_time >= hours3 then + return true + else + local stats = Statistics:get(player, {}) + local playTime, afkTime, mapCount = stats.Playtime or 0, stats.AfkTime or 0, stats.MapsPlayed or 0 + return playTime - afkTime >= hours15 and mapCount >= 5 + end + end) --- Guest/Default role -local default = Roles.new_role('Guest','') -:set_permission_group('Guest') -:set_custom_color{r=185,g=187,b=160} -:allow{ - 'command/tag', - 'command/tag-clear', - 'command/search-help', - 'command/list-roles', - 'command/find-on-map', - 'command/report', - 'command/ratio', - 'command/server-ups', - 'command/save-data', - 'command/preference', - 'command/set-preference', - 'command/connect', - 'gui/player-list', - 'gui/rocket-info', - 'gui/science-info', - 'gui/task-list', - 'gui/warp-list', - 'gui/readme', - 'gui/vlayer', - 'gui/research', - 'gui/autofill', - 'gui/module', - 'gui/landfill', - 'gui/production' -} +local default = Roles.new_role("Guest", "") + :set_permission_group("Guest") + :set_custom_color{ r = 185, g = 187, b = 160 } + :allow{ + "command/tag", + "command/tag-clear", + "command/search-help", + "command/list-roles", + "command/find-on-map", + "command/report", + "command/ratio", + "command/server-ups", + "command/save-data", + "command/preference", + "command/set-preference", + "command/connect", + "gui/player-list", + "gui/rocket-info", + "gui/science-info", + "gui/task-list", + "gui/warp-list", + "gui/readme", + "gui/vlayer", + "gui/research", + "gui/autofill", + "gui/module", + "gui/landfill", + "gui/production", + } --- Jail role -Roles.new_role('Jail') -:set_permission_group('Restricted') -:set_custom_color{r=50,g=50,b=50} -:set_block_auto_assign(true) -:set_flag('defer_role_changes') -:disallow(default.allowed) +Roles.new_role("Jail") + :set_permission_group("Restricted") + :set_custom_color{ r = 50, g = 50, b = 50 } + :set_block_auto_assign(true) + :set_flag("defer_role_changes") + :disallow(default.allowed) --- System defaults which are required to be set -Roles.set_root('System') -Roles.set_default('Guest') +Roles.set_root("System") +Roles.set_default("Guest") Roles.define_role_order{ - 'System', -- Best to keep root at top - 'Senior Administrator', - 'Administrator', - 'Moderator', - 'Trainee', - 'Board Member', - 'Senior Backer', - 'Sponsor', - 'Supporter', - 'Partner', - 'Veteran', - 'Member', - 'Regular', - 'Jail', - 'Guest' -- Default must be last if you want to apply restrictions to other roles + "System", -- Best to keep root at top + "Senior Administrator", + "Administrator", + "Moderator", + "Trainee", + "Board Member", + "Senior Backer", + "Sponsor", + "Supporter", + "Partner", + "Veteran", + "Member", + "Regular", + "Jail", + "Guest", -- Default must be last if you want to apply restrictions to other roles } Roles.override_player_roles{ - ['PHIDIAS0303']={'Moderator', 'Board Member', 'Member'}, - ['aldldl']={'Administrator', 'Moderator','Member'}, - ['arty714']={'Senior Administrator', 'Moderator', 'Member'}, - ['Cooldude2606']={'Senior Administrator', 'Moderator', 'Member'}, - ['Drahc_pro']={'Administrator', 'Moderator', 'Member'}, - ['mark9064']={'Administrator', 'Moderator','Member'}, - ['7h3w1z4rd']={'Moderator','Member'}, - ['FlipHalfling90']={'Moderator','Member'}, - ['hamsterbryan']={'Moderator','Member'}, - ['HunterOfGames']={'Moderator','Member'}, - ['NextIdea']={'Moderator','Member'}, - ['TheKernel32']={'Moderator','Member'}, - ['TheKernel64']={'Moderator','Member'}, - ['tovernaar123']={'Moderator','Member'}, - ['UUBlueFire']={'Moderator','Member'}, - ['AssemblyStorm']={'Moderator', 'Member'}, - ['banakeg']={'Moderator','Member'}, - ['connormkii']={'Moderator', 'Member'}, - ['cydes']={'Moderator','Member'}, - ['darklich14']={'Moderator','Member'}, - ['facere']={'Moderator','Member'}, - ['freek18']={'Moderator','Member'}, - ['Gizan']={'Moderator','Member'}, - ['LoicB']={'Moderator','Member'}, - ['M74132']={'Moderator','Member'}, - ['mafisch3']={'Moderator','Member'}, - ['maplesyrup01']={'Moderator','Member'}, - ['ookl']={'Moderator','Member'}, - ['Phoenix27833']={'Moderator','Member'}, - ['porelos']={'Moderator','Member'}, - ['Ruuyji']={'Moderator','Member'}, - ['samy115']={'Moderator','Member'}, - ['SilentLog']={'Moderator','Member'}, - ['Tcheko']={'Moderator','Member'}, - ['thadius856']={'Moderator','Member'}, - ['whoami32']={'Moderator','Member'}, - ['Windbomb']={'Moderator','Member'}, - ['XenoCyber']={'Moderator','Member'} + ["PHIDIAS0303"] = { "Moderator", "Board Member", "Member" }, + ["aldldl"] = { "Administrator", "Moderator", "Member" }, + ["arty714"] = { "Senior Administrator", "Moderator", "Member" }, + ["Cooldude2606"] = { "Senior Administrator", "Moderator", "Member" }, + ["Drahc_pro"] = { "Administrator", "Moderator", "Member" }, + ["mark9064"] = { "Administrator", "Moderator", "Member" }, + ["7h3w1z4rd"] = { "Moderator", "Member" }, + ["FlipHalfling90"] = { "Moderator", "Member" }, + ["hamsterbryan"] = { "Moderator", "Member" }, + ["HunterOfGames"] = { "Moderator", "Member" }, + ["NextIdea"] = { "Moderator", "Member" }, + ["TheKernel32"] = { "Moderator", "Member" }, + ["TheKernel64"] = { "Moderator", "Member" }, + ["tovernaar123"] = { "Moderator", "Member" }, + ["UUBlueFire"] = { "Moderator", "Member" }, + ["AssemblyStorm"] = { "Moderator", "Member" }, + ["banakeg"] = { "Moderator", "Member" }, + ["connormkii"] = { "Moderator", "Member" }, + ["cydes"] = { "Moderator", "Member" }, + ["darklich14"] = { "Moderator", "Member" }, + ["facere"] = { "Moderator", "Member" }, + ["freek18"] = { "Moderator", "Member" }, + ["Gizan"] = { "Moderator", "Member" }, + ["LoicB"] = { "Moderator", "Member" }, + ["M74132"] = { "Moderator", "Member" }, + ["mafisch3"] = { "Moderator", "Member" }, + ["maplesyrup01"] = { "Moderator", "Member" }, + ["ookl"] = { "Moderator", "Member" }, + ["Phoenix27833"] = { "Moderator", "Member" }, + ["porelos"] = { "Moderator", "Member" }, + ["Ruuyji"] = { "Moderator", "Member" }, + ["samy115"] = { "Moderator", "Member" }, + ["SilentLog"] = { "Moderator", "Member" }, + ["Tcheko"] = { "Moderator", "Member" }, + ["thadius856"] = { "Moderator", "Member" }, + ["whoami32"] = { "Moderator", "Member" }, + ["Windbomb"] = { "Moderator", "Member" }, + ["XenoCyber"] = { "Moderator", "Member" }, } diff --git a/exp_legacy/module/config/graftorio.lua b/exp_legacy/module/config/graftorio.lua index f42f1929..9848a1ca 100644 --- a/exp_legacy/module/config/graftorio.lua +++ b/exp_legacy/module/config/graftorio.lua @@ -1,7 +1,7 @@ return { - modules = { - ["forcestats"] = true, - ["logistorage"] = false, - ["other"] = true, - } + modules = { + ["forcestats"] = true, + ["logistorage"] = false, + ["other"] = true, + }, } diff --git a/exp_legacy/module/config/gui/autofill.lua b/exp_legacy/module/config/gui/autofill.lua index 1f69dc53..e20e1ee3 100644 --- a/exp_legacy/module/config/gui/autofill.lua +++ b/exp_legacy/module/config/gui/autofill.lua @@ -4,109 +4,110 @@ local table = require("modules.exp_legacy.overrides.table") -- @dep overrides.table local config = { - -- General config - icon = 'item/piercing-rounds-magazine', -- @setting icon that will be used for the toolbar - categories = { - ammo = 'ammo', - fuel = 'fuel', - shell = 'shell' - }, - entities = { - car = 'car', - tank = 'tank', - spidertron = 'spidertron', - locomotive = 'locomotive', - gun_turret = 'gun-turret', - burner_mining_drill = 'burner-mining-drill', - stone_furnace = 'stone-furnace', - steel_furnace = 'steel-furnace' - }, - default_entities = {} + -- General config + icon = "item/piercing-rounds-magazine", -- @setting icon that will be used for the toolbar + categories = { + ammo = "ammo", + fuel = "fuel", + shell = "shell", + }, + entities = { + car = "car", + tank = "tank", + spidertron = "spidertron", + locomotive = "locomotive", + gun_turret = "gun-turret", + burner_mining_drill = "burner-mining-drill", + stone_furnace = "stone-furnace", + steel_furnace = "steel-furnace", + }, + default_entities = {}, } local default_categories = { - { - category = config.categories.ammo, - entity = {config.entities.car, config.entities.tank, config.entities.gun_turret}, - inv = {defines.inventory.car_ammo, defines.inventory.turret_ammo}, - items = { - { name = 'uranium-rounds-magazine', amount = 10, enabled = false }, - { name = 'piercing-rounds-magazine', amount = 10, enabled = false }, - { name = 'firearm-magazine', amount = 10, enabled = false }, - } - }, - { - category = config.categories.ammo, - entity = {config.entities.tank}, - inv = {defines.inventory.car_ammo}, - items = { - { name = 'flamethrower-ammo', amount = 10, enabled = false }, - } - }, - { - category = config.categories.shell, - entity = {config.entities.tank}, - inv = {defines.inventory.car_ammo}, - items = { - { name = 'cannon-shell', amount = 10, enabled = false }, - { name = 'explosive-cannon-shell', amount = 10, enabled = false }, - { name = 'uranium-cannon-shell', amount = 10, enabled = false }, - { name = 'explosive-uranium-cannon-shell', amount = 10, enabled = false }, - } - }, - { - category = config.categories.ammo, - entity = {config.entities.spidertron}, - inv = {defines.inventory.car_ammo}, - items = { - { name = 'rocket', amount = 10, enabled = false }, - { name = 'explosive-rocket', amount = 10, enabled = false }, - { name = 'atomic-bomb', amount = 10, enabled = false }, - } - }, - { - category = config.categories.fuel, - entity = {config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.burner_mining_drill, config.entities.stone_furnace, config.entities.steel_furnace}, - inv = {defines.inventory.fuel}, - items = { - { name = 'nuclear-fuel', amount = 10, enabled = false }, - { name = 'rocket-fuel', amount = 10, enabled = false }, - { name = 'solid-fuel', amount = 10, enabled = false }, - { name = 'coal', amount = 10, enabled = false }, - } - } + { + category = config.categories.ammo, + entity = { config.entities.car, config.entities.tank, config.entities.gun_turret }, + inv = { defines.inventory.car_ammo, defines.inventory.turret_ammo }, + items = { + { name = "uranium-rounds-magazine", amount = 10, enabled = false }, + { name = "piercing-rounds-magazine", amount = 10, enabled = false }, + { name = "firearm-magazine", amount = 10, enabled = false }, + }, + }, + { + category = config.categories.ammo, + entity = { config.entities.tank }, + inv = { defines.inventory.car_ammo }, + items = { + { name = "flamethrower-ammo", amount = 10, enabled = false }, + }, + }, + { + category = config.categories.shell, + entity = { config.entities.tank }, + inv = { defines.inventory.car_ammo }, + items = { + { name = "cannon-shell", amount = 10, enabled = false }, + { name = "explosive-cannon-shell", amount = 10, enabled = false }, + { name = "uranium-cannon-shell", amount = 10, enabled = false }, + { name = "explosive-uranium-cannon-shell", amount = 10, enabled = false }, + }, + }, + { + category = config.categories.ammo, + entity = { config.entities.spidertron }, + inv = { defines.inventory.car_ammo }, + items = { + { name = "rocket", amount = 10, enabled = false }, + { name = "explosive-rocket", amount = 10, enabled = false }, + { name = "atomic-bomb", amount = 10, enabled = false }, + }, + }, + { + category = config.categories.fuel, + entity = { config.entities.car, config.entities.tank, config.entities.locomotive, config.entities.burner_mining_drill, config.entities.stone_furnace, config.entities.steel_furnace }, + inv = { defines.inventory.fuel }, + items = { + { name = "nuclear-fuel", amount = 10, enabled = false }, + { name = "rocket-fuel", amount = 10, enabled = false }, + { name = "solid-fuel", amount = 10, enabled = false }, + { name = "coal", amount = 10, enabled = false }, + }, + }, } local function get_items_by_inv(entity, inv) - local items = entity.items - for _, category in pairs(default_categories) do - if table.contains(category.entity, entity.entity) then - if table.contains(category.inv, inv) then - for _, item in pairs(category.items) do - items[item.name] = { - entity = entity.entity, - category = category.category, - inv = inv, - name = item.name, - amount = item.amount, - enabled = item.enabled - } - end - end - end - end - return items + local items = entity.items + for _, category in pairs(default_categories) do + if table.contains(category.entity, entity.entity) then + if table.contains(category.inv, inv) then + for _, item in pairs(category.items) do + items[item.name] = { + entity = entity.entity, + category = category.category, + inv = inv, + name = item.name, + amount = item.amount, + enabled = item.enabled, + } + end + end + end + end + + return items end local function generate_default_setting(entity_name, inv, enabled) - if not config.default_entities[entity_name] then - config.default_entities[entity_name] = { - entity = entity_name, - enabled = enabled, - items = {} - } - end - get_items_by_inv(config.default_entities[entity_name], inv) + if not config.default_entities[entity_name] then + config.default_entities[entity_name] = { + entity = entity_name, + enabled = enabled, + items = {}, + } + end + get_items_by_inv(config.default_entities[entity_name], inv) end generate_default_setting(config.entities.car, defines.inventory.fuel, true) @@ -127,4 +128,4 @@ generate_default_setting(config.entities.stone_furnace, defines.inventory.fuel, generate_default_setting(config.entities.steel_furnace, defines.inventory.fuel, true) -return config \ No newline at end of file +return config diff --git a/exp_legacy/module/config/gui/player_list_actions.lua b/exp_legacy/module/config/gui/player_list_actions.lua index e6742dfe..18244240 100644 --- a/exp_legacy/module/config/gui/player_list_actions.lua +++ b/exp_legacy/module/config/gui/player_list_actions.lua @@ -19,7 +19,7 @@ local function set_datastores(player, action) end -- auth that will only allow when on player's of lower roles -local function auth_lower_role(player,selected_player_name) +local function auth_lower_role(player, selected_player_name) local player_highest = Roles.get_player_highest_role(player) local action_player_highest = Roles.get_player_highest_role(selected_player_name) if player_highest.index < action_player_highest.index then @@ -36,170 +36,170 @@ local function get_action_player_name(player) end -- teleports one player to another -local function teleport(from_player,to_player) +local function teleport(from_player, to_player) local surface = to_player.surface - local position = surface.find_non_colliding_position('character',to_player.position,32,1) + local position = surface.find_non_colliding_position("character", to_player.position, 32, 1) if not position then return false end -- return false if no new position if from_player.driving then from_player.driving = false end -- kicks a player out a vehicle if in one - from_player.teleport(position,surface) + from_player.teleport(position, surface) return true end -local function new_button(sprite,tooltip) +local function new_button(sprite, tooltip) return Gui.element{ - type = 'sprite-button', - style = 'tool_button', + type = "sprite-button", + style = "tool_button", sprite = sprite, - tooltip = tooltip + tooltip = tooltip, }:style{ padding = -1, height = 28, - width = 28 + width = 28, } end --- Teleports the user to the action player -- @element goto_player -local goto_player = new_button('utility/export',{'player-list.goto-player'}) -:on_click(function(player) - local selected_player_name = get_action_player_name(player) - local selected_player = game.players[selected_player_name] - if not player.character or not selected_player.character then - player.print({'expcore-commands.reject-player-alive'},Colors.orange_red) - else - teleport(player,selected_player) - end -end) +local goto_player = new_button("utility/export", { "player-list.goto-player" }) + :on_click(function(player) + local selected_player_name = get_action_player_name(player) + local selected_player = game.players[selected_player_name] + if not player.character or not selected_player.character then + player.print({ "expcore-commands.reject-player-alive" }, Colors.orange_red) + else + teleport(player, selected_player) + end + end) --- Teleports the action player to the user -- @element bring_player -local bring_player = new_button('utility/import',{'player-list.bring-player'}) -:on_click(function(player) - local selected_player_name = get_action_player_name(player) - local selected_player = game.players[selected_player_name] - if not player.character or not selected_player.character then - player.print({'expcore-commands.reject-player-alive'},Colors.orange_red) - else - teleport(selected_player,player) - end -end) +local bring_player = new_button("utility/import", { "player-list.bring-player" }) + :on_click(function(player) + local selected_player_name = get_action_player_name(player) + local selected_player = game.players[selected_player_name] + if not player.character or not selected_player.character then + player.print({ "expcore-commands.reject-player-alive" }, Colors.orange_red) + else + teleport(selected_player, player) + end + end) --- Reports the action player, requires a reason to be given -- @element report_player -local report_player = new_button('utility/spawn_flag',{'player-list.report-player'}) -:on_click(function(player) - local selected_player_name = get_action_player_name(player) - if Reports.is_reported(selected_player_name,player.name) then - player.print({'expcom-report.already-reported'},Colors.orange_red) - else - SelectedAction:set(player, 'command/report') - end -end) +local report_player = new_button("utility/spawn_flag", { "player-list.report-player" }) + :on_click(function(player) + local selected_player_name = get_action_player_name(player) + if Reports.is_reported(selected_player_name, player.name) then + player.print({ "expcom-report.already-reported" }, Colors.orange_red) + else + SelectedAction:set(player, "command/report") + end + end) -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 by_player_name_color = format_chat_player_name(player) - game.print{'expcom-report.non-admin', selected_player_color,reason} - Roles.print_to_roles_higher('Trainee',{'expcom-report.admin', selected_player_color,by_player_name_color,reason}) - Reports.report_player(selected_player_name,player.name,reason) + game.print{ "expcom-report.non-admin", selected_player_color, reason } + Roles.print_to_roles_higher("Trainee", { "expcom-report.admin", selected_player_color, by_player_name_color, reason }) + Reports.report_player(selected_player_name, player.name, reason) end --- Gives the action player a warning, requires a reason -- @element warn_player -local warn_player = new_button('utility/spawn_flag',{'player-list.warn-player'}) -:on_click(function(player) - SelectedAction:set(player, 'command/give-warning') -end) +local warn_player = new_button("utility/spawn_flag", { "player-list.warn-player" }) + :on_click(function(player) + SelectedAction:set(player, "command/give-warning") + end) -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 by_player_name_color = format_chat_player_name(player) - game.print{'expcom-warnings.received', selected_player_color,by_player_name_color,reason} - Warnings.add_warning(selected_player_name,player.name,reason) + game.print{ "expcom-warnings.received", selected_player_color, by_player_name_color, reason } + Warnings.add_warning(selected_player_name, player.name, reason) end --- Jails the action player, requires a reason -- @element jail_player -local jail_player = new_button('utility/multiplayer_waiting_icon',{'player-list.jail-player'}) -:on_click(function(player) - local selected_player_name, selected_player_color = get_action_player_name(player) - if Jail.is_jailed(selected_player_name) then - player.print({'expcom-jail.already-jailed', selected_player_color},Colors.orange_red) - else - SelectedAction:set(player, 'command/jail') - end -end) +local jail_player = new_button("utility/multiplayer_waiting_icon", { "player-list.jail-player" }) + :on_click(function(player) + local selected_player_name, selected_player_color = get_action_player_name(player) + if Jail.is_jailed(selected_player_name) then + player.print({ "expcom-jail.already-jailed", selected_player_color }, Colors.orange_red) + else + SelectedAction:set(player, "command/jail") + end + end) -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 by_player_name_color = format_chat_player_name(player) - game.print{'expcom-jail.give', selected_player_color,by_player_name_color,reason} - Jail.jail_player(selected_player_name,player.name,reason) + game.print{ "expcom-jail.give", selected_player_color, by_player_name_color, reason } + Jail.jail_player(selected_player_name, player.name, reason) end --- Kicks the action player, requires a reason -- @element kick_player -local kick_player = new_button('utility/warning_icon',{'player-list.kick-player'}) -:on_click(function(player) - SelectedAction:set(player, 'command/kick') -end) +local kick_player = new_button("utility/warning_icon", { "player-list.kick-player" }) + :on_click(function(player) + SelectedAction:set(player, "command/kick") + end) -local function kick_player_callback(player,reason) +local function kick_player_callback(player, reason) local selected_player = get_action_player_name(player) - game.kick_player(selected_player,reason) + game.kick_player(selected_player, reason) end --- Bans the action player, requires a reason -- @element ban_player -local ban_player = new_button('utility/danger_icon',{'player-list.ban-player'}) -:on_click(function(player) - SelectedAction:set(player, 'command/ban') -end) +local ban_player = new_button("utility/danger_icon", { "player-list.ban-player" }) + :on_click(function(player) + SelectedAction:set(player, "command/ban") + end) -local function ban_player_callback(player,reason) +local function ban_player_callback(player, reason) local selected_player = get_action_player_name(player) - game.ban_player(selected_player,reason) + game.ban_player(selected_player, reason) end return { set_datastores = set_datastores, buttons = { - ['command/teleport'] = { - auth=function(player,selected_player) + ["command/teleport"] = { + auth = function(player, selected_player) return player.name ~= selected_player.name end, -- cant teleport to your self goto_player, - bring_player + bring_player, }, - ['command/report'] = { - auth=function(player,selected_player) + ["command/report"] = { + auth = function(player, selected_player) if player == selected_player then return false end - if not Roles.player_allowed(player,'command/give-warning') then - return not Roles.player_has_flag(selected_player,'report-immune') + if not Roles.player_allowed(player, "command/give-warning") then + return not Roles.player_has_flag(selected_player, "report-immune") end end, -- can report any player that isn't immune and you aren't able to give warnings - reason_callback=report_player_callback, - report_player + reason_callback = report_player_callback, + report_player, }, - ['command/give-warning'] = { - auth=auth_lower_role, -- warn a lower user, replaces report - reason_callback=warn_player_callback, - warn_player + ["command/give-warning"] = { + auth = auth_lower_role, -- warn a lower user, replaces report + reason_callback = warn_player_callback, + warn_player, }, - ['command/jail'] = { - auth=auth_lower_role, - reason_callback=jail_player_callback, - jail_player + ["command/jail"] = { + auth = auth_lower_role, + reason_callback = jail_player_callback, + jail_player, }, - ['command/kick'] = { - auth=auth_lower_role, - reason_callback=kick_player_callback, - kick_player + ["command/kick"] = { + auth = auth_lower_role, + reason_callback = kick_player_callback, + kick_player, }, - ['command/ban'] = { - auth=auth_lower_role, - reason_callback=ban_player_callback, - ban_player - } - } -} \ No newline at end of file + ["command/ban"] = { + auth = auth_lower_role, + reason_callback = ban_player_callback, + ban_player, + }, + }, +} diff --git a/exp_legacy/module/config/gui/rockets.lua b/exp_legacy/module/config/gui/rockets.lua index 00432a9d..2d90778d 100644 --- a/exp_legacy/module/config/gui/rockets.lua +++ b/exp_legacy/module/config/gui/rockets.lua @@ -3,33 +3,45 @@ return { stats = { --- @setting stats The data that will show in the stats section - show_stats=true, --- @setting show_stats false will hide this section all together + show_stats = true, --- @setting show_stats false will hide this section all together show_first_rocket = true, --- @setting show_first_rocket false will not show when the first rocket was launched show_last_rocket = true, --- @setting show_last_rocket false will not show when the last rocket was launched show_fastest_rocket = true, --- @setting show_fastest_rocket false will not show the time taken for the fastest rocket show_total_rockets = true, --- @setting show_total_rockets false will not show the total number of rockets launched show_game_avg = true, --- @setting show_game_avg false will hide the avg across the entire map time rolling_avg = { --- @setting rolling_avg each number will be one statistic; 5 means the avg time taken for the last 5 rockets - 5,10,25 - } + 5, 10, 25, + }, }, milestones = { --- @setting milestones each number will be one statistic; 5 means the time that the 5th rocket was launched - show_milestones=true, --- @setting show_milestones false will hide this section all together - 1,2,5, - 10,20,50, - 100,200,500, - 1000,1500,2000,2500, - 3000,3500,4000,4500, - 5000 + show_milestones = true, --- @setting show_milestones false will hide this section all together + 1, + 2, + 5, + 10, + 20, + 50, + 100, + 200, + 500, + 1000, + 1500, + 2000, + 2500, + 3000, + 3500, + 4000, + 4500, + 5000, }, progress = { --- @setting progress The data and buttons in the build progress section show_progress = true, --- @setting show_progress false will hide this section altogether allow_zoom_to_map = true, --- @setting allow_zoom_to_map false will disable the zoom to map feature allow_remote_launch = true, --- @setting allow_remote_launch false removes the remote launch button for all players remote_launch_admins_only = false, --- @setting remote_launch_admins_only true will remove the remote launch button for all non (game) admins - remote_launch_role_permission = 'gui/rocket-info/remote_launch', --- @setting remote_launch_role_permission value used by custom permission system to allow or disallow the button + remote_launch_role_permission = "gui/rocket-info/remote_launch", --- @setting remote_launch_role_permission value used by custom permission system to allow or disallow the button allow_toggle_active = true, --- @setting allow_toggle_active false removes the remote toggle auto launch button for all players toggle_active_admins_only = false, --- @setting toggle_active_admins_only true will remove the toggle auto launch button for all non (game) admins - toggle_active_role_permission = 'gui/rocket-info/toggle-active' --- @setting toggle_active_role_permission value used by custom permission system to allow or disallow the button - } -} \ No newline at end of file + toggle_active_role_permission = "gui/rocket-info/toggle-active", --- @setting toggle_active_role_permission value used by custom permission system to allow or disallow the button + }, +} diff --git a/exp_legacy/module/config/gui/science.lua b/exp_legacy/module/config/gui/science.lua index 6c5ce3cb..572de9d2 100644 --- a/exp_legacy/module/config/gui/science.lua +++ b/exp_legacy/module/config/gui/science.lua @@ -6,11 +6,11 @@ return { show_eta = true, --- @setting show_eta when true the eta for research completion will be shown color_cutoff = 0.8, --- @setting color_cutoff the amount that production can fall before the text changes color color_flux = 0.1, --- @setting color_flux the amount of fluctuation allowed in production before the icon changes color - 'automation-science-pack', - 'logistic-science-pack', - 'military-science-pack', - 'chemical-science-pack', - 'production-science-pack', - 'utility-science-pack', - 'space-science-pack', -} \ No newline at end of file + "automation-science-pack", + "logistic-science-pack", + "military-science-pack", + "chemical-science-pack", + "production-science-pack", + "utility-science-pack", + "space-science-pack", +} diff --git a/exp_legacy/module/config/gui/tasks.lua b/exp_legacy/module/config/gui/tasks.lua index f7968e8e..91f6bdcd 100644 --- a/exp_legacy/module/config/gui/tasks.lua +++ b/exp_legacy/module/config/gui/tasks.lua @@ -3,11 +3,11 @@ return { -- Adding tasks - allow_add_task = 'all', --- @setting allow_add_task dictates who is allowed to add new tasks; values: all, admin, expcore.roles, none - expcore_roles_allow_add_task = 'gui/task-list/add', --- @setting expcore_roles_allow_add_task if expcore.roles is used then this is the required permission + allow_add_task = "all", --- @setting allow_add_task dictates who is allowed to add new tasks; values: all, admin, expcore.roles, none + expcore_roles_allow_add_task = "gui/task-list/add", --- @setting expcore_roles_allow_add_task if expcore.roles is used then this is the required permission -- Editing tasks - allow_edit_task = 'expcore.roles', --- @setting allow_edit_task dictates who is allowed to edit existing tasks; values: all, admin, expcore.roles, none - expcore_roles_allow_edit_task = 'gui/task-list/edit', --- @setting expcore_roles_allow_edit_task if expcore.roles is used then this is the required permission - user_can_edit_own_tasks = true --- @settings if true then the user who made the task can edit it regardless of the allow_edit_task setting -} \ No newline at end of file + allow_edit_task = "expcore.roles", --- @setting allow_edit_task dictates who is allowed to edit existing tasks; values: all, admin, expcore.roles, none + expcore_roles_allow_edit_task = "gui/task-list/edit", --- @setting expcore_roles_allow_edit_task if expcore.roles is used then this is the required permission + user_can_edit_own_tasks = true, --- @settings if true then the user who made the task can edit it regardless of the allow_edit_task setting +} diff --git a/exp_legacy/module/config/gui/warps.lua b/exp_legacy/module/config/gui/warps.lua index 21bd770b..af1a8bab 100644 --- a/exp_legacy/module/config/gui/warps.lua +++ b/exp_legacy/module/config/gui/warps.lua @@ -5,48 +5,48 @@ return { -- General config update_smoothing = 10, --- @setting update_smoothing the amount of smoothing applied to updates to the cooldown timer, higher is better, max is 60 minimum_distance = 100, --- @setting minimum_distance the minimum distance that is allowed between warps on the same force - default_icon = {type = 'item', name = 'discharge-defense-equipment'}, --- @setting default_icon the default icon that will be used for warps + default_icon = { type = "item", name = "discharge-defense-equipment" }, --- @setting default_icon the default icon that will be used for warps -- Warp cooldowns - bypass_warp_cooldown = 'expcore.roles', --- @setting bypass_warp_cooldown dictates who the warp cooldown is applied to; values: all, admin, expcore.roles, none - expcore_roles_bypass_warp_cooldown = 'gui/warp-list/bypass-cooldown', --- @setting expcore_roles_bypass_warp_cooldown if expcore.roles is used then this is the required permission + bypass_warp_cooldown = "expcore.roles", --- @setting bypass_warp_cooldown dictates who the warp cooldown is applied to; values: all, admin, expcore.roles, none + expcore_roles_bypass_warp_cooldown = "gui/warp-list/bypass-cooldown", --- @setting expcore_roles_bypass_warp_cooldown if expcore.roles is used then this is the required permission cooldown_duration = 60, --- @setting cooldown_duration the duration of the warp cooldown in seconds -- Warp proximity - bypass_warp_proximity = 'expcore.roles', --- @setting bypass_warp_proximity dictates who the warp proximity is applied to; values: all, admin, expcore.roles, none - expcore_roles_bypass_warp_proximity = 'gui/warp-list/bypass-proximity', --- @setting expcore_roles_bypass_warp_proximity if expcore.roles is used then this is the required permission + bypass_warp_proximity = "expcore.roles", --- @setting bypass_warp_proximity dictates who the warp proximity is applied to; values: all, admin, expcore.roles, none + expcore_roles_bypass_warp_proximity = "gui/warp-list/bypass-proximity", --- @setting expcore_roles_bypass_warp_proximity if expcore.roles is used then this is the required permission standard_proximity_radius = 4, --- @setting standard_proximity_radius the minimum distance a player is allowed to be to a warp in order to use it spawn_proximity_radius = 20, --- @setting spawn_proximity_radius the minimum distance a player is allowed to be from they spawn point to use warps -- Adding warps - allow_add_warp = 'expcore.roles', --- @setting allow_add_warp dictates who is allowed to add warps; values: all, admin, expcore.roles, none - expcore_roles_allow_add_warp = 'gui/warp-list/add', --- @setting expcore_roles_allow_add_warp if expcore.roles is used then this is the required permission + allow_add_warp = "expcore.roles", --- @setting allow_add_warp dictates who is allowed to add warps; values: all, admin, expcore.roles, none + expcore_roles_allow_add_warp = "gui/warp-list/add", --- @setting expcore_roles_allow_add_warp if expcore.roles is used then this is the required permission -- Editing warps - allow_edit_warp = 'expcore.roles', --- @setting allow_edit_warp dictates who is allowed to edit warps; values: all, admin, expcore.roles, none - expcore_roles_allow_edit_warp = 'gui/warp-list/edit', --- @setting expcore_roles_allow_edit_warp if expcore.roles is used then this is the required permission + allow_edit_warp = "expcore.roles", --- @setting allow_edit_warp dictates who is allowed to edit warps; values: all, admin, expcore.roles, none + expcore_roles_allow_edit_warp = "gui/warp-list/edit", --- @setting expcore_roles_allow_edit_warp if expcore.roles is used then this is the required permission user_can_edit_own_warps = false, --- @settings user_can_edit_own_warps if true then the user who made the warp can edit it regardless of the allow_edit_warp setting -- Warp area generation entities = { --- @setting entities The entities which are created for warp areas - {'small-lamp', -4, -2}, {'small-lamp', -2, -4}, {'medium-electric-pole',-3,-3}, -- Top left corner - {'small-lamp', 3, -2}, {'small-lamp', 1, -4}, {'medium-electric-pole',2,-3}, -- Top right corner - {'small-lamp', 3, 1}, {'small-lamp', 1, 3}, {'medium-electric-pole',2,2}, -- Bottom right corner - {'small-lamp', -4, 1}, {'small-lamp', -2, 3}, {'medium-electric-pole',-3,2}, -- Bottom left corner + { "small-lamp", -4, -2 }, { "small-lamp", -2, -4 }, { "medium-electric-pole", -3, -3 }, -- Top left corner + { "small-lamp", 3, -2 }, { "small-lamp", 1, -4 }, { "medium-electric-pole", 2, -3 }, -- Top right corner + { "small-lamp", 3, 1 }, { "small-lamp", 1, 3 }, { "medium-electric-pole", 2, 2 }, -- Bottom right corner + { "small-lamp", -4, 1 }, { "small-lamp", -2, 3 }, { "medium-electric-pole", -3, 2 }, -- Bottom left corner }, tiles = { --- @setting tiles The tiles which are created for warp areas - {'black-refined-concrete',-4,-2}, {'black-refined-concrete',-4,-1}, {'black-refined-concrete',-4,0}, {'black-refined-concrete',-4,1}, - {'black-refined-concrete',-3,-3}, {'purple-refined-concrete',-3,-2}, {'purple-refined-concrete',-3,-1}, {'purple-refined-concrete',-3,0}, - {'purple-refined-concrete',-3,1}, {'black-refined-concrete',-3,2}, {'black-refined-concrete',-2,-4}, {'purple-refined-concrete',-2,-3}, - {'purple-refined-concrete',-2,-2}, {'purple-refined-concrete',-2,-1}, {'purple-refined-concrete',-2,0}, {'purple-refined-concrete',-2,1}, - {'purple-refined-concrete',-2,2}, {'black-refined-concrete',-2,3}, {'black-refined-concrete',-1,-4}, {'purple-refined-concrete',-1,-3}, - {'purple-refined-concrete',-1,-2}, {'purple-refined-concrete',-1,-1}, {'purple-refined-concrete',-1,0}, {'purple-refined-concrete',-1,1}, - {'purple-refined-concrete',-1,2}, {'black-refined-concrete',-1,3}, {'black-refined-concrete',0,-4}, {'purple-refined-concrete',0,-3}, - {'purple-refined-concrete',0,-2}, {'purple-refined-concrete',0,-1}, {'purple-refined-concrete',0,0}, {'purple-refined-concrete',0,1}, - {'purple-refined-concrete',0,2}, {'black-refined-concrete',0,3}, {'black-refined-concrete',1,-4}, {'purple-refined-concrete',1,-3}, - {'purple-refined-concrete',1,-2}, {'purple-refined-concrete',1,-1}, {'purple-refined-concrete',1,0}, {'purple-refined-concrete',1,1}, - {'purple-refined-concrete',1,2}, {'black-refined-concrete',1,3}, {'black-refined-concrete',2,-3}, {'purple-refined-concrete',2,-2}, - {'purple-refined-concrete',2,-1}, {'purple-refined-concrete',2,0}, {'purple-refined-concrete',2,1}, {'black-refined-concrete',2,2}, - {'black-refined-concrete',3,-2}, {'black-refined-concrete',3,-1}, {'black-refined-concrete',3,0}, {'black-refined-concrete',3,1} - } + { "black-refined-concrete", -4, -2 }, { "black-refined-concrete", -4, -1 }, { "black-refined-concrete", -4, 0 }, { "black-refined-concrete", -4, 1 }, + { "black-refined-concrete", -3, -3 }, { "purple-refined-concrete", -3, -2 }, { "purple-refined-concrete", -3, -1 }, { "purple-refined-concrete", -3, 0 }, + { "purple-refined-concrete", -3, 1 }, { "black-refined-concrete", -3, 2 }, { "black-refined-concrete", -2, -4 }, { "purple-refined-concrete", -2, -3 }, + { "purple-refined-concrete", -2, -2 }, { "purple-refined-concrete", -2, -1 }, { "purple-refined-concrete", -2, 0 }, { "purple-refined-concrete", -2, 1 }, + { "purple-refined-concrete", -2, 2 }, { "black-refined-concrete", -2, 3 }, { "black-refined-concrete", -1, -4 }, { "purple-refined-concrete", -1, -3 }, + { "purple-refined-concrete", -1, -2 }, { "purple-refined-concrete", -1, -1 }, { "purple-refined-concrete", -1, 0 }, { "purple-refined-concrete", -1, 1 }, + { "purple-refined-concrete", -1, 2 }, { "black-refined-concrete", -1, 3 }, { "black-refined-concrete", 0, -4 }, { "purple-refined-concrete", 0, -3 }, + { "purple-refined-concrete", 0, -2 }, { "purple-refined-concrete", 0, -1 }, { "purple-refined-concrete", 0, 0 }, { "purple-refined-concrete", 0, 1 }, + { "purple-refined-concrete", 0, 2 }, { "black-refined-concrete", 0, 3 }, { "black-refined-concrete", 1, -4 }, { "purple-refined-concrete", 1, -3 }, + { "purple-refined-concrete", 1, -2 }, { "purple-refined-concrete", 1, -1 }, { "purple-refined-concrete", 1, 0 }, { "purple-refined-concrete", 1, 1 }, + { "purple-refined-concrete", 1, 2 }, { "black-refined-concrete", 1, 3 }, { "black-refined-concrete", 2, -3 }, { "purple-refined-concrete", 2, -2 }, + { "purple-refined-concrete", 2, -1 }, { "purple-refined-concrete", 2, 0 }, { "purple-refined-concrete", 2, 1 }, { "black-refined-concrete", 2, 2 }, + { "black-refined-concrete", 3, -2 }, { "black-refined-concrete", 3, -1 }, { "black-refined-concrete", 3, 0 }, { "black-refined-concrete", 3, 1 }, + }, } diff --git a/exp_legacy/module/config/inventory_clear.lua b/exp_legacy/module/config/inventory_clear.lua index ece84814..f0f24419 100644 --- a/exp_legacy/module/config/inventory_clear.lua +++ b/exp_legacy/module/config/inventory_clear.lua @@ -5,5 +5,5 @@ local events = defines.events return { events.on_player_banned, events.on_player_kicked, - --events.on_player_left_game -} \ No newline at end of file + -- events.on_player_left_game +} diff --git a/exp_legacy/module/config/join_messages.lua b/exp_legacy/module/config/join_messages.lua index b0226a28..61278a2f 100644 --- a/exp_legacy/module/config/join_messages.lua +++ b/exp_legacy/module/config/join_messages.lua @@ -1,8 +1,8 @@ return { - Cooldude2606 = 'Lua lets you set metatables on numbers, did you know that? Cooldude2606 knows this.', - samy115 = 'Tremble in fear as the banhammer is now here, its owner: samy115', + Cooldude2606 = "Lua lets you set metatables on numbers, did you know that? Cooldude2606 knows this.", + samy115 = "Tremble in fear as the banhammer is now here, its owner: samy115", XenoCyber = '"Fire Fire Fire" oops wrong game, have no fear XenoCyber is here', - HunterOfGames = 'Unable to support HunterOfGames. You must construct additional miners.', + HunterOfGames = "Unable to support HunterOfGames. You must construct additional miners.", ookl = 'ookl says: "Pineapples are amazing, hello everyone!"', - arty714 = 'Arty\'s Potato made it!' -} \ No newline at end of file + arty714 = "Arty\'s Potato made it!", +} diff --git a/exp_legacy/module/config/lawnmower.lua b/exp_legacy/module/config/lawnmower.lua index 80506da0..f31559c8 100644 --- a/exp_legacy/module/config/lawnmower.lua +++ b/exp_legacy/module/config/lawnmower.lua @@ -2,5 +2,5 @@ -- @config lawnmower return { - destroy_decoratives = false + destroy_decoratives = false, } diff --git a/exp_legacy/module/config/logging.lua b/exp_legacy/module/config/logging.lua index 1f3c0f81..73eb688a 100644 --- a/exp_legacy/module/config/logging.lua +++ b/exp_legacy/module/config/logging.lua @@ -2,7 +2,7 @@ -- @config logging return { - file_name = 'log/logging.log', + file_name = "log/logging.log", rocket_launch_display = { [1] = true, [2] = true, @@ -11,20 +11,33 @@ return { [20] = true, [50] = true, [100] = true, - [200] = true + [200] = true, + [500] = true, + [1000] = true, + [2000] = true, + [5000] = true, + [10000] = true, + [20000] = true, + [50000] = true, + [100000] = true, + [200000] = true, + [500000] = true, + [1000000] = true, + [2000000] = true, + [5000000] = true, + [10000000] = true, }, - rocket_launch_display_rate = 500, disconnect_reason = { - [defines.disconnect_reason.quit] = ' left the game', - [defines.disconnect_reason.dropped] = ' was dropped from the game', - [defines.disconnect_reason.reconnect] = ' is reconnecting', - [defines.disconnect_reason.wrong_input] = ' was having a wrong input', - [defines.disconnect_reason.desync_limit_reached] = ' had desync limit reached', - [defines.disconnect_reason.cannot_keep_up] = ' cannot keep up', - [defines.disconnect_reason.afk] = ' was afk', - [defines.disconnect_reason.kicked] = ' was kicked', - [defines.disconnect_reason.kicked_and_deleted] = ' was kicked and deleted', - [defines.disconnect_reason.banned] = ' was banned', - [defines.disconnect_reason.switching_servers] = ' is switching servers' - } + [defines.disconnect_reason.quit] = " left the game", + [defines.disconnect_reason.dropped] = " was dropped from the game", + [defines.disconnect_reason.reconnect] = " is reconnecting", + [defines.disconnect_reason.wrong_input] = " was having a wrong input", + [defines.disconnect_reason.desync_limit_reached] = " had desync limit reached", + [defines.disconnect_reason.cannot_keep_up] = " cannot keep up", + [defines.disconnect_reason.afk] = " was afk", + [defines.disconnect_reason.kicked] = " was kicked", + [defines.disconnect_reason.kicked_and_deleted] = " was kicked and deleted", + [defines.disconnect_reason.banned] = " was banned", + [defines.disconnect_reason.switching_servers] = " is switching servers", + }, } diff --git a/exp_legacy/module/config/miner.lua b/exp_legacy/module/config/miner.lua index 7ee2a3ab..c6fceb31 100644 --- a/exp_legacy/module/config/miner.lua +++ b/exp_legacy/module/config/miner.lua @@ -3,5 +3,5 @@ return { fluid = true, --- @setting fluid When true, checks for for fluid pipes when removing miners - chest = true --- @setting chest When true, checks for for chest when removing miners + chest = true, --- @setting chest When true, checks for for chest when removing miners } diff --git a/exp_legacy/module/config/module.lua b/exp_legacy/module/config/module.lua index 4f9de797..2ca76040 100644 --- a/exp_legacy/module/config/module.lua +++ b/exp_legacy/module/config/module.lua @@ -5,94 +5,94 @@ return { copy_paste_module = true, copy_paste_rotation = false, machine = { - ['electric-mining-drill'] = { - ['module'] = 'effectivity-module', - ['prod'] = true + ["electric-mining-drill"] = { + ["module"] = "effectivity-module", + ["prod"] = true, }, - ['pumpjack'] = { - ['module'] = 'effectivity-module', - ['prod'] = true + ["pumpjack"] = { + ["module"] = "effectivity-module", + ["prod"] = true, }, - ['assembling-machine-2'] = { - ['module'] = 'productivity-module', - ['prod'] = true + ["assembling-machine-2"] = { + ["module"] = "productivity-module", + ["prod"] = true, }, - ['assembling-machine-3'] = { - ['module'] = 'productivity-module-3', - ['prod'] = true + ["assembling-machine-3"] = { + ["module"] = "productivity-module-3", + ["prod"] = true, }, - ['electric-furnace'] = { - ['module'] = 'productivity-module-3', - ['prod'] = true + ["electric-furnace"] = { + ["module"] = "productivity-module-3", + ["prod"] = true, }, - ['beacon'] = { - ['module'] = 'speed-module-3', - ['prod'] = false + ["beacon"] = { + ["module"] = "speed-module-3", + ["prod"] = false, }, - ['oil-refinery'] = { - ['module'] = 'productivity-module-3', - ['prod'] = true + ["oil-refinery"] = { + ["module"] = "productivity-module-3", + ["prod"] = true, }, - ['chemical-plant'] = { - ['module'] = 'productivity-module-3', - ['prod'] = true + ["chemical-plant"] = { + ["module"] = "productivity-module-3", + ["prod"] = true, }, - ['centrifuge'] = { - ['module'] = 'productivity-module-3', - ['prod'] = true + ["centrifuge"] = { + ["module"] = "productivity-module-3", + ["prod"] = true, }, - ['lab'] = { - ['module'] = 'productivity-module-3', - ['prod'] = true + ["lab"] = { + ["module"] = "productivity-module-3", + ["prod"] = true, + }, + ["rocket-silo"] = { + ["module"] = "productivity-module-3", + ["prod"] = true, }, - ['rocket-silo'] = { - ['module'] = 'productivity-module-3', - ['prod'] = true - } }, module_allowed = { - ['advanced-circuit'] = true, - ['automation-science-pack'] = true, - ['battery'] = true, - ['chemical-science-pack'] = true, - ['copper-cable'] = true, - ['copper-plate'] = true, - ['electric-engine-unit'] = true, - ['electronic-circuit'] = true, - ['empty-barrel'] = true, - ['engine-unit'] = true, - ['explosives'] = true, - ['flying-robot-frame'] = true, - ['iron-gear-wheel'] = true, - ['iron-plate'] = true, - ['iron-stick'] = true, - ['logistic-science-pack'] = true, - ['low-density-structure'] = true, - ['lubricant'] = true, - ['military-science-pack'] = true, - ['nuclear-fuel'] = true, - ['plastic-bar'] = true, - ['processing-unit'] = true, - ['production-science-pack'] = true, - ['rocket-control-unit'] = true, - ['rocket-fuel'] = true, - ['rocket-part'] = true, - ['steel-plate'] = true, - ['stone-brick'] = true, - ['sulfur'] = true, - ['sulfuric-acid'] = true, - ['uranium-fuel-cell'] = true, - ['utility-science-pack'] = true, - ['basic-oil-processing'] = true, - ['advanced-oil-processing'] = true, - ['coal-liquefaction'] = true, - ['heavy-oil-cracking'] = true, - ['light-oil-cracking'] = true, - ['solid-fuel-from-light-oil'] = true, - ['solid-fuel-from-petroleum-gas'] = true, - ['solid-fuel-from-heavy-oil'] = true, - ['uranium-processing'] = true, - ['nuclear-fuel-reprocessing'] = true, - ['kovarex-enrichment-process'] = true - } + ["advanced-circuit"] = true, + ["automation-science-pack"] = true, + ["battery"] = true, + ["chemical-science-pack"] = true, + ["copper-cable"] = true, + ["copper-plate"] = true, + ["electric-engine-unit"] = true, + ["electronic-circuit"] = true, + ["empty-barrel"] = true, + ["engine-unit"] = true, + ["explosives"] = true, + ["flying-robot-frame"] = true, + ["iron-gear-wheel"] = true, + ["iron-plate"] = true, + ["iron-stick"] = true, + ["logistic-science-pack"] = true, + ["low-density-structure"] = true, + ["lubricant"] = true, + ["military-science-pack"] = true, + ["nuclear-fuel"] = true, + ["plastic-bar"] = true, + ["processing-unit"] = true, + ["production-science-pack"] = true, + ["rocket-control-unit"] = true, + ["rocket-fuel"] = true, + ["rocket-part"] = true, + ["steel-plate"] = true, + ["stone-brick"] = true, + ["sulfur"] = true, + ["sulfuric-acid"] = true, + ["uranium-fuel-cell"] = true, + ["utility-science-pack"] = true, + ["basic-oil-processing"] = true, + ["advanced-oil-processing"] = true, + ["coal-liquefaction"] = true, + ["heavy-oil-cracking"] = true, + ["light-oil-cracking"] = true, + ["solid-fuel-from-light-oil"] = true, + ["solid-fuel-from-petroleum-gas"] = true, + ["solid-fuel-from-heavy-oil"] = true, + ["uranium-processing"] = true, + ["nuclear-fuel-reprocessing"] = true, + ["kovarex-enrichment-process"] = true, + }, } diff --git a/exp_legacy/module/config/nukeprotect.lua b/exp_legacy/module/config/nukeprotect.lua index ccbeaba7..65af3830 100644 --- a/exp_legacy/module/config/nukeprotect.lua +++ b/exp_legacy/module/config/nukeprotect.lua @@ -1,34 +1,34 @@ return { - inventories = { - { - inventory = defines.inventory.character_ammo, - event = defines.events.on_player_ammo_inventory_changed, - items = { - ["atomic-bomb"] = true - }, - }, - { - inventory = defines.inventory.character_armor, - event = defines.events.on_player_armor_inventory_changed, - items = {}, - }, - { - inventory = defines.inventory.character_guns, - event = defines.events.on_player_gun_inventory_changed, - items = {}, - }, - { - inventory = defines.inventory.character_main, - event = defines.events.on_player_main_inventory_changed, - items = { - ["atomic-bomb"] = true - }, - }, - }, - ignore_permisison = "bypass-nukeprotect", -- @setting ignore_permisison The permission that nukeprotect will ignore - ignore_admins = true, -- @setting ignore_admins Ignore admins, true by default. Allows usage outside of the roles module - disable_nuke_research = false, -- @setting disable_nuke_research Disable the nuke research, true by default - disable_nuke_research_names = { - ["atomic-bomb"] = true - } -- @setting disable_nuke_research_names The names of the researches to disabled + inventories = { + { + inventory = defines.inventory.character_ammo, + event = defines.events.on_player_ammo_inventory_changed, + items = { + ["atomic-bomb"] = true, + }, + }, + { + inventory = defines.inventory.character_armor, + event = defines.events.on_player_armor_inventory_changed, + items = {}, + }, + { + inventory = defines.inventory.character_guns, + event = defines.events.on_player_gun_inventory_changed, + items = {}, + }, + { + inventory = defines.inventory.character_main, + event = defines.events.on_player_main_inventory_changed, + items = { + ["atomic-bomb"] = true, + }, + }, + }, + ignore_permisison = "bypass-nukeprotect", -- @setting ignore_permisison The permission that nukeprotect will ignore + ignore_admins = true, -- @setting ignore_admins Ignore admins, true by default. Allows usage outside of the roles module + disable_nuke_research = false, -- @setting disable_nuke_research Disable the nuke research, true by default + disable_nuke_research_names = { + ["atomic-bomb"] = true, + }, -- @setting disable_nuke_research_names The names of the researches to disabled } diff --git a/exp_legacy/module/config/personal_logistic.lua b/exp_legacy/module/config/personal_logistic.lua index 8d26ac30..59a1e947 100644 --- a/exp_legacy/module/config/personal_logistic.lua +++ b/exp_legacy/module/config/personal_logistic.lua @@ -2,1639 +2,1640 @@ -- @config Personal Logistic return { + start = 0, production_required = { - ['belt'] = 100, - ['power'] = 20, - ['miner'] = 20, - ['furnace'] = 20, - ['machine'] = 20, - ['pole'] = 20, - ['bot'] = 20, - ['inserter'] = 20, - ['chest'] = 20, - ['rail'] = 100, - ['module'] = 20, - ['defense'] = 20, - ['rocket'] = 20, - ['ammo'] = 20, - ['armor'] = 3, - ['armor_equipment'] = 4, - ['weapon'] = 0 + ["belt"] = 100, + ["power"] = 20, + ["miner"] = 20, + ["furnace"] = 20, + ["machine"] = 20, + ["pole"] = 20, + ["bot"] = 20, + ["inserter"] = 20, + ["chest"] = 20, + ["rail"] = 100, + ["module"] = 20, + ["defense"] = 20, + ["rocket"] = 20, + ["ammo"] = 20, + ["armor"] = 3, + ["armor_equipment"] = 4, + ["weapon"] = 0, }, request = { -- belt - ['transport-belt'] = { + ["transport-belt"] = { key = 1, upgrade_of = nil, - type = 'belt', + type = "belt", stack = 100, min = 800, - max = 800 + max = 800, }, - ['underground-belt'] = { + ["underground-belt"] = { key = 2, upgrade_of = nil, - type = 'belt', + type = "belt", stack = 50, min = 250, - max = 250 + max = 250, }, - ['splitter'] = { + ["splitter"] = { key = 3, upgrade_of = nil, - type = 'belt', + type = "belt", stack = 50, min = 100, - max = 100 + max = 100, }, - ['fast-transport-belt'] = { + ["fast-transport-belt"] = { key = 11, - upgrade_of = 'transport-belt', - type = 'belt', + upgrade_of = "transport-belt", + type = "belt", stack = 100, min = 800, - max = 800 + max = 800, }, - ['fast-underground-belt'] = { + ["fast-underground-belt"] = { key = 12, - upgrade_of = 'underground-belt', - type = 'belt', + upgrade_of = "underground-belt", + type = "belt", stack = 50, min = 250, - max = 250 + max = 250, }, - ['fast-splitter'] = { + ["fast-splitter"] = { key = 13, - upgrade_of = 'splitter', - type = 'belt', + upgrade_of = "splitter", + type = "belt", stack = 50, min = 100, - max = 100 + max = 100, }, - ['express-transport-belt'] = { + ["express-transport-belt"] = { key = 21, - upgrade_of = 'fast-transport-belt', - type = 'belt', + upgrade_of = "fast-transport-belt", + type = "belt", stack = 100, min = 800, - max = 800 + max = 800, }, - ['express-underground-belt'] = { + ["express-underground-belt"] = { key = 22, - upgrade_of = 'fast-underground-belt', - type = 'belt', + upgrade_of = "fast-underground-belt", + type = "belt", stack = 50, min = 250, - max = 250 + max = 250, }, - ['express-splitter'] = { + ["express-splitter"] = { key = 23, - upgrade_of = 'fast-splitter', - type = 'belt', + upgrade_of = "fast-splitter", + type = "belt", stack = 50, min = 100, - max = 100 + max = 100, }, -- power - ['solar-panel'] = { + ["solar-panel"] = { key = 4, upgrade_of = nil, - type = 'power', + type = "power", stack = 50, min = 0, - max = 0 + max = 0, }, - ['accumulator'] = { + ["accumulator"] = { key = 5, upgrade_of = nil, - type = 'power', + type = "power", stack = 50, min = 0, - max = 0 + max = 0, }, - ['boiler'] = { + ["boiler"] = { key = 6, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['steam-engine'] = { + ["steam-engine"] = { key = 7, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, -- miner - ['burner-mining-drill'] = { + ["burner-mining-drill"] = { key = 8, upgrade_of = nil, - type = 'miner', + type = "miner", stack = 50, min = 0, - max = 0 + max = 0, }, - ['electric-mining-drill'] = { + ["electric-mining-drill"] = { key = 9, - upgrade_of = 'burner-mining-drill', - type = 'miner', + upgrade_of = "burner-mining-drill", + type = "miner", stack = 50, min = 250, - max = 250 + max = 250, }, - ['pumpjack'] = { + ["pumpjack"] = { key = 10, upgrade_of = nil, - type = 'miner', + type = "miner", stack = 20, min = 20, - max = 20 + max = 20, }, -- furnace - ['stone-furnace'] = { + ["stone-furnace"] = { key = 18, upgrade_of = nil, - type = 'furnace', + type = "furnace", stack = 50, min = 0, - max = 0 + max = 0, }, - ['steel-furnace'] = { + ["steel-furnace"] = { key = 19, - upgrade_of = 'stone-furnace', - type = 'furnace', + upgrade_of = "stone-furnace", + type = "furnace", stack = 50, min = 0, - max = 0 + max = 0, }, - ['electric-furnace'] = { + ["electric-furnace"] = { key = 20, - upgrade_of = 'steel-furnace', - type = 'furnace', + upgrade_of = "steel-furnace", + type = "furnace", stack = 50, min = 0, - max = 0 + max = 0, }, -- machine - ['assembling-machine-1'] = { + ["assembling-machine-1"] = { key = 28, upgrade_of = nil, - type = 'machine', + type = "machine", stack = 50, min = 0, - max = 50 + max = 50, }, - ['assembling-machine-2'] = { + ["assembling-machine-2"] = { key = 29, - upgrade_of = 'assembling-machine-1', - type = 'machine', + upgrade_of = "assembling-machine-1", + type = "machine", stack = 50, min = 50, - max = 50 + max = 50, }, - ['assembling-machine-3'] = { + ["assembling-machine-3"] = { key = 30, - upgrade_of = 'assembling-machine-2', - type = 'machine', + upgrade_of = "assembling-machine-2", + type = "machine", stack = 50, min = 50, - max = 50 + max = 50, }, - ['oil-refinery'] = { + ["oil-refinery"] = { key = 24, upgrade_of = nil, - type = 'machine', + type = "machine", stack = 10, min = 0, - max = 0 + max = 0, }, - ['chemical-plant'] = { + ["chemical-plant"] = { key = 25, upgrade_of = nil, - type = 'machine', + type = "machine", stack = 10, min = 0, - max = 0 + max = 0, }, - ['centrifuge'] = { + ["centrifuge"] = { key = 26, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['lab'] = { + ["lab"] = { key = 27, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['nuclear-reactor'] = { + ["nuclear-reactor"] = { key = 14, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['heat-pipe'] = { + ["heat-pipe"] = { key = 15, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['heat-exchanger'] = { + ["heat-exchanger"] = { key = 16, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['steam-turbine'] = { + ["steam-turbine"] = { key = 17, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['rocket-silo'] = { + ["rocket-silo"] = { key = 80, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 0 + max = 0, }, -- pole - ['small-electric-pole'] = { + ["small-electric-pole"] = { key = 31, upgrade_of = nil, - type = 'pole', + type = "pole", stack = 50, min = 150, - max = 150 + max = 150, }, - ['medium-electric-pole'] = { + ["medium-electric-pole"] = { key = 32, - upgrade_of = 'small-electric-pole', - type = 'pole', + upgrade_of = "small-electric-pole", + type = "pole", stack = 50, min = 150, - max = 150 + max = 150, }, - ['big-electric-pole'] = { + ["big-electric-pole"] = { key = 33, upgrade_of = nil, - type = 'pole', + type = "pole", stack = 50, min = 150, - max = 150 + max = 150, }, - ['substation'] = { + ["substation"] = { key = 34, upgrade_of = nil, - type = 'pole', + type = "pole", stack = 50, min = 50, - max = 50 + max = 50, }, -- bot - ['roboport'] = { + ["roboport"] = { key = 35, upgrade_of = nil, - type = 'bot', + type = "bot", stack = 10, min = 20, - max = 20 + max = 20, }, - ['construction-robot'] = { + ["construction-robot"] = { key = 36, upgrade_of = nil, - type = 'bot', + type = "bot", stack = 50, min = 100, - max = 100 + max = 100, }, - ['logistic-robot'] = { + ["logistic-robot"] = { key = 37, upgrade_of = nil, - type = 'bot', + type = "bot", stack = 50, min = 10, - max = 10 + max = 10, }, - ['cliff-explosives'] = { + ["cliff-explosives"] = { key = 38, upgrade_of = nil, - type = 'bot', + type = "bot", stack = 20, min = 80, - max = 80 + max = 80, }, - ['repair-pack'] = { + ["repair-pack"] = { key = 39, upgrade_of = nil, - type = 'bot', + type = "bot", stack = 100, min = 100, - max = 100 + max = 100, }, - ['landfill'] = { + ["landfill"] = { key = 40, upgrade_of = nil, - type = 'bot', + type = "bot", stack = 100, min = 300, - max = 300 + max = 300, }, -- ore - ['wood'] = { + ["wood"] = { key = 151, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['coal'] = { + ["coal"] = { key = 152, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['stone'] = { + ["stone"] = { key = 153, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['iron-ore'] = { + ["iron-ore"] = { key = 154, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['copper-ore'] = { + ["copper-ore"] = { key = 155, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['uranium-ore'] = { + ["uranium-ore"] = { key = 156, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['raw-fish'] = { + ["raw-fish"] = { key = 157, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['iron-stick'] = { + ["iron-stick"] = { key = 158, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['iron-gear-wheel'] = { + ["iron-gear-wheel"] = { key = 159, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['satellite'] = { + ["satellite"] = { key = 160, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 0 + max = 0, }, -- inserter - ['burner-inserter'] = { + ["burner-inserter"] = { key = 41, upgrade_of = nil, - type = 'inserter', + type = "inserter", stack = 50, min = 0, - max = 50 + max = 50, }, - ['inserter'] = { + ["inserter"] = { key = 42, - upgrade_of = 'burner-inserter', - type = 'inserter', + upgrade_of = "burner-inserter", + type = "inserter", stack = 50, min = 0, - max = 50 + max = 50, }, - ['long-handed-inserter'] = { + ["long-handed-inserter"] = { key = 43, upgrade_of = nil, - type = 'inserter', + type = "inserter", stack = 50, min = 0, - max = 0 + max = 0, }, - ['fast-inserter'] = { + ["fast-inserter"] = { key = 44, - upgrade_of = 'inserter', - type = 'inserter', + upgrade_of = "inserter", + type = "inserter", stack = 50, min = 0, - max = 50 + max = 50, }, - ['filter-inserter'] = { + ["filter-inserter"] = { key = 45, upgrade_of = nil, - type = 'inserter', + type = "inserter", stack = 50, min = 50, - max = 50 + max = 50, }, - ['stack-inserter'] = { + ["stack-inserter"] = { key = 46, - upgrade_of = 'fast-inserter', - type = 'inserter', + upgrade_of = "fast-inserter", + type = "inserter", stack = 50, min = 100, - max = 100 + max = 100, }, - ['stack-filter-inserter'] = { + ["stack-filter-inserter"] = { key = 47, upgrade_of = nil, - type = 'inserter', + type = "inserter", stack = 50, min = 50, - max = 50 + max = 50, }, -- pipe - ['pipe'] = { + ["pipe"] = { key = 48, upgrade_of = nil, type = nil, stack = 100, min = 200, - max = 200 + max = 200, }, - ['pipe-to-ground'] = { + ["pipe-to-ground"] = { key = 49, upgrade_of = nil, type = nil, stack = 50, min = 150, - max = 150 + max = 150, }, - ['pump'] = { + ["pump"] = { key = 50, upgrade_of = nil, type = nil, stack = 50, min = 100, - max = 100 + max = 100, }, - ['storage-tank'] = { + ["storage-tank"] = { key = 59, upgrade_of = nil, type = nil, stack = 50, min = 50, - max = 50 + max = 50, }, -- chest - ['wooden-chest'] = { + ["wooden-chest"] = { key = 51, upgrade_of = nil, - type = 'chest', + type = "chest", stack = 50, min = 0, - max = 50 + max = 50, }, - ['iron-chest'] = { + ["iron-chest"] = { key = 52, - upgrade_of = 'wooden-chest', - type = 'chest', + upgrade_of = "wooden-chest", + type = "chest", stack = 50, min = 0, - max = 50 + max = 50, }, - ['steel-chest'] = { + ["steel-chest"] = { key = 53, - upgrade_of = 'iron-chest', - type = 'chest', + upgrade_of = "iron-chest", + type = "chest", stack = 50, min = 50, - max = 100 + max = 100, }, - ['logistic-chest-passive-provider'] = { + ["logistic-chest-passive-provider"] = { key = 54, upgrade_of = nil, - type = 'chest', + type = "chest", stack = 50, min = 50, - max = 50 + max = 50, }, - ['logistic-chest-storage'] = { + ["logistic-chest-storage"] = { key = 55, upgrade_of = nil, - type = 'chest', + type = "chest", stack = 50, min = 50, - max = 50 + max = 50, }, - ['logistic-chest-requester'] = { + ["logistic-chest-requester"] = { key = 56, upgrade_of = nil, - type = 'chest', + type = "chest", stack = 50, min = 50, - max = 50 + max = 50, }, - ['logistic-chest-buffer'] = { + ["logistic-chest-buffer"] = { key = 57, upgrade_of = nil, - type = 'chest', + type = "chest", stack = 50, min = 50, - max = 50 + max = 50, }, - ['logistic-chest-active-provider'] = { + ["logistic-chest-active-provider"] = { key = 58, upgrade_of = nil, - type = 'chest', + type = "chest", stack = 50, min = 50, - max = 50 + max = 50, }, -- rail - ['rail'] = { + ["rail"] = { key = 61, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 100, min = 1500, - max = 1500 + max = 1500, }, - ['train-stop'] = { + ["train-stop"] = { key = 62, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 10, min = 20, - max = 20 + max = 20, }, - ['rail-signal'] = { + ["rail-signal"] = { key = 63, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 50, min = 150, - max = 150 + max = 150, }, - ['rail-chain-signal'] = { + ["rail-chain-signal"] = { key = 64, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 50, min = 150, - max = 150 + max = 150, }, - ['locomotive'] = { + ["locomotive"] = { key = 65, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 5, min = 0, - max = 0 + max = 0, }, - ['cargo-wagon'] = { + ["cargo-wagon"] = { key = 66, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 5, min = 0, - max = 0 + max = 0, }, - ['fluid-wagon'] = { + ["fluid-wagon"] = { key = 67, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 5, min = 0, - max = 0 + max = 0, }, - ['artillery-wagon'] = { + ["artillery-wagon"] = { key = 68, upgrade_of = nil, - type = 'rail', + type = "rail", stack = 5, min = 0, - max = 0 + max = 0, }, -- circuit - ['constant-combinator'] = { + ["constant-combinator"] = { key = 71, upgrade_of = nil, type = nil, stack = 50, min = 50, - max = 50 + max = 50, }, - ['arithmetic-combinator'] = { + ["arithmetic-combinator"] = { key = 72, upgrade_of = nil, type = nil, stack = 50, min = 50, - max = 50 + max = 50, }, - ['decider-combinator'] = { + ["decider-combinator"] = { key = 73, upgrade_of = nil, type = nil, stack = 50, min = 50, - max = 50 + max = 50, }, - ['small-lamp'] = { + ["small-lamp"] = { key = 74, upgrade_of = nil, type = nil, stack = 50, min = 50, - max = 50 + max = 50, }, - ['red-wire'] = { + ["red-wire"] = { key = 75, upgrade_of = nil, type = nil, stack = 200, min = 200, - max = 200 + max = 200, }, - ['green-wire'] = { + ["green-wire"] = { key = 76, upgrade_of = nil, type = nil, stack = 200, min = 200, - max = 200 + max = 200, }, - ['copper-cable'] = { + ["copper-cable"] = { key = 77, upgrade_of = nil, type = nil, stack = 200, min = 200, - max = 200 + max = 200, }, - ['power-switch'] = { + ["power-switch"] = { key = 78, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['programmable-speaker'] = { + ["programmable-speaker"] = { key = 79, upgrade_of = nil, type = nil, stack = 50, min = 10, - max = 10 + max = 10, }, - ['offshore-pump'] = { + ["offshore-pump"] = { key = 60, upgrade_of = nil, type = nil, stack = 20, min = 20, - max = 20 + max = 20, }, -- module - ['beacon'] = { + ["beacon"] = { key = 81, upgrade_of = nil, - type = 'module', + type = "module", stack = 10, min = 120, - max = 120 + max = 120, }, - ['speed-module'] = { + ["speed-module"] = { key = 82, upgrade_of = nil, - type = 'module', + type = "module", stack = 50, min = 500, - max = 500 + max = 500, }, - ['speed-module-2'] = { + ["speed-module-2"] = { key = 83, - upgrade_of = 'speed-module', - type = 'module', + upgrade_of = "speed-module", + type = "module", stack = 50, min = 0, - max = 0 + max = 0, }, - ['speed-module-3'] = { + ["speed-module-3"] = { key = 84, - upgrade_of = 'speed-module-2', - type = 'module', + upgrade_of = "speed-module-2", + type = "module", stack = 50, min = 500, - max = 500 + max = 500, }, - ['productivity-module'] = { + ["productivity-module"] = { key = 85, upgrade_of = nil, - type = 'module', + type = "module", stack = 50, min = 0, - max = 0 + max = 0, }, - ['productivity-module-2'] = { + ["productivity-module-2"] = { key = 86, - upgrade_of = 'productivity-module', - type = 'module', + upgrade_of = "productivity-module", + type = "module", stack = 50, min = 0, - max = 0 + max = 0, }, - ['productivity-module-3'] = { + ["productivity-module-3"] = { key = 87, - upgrade_of = 'productivity-module-2', - type = 'module', + upgrade_of = "productivity-module-2", + type = "module", stack = 50, min = 0, - max = 0 + max = 0, }, - ['effectivity-module'] = { + ["effectivity-module"] = { key = 88, upgrade_of = nil, - type = 'module', + type = "module", stack = 50, min = 0, - max = 0 + max = 0, }, - ['effectivity-module-2'] = { + ["effectivity-module-2"] = { key = 89, - upgrade_of = 'effectivity-module', - type = 'module', + upgrade_of = "effectivity-module", + type = "module", stack = 50, min = 0, - max = 0 + max = 0, }, - ['effectivity-module-3'] = { + ["effectivity-module-3"] = { key = 90, - upgrade_of = 'effectivity-module-2', - type = 'module', + upgrade_of = "effectivity-module-2", + type = "module", stack = 50, min = 0, - max = 0 + max = 0, }, -- defense - ['stone-wall'] = { + ["stone-wall"] = { key = 91, upgrade_of = nil, - type = 'defense', + type = "defense", stack = 100, min = 0, - max = 0 + max = 0, }, - ['gate'] = { + ["gate"] = { key = 92, upgrade_of = nil, - type = 'defense', + type = "defense", stack = 50, min = 0, - max = 0 + max = 0, }, - ['gun-turret'] = { + ["gun-turret"] = { key = 93, upgrade_of = nil, - type = 'defense', + type = "defense", stack = 50, min = 0, - max = 0 + max = 0, }, - ['laser-turret'] = { + ["laser-turret"] = { key = 94, upgrade_of = nil, - type = 'defense', + type = "defense", stack = 50, min = 100, - max = 100 + max = 100, }, - ['flamethrower-turret'] = { + ["flamethrower-turret"] = { key = 95, upgrade_of = nil, - type = 'defense', + type = "defense", stack = 50, min = 0, - max = 0 + max = 0, }, - ['artillery-turret'] = { + ["artillery-turret"] = { key = 96, upgrade_of = nil, - type = 'defense', + type = "defense", stack = 10, min = 0, - max = 0 + max = 0, }, -- rocket - ['rocket'] = { + ["rocket"] = { key = 101, upgrade_of = nil, - type = 'rocket', + type = "rocket", stack = 200, min = 0, - max = 0 + max = 0, }, - ['explosive-rocket'] = { + ["explosive-rocket"] = { key = 102, - upgrade_of = 'rocket', - type = 'rocket', + upgrade_of = "rocket", + type = "rocket", stack = 200, min = 0, - max = 0 + max = 0, }, - ['atomic-bomb'] = { + ["atomic-bomb"] = { key = 103, - upgrade_of = 'explosive-rocket', - type = 'rocket', + upgrade_of = "explosive-rocket", + type = "rocket", stack = 10, min = 0, - max = 0 + max = 0, }, - ['rocket-launcher'] = { + ["rocket-launcher"] = { key = 104, upgrade_of = nil, - type = 'weapon', + type = "weapon", stack = 5, min = 1, - max = 1 + max = 1, }, - ['flamethrower'] = { + ["flamethrower"] = { key = 105, upgrade_of = nil, - type = 'weapon', + type = "weapon", stack = 5, min = 0, - max = 0 + max = 0, }, - ['pistol'] = { + ["pistol"] = { key = 106, upgrade_of = nil, - type = 'weapon', + type = "weapon", stack = 5, min = 0, - max = 0 + max = 0, }, - ['submachine-gun'] = { + ["submachine-gun"] = { key = 107, upgrade_of = nil, - type = 'weapon', + type = "weapon", stack = 5, min = 0, - max = 0 + max = 0, }, - ['shotgun'] = { + ["shotgun"] = { key = 108, upgrade_of = nil, - type = 'weapon', + type = "weapon", stack = 5, min = 0, - max = 0 + max = 0, }, - ['combat-shotgun'] = { + ["combat-shotgun"] = { key = 109, upgrade_of = nil, - type = 'weapon', + type = "weapon", stack = 5, min = 0, - max = 0 + max = 0, }, - ['land-mine'] = { + ["land-mine"] = { key = 110, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, -- ammo - ['firearm-magazine'] = { + ["firearm-magazine"] = { key = 111, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['piercing-rounds-magazine'] = { + ["piercing-rounds-magazine"] = { key = 112, - upgrade_of = 'firearm-magazine', - type = 'ammo', + upgrade_of = "firearm-magazine", + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['uranium-rounds-magazine'] = { + ["uranium-rounds-magazine"] = { key = 113, - upgrade_of = 'piercing-rounds-magazine', - type = 'ammo', + upgrade_of = "piercing-rounds-magazine", + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['flamethrower-ammo'] = { + ["flamethrower-ammo"] = { key = 114, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 100, min = 0, - max = 0 + max = 0, }, - ['shotgun-shell'] = { + ["shotgun-shell"] = { key = 115, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['piercing-shotgun-shell'] = { + ["piercing-shotgun-shell"] = { key = 116, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['cannon-shell'] = { + ["cannon-shell"] = { key = 117, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['explosive-cannon-shell'] = { + ["explosive-cannon-shell"] = { key = 118, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['uranium-cannon-shell'] = { + ["uranium-cannon-shell"] = { key = 119, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['explosive-uranium-cannon-shell'] = { + ["explosive-uranium-cannon-shell"] = { key = 120, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 200, min = 0, - max = 0 + max = 0, }, - ['grenade'] = { + ["grenade"] = { key = 97, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 100, min = 0, - max = 0 + max = 0, }, - ['cluster-grenade'] = { + ["cluster-grenade"] = { key = 98, upgrade_of = nil, - type = 'ammo', + type = "ammo", stack = 100, min = 0, - max = 0 + max = 0, }, - ['artillery-shell'] = { + ["artillery-shell"] = { key = 121, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 0 + max = 0, }, - ['poison-capsule'] = { + ["poison-capsule"] = { key = 122, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['slowdown-capsule'] = { + ["slowdown-capsule"] = { key = 123, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['defender-capsule'] = { + ["defender-capsule"] = { key = 124, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['distractor-capsule'] = { + ["distractor-capsule"] = { key = 125, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['destroyer-capsule'] = { + ["destroyer-capsule"] = { key = 126, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['car'] = { + ["car"] = { key = 127, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 0 + max = 0, }, - ['tank'] = { + ["tank"] = { key = 128, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 0 + max = 0, }, - ['spidertron'] = { + ["spidertron"] = { key = 129, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 5 + max = 5, }, - ['spidertron-remote'] = { + ["spidertron-remote"] = { key = 130, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 5 + max = 5, }, - ['radar'] = { + ["radar"] = { key = 99, upgrade_of = nil, type = nil, stack = 50, min = 50, - max = 50 + max = 50, }, -- armor - ['light-armor'] = { + ["light-armor"] = { key = 131, upgrade_of = nil, - type = 'armor', + type = "armor", stack = 1, min = 0, - max = 1 + max = 1, }, - ['heavy-armor'] = { + ["heavy-armor"] = { key = 132, - upgrade_of = 'light-armor', - type = 'armor', + upgrade_of = "light-armor", + type = "armor", stack = 1, min = 0, - max = 1 + max = 1, }, - ['modular-armor'] = { + ["modular-armor"] = { key = 133, - upgrade_of = 'heavy-armor', - type = 'armor', + upgrade_of = "heavy-armor", + type = "armor", stack = 1, min = 0, - max = 1 + max = 1, }, - ['power-armor'] = { + ["power-armor"] = { key = 134, - upgrade_of = 'modular-armor', - type = 'armor', + upgrade_of = "modular-armor", + type = "armor", stack = 1, min = 0, - max = 1 + max = 1, }, - ['power-armor-mk2'] = { + ["power-armor-mk2"] = { key = 135, - upgrade_of = 'power-armor', - type = 'armor', + upgrade_of = "power-armor", + type = "armor", stack = 1, min = 0, - max = 1 + max = 1, }, -- armor equipment - ['solar-panel-equipment'] = { + ["solar-panel-equipment"] = { key = 136, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['fusion-reactor-equipment'] = { + ["fusion-reactor-equipment"] = { key = 137, - upgrade_of = 'solar-panel-equipment', - type = 'armor_equipment', + upgrade_of = "solar-panel-equipment", + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['belt-immunity-equipment'] = { + ["belt-immunity-equipment"] = { key = 138, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['night-vision-equipment'] = { + ["night-vision-equipment"] = { key = 139, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['personal-laser-defense-equipment'] = { + ["personal-laser-defense-equipment"] = { key = 140, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 20 + max = 20, }, - ['personal-roboport-equipment'] = { + ["personal-roboport-equipment"] = { key = 141, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 0 + max = 0, }, - ['personal-roboport-mk2-equipment'] = { + ["personal-roboport-mk2-equipment"] = { key = 142, - upgrade_of = 'personal-roboport-equipment', - type = 'armor_equipment', + upgrade_of = "personal-roboport-equipment", + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['energy-shield-equipment'] = { + ["energy-shield-equipment"] = { key = 143, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 0 + max = 0, }, - ['energy-shield-mk2-equipment'] = { + ["energy-shield-mk2-equipment"] = { key = 144, - upgrade_of = 'energy-shield-equipment', - type = 'armor_equipment', + upgrade_of = "energy-shield-equipment", + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['battery-equipment'] = { + ["battery-equipment"] = { key = 145, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 0 + max = 0, }, - ['battery-mk2-equipment'] = { + ["battery-mk2-equipment"] = { key = 146, - upgrade_of = 'battery-equipment', - type = 'armor_equipment', + upgrade_of = "battery-equipment", + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['exoskeleton-equipment'] = { + ["exoskeleton-equipment"] = { key = 147, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 5 + max = 5, }, - ['discharge-defense-equipment'] = { + ["discharge-defense-equipment"] = { key = 148, upgrade_of = nil, - type = 'armor_equipment', + type = "armor_equipment", stack = 20, min = 0, - max = 0 + max = 0, }, - ['discharge-defense-remote'] = { + ["discharge-defense-remote"] = { key = 149, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 0 + max = 0, }, - ['artillery-targeting-remote'] = { + ["artillery-targeting-remote"] = { key = 150, upgrade_of = nil, type = nil, stack = 1, min = 1, - max = 1 + max = 1, }, -- path - ['stone-brick'] = { + ["stone-brick"] = { key = 100, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['concrete'] = { + ["concrete"] = { key = 69, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['hazard-concrete'] = { + ["hazard-concrete"] = { key = 70, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['refined-concrete'] = { + ["refined-concrete"] = { key = 188, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['refined-hazard-concrete'] = { + ["refined-hazard-concrete"] = { key = 189, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['crude-oil-barrel'] = { + ["crude-oil-barrel"] = { key = 161, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['heavy-oil-barrel'] = { + ["heavy-oil-barrel"] = { key = 162, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['light-oil-barrel'] = { + ["light-oil-barrel"] = { key = 163, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['lubricant-barrel'] = { + ["lubricant-barrel"] = { key = 164, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['petroleum-gas-barrel'] = { + ["petroleum-gas-barrel"] = { key = 165, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['sulfuric-acid-barrel'] = { + ["sulfuric-acid-barrel"] = { key = 166, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['water-barrel'] = { + ["water-barrel"] = { key = 167, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['empty-barrel'] = { + ["empty-barrel"] = { key = 168, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['uranium-fuel-cell'] = { + ["uranium-fuel-cell"] = { key = 169, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['used-up-uranium-fuel-cell'] = { + ["used-up-uranium-fuel-cell"] = { key = 170, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, -- science and circuit - ['automation-science-pack'] = { + ["automation-science-pack"] = { key = 171, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['logistic-science-pack'] = { + ["logistic-science-pack"] = { key = 172, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['military-science-pack'] = { + ["military-science-pack"] = { key = 173, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['chemical-science-pack'] = { + ["chemical-science-pack"] = { key = 174, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['production-science-pack'] = { + ["production-science-pack"] = { key = 175, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['utility-science-pack'] = { + ["utility-science-pack"] = { key = 176, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['space-science-pack'] = { + ["space-science-pack"] = { key = 177, upgrade_of = nil, type = nil, stack = 2000, min = 0, - max = 0 + max = 0, }, - ['electronic-circuit'] = { + ["electronic-circuit"] = { key = 178, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['advanced-circuit'] = { + ["advanced-circuit"] = { key = 179, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['processing-unit'] = { + ["processing-unit"] = { key = 180, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, -- intermediate - ['iron-plate'] = { + ["iron-plate"] = { key = 181, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['copper-plate'] = { + ["copper-plate"] = { key = 182, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['steel-plate'] = { + ["steel-plate"] = { key = 183, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['plastic-bar'] = { + ["plastic-bar"] = { key = 184, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['sulfur'] = { + ["sulfur"] = { key = 185, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['battery'] = { + ["battery"] = { key = 186, upgrade_of = nil, type = nil, stack = 200, min = 0, - max = 0 + max = 0, }, - ['explosives'] = { + ["explosives"] = { key = 187, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['engine-unit'] = { + ["engine-unit"] = { key = 191, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['electric-engine-unit'] = { + ["electric-engine-unit"] = { key = 192, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['flying-robot-frame'] = { + ["flying-robot-frame"] = { key = 193, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['rocket-control-unit'] = { + ["rocket-control-unit"] = { key = 194, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['low-density-structure'] = { + ["low-density-structure"] = { key = 195, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['solid-fuel'] = { + ["solid-fuel"] = { key = 196, upgrade_of = nil, type = nil, stack = 50, min = 0, - max = 0 + max = 0, }, - ['rocket-fuel'] = { + ["rocket-fuel"] = { key = 197, upgrade_of = nil, type = nil, stack = 10, min = 0, - max = 0 + max = 0, }, - ['nuclear-fuel'] = { + ["nuclear-fuel"] = { key = 198, upgrade_of = nil, type = nil, stack = 1, min = 0, - max = 0 + max = 0, }, - ['uranium-235'] = { + ["uranium-235"] = { key = 199, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 + max = 0, }, - ['uranium-238'] = { + ["uranium-238"] = { key = 200, upgrade_of = nil, type = nil, stack = 100, min = 0, - max = 0 - } - } + max = 0, + }, + }, } diff --git a/exp_legacy/module/config/pollution_grading.lua b/exp_legacy/module/config/pollution_grading.lua index fdb73369..07e5f3f2 100644 --- a/exp_legacy/module/config/pollution_grading.lua +++ b/exp_legacy/module/config/pollution_grading.lua @@ -2,8 +2,8 @@ -- @config Pollution-Grading return { - reference_point = {x=0,y=0}, --- @setting reference_point where pollution is read from + reference_point = { x = 0, y = 0 }, --- @setting reference_point where pollution is read from max_scalar = 0.5, --- @setting max_scalar the scale between true max and max min_scalar = 0.17, --- @setting min_scalar the scale between the lowest max and min - update_delay = 15 --- @setting update_delay time in minutes between view updates -} \ No newline at end of file + update_delay = 15, --- @setting update_delay time in minutes between view updates +} diff --git a/exp_legacy/module/config/popup_messages.lua b/exp_legacy/module/config/popup_messages.lua index 75db9a47..3a098d0e 100644 --- a/exp_legacy/module/config/popup_messages.lua +++ b/exp_legacy/module/config/popup_messages.lua @@ -2,9 +2,9 @@ -- @config Popup-Messages return { - show_player_messages=true, --- @setting show_player_messages weather a message in chat will make a popup above them - show_player_mentions=true, --- @setting show_player_mentions weather a mentioned player will have a popup when mentioned in chat - show_player_damage=true, --- @setting show_player_damage weather to show damage done by players - show_player_health=true, --- @setting show_player_health weather to show player health when attacked - damage_location_variance=0.8 --- @setting damage_location_variance how close to the eade of an entity the popups will appear -} \ No newline at end of file + show_player_messages = true, --- @setting show_player_messages weather a message in chat will make a popup above them + show_player_mentions = true, --- @setting show_player_mentions weather a mentioned player will have a popup when mentioned in chat + show_player_damage = true, --- @setting show_player_damage weather to show damage done by players + show_player_health = true, --- @setting show_player_health weather to show player health when attacked + damage_location_variance = 0.8, --- @setting damage_location_variance how close to the eade of an entity the popups will appear +} diff --git a/exp_legacy/module/config/preset_player_colours.lua b/exp_legacy/module/config/preset_player_colours.lua index b592e26c..637799e8 100644 --- a/exp_legacy/module/config/preset_player_colours.lua +++ b/exp_legacy/module/config/preset_player_colours.lua @@ -2,32 +2,32 @@ -- @config Preset-Player-Colours return { - players={ --- @setting players list of all players and the colour in rgb256 that they will recive upon joining - PHIDIAS0303={r=255,g=255,b=255}, - BADgamerNL={r=255,g=20,b=147}, - arty714={r=150,g=68,b=161}, - Cooldude2606={r=57,g=192,b=207}, - mark9064={r=99,g=0,b=255}, - eissturm={r=25,g=25,b=112}, - Sakama={r=20,g=213,b=80}, - freek18={r=50,g=0,b=255}, - aldldl={r=0,g=131,b=255}, - NAD4X4={r=135,g=206,b=250}, - cydes={r=82,g=249,b=155}, - UUBlueFire={r=0,g=204,b=255}, - CmonMate497={r=103,g=224,b=194}, - s4sh={r=255,g=120,b=0}, - ArPiiX={r=0,g=255,b=0}, - NextIdea={r=255,g=255,b=255}, - hamsterbryan={r=0,g=255,b=0}, - XenoCyber={r=0,g=128,b=255} - }, - disallow = { --- @setting disallow colours which will not given to players; the value does not matter it is only the key which is checked - black = {r = 0, g = 0, b = 0}, - white = {r = 255, g = 255, b = 255}, - success = {r = 0, g = 255, b = 0}, - warning = {r = 255, g = 255, b = 0}, - fail = {r = 255, g = 0, b = 0}, - info = {r = 255, g = 255, b = 255} - } + players = { --- @setting players list of all players and the colour in rgb256 that they will recive upon joining + PHIDIAS0303 = { r = 255, g = 255, b = 255 }, + BADgamerNL = { r = 255, g = 20, b = 147 }, + arty714 = { r = 150, g = 68, b = 161 }, + Cooldude2606 = { r = 57, g = 192, b = 207 }, + mark9064 = { r = 99, g = 0, b = 255 }, + eissturm = { r = 25, g = 25, b = 112 }, + Sakama = { r = 20, g = 213, b = 80 }, + freek18 = { r = 50, g = 0, b = 255 }, + aldldl = { r = 0, g = 131, b = 255 }, + NAD4X4 = { r = 135, g = 206, b = 250 }, + cydes = { r = 82, g = 249, b = 155 }, + UUBlueFire = { r = 0, g = 204, b = 255 }, + CmonMate497 = { r = 103, g = 224, b = 194 }, + s4sh = { r = 255, g = 120, b = 0 }, + ArPiiX = { r = 0, g = 255, b = 0 }, + NextIdea = { r = 255, g = 255, b = 255 }, + hamsterbryan = { r = 0, g = 255, b = 0 }, + XenoCyber = { r = 0, g = 128, b = 255 }, + }, + disallow = { --- @setting disallow colours which will not given to players; the value does not matter it is only the key which is checked + black = { r = 0, g = 0, b = 0 }, + white = { r = 255, g = 255, b = 255 }, + success = { r = 0, g = 255, b = 0 }, + warning = { r = 255, g = 255, b = 0 }, + fail = { r = 255, g = 0, b = 0 }, + info = { r = 255, g = 255, b = 255 }, + }, } diff --git a/exp_legacy/module/config/preset_player_quickbar.lua b/exp_legacy/module/config/preset_player_quickbar.lua index de0ea7ef..47657ebe 100644 --- a/exp_legacy/module/config/preset_player_quickbar.lua +++ b/exp_legacy/module/config/preset_player_quickbar.lua @@ -2,5 +2,5 @@ -- @config Preset-Player-Quickbar return { - dangerarea = {"transport-belt", "underground-belt", "splitter", "pipe", "pipe-to-ground", "inserter", "fast-inserter", "long-handed-inserter", "stack-inserter", "roboport", "small-electric-pole", "medium-electric-pole", "big-electric-pole", "substation", nil, "rail", "rail-signal", "rail-chain-signal", "landfill", "cliff-explosives", "fast-transport-belt", "fast-underground-belt", "fast-splitter", "pipe", "pipe-to-ground", "fast-inserter", "long-handed-inserter", "stack-inserter", "stack-filter-inserter", "roboport", [81] = "red-wire", [82] = "green-wire", [83] = "arithmetic-combinator", [84] = "decider-combinator", [85] = "constant-combinator", [86] = "power-switch", [91] = "logistic-chest-active-provider", [92] = "logistic-chest-passive-provider", [93] = "logistic-chest-storage", [94] = "logistic-chest-buffer", [95] = "logistic-chest-requester", [96] = "roboport"} + dangerarea = { "transport-belt", "underground-belt", "splitter", "pipe", "pipe-to-ground", "inserter", "fast-inserter", "long-handed-inserter", "stack-inserter", "roboport", "small-electric-pole", "medium-electric-pole", "big-electric-pole", "substation", nil, "rail", "rail-signal", "rail-chain-signal", "landfill", "cliff-explosives", "fast-transport-belt", "fast-underground-belt", "fast-splitter", "pipe", "pipe-to-ground", "fast-inserter", "long-handed-inserter", "stack-inserter", "stack-filter-inserter", "roboport", [81] = "red-wire", [82] = "green-wire", [83] = "arithmetic-combinator", [84] = "decider-combinator", [85] = "constant-combinator", [86] = "power-switch", [91] = "logistic-chest-active-provider", [92] = "logistic-chest-passive-provider", [93] = "logistic-chest-storage", [94] = "logistic-chest-buffer", [95] = "logistic-chest-requester", [96] = "roboport" }, } diff --git a/exp_legacy/module/config/protection.lua b/exp_legacy/module/config/protection.lua index 6f051c37..37c78f79 100644 --- a/exp_legacy/module/config/protection.lua +++ b/exp_legacy/module/config/protection.lua @@ -1,19 +1,19 @@ return { ignore_admins = true, --- @setting ignore_admins If admins are ignored by the protection filter - ignore_permission = 'bypass-entity-protection', --- @setting ignore_permission Players with this permission will be ignored by the protection filter, leave nil if expcore.roles is not used + ignore_permission = "bypass-entity-protection", --- @setting ignore_permission Players with this permission will be ignored by the protection filter, leave nil if expcore.roles is not used repeat_count = 5, --- @setting repeat_count Number of protected entities that must be removed within repeat_lifetime in order to trigger repeated removal protection - repeat_lifetime = 3600*20, --- @setting repeat_lifetime The length of time, in ticks, that protected removals will be remembered for - refresh_rate = 3600*5, --- @setting refresh_rate How often the age of protected removals are checked against repeat_lifetime + repeat_lifetime = 3600 * 20, --- @setting repeat_lifetime The length of time, in ticks, that protected removals will be remembered for + refresh_rate = 3600 * 5, --- @setting refresh_rate How often the age of protected removals are checked against repeat_lifetime always_protected_names = { --- @setting always_protected_names Names of entities which are always protected }, always_protected_types = { --- @setting always_protected_types Types of entities which are always protected - 'boiler', 'generator', 'offshore-pump', 'power-switch', 'reactor', 'rocket-silo' + "boiler", "generator", "offshore-pump", "power-switch", "reactor", "rocket-silo", }, always_trigger_repeat_names = { --- @setting always_trigger_repeat_names Names of entities which always trigger repeated removal protection }, always_trigger_repeat_types = { --- @setting always_trigger_repeat_types Types of entities which always trigger repeated removal protection - 'reactor', 'rocket-silo' - } -} \ No newline at end of file + "reactor", "rocket-silo", + }, +} diff --git a/exp_legacy/module/config/repair.lua b/exp_legacy/module/config/repair.lua index 0dbb1224..2b8d86b5 100644 --- a/exp_legacy/module/config/repair.lua +++ b/exp_legacy/module/config/repair.lua @@ -3,14 +3,14 @@ return { disallow = { --- @setting disallow items in this list will never be repaired - ['loader']=true, - ['fast-loader']=true, - ['express-loader']=true, - ['electric-energy-interface']=true, - ['infinity-chest']=true + ["loader"] = true, + ["fast-loader"] = true, + ["express-loader"] = true, + ["electric-energy-interface"] = true, + ["infinity-chest"] = true, }, - max_range=50, --- @setting max_range the max range that can be used with the repair command - allow_blueprint_repair=false, --- @setting allow_blueprint_repair when true will allow blueprints (things not destroyed by biters) to be build instantly using the repair command - allow_ghost_revive=true, --- @setting allow_ghost_revive when true will allow ghosts (things destroyed by biters) to be build instantly using the repair command - allow_heal_entities=true --- @setting allow_heal_entities when true will heal entities to full health that are within range -} \ No newline at end of file + max_range = 50, --- @setting max_range the max range that can be used with the repair command + allow_blueprint_repair = false, --- @setting allow_blueprint_repair when true will allow blueprints (things not destroyed by biters) to be build instantly using the repair command + allow_ghost_revive = true, --- @setting allow_ghost_revive when true will allow ghosts (things destroyed by biters) to be build instantly using the repair command + allow_heal_entities = true, --- @setting allow_heal_entities when true will heal entities to full health that are within range +} diff --git a/exp_legacy/module/config/research.lua b/exp_legacy/module/config/research.lua index d394ba55..fa0070d6 100644 --- a/exp_legacy/module/config/research.lua +++ b/exp_legacy/module/config/research.lua @@ -8,74 +8,74 @@ return { -- this enable 20 more inventory for each mining productivity level up to 4 bonus_inventory = { enabled = true, - name = 'character_inventory_slots_bonus', + name = "character_inventory_slots_bonus", rate = 5, - limit = 20 + limit = 20, }, - file_name = 'log/research.log', + file_name = "log/research.log", milestone = { - ['automation'] = 600, - ['logistics'] = 300, - ['steel-processing'] = 300, - ['logistic-science-pack'] = 300, - ['electronics'] = 300, - ['fast-inserter'] = 300, - ['steel-axe'] = 300, - ['automation-2'] = 300, - ['advanced-material-processing'] = 300, - ['engine'] = 300, - ['fluid-handling'] = 300, - ['oil-processing'] = 300, - ['sulfur-processing'] = 300, - ['plastics'] = 300, - ['advanced-electronics'] = 300, - ['chemical-science-pack'] = 300, - ['modules'] = 300, - ['logistics-2'] = 300, - ['railway'] = 300, - ['research-speed-1'] = 300, - ['research-speed-2'] = 300, - ['battery'] = 300, - ['concrete'] = 300, - ['flammables'] = 300, - ['low-density-structure'] = 300, - ['advanced-material-processing-2'] = 300, - ['productivity-module'] = 300, - ['production-science-pack'] = 300, - ['advanced-electronics-2'] = 300, - ['advanced-oil-processing'] = 300, - ['electric-engine'] = 300, - ['robotics'] = 300, - ['construction-robotics'] = 300, - ['worker-robots-speed-1'] = 300, - ['worker-robots-speed-2'] = 300, - ['utility-science-pack'] = 300, - ['productivity-module-2'] = 300, - ['speed-module-2'] = 300, - ['rocket-fuel'] = 300, - ['effect-transmission'] = 300, - ['productivity-module-3'] = 300, - ['rocket-control-unit'] = 300, - ['speed-module-3'] = 300, - ['rocket-silo'] = 300, - ['space-science-pack'] = 300, + ["automation"] = 600, + ["logistics"] = 300, + ["steel-processing"] = 300, + ["logistic-science-pack"] = 300, + ["electronics"] = 300, + ["fast-inserter"] = 300, + ["steel-axe"] = 300, + ["automation-2"] = 300, + ["advanced-material-processing"] = 300, + ["engine"] = 300, + ["fluid-handling"] = 300, + ["oil-processing"] = 300, + ["sulfur-processing"] = 300, + ["plastics"] = 300, + ["advanced-electronics"] = 300, + ["chemical-science-pack"] = 300, + ["modules"] = 300, + ["logistics-2"] = 300, + ["railway"] = 300, + ["research-speed-1"] = 300, + ["research-speed-2"] = 300, + ["battery"] = 300, + ["concrete"] = 300, + ["flammables"] = 300, + ["low-density-structure"] = 300, + ["advanced-material-processing-2"] = 300, + ["productivity-module"] = 300, + ["production-science-pack"] = 300, + ["advanced-electronics-2"] = 300, + ["advanced-oil-processing"] = 300, + ["electric-engine"] = 300, + ["robotics"] = 300, + ["construction-robotics"] = 300, + ["worker-robots-speed-1"] = 300, + ["worker-robots-speed-2"] = 300, + ["utility-science-pack"] = 300, + ["productivity-module-2"] = 300, + ["speed-module-2"] = 300, + ["rocket-fuel"] = 300, + ["effect-transmission"] = 300, + ["productivity-module-3"] = 300, + ["rocket-control-unit"] = 300, + ["speed-module-3"] = 300, + ["rocket-silo"] = 300, + ["space-science-pack"] = 300, }, inf_res = { -- Mining Productivity - ['mining-productivity-4'] = 4, + ["mining-productivity-4"] = 4, -- Robot Speed - ['worker-robots-speed-6'] = 6, + ["worker-robots-speed-6"] = 6, -- Laser Damage - ['energy-weapons-damage-7'] = 7, + ["energy-weapons-damage-7"] = 7, -- Explosive Damage - ['stronger-explosives-7'] = 7, + ["stronger-explosives-7"] = 7, -- Bullet Damage - ['physical-projectile-damage-7'] = 7, + ["physical-projectile-damage-7"] = 7, -- Flame Damage - ['refined-flammables-7'] = 7, + ["refined-flammables-7"] = 7, -- Artillery Range - ['artillery-shell-range-1'] = 1, + ["artillery-shell-range-1"] = 1, -- Artillery Speed - ['artillery-shell-speed-1'] = 1 - } + ["artillery-shell-speed-1"] = 1, + }, } diff --git a/exp_legacy/module/config/scorched_earth.lua b/exp_legacy/module/config/scorched_earth.lua index fb3a92c1..ee33cd44 100644 --- a/exp_legacy/module/config/scorched_earth.lua +++ b/exp_legacy/module/config/scorched_earth.lua @@ -2,115 +2,115 @@ -- @config Scorched-Earth return { - weakness_value=70, --- @setting weakness_value lower value will make tiles more likely to degrade - strengths={ --- @setting strengths this decides how "strong" a tile is, bigger number means less likely to degrade + weakness_value = 70, --- @setting weakness_value lower value will make tiles more likely to degrade + strengths = { --- @setting strengths this decides how "strong" a tile is, bigger number means less likely to degrade -- debug: /interface require('modules.addons.worn-paths')(player.name,true) -- note: tiles are effected by the tiles around them, so player paths will not degrade as fast when made wider -- note: values are relative to the tile with the highest value, recommended to keep highest tile as a "nice" number -- note: tiles not in list will never degrade under any conditions (which is why some are omitted such as water) - ["refined-concrete"]=100, - ["refined-hazard-concrete-left"]=100, - ["refined-hazard-concrete-right"]=100, - ["concrete"]=90, - ["hazard-concrete-left"]=90, - ["hazard-concrete-right"]=90, - ["stone-path"]=80, - ["red-desert-0"]=80, - ["dry-dirt"]=50, + ["refined-concrete"] = 100, + ["refined-hazard-concrete-left"] = 100, + ["refined-hazard-concrete-right"] = 100, + ["concrete"] = 90, + ["hazard-concrete-left"] = 90, + ["hazard-concrete-right"] = 90, + ["stone-path"] = 80, + ["red-desert-0"] = 80, + ["dry-dirt"] = 50, -- grass four (main grass tiles) - ["grass-1"]=50, - ["grass-2"]=40, - ["grass-3"]=30, - ["grass-4"]=25, + ["grass-1"] = 50, + ["grass-2"] = 40, + ["grass-3"] = 30, + ["grass-4"] = 25, -- red three (main red tiles) - ["red-desert-1"]=40, - ["red-desert-2"]=30, - ["red-desert-3"]=25, + ["red-desert-1"] = 40, + ["red-desert-2"] = 30, + ["red-desert-3"] = 25, -- sand three (main sand tiles) - ["sand-1"]=40, - ["sand-2"]=30, - ["sand-3"]=25, + ["sand-1"] = 40, + ["sand-2"] = 30, + ["sand-3"] = 25, -- dirt 3 (main dirt tiles) - ["dirt-1"]=40, - ["dirt-2"]=30, - ["dirt-3"]=25, + ["dirt-1"] = 40, + ["dirt-2"] = 30, + ["dirt-3"] = 25, -- last three/four (all sets of three merge here) - ["dirt-4"]=25, - ["dirt-5"]=30, - ["dirt-6"]=40, - --["dirt-7"]=0, -- last tile, nothing to degrade to + ["dirt-4"] = 25, + ["dirt-5"] = 30, + ["dirt-6"] = 40, + -- ["dirt-7"]=0, -- last tile, nothing to degrade to -- land fill chain -- ["landfill"]=50, - --["water-shallow"]=90, - --["water-mud"]=0, -- last tile, nothing to degrade to + -- ["water-shallow"]=90, + -- ["water-mud"]=0, -- last tile, nothing to degrade to }, - degrade_order={ --- @setting degrade_order when a tile degrades it will turn into the next tile given here - ["refined-concrete"]='concrete', - ["refined-hazard-concrete-left"]='hazard-concrete-left', - ["refined-hazard-concrete-right"]='hazard-concrete-right', - ["concrete"]='stone-path', - ["hazard-concrete-left"]='stone-path', - ["hazard-concrete-right"]='stone-path', - ["stone-path"]='dry-dirt', - ["red-desert-0"]='dry-dirt', - ["dry-dirt"]='dirt-4', + degrade_order = { --- @setting degrade_order when a tile degrades it will turn into the next tile given here + ["refined-concrete"] = "concrete", + ["refined-hazard-concrete-left"] = "hazard-concrete-left", + ["refined-hazard-concrete-right"] = "hazard-concrete-right", + ["concrete"] = "stone-path", + ["hazard-concrete-left"] = "stone-path", + ["hazard-concrete-right"] = "stone-path", + ["stone-path"] = "dry-dirt", + ["red-desert-0"] = "dry-dirt", + ["dry-dirt"] = "dirt-4", -- grass four (main grass tiles) - ["grass-1"]='grass-2', - ["grass-2"]='grass-3', - ["grass-3"]='grass-4', - ["grass-4"]='dirt-4', + ["grass-1"] = "grass-2", + ["grass-2"] = "grass-3", + ["grass-3"] = "grass-4", + ["grass-4"] = "dirt-4", -- red three (main red tiles) - ["red-desert-1"]='red-desert-2', - ["red-desert-2"]='red-desert-3', - ["red-desert-3"]='dirt-4', + ["red-desert-1"] = "red-desert-2", + ["red-desert-2"] = "red-desert-3", + ["red-desert-3"] = "dirt-4", -- sand three (main sand tiles) - ["sand-1"]='sand-2', - ["sand-2"]='sand-3', - ["sand-3"]='dirt-4', + ["sand-1"] = "sand-2", + ["sand-2"] = "sand-3", + ["sand-3"] = "dirt-4", -- dirt 3 (main dirt tiles) - ["dirt-1"]='dirt-2', - ["dirt-2"]='dirt-3', - ["dirt-3"]='dirt-4', + ["dirt-1"] = "dirt-2", + ["dirt-2"] = "dirt-3", + ["dirt-3"] = "dirt-4", -- last three/four (all sets of three merge here) - ["dirt-4"]='dirt-5', - ["dirt-5"]='dirt-6', - ["dirt-6"]='dirt-7', - --["dirt-7"]=0, -- last tile, nothing to degrade to + ["dirt-4"] = "dirt-5", + ["dirt-5"] = "dirt-6", + ["dirt-6"] = "dirt-7", + -- ["dirt-7"]=0, -- last tile, nothing to degrade to -- land fill chain -- ["landfill"]='grass-2', -- 'water-shallow' - --["water-shallow"]='water-mud', - --["water-mud"]=0, -- last tile, nothing to degrade to + -- ["water-shallow"]='water-mud', + -- ["water-mud"]=0, -- last tile, nothing to degrade to }, - entities={ --- @setting entities entities in this list will degrade the tiles under them when they are placed - ['stone-furnace']=true, - ['steel-furnace']=true, - ['electric-furnace']=true, - ['assembling-machine-1']=true, - ['assembling-machine-2']=true, - ['assembling-machine-3']=true, - ['beacon']=true, - ['centrifuge']=true, - ['chemical-plant']=true, - ['oil-refinery']=true, - ['storage-tank']=true, - ['nuclear-reactor']=true, - ['steam-engine']=true, - ['steam-turbine']=true, - ['boiler']=true, - ['heat-exchanger']=true, - ['stone-wall']=true, - ['gate']=true, - ['gun-turret']=true, - ['laser-turret']=true, - ['flamethrower-turret']=true, - ['radar']=true, - ['lab']=true, - ['big-electric-pole']=true, - ['substation']=true, - ['rocket-silo']=true, - ['pumpjack']=true, - ['electric-mining-drill']=true, - ['roboport']=true, - ['accumulator']=true - } -} \ No newline at end of file + entities = { --- @setting entities entities in this list will degrade the tiles under them when they are placed + ["stone-furnace"] = true, + ["steel-furnace"] = true, + ["electric-furnace"] = true, + ["assembling-machine-1"] = true, + ["assembling-machine-2"] = true, + ["assembling-machine-3"] = true, + ["beacon"] = true, + ["centrifuge"] = true, + ["chemical-plant"] = true, + ["oil-refinery"] = true, + ["storage-tank"] = true, + ["nuclear-reactor"] = true, + ["steam-engine"] = true, + ["steam-turbine"] = true, + ["boiler"] = true, + ["heat-exchanger"] = true, + ["stone-wall"] = true, + ["gate"] = true, + ["gun-turret"] = true, + ["laser-turret"] = true, + ["flamethrower-turret"] = true, + ["radar"] = true, + ["lab"] = true, + ["big-electric-pole"] = true, + ["substation"] = true, + ["rocket-silo"] = true, + ["pumpjack"] = true, + ["electric-mining-drill"] = true, + ["roboport"] = true, + ["accumulator"] = true, + }, +} diff --git a/exp_legacy/module/config/spawn_area.lua b/exp_legacy/module/config/spawn_area.lua index 335c4876..3d6c0d80 100644 --- a/exp_legacy/module/config/spawn_area.lua +++ b/exp_legacy/module/config/spawn_area.lua @@ -6,249 +6,249 @@ return { -- Enable predefined patches: 128, else: 32 deconstruction_radius = 20, -- @setting deconstruction_radius All entities within this radius will be removed tile_radius = 20, - deconstruction_tile = 'concrete', --- @setting deconstruction_tile Tile to be placed in the deconstruction radius, use nil for map gen + deconstruction_tile = "concrete", --- @setting deconstruction_tile Tile to be placed in the deconstruction radius, use nil for map gen landfill_radius = 50, --- @setting pattern_radius All water within this radius will be land filled }, turrets = { --- @setting turrets Settings relating to adding turrets to spawn enabled = true, --- @setting enabled Whether turrets will be added to spawn - ammo_type = 'uranium-rounds-magazine', --- @setting ammo_type The ammo type that will be used during refills - refill_time = 60*60*5, --- @setting refill_time The time in ticks between each refill of the turrets, only change if having lag issues - offset = {x=0, y=0}, --- @setting offset The position offset to apply to turrets + ammo_type = "uranium-rounds-magazine", --- @setting ammo_type The ammo type that will be used during refills + refill_time = 60 * 60 * 5, --- @setting refill_time The time in ticks between each refill of the turrets, only change if having lag issues + offset = { x = 0, y = 0 }, --- @setting offset The position offset to apply to turrets locations = { --- @setting locations The locations of all turrets, this list can change during runtime - {surface=1,position={x=-3,y=-3}}, - {surface=1,position={x=3,y=-3}}, - {surface=1,position={x=-3,y=3}}, - {surface=1,position={x=3,y=3}} - } + { surface = 1, position = { x = -3, y = -3 } }, + { surface = 1, position = { x = 3, y = -3 } }, + { surface = 1, position = { x = -3, y = 3 } }, + { surface = 1, position = { x = 3, y = 3 } }, + }, }, afk_belts = { --- @setting afk_belts Settings relating to adding afk belts to spawn enabled = true, --- @setting enabled Whether afk belts will be added to spawn - belt_type = 'transport-belt', --- @setting belt_type The belt to be used as afk belts + belt_type = "transport-belt", --- @setting belt_type The belt to be used as afk belts protected = true, --- @setting protected Whether belts will be protected from player interaction - offset = {x=0, y=0}, --- @setting offset The position offset to apply to afk belts - locations={ --- @setting locations The locations to spawn afk belts at, given as the top left position - {-5,-5}, {5,-5}, - {-5,5}, {5,5} - } + offset = { x = 0, y = 0 }, --- @setting offset The position offset to apply to afk belts + locations = { --- @setting locations The locations to spawn afk belts at, given as the top left position + { -5, -5 }, { 5, -5 }, + { -5, 5 }, { 5, 5 }, + }, }, water = { --- @setting water Settings relating to adding water to spawn enabled = true, --- @setting enabled Whether water tiles will be added to spawn - water_tile = 'water-mud', --- @setting water_tile The tile to be used as the water tile - offset = {x=0, y=0}, --- @setting offset The position offset to apply to water tiles + water_tile = "water-mud", --- @setting water_tile The tile to be used as the water tile + offset = { x = 0, y = 0 }, --- @setting offset The position offset to apply to water tiles locations = { --- @setting locations The location of the water tiles {x,y} -- Each is a 3x3 with the closest tile to 0,0 removed - {7,8}, {7,9}, {8,7}, {8,8}, {8,9}, {9,7}, {9,8}, {9,9}, -- Bottom Right - {7,-9}, {7,-10}, {8,-8}, {8,-9}, {8,-10}, {9,-8}, { 9,-9}, {9,-10}, -- Top Right - {-8,-9}, {-8,-10}, {-9,-8}, {-9,-9}, {-9,-10}, {-10,-8}, {-10,-9}, {-10,-10}, -- Top Left - {-8,8}, {-8,9}, {-9,7}, {-9,8}, {-9,9}, {-10,7}, {-10,8}, {-10,9}, -- Bottom Left - } + { 7, 8 }, { 7, 9 }, { 8, 7 }, { 8, 8 }, { 8, 9 }, { 9, 7 }, { 9, 8 }, { 9, 9 }, -- Bottom Right + { 7, -9 }, { 7, -10 }, { 8, -8 }, { 8, -9 }, { 8, -10 }, { 9, -8 }, { 9, -9 }, { 9, -10 }, -- Top Right + { -8, -9 }, { -8, -10 }, { -9, -8 }, { -9, -9 }, { -9, -10 }, { -10, -8 }, { -10, -9 }, { -10, -10 }, -- Top Left + { -8, 8 }, { -8, 9 }, { -9, 7 }, { -9, 8 }, { -9, 9 }, { -10, 7 }, { -10, 8 }, { -10, 9 }, -- Bottom Left + }, }, entities = { --- @setting entities Settings relating to adding entities to spawn - enabled = true, --- @setting enabled Whether entities will be added to spawn + enabled = true, --- @setting enabled Whether entities will be added to spawn protected = true, --- @setting protected Whether entities will be protected from player interaction operable = true, --- @setting operable Whether entities can be opened by players, must be true if chests are used - offset = {x=0, y=-2}, --- @setting offset The position offset to apply to entities + offset = { x = 0, y = -2 }, --- @setting offset The position offset to apply to entities locations = { --- @setting locations The location and names of entities {name,x,y} - {'stone-wall',-10,-5},{'stone-wall',-10,-4},{'stone-wall',-10,-3},{'stone-wall',-10,-2},{'stone-wall',-10,-1},{'stone-wall',-10,0},{'stone-wall',-10,3},{'stone-wall',-10,4},{'stone-wall',-10,5}, - {'stone-wall',-10,6},{'stone-wall',-10,7},{'stone-wall',-10,8},{'small-lamp',-8,-4},{'small-lamp',-8,-1},{'iron-chest',-8,0},{'iron-chest',-8,3},{'small-lamp',-8,4}, - {'small-lamp',-8,7},{'stone-wall',-7,-8},{'small-electric-pole',-7,-2},{'iron-chest',-7,0},{'iron-chest',-7,3},{'small-electric-pole',-7,5},{'stone-wall',-7,11},{'stone-wall',-6,-8},{'small-lamp',-6,-6}, - {'iron-chest',-6,0},{'iron-chest',-6,3},{'small-lamp',-6,9},{'stone-wall',-6,11},{'stone-wall',-5,-8},{'small-lamp',-5,-1},{'iron-chest',-5,0},{'iron-chest',-5,3},{'small-lamp',-5,4},{'stone-wall',-5,11}, - {'stone-wall',-4,-8},{'small-electric-pole',-4,-5},{'iron-chest',-4,0},{'iron-chest',-4,3},{'small-electric-pole',-4,8},{'stone-wall',-4,11},{'stone-wall',-3,-8},{'small-lamp',-3,-6},{'small-lamp',-3,-3},{'small-lamp',-3,6}, - {'small-lamp',-3,9},{'stone-wall',-3,11},{'stone-wall',-2,-8},{'iron-chest',-2,-6},{'iron-chest',-2,-5},{'iron-chest',-2,-4},{'iron-chest',-2,-3},{'iron-chest',-2,-2},{'iron-chest',-2,5},{'iron-chest',-2,6}, - {'iron-chest',-2,7},{'iron-chest',-2,8},{'iron-chest',-2,9},{'stone-wall',-2,11},{'stone-wall',1,-8},{'iron-chest',1,-6}, - {'iron-chest',1,-5},{'iron-chest',1,-4},{'iron-chest',1,-3},{'iron-chest',1,-2},{'iron-chest',1,5},{'iron-chest',1,6},{'iron-chest',1,7},{'iron-chest',1,8},{'iron-chest',1,9},{'stone-wall',1,11}, - {'stone-wall',2,-8},{'small-lamp',2,-6},{'small-lamp',2,-3},{'small-lamp',2,6},{'small-lamp',2,9},{'stone-wall',2,11},{'stone-wall',3,-8},{'small-electric-pole',3,-5},{'iron-chest',3,0},{'iron-chest',3,3}, - {'small-electric-pole',3,8},{'stone-wall',3,11},{'stone-wall',4,-8},{'small-lamp',4,-1},{'iron-chest',4,0},{'iron-chest',4,3},{'small-lamp',4,4},{'stone-wall',4,11},{'stone-wall',5,-8},{'small-lamp',5,-6}, - {'iron-chest',5,0},{'iron-chest',5,3},{'small-lamp',5,9},{'stone-wall',5,11},{'stone-wall',6,-8},{'small-electric-pole',6,-2},{'iron-chest',6,0},{'iron-chest',6,3},{'small-electric-pole',6,5},{'stone-wall',6,11}, - {'small-lamp',7,-4},{'small-lamp',7,-1},{'iron-chest',7,0},{'iron-chest',7,3},{'small-lamp',7,4},{'small-lamp',7,7},{'stone-wall',9,-5}, - {'stone-wall',9,-4},{'stone-wall',9,-3},{'stone-wall',9,-2},{'stone-wall',9,-1},{'stone-wall',9,0},{'stone-wall',9,3},{'stone-wall',9,4},{'stone-wall',9,5},{'stone-wall',9,6},{'stone-wall',9,7}, - {'stone-wall',9,8} - } + { "stone-wall", -10, -5 }, { "stone-wall", -10, -4 }, { "stone-wall", -10, -3 }, { "stone-wall", -10, -2 }, { "stone-wall", -10, -1 }, { "stone-wall", -10, 0 }, { "stone-wall", -10, 3 }, { "stone-wall", -10, 4 }, { "stone-wall", -10, 5 }, + { "stone-wall", -10, 6 }, { "stone-wall", -10, 7 }, { "stone-wall", -10, 8 }, { "small-lamp", -8, -4 }, { "small-lamp", -8, -1 }, { "iron-chest", -8, 0 }, { "iron-chest", -8, 3 }, { "small-lamp", -8, 4 }, + { "small-lamp", -8, 7 }, { "stone-wall", -7, -8 }, { "small-electric-pole", -7, -2 }, { "iron-chest", -7, 0 }, { "iron-chest", -7, 3 }, { "small-electric-pole", -7, 5 }, { "stone-wall", -7, 11 }, { "stone-wall", -6, -8 }, { "small-lamp", -6, -6 }, + { "iron-chest", -6, 0 }, { "iron-chest", -6, 3 }, { "small-lamp", -6, 9 }, { "stone-wall", -6, 11 }, { "stone-wall", -5, -8 }, { "small-lamp", -5, -1 }, { "iron-chest", -5, 0 }, { "iron-chest", -5, 3 }, { "small-lamp", -5, 4 }, { "stone-wall", -5, 11 }, + { "stone-wall", -4, -8 }, { "small-electric-pole", -4, -5 }, { "iron-chest", -4, 0 }, { "iron-chest", -4, 3 }, { "small-electric-pole", -4, 8 }, { "stone-wall", -4, 11 }, { "stone-wall", -3, -8 }, { "small-lamp", -3, -6 }, { "small-lamp", -3, -3 }, { "small-lamp", -3, 6 }, + { "small-lamp", -3, 9 }, { "stone-wall", -3, 11 }, { "stone-wall", -2, -8 }, { "iron-chest", -2, -6 }, { "iron-chest", -2, -5 }, { "iron-chest", -2, -4 }, { "iron-chest", -2, -3 }, { "iron-chest", -2, -2 }, { "iron-chest", -2, 5 }, { "iron-chest", -2, 6 }, + { "iron-chest", -2, 7 }, { "iron-chest", -2, 8 }, { "iron-chest", -2, 9 }, { "stone-wall", -2, 11 }, { "stone-wall", 1, -8 }, { "iron-chest", 1, -6 }, + { "iron-chest", 1, -5 }, { "iron-chest", 1, -4 }, { "iron-chest", 1, -3 }, { "iron-chest", 1, -2 }, { "iron-chest", 1, 5 }, { "iron-chest", 1, 6 }, { "iron-chest", 1, 7 }, { "iron-chest", 1, 8 }, { "iron-chest", 1, 9 }, { "stone-wall", 1, 11 }, + { "stone-wall", 2, -8 }, { "small-lamp", 2, -6 }, { "small-lamp", 2, -3 }, { "small-lamp", 2, 6 }, { "small-lamp", 2, 9 }, { "stone-wall", 2, 11 }, { "stone-wall", 3, -8 }, { "small-electric-pole", 3, -5 }, { "iron-chest", 3, 0 }, { "iron-chest", 3, 3 }, + { "small-electric-pole", 3, 8 }, { "stone-wall", 3, 11 }, { "stone-wall", 4, -8 }, { "small-lamp", 4, -1 }, { "iron-chest", 4, 0 }, { "iron-chest", 4, 3 }, { "small-lamp", 4, 4 }, { "stone-wall", 4, 11 }, { "stone-wall", 5, -8 }, { "small-lamp", 5, -6 }, + { "iron-chest", 5, 0 }, { "iron-chest", 5, 3 }, { "small-lamp", 5, 9 }, { "stone-wall", 5, 11 }, { "stone-wall", 6, -8 }, { "small-electric-pole", 6, -2 }, { "iron-chest", 6, 0 }, { "iron-chest", 6, 3 }, { "small-electric-pole", 6, 5 }, { "stone-wall", 6, 11 }, + { "small-lamp", 7, -4 }, { "small-lamp", 7, -1 }, { "iron-chest", 7, 0 }, { "iron-chest", 7, 3 }, { "small-lamp", 7, 4 }, { "small-lamp", 7, 7 }, { "stone-wall", 9, -5 }, + { "stone-wall", 9, -4 }, { "stone-wall", 9, -3 }, { "stone-wall", 9, -2 }, { "stone-wall", 9, -1 }, { "stone-wall", 9, 0 }, { "stone-wall", 9, 3 }, { "stone-wall", 9, 4 }, { "stone-wall", 9, 5 }, { "stone-wall", 9, 6 }, { "stone-wall", 9, 7 }, + { "stone-wall", 9, 8 }, + }, }, pattern = { enabled = true, --- @setting enabled Whether pattern tiles will be added to spawn - pattern_tile = 'stone-path', --- @setting pattern_tile The tile to be used for the pattern - offset = {x=0, y=-2}, --- @setting offset The position offset to apply to pattern tiles + pattern_tile = "stone-path", --- @setting pattern_tile The tile to be used for the pattern + offset = { x = 0, y = -2 }, --- @setting offset The position offset to apply to pattern tiles locations = { --- @setting locations The location of the pattern tiles {x,y} - {-49,-3},{-49,-2},{-49,1},{-49,2},{-49,5},{-49,6},{-48,-4},{-48,-3},{-48,-2},{-48,1},{-48,2},{-48,5},{-48,6},{-48,7},{-47,-7},{-47,-6},{-47,-5},{-47,-4},{-47,-3},{-47,-2},{-47,5},{-47,6},{-47,7},{-47,8},{-47,9},{-47,10},{-46,-8},{-46,-7},{-46,-6},{-46,-5}, - {-46,-4},{-46,-3},{-46,-2},{-46,-1},{-46,4},{-46,5},{-46,6},{-46,7},{-46,8},{-46,9},{-46,10},{-46,11},{-45,-17},{-45,-16},{-45,-15},{-45,-14},{-45,-13},{-45,-12},{-45,-9},{-45,-8},{-45,-7},{-45,-2},{-45,-1},{-45,0},{-45,1},{-45,2},{-45,3},{-45,4},{-45,5},{-45,10}, - {-45,11},{-45,12},{-45,15},{-45,16},{-45,17},{-45,18},{-45,19},{-45,20},{-44,-18},{-44,-17},{-44,-16},{-44,-15},{-44,-14},{-44,-13},{-44,-12},{-44,-9},{-44,-8},{-44,-1},{-44,0},{-44,1},{-44,2},{-44,3},{-44,4},{-44,11},{-44,12},{-44,15},{-44,16},{-44,17},{-44,18},{-44,19}, - {-44,20},{-44,21},{-43,-19},{-43,-18},{-43,-17},{-43,-1},{-43,0},{-43,1},{-43,2},{-43,3},{-43,4},{-43,20},{-43,21},{-43,22},{-42,-19},{-42,-18},{-42,-1},{-42,0},{-42,1},{-42,2},{-42,3},{-42,4},{-42,21},{-42,22},{-41,-25},{-41,-24},{-41,-19},{-41,-18},{-41,-13},{-41,-12}, - {-41,-11},{-41,-10},{-41,-5},{-41,-4},{-41,7},{-41,8},{-41,13},{-41,14},{-41,15},{-41,16},{-41,21},{-41,22},{-41,27},{-41,28},{-40,-26},{-40,-25},{-40,-24},{-40,-20},{-40,-19},{-40,-18},{-40,-13},{-40,-12},{-40,-11},{-40,-10},{-40,-5},{-40,-4},{-40,7},{-40,8},{-40,13},{-40,14}, - {-40,15},{-40,16},{-40,21},{-40,22},{-40,23},{-40,27},{-40,28},{-40,29},{-39,-27},{-39,-26},{-39,-25},{-39,-24},{-39,-21},{-39,-20},{-39,-19},{-39,-13},{-39,-12},{-39,-5},{-39,-4},{-39,-3},{-39,-2},{-39,-1},{-39,0},{-39,1},{-39,2},{-39,3},{-39,4},{-39,5},{-39,6},{-39,7}, - {-39,8},{-39,15},{-39,16},{-39,22},{-39,23},{-39,24},{-39,27},{-39,28},{-39,29},{-39,30},{-38,-27},{-38,-26},{-38,-25},{-38,-24},{-38,-21},{-38,-20},{-38,-13},{-38,-12},{-38,-5},{-38,-4},{-38,-3},{-38,-2},{-38,-1},{-38,0},{-38,1},{-38,2},{-38,3},{-38,4},{-38,5},{-38,6}, - {-38,7},{-38,8},{-38,15},{-38,16},{-38,23},{-38,24},{-38,27},{-38,28},{-38,29},{-38,30},{-37,-17},{-37,-16},{-37,-13},{-37,-12},{-37,-11},{-37,-10},{-37,-4},{-37,-3},{-37,-2},{-37,-1},{-37,0},{-37,3},{-37,4},{-37,5},{-37,6},{-37,7},{-37,13},{-37,14},{-37,15},{-37,16}, - {-37,19},{-37,20},{-36,-17},{-36,-16},{-36,-13},{-36,-12},{-36,-11},{-36,-10},{-36,-9},{-36,-3},{-36,-2},{-36,-1},{-36,0},{-36,3},{-36,4},{-36,5},{-36,6},{-36,12},{-36,13},{-36,14},{-36,15},{-36,16},{-36,19},{-36,20},{-35,-29},{-35,-28},{-35,-23},{-35,-22},{-35,-17},{-35,-16}, - {-35,-12},{-35,-11},{-35,-10},{-35,-9},{-35,-8},{-35,11},{-35,12},{-35,13},{-35,14},{-35,15},{-35,19},{-35,20},{-35,25},{-35,26},{-35,31},{-35,32},{-34,-30},{-34,-29},{-34,-28},{-34,-23},{-34,-22},{-34,-17},{-34,-16},{-34,-15},{-34,-11},{-34,-10},{-34,-9},{-34,-8},{-34,11},{-34,12}, - {-34,13},{-34,14},{-34,18},{-34,19},{-34,20},{-34,25},{-34,26},{-34,31},{-34,32},{-34,33},{-33,-31},{-33,-30},{-33,-29},{-33,-28},{-33,-23},{-33,-22},{-33,-16},{-33,-15},{-33,-14},{-33,-5},{-33,-4},{-33,-1},{-33,0},{-33,3},{-33,4},{-33,7},{-33,8},{-33,17},{-33,18},{-33,19}, - {-33,25},{-33,26},{-33,31},{-33,32},{-33,33},{-33,34},{-32,-32},{-32,-31},{-32,-30},{-32,-29},{-32,-28},{-32,-27},{-32,-23},{-32,-22},{-32,-21},{-32,-15},{-32,-14},{-32,-6},{-32,-5},{-32,-4},{-32,-1},{-32,0},{-32,3},{-32,4},{-32,7},{-32,8},{-32,9},{-32,17},{-32,18},{-32,24}, - {-32,25},{-32,26},{-32,30},{-32,31},{-32,32},{-32,33},{-32,34},{-32,35},{-31,-33},{-31,-32},{-31,-31},{-31,-30},{-31,-29},{-31,-28},{-31,-27},{-31,-26},{-31,-22},{-31,-21},{-31,-20},{-31,-19},{-31,-18},{-31,-11},{-31,-10},{-31,-9},{-31,-8},{-31,-7},{-31,-6},{-31,-5},{-31,-1},{-31,0}, - {-31,1},{-31,2},{-31,3},{-31,4},{-31,8},{-31,9},{-31,10},{-31,11},{-31,12},{-31,13},{-31,14},{-31,21},{-31,22},{-31,23},{-31,24},{-31,25},{-31,29},{-31,30},{-31,31},{-31,32},{-31,33},{-31,34},{-31,35},{-31,36},{-30,-33},{-30,-32},{-30,-31},{-30,-30},{-30,-29},{-30,-28}, - {-30,-27},{-30,-26},{-30,-21},{-30,-20},{-30,-19},{-30,-18},{-30,-11},{-30,-10},{-30,-9},{-30,-8},{-30,-7},{-30,-6},{-30,-1},{-30,0},{-30,1},{-30,2},{-30,3},{-30,4},{-30,9},{-30,10},{-30,11},{-30,12},{-30,13},{-30,14},{-30,21},{-30,22},{-30,23},{-30,24},{-30,29},{-30,30}, - {-30,31},{-30,32},{-30,33},{-30,34},{-30,35},{-30,36},{-29,-37},{-29,-36},{-29,-30},{-29,-29},{-29,-28},{-29,-27},{-29,-26},{-29,-15},{-29,-14},{-29,-10},{-29,-9},{-29,-8},{-29,-7},{-29,10},{-29,11},{-29,12},{-29,13},{-29,17},{-29,18},{-29,29},{-29,30},{-29,31},{-29,32},{-29,33}, - {-29,39},{-29,40},{-28,-38},{-28,-37},{-28,-36},{-28,-29},{-28,-28},{-28,-27},{-28,-26},{-28,-16},{-28,-15},{-28,-14},{-28,-9},{-28,-8},{-28,11},{-28,12},{-28,17},{-28,18},{-28,19},{-28,29},{-28,30},{-28,31},{-28,32},{-28,39},{-28,40},{-28,41},{-27,-39},{-27,-38},{-27,-37},{-27,-36}, - {-27,-23},{-27,-22},{-27,-19},{-27,-18},{-27,-17},{-27,-16},{-27,-15},{-27,-5},{-27,-4},{-27,-1},{-27,0},{-27,1},{-27,2},{-27,3},{-27,4},{-27,7},{-27,8},{-27,18},{-27,19},{-27,20},{-27,21},{-27,22},{-27,25},{-27,26},{-27,39},{-27,40},{-27,41},{-27,42},{-26,-39},{-26,-38}, - {-26,-37},{-26,-36},{-26,-24},{-26,-23},{-26,-22},{-26,-19},{-26,-18},{-26,-17},{-26,-16},{-26,-6},{-26,-5},{-26,-4},{-26,-1},{-26,0},{-26,1},{-26,2},{-26,3},{-26,4},{-26,7},{-26,8},{-26,9},{-26,19},{-26,20},{-26,21},{-26,22},{-26,25},{-26,26},{-26,27},{-26,39},{-26,40}, - {-26,41},{-26,42},{-25,-33},{-25,-32},{-25,-31},{-25,-30},{-25,-25},{-25,-24},{-25,-23},{-25,-22},{-25,-19},{-25,-18},{-25,-17},{-25,-9},{-25,-8},{-25,-7},{-25,-6},{-25,-5},{-25,-4},{-25,-1},{-25,0},{-25,1},{-25,2},{-25,3},{-25,4},{-25,7},{-25,8},{-25,9},{-25,10},{-25,11}, - {-25,12},{-25,20},{-25,21},{-25,22},{-25,25},{-25,26},{-25,27},{-25,28},{-25,33},{-25,34},{-25,35},{-25,36},{-24,-33},{-24,-32},{-24,-31},{-24,-30},{-24,-29},{-24,-25},{-24,-24},{-24,-23},{-24,-22},{-24,-19},{-24,-18},{-24,-9},{-24,-8},{-24,-7},{-24,-6},{-24,-5},{-24,-4},{-24,-1}, - {-24,0},{-24,1},{-24,2},{-24,3},{-24,4},{-24,7},{-24,8},{-24,9},{-24,10},{-24,11},{-24,12},{-24,21},{-24,22},{-24,25},{-24,26},{-24,27},{-24,28},{-24,32},{-24,33},{-24,34},{-24,35},{-24,36},{-23,-37},{-23,-36},{-23,-30},{-23,-29},{-23,-28},{-23,-19},{-23,-18},{-23,-15}, - {-23,-14},{-23,-9},{-23,-8},{-23,-7},{-23,-6},{-23,-5},{-23,0},{-23,1},{-23,2},{-23,3},{-23,8},{-23,9},{-23,10},{-23,11},{-23,12},{-23,17},{-23,18},{-23,21},{-23,22},{-23,31},{-23,32},{-23,33},{-23,39},{-23,40},{-22,-38},{-22,-37},{-22,-36},{-22,-29},{-22,-28},{-22,-19}, - {-22,-18},{-22,-15},{-22,-14},{-22,-13},{-22,-9},{-22,-8},{-22,-7},{-22,-6},{-22,1},{-22,2},{-22,9},{-22,10},{-22,11},{-22,12},{-22,16},{-22,17},{-22,18},{-22,21},{-22,22},{-22,31},{-22,32},{-22,39},{-22,40},{-22,41},{-21,-41},{-21,-40},{-21,-39},{-21,-38},{-21,-37},{-21,-29}, - {-21,-28},{-21,-25},{-21,-24},{-21,-23},{-21,-22},{-21,-21},{-21,-20},{-21,-19},{-21,-18},{-21,-15},{-21,-14},{-21,-13},{-21,-12},{-21,-3},{-21,-2},{-21,5},{-21,6},{-21,15},{-21,16},{-21,17},{-21,18},{-21,21},{-21,22},{-21,23},{-21,24},{-21,25},{-21,26},{-21,27},{-21,28},{-21,31}, - {-21,32},{-21,40},{-21,41},{-21,42},{-21,43},{-21,44},{-20,-42},{-20,-41},{-20,-40},{-20,-39},{-20,-38},{-20,-29},{-20,-28},{-20,-25},{-20,-24},{-20,-23},{-20,-22},{-20,-21},{-20,-20},{-20,-19},{-20,-18},{-20,-15},{-20,-14},{-20,-13},{-20,-12},{-20,-3},{-20,-2},{-20,-1},{-20,4},{-20,5}, - {-20,6},{-20,15},{-20,16},{-20,17},{-20,18},{-20,21},{-20,22},{-20,23},{-20,24},{-20,25},{-20,26},{-20,27},{-20,28},{-20,31},{-20,32},{-20,41},{-20,42},{-20,43},{-20,44},{-20,45},{-19,-43},{-19,-42},{-19,-41},{-19,-35},{-19,-34},{-19,-33},{-19,-32},{-19,-25},{-19,-24},{-19,-23}, - {-19,-15},{-19,-14},{-19,-13},{-19,-9},{-19,-8},{-19,-7},{-19,-6},{-19,-2},{-19,-1},{-19,0},{-19,1},{-19,2},{-19,3},{-19,4},{-19,5},{-19,9},{-19,10},{-19,11},{-19,12},{-19,16},{-19,17},{-19,18},{-19,26},{-19,27},{-19,28},{-19,35},{-19,36},{-19,37},{-19,38},{-19,44}, - {-19,45},{-19,46},{-18,-43},{-18,-42},{-18,-35},{-18,-34},{-18,-33},{-18,-32},{-18,-31},{-18,-26},{-18,-25},{-18,-24},{-18,-15},{-18,-14},{-18,-10},{-18,-9},{-18,-8},{-18,-7},{-18,-6},{-18,-1},{-18,0},{-18,1},{-18,2},{-18,3},{-18,4},{-18,9},{-18,10},{-18,11},{-18,12},{-18,13}, - {-18,17},{-18,18},{-18,27},{-18,28},{-18,29},{-18,34},{-18,35},{-18,36},{-18,37},{-18,38},{-18,45},{-18,46},{-17,-43},{-17,-42},{-17,-32},{-17,-31},{-17,-30},{-17,-27},{-17,-26},{-17,-25},{-17,-21},{-17,-20},{-17,-19},{-17,-18},{-17,-17},{-17,-16},{-17,-15},{-17,-14},{-17,-11},{-17,-10}, - {-17,-9},{-17,-8},{-17,-7},{-17,-6},{-17,0},{-17,1},{-17,2},{-17,3},{-17,9},{-17,10},{-17,11},{-17,12},{-17,13},{-17,14},{-17,17},{-17,18},{-17,19},{-17,20},{-17,21},{-17,22},{-17,23},{-17,24},{-17,28},{-17,29},{-17,30},{-17,33},{-17,34},{-17,35},{-17,45},{-17,46}, - {-16,-43},{-16,-42},{-16,-31},{-16,-30},{-16,-27},{-16,-26},{-16,-21},{-16,-20},{-16,-19},{-16,-18},{-16,-17},{-16,-16},{-16,-15},{-16,-14},{-16,-11},{-16,-10},{-16,-9},{-16,-8},{-16,-7},{-16,-6},{-16,1},{-16,2},{-16,9},{-16,10},{-16,11},{-16,12},{-16,13},{-16,14},{-16,17},{-16,18}, - {-16,19},{-16,20},{-16,21},{-16,22},{-16,23},{-16,24},{-16,29},{-16,30},{-16,33},{-16,34},{-16,45},{-16,46},{-15,-43},{-15,-42},{-15,-39},{-15,-38},{-15,-37},{-15,-36},{-15,-35},{-15,-34},{-15,-20},{-15,-19},{-15,-18},{-15,-17},{-15,-10},{-15,-9},{-15,-8},{-15,-7},{-15,-3},{-15,-2}, - {-15,1},{-15,2},{-15,5},{-15,6},{-15,10},{-15,11},{-15,12},{-15,13},{-15,20},{-15,21},{-15,22},{-15,23},{-15,37},{-15,38},{-15,39},{-15,40},{-15,41},{-15,42},{-15,45},{-15,46},{-14,-43},{-14,-42},{-14,-39},{-14,-38},{-14,-37},{-14,-36},{-14,-35},{-14,-34},{-14,-33},{-14,-19}, - {-14,-18},{-14,-9},{-14,-8},{-14,-4},{-14,-3},{-14,-2},{-14,1},{-14,2},{-14,5},{-14,6},{-14,7},{-14,11},{-14,12},{-14,21},{-14,22},{-14,36},{-14,37},{-14,38},{-14,39},{-14,40},{-14,41},{-14,42},{-14,45},{-14,46},{-13,-39},{-13,-38},{-13,-35},{-13,-34},{-13,-33},{-13,-32}, - {-13,-29},{-13,-28},{-13,-15},{-13,-14},{-13,-5},{-13,-4},{-13,-3},{-13,-2},{-13,5},{-13,6},{-13,7},{-13,8},{-13,17},{-13,18},{-13,31},{-13,32},{-13,35},{-13,36},{-13,37},{-13,38},{-13,41},{-13,42},{-12,-39},{-12,-38},{-12,-35},{-12,-34},{-12,-33},{-12,-32},{-12,-29},{-12,-28}, - {-12,-27},{-12,-16},{-12,-15},{-12,-14},{-12,-13},{-12,-5},{-12,-4},{-12,-3},{-12,-2},{-12,5},{-12,6},{-12,7},{-12,8},{-12,16},{-12,17},{-12,18},{-12,19},{-12,30},{-12,31},{-12,32},{-12,35},{-12,36},{-12,37},{-12,38},{-12,41},{-12,42},{-11,-43},{-11,-42},{-11,-34},{-11,-33}, - {-11,-32},{-11,-29},{-11,-28},{-11,-27},{-11,-26},{-11,-23},{-11,-22},{-11,-21},{-11,-20},{-11,-17},{-11,-16},{-11,-15},{-11,-14},{-11,-13},{-11,-12},{-11,-9},{-11,-8},{-11,1},{-11,2},{-11,11},{-11,12},{-11,15},{-11,16},{-11,17},{-11,18},{-11,19},{-11,20},{-11,23},{-11,24},{-11,25}, - {-11,26},{-11,29},{-11,30},{-11,31},{-11,32},{-11,35},{-11,36},{-11,37},{-11,45},{-11,46},{-10,-44},{-10,-43},{-10,-42},{-10,-33},{-10,-32},{-10,-29},{-10,-28},{-10,-27},{-10,-26},{-10,-23},{-10,-22},{-10,-21},{-10,-20},{-10,-17},{-10,-16},{-10,-15},{-10,-14},{-10,-13},{-10,-12},{-10,-9}, - {-10,-8},{-10,-7},{-10,0},{-10,1},{-10,2},{-10,3},{-10,10},{-10,11},{-10,12},{-10,15},{-10,16},{-10,17},{-10,18},{-10,19},{-10,20},{-10,23},{-10,24},{-10,25},{-10,26},{-10,29},{-10,30},{-10,31},{-10,32},{-10,35},{-10,36},{-10,45},{-10,46},{-10,47},{-9,-45},{-9,-44}, - {-9,-43},{-9,-29},{-9,-28},{-9,-27},{-9,-23},{-9,-22},{-9,-21},{-9,-20},{-9,-17},{-9,-16},{-9,-15},{-9,-14},{-9,-13},{-9,-8},{-9,-7},{-9,-6},{-9,-5},{-9,-1},{-9,0},{-9,1},{-9,2},{-9,3},{-9,4},{-9,8},{-9,9},{-9,10},{-9,11},{-9,16},{-9,17},{-9,18}, - {-9,19},{-9,20},{-9,23},{-9,24},{-9,25},{-9,26},{-9,30},{-9,31},{-9,32},{-9,46},{-9,47},{-9,48},{-8,-45},{-8,-44},{-8,-30},{-8,-29},{-8,-28},{-8,-24},{-8,-23},{-8,-22},{-8,-21},{-8,-20},{-8,-17},{-8,-16},{-8,-15},{-8,-14},{-8,-7},{-8,-6},{-8,-5},{-8,-4}, - {-8,-1},{-8,0},{-8,1},{-8,2},{-8,3},{-8,4},{-8,7},{-8,8},{-8,9},{-8,10},{-8,17},{-8,18},{-8,19},{-8,20},{-8,23},{-8,24},{-8,25},{-8,26},{-8,27},{-8,31},{-8,32},{-8,33},{-8,47},{-8,48},{-7,-45},{-7,-44},{-7,-39},{-7,-38},{-7,-37},{-7,-36}, - {-7,-31},{-7,-30},{-7,-29},{-7,-25},{-7,-24},{-7,-23},{-7,-22},{-7,-21},{-7,-11},{-7,-10},{-7,-7},{-7,-6},{-7,-5},{-7,-4},{-7,7},{-7,8},{-7,9},{-7,10},{-7,13},{-7,14},{-7,24},{-7,25},{-7,26},{-7,27},{-7,28},{-7,32},{-7,33},{-7,34},{-7,39},{-7,40}, - {-7,41},{-7,42},{-7,47},{-7,48},{-6,-46},{-6,-45},{-6,-44},{-6,-39},{-6,-38},{-6,-37},{-6,-36},{-6,-35},{-6,-31},{-6,-30},{-6,-25},{-6,-24},{-6,-23},{-6,-22},{-6,-12},{-6,-11},{-6,-10},{-6,-6},{-6,-5},{-6,8},{-6,9},{-6,13},{-6,14},{-6,15},{-6,25},{-6,26}, - {-6,27},{-6,28},{-6,33},{-6,34},{-6,38},{-6,39},{-6,40},{-6,41},{-6,42},{-6,47},{-6,48},{-6,49},{-5,-47},{-5,-46},{-5,-45},{-5,-44},{-5,-37},{-5,-36},{-5,-35},{-5,-34},{-5,-19},{-5,-18},{-5,-13},{-5,-12},{-5,-11},{-5,-10},{-5,-1},{-5,0},{-5,1},{-5,2}, - {-5,3},{-5,4},{-5,13},{-5,14},{-5,15},{-5,16},{-5,21},{-5,22},{-5,37},{-5,38},{-5,39},{-5,40},{-5,47},{-5,48},{-5,49},{-5,50},{-4,-47},{-4,-46},{-4,-45},{-4,-44},{-4,-43},{-4,-37},{-4,-36},{-4,-35},{-4,-34},{-4,-19},{-4,-18},{-4,-17},{-4,-13},{-4,-12}, - {-4,-11},{-4,-10},{-4,-2},{-4,-1},{-4,0},{-4,1},{-4,2},{-4,3},{-4,4},{-4,5},{-4,13},{-4,14},{-4,15},{-4,16},{-4,20},{-4,21},{-4,22},{-4,37},{-4,38},{-4,39},{-4,40},{-4,46},{-4,47},{-4,48},{-4,49},{-4,50},{-3,-44},{-3,-43},{-3,-42},{-3,-41}, - {-3,-40},{-3,-37},{-3,-36},{-3,-35},{-3,-34},{-3,-31},{-3,-30},{-3,-29},{-3,-28},{-3,-25},{-3,-24},{-3,-23},{-3,-22},{-3,-18},{-3,-17},{-3,-16},{-3,-7},{-3,-6},{-3,-3},{-3,-2},{-3,-1},{-3,0},{-3,3},{-3,4},{-3,5},{-3,6},{-3,9},{-3,10},{-3,19},{-3,20}, - {-3,21},{-3,25},{-3,26},{-3,27},{-3,28},{-3,31},{-3,32},{-3,33},{-3,34},{-3,37},{-3,38},{-3,39},{-3,40},{-3,43},{-3,44},{-3,45},{-3,46},{-3,47},{-2,-43},{-2,-42},{-2,-41},{-2,-40},{-2,-37},{-2,-36},{-2,-35},{-2,-34},{-2,-31},{-2,-30},{-2,-29},{-2,-28}, - {-2,-25},{-2,-24},{-2,-23},{-2,-22},{-2,-21},{-2,-17},{-2,-16},{-2,-15},{-2,-8},{-2,-7},{-2,-6},{-2,-3},{-2,-2},{-2,-1},{-2,0},{-2,3},{-2,4},{-2,5},{-2,6},{-2,9},{-2,10},{-2,11},{-2,18},{-2,19},{-2,20},{-2,24},{-2,25},{-2,26},{-2,27},{-2,28}, - {-2,31},{-2,32},{-2,33},{-2,34},{-2,37},{-2,38},{-2,39},{-2,40},{-2,43},{-2,44},{-2,45},{-2,46},{-1,-47},{-1,-46},{-1,-43},{-1,-42},{-1,-41},{-1,-40},{-1,-37},{-1,-36},{-1,-29},{-1,-28},{-1,-25},{-1,-24},{-1,-23},{-1,-22},{-1,-21},{-1,-20},{-1,-17},{-1,-16}, - {-1,-15},{-1,-14},{-1,-13},{-1,-12},{-1,-9},{-1,-8},{-1,-7},{-1,-6},{-1,-3},{-1,-2},{-1,5},{-1,6},{-1,9},{-1,10},{-1,11},{-1,12},{-1,15},{-1,16},{-1,17},{-1,18},{-1,19},{-1,20},{-1,23},{-1,24},{-1,25},{-1,26},{-1,27},{-1,28},{-1,31},{-1,32}, - {-1,39},{-1,40},{-1,43},{-1,44},{-1,45},{-1,46},{-1,49},{-1,50},{0,-47},{0,-46},{0,-43},{0,-42},{0,-41},{0,-40},{0,-37},{0,-36},{0,-29},{0,-28},{0,-25},{0,-24},{0,-23},{0,-22},{0,-21},{0,-20},{0,-17},{0,-16},{0,-15},{0,-14},{0,-13},{0,-12}, - {0,-9},{0,-8},{0,-7},{0,-6},{0,-3},{0,-2},{0,5},{0,6},{0,9},{0,10},{0,11},{0,12},{0,15},{0,16},{0,17},{0,18},{0,19},{0,20},{0,23},{0,24},{0,25},{0,26},{0,27},{0,28},{0,31},{0,32},{0,39},{0,40},{0,43},{0,44}, - {0,45},{0,46},{0,49},{0,50},{1,-43},{1,-42},{1,-41},{1,-40},{1,-37},{1,-36},{1,-35},{1,-34},{1,-31},{1,-30},{1,-29},{1,-28},{1,-25},{1,-24},{1,-23},{1,-22},{1,-21},{1,-17},{1,-16},{1,-15},{1,-8},{1,-7},{1,-6},{1,-3},{1,-2},{1,-1}, - {1,0},{1,3},{1,4},{1,5},{1,6},{1,9},{1,10},{1,11},{1,18},{1,19},{1,20},{1,24},{1,25},{1,26},{1,27},{1,28},{1,31},{1,32},{1,33},{1,34},{1,37},{1,38},{1,39},{1,40},{1,43},{1,44},{1,45},{1,46},{2,-44},{2,-43}, - {2,-42},{2,-41},{2,-40},{2,-37},{2,-36},{2,-35},{2,-34},{2,-31},{2,-30},{2,-29},{2,-28},{2,-25},{2,-24},{2,-23},{2,-22},{2,-18},{2,-17},{2,-16},{2,-7},{2,-6},{2,-3},{2,-2},{2,-1},{2,0},{2,3},{2,4},{2,5},{2,6},{2,9},{2,10}, - {2,19},{2,20},{2,21},{2,25},{2,26},{2,27},{2,28},{2,31},{2,32},{2,33},{2,34},{2,37},{2,38},{2,39},{2,40},{2,43},{2,44},{2,45},{2,46},{2,47},{3,-47},{3,-46},{3,-45},{3,-44},{3,-43},{3,-37},{3,-36},{3,-35},{3,-34},{3,-19}, - {3,-18},{3,-17},{3,-13},{3,-12},{3,-11},{3,-10},{3,-2},{3,-1},{3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,13},{3,14},{3,15},{3,16},{3,20},{3,21},{3,22},{3,37},{3,38},{3,39},{3,40},{3,46},{3,47},{3,48},{3,49},{3,50}, - {4,-47},{4,-46},{4,-45},{4,-44},{4,-37},{4,-36},{4,-35},{4,-34},{4,-19},{4,-18},{4,-13},{4,-12},{4,-11},{4,-10},{4,-1},{4,0},{4,1},{4,2},{4,3},{4,4},{4,13},{4,14},{4,15},{4,16},{4,21},{4,22},{4,37},{4,38},{4,39},{4,40}, - {4,47},{4,48},{4,49},{4,50},{5,-46},{5,-45},{5,-44},{5,-39},{5,-38},{5,-37},{5,-36},{5,-35},{5,-31},{5,-30},{5,-25},{5,-24},{5,-23},{5,-22},{5,-12},{5,-11},{5,-10},{5,-6},{5,-5},{5,8},{5,9},{5,13},{5,14},{5,15},{5,25},{5,26}, - {5,27},{5,28},{5,33},{5,34},{5,38},{5,39},{5,40},{5,41},{5,42},{5,47},{5,48},{5,49},{6,-45},{6,-44},{6,-39},{6,-38},{6,-37},{6,-36},{6,-31},{6,-30},{6,-29},{6,-25},{6,-24},{6,-23},{6,-22},{6,-21},{6,-11},{6,-10},{6,-7},{6,-6}, - {6,-5},{6,-4},{6,7},{6,8},{6,9},{6,10},{6,13},{6,14},{6,24},{6,25},{6,26},{6,27},{6,28},{6,32},{6,33},{6,34},{6,39},{6,40},{6,41},{6,42},{6,47},{6,48},{7,-45},{7,-44},{7,-30},{7,-29},{7,-28},{7,-24},{7,-23},{7,-22}, - {7,-21},{7,-20},{7,-17},{7,-16},{7,-15},{7,-14},{7,-7},{7,-6},{7,-5},{7,-4},{7,-1},{7,0},{7,1},{7,2},{7,3},{7,4},{7,7},{7,8},{7,9},{7,10},{7,17},{7,18},{7,19},{7,20},{7,23},{7,24},{7,25},{7,26},{7,27},{7,31}, - {7,32},{7,33},{7,47},{7,48},{8,-45},{8,-44},{8,-43},{8,-29},{8,-28},{8,-27},{8,-23},{8,-22},{8,-21},{8,-20},{8,-17},{8,-16},{8,-15},{8,-14},{8,-13},{8,-8},{8,-7},{8,-6},{8,-5},{8,-1},{8,0},{8,1},{8,2},{8,3},{8,4},{8,8}, - {8,9},{8,10},{8,11},{8,16},{8,17},{8,18},{8,19},{8,20},{8,23},{8,24},{8,25},{8,26},{8,30},{8,31},{8,32},{8,46},{8,47},{8,48},{9,-44},{9,-43},{9,-42},{9,-33},{9,-32},{9,-29},{9,-28},{9,-27},{9,-26},{9,-23},{9,-22},{9,-21}, - {9,-20},{9,-17},{9,-16},{9,-15},{9,-14},{9,-13},{9,-12},{9,-9},{9,-8},{9,-7},{9,0},{9,1},{9,2},{9,3},{9,10},{9,11},{9,12},{9,15},{9,16},{9,17},{9,18},{9,19},{9,20},{9,23},{9,24},{9,25},{9,26},{9,29},{9,30},{9,31}, - {9,32},{9,35},{9,36},{9,45},{9,46},{9,47},{10,-43},{10,-42},{10,-34},{10,-33},{10,-32},{10,-29},{10,-28},{10,-27},{10,-26},{10,-23},{10,-22},{10,-21},{10,-20},{10,-17},{10,-16},{10,-15},{10,-14},{10,-13},{10,-12},{10,-9},{10,-8},{10,1},{10,2},{10,11}, - {10,12},{10,15},{10,16},{10,17},{10,18},{10,19},{10,20},{10,23},{10,24},{10,25},{10,26},{10,29},{10,30},{10,31},{10,32},{10,35},{10,36},{10,37},{10,45},{10,46},{11,-39},{11,-38},{11,-35},{11,-34},{11,-33},{11,-32},{11,-29},{11,-28},{11,-27},{11,-16}, - {11,-15},{11,-14},{11,-13},{11,-5},{11,-4},{11,-3},{11,-2},{11,5},{11,6},{11,7},{11,8},{11,16},{11,17},{11,18},{11,19},{11,30},{11,31},{11,32},{11,35},{11,36},{11,37},{11,38},{11,41},{11,42},{12,-39},{12,-38},{12,-35},{12,-34},{12,-33},{12,-32}, - {12,-29},{12,-28},{12,-15},{12,-14},{12,-5},{12,-4},{12,-3},{12,-2},{12,5},{12,6},{12,7},{12,8},{12,17},{12,18},{12,31},{12,32},{12,35},{12,36},{12,37},{12,38},{12,41},{12,42},{13,-43},{13,-42},{13,-39},{13,-38},{13,-37},{13,-36},{13,-35},{13,-34}, - {13,-33},{13,-19},{13,-18},{13,-9},{13,-8},{13,-4},{13,-3},{13,-2},{13,1},{13,2},{13,5},{13,6},{13,7},{13,11},{13,12},{13,21},{13,22},{13,36},{13,37},{13,38},{13,39},{13,40},{13,41},{13,42},{13,45},{13,46},{14,-43},{14,-42},{14,-39},{14,-38}, - {14,-37},{14,-36},{14,-35},{14,-34},{14,-20},{14,-19},{14,-18},{14,-17},{14,-10},{14,-9},{14,-8},{14,-7},{14,-3},{14,-2},{14,1},{14,2},{14,5},{14,6},{14,10},{14,11},{14,12},{14,13},{14,20},{14,21},{14,22},{14,23},{14,37},{14,38},{14,39},{14,40}, - {14,41},{14,42},{14,45},{14,46},{15,-43},{15,-42},{15,-31},{15,-30},{15,-27},{15,-26},{15,-21},{15,-20},{15,-19},{15,-18},{15,-17},{15,-16},{15,-15},{15,-14},{15,-11},{15,-10},{15,-9},{15,-8},{15,-7},{15,-6},{15,1},{15,2},{15,9},{15,10},{15,11},{15,12}, - {15,13},{15,14},{15,17},{15,18},{15,19},{15,20},{15,21},{15,22},{15,23},{15,24},{15,29},{15,30},{15,33},{15,34},{15,45},{15,46},{16,-43},{16,-42},{16,-32},{16,-31},{16,-30},{16,-27},{16,-26},{16,-25},{16,-21},{16,-20},{16,-19},{16,-18},{16,-17},{16,-16}, - {16,-15},{16,-14},{16,-11},{16,-10},{16,-9},{16,-8},{16,-7},{16,-6},{16,0},{16,1},{16,2},{16,3},{16,9},{16,10},{16,11},{16,12},{16,13},{16,14},{16,17},{16,18},{16,19},{16,20},{16,21},{16,22},{16,23},{16,24},{16,28},{16,29},{16,30},{16,33}, - {16,34},{16,35},{16,45},{16,46},{17,-43},{17,-42},{17,-35},{17,-34},{17,-33},{17,-32},{17,-31},{17,-26},{17,-25},{17,-24},{17,-15},{17,-14},{17,-10},{17,-9},{17,-8},{17,-7},{17,-6},{17,-1},{17,0},{17,1},{17,2},{17,3},{17,4},{17,9},{17,10},{17,11}, - {17,12},{17,13},{17,17},{17,18},{17,27},{17,28},{17,29},{17,34},{17,35},{17,36},{17,37},{17,38},{17,45},{17,46},{18,-43},{18,-42},{18,-41},{18,-35},{18,-34},{18,-33},{18,-32},{18,-25},{18,-24},{18,-23},{18,-15},{18,-14},{18,-13},{18,-9},{18,-8},{18,-7}, - {18,-6},{18,-2},{18,-1},{18,0},{18,1},{18,2},{18,3},{18,4},{18,5},{18,9},{18,10},{18,11},{18,12},{18,16},{18,17},{18,18},{18,26},{18,27},{18,28},{18,35},{18,36},{18,37},{18,38},{18,44},{18,45},{18,46},{19,-42},{19,-41},{19,-40},{19,-39}, - {19,-38},{19,-29},{19,-28},{19,-25},{19,-24},{19,-23},{19,-22},{19,-21},{19,-20},{19,-19},{19,-18},{19,-15},{19,-14},{19,-13},{19,-12},{19,-3},{19,-2},{19,-1},{19,4},{19,5},{19,6},{19,15},{19,16},{19,17},{19,18},{19,21},{19,22},{19,23},{19,24},{19,25}, - {19,26},{19,27},{19,28},{19,31},{19,32},{19,41},{19,42},{19,43},{19,44},{19,45},{20,-41},{20,-40},{20,-39},{20,-38},{20,-37},{20,-29},{20,-28},{20,-25},{20,-24},{20,-23},{20,-22},{20,-21},{20,-20},{20,-19},{20,-18},{20,-15},{20,-14},{20,-13},{20,-12},{20,-3}, - {20,-2},{20,5},{20,6},{20,15},{20,16},{20,17},{20,18},{20,21},{20,22},{20,23},{20,24},{20,25},{20,26},{20,27},{20,28},{20,31},{20,32},{20,40},{20,41},{20,42},{20,43},{20,44},{21,-38},{21,-37},{21,-36},{21,-29},{21,-28},{21,-19},{21,-18},{21,-15}, - {21,-14},{21,-13},{21,-9},{21,-8},{21,-7},{21,-6},{21,1},{21,2},{21,9},{21,10},{21,11},{21,12},{21,16},{21,17},{21,18},{21,21},{21,22},{21,31},{21,32},{21,39},{21,40},{21,41},{22,-37},{22,-36},{22,-30},{22,-29},{22,-28},{22,-19},{22,-18},{22,-15}, - {22,-14},{22,-9},{22,-8},{22,-7},{22,-6},{22,-5},{22,0},{22,1},{22,2},{22,3},{22,8},{22,9},{22,10},{22,11},{22,12},{22,17},{22,18},{22,21},{22,22},{22,31},{22,32},{22,33},{22,39},{22,40},{23,-33},{23,-32},{23,-31},{23,-30},{23,-29},{23,-25}, - {23,-24},{23,-23},{23,-22},{23,-19},{23,-18},{23,-9},{23,-8},{23,-7},{23,-6},{23,-5},{23,-4},{23,-1},{23,0},{23,1},{23,2},{23,3},{23,4},{23,7},{23,8},{23,9},{23,10},{23,11},{23,12},{23,21},{23,22},{23,25},{23,26},{23,27},{23,28},{23,32}, - {23,33},{23,34},{23,35},{23,36},{24,-33},{24,-32},{24,-31},{24,-30},{24,-25},{24,-24},{24,-23},{24,-22},{24,-19},{24,-18},{24,-17},{24,-9},{24,-8},{24,-7},{24,-6},{24,-5},{24,-4},{24,-1},{24,0},{24,1},{24,2},{24,3},{24,4},{24,7},{24,8},{24,9}, - {24,10},{24,11},{24,12},{24,20},{24,21},{24,22},{24,25},{24,26},{24,27},{24,28},{24,33},{24,34},{24,35},{24,36},{25,-39},{25,-38},{25,-37},{25,-36},{25,-24},{25,-23},{25,-22},{25,-19},{25,-18},{25,-17},{25,-16},{25,-6},{25,-5},{25,-4},{25,-1},{25,0}, - {25,1},{25,2},{25,3},{25,4},{25,7},{25,8},{25,9},{25,19},{25,20},{25,21},{25,22},{25,25},{25,26},{25,27},{25,39},{25,40},{25,41},{25,42},{26,-39},{26,-38},{26,-37},{26,-36},{26,-23},{26,-22},{26,-19},{26,-18},{26,-17},{26,-16},{26,-15},{26,-5}, - {26,-4},{26,-1},{26,0},{26,1},{26,2},{26,3},{26,4},{26,7},{26,8},{26,18},{26,19},{26,20},{26,21},{26,22},{26,25},{26,26},{26,39},{26,40},{26,41},{26,42},{27,-38},{27,-37},{27,-36},{27,-29},{27,-28},{27,-27},{27,-26},{27,-16},{27,-15},{27,-14}, - {27,-9},{27,-8},{27,11},{27,12},{27,17},{27,18},{27,19},{27,29},{27,30},{27,31},{27,32},{27,39},{27,40},{27,41},{28,-37},{28,-36},{28,-30},{28,-29},{28,-28},{28,-27},{28,-26},{28,-15},{28,-14},{28,-10},{28,-9},{28,-8},{28,-7},{28,10},{28,11},{28,12}, - {28,13},{28,17},{28,18},{28,29},{28,30},{28,31},{28,32},{28,33},{28,39},{28,40},{29,-33},{29,-32},{29,-31},{29,-30},{29,-29},{29,-28},{29,-27},{29,-26},{29,-21},{29,-20},{29,-19},{29,-18},{29,-11},{29,-10},{29,-9},{29,-8},{29,-7},{29,-6},{29,-1},{29,0}, - {29,1},{29,2},{29,3},{29,4},{29,9},{29,10},{29,11},{29,12},{29,13},{29,14},{29,21},{29,22},{29,23},{29,24},{29,29},{29,30},{29,31},{29,32},{29,33},{29,34},{29,35},{29,36},{30,-33},{30,-32},{30,-31},{30,-30},{30,-29},{30,-28},{30,-27},{30,-26}, - {30,-22},{30,-21},{30,-20},{30,-19},{30,-18},{30,-11},{30,-10},{30,-9},{30,-8},{30,-7},{30,-6},{30,-5},{30,-1},{30,0},{30,1},{30,2},{30,3},{30,4},{30,8},{30,9},{30,10},{30,11},{30,12},{30,13},{30,14},{30,21},{30,22},{30,23},{30,24},{30,25}, - {30,29},{30,30},{30,31},{30,32},{30,33},{30,34},{30,35},{30,36},{31,-32},{31,-31},{31,-30},{31,-29},{31,-28},{31,-27},{31,-23},{31,-22},{31,-21},{31,-15},{31,-14},{31,-6},{31,-5},{31,-4},{31,-1},{31,0},{31,3},{31,4},{31,7},{31,8},{31,9},{31,17}, - {31,18},{31,24},{31,25},{31,26},{31,30},{31,31},{31,32},{31,33},{31,34},{31,35},{32,-31},{32,-30},{32,-29},{32,-28},{32,-23},{32,-22},{32,-16},{32,-15},{32,-14},{32,-5},{32,-4},{32,-1},{32,0},{32,3},{32,4},{32,7},{32,8},{32,17},{32,18},{32,19}, - {32,25},{32,26},{32,31},{32,32},{32,33},{32,34},{33,-30},{33,-29},{33,-28},{33,-23},{33,-22},{33,-17},{33,-16},{33,-15},{33,-11},{33,-10},{33,-9},{33,-8},{33,11},{33,12},{33,13},{33,14},{33,18},{33,19},{33,20},{33,25},{33,26},{33,31},{33,32},{33,33}, - {34,-29},{34,-28},{34,-23},{34,-22},{34,-17},{34,-16},{34,-12},{34,-11},{34,-10},{34,-9},{34,-8},{34,11},{34,12},{34,13},{34,14},{34,15},{34,19},{34,20},{34,25},{34,26},{34,31},{34,32},{35,-17},{35,-16},{35,-13},{35,-12},{35,-11},{35,-10},{35,-9},{35,-3}, - {35,-2},{35,-1},{35,0},{35,3},{35,4},{35,5},{35,6},{35,12},{35,13},{35,14},{35,15},{35,16},{35,19},{35,20},{36,-17},{36,-16},{36,-13},{36,-12},{36,-11},{36,-10},{36,-4},{36,-3},{36,-2},{36,-1},{36,0},{36,3},{36,4},{36,5},{36,6},{36,7}, - {36,13},{36,14},{36,15},{36,16},{36,19},{36,20},{37,-27},{37,-26},{37,-25},{37,-24},{37,-21},{37,-20},{37,-13},{37,-12},{37,-5},{37,-4},{37,-3},{37,-2},{37,-1},{37,0},{37,1},{37,2},{37,3},{37,4},{37,5},{37,6},{37,7},{37,8},{37,15},{37,16}, - {37,23},{37,24},{37,27},{37,28},{37,29},{37,30},{38,-27},{38,-26},{38,-25},{38,-24},{38,-21},{38,-20},{38,-19},{38,-13},{38,-12},{38,-5},{38,-4},{38,-3},{38,-2},{38,-1},{38,0},{38,1},{38,2},{38,3},{38,4},{38,5},{38,6},{38,7},{38,8},{38,15}, - {38,16},{38,22},{38,23},{38,24},{38,27},{38,28},{38,29},{38,30},{39,-26},{39,-25},{39,-24},{39,-20},{39,-19},{39,-18},{39,-13},{39,-12},{39,-11},{39,-10},{39,-5},{39,-4},{39,7},{39,8},{39,13},{39,14},{39,15},{39,16},{39,21},{39,22},{39,23},{39,27}, - {39,28},{39,29},{40,-25},{40,-24},{40,-19},{40,-18},{40,-13},{40,-12},{40,-11},{40,-10},{40,-5},{40,-4},{40,7},{40,8},{40,13},{40,14},{40,15},{40,16},{40,21},{40,22},{40,27},{40,28},{41,-19},{41,-18},{41,-1},{41,0},{41,1},{41,2},{41,3},{41,4}, - {41,21},{41,22},{42,-19},{42,-18},{42,-17},{42,-1},{42,0},{42,1},{42,2},{42,3},{42,4},{42,20},{42,21},{42,22},{43,-18},{43,-17},{43,-16},{43,-15},{43,-14},{43,-13},{43,-12},{43,-9},{43,-8},{43,-1},{43,0},{43,1},{43,2},{43,3},{43,4},{43,11}, - {43,12},{43,15},{43,16},{43,17},{43,18},{43,19},{43,20},{43,21},{44,-17},{44,-16},{44,-15},{44,-14},{44,-13},{44,-12},{44,-9},{44,-8},{44,-7},{44,-2},{44,-1},{44,0},{44,1},{44,2},{44,3},{44,4},{44,5},{44,10},{44,11},{44,12},{44,15},{44,16}, - {44,17},{44,18},{44,19},{44,20},{45,-8},{45,-7},{45,-6},{45,-5},{45,-4},{45,-3},{45,-2},{45,-1},{45,4},{45,5},{45,6},{45,7},{45,8},{45,9},{45,10},{45,11},{46,-7},{46,-6},{46,-5},{46,-4},{46,-3},{46,-2},{46,5},{46,6},{46,7},{46,8}, - {46,9},{46,10},{47,-4},{47,-3},{47,-2},{47,1},{47,2},{47,5},{47,6},{47,7},{48,-3},{48,-2},{48,1},{48,2},{48,5},{48,6} - } + { -49, -3 }, { -49, -2 }, { -49, 1 }, { -49, 2 }, { -49, 5 }, { -49, 6 }, { -48, -4 }, { -48, -3 }, { -48, -2 }, { -48, 1 }, { -48, 2 }, { -48, 5 }, { -48, 6 }, { -48, 7 }, { -47, -7 }, { -47, -6 }, { -47, -5 }, { -47, -4 }, { -47, -3 }, { -47, -2 }, { -47, 5 }, { -47, 6 }, { -47, 7 }, { -47, 8 }, { -47, 9 }, { -47, 10 }, { -46, -8 }, { -46, -7 }, { -46, -6 }, { -46, -5 }, + { -46, -4 }, { -46, -3 }, { -46, -2 }, { -46, -1 }, { -46, 4 }, { -46, 5 }, { -46, 6 }, { -46, 7 }, { -46, 8 }, { -46, 9 }, { -46, 10 }, { -46, 11 }, { -45, -17 }, { -45, -16 }, { -45, -15 }, { -45, -14 }, { -45, -13 }, { -45, -12 }, { -45, -9 }, { -45, -8 }, { -45, -7 }, { -45, -2 }, { -45, -1 }, { -45, 0 }, { -45, 1 }, { -45, 2 }, { -45, 3 }, { -45, 4 }, { -45, 5 }, { -45, 10 }, + { -45, 11 }, { -45, 12 }, { -45, 15 }, { -45, 16 }, { -45, 17 }, { -45, 18 }, { -45, 19 }, { -45, 20 }, { -44, -18 }, { -44, -17 }, { -44, -16 }, { -44, -15 }, { -44, -14 }, { -44, -13 }, { -44, -12 }, { -44, -9 }, { -44, -8 }, { -44, -1 }, { -44, 0 }, { -44, 1 }, { -44, 2 }, { -44, 3 }, { -44, 4 }, { -44, 11 }, { -44, 12 }, { -44, 15 }, { -44, 16 }, { -44, 17 }, { -44, 18 }, { -44, 19 }, + { -44, 20 }, { -44, 21 }, { -43, -19 }, { -43, -18 }, { -43, -17 }, { -43, -1 }, { -43, 0 }, { -43, 1 }, { -43, 2 }, { -43, 3 }, { -43, 4 }, { -43, 20 }, { -43, 21 }, { -43, 22 }, { -42, -19 }, { -42, -18 }, { -42, -1 }, { -42, 0 }, { -42, 1 }, { -42, 2 }, { -42, 3 }, { -42, 4 }, { -42, 21 }, { -42, 22 }, { -41, -25 }, { -41, -24 }, { -41, -19 }, { -41, -18 }, { -41, -13 }, { -41, -12 }, + { -41, -11 }, { -41, -10 }, { -41, -5 }, { -41, -4 }, { -41, 7 }, { -41, 8 }, { -41, 13 }, { -41, 14 }, { -41, 15 }, { -41, 16 }, { -41, 21 }, { -41, 22 }, { -41, 27 }, { -41, 28 }, { -40, -26 }, { -40, -25 }, { -40, -24 }, { -40, -20 }, { -40, -19 }, { -40, -18 }, { -40, -13 }, { -40, -12 }, { -40, -11 }, { -40, -10 }, { -40, -5 }, { -40, -4 }, { -40, 7 }, { -40, 8 }, { -40, 13 }, { -40, 14 }, + { -40, 15 }, { -40, 16 }, { -40, 21 }, { -40, 22 }, { -40, 23 }, { -40, 27 }, { -40, 28 }, { -40, 29 }, { -39, -27 }, { -39, -26 }, { -39, -25 }, { -39, -24 }, { -39, -21 }, { -39, -20 }, { -39, -19 }, { -39, -13 }, { -39, -12 }, { -39, -5 }, { -39, -4 }, { -39, -3 }, { -39, -2 }, { -39, -1 }, { -39, 0 }, { -39, 1 }, { -39, 2 }, { -39, 3 }, { -39, 4 }, { -39, 5 }, { -39, 6 }, { -39, 7 }, + { -39, 8 }, { -39, 15 }, { -39, 16 }, { -39, 22 }, { -39, 23 }, { -39, 24 }, { -39, 27 }, { -39, 28 }, { -39, 29 }, { -39, 30 }, { -38, -27 }, { -38, -26 }, { -38, -25 }, { -38, -24 }, { -38, -21 }, { -38, -20 }, { -38, -13 }, { -38, -12 }, { -38, -5 }, { -38, -4 }, { -38, -3 }, { -38, -2 }, { -38, -1 }, { -38, 0 }, { -38, 1 }, { -38, 2 }, { -38, 3 }, { -38, 4 }, { -38, 5 }, { -38, 6 }, + { -38, 7 }, { -38, 8 }, { -38, 15 }, { -38, 16 }, { -38, 23 }, { -38, 24 }, { -38, 27 }, { -38, 28 }, { -38, 29 }, { -38, 30 }, { -37, -17 }, { -37, -16 }, { -37, -13 }, { -37, -12 }, { -37, -11 }, { -37, -10 }, { -37, -4 }, { -37, -3 }, { -37, -2 }, { -37, -1 }, { -37, 0 }, { -37, 3 }, { -37, 4 }, { -37, 5 }, { -37, 6 }, { -37, 7 }, { -37, 13 }, { -37, 14 }, { -37, 15 }, { -37, 16 }, + { -37, 19 }, { -37, 20 }, { -36, -17 }, { -36, -16 }, { -36, -13 }, { -36, -12 }, { -36, -11 }, { -36, -10 }, { -36, -9 }, { -36, -3 }, { -36, -2 }, { -36, -1 }, { -36, 0 }, { -36, 3 }, { -36, 4 }, { -36, 5 }, { -36, 6 }, { -36, 12 }, { -36, 13 }, { -36, 14 }, { -36, 15 }, { -36, 16 }, { -36, 19 }, { -36, 20 }, { -35, -29 }, { -35, -28 }, { -35, -23 }, { -35, -22 }, { -35, -17 }, { -35, -16 }, + { -35, -12 }, { -35, -11 }, { -35, -10 }, { -35, -9 }, { -35, -8 }, { -35, 11 }, { -35, 12 }, { -35, 13 }, { -35, 14 }, { -35, 15 }, { -35, 19 }, { -35, 20 }, { -35, 25 }, { -35, 26 }, { -35, 31 }, { -35, 32 }, { -34, -30 }, { -34, -29 }, { -34, -28 }, { -34, -23 }, { -34, -22 }, { -34, -17 }, { -34, -16 }, { -34, -15 }, { -34, -11 }, { -34, -10 }, { -34, -9 }, { -34, -8 }, { -34, 11 }, { -34, 12 }, + { -34, 13 }, { -34, 14 }, { -34, 18 }, { -34, 19 }, { -34, 20 }, { -34, 25 }, { -34, 26 }, { -34, 31 }, { -34, 32 }, { -34, 33 }, { -33, -31 }, { -33, -30 }, { -33, -29 }, { -33, -28 }, { -33, -23 }, { -33, -22 }, { -33, -16 }, { -33, -15 }, { -33, -14 }, { -33, -5 }, { -33, -4 }, { -33, -1 }, { -33, 0 }, { -33, 3 }, { -33, 4 }, { -33, 7 }, { -33, 8 }, { -33, 17 }, { -33, 18 }, { -33, 19 }, + { -33, 25 }, { -33, 26 }, { -33, 31 }, { -33, 32 }, { -33, 33 }, { -33, 34 }, { -32, -32 }, { -32, -31 }, { -32, -30 }, { -32, -29 }, { -32, -28 }, { -32, -27 }, { -32, -23 }, { -32, -22 }, { -32, -21 }, { -32, -15 }, { -32, -14 }, { -32, -6 }, { -32, -5 }, { -32, -4 }, { -32, -1 }, { -32, 0 }, { -32, 3 }, { -32, 4 }, { -32, 7 }, { -32, 8 }, { -32, 9 }, { -32, 17 }, { -32, 18 }, { -32, 24 }, + { -32, 25 }, { -32, 26 }, { -32, 30 }, { -32, 31 }, { -32, 32 }, { -32, 33 }, { -32, 34 }, { -32, 35 }, { -31, -33 }, { -31, -32 }, { -31, -31 }, { -31, -30 }, { -31, -29 }, { -31, -28 }, { -31, -27 }, { -31, -26 }, { -31, -22 }, { -31, -21 }, { -31, -20 }, { -31, -19 }, { -31, -18 }, { -31, -11 }, { -31, -10 }, { -31, -9 }, { -31, -8 }, { -31, -7 }, { -31, -6 }, { -31, -5 }, { -31, -1 }, { -31, 0 }, + { -31, 1 }, { -31, 2 }, { -31, 3 }, { -31, 4 }, { -31, 8 }, { -31, 9 }, { -31, 10 }, { -31, 11 }, { -31, 12 }, { -31, 13 }, { -31, 14 }, { -31, 21 }, { -31, 22 }, { -31, 23 }, { -31, 24 }, { -31, 25 }, { -31, 29 }, { -31, 30 }, { -31, 31 }, { -31, 32 }, { -31, 33 }, { -31, 34 }, { -31, 35 }, { -31, 36 }, { -30, -33 }, { -30, -32 }, { -30, -31 }, { -30, -30 }, { -30, -29 }, { -30, -28 }, + { -30, -27 }, { -30, -26 }, { -30, -21 }, { -30, -20 }, { -30, -19 }, { -30, -18 }, { -30, -11 }, { -30, -10 }, { -30, -9 }, { -30, -8 }, { -30, -7 }, { -30, -6 }, { -30, -1 }, { -30, 0 }, { -30, 1 }, { -30, 2 }, { -30, 3 }, { -30, 4 }, { -30, 9 }, { -30, 10 }, { -30, 11 }, { -30, 12 }, { -30, 13 }, { -30, 14 }, { -30, 21 }, { -30, 22 }, { -30, 23 }, { -30, 24 }, { -30, 29 }, { -30, 30 }, + { -30, 31 }, { -30, 32 }, { -30, 33 }, { -30, 34 }, { -30, 35 }, { -30, 36 }, { -29, -37 }, { -29, -36 }, { -29, -30 }, { -29, -29 }, { -29, -28 }, { -29, -27 }, { -29, -26 }, { -29, -15 }, { -29, -14 }, { -29, -10 }, { -29, -9 }, { -29, -8 }, { -29, -7 }, { -29, 10 }, { -29, 11 }, { -29, 12 }, { -29, 13 }, { -29, 17 }, { -29, 18 }, { -29, 29 }, { -29, 30 }, { -29, 31 }, { -29, 32 }, { -29, 33 }, + { -29, 39 }, { -29, 40 }, { -28, -38 }, { -28, -37 }, { -28, -36 }, { -28, -29 }, { -28, -28 }, { -28, -27 }, { -28, -26 }, { -28, -16 }, { -28, -15 }, { -28, -14 }, { -28, -9 }, { -28, -8 }, { -28, 11 }, { -28, 12 }, { -28, 17 }, { -28, 18 }, { -28, 19 }, { -28, 29 }, { -28, 30 }, { -28, 31 }, { -28, 32 }, { -28, 39 }, { -28, 40 }, { -28, 41 }, { -27, -39 }, { -27, -38 }, { -27, -37 }, { -27, -36 }, + { -27, -23 }, { -27, -22 }, { -27, -19 }, { -27, -18 }, { -27, -17 }, { -27, -16 }, { -27, -15 }, { -27, -5 }, { -27, -4 }, { -27, -1 }, { -27, 0 }, { -27, 1 }, { -27, 2 }, { -27, 3 }, { -27, 4 }, { -27, 7 }, { -27, 8 }, { -27, 18 }, { -27, 19 }, { -27, 20 }, { -27, 21 }, { -27, 22 }, { -27, 25 }, { -27, 26 }, { -27, 39 }, { -27, 40 }, { -27, 41 }, { -27, 42 }, { -26, -39 }, { -26, -38 }, + { -26, -37 }, { -26, -36 }, { -26, -24 }, { -26, -23 }, { -26, -22 }, { -26, -19 }, { -26, -18 }, { -26, -17 }, { -26, -16 }, { -26, -6 }, { -26, -5 }, { -26, -4 }, { -26, -1 }, { -26, 0 }, { -26, 1 }, { -26, 2 }, { -26, 3 }, { -26, 4 }, { -26, 7 }, { -26, 8 }, { -26, 9 }, { -26, 19 }, { -26, 20 }, { -26, 21 }, { -26, 22 }, { -26, 25 }, { -26, 26 }, { -26, 27 }, { -26, 39 }, { -26, 40 }, + { -26, 41 }, { -26, 42 }, { -25, -33 }, { -25, -32 }, { -25, -31 }, { -25, -30 }, { -25, -25 }, { -25, -24 }, { -25, -23 }, { -25, -22 }, { -25, -19 }, { -25, -18 }, { -25, -17 }, { -25, -9 }, { -25, -8 }, { -25, -7 }, { -25, -6 }, { -25, -5 }, { -25, -4 }, { -25, -1 }, { -25, 0 }, { -25, 1 }, { -25, 2 }, { -25, 3 }, { -25, 4 }, { -25, 7 }, { -25, 8 }, { -25, 9 }, { -25, 10 }, { -25, 11 }, + { -25, 12 }, { -25, 20 }, { -25, 21 }, { -25, 22 }, { -25, 25 }, { -25, 26 }, { -25, 27 }, { -25, 28 }, { -25, 33 }, { -25, 34 }, { -25, 35 }, { -25, 36 }, { -24, -33 }, { -24, -32 }, { -24, -31 }, { -24, -30 }, { -24, -29 }, { -24, -25 }, { -24, -24 }, { -24, -23 }, { -24, -22 }, { -24, -19 }, { -24, -18 }, { -24, -9 }, { -24, -8 }, { -24, -7 }, { -24, -6 }, { -24, -5 }, { -24, -4 }, { -24, -1 }, + { -24, 0 }, { -24, 1 }, { -24, 2 }, { -24, 3 }, { -24, 4 }, { -24, 7 }, { -24, 8 }, { -24, 9 }, { -24, 10 }, { -24, 11 }, { -24, 12 }, { -24, 21 }, { -24, 22 }, { -24, 25 }, { -24, 26 }, { -24, 27 }, { -24, 28 }, { -24, 32 }, { -24, 33 }, { -24, 34 }, { -24, 35 }, { -24, 36 }, { -23, -37 }, { -23, -36 }, { -23, -30 }, { -23, -29 }, { -23, -28 }, { -23, -19 }, { -23, -18 }, { -23, -15 }, + { -23, -14 }, { -23, -9 }, { -23, -8 }, { -23, -7 }, { -23, -6 }, { -23, -5 }, { -23, 0 }, { -23, 1 }, { -23, 2 }, { -23, 3 }, { -23, 8 }, { -23, 9 }, { -23, 10 }, { -23, 11 }, { -23, 12 }, { -23, 17 }, { -23, 18 }, { -23, 21 }, { -23, 22 }, { -23, 31 }, { -23, 32 }, { -23, 33 }, { -23, 39 }, { -23, 40 }, { -22, -38 }, { -22, -37 }, { -22, -36 }, { -22, -29 }, { -22, -28 }, { -22, -19 }, + { -22, -18 }, { -22, -15 }, { -22, -14 }, { -22, -13 }, { -22, -9 }, { -22, -8 }, { -22, -7 }, { -22, -6 }, { -22, 1 }, { -22, 2 }, { -22, 9 }, { -22, 10 }, { -22, 11 }, { -22, 12 }, { -22, 16 }, { -22, 17 }, { -22, 18 }, { -22, 21 }, { -22, 22 }, { -22, 31 }, { -22, 32 }, { -22, 39 }, { -22, 40 }, { -22, 41 }, { -21, -41 }, { -21, -40 }, { -21, -39 }, { -21, -38 }, { -21, -37 }, { -21, -29 }, + { -21, -28 }, { -21, -25 }, { -21, -24 }, { -21, -23 }, { -21, -22 }, { -21, -21 }, { -21, -20 }, { -21, -19 }, { -21, -18 }, { -21, -15 }, { -21, -14 }, { -21, -13 }, { -21, -12 }, { -21, -3 }, { -21, -2 }, { -21, 5 }, { -21, 6 }, { -21, 15 }, { -21, 16 }, { -21, 17 }, { -21, 18 }, { -21, 21 }, { -21, 22 }, { -21, 23 }, { -21, 24 }, { -21, 25 }, { -21, 26 }, { -21, 27 }, { -21, 28 }, { -21, 31 }, + { -21, 32 }, { -21, 40 }, { -21, 41 }, { -21, 42 }, { -21, 43 }, { -21, 44 }, { -20, -42 }, { -20, -41 }, { -20, -40 }, { -20, -39 }, { -20, -38 }, { -20, -29 }, { -20, -28 }, { -20, -25 }, { -20, -24 }, { -20, -23 }, { -20, -22 }, { -20, -21 }, { -20, -20 }, { -20, -19 }, { -20, -18 }, { -20, -15 }, { -20, -14 }, { -20, -13 }, { -20, -12 }, { -20, -3 }, { -20, -2 }, { -20, -1 }, { -20, 4 }, { -20, 5 }, + { -20, 6 }, { -20, 15 }, { -20, 16 }, { -20, 17 }, { -20, 18 }, { -20, 21 }, { -20, 22 }, { -20, 23 }, { -20, 24 }, { -20, 25 }, { -20, 26 }, { -20, 27 }, { -20, 28 }, { -20, 31 }, { -20, 32 }, { -20, 41 }, { -20, 42 }, { -20, 43 }, { -20, 44 }, { -20, 45 }, { -19, -43 }, { -19, -42 }, { -19, -41 }, { -19, -35 }, { -19, -34 }, { -19, -33 }, { -19, -32 }, { -19, -25 }, { -19, -24 }, { -19, -23 }, + { -19, -15 }, { -19, -14 }, { -19, -13 }, { -19, -9 }, { -19, -8 }, { -19, -7 }, { -19, -6 }, { -19, -2 }, { -19, -1 }, { -19, 0 }, { -19, 1 }, { -19, 2 }, { -19, 3 }, { -19, 4 }, { -19, 5 }, { -19, 9 }, { -19, 10 }, { -19, 11 }, { -19, 12 }, { -19, 16 }, { -19, 17 }, { -19, 18 }, { -19, 26 }, { -19, 27 }, { -19, 28 }, { -19, 35 }, { -19, 36 }, { -19, 37 }, { -19, 38 }, { -19, 44 }, + { -19, 45 }, { -19, 46 }, { -18, -43 }, { -18, -42 }, { -18, -35 }, { -18, -34 }, { -18, -33 }, { -18, -32 }, { -18, -31 }, { -18, -26 }, { -18, -25 }, { -18, -24 }, { -18, -15 }, { -18, -14 }, { -18, -10 }, { -18, -9 }, { -18, -8 }, { -18, -7 }, { -18, -6 }, { -18, -1 }, { -18, 0 }, { -18, 1 }, { -18, 2 }, { -18, 3 }, { -18, 4 }, { -18, 9 }, { -18, 10 }, { -18, 11 }, { -18, 12 }, { -18, 13 }, + { -18, 17 }, { -18, 18 }, { -18, 27 }, { -18, 28 }, { -18, 29 }, { -18, 34 }, { -18, 35 }, { -18, 36 }, { -18, 37 }, { -18, 38 }, { -18, 45 }, { -18, 46 }, { -17, -43 }, { -17, -42 }, { -17, -32 }, { -17, -31 }, { -17, -30 }, { -17, -27 }, { -17, -26 }, { -17, -25 }, { -17, -21 }, { -17, -20 }, { -17, -19 }, { -17, -18 }, { -17, -17 }, { -17, -16 }, { -17, -15 }, { -17, -14 }, { -17, -11 }, { -17, -10 }, + { -17, -9 }, { -17, -8 }, { -17, -7 }, { -17, -6 }, { -17, 0 }, { -17, 1 }, { -17, 2 }, { -17, 3 }, { -17, 9 }, { -17, 10 }, { -17, 11 }, { -17, 12 }, { -17, 13 }, { -17, 14 }, { -17, 17 }, { -17, 18 }, { -17, 19 }, { -17, 20 }, { -17, 21 }, { -17, 22 }, { -17, 23 }, { -17, 24 }, { -17, 28 }, { -17, 29 }, { -17, 30 }, { -17, 33 }, { -17, 34 }, { -17, 35 }, { -17, 45 }, { -17, 46 }, + { -16, -43 }, { -16, -42 }, { -16, -31 }, { -16, -30 }, { -16, -27 }, { -16, -26 }, { -16, -21 }, { -16, -20 }, { -16, -19 }, { -16, -18 }, { -16, -17 }, { -16, -16 }, { -16, -15 }, { -16, -14 }, { -16, -11 }, { -16, -10 }, { -16, -9 }, { -16, -8 }, { -16, -7 }, { -16, -6 }, { -16, 1 }, { -16, 2 }, { -16, 9 }, { -16, 10 }, { -16, 11 }, { -16, 12 }, { -16, 13 }, { -16, 14 }, { -16, 17 }, { -16, 18 }, + { -16, 19 }, { -16, 20 }, { -16, 21 }, { -16, 22 }, { -16, 23 }, { -16, 24 }, { -16, 29 }, { -16, 30 }, { -16, 33 }, { -16, 34 }, { -16, 45 }, { -16, 46 }, { -15, -43 }, { -15, -42 }, { -15, -39 }, { -15, -38 }, { -15, -37 }, { -15, -36 }, { -15, -35 }, { -15, -34 }, { -15, -20 }, { -15, -19 }, { -15, -18 }, { -15, -17 }, { -15, -10 }, { -15, -9 }, { -15, -8 }, { -15, -7 }, { -15, -3 }, { -15, -2 }, + { -15, 1 }, { -15, 2 }, { -15, 5 }, { -15, 6 }, { -15, 10 }, { -15, 11 }, { -15, 12 }, { -15, 13 }, { -15, 20 }, { -15, 21 }, { -15, 22 }, { -15, 23 }, { -15, 37 }, { -15, 38 }, { -15, 39 }, { -15, 40 }, { -15, 41 }, { -15, 42 }, { -15, 45 }, { -15, 46 }, { -14, -43 }, { -14, -42 }, { -14, -39 }, { -14, -38 }, { -14, -37 }, { -14, -36 }, { -14, -35 }, { -14, -34 }, { -14, -33 }, { -14, -19 }, + { -14, -18 }, { -14, -9 }, { -14, -8 }, { -14, -4 }, { -14, -3 }, { -14, -2 }, { -14, 1 }, { -14, 2 }, { -14, 5 }, { -14, 6 }, { -14, 7 }, { -14, 11 }, { -14, 12 }, { -14, 21 }, { -14, 22 }, { -14, 36 }, { -14, 37 }, { -14, 38 }, { -14, 39 }, { -14, 40 }, { -14, 41 }, { -14, 42 }, { -14, 45 }, { -14, 46 }, { -13, -39 }, { -13, -38 }, { -13, -35 }, { -13, -34 }, { -13, -33 }, { -13, -32 }, + { -13, -29 }, { -13, -28 }, { -13, -15 }, { -13, -14 }, { -13, -5 }, { -13, -4 }, { -13, -3 }, { -13, -2 }, { -13, 5 }, { -13, 6 }, { -13, 7 }, { -13, 8 }, { -13, 17 }, { -13, 18 }, { -13, 31 }, { -13, 32 }, { -13, 35 }, { -13, 36 }, { -13, 37 }, { -13, 38 }, { -13, 41 }, { -13, 42 }, { -12, -39 }, { -12, -38 }, { -12, -35 }, { -12, -34 }, { -12, -33 }, { -12, -32 }, { -12, -29 }, { -12, -28 }, + { -12, -27 }, { -12, -16 }, { -12, -15 }, { -12, -14 }, { -12, -13 }, { -12, -5 }, { -12, -4 }, { -12, -3 }, { -12, -2 }, { -12, 5 }, { -12, 6 }, { -12, 7 }, { -12, 8 }, { -12, 16 }, { -12, 17 }, { -12, 18 }, { -12, 19 }, { -12, 30 }, { -12, 31 }, { -12, 32 }, { -12, 35 }, { -12, 36 }, { -12, 37 }, { -12, 38 }, { -12, 41 }, { -12, 42 }, { -11, -43 }, { -11, -42 }, { -11, -34 }, { -11, -33 }, + { -11, -32 }, { -11, -29 }, { -11, -28 }, { -11, -27 }, { -11, -26 }, { -11, -23 }, { -11, -22 }, { -11, -21 }, { -11, -20 }, { -11, -17 }, { -11, -16 }, { -11, -15 }, { -11, -14 }, { -11, -13 }, { -11, -12 }, { -11, -9 }, { -11, -8 }, { -11, 1 }, { -11, 2 }, { -11, 11 }, { -11, 12 }, { -11, 15 }, { -11, 16 }, { -11, 17 }, { -11, 18 }, { -11, 19 }, { -11, 20 }, { -11, 23 }, { -11, 24 }, { -11, 25 }, + { -11, 26 }, { -11, 29 }, { -11, 30 }, { -11, 31 }, { -11, 32 }, { -11, 35 }, { -11, 36 }, { -11, 37 }, { -11, 45 }, { -11, 46 }, { -10, -44 }, { -10, -43 }, { -10, -42 }, { -10, -33 }, { -10, -32 }, { -10, -29 }, { -10, -28 }, { -10, -27 }, { -10, -26 }, { -10, -23 }, { -10, -22 }, { -10, -21 }, { -10, -20 }, { -10, -17 }, { -10, -16 }, { -10, -15 }, { -10, -14 }, { -10, -13 }, { -10, -12 }, { -10, -9 }, + { -10, -8 }, { -10, -7 }, { -10, 0 }, { -10, 1 }, { -10, 2 }, { -10, 3 }, { -10, 10 }, { -10, 11 }, { -10, 12 }, { -10, 15 }, { -10, 16 }, { -10, 17 }, { -10, 18 }, { -10, 19 }, { -10, 20 }, { -10, 23 }, { -10, 24 }, { -10, 25 }, { -10, 26 }, { -10, 29 }, { -10, 30 }, { -10, 31 }, { -10, 32 }, { -10, 35 }, { -10, 36 }, { -10, 45 }, { -10, 46 }, { -10, 47 }, { -9, -45 }, { -9, -44 }, + { -9, -43 }, { -9, -29 }, { -9, -28 }, { -9, -27 }, { -9, -23 }, { -9, -22 }, { -9, -21 }, { -9, -20 }, { -9, -17 }, { -9, -16 }, { -9, -15 }, { -9, -14 }, { -9, -13 }, { -9, -8 }, { -9, -7 }, { -9, -6 }, { -9, -5 }, { -9, -1 }, { -9, 0 }, { -9, 1 }, { -9, 2 }, { -9, 3 }, { -9, 4 }, { -9, 8 }, { -9, 9 }, { -9, 10 }, { -9, 11 }, { -9, 16 }, { -9, 17 }, { -9, 18 }, + { -9, 19 }, { -9, 20 }, { -9, 23 }, { -9, 24 }, { -9, 25 }, { -9, 26 }, { -9, 30 }, { -9, 31 }, { -9, 32 }, { -9, 46 }, { -9, 47 }, { -9, 48 }, { -8, -45 }, { -8, -44 }, { -8, -30 }, { -8, -29 }, { -8, -28 }, { -8, -24 }, { -8, -23 }, { -8, -22 }, { -8, -21 }, { -8, -20 }, { -8, -17 }, { -8, -16 }, { -8, -15 }, { -8, -14 }, { -8, -7 }, { -8, -6 }, { -8, -5 }, { -8, -4 }, + { -8, -1 }, { -8, 0 }, { -8, 1 }, { -8, 2 }, { -8, 3 }, { -8, 4 }, { -8, 7 }, { -8, 8 }, { -8, 9 }, { -8, 10 }, { -8, 17 }, { -8, 18 }, { -8, 19 }, { -8, 20 }, { -8, 23 }, { -8, 24 }, { -8, 25 }, { -8, 26 }, { -8, 27 }, { -8, 31 }, { -8, 32 }, { -8, 33 }, { -8, 47 }, { -8, 48 }, { -7, -45 }, { -7, -44 }, { -7, -39 }, { -7, -38 }, { -7, -37 }, { -7, -36 }, + { -7, -31 }, { -7, -30 }, { -7, -29 }, { -7, -25 }, { -7, -24 }, { -7, -23 }, { -7, -22 }, { -7, -21 }, { -7, -11 }, { -7, -10 }, { -7, -7 }, { -7, -6 }, { -7, -5 }, { -7, -4 }, { -7, 7 }, { -7, 8 }, { -7, 9 }, { -7, 10 }, { -7, 13 }, { -7, 14 }, { -7, 24 }, { -7, 25 }, { -7, 26 }, { -7, 27 }, { -7, 28 }, { -7, 32 }, { -7, 33 }, { -7, 34 }, { -7, 39 }, { -7, 40 }, + { -7, 41 }, { -7, 42 }, { -7, 47 }, { -7, 48 }, { -6, -46 }, { -6, -45 }, { -6, -44 }, { -6, -39 }, { -6, -38 }, { -6, -37 }, { -6, -36 }, { -6, -35 }, { -6, -31 }, { -6, -30 }, { -6, -25 }, { -6, -24 }, { -6, -23 }, { -6, -22 }, { -6, -12 }, { -6, -11 }, { -6, -10 }, { -6, -6 }, { -6, -5 }, { -6, 8 }, { -6, 9 }, { -6, 13 }, { -6, 14 }, { -6, 15 }, { -6, 25 }, { -6, 26 }, + { -6, 27 }, { -6, 28 }, { -6, 33 }, { -6, 34 }, { -6, 38 }, { -6, 39 }, { -6, 40 }, { -6, 41 }, { -6, 42 }, { -6, 47 }, { -6, 48 }, { -6, 49 }, { -5, -47 }, { -5, -46 }, { -5, -45 }, { -5, -44 }, { -5, -37 }, { -5, -36 }, { -5, -35 }, { -5, -34 }, { -5, -19 }, { -5, -18 }, { -5, -13 }, { -5, -12 }, { -5, -11 }, { -5, -10 }, { -5, -1 }, { -5, 0 }, { -5, 1 }, { -5, 2 }, + { -5, 3 }, { -5, 4 }, { -5, 13 }, { -5, 14 }, { -5, 15 }, { -5, 16 }, { -5, 21 }, { -5, 22 }, { -5, 37 }, { -5, 38 }, { -5, 39 }, { -5, 40 }, { -5, 47 }, { -5, 48 }, { -5, 49 }, { -5, 50 }, { -4, -47 }, { -4, -46 }, { -4, -45 }, { -4, -44 }, { -4, -43 }, { -4, -37 }, { -4, -36 }, { -4, -35 }, { -4, -34 }, { -4, -19 }, { -4, -18 }, { -4, -17 }, { -4, -13 }, { -4, -12 }, + { -4, -11 }, { -4, -10 }, { -4, -2 }, { -4, -1 }, { -4, 0 }, { -4, 1 }, { -4, 2 }, { -4, 3 }, { -4, 4 }, { -4, 5 }, { -4, 13 }, { -4, 14 }, { -4, 15 }, { -4, 16 }, { -4, 20 }, { -4, 21 }, { -4, 22 }, { -4, 37 }, { -4, 38 }, { -4, 39 }, { -4, 40 }, { -4, 46 }, { -4, 47 }, { -4, 48 }, { -4, 49 }, { -4, 50 }, { -3, -44 }, { -3, -43 }, { -3, -42 }, { -3, -41 }, + { -3, -40 }, { -3, -37 }, { -3, -36 }, { -3, -35 }, { -3, -34 }, { -3, -31 }, { -3, -30 }, { -3, -29 }, { -3, -28 }, { -3, -25 }, { -3, -24 }, { -3, -23 }, { -3, -22 }, { -3, -18 }, { -3, -17 }, { -3, -16 }, { -3, -7 }, { -3, -6 }, { -3, -3 }, { -3, -2 }, { -3, -1 }, { -3, 0 }, { -3, 3 }, { -3, 4 }, { -3, 5 }, { -3, 6 }, { -3, 9 }, { -3, 10 }, { -3, 19 }, { -3, 20 }, + { -3, 21 }, { -3, 25 }, { -3, 26 }, { -3, 27 }, { -3, 28 }, { -3, 31 }, { -3, 32 }, { -3, 33 }, { -3, 34 }, { -3, 37 }, { -3, 38 }, { -3, 39 }, { -3, 40 }, { -3, 43 }, { -3, 44 }, { -3, 45 }, { -3, 46 }, { -3, 47 }, { -2, -43 }, { -2, -42 }, { -2, -41 }, { -2, -40 }, { -2, -37 }, { -2, -36 }, { -2, -35 }, { -2, -34 }, { -2, -31 }, { -2, -30 }, { -2, -29 }, { -2, -28 }, + { -2, -25 }, { -2, -24 }, { -2, -23 }, { -2, -22 }, { -2, -21 }, { -2, -17 }, { -2, -16 }, { -2, -15 }, { -2, -8 }, { -2, -7 }, { -2, -6 }, { -2, -3 }, { -2, -2 }, { -2, -1 }, { -2, 0 }, { -2, 3 }, { -2, 4 }, { -2, 5 }, { -2, 6 }, { -2, 9 }, { -2, 10 }, { -2, 11 }, { -2, 18 }, { -2, 19 }, { -2, 20 }, { -2, 24 }, { -2, 25 }, { -2, 26 }, { -2, 27 }, { -2, 28 }, + { -2, 31 }, { -2, 32 }, { -2, 33 }, { -2, 34 }, { -2, 37 }, { -2, 38 }, { -2, 39 }, { -2, 40 }, { -2, 43 }, { -2, 44 }, { -2, 45 }, { -2, 46 }, { -1, -47 }, { -1, -46 }, { -1, -43 }, { -1, -42 }, { -1, -41 }, { -1, -40 }, { -1, -37 }, { -1, -36 }, { -1, -29 }, { -1, -28 }, { -1, -25 }, { -1, -24 }, { -1, -23 }, { -1, -22 }, { -1, -21 }, { -1, -20 }, { -1, -17 }, { -1, -16 }, + { -1, -15 }, { -1, -14 }, { -1, -13 }, { -1, -12 }, { -1, -9 }, { -1, -8 }, { -1, -7 }, { -1, -6 }, { -1, -3 }, { -1, -2 }, { -1, 5 }, { -1, 6 }, { -1, 9 }, { -1, 10 }, { -1, 11 }, { -1, 12 }, { -1, 15 }, { -1, 16 }, { -1, 17 }, { -1, 18 }, { -1, 19 }, { -1, 20 }, { -1, 23 }, { -1, 24 }, { -1, 25 }, { -1, 26 }, { -1, 27 }, { -1, 28 }, { -1, 31 }, { -1, 32 }, + { -1, 39 }, { -1, 40 }, { -1, 43 }, { -1, 44 }, { -1, 45 }, { -1, 46 }, { -1, 49 }, { -1, 50 }, { 0, -47 }, { 0, -46 }, { 0, -43 }, { 0, -42 }, { 0, -41 }, { 0, -40 }, { 0, -37 }, { 0, -36 }, { 0, -29 }, { 0, -28 }, { 0, -25 }, { 0, -24 }, { 0, -23 }, { 0, -22 }, { 0, -21 }, { 0, -20 }, { 0, -17 }, { 0, -16 }, { 0, -15 }, { 0, -14 }, { 0, -13 }, { 0, -12 }, + { 0, -9 }, { 0, -8 }, { 0, -7 }, { 0, -6 }, { 0, -3 }, { 0, -2 }, { 0, 5 }, { 0, 6 }, { 0, 9 }, { 0, 10 }, { 0, 11 }, { 0, 12 }, { 0, 15 }, { 0, 16 }, { 0, 17 }, { 0, 18 }, { 0, 19 }, { 0, 20 }, { 0, 23 }, { 0, 24 }, { 0, 25 }, { 0, 26 }, { 0, 27 }, { 0, 28 }, { 0, 31 }, { 0, 32 }, { 0, 39 }, { 0, 40 }, { 0, 43 }, { 0, 44 }, + { 0, 45 }, { 0, 46 }, { 0, 49 }, { 0, 50 }, { 1, -43 }, { 1, -42 }, { 1, -41 }, { 1, -40 }, { 1, -37 }, { 1, -36 }, { 1, -35 }, { 1, -34 }, { 1, -31 }, { 1, -30 }, { 1, -29 }, { 1, -28 }, { 1, -25 }, { 1, -24 }, { 1, -23 }, { 1, -22 }, { 1, -21 }, { 1, -17 }, { 1, -16 }, { 1, -15 }, { 1, -8 }, { 1, -7 }, { 1, -6 }, { 1, -3 }, { 1, -2 }, { 1, -1 }, + { 1, 0 }, { 1, 3 }, { 1, 4 }, { 1, 5 }, { 1, 6 }, { 1, 9 }, { 1, 10 }, { 1, 11 }, { 1, 18 }, { 1, 19 }, { 1, 20 }, { 1, 24 }, { 1, 25 }, { 1, 26 }, { 1, 27 }, { 1, 28 }, { 1, 31 }, { 1, 32 }, { 1, 33 }, { 1, 34 }, { 1, 37 }, { 1, 38 }, { 1, 39 }, { 1, 40 }, { 1, 43 }, { 1, 44 }, { 1, 45 }, { 1, 46 }, { 2, -44 }, { 2, -43 }, + { 2, -42 }, { 2, -41 }, { 2, -40 }, { 2, -37 }, { 2, -36 }, { 2, -35 }, { 2, -34 }, { 2, -31 }, { 2, -30 }, { 2, -29 }, { 2, -28 }, { 2, -25 }, { 2, -24 }, { 2, -23 }, { 2, -22 }, { 2, -18 }, { 2, -17 }, { 2, -16 }, { 2, -7 }, { 2, -6 }, { 2, -3 }, { 2, -2 }, { 2, -1 }, { 2, 0 }, { 2, 3 }, { 2, 4 }, { 2, 5 }, { 2, 6 }, { 2, 9 }, { 2, 10 }, + { 2, 19 }, { 2, 20 }, { 2, 21 }, { 2, 25 }, { 2, 26 }, { 2, 27 }, { 2, 28 }, { 2, 31 }, { 2, 32 }, { 2, 33 }, { 2, 34 }, { 2, 37 }, { 2, 38 }, { 2, 39 }, { 2, 40 }, { 2, 43 }, { 2, 44 }, { 2, 45 }, { 2, 46 }, { 2, 47 }, { 3, -47 }, { 3, -46 }, { 3, -45 }, { 3, -44 }, { 3, -43 }, { 3, -37 }, { 3, -36 }, { 3, -35 }, { 3, -34 }, { 3, -19 }, + { 3, -18 }, { 3, -17 }, { 3, -13 }, { 3, -12 }, { 3, -11 }, { 3, -10 }, { 3, -2 }, { 3, -1 }, { 3, 0 }, { 3, 1 }, { 3, 2 }, { 3, 3 }, { 3, 4 }, { 3, 5 }, { 3, 13 }, { 3, 14 }, { 3, 15 }, { 3, 16 }, { 3, 20 }, { 3, 21 }, { 3, 22 }, { 3, 37 }, { 3, 38 }, { 3, 39 }, { 3, 40 }, { 3, 46 }, { 3, 47 }, { 3, 48 }, { 3, 49 }, { 3, 50 }, + { 4, -47 }, { 4, -46 }, { 4, -45 }, { 4, -44 }, { 4, -37 }, { 4, -36 }, { 4, -35 }, { 4, -34 }, { 4, -19 }, { 4, -18 }, { 4, -13 }, { 4, -12 }, { 4, -11 }, { 4, -10 }, { 4, -1 }, { 4, 0 }, { 4, 1 }, { 4, 2 }, { 4, 3 }, { 4, 4 }, { 4, 13 }, { 4, 14 }, { 4, 15 }, { 4, 16 }, { 4, 21 }, { 4, 22 }, { 4, 37 }, { 4, 38 }, { 4, 39 }, { 4, 40 }, + { 4, 47 }, { 4, 48 }, { 4, 49 }, { 4, 50 }, { 5, -46 }, { 5, -45 }, { 5, -44 }, { 5, -39 }, { 5, -38 }, { 5, -37 }, { 5, -36 }, { 5, -35 }, { 5, -31 }, { 5, -30 }, { 5, -25 }, { 5, -24 }, { 5, -23 }, { 5, -22 }, { 5, -12 }, { 5, -11 }, { 5, -10 }, { 5, -6 }, { 5, -5 }, { 5, 8 }, { 5, 9 }, { 5, 13 }, { 5, 14 }, { 5, 15 }, { 5, 25 }, { 5, 26 }, + { 5, 27 }, { 5, 28 }, { 5, 33 }, { 5, 34 }, { 5, 38 }, { 5, 39 }, { 5, 40 }, { 5, 41 }, { 5, 42 }, { 5, 47 }, { 5, 48 }, { 5, 49 }, { 6, -45 }, { 6, -44 }, { 6, -39 }, { 6, -38 }, { 6, -37 }, { 6, -36 }, { 6, -31 }, { 6, -30 }, { 6, -29 }, { 6, -25 }, { 6, -24 }, { 6, -23 }, { 6, -22 }, { 6, -21 }, { 6, -11 }, { 6, -10 }, { 6, -7 }, { 6, -6 }, + { 6, -5 }, { 6, -4 }, { 6, 7 }, { 6, 8 }, { 6, 9 }, { 6, 10 }, { 6, 13 }, { 6, 14 }, { 6, 24 }, { 6, 25 }, { 6, 26 }, { 6, 27 }, { 6, 28 }, { 6, 32 }, { 6, 33 }, { 6, 34 }, { 6, 39 }, { 6, 40 }, { 6, 41 }, { 6, 42 }, { 6, 47 }, { 6, 48 }, { 7, -45 }, { 7, -44 }, { 7, -30 }, { 7, -29 }, { 7, -28 }, { 7, -24 }, { 7, -23 }, { 7, -22 }, + { 7, -21 }, { 7, -20 }, { 7, -17 }, { 7, -16 }, { 7, -15 }, { 7, -14 }, { 7, -7 }, { 7, -6 }, { 7, -5 }, { 7, -4 }, { 7, -1 }, { 7, 0 }, { 7, 1 }, { 7, 2 }, { 7, 3 }, { 7, 4 }, { 7, 7 }, { 7, 8 }, { 7, 9 }, { 7, 10 }, { 7, 17 }, { 7, 18 }, { 7, 19 }, { 7, 20 }, { 7, 23 }, { 7, 24 }, { 7, 25 }, { 7, 26 }, { 7, 27 }, { 7, 31 }, + { 7, 32 }, { 7, 33 }, { 7, 47 }, { 7, 48 }, { 8, -45 }, { 8, -44 }, { 8, -43 }, { 8, -29 }, { 8, -28 }, { 8, -27 }, { 8, -23 }, { 8, -22 }, { 8, -21 }, { 8, -20 }, { 8, -17 }, { 8, -16 }, { 8, -15 }, { 8, -14 }, { 8, -13 }, { 8, -8 }, { 8, -7 }, { 8, -6 }, { 8, -5 }, { 8, -1 }, { 8, 0 }, { 8, 1 }, { 8, 2 }, { 8, 3 }, { 8, 4 }, { 8, 8 }, + { 8, 9 }, { 8, 10 }, { 8, 11 }, { 8, 16 }, { 8, 17 }, { 8, 18 }, { 8, 19 }, { 8, 20 }, { 8, 23 }, { 8, 24 }, { 8, 25 }, { 8, 26 }, { 8, 30 }, { 8, 31 }, { 8, 32 }, { 8, 46 }, { 8, 47 }, { 8, 48 }, { 9, -44 }, { 9, -43 }, { 9, -42 }, { 9, -33 }, { 9, -32 }, { 9, -29 }, { 9, -28 }, { 9, -27 }, { 9, -26 }, { 9, -23 }, { 9, -22 }, { 9, -21 }, + { 9, -20 }, { 9, -17 }, { 9, -16 }, { 9, -15 }, { 9, -14 }, { 9, -13 }, { 9, -12 }, { 9, -9 }, { 9, -8 }, { 9, -7 }, { 9, 0 }, { 9, 1 }, { 9, 2 }, { 9, 3 }, { 9, 10 }, { 9, 11 }, { 9, 12 }, { 9, 15 }, { 9, 16 }, { 9, 17 }, { 9, 18 }, { 9, 19 }, { 9, 20 }, { 9, 23 }, { 9, 24 }, { 9, 25 }, { 9, 26 }, { 9, 29 }, { 9, 30 }, { 9, 31 }, + { 9, 32 }, { 9, 35 }, { 9, 36 }, { 9, 45 }, { 9, 46 }, { 9, 47 }, { 10, -43 }, { 10, -42 }, { 10, -34 }, { 10, -33 }, { 10, -32 }, { 10, -29 }, { 10, -28 }, { 10, -27 }, { 10, -26 }, { 10, -23 }, { 10, -22 }, { 10, -21 }, { 10, -20 }, { 10, -17 }, { 10, -16 }, { 10, -15 }, { 10, -14 }, { 10, -13 }, { 10, -12 }, { 10, -9 }, { 10, -8 }, { 10, 1 }, { 10, 2 }, { 10, 11 }, + { 10, 12 }, { 10, 15 }, { 10, 16 }, { 10, 17 }, { 10, 18 }, { 10, 19 }, { 10, 20 }, { 10, 23 }, { 10, 24 }, { 10, 25 }, { 10, 26 }, { 10, 29 }, { 10, 30 }, { 10, 31 }, { 10, 32 }, { 10, 35 }, { 10, 36 }, { 10, 37 }, { 10, 45 }, { 10, 46 }, { 11, -39 }, { 11, -38 }, { 11, -35 }, { 11, -34 }, { 11, -33 }, { 11, -32 }, { 11, -29 }, { 11, -28 }, { 11, -27 }, { 11, -16 }, + { 11, -15 }, { 11, -14 }, { 11, -13 }, { 11, -5 }, { 11, -4 }, { 11, -3 }, { 11, -2 }, { 11, 5 }, { 11, 6 }, { 11, 7 }, { 11, 8 }, { 11, 16 }, { 11, 17 }, { 11, 18 }, { 11, 19 }, { 11, 30 }, { 11, 31 }, { 11, 32 }, { 11, 35 }, { 11, 36 }, { 11, 37 }, { 11, 38 }, { 11, 41 }, { 11, 42 }, { 12, -39 }, { 12, -38 }, { 12, -35 }, { 12, -34 }, { 12, -33 }, { 12, -32 }, + { 12, -29 }, { 12, -28 }, { 12, -15 }, { 12, -14 }, { 12, -5 }, { 12, -4 }, { 12, -3 }, { 12, -2 }, { 12, 5 }, { 12, 6 }, { 12, 7 }, { 12, 8 }, { 12, 17 }, { 12, 18 }, { 12, 31 }, { 12, 32 }, { 12, 35 }, { 12, 36 }, { 12, 37 }, { 12, 38 }, { 12, 41 }, { 12, 42 }, { 13, -43 }, { 13, -42 }, { 13, -39 }, { 13, -38 }, { 13, -37 }, { 13, -36 }, { 13, -35 }, { 13, -34 }, + { 13, -33 }, { 13, -19 }, { 13, -18 }, { 13, -9 }, { 13, -8 }, { 13, -4 }, { 13, -3 }, { 13, -2 }, { 13, 1 }, { 13, 2 }, { 13, 5 }, { 13, 6 }, { 13, 7 }, { 13, 11 }, { 13, 12 }, { 13, 21 }, { 13, 22 }, { 13, 36 }, { 13, 37 }, { 13, 38 }, { 13, 39 }, { 13, 40 }, { 13, 41 }, { 13, 42 }, { 13, 45 }, { 13, 46 }, { 14, -43 }, { 14, -42 }, { 14, -39 }, { 14, -38 }, + { 14, -37 }, { 14, -36 }, { 14, -35 }, { 14, -34 }, { 14, -20 }, { 14, -19 }, { 14, -18 }, { 14, -17 }, { 14, -10 }, { 14, -9 }, { 14, -8 }, { 14, -7 }, { 14, -3 }, { 14, -2 }, { 14, 1 }, { 14, 2 }, { 14, 5 }, { 14, 6 }, { 14, 10 }, { 14, 11 }, { 14, 12 }, { 14, 13 }, { 14, 20 }, { 14, 21 }, { 14, 22 }, { 14, 23 }, { 14, 37 }, { 14, 38 }, { 14, 39 }, { 14, 40 }, + { 14, 41 }, { 14, 42 }, { 14, 45 }, { 14, 46 }, { 15, -43 }, { 15, -42 }, { 15, -31 }, { 15, -30 }, { 15, -27 }, { 15, -26 }, { 15, -21 }, { 15, -20 }, { 15, -19 }, { 15, -18 }, { 15, -17 }, { 15, -16 }, { 15, -15 }, { 15, -14 }, { 15, -11 }, { 15, -10 }, { 15, -9 }, { 15, -8 }, { 15, -7 }, { 15, -6 }, { 15, 1 }, { 15, 2 }, { 15, 9 }, { 15, 10 }, { 15, 11 }, { 15, 12 }, + { 15, 13 }, { 15, 14 }, { 15, 17 }, { 15, 18 }, { 15, 19 }, { 15, 20 }, { 15, 21 }, { 15, 22 }, { 15, 23 }, { 15, 24 }, { 15, 29 }, { 15, 30 }, { 15, 33 }, { 15, 34 }, { 15, 45 }, { 15, 46 }, { 16, -43 }, { 16, -42 }, { 16, -32 }, { 16, -31 }, { 16, -30 }, { 16, -27 }, { 16, -26 }, { 16, -25 }, { 16, -21 }, { 16, -20 }, { 16, -19 }, { 16, -18 }, { 16, -17 }, { 16, -16 }, + { 16, -15 }, { 16, -14 }, { 16, -11 }, { 16, -10 }, { 16, -9 }, { 16, -8 }, { 16, -7 }, { 16, -6 }, { 16, 0 }, { 16, 1 }, { 16, 2 }, { 16, 3 }, { 16, 9 }, { 16, 10 }, { 16, 11 }, { 16, 12 }, { 16, 13 }, { 16, 14 }, { 16, 17 }, { 16, 18 }, { 16, 19 }, { 16, 20 }, { 16, 21 }, { 16, 22 }, { 16, 23 }, { 16, 24 }, { 16, 28 }, { 16, 29 }, { 16, 30 }, { 16, 33 }, + { 16, 34 }, { 16, 35 }, { 16, 45 }, { 16, 46 }, { 17, -43 }, { 17, -42 }, { 17, -35 }, { 17, -34 }, { 17, -33 }, { 17, -32 }, { 17, -31 }, { 17, -26 }, { 17, -25 }, { 17, -24 }, { 17, -15 }, { 17, -14 }, { 17, -10 }, { 17, -9 }, { 17, -8 }, { 17, -7 }, { 17, -6 }, { 17, -1 }, { 17, 0 }, { 17, 1 }, { 17, 2 }, { 17, 3 }, { 17, 4 }, { 17, 9 }, { 17, 10 }, { 17, 11 }, + { 17, 12 }, { 17, 13 }, { 17, 17 }, { 17, 18 }, { 17, 27 }, { 17, 28 }, { 17, 29 }, { 17, 34 }, { 17, 35 }, { 17, 36 }, { 17, 37 }, { 17, 38 }, { 17, 45 }, { 17, 46 }, { 18, -43 }, { 18, -42 }, { 18, -41 }, { 18, -35 }, { 18, -34 }, { 18, -33 }, { 18, -32 }, { 18, -25 }, { 18, -24 }, { 18, -23 }, { 18, -15 }, { 18, -14 }, { 18, -13 }, { 18, -9 }, { 18, -8 }, { 18, -7 }, + { 18, -6 }, { 18, -2 }, { 18, -1 }, { 18, 0 }, { 18, 1 }, { 18, 2 }, { 18, 3 }, { 18, 4 }, { 18, 5 }, { 18, 9 }, { 18, 10 }, { 18, 11 }, { 18, 12 }, { 18, 16 }, { 18, 17 }, { 18, 18 }, { 18, 26 }, { 18, 27 }, { 18, 28 }, { 18, 35 }, { 18, 36 }, { 18, 37 }, { 18, 38 }, { 18, 44 }, { 18, 45 }, { 18, 46 }, { 19, -42 }, { 19, -41 }, { 19, -40 }, { 19, -39 }, + { 19, -38 }, { 19, -29 }, { 19, -28 }, { 19, -25 }, { 19, -24 }, { 19, -23 }, { 19, -22 }, { 19, -21 }, { 19, -20 }, { 19, -19 }, { 19, -18 }, { 19, -15 }, { 19, -14 }, { 19, -13 }, { 19, -12 }, { 19, -3 }, { 19, -2 }, { 19, -1 }, { 19, 4 }, { 19, 5 }, { 19, 6 }, { 19, 15 }, { 19, 16 }, { 19, 17 }, { 19, 18 }, { 19, 21 }, { 19, 22 }, { 19, 23 }, { 19, 24 }, { 19, 25 }, + { 19, 26 }, { 19, 27 }, { 19, 28 }, { 19, 31 }, { 19, 32 }, { 19, 41 }, { 19, 42 }, { 19, 43 }, { 19, 44 }, { 19, 45 }, { 20, -41 }, { 20, -40 }, { 20, -39 }, { 20, -38 }, { 20, -37 }, { 20, -29 }, { 20, -28 }, { 20, -25 }, { 20, -24 }, { 20, -23 }, { 20, -22 }, { 20, -21 }, { 20, -20 }, { 20, -19 }, { 20, -18 }, { 20, -15 }, { 20, -14 }, { 20, -13 }, { 20, -12 }, { 20, -3 }, + { 20, -2 }, { 20, 5 }, { 20, 6 }, { 20, 15 }, { 20, 16 }, { 20, 17 }, { 20, 18 }, { 20, 21 }, { 20, 22 }, { 20, 23 }, { 20, 24 }, { 20, 25 }, { 20, 26 }, { 20, 27 }, { 20, 28 }, { 20, 31 }, { 20, 32 }, { 20, 40 }, { 20, 41 }, { 20, 42 }, { 20, 43 }, { 20, 44 }, { 21, -38 }, { 21, -37 }, { 21, -36 }, { 21, -29 }, { 21, -28 }, { 21, -19 }, { 21, -18 }, { 21, -15 }, + { 21, -14 }, { 21, -13 }, { 21, -9 }, { 21, -8 }, { 21, -7 }, { 21, -6 }, { 21, 1 }, { 21, 2 }, { 21, 9 }, { 21, 10 }, { 21, 11 }, { 21, 12 }, { 21, 16 }, { 21, 17 }, { 21, 18 }, { 21, 21 }, { 21, 22 }, { 21, 31 }, { 21, 32 }, { 21, 39 }, { 21, 40 }, { 21, 41 }, { 22, -37 }, { 22, -36 }, { 22, -30 }, { 22, -29 }, { 22, -28 }, { 22, -19 }, { 22, -18 }, { 22, -15 }, + { 22, -14 }, { 22, -9 }, { 22, -8 }, { 22, -7 }, { 22, -6 }, { 22, -5 }, { 22, 0 }, { 22, 1 }, { 22, 2 }, { 22, 3 }, { 22, 8 }, { 22, 9 }, { 22, 10 }, { 22, 11 }, { 22, 12 }, { 22, 17 }, { 22, 18 }, { 22, 21 }, { 22, 22 }, { 22, 31 }, { 22, 32 }, { 22, 33 }, { 22, 39 }, { 22, 40 }, { 23, -33 }, { 23, -32 }, { 23, -31 }, { 23, -30 }, { 23, -29 }, { 23, -25 }, + { 23, -24 }, { 23, -23 }, { 23, -22 }, { 23, -19 }, { 23, -18 }, { 23, -9 }, { 23, -8 }, { 23, -7 }, { 23, -6 }, { 23, -5 }, { 23, -4 }, { 23, -1 }, { 23, 0 }, { 23, 1 }, { 23, 2 }, { 23, 3 }, { 23, 4 }, { 23, 7 }, { 23, 8 }, { 23, 9 }, { 23, 10 }, { 23, 11 }, { 23, 12 }, { 23, 21 }, { 23, 22 }, { 23, 25 }, { 23, 26 }, { 23, 27 }, { 23, 28 }, { 23, 32 }, + { 23, 33 }, { 23, 34 }, { 23, 35 }, { 23, 36 }, { 24, -33 }, { 24, -32 }, { 24, -31 }, { 24, -30 }, { 24, -25 }, { 24, -24 }, { 24, -23 }, { 24, -22 }, { 24, -19 }, { 24, -18 }, { 24, -17 }, { 24, -9 }, { 24, -8 }, { 24, -7 }, { 24, -6 }, { 24, -5 }, { 24, -4 }, { 24, -1 }, { 24, 0 }, { 24, 1 }, { 24, 2 }, { 24, 3 }, { 24, 4 }, { 24, 7 }, { 24, 8 }, { 24, 9 }, + { 24, 10 }, { 24, 11 }, { 24, 12 }, { 24, 20 }, { 24, 21 }, { 24, 22 }, { 24, 25 }, { 24, 26 }, { 24, 27 }, { 24, 28 }, { 24, 33 }, { 24, 34 }, { 24, 35 }, { 24, 36 }, { 25, -39 }, { 25, -38 }, { 25, -37 }, { 25, -36 }, { 25, -24 }, { 25, -23 }, { 25, -22 }, { 25, -19 }, { 25, -18 }, { 25, -17 }, { 25, -16 }, { 25, -6 }, { 25, -5 }, { 25, -4 }, { 25, -1 }, { 25, 0 }, + { 25, 1 }, { 25, 2 }, { 25, 3 }, { 25, 4 }, { 25, 7 }, { 25, 8 }, { 25, 9 }, { 25, 19 }, { 25, 20 }, { 25, 21 }, { 25, 22 }, { 25, 25 }, { 25, 26 }, { 25, 27 }, { 25, 39 }, { 25, 40 }, { 25, 41 }, { 25, 42 }, { 26, -39 }, { 26, -38 }, { 26, -37 }, { 26, -36 }, { 26, -23 }, { 26, -22 }, { 26, -19 }, { 26, -18 }, { 26, -17 }, { 26, -16 }, { 26, -15 }, { 26, -5 }, + { 26, -4 }, { 26, -1 }, { 26, 0 }, { 26, 1 }, { 26, 2 }, { 26, 3 }, { 26, 4 }, { 26, 7 }, { 26, 8 }, { 26, 18 }, { 26, 19 }, { 26, 20 }, { 26, 21 }, { 26, 22 }, { 26, 25 }, { 26, 26 }, { 26, 39 }, { 26, 40 }, { 26, 41 }, { 26, 42 }, { 27, -38 }, { 27, -37 }, { 27, -36 }, { 27, -29 }, { 27, -28 }, { 27, -27 }, { 27, -26 }, { 27, -16 }, { 27, -15 }, { 27, -14 }, + { 27, -9 }, { 27, -8 }, { 27, 11 }, { 27, 12 }, { 27, 17 }, { 27, 18 }, { 27, 19 }, { 27, 29 }, { 27, 30 }, { 27, 31 }, { 27, 32 }, { 27, 39 }, { 27, 40 }, { 27, 41 }, { 28, -37 }, { 28, -36 }, { 28, -30 }, { 28, -29 }, { 28, -28 }, { 28, -27 }, { 28, -26 }, { 28, -15 }, { 28, -14 }, { 28, -10 }, { 28, -9 }, { 28, -8 }, { 28, -7 }, { 28, 10 }, { 28, 11 }, { 28, 12 }, + { 28, 13 }, { 28, 17 }, { 28, 18 }, { 28, 29 }, { 28, 30 }, { 28, 31 }, { 28, 32 }, { 28, 33 }, { 28, 39 }, { 28, 40 }, { 29, -33 }, { 29, -32 }, { 29, -31 }, { 29, -30 }, { 29, -29 }, { 29, -28 }, { 29, -27 }, { 29, -26 }, { 29, -21 }, { 29, -20 }, { 29, -19 }, { 29, -18 }, { 29, -11 }, { 29, -10 }, { 29, -9 }, { 29, -8 }, { 29, -7 }, { 29, -6 }, { 29, -1 }, { 29, 0 }, + { 29, 1 }, { 29, 2 }, { 29, 3 }, { 29, 4 }, { 29, 9 }, { 29, 10 }, { 29, 11 }, { 29, 12 }, { 29, 13 }, { 29, 14 }, { 29, 21 }, { 29, 22 }, { 29, 23 }, { 29, 24 }, { 29, 29 }, { 29, 30 }, { 29, 31 }, { 29, 32 }, { 29, 33 }, { 29, 34 }, { 29, 35 }, { 29, 36 }, { 30, -33 }, { 30, -32 }, { 30, -31 }, { 30, -30 }, { 30, -29 }, { 30, -28 }, { 30, -27 }, { 30, -26 }, + { 30, -22 }, { 30, -21 }, { 30, -20 }, { 30, -19 }, { 30, -18 }, { 30, -11 }, { 30, -10 }, { 30, -9 }, { 30, -8 }, { 30, -7 }, { 30, -6 }, { 30, -5 }, { 30, -1 }, { 30, 0 }, { 30, 1 }, { 30, 2 }, { 30, 3 }, { 30, 4 }, { 30, 8 }, { 30, 9 }, { 30, 10 }, { 30, 11 }, { 30, 12 }, { 30, 13 }, { 30, 14 }, { 30, 21 }, { 30, 22 }, { 30, 23 }, { 30, 24 }, { 30, 25 }, + { 30, 29 }, { 30, 30 }, { 30, 31 }, { 30, 32 }, { 30, 33 }, { 30, 34 }, { 30, 35 }, { 30, 36 }, { 31, -32 }, { 31, -31 }, { 31, -30 }, { 31, -29 }, { 31, -28 }, { 31, -27 }, { 31, -23 }, { 31, -22 }, { 31, -21 }, { 31, -15 }, { 31, -14 }, { 31, -6 }, { 31, -5 }, { 31, -4 }, { 31, -1 }, { 31, 0 }, { 31, 3 }, { 31, 4 }, { 31, 7 }, { 31, 8 }, { 31, 9 }, { 31, 17 }, + { 31, 18 }, { 31, 24 }, { 31, 25 }, { 31, 26 }, { 31, 30 }, { 31, 31 }, { 31, 32 }, { 31, 33 }, { 31, 34 }, { 31, 35 }, { 32, -31 }, { 32, -30 }, { 32, -29 }, { 32, -28 }, { 32, -23 }, { 32, -22 }, { 32, -16 }, { 32, -15 }, { 32, -14 }, { 32, -5 }, { 32, -4 }, { 32, -1 }, { 32, 0 }, { 32, 3 }, { 32, 4 }, { 32, 7 }, { 32, 8 }, { 32, 17 }, { 32, 18 }, { 32, 19 }, + { 32, 25 }, { 32, 26 }, { 32, 31 }, { 32, 32 }, { 32, 33 }, { 32, 34 }, { 33, -30 }, { 33, -29 }, { 33, -28 }, { 33, -23 }, { 33, -22 }, { 33, -17 }, { 33, -16 }, { 33, -15 }, { 33, -11 }, { 33, -10 }, { 33, -9 }, { 33, -8 }, { 33, 11 }, { 33, 12 }, { 33, 13 }, { 33, 14 }, { 33, 18 }, { 33, 19 }, { 33, 20 }, { 33, 25 }, { 33, 26 }, { 33, 31 }, { 33, 32 }, { 33, 33 }, + { 34, -29 }, { 34, -28 }, { 34, -23 }, { 34, -22 }, { 34, -17 }, { 34, -16 }, { 34, -12 }, { 34, -11 }, { 34, -10 }, { 34, -9 }, { 34, -8 }, { 34, 11 }, { 34, 12 }, { 34, 13 }, { 34, 14 }, { 34, 15 }, { 34, 19 }, { 34, 20 }, { 34, 25 }, { 34, 26 }, { 34, 31 }, { 34, 32 }, { 35, -17 }, { 35, -16 }, { 35, -13 }, { 35, -12 }, { 35, -11 }, { 35, -10 }, { 35, -9 }, { 35, -3 }, + { 35, -2 }, { 35, -1 }, { 35, 0 }, { 35, 3 }, { 35, 4 }, { 35, 5 }, { 35, 6 }, { 35, 12 }, { 35, 13 }, { 35, 14 }, { 35, 15 }, { 35, 16 }, { 35, 19 }, { 35, 20 }, { 36, -17 }, { 36, -16 }, { 36, -13 }, { 36, -12 }, { 36, -11 }, { 36, -10 }, { 36, -4 }, { 36, -3 }, { 36, -2 }, { 36, -1 }, { 36, 0 }, { 36, 3 }, { 36, 4 }, { 36, 5 }, { 36, 6 }, { 36, 7 }, + { 36, 13 }, { 36, 14 }, { 36, 15 }, { 36, 16 }, { 36, 19 }, { 36, 20 }, { 37, -27 }, { 37, -26 }, { 37, -25 }, { 37, -24 }, { 37, -21 }, { 37, -20 }, { 37, -13 }, { 37, -12 }, { 37, -5 }, { 37, -4 }, { 37, -3 }, { 37, -2 }, { 37, -1 }, { 37, 0 }, { 37, 1 }, { 37, 2 }, { 37, 3 }, { 37, 4 }, { 37, 5 }, { 37, 6 }, { 37, 7 }, { 37, 8 }, { 37, 15 }, { 37, 16 }, + { 37, 23 }, { 37, 24 }, { 37, 27 }, { 37, 28 }, { 37, 29 }, { 37, 30 }, { 38, -27 }, { 38, -26 }, { 38, -25 }, { 38, -24 }, { 38, -21 }, { 38, -20 }, { 38, -19 }, { 38, -13 }, { 38, -12 }, { 38, -5 }, { 38, -4 }, { 38, -3 }, { 38, -2 }, { 38, -1 }, { 38, 0 }, { 38, 1 }, { 38, 2 }, { 38, 3 }, { 38, 4 }, { 38, 5 }, { 38, 6 }, { 38, 7 }, { 38, 8 }, { 38, 15 }, + { 38, 16 }, { 38, 22 }, { 38, 23 }, { 38, 24 }, { 38, 27 }, { 38, 28 }, { 38, 29 }, { 38, 30 }, { 39, -26 }, { 39, -25 }, { 39, -24 }, { 39, -20 }, { 39, -19 }, { 39, -18 }, { 39, -13 }, { 39, -12 }, { 39, -11 }, { 39, -10 }, { 39, -5 }, { 39, -4 }, { 39, 7 }, { 39, 8 }, { 39, 13 }, { 39, 14 }, { 39, 15 }, { 39, 16 }, { 39, 21 }, { 39, 22 }, { 39, 23 }, { 39, 27 }, + { 39, 28 }, { 39, 29 }, { 40, -25 }, { 40, -24 }, { 40, -19 }, { 40, -18 }, { 40, -13 }, { 40, -12 }, { 40, -11 }, { 40, -10 }, { 40, -5 }, { 40, -4 }, { 40, 7 }, { 40, 8 }, { 40, 13 }, { 40, 14 }, { 40, 15 }, { 40, 16 }, { 40, 21 }, { 40, 22 }, { 40, 27 }, { 40, 28 }, { 41, -19 }, { 41, -18 }, { 41, -1 }, { 41, 0 }, { 41, 1 }, { 41, 2 }, { 41, 3 }, { 41, 4 }, + { 41, 21 }, { 41, 22 }, { 42, -19 }, { 42, -18 }, { 42, -17 }, { 42, -1 }, { 42, 0 }, { 42, 1 }, { 42, 2 }, { 42, 3 }, { 42, 4 }, { 42, 20 }, { 42, 21 }, { 42, 22 }, { 43, -18 }, { 43, -17 }, { 43, -16 }, { 43, -15 }, { 43, -14 }, { 43, -13 }, { 43, -12 }, { 43, -9 }, { 43, -8 }, { 43, -1 }, { 43, 0 }, { 43, 1 }, { 43, 2 }, { 43, 3 }, { 43, 4 }, { 43, 11 }, + { 43, 12 }, { 43, 15 }, { 43, 16 }, { 43, 17 }, { 43, 18 }, { 43, 19 }, { 43, 20 }, { 43, 21 }, { 44, -17 }, { 44, -16 }, { 44, -15 }, { 44, -14 }, { 44, -13 }, { 44, -12 }, { 44, -9 }, { 44, -8 }, { 44, -7 }, { 44, -2 }, { 44, -1 }, { 44, 0 }, { 44, 1 }, { 44, 2 }, { 44, 3 }, { 44, 4 }, { 44, 5 }, { 44, 10 }, { 44, 11 }, { 44, 12 }, { 44, 15 }, { 44, 16 }, + { 44, 17 }, { 44, 18 }, { 44, 19 }, { 44, 20 }, { 45, -8 }, { 45, -7 }, { 45, -6 }, { 45, -5 }, { 45, -4 }, { 45, -3 }, { 45, -2 }, { 45, -1 }, { 45, 4 }, { 45, 5 }, { 45, 6 }, { 45, 7 }, { 45, 8 }, { 45, 9 }, { 45, 10 }, { 45, 11 }, { 46, -7 }, { 46, -6 }, { 46, -5 }, { 46, -4 }, { 46, -3 }, { 46, -2 }, { 46, 5 }, { 46, 6 }, { 46, 7 }, { 46, 8 }, + { 46, 9 }, { 46, 10 }, { 47, -4 }, { 47, -3 }, { 47, -2 }, { 47, 1 }, { 47, 2 }, { 47, 5 }, { 47, 6 }, { 47, 7 }, { 48, -3 }, { 48, -2 }, { 48, 1 }, { 48, 2 }, { 48, 5 }, { 48, 6 }, + }, }, resource_tiles = { enabled = false, resources = { { enabled = false, - name = 'iron-ore', + name = "iron-ore", amount = 4000, - size = {26, 27}, + size = { 26, 27 }, -- offset = {-64,-32} - offset = {-64,-64} + offset = { -64, -64 }, }, { enabled = false, - name = 'copper-ore', + name = "copper-ore", amount = 4000, - size = {26, 27}, + size = { 26, 27 }, -- offset = {-64, 0} - offset = {64, -64} + offset = { 64, -64 }, }, { enabled = false, - name = 'stone', + name = "stone", amount = 4000, - size = {22, 20}, + size = { 22, 20 }, -- offset = {-64, 32} - offset = {-64, 64} + offset = { -64, 64 }, }, { enabled = false, - name = 'coal', + name = "coal", amount = 4000, - size = {22, 20}, + size = { 22, 20 }, -- offset = {-64, -64} - offset = {64, 64} + offset = { 64, 64 }, }, { enabled = false, - name = 'uranium-ore', + name = "uranium-ore", amount = 4000, - size = {22, 20}, + size = { 22, 20 }, -- offset = {-64, -96} - offset = {0, 64} - } - } + offset = { 0, 64 }, + }, + }, }, resource_patches = { enabled = false, resources = { { enabled = false, - name = 'crude-oil', + name = "crude-oil", num_patches = 4, amount = 4000000, -- offset = {-80, -12}, - offset = {-12, 64}, + offset = { -12, 64 }, -- offset_next = {0, 6} - offset_next = {6, 0} - } - } + offset_next = { 6, 0 }, + }, + }, }, resource_refill_nearby = { enabled = false, range = 128, resources_name = { - 'iron-ore', - 'copper-ore', - 'stone', - 'coal', - 'uranium-ore' + "iron-ore", + "copper-ore", + "stone", + "coal", + "uranium-ore", }, - amount = {2500, 4000} - } -} \ No newline at end of file + amount = { 2500, 4000 }, + }, +} diff --git a/exp_legacy/module/config/station_auto_name.lua b/exp_legacy/module/config/station_auto_name.lua index d95cfd97..60f93124 100644 --- a/exp_legacy/module/config/station_auto_name.lua +++ b/exp_legacy/module/config/station_auto_name.lua @@ -7,5 +7,5 @@ return { __x__ __y__ ]] - station_name = '[L] __icon__' -} \ No newline at end of file + station_name = "[L] __icon__", +} diff --git a/exp_legacy/module/config/statistics.lua b/exp_legacy/module/config/statistics.lua index c766972f..c4a4d4a0 100644 --- a/exp_legacy/module/config/statistics.lua +++ b/exp_legacy/module/config/statistics.lua @@ -27,20 +27,20 @@ return { JoinCount = e.on_player_joined_game, TilesRemoved = e.on_player_mined_tile, CapsulesUsed = e.on_player_used_capsule, - EntityRepaired= e.on_player_repaired_entity + EntityRepaired = e.on_player_repaired_entity, }, display_order = { --- @setting display_order The order that the statistics should be shown in when in a gui or command - 'Playtime', 'AfkTime', - 'MapsPlayed', 'JoinCount', - 'ChatMessages', 'CommandsUsed', - 'RocketsLaunched', 'ResearchCompleted', - 'MachinesBuilt', 'MachinesRemoved', - 'TilesBuilt', 'TilesRemoved', - 'TreesDestroyed', 'OreMined', - 'ItemsCrafted', 'ItemsPickedUp', - 'Kills', 'Deaths', - 'DamageDealt', 'DistanceTravelled', - 'CapsulesUsed', 'EntityRepaired', - 'DeconstructionPlannerUsed', 'MapTagsMade' - } -} \ No newline at end of file + "Playtime", "AfkTime", + "MapsPlayed", "JoinCount", + "ChatMessages", "CommandsUsed", + "RocketsLaunched", "ResearchCompleted", + "MachinesBuilt", "MachinesRemoved", + "TilesBuilt", "TilesRemoved", + "TreesDestroyed", "OreMined", + "ItemsCrafted", "ItemsPickedUp", + "Kills", "Deaths", + "DamageDealt", "DistanceTravelled", + "CapsulesUsed", "EntityRepaired", + "DeconstructionPlannerUsed", "MapTagsMade", + }, +} diff --git a/exp_legacy/module/config/vlayer.lua b/exp_legacy/module/config/vlayer.lua index 084b352c..d3355c6b 100644 --- a/exp_legacy/module/config/vlayer.lua +++ b/exp_legacy/module/config/vlayer.lua @@ -10,7 +10,7 @@ return { unlimited_surface_area = false, --- @setting unlimited_surface_area When true the vlayer has an unlimited surface area, landfill is not required modded_auto_downgrade = false, --- @setting modded_auto_downgrade When true modded items will be converted into their base game equivalent, original items can not be recovered - mimic_surface = 'nauvis', --- @setting mimic_surface Surface name/index the vlayer will copy its settings from, use nil to use the settings below + mimic_surface = "nauvis", --- @setting mimic_surface Surface name/index the vlayer will copy its settings from, use nil to use the settings below surface = { --- @setting surface When mimic_surface is nil these settings will be used instead, see LuaSurface for details always_day = false, solar_power_multiplier = 1, @@ -20,14 +20,14 @@ return { dusk = 0.25, evening = 0.45, morning = 0.55, - dawn = 0.75 + dawn = 0.75, }, interface_limit = { --- @setting interface_limit Sets the limit for the number of vlayer interfaces that can be created energy = 1, -- >1 allows for disconnected power networks to receive power circuit = 10, -- No caveats storage_input = 10, -- No caveats - storage_output = 1 -- >0 allows for item teleportation (allowed_items only) + storage_output = 1, -- >0 allows for item teleportation (allowed_items only) }, allowed_items = { --- @setting allowed_items List of all items allowed in vlayer storage and their properties @@ -40,36 +40,36 @@ return { capacity = 0: The energy capacity of the item in MJ, used for accumulators surface_area = 0: The surface area provided by the item, used for landfill ]] - ['solar-panel'] = { + ["solar-panel"] = { starting_value = 0, required_area = 9, - production = 0.06 -- MW + production = 0.06, -- MW }, - ['accumulator'] = { + ["accumulator"] = { starting_value = 0, required_area = 4, discharge = 0.3, -- MW - capacity = 5 -- MJ + capacity = 5, -- MJ }, - ['landfill'] = { + ["landfill"] = { starting_value = 0, required_area = 0, - surface_area = 6 -- Tiles + surface_area = 6, -- Tiles }, - ['wood'] = { + ["wood"] = { starting_value = 0, required_area = 0, surface_area = 0, fuel_value = 2, -- MJ - power = true -- turn all wood to power to reduce trash + power = true, -- turn all wood to power to reduce trash }, - ['coal'] = { + ["coal"] = { starting_value = 0, required_area = 0, surface_area = 0, fuel_value = 4, -- MJ - power = false -- turn all coal to power to reduce trash - } + power = false, -- turn all coal to power to reduce trash + }, --[[ ['iron-ore'] = { starting_value = 0, @@ -100,75 +100,75 @@ return { }, modded_items = { --- @setting modded_items List of all modded items allowed in vlayer storage and their base game equivalent - ['solar-panel-2'] = { + ["solar-panel-2"] = { starting_value = 0, - base_game_equivalent = 'solar-panel', - multiplier = 4 + base_game_equivalent = "solar-panel", + multiplier = 4, }, - ['solar-panel-3'] = { + ["solar-panel-3"] = { starting_value = 0, - base_game_equivalent = 'solar-panel', - multiplier = 16 + base_game_equivalent = "solar-panel", + multiplier = 16, }, - ['solar-panel-4'] = { + ["solar-panel-4"] = { starting_value = 0, - base_game_equivalent = 'solar-panel', - multiplier = 64 + base_game_equivalent = "solar-panel", + multiplier = 64, }, - ['solar-panel-5'] = { + ["solar-panel-5"] = { starting_value = 0, - base_game_equivalent = 'solar-panel', - multiplier = 256 + base_game_equivalent = "solar-panel", + multiplier = 256, }, - ['solar-panel-6'] = { + ["solar-panel-6"] = { starting_value = 0, - base_game_equivalent = 'solar-panel', - multiplier = 1024 + base_game_equivalent = "solar-panel", + multiplier = 1024, }, - ['solar-panel-7'] = { + ["solar-panel-7"] = { starting_value = 0, - base_game_equivalent = 'solar-panel', - multiplier = 4096 + base_game_equivalent = "solar-panel", + multiplier = 4096, }, - ['solar-panel-8'] = { + ["solar-panel-8"] = { starting_value = 0, - base_game_equivalent = 'solar-panel', - multiplier = 16384 + base_game_equivalent = "solar-panel", + multiplier = 16384, }, - ['accumulator-2'] = { + ["accumulator-2"] = { starting_value = 0, - base_game_equivalent = 'accumulator', - multiplier = 4 + base_game_equivalent = "accumulator", + multiplier = 4, }, - ['accumulator-3'] = { + ["accumulator-3"] = { starting_value = 0, - base_game_equivalent = 'accumulator', - multiplier = 16 + base_game_equivalent = "accumulator", + multiplier = 16, }, - ['accumulator-4'] = { + ["accumulator-4"] = { starting_value = 0, - base_game_equivalent = 'accumulator', - multiplier = 64 + base_game_equivalent = "accumulator", + multiplier = 64, }, - ['accumulator-5'] = { + ["accumulator-5"] = { starting_value = 0, - base_game_equivalent = 'accumulator', - multiplier = 256 + base_game_equivalent = "accumulator", + multiplier = 256, }, - ['accumulator-6'] = { + ["accumulator-6"] = { starting_value = 0, - base_game_equivalent = 'accumulator', - multiplier = 1024 + base_game_equivalent = "accumulator", + multiplier = 1024, }, - ['accumulator-7'] = { + ["accumulator-7"] = { starting_value = 0, - base_game_equivalent = 'accumulator', - multiplier = 4096 + base_game_equivalent = "accumulator", + multiplier = 4096, }, - ['accumulator-8'] = { + ["accumulator-8"] = { starting_value = 0, - base_game_equivalent = 'accumulator', - multiplier = 16384 + base_game_equivalent = "accumulator", + multiplier = 16384, }, - } + }, } diff --git a/exp_legacy/module/config/warnings.lua b/exp_legacy/module/config/warnings.lua index 24f85867..3684a088 100644 --- a/exp_legacy/module/config/warnings.lua +++ b/exp_legacy/module/config/warnings.lua @@ -4,18 +4,18 @@ return { actions = { --- @setting actions what actions are taking at number of warnings -- if a localized string is used then __1__ will by_player_name and __2__ will be the current warning count (auto inserted) - {'warnings.received',''}, - {'warnings.received',''}, - {'warnings.received',{'warnings.pre-kick'}}, - function(player,by_player_name,number_of_warnings) - game.kick_player(player,{'warnings.received',by_player_name,number_of_warnings,{'warnings.kick'}}) + { "warnings.received", "" }, + { "warnings.received", "" }, + { "warnings.received", { "warnings.pre-kick" } }, + function(player, by_player_name, number_of_warnings) + game.kick_player(player, { "warnings.received", by_player_name, number_of_warnings, { "warnings.kick" } }) + end, + { "warnings.received", { "warnings.pre-pre-ban" } }, + { "warnings.received", { "warnings.pre-ban" } }, + function(player, by_player_name, number_of_warnings) + game.ban_player(player, { "warnings.received", by_player_name, number_of_warnings, { "warnings.ban", { "links.website" } } }) end, - {'warnings.received',{'warnings.pre-pre-ban'}}, - {'warnings.received',{'warnings.pre-ban'}}, - function(player,by_player_name,number_of_warnings) - game.ban_player(player,{'warnings.received',by_player_name,number_of_warnings,{'warnings.ban',{'links.website'}}}) - 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_limit=5 --- @setting script_warning_limit the number of script warnings (given by script) that are allowed before full warnings are given -} \ No newline at end of file + 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_limit = 5, --- @setting script_warning_limit the number of script warnings (given by script) that are allowed before full warnings are given +} diff --git a/exp_legacy/module/control.lua b/exp_legacy/module/control.lua index eb4c100f..6dbed200 100644 --- a/exp_legacy/module/control.lua +++ b/exp_legacy/module/control.lua @@ -1,18 +1,17 @@ - --- Please go to ./config if you want to change settings, each file is commented with what it does -- if it is not in ./config then you should not attempt to change it unless you know what you are doing -- 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 local _xpcall = xpcall -xpcall = function (func, error_handler, ...) +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 -log('[START] -----| Explosive Gaming Scenario Loader |-----') -log('[INFO] Setting up lua environment') +log("[START] -----| Explosive Gaming Scenario Loader |-----") +log("[INFO] Setting up lua environment") -- Require the global overrides require("modules.exp_legacy.overrides.table") -- Adds alot more functions to the table module @@ -20,38 +19,39 @@ storage.version = require("modules.exp_legacy.overrides.version") -- The current _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 -log('[INFO] Reading loader config') +log("[INFO] Reading loader config") local files = require("modules.exp_legacy.config._file_loader") -- Error handler for loading files local errors = {} local error_count = 0 -local error_format = '[ERROR] %s :: %s' +local error_format = "[ERROR] %s :: %s" local currently_loading = nil local function error_handler(err) error_count = error_count + 1 - if err:find('module '..currently_loading..' not found;', nil, true) then - log('[ERROR] File not found: '..currently_loading) + if err:find("module " .. currently_loading .. " not found;", nil, true) then + log("[ERROR] File not found: " .. currently_loading) errors[error_count] = error_format:format(currently_loading, err) else - log('[ERROR] Failed to load: '..currently_loading) + log("[ERROR] Failed to load: " .. currently_loading) errors[error_count] = debug.traceback(error_format:format(currently_loading, err)) end end -- Loads all files from the config and logs that they are loaded -local total_file_count = string.format('%3d', #files) +local total_file_count = string.format("%3d", #files) for index, path in pairs(files) do currently_loading = path - log(string.format('[INFO] Loading file %3d/%s (%s)', index, total_file_count, path)) + log(string.format("[INFO] Loading file %3d/%s (%s)", index, total_file_count, path)) xpcall(require, error_handler, "modules.exp_legacy." .. path) end -- Logs all errors again to make it make it easy to find -log('[INFO] All files loaded with '..error_count..' errors:') +log("[INFO] All files loaded with " .. error_count .. " errors:") for _, error in ipairs(errors) do log(error) end -log('[END] -----| Explosive Gaming Scenario Loader |-----') + +log("[END] -----| Explosive Gaming Scenario Loader |-----") --- Register all event handlers via clusterio local Event = require("modules/exp_legacy/utils/event") -return Event.real_handlers \ No newline at end of file +return Event.real_handlers diff --git a/exp_legacy/module/expcore/commands.lua b/exp_legacy/module/expcore/commands.lua index afe6eb20..3ed374e6 100644 --- a/exp_legacy/module/expcore/commands.lua +++ b/exp_legacy/module/expcore/commands.lua @@ -191,9 +191,9 @@ local trace = debug.traceback local Commands = { --- Constant values used by the command system defines = { - error = 'CommandError', - unauthorized = 'CommandErrorUnauthorized', - success = 'CommandSuccess' + error = "CommandError", + unauthorized = "CommandErrorUnauthorized", + success = "CommandSuccess", }, --- An array of all custom commands that are registered commands = {}, @@ -243,7 +243,7 @@ Commands.remove_authenticator(admin_authenticator) ]] function Commands.remove_authenticator(authenticator) - if type(authenticator) == 'number' then + if type(authenticator) == "number" then -- If a number is passed then it is assumed to be the index if Commands.authenticators[authenticator] then Commands.authenticators[authenticator] = nil @@ -281,15 +281,15 @@ function Commands.authorize(player, command_name) -- This is the reject function given to authenticators local failure_message local function reject(message) - failure_message = message or {'expcore-commands.unauthorized'} + failure_message = message or { "expcore-commands.unauthorized" } return Commands.defines.unauthorized end -- This is the internal error function used when an authenticator errors local function authenticator_error(err) - log('[ERROR] Authorization failed: '..trace(err)) + log("[ERROR] Authorization failed: " .. trace(err)) if Commands.authorization_failure_on_error then - return reject('Internal Error') + return reject("Internal Error") end end @@ -298,7 +298,7 @@ function Commands.authorize(player, command_name) -- player: LuaPlayer, command: string, flags: table, reject: function(error_message: string) local _, rtn = xpcall(authenticator, authenticator_error, player, command_name, command_data.flags, reject) if rtn == false or rtn == Commands.defines.unauthorized or rtn == reject or failure_message ~= nil then - if failure_message == nil then failure_message = {'expcore-commands.unauthorized'} end + if failure_message == nil then failure_message = { "expcore-commands.unauthorized" } end return false, failure_message end end @@ -370,7 +370,10 @@ end) function Commands.parse(name, input, player, reject, ...) if not Commands.parsers[name] then return end local success, rtn = pcall(Commands.parsers[name], input, player, reject, ...) - if not success then error(rtn, 2) return end + if not success then + error(rtn, 2) + return + end if not rtn or rtn == Commands.defines.error then return end return rtn end @@ -398,6 +401,7 @@ function Commands.get(player) allowed[name] = command_data end end + return allowed end @@ -420,12 +424,13 @@ function Commands.search(keyword, player) -- Loops over custom commands for name, command_data in pairs(custom_commands) do -- combines name help and aliases into one message to be searched - local search = string.format('%s %s %s %s', name, command_data.help, command_data.searchable_description, table.concat(command_data.aliases, ' ')) + local search = string.format("%s %s %s %s", name, command_data.help, command_data.searchable_description, table.concat(command_data.aliases, " ")) if search:lower():match(keyword) then matches[name] = command_data end end + -- Loops over the names of game commands for name, description in pairs(commands.game_commands) do if name:lower():match(keyword) then @@ -433,11 +438,12 @@ function Commands.search(keyword, player) matches[name] = { name = name, help = description, - description = '', - aliases = {} + description = "", + aliases = {}, } end end + return matches end @@ -458,16 +464,16 @@ function Commands.new_command(name, help, descr) local command = setmetatable({ name = name, help = help, - searchable_description = descr or '', - callback = function() Commands.internal_error(false, name, 'No callback registered') end, + searchable_description = descr or "", + callback = function() Commands.internal_error(false, name, "No callback registered") end, auto_concat = false, min_param_count = 0, max_param_count = 0, - flags = {}, -- stores flags that can be used by auth + flags = {}, -- stores flags that can be used by auth aliases = {}, -- stores aliases to this command - params = {}, -- [param_name] = {optional: boolean, default: any, parse: function, parse_args: table} + params = {}, -- [param_name] = {optional: boolean, default: any, parse: function, parse_args: table} }, { - __index = Commands._prototype + __index = Commands._prototype, }) Commands.commands[name] = command return command @@ -491,17 +497,17 @@ end) ]] function Commands._prototype:add_param(name, optional, parse, ...) - local parse_args = {...} - if type(optional) ~= 'boolean' then - parse_args = {parse, ...} + local parse_args = { ... } + if type(optional) ~= "boolean" then + parse_args = { parse, ... } parse = optional optional = false end self.params[name] = { - optional = optional, - parse = parse or function(string) return string end, - parse_args = parse_args + optional = optional, + parse = parse or function(string) return string end, + parse_args = parse_args, } self.max_param_count = self.max_param_count + 1 @@ -532,6 +538,7 @@ function Commands._prototype:set_defaults(defaults) self.params[name].default = value end end + return self end @@ -562,9 +569,10 @@ command:add_alias('name', 'rname') ]] function Commands._prototype:add_alias(...) local start_index = #self.aliases - for index, alias in ipairs{...} do - self.aliases[start_index+index] = alias + for index, alias in ipairs{ ... } do + self.aliases[start_index + index] = alias end + return self end @@ -600,14 +608,15 @@ function Commands._prototype:register(callback) self.callback = callback -- Generates a description to be used - local description = '' + local description = "" for param_name, param_details in pairs(self.params) do if param_details.optional then - description = string.format('%s [%s]', description, param_name) + description = string.format("%s [%s]", description, param_name) else - description = string.format('%s <%s>', description, param_name) + description = string.format("%s <%s>", description, param_name) end end + self.description = description -- Last resort error handler for commands @@ -622,7 +631,7 @@ function Commands._prototype:register(callback) end -- Registers the command under its own name - local help = {'expcore-commands.command-help', description, self.help} + local help = { "expcore-commands.command-help", description, self.help } commands.add_command(self.name, help, command_callback) -- Adds any aliases that it has @@ -650,7 +659,7 @@ return 'Your message has been printed' ]] function Commands.success(value) if value ~= nil then player_return(value) end - player_return({'expcore-commands.command-ran'}, 'cyan') + player_return({ "expcore-commands.command-ran" }, "cyan") return Commands.defines.success end @@ -675,11 +684,11 @@ return Commands.error('The player you selected is offline') ]] function Commands.error(error_message, play_sound) - error_message = error_message or '' - player_return({'expcore-commands.command-fail', error_message}, 'orange_red') + error_message = error_message or "" + player_return({ "expcore-commands.command-fail", error_message }, "orange_red") if play_sound ~= false then - play_sound = play_sound or 'utility/wire_pickup' - if game.player then game.player.play_sound{path=play_sound} end + play_sound = play_sound or "utility/wire_pickup" + if game.player then game.player.play_sound{ path = play_sound } end end return Commands.defines.error end @@ -700,22 +709,22 @@ end ]] function Commands.internal_error(success, command_name, error_message) if not success then - Commands.error('Internal Error, Please contact an admin', 'utility/cannot_build') - log{'expcore-commands.command-error-log-format', command_name, error_message} + Commands.error("Internal Error, Please contact an admin", "utility/cannot_build") + log{ "expcore-commands.command-error-log-format", command_name, error_message } end return not success end --- Logs command usage to file local function command_log(player, command, comment, params, raw, details) - local player_name = player and player.name or '' - write_json('log/commands.log', { - player_name = player_name, + local player_name = player and player.name or "" + write_json("log/commands.log", { + player_name = player_name, command_name = command.name, - comment = comment, - details = details, - params = params, - raw = raw + comment = comment, + details = details, + params = params, + raw = raw, }) end @@ -733,46 +742,46 @@ function Commands.run_command(command_event) -- Check if the player is allowed to use the command local authorized, auth_fail = Commands.authorize(player, command_data.name) if not authorized then - command_log(player, command_data, 'Failed Auth', {}, command_event.parameter) - Commands.error(auth_fail, 'utility/cannot_build') + command_log(player, command_data, "Failed Auth", {}, command_event.parameter) + Commands.error(auth_fail, "utility/cannot_build") return end -- Check for parameter being nil if command_data.min_param_count > 0 and not command_event.parameter then - command_log(player, command_data, 'No Params Given', {}, command_event.parameter) - Commands.error{'expcore-commands.invalid-inputs', command_data.name, command_data.description} + command_log(player, command_data, "No Params Given", {}, command_event.parameter) + Commands.error{ "expcore-commands.invalid-inputs", command_data.name, command_data.description } return end -- Extract quoted arguments - local raw_input = command_event.parameter or '' + local raw_input = command_event.parameter or "" local quote_params = {} local input_string = raw_input:gsub('"[^"]-"', function(word) - local no_spaces = word:gsub('%s', '%%s') + local no_spaces = word:gsub("%s", "%%s") quote_params[no_spaces] = word:sub(2, -2) - return ' '..no_spaces..' ' + return " " .. no_spaces .. " " end) -- Extract unquoted arguments local raw_params = {} local last_index = 0 local param_number = 0 - for word in input_string:gmatch('%S+') do + for word in input_string:gmatch("%S+") do param_number = param_number + 1 if param_number > command_data.max_param_count then -- there are too many params given to the command if not command_data.auto_concat then -- error as they should not be more - command_log(player, command_data, 'Invalid Input: Too Many Params', raw_params, raw_input) - Commands.error{'expcore-commands.invalid-inputs', command_data.name, command_data.description} + command_log(player, command_data, "Invalid Input: Too Many Params", raw_params, raw_input) + Commands.error{ "expcore-commands.invalid-inputs", command_data.name, command_data.description } return else -- concat to the last param if quote_params[word] then - raw_params[last_index] = raw_params[last_index]..' "'..quote_params[word]..'"' + raw_params[last_index] = raw_params[last_index] .. ' "' .. quote_params[word] .. '"' else - raw_params[last_index] = raw_params[last_index]..' '..word + raw_params[last_index] = raw_params[last_index] .. " " .. word end end else @@ -790,8 +799,8 @@ function Commands.run_command(command_event) -- Check the param count local param_count = #raw_params if param_count < command_data.min_param_count then - command_log(player, command_data, 'Invalid Input: Not Enough Params', raw_params, raw_input) - Commands.error{'expcore-commands.invalid-inputs', command_data.name, command_data.description} + command_log(player, command_data, "Invalid Input: Not Enough Params", raw_params, raw_input) + Commands.error{ "expcore-commands.invalid-inputs", command_data.name, command_data.description } return end @@ -801,48 +810,46 @@ function Commands.run_command(command_event) for param_name, param_data in pairs(command_data.params) do local parse_callback = param_data.parse -- If its a string this get it from the parser table - if type(parse_callback) == 'string' then + if type(parse_callback) == "string" then parse_callback = Commands.parsers[parse_callback] end -- If its not a function throw and error - if type(parse_callback) ~= 'function' then - Commands.internal_error(false, command_data.name, 'Invalid param parse '..tostring(param_data.parse)) - command_log(player, command_data, 'Internal Error: Invalid Param Parse', params, raw_input, tostring(param_data.parse)) + if type(parse_callback) ~= "function" then + Commands.internal_error(false, command_data.name, "Invalid param parse " .. tostring(param_data.parse)) + command_log(player, command_data, "Internal Error: Invalid Param Parse", params, raw_input, tostring(param_data.parse)) return end -- This is the reject function given to parse callbacks local function reject(error_message) - error_message = error_message or '' - command_log(player, command_data, 'Invalid Param Given', raw_params, input_string) - return Commands.error{'expcore-commands.invalid-param', param_name, error_message} + error_message = error_message or "" + command_log(player, command_data, "Invalid Param Given", raw_params, input_string) + return Commands.error{ "expcore-commands.invalid-param", param_name, error_message } end -- input: string, player: LuaPlayer, reject: function, ... extra args local success, param_parsed = pcall(parse_callback, raw_params[index], player, reject, table.unpack(param_data.parse_args)) if Commands.internal_error(success, command_data.name, param_parsed) then - return command_log(player, command_data, 'Internal Error: Param Parse Fail', params, raw_input, param_parsed) + return command_log(player, command_data, "Internal Error: Param Parse Fail", params, raw_input, param_parsed) end if param_data.optional == true and raw_params[index] == nil then -- If the param is optional and nil then it is set to default param_parsed = param_data.default - if type(param_parsed) == 'function' then + if type(param_parsed) == "function" then success, param_parsed = pcall(param_parsed, player) if Commands.internal_error(success, command_data.name, param_parsed) then - return command_log(player, command_data, 'Internal Error: Default Value Fail', params, raw_input, param_parsed) + return command_log(player, command_data, "Internal Error: Default Value Fail", params, raw_input, param_parsed) end end - elseif param_parsed == nil or param_parsed == Commands.defines.error or param_parsed == reject then -- No value was returned or error was returned, if nil then give generic error if param_parsed ~= Commands.defines.error then - command_log(player, command_data, 'Invalid Param Given', raw_params, raw_input, param_name) - Commands.error{'expcore-commands.command-error-param-format', param_name, 'please make sure it is the correct type'} + command_log(player, command_data, "Invalid Param Given", raw_params, raw_input, param_name) + Commands.error{ "expcore-commands.command-error-param-format", param_name, "please make sure it is the correct type" } end return - end -- Add the param to the table to be passed to the command callback @@ -852,19 +859,19 @@ function Commands.run_command(command_event) -- Run the command -- player: LuaPlayer, ... command params, raw: string - params[command_data.max_param_count+1] = raw_input + params[command_data.max_param_count + 1] = raw_input local success, rtn = pcall(command_data.callback, player, table.unpack(params)) if Commands.internal_error(success, command_data.name, rtn) then - return command_log(player, command_data, 'Internal Error: Command Callback Fail', raw_params, command_event.parameter, rtn) + return command_log(player, command_data, "Internal Error: Command Callback Fail", raw_params, command_event.parameter, rtn) end -- Give output to the player if rtn == Commands.defines.error or rtn == Commands.error then - return command_log(player, command_data, 'Custom Error', raw_params, raw_input) + return command_log(player, command_data, "Custom Error", raw_params, raw_input) elseif rtn ~= Commands.defines.success and rtn ~= Commands.success then Commands.success(rtn) end - command_log(player, command_data, 'Success', raw_params, raw_input) + command_log(player, command_data, "Success", raw_params, raw_input) end return Commands diff --git a/exp_legacy/module/expcore/common.lua b/exp_legacy/module/expcore/common.lua index daa385bc..9e36490c 100644 --- a/exp_legacy/module/expcore/common.lua +++ b/exp_legacy/module/expcore/common.lua @@ -40,7 +40,7 @@ type_error(value, 'number', 'Value must be a number') ]] function Common.type_error(value, test_type, error_message, level) - level = level and level+1 or 2 + level = level and level + 1 or 2 return Common.type_check(value, test_type) or error(error_message, level) end @@ -60,6 +60,7 @@ function Common.multi_type_check(value, test_types) return true end end + return false end @@ -75,7 +76,7 @@ multi_type_error('foo', {'string', 'table'}, 'Value must be a string or table') ]] function Common.multi_type_error(value, test_types, error_message, level) - level = level and level+1 or 2 + level = level and level + 1 or 2 return Common.mult_type_check(value, test_types) or error(error_message, level) end @@ -95,12 +96,12 @@ validate_argument_type(value, 'number', 2, 'repeat_count') ]] function Common.validate_argument_type(value, test_type, param_number, param_name) if not Common.test_type(value, test_type) then - local function_name = debug.getinfo(2, 'n').name or '' + local function_name = debug.getinfo(2, "n").name or "" local error_message if param_name then - error_message = string.format('Bad argument #%d to %q; %q is of type %s expected %s', param_number, function_name, param_name, type(value), test_type) + error_message = string.format("Bad argument #%d to %q; %q is of type %s expected %s", param_number, function_name, param_name, type(value), test_type) else - error_message = string.format('Bad argument #%d to %q; argument is of type %s expected %s', param_number, function_name, type(value), test_type) + error_message = string.format("Bad argument #%d to %q; argument is of type %s expected %s", param_number, function_name, type(value), test_type) end return error(error_message, 3) end @@ -123,12 +124,12 @@ validate_argument_type(value, {'string', 'table'}, 2, 'player') ]] function Common.validate_argument_multi_type(value, test_types, param_number, param_name) if not Common.multi_type_check(value, test_types) then - local function_name = debug.getinfo(2, 'n').name or '' + local function_name = debug.getinfo(2, "n").name or "" local error_message if param_name then - error_message = string.format('Bad argument #%2d to %q; %q is of type %s expected %s', param_number, function_name, param_name, type(value), table.concat(test_types, ' or ')) + error_message = string.format("Bad argument #%2d to %q; %q is of type %s expected %s", param_number, function_name, param_name, type(value), table.concat(test_types, " or ")) else - error_message = string.format('Bad argument #%2d to %q; argument is of type %s expected %s', param_number, function_name, type(value), table.concat(test_types, ' or ')) + error_message = string.format("Bad argument #%2d to %q; argument is of type %s expected %s", param_number, function_name, type(value), table.concat(test_types, " or ")) end return error(error_message, 3) end @@ -139,8 +140,8 @@ end -- @usage error_if_runtime() function Common.error_if_runtime() if package.lifecycle == 8 then - local function_name = debug.getinfo(2, 'n').name or '' - error(function_name..' can not be called during runtime', 3) + local function_name = debug.getinfo(2, "n").name or "" + error(function_name .. " can not be called during runtime", 3) end end @@ -171,7 +172,7 @@ local value = Common.resolve_value(self.defaut_value, self) ]] function Common.resolve_value(value, ...) - return value and type(value) == 'function' and value(...) or value + return value and type(value) == "function" and value(...) or value end --- Converts a varible into its boolean value, nil and false return false @@ -190,8 +191,8 @@ end --- Returns a string for a number with comma seperators -- @usage comma_value(input_number) function Common.comma_value(n) -- credit http://richard.warburton.it - local left, num, right = string.match(n, '^([^%d]*%d)(%d*)(.-)$') - return left .. (num:reverse():gsub('(%d%d%d)', '%1, '):reverse()) .. right + local left, num, right = string.match(n, "^([^%d]*%d)(%d*)(.-)$") + return left .. (num:reverse():gsub("(%d%d%d)", "%1, "):reverse()) .. right end --[[-- Sets a table element to value while also returning value. @@ -218,7 +219,7 @@ write_json('dump', tbl) ]] function Common.write_json(path, tbl) - game.write_file(path, game.table_to_json(tbl)..'\n', true, 0) + game.write_file(path, game.table_to_json(tbl) .. "\n", true, 0) end --[[-- Calls a require that will not error if the file is not found @@ -232,8 +233,11 @@ local Module = opt_require 'expcore.common' ]] function Common.opt_require(path) local success, rtn = pcall(require, path) - if success then return rtn - else return nil, rtn end + if success then + return rtn + else + return nil, rtn + end end --[[-- Returns a desync safe file path for the current file @@ -246,7 +250,7 @@ local file_path = get_file_path() ]] function Common.get_file_path(offset) offset = offset or 0 - return debug.getinfo(offset+2, 'S').short_src:sub(10, -5) + return debug.getinfo(offset + 2, "S").short_src:sub(10, -5) end --[[-- Converts a table to an enum @@ -264,18 +268,21 @@ local colors = enum{ function Common.enum(tbl) local rtn = {} for k, v in pairs(tbl) do - if type(k) ~= 'number' then - rtn[v]=k + if type(k) ~= "number" then + rtn[v] = k end end + for k, v in pairs(tbl) do - if type(k) == 'number' then + if type(k) == "number" then table.insert(rtn, v) end end + for k, v in pairs(rtn) do - rtn[v]=k + rtn[v] = k end + return rtn end @@ -297,7 +304,7 @@ local key = auto_complete(tbl, "foo", true, true) ]] function Common.auto_complete(options, input, use_key, rtn_key) - if type(input) ~= 'string' then return end + if type(input) ~= "string" then return end input = input:lower() for key, value in pairs(options) do local check = use_key and key or value @@ -319,7 +326,7 @@ local player_name = get_actor() ]] function Common.get_actor(player_name) - return game.player and game.player.name or player_name or '' + return game.player and game.player.name or player_name or "" end --[[-- Returns a message with valid chat tags to change its colour @@ -333,8 +340,8 @@ local message = format_chat_colour('Hello, World!', { r=355, g=100, b=100 }) ]] function Common.format_chat_colour(message, color) color = color or Colours.white - local color_tag = '[color='..math.round(color.r, 3)..', '..math.round(color.g, 3)..', '..math.round(color.b, 3)..']' - return string.format('%s%s[/color]', color_tag, message) + local color_tag = "[color=" .. math.round(color.r, 3) .. ", " .. math.round(color.g, 3) .. ", " .. math.round(color.b, 3) .. "]" + return string.format("%s%s[/color]", color_tag, message) end --[[-- Returns a message with valid chat tags to change its colour, using localization @@ -348,8 +355,8 @@ local message = format_chat_colour_localized('Hello, World!', { r=355, g=100, b= ]] function Common.format_chat_colour_localized(message, color) color = color or Colours.white - color = math.round(color.r, 3)..', '..math.round(color.g, 3)..', '..math.round(color.b, 3) - return {'color-tag', color, message} + color = math.round(color.r, 3) .. ", " .. math.round(color.g, 3) .. ", " .. math.round(color.b, 3) + return { "color-tag", color, message } end --[[-- Returns the players name in the players color @@ -363,7 +370,7 @@ local message = format_chat_player_name(game.player, true) ]] function Common.format_chat_player_name(player, raw_string) player = Game.get_player_from_any(player) - local player_name = player and player.name or '' + local player_name = player and player.name or "" local player_chat_colour = player and player.chat_color or Colours.white if raw_string then return Common.format_chat_colour(player_name, player_chat_colour) @@ -388,37 +395,41 @@ player_return('Hello, World!', nil, player) ]] 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 -- converts the value to a string local returnAsString - 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, "table") or type(value) == "userdata" then + if Common.type_check(value.__self, "userdata") or type(value) == "userdata" then -- value is userdata - returnAsString = 'Cant Display Userdata' - elseif Common.type_check(value[1], 'string') and string.find(value[1], '.+[.].+') and not string.find(value[1], '%s') then + returnAsString = "Cant Display Userdata" + elseif Common.type_check(value[1], "string") and string.find(value[1], ".+[.].+") and not string.find(value[1], "%s") then -- value is a locale string returnAsString = value - 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 returnAsString = tostring(value) else -- value is a table - returnAsString = table.inspect(value, {depth=5, indent=' ', newline='\n'}) + returnAsString = table.inspect(value, { depth = 5, indent = " ", newline = "\n" }) end - elseif Common.type_check(value, 'function') then + elseif Common.type_check(value, "function") then -- value is a function - returnAsString = 'Cant Display Functions' - else returnAsString = tostring(value) end + returnAsString = "Cant Display Functions" + else + returnAsString = tostring(value) + end -- returns to the player or the server if player then -- allows any valid player identifier to be used player = Game.get_player_from_any(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 - player.play_sound{path='utility/scenario_message'} + player.play_sound{ path = "utility/scenario_message" } player.print(returnAsString, colour) - else rcon.print(returnAsString) end + else + rcon.print(returnAsString) + end end --[[-- Formats tick into a clean format, denominations from highest to lowest @@ -444,78 +455,78 @@ local time = format_time(18000, { hours=true, minutes=true, seconds=true, string function Common.format_time(ticks, options) -- Sets up the options options = options or { - days=false, - hours=true, - minutes=true, - seconds=false, - long=false, - time=false, - string=false, - null=false + days = false, + hours = true, + minutes = true, + seconds = false, + long = false, + time = false, + string = false, + null = false, } -- Basic numbers that are used in calculations - local max_days, max_hours, max_minutes, max_seconds = ticks/5184000, ticks/216000, ticks/3600, ticks/60 - 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 max_days, max_hours, max_minutes, max_seconds = ticks / 5184000, ticks / 216000, ticks / 3600, ticks / 60 + local days, hours = max_days, max_hours - math.floor(max_days) * 24 + local minutes, seconds = max_minutes - math.floor(max_hours) * 60, max_seconds - math.floor(max_minutes) * 60 -- Handles overflow of disabled denominations local rtn_days, rtn_hours, rtn_minutes, rtn_seconds = math.floor(days), math.floor(hours), math.floor(minutes), math.floor(seconds) if not options.days then - rtn_hours = rtn_hours + rtn_days*24 + rtn_hours = rtn_hours + rtn_days * 24 end if not options.hours then - rtn_minutes = rtn_minutes + rtn_hours*60 + rtn_minutes = rtn_minutes + rtn_hours * 60 end if not options.minutes then - rtn_seconds = rtn_seconds + rtn_minutes*60 + rtn_seconds = rtn_seconds + rtn_minutes * 60 end -- Creates the null time format, does not work with long if options.null and not options.long then - rtn_days='--' - rtn_hours='--' - rtn_minutes='--' - rtn_seconds='--' + rtn_days = "--" + rtn_hours = "--" + rtn_minutes = "--" + rtn_seconds = "--" end -- Format options - local suffix = 'time-symbol-' - local suffix_2 = '-short' + local suffix = "time-symbol-" + local suffix_2 = "-short" if options.long then - suffix = '' - suffix_2 = '' + suffix = "" + suffix_2 = "" end - 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 - div = options.string and ':' or 'time-format.simple-format-div' + div = options.string and ":" or "time-format.simple-format-div" suffix = false end -- Adds formatting if suffix ~= false then if options.string then -- format it as a string - local long = suffix == '' - rtn_days = long and rtn_days..' days' or rtn_days..'d' - rtn_hours = long and rtn_hours..' hours' or rtn_hours..'h' - rtn_minutes = long and rtn_minutes..' minutes' or rtn_minutes..'m' - rtn_seconds = long and rtn_seconds..' seconds' or rtn_seconds..'s' + local long = suffix == "" + rtn_days = long and rtn_days .. " days" or rtn_days .. "d" + rtn_hours = long and rtn_hours .. " hours" or rtn_hours .. "h" + rtn_minutes = long and rtn_minutes .. " minutes" or rtn_minutes .. "m" + rtn_seconds = long and rtn_seconds .. " seconds" or rtn_seconds .. "s" else - rtn_days = {suffix..'days'..suffix_2, rtn_days} - rtn_hours = {suffix..'hours'..suffix_2, rtn_hours} - rtn_minutes = {suffix..'minutes'..suffix_2, rtn_minutes} - rtn_seconds = {suffix..'seconds'..suffix_2, rtn_seconds} + rtn_days = { suffix .. "days" .. suffix_2, rtn_days } + rtn_hours = { suffix .. "hours" .. suffix_2, rtn_hours } + rtn_minutes = { suffix .. "minutes" .. suffix_2, rtn_minutes } + rtn_seconds = { suffix .. "seconds" .. suffix_2, rtn_seconds } end elseif not options.null then -- weather string or not it has same format - rtn_days = string.format('%02d', rtn_days) - rtn_hours = string.format('%02d', rtn_hours) - rtn_minutes = string.format('%02d', rtn_minutes) - rtn_seconds = string.format('%02d', rtn_seconds) + rtn_days = string.format("%02d", rtn_days) + rtn_hours = string.format("%02d", rtn_hours) + rtn_minutes = string.format("%02d", rtn_minutes) + rtn_seconds = string.format("%02d", rtn_seconds) end -- The final return is construed local rtn local append = function(dom, value) if dom and options.string then - rtn = rtn and rtn..div..value or value + rtn = rtn and rtn .. div .. value or value elseif dom then - rtn = rtn and {div, rtn, value} or value + rtn = rtn and { div, rtn, value } or value end end append(options.days, rtn_days) @@ -542,51 +553,52 @@ copy_items_stack(game.player.get_main_inventory().get_contents()) ]] function Common.copy_items_stack(items, surface, position, radius, chest_type) - chest_type = chest_type or 'iron-chest' - surface = surface or game.surfaces[1] - if position and type(position) ~= 'table' then return end - if type(items) ~= 'table' then return end - -- Finds all entities of the given type - local p = position or {x=0, y=0} - local r = radius or 32 - local entities = surface.find_entities_filtered{area={{p.x-r, p.y-r}, {p.x+r, p.y+r}}, name=chest_type} or {} - local count = #entities - local current = 1 - -- Makes a new empty chest when it is needed - local function make_new_chest() - local pos = surface.find_non_colliding_position(chest_type, position, 32, 1) - local chest = surface.create_entity{name=chest_type, position=pos, force='neutral'} - table.insert(entities, chest) - count = count + 1 - return chest - end - -- Function used to round robin the items into all chests - local function next_chest(item) - local chest = entities[current] - if count == 0 then return make_new_chest() end - if chest.get_inventory(defines.inventory.chest).can_insert(item) then - -- If the item can be inserted then the chest is returned - current = current+1 - if current > count then current = 1 end - return chest - else - -- Other wise it is removed from the list - table.remove(entities, current) - count = count - 1 - end - end - -- Inserts the items into the chests - local last_chest - for i=1,#items do - local item = items[i] - if item.valid_for_read then - local chest = next_chest(item) - if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item.name, surface.name, p.x, p.y)) end - chest.insert(item) - last_chest = chest - end - end - return last_chest + chest_type = chest_type or "iron-chest" + surface = surface or game.surfaces[1] + if position and type(position) ~= "table" then return end + if type(items) ~= "table" then return end + -- Finds all entities of the given type + local p = position or { x = 0, y = 0 } + local r = radius or 32 + local entities = surface.find_entities_filtered{ area = { { p.x - r, p.y - r }, { p.x + r, p.y + r } }, name = chest_type } or {} + local count = #entities + local current = 1 + -- Makes a new empty chest when it is needed + local function make_new_chest() + local pos = surface.find_non_colliding_position(chest_type, position, 32, 1) + local chest = surface.create_entity{ name = chest_type, position = pos, force = "neutral" } + table.insert(entities, chest) + count = count + 1 + return chest + end + -- Function used to round robin the items into all chests + local function next_chest(item) + local chest = entities[current] + if count == 0 then return make_new_chest() end + if chest.get_inventory(defines.inventory.chest).can_insert(item) then + -- If the item can be inserted then the chest is returned + current = current + 1 + if current > count then current = 1 end + return chest + else + -- Other wise it is removed from the list + table.remove(entities, current) + count = count - 1 + end + end + -- Inserts the items into the chests + local last_chest + for i = 1, #items do + local item = items[i] + if item.valid_for_read then + local chest = next_chest(item) + if not chest or not chest.valid then return error(string.format("Cant move item %s to %s{%s, %s} no valid chest in radius", item.name, surface.name, p.x, p.y)) end + chest.insert(item) + last_chest = chest + end + end + + return last_chest end --[[-- Moves items to the position and stores them in the closest entity of the type given @@ -603,23 +615,23 @@ move_items_stack(game.player.get_main_inventory()) ]] function Common.move_items_stack(items, surface, position, radius, chest_type) - chest_type = chest_type or 'steel-chest' - surface = surface or game.surfaces[1] + chest_type = chest_type or "steel-chest" + surface = surface or game.surfaces[1] - if position and type(position) ~= 'table' then + if position and type(position) ~= "table" then return end - if type(items) ~= 'table' then + if type(items) ~= "table" then return end - -- Finds all entities of the given type - local p = position or {x=0, y=0} - local r = radius or 32 - local entities = surface.find_entities_filtered{area={{p.x - r, p.y - r}, {p.x + r, p.y + r}}, name={chest_type, 'iron-chest'}} or {} - local count = #entities - local current = 0 + -- Finds all entities of the given type + local p = position or { x = 0, y = 0 } + local r = radius or 32 + local entities = surface.find_entities_filtered{ area = { { p.x - r, p.y - r }, { p.x + r, p.y + r } }, name = { chest_type, "iron-chest" } } or {} + local count = #entities + local current = 0 local last_entity = nil -- ipairs does not work on LuaInventory @@ -664,7 +676,7 @@ function Common.move_items_stack(items, surface, position, radius, chest_type) ]] local pos = surface.find_non_colliding_position(chest_type, p, r, 1, true) - last_entity = surface.create_entity{name=chest_type, position=pos, force='neutral'} + last_entity = surface.create_entity{ name = chest_type, position = pos, force = "neutral" } count = count + 1 entities[count] = last_entity @@ -675,63 +687,63 @@ function Common.move_items_stack(items, surface, position, radius, chest_type) end --[[ - -- Makes a new empty chest when it is needed - local function make_new_chest() - local pos = surface.find_non_colliding_position(chest_type, position, 32, 1) - local chest = surface.create_entity{name=chest_type, position=pos, force='neutral'} - table.insert(entities, chest) - count = count + 1 + -- Makes a new empty chest when it is needed + local function make_new_chest() + local pos = surface.find_non_colliding_position(chest_type, position, 32, 1) + local chest = surface.create_entity{name=chest_type, position=pos, force='neutral'} + table.insert(entities, chest) + count = count + 1 - return chest - end + return chest + end - -- Function used to round robin the items into all chests - local function next_chest(item) - local chest = entities[current] + -- Function used to round robin the items into all chests + local function next_chest(item) + local chest = entities[current] - if count == 0 then + if count == 0 then return make_new_chest() end - if chest.get_inventory(defines.inventory.chest).can_insert(item) then - -- If the item can be inserted then the chest is returned - current = current + 1 - if current > count then + if chest.get_inventory(defines.inventory.chest).can_insert(item) then + -- If the item can be inserted then the chest is returned + current = current + 1 + if current > count then current = 1 end - return chest + return chest - else - -- Other wise it is removed from the list - table.remove(entities, current) - count = count - 1 - end - end + else + -- Other wise it is removed from the list + table.remove(entities, current) + count = count - 1 + end + end - -- Inserts the items into the chests - local last_chest + -- Inserts the items into the chests + local last_chest - for i=1,#items do - local item = items[i] + for i=1,#items do + local item = items[i] if item.valid_for_read then - local chest = next_chest(item) + local chest = next_chest(item) - if not chest or not chest.valid then + if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item.name, surface.name, p.x, p.y)) end - local empty_stack = chest.get_inventory(defines.inventory.chest).find_empty_stack(item.name) + local empty_stack = chest.get_inventory(defines.inventory.chest).find_empty_stack(item.name) if not empty_stack then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item.name, surface.name, p.x, p.y)) end - empty_stack.transfer_stack(item) - last_chest = chest - end - end + empty_stack.transfer_stack(item) + last_chest = chest + end + end return last_chest ]] @@ -753,34 +765,34 @@ print_grid_value(0, game.player.surface, { x=0, y=0 }) ]] function Common.print_grid_value(value, surface, position, scale, offset, immutable) - local is_string = type(value) == 'string' + local is_string = type(value) == "string" local color = Colours.white local text = value - if type(immutable) ~= 'boolean' then + if type(immutable) ~= "boolean" then immutable = false end if not is_string then scale = scale or 1 offset = offset or 0 - position = {x = position.x + offset, y = position.y + offset} - local r = math.clamp(-value/scale, 0, 1) - local g = math.clamp(1-math.abs(value)/scale, 0, 1) - local b = math.clamp(value/scale, 0, 1) + position = { x = position.x + offset, y = position.y + offset } + local r = math.clamp(-value / scale, 0, 1) + local g = math.clamp(1 - math.abs(value) / scale, 0, 1) + local b = math.clamp(value / scale, 0, 1) - color = { r = r, g = g, b = b} + color = { r = r, g = g, b = b } -- round at precision of 2 text = math.floor(100 * value) * 0.01 if (0 == text) then - text = '0.00' + text = "0.00" end end if not immutable then - local text_entity = surface.find_entity('flying-text', position) + local text_entity = surface.find_entity("flying-text", position) if text_entity then text_entity.text = text @@ -790,10 +802,10 @@ function Common.print_grid_value(value, surface, position, scale, offset, immuta end surface.create_entity{ - name = 'flying-text', + name = "flying-text", color = color, text = text, - position = position + position = position, }.active = false end @@ -805,7 +817,7 @@ clear_flying_text(game.player.surface) ]] function Common.clear_flying_text(surface) - local entities = surface.find_entities_filtered{name ='flying-text'} + local entities = surface.find_entities_filtered{ name = "flying-text" } for _, entity in pairs(entities) do if entity and entity.valid then entity.destroy() diff --git a/exp_legacy/module/expcore/datastore.lua b/exp_legacy/module/expcore/datastore.lua index da1ca956..27b5d278 100644 --- a/exp_legacy/module/expcore/datastore.lua +++ b/exp_legacy/module/expcore/datastore.lua @@ -169,8 +169,8 @@ end) --- Metatable used on datastores DatastoreManager.metatable = { __index = function(self, key) return rawget(self.children, key) or rawget(Datastore, key) end, - __newidnex = function(_, _, _) error('Datastore can not be modified', 2) end, - __call = function(self, ...) return self:get(...) end + __newidnex = function(_, _, _) error("Datastore can not be modified", 2) end, + __call = function(self, ...) return self:get(...) end, } --[[-- Make a new datastore connection, if a connection already exists then it is returned @@ -188,7 +188,7 @@ function DatastoreManager.connect(datastoreName, saveToDisk, autoSave, propagate if Datastores[datastoreName] then return Datastores[datastoreName] end if package.lifecycle ~= package.lifecycle_stage.control then -- Only allow this function to be called during the control stage - error('New datastore connection can not be created during runtime', 2) + error("New datastore connection can not be created during runtime", 2) end local new_datastore = { @@ -202,7 +202,7 @@ function DatastoreManager.connect(datastoreName, saveToDisk, autoSave, propagate children = {}, metadata = {}, events = {}, - data = {} + data = {}, } Data[datastoreName] = new_datastore.data @@ -220,7 +220,7 @@ local BarData = Datastore.combine('ExampleData', 'Bar') ]] function DatastoreManager.combine(datastoreName, subDatastoreName) - local datastore = assert(Datastores[datastoreName], 'Datastore not found '..tostring(datastoreName)) + local datastore = assert(Datastores[datastoreName], "Datastore not found " .. tostring(datastoreName)) return datastore:combine(subDatastoreName) end @@ -235,27 +235,23 @@ Datastore.ingest('request', 'ExampleData', 'TestKey', 'Foo') ]] function DatastoreManager.ingest(action, datastoreName, key, valueJson) - local datastore = assert(Datastores[datastoreName], 'Datastore ingest error, Datastore not found '..tostring(datastoreName)) - 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)) + local datastore = assert(Datastores[datastoreName], "Datastore ingest error, Datastore not found " .. tostring(datastoreName)) + assert(type(action) == "string", "Datastore ingest error, Action is not a string got: " .. type(action)) + assert(type(key) == "string", "Datastore ingest error, Key is not a string got: " .. type(key)) - if action == 'remove' then + if action == "remove" then datastore:raw_set(key) - - elseif action == 'message' then + elseif action == "message" then local success, value = pcall(game.json_to_table, valueJson) if not success or value == nil then value = tonumber(valueJson) or valueJson end - datastore:raise_event('on_message', key, value) - - elseif action == 'propagate' or action == 'request' then + datastore:raise_event("on_message", key, value) + elseif action == "propagate" or action == "request" then local success, value = pcall(game.json_to_table, valueJson) if not success or value == nil then value = tonumber(valueJson) or valueJson end local 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) - end - end --[[-- Debug, Use to get all datastores, or return debug info on a datastore @@ -270,7 +266,7 @@ local debug_info = Datastore.debug('ExampleData') ]] function DatastoreManager.debug(datastoreName) if not datastoreName then return Datastores end - local datastore = assert(Datastores[datastoreName], 'Datastore not found '..tostring(datastoreName)) + local datastore = assert(Datastores[datastoreName], "Datastore not found " .. tostring(datastoreName)) return datastore:debug() end @@ -308,11 +304,13 @@ function Datastore:debug() end local children = {} - for name in pairs(self.children) do children[#children+1] = name end + for name in pairs(self.children) do children[#children + 1] = name end + if #children > 0 then debug_info.children = children end local events = {} for name, handlers in pairs(self.events) do events[name] = #handlers end + if next(events) then debug_info.events = events end if next(self.metadata) then debug_info.metadata = self.metadata end @@ -334,7 +332,7 @@ function Datastore:raw_get(key, fromChild) local data = self.data if self.parent then data = self.parent:raw_get(key, true) - key = self.value_name + key = self.value_name end local value = data[key] if value ~= nil then return value end @@ -360,7 +358,7 @@ function Datastore:raw_set(key, value) end end -local function serialize_error(err) error('An error ocurred in a datastore serializer: '..trace(err)) end +local function serialize_error(err) error("An error ocurred in a datastore serializer: " .. trace(err)) end --[[-- Internal, Return the serialized key @tparam any rawKey The key that needs to be serialized, if it is already a string then it is returned @treturn string The key after it has been serialized @@ -370,8 +368,8 @@ key = self:serialize(key) ]] function Datastore:serialize(rawKey) - if type(rawKey) == 'string' then return rawKey end - assert(self.serializer, 'Datastore does not have a serializer and received non string key') + if type(rawKey) == "string" then return rawKey end + assert(self.serializer, "Datastore does not have a serializer and received non string key") local success, key = xpcall(self.serializer, serialize_error, rawKey) return success and key or nil end @@ -389,11 +387,11 @@ self:write_action('save', 'TestKey', 'Foo') ]] function Datastore:write_action(action, key, value) - local data = {action, self.name, key} + local data = { action, self.name, key } if value ~= nil then - data[4] = type(value) == 'table' and game.table_to_json(value) or value + data[4] = type(value) == "table" and game.table_to_json(value) or value end - game.write_file('ext/datastore.out', table.concat(data, ' ')..'\n', true, 0) + game.write_file("ext/datastore.out", table.concat(data, " ") .. "\n", true, 0) end ----- Datastore Local @@ -409,7 +407,7 @@ local BarData = ExampleData:combine('Bar') ]] function Datastore:combine(subDatastoreName) - local new_datastore = DatastoreManager.connect(self.name..'.'..subDatastoreName) + local new_datastore = DatastoreManager.connect(self.name .. "." .. subDatastoreName) self.children[subDatastoreName] = new_datastore new_datastore.value_name = subDatastoreName new_datastore.serializer = self.serializer @@ -431,7 +429,7 @@ end) ]] function Datastore:set_serializer(callback) - assert(type(callback) == 'function', 'Callback must be a function') + assert(type(callback) == "function", "Callback must be a function") self.serializer = callback end @@ -501,7 +499,7 @@ function Datastore:set(key, value) else self:raw_set(key, value) end - self:raise_event('on_update', key, value, old_value) + self:raise_event("on_update", key, value, old_value) if self.auto_save then self:save(key) end return value end @@ -521,7 +519,7 @@ function Datastore:increment(key, delta) return self:set(key, value + (delta or 1)) end -local function update_error(err) log('An error occurred in datastore update:\n\t'..trace(err)) end +local function update_error(err) log("An error occurred in datastore update:\n\t" .. trace(err)) end --[[-- Use a function to update the value locally, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save @tparam any key The key that you want to apply the update to, must be a string unless a serializer is set @tparam function callback The function that will be used to update the value at this key @@ -546,7 +544,7 @@ function Datastore:update(key, callback) elseif raw_value == nil then self:set(key, value) else - self:raise_event('on_update', key, value, old_value) + self:raise_event("on_update", key, value, old_value) if self.auto_save then self:save(key) end end end @@ -563,12 +561,12 @@ function Datastore:remove(key) key = self:serialize(key) local old_value = self:raw_get(key) self:raw_set(key) - self:raise_event('on_update', key, nil, old_value) - if self.save_to_disk then self:write_action('remove', key) end + self:raise_event("on_update", key, nil, old_value) + if self.save_to_disk then self:write_action("remove", key) end if self.parent and self.parent.auto_save then return self.parent:save(key) end end -local function filter_error(err) log('An error ocurred in a datastore filter:\n\t'..trace(err)) end +local function filter_error(err) log("An error ocurred in a datastore filter:\n\t" .. trace(err)) end --[[-- Internal, Used to filter elements from a table @tparam table tbl The table that will have the filter applied to it @tparam[opt] function callback The function that will be used as a filter, if none giving then the provided table is returned @@ -587,6 +585,7 @@ local function filter(tbl, callback) local success, add = xpcall(callback, filter_error, key, value) if success and add then rtn[key] = value end end + return rtn end @@ -613,6 +612,7 @@ function Datastore:get_all(callback) for key, value in pairs(self.parent:get_all()) do data[key] = value[value_name] end + return filter(data, callback) end end @@ -635,7 +635,7 @@ function Datastore:update_all(callback) if success and new_value ~= nil then self:set(key, new_value) else - self:raise_event('on_update', key, value, old_value) + self:raise_event("on_update", key, value, old_value) if self.auto_save then self:save(key) end end end @@ -655,7 +655,7 @@ ExampleData:request('TestKey') function Datastore:request(key) if self.parent then return self.parent:request(key) end key = self:serialize(key) - self:write_action('request', key) + self:write_action("request", key) end --[[-- Save a value to an external source, will trigger on_save before data is saved, save_to_disk must be set to true @@ -670,8 +670,8 @@ function Datastore:save(key) if self.parent then self.parent:save(key) end if not self.save_to_disk then return end key = self:serialize(key) - local value = self:raise_event('on_save', key, copy(self:raw_get(key))) - local action = self.propagate_changes and 'propagate' or 'save' + local value = self:raise_event("on_save", key, copy(self:raw_get(key))) + local action = self.propagate_changes and "propagate" or "save" self:write_action(action, key, value) end @@ -686,7 +686,7 @@ ExampleData:unload('TestKey') function Datastore:unload(key) if self.parent then return self.parent:unload(key) end key = self:serialize(key) - self:raise_event('on_unload', key, copy(self:raw_get(key))) + self:raise_event("on_unload", key, copy(self:raw_get(key))) self:save(key) self:raw_set(key) end @@ -702,7 +702,7 @@ ExampleData:message('TestKey', 'Foo') ]] function Datastore:message(key, message) key = self:serialize(key) - self:write_action('message', key, message) + self:write_action("message", key, message) end --[[-- Save all the keys in the datastore, optional filter callback @@ -746,7 +746,7 @@ end ----- Events -- @section events -local function event_error(err) log('An error ocurred in a datastore event handler:\n\t'..trace(err)) end +local function event_error(err) log("An error ocurred in a datastore event handler:\n\t" .. trace(err)) end --[[-- Internal, Raise an event on this datastore @tparam string event_name The name of the event to raise for this datastore @tparam string key The key that this event is being raised for @@ -761,11 +761,11 @@ value = self:raise_event('on_save', key, value) ]] function Datastore:raise_event(event_name, key, value, old_value, source) -- Raise the event for the children of this datastore - if source ~= 'child' and next(self.children) then - if type(value) ~= 'table' then value = {} end + if source ~= "child" and next(self.children) then + if type(value) ~= "table" then value = {} end for value_name, child in pairs(self.children) do local old_child_value = old_value and old_value[value_name] or nil - value[value_name] = child:raise_event(event_name, key, value[value_name], old_child_value, 'parent') + value[value_name] = child:raise_event(event_name, key, value[value_name], old_child_value, "parent") end end @@ -779,13 +779,13 @@ function Datastore:raise_event(event_name, key, value, old_value, source) end -- Raise the event for the parent of this datastore - if source ~= 'parent' and self.parent then + if source ~= "parent" and self.parent then local parent_value = self.parent:raw_get(key, true) - self.parent:raise_event(event_name, key, parent_value, parent_value, 'child') + self.parent:raise_event(event_name, key, parent_value, parent_value, "child") end -- If this is the save event and the table is empty then return nil - if event_name == 'on_save' and next(self.children) and not next(value) then return end + if event_name == "on_save" and next(self.children) and not next(value) then return end return value end @@ -799,12 +799,12 @@ Datastore.on_load = event_factory('on_load') ]] local function event_factory(event_name) return function(self, callback) - assert(type(callback) == 'function', 'Handler must be a function') + assert(type(callback) == "function", "Handler must be a function") local handlers = self.events[event_name] if not handlers then self.events[event_name] = { callback } else - handlers[#handlers+1] = callback + handlers[#handlers + 1] = callback end end end @@ -817,7 +817,7 @@ ExampleData:on_load(function(key, value) game.print('Test data loaded for: '..key) end) ]] -Datastore.on_load = event_factory('on_load') +Datastore.on_load = event_factory("on_load") --[[-- Register a callback that triggers before data is saved, returned value is saved externally @tparam function callback The handler that will be registered to the on_load event @@ -827,7 +827,7 @@ ExampleData:on_save(function(key, value) game.print('Test data saved for: '..key) end) ]] -Datastore.on_save = event_factory('on_save') +Datastore.on_save = event_factory("on_save") --[[-- Register a callback that triggers before data is unloaded, returned value is ignored @tparam function callback The handler that will be registered to the on_load event @@ -837,7 +837,7 @@ ExampleData:on_load(function(key, value) game.print('Test data unloaded for: '..key) end) ]] -Datastore.on_unload = event_factory('on_unload') +Datastore.on_unload = event_factory("on_unload") --[[-- Register a callback that triggers when a message is received, returned value is ignored @tparam function callback The handler that will be registered to the on_load event @@ -847,7 +847,7 @@ ExampleData:on_message(function(key, value) game.print('Test data message for: '..key) end) ]] -Datastore.on_message = event_factory('on_message') +Datastore.on_message = event_factory("on_message") --[[-- Register a callback that triggers any time a value is changed, returned value is ignored @tparam function callback The handler that will be registered to the on_load event @@ -857,7 +857,7 @@ ExampleData:on_update(function(key, value) game.print('Test data updated for: '..key) end) ]] -Datastore.on_update = event_factory('on_update') +Datastore.on_update = event_factory("on_update") ----- Module Return return DatastoreManager diff --git a/exp_legacy/module/expcore/external.lua b/exp_legacy/module/expcore/external.lua index 27cf8699..95375cbd 100644 --- a/exp_legacy/module/expcore/external.lua +++ b/exp_legacy/module/expcore/external.lua @@ -47,8 +47,8 @@ local servers = External.get_servers() ]] function External.get_servers() - assert(ext, 'No external data was found, use External.valid() to ensure external data exists.') - return assert(ext.servers, 'No server list was found, please ensure that the external service is running') + assert(ext, "No external data was found, use External.valid() to ensure external data exists.") + return assert(ext.servers, "No server list was found, please ensure that the external service is running") end --[[-- Gets a table of all the servers filtered by name, key is the server id, value is the server details @@ -60,14 +60,15 @@ local servers = External.get_servers_filtered(public) ]] function External.get_servers_filtered(search) - assert(ext, 'No external data was found, use External.valid() to ensure external data exists.') - local servers = assert(ext.servers, 'No server list was found, please ensure that the external service is running') + assert(ext, "No external data was found, use External.valid() to ensure external data exists.") + local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running") local found_servers = {} search = search:lower() for server_id, server in pairs(servers) do - local str = concat{server.name, server.short_name, server.id} + local str = concat{ server.name, server.short_name, server.id } if str:lower():find(search, 1, true) then found_servers[server_id] = server end end + return found_servers end @@ -79,9 +80,9 @@ local server = External.get_current_server() ]] function External.get_current_server() - assert(ext, 'No external data was found, use External.valid() to ensure external data exists.') - local servers = assert(ext.servers, 'No server list was found, please ensure that the external service is running') - local server_id = assert(ext.current, 'No current id was found, please ensure that the external service is running') + assert(ext, "No external data was found, use External.valid() to ensure external data exists.") + local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running") + local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running") return servers[server_id] end @@ -94,8 +95,8 @@ local server = External.get_server_details('eu-01') ]] function External.get_server_details(server_id) - assert(ext, 'No external data was found, use External.valid() to ensure external data exists.') - local servers = assert(ext.servers, 'No server list was found, please ensure that the external service is running') + assert(ext, "No external data was found, use External.valid() to ensure external data exists.") + local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running") return servers[server_id] end @@ -109,10 +110,10 @@ local status = External.get_server_status('eu-01') ]] function External.get_server_status(server_id, raw) - assert(var, 'No external data was found, use External.valid() to ensure external data exists.') - local servers = assert(var.status, 'No server status was found, please ensure that the external service is running') - local current = assert(ext.current, 'No current id was found, please ensure that the external service is running') - return not raw and server_id == current and 'Current' or servers[server_id] + assert(var, "No external data was found, use External.valid() to ensure external data exists.") + local servers = assert(var.status, "No server status was found, please ensure that the external service is running") + local current = assert(ext.current, "No current id was found, please ensure that the external service is running") + return not raw and server_id == current and "Current" or servers[server_id] end --[[-- Gets the ups of the current server @@ -121,8 +122,8 @@ local server_ups = External.get_server_ups() ]] function External.get_server_ups() - assert(var, 'No external data was found, use External.valid() to ensure external data exists.') - return assert(var.server_ups, 'No server ups was found, please ensure that the external service is running') + assert(var, "No external data was found, use External.valid() to ensure external data exists.") + return assert(var.server_ups, "No server ups was found, please ensure that the external service is running") end --[[-- Connect a player to the given server @@ -138,16 +139,16 @@ External.request_connection(player, 'eu-01', true) ]] function External.request_connection(player, server_id, self_requested) - local server = { address = server_id, name = 'Unknown Server', description = 'This server is not ran by us, please check the address of the server.' } + local server = { address = server_id, name = "Unknown Server", description = "This server is not ran by us, please check the address of the server." } if ext and ext.servers and ext.servers[server_id] then server = ext.servers[server_id] end - local message = 'Please press the connect button below to join.' - if not self_requested then message = 'You have been asked to switch to a different server.\n'..message end + local message = "Please press the connect button below to join." + if not self_requested then message = "You have been asked to switch to a different server.\n" .. message end player.connect_to_server{ address = server.address, - name = '\n[color=orange][font=heading-1]'..server.name..'[/font][/color]\n', - description = server.description..'\n'..message + name = "\n[color=orange][font=heading-1]" .. server.name .. "[/font][/color]\n", + description = server.description .. "\n" .. message, } end --- Module return -return External \ No newline at end of file +return External diff --git a/exp_legacy/module/expcore/gui/_require.lua b/exp_legacy/module/expcore/gui/_require.lua index 1c2ecf8f..ab2ca4ec 100644 --- a/exp_legacy/module/expcore/gui/_require.lua +++ b/exp_legacy/module/expcore/gui/_require.lua @@ -132,13 +132,12 @@ local Roles = _C.opt_require("modules.exp_legacy.expcore.roles") local Event = _C.opt_require("modules/exp_legacy/utils/event") if Roles and Event then - Event.add(Roles.events.on_role_assigned, function(e) - Gui.update_top_flow(game.get_player(e.player_index)) - end) - Event.add(Roles.events.on_role_unassigned, function(e) - Gui.update_top_flow(game.get_player(e.player_index)) - end) + Event.add(Roles.events.on_role_assigned, function(e) + Gui.update_top_flow(game.get_player(e.player_index)) + end) + Event.add(Roles.events.on_role_unassigned, function(e) + Gui.update_top_flow(game.get_player(e.player_index)) + end) end - -return Gui \ No newline at end of file +return Gui diff --git a/exp_legacy/module/expcore/gui/core_defines.lua b/exp_legacy/module/expcore/gui/core_defines.lua index dee098b3..fc61fc7d 100644 --- a/exp_legacy/module/expcore/gui/core_defines.lua +++ b/exp_legacy/module/expcore/gui/core_defines.lua @@ -12,61 +12,61 @@ local Event = require("modules/exp_legacy/utils/event") --- Button which toggles the top flow elements, version which shows inside the top flow when top flow is visible -- @element hide_top_flow local hide_top_flow = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/preset', - style = 'tool_button', - tooltip = {'gui_util.button_tooltip'}, - name = Gui.unique_static_name -} -:style{ - padding = -2, - width = 18, - height = 36 -} -:on_click(function(player, _,_) - Gui.toggle_top_flow(player, false) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/preset", + style = "tool_button", + tooltip = { "gui_util.button_tooltip" }, + name = Gui.unique_static_name, + } + :style{ + padding = -2, + width = 18, + height = 36, + } + :on_click(function(player, _, _) + Gui.toggle_top_flow(player, false) + end) Gui.core_defines.hide_top_flow = hide_top_flow --- Button which toggles the top flow elements, version which shows inside the left flow when top flow is hidden -- @element show_top_flow local show_top_flow = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/preset', - style = 'tool_button', - tooltip = {'gui_util.button_tooltip'}, - name = Gui.unique_static_name -} -:style{ - padding = -2, - width = 18, - height = 20 -} -:on_click(function(player, _,_) - Gui.toggle_top_flow(player, true) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/preset", + style = "tool_button", + tooltip = { "gui_util.button_tooltip" }, + name = Gui.unique_static_name, + } + :style{ + padding = -2, + width = 18, + height = 20, + } + :on_click(function(player, _, _) + Gui.toggle_top_flow(player, true) + end) Gui.core_defines.show_top_flow = show_top_flow --- Button which hides the elements in the left flow, shows inside the left flow when frames are visible -- @element hide_left_flow local hide_left_flow = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/close_black', - style = 'tool_button', - tooltip = {'expcore-gui.left-button-tooltip'}, - name = Gui.unique_static_name -} -:style{ - padding = -3, - width = 18, - height = 20 -} -:on_click(function(player, _,_) - Gui.hide_left_flow(player) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/close_black", + style = "tool_button", + tooltip = { "expcore-gui.left-button-tooltip" }, + name = Gui.unique_static_name, + } + :style{ + padding = -3, + width = 18, + height = 20, + } + :on_click(function(player, _, _) + Gui.hide_left_flow(player) + end) Gui.core_defines.hide_left_flow = hide_left_flow --- Draw the core elements when a player joins the game @@ -80,10 +80,10 @@ Event.add(defines.events.on_player_created, function(event) -- Draw the left flow local left_flow = Gui.get_left_flow(player) - local button_flow = left_flow.add{ type = 'flow', name = 'gui_core_buttons', direction = 'vertical' } + local button_flow = left_flow.add{ type = "flow", name = "gui_core_buttons", direction = "vertical" } local show_top = show_top_flow(button_flow) local hide_left = hide_left_flow(button_flow) show_top.visible = false hide_left.visible = false Gui.draw_left_flow(player) -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/expcore/gui/defines.lua b/exp_legacy/module/expcore/gui/defines.lua index 58bc3e87..548e0365 100644 --- a/exp_legacy/module/expcore/gui/defines.lua +++ b/exp_legacy/module/expcore/gui/defines.lua @@ -24,19 +24,19 @@ local alignment = Gui.alignment(element, 'example_center_top_alignment', 'center ]] Gui.alignment = -Gui.element(function(_, parent, name, _,_) - return parent.add{ - name = name or 'alignment', - type = 'flow', - } -end) -:style(function(style, _,_, horizontal_align, vertical_align) - style.padding = {1, 2} - style.vertical_align = vertical_align or 'center' - style.horizontal_align = horizontal_align or 'right' - style.vertically_stretchable = style.vertical_align ~= 'center' - style.horizontally_stretchable = style.horizontal_align ~= 'center' -end) + Gui.element(function(_, parent, name, _, _) + return parent.add{ + name = name or "alignment", + type = "flow", + } + end) + :style(function(style, _, _, horizontal_align, vertical_align) + style.padding = { 1, 2 } + style.vertical_align = vertical_align or "center" + style.horizontal_align = horizontal_align or "right" + style.vertically_stretchable = style.vertical_align ~= "center" + style.horizontally_stretchable = style.horizontal_align ~= "center" + end) --[[-- Draw a scroll pane that has a table inside of it @element Gui.scroll_table @@ -51,42 +51,42 @@ local scroll_table = Gui.scroll_table(element, 200, 3) ]] Gui.scroll_table = -Gui.element(function(_, parent, height, column_count, name) - -- Draw the scroll - local scroll_pane = - parent.add{ - name = name or 'scroll', - type = 'scroll-pane', - direction = 'vertical', - horizontal_scroll_policy = 'never', - vertical_scroll_policy = 'auto', - style = 'scroll_pane_under_subheader' + Gui.element(function(_, parent, height, column_count, name) + -- Draw the scroll + local scroll_pane = + parent.add{ + name = name or "scroll", + type = "scroll-pane", + direction = "vertical", + horizontal_scroll_policy = "never", + vertical_scroll_policy = "auto", + style = "scroll_pane_under_subheader", + } + + -- Set the style of the scroll pane + local scroll_style = scroll_pane.style + scroll_style.padding = { 1, 3 } + scroll_style.maximal_height = height + scroll_style.horizontally_stretchable = true + + -- Draw the table + local scroll_table = + scroll_pane.add{ + type = "table", + name = "table", + column_count = column_count, + } + + -- Return the scroll table + return scroll_table + end) + :style{ + padding = 0, + cell_padding = 0, + vertical_align = "center", + horizontally_stretchable = true, } - -- Set the style of the scroll pane - local scroll_style = scroll_pane.style - scroll_style.padding = {1, 3} - scroll_style.maximal_height = height - scroll_style.horizontally_stretchable = true - - -- Draw the table - local scroll_table = - scroll_pane.add{ - type = 'table', - name = 'table', - column_count = column_count - } - - -- Return the scroll table - return scroll_table -end) -:style{ - padding = 0, - cell_padding = 0, - vertical_align = 'center', - horizontally_stretchable = true -} - --[[-- Used to add a frame with the header style, has the option for a right alignment flow for buttons @element Gui.header @tparam LuaGuiElement parent the parent element to which the header will be added @@ -105,35 +105,35 @@ local header = Gui.header( ]] Gui.header = -Gui.element(function(_, parent, caption, tooltip, add_alignment, name, label_name) - -- Draw the header - local header = - parent.add{ - name = name or 'header', - type = 'frame', - style = 'subheader_frame' - } + Gui.element(function(_, parent, caption, tooltip, add_alignment, name, label_name) + -- Draw the header + local header = + parent.add{ + name = name or "header", + type = "frame", + style = "subheader_frame", + } - -- Change the style of the header - local style = header.style - style.padding = {2, 4} - style.use_header_filler = false - style.horizontally_stretchable = true + -- Change the style of the header + local style = header.style + style.padding = { 2, 4 } + style.use_header_filler = false + style.horizontally_stretchable = true - -- Draw the caption label - if caption then - header.add{ - name = label_name or 'header_label', - type = 'label', - style = 'frame_title', - caption = caption, - tooltip = tooltip - } - end + -- Draw the caption label + if caption then + header.add{ + name = label_name or "header_label", + type = "label", + style = "frame_title", + caption = caption, + tooltip = tooltip, + } + end - -- Return either the header or the added alignment - return add_alignment and Gui.alignment(header) or header -end) + -- Return either the header or the added alignment + return add_alignment and Gui.alignment(header) or header + end) --[[-- Used to add a frame with the footer style, has the option for a right alignment flow for buttons @element Gui.footer @@ -153,35 +153,35 @@ local footer = Gui.footer( ]] Gui.footer = -Gui.element(function(_, parent, caption, tooltip, add_alignment, name) - -- Draw the header - local footer = - parent.add{ - name = name or 'footer', - type = 'frame', - style = 'subfooter_frame' - } + Gui.element(function(_, parent, caption, tooltip, add_alignment, name) + -- Draw the header + local footer = + parent.add{ + name = name or "footer", + type = "frame", + style = "subfooter_frame", + } - -- Change the style of the footer - local style = footer.style - style.padding = {2, 4} - style.use_header_filler = false - style.horizontally_stretchable = true + -- Change the style of the footer + local style = footer.style + style.padding = { 2, 4 } + style.use_header_filler = false + style.horizontally_stretchable = true - -- Draw the caption label - if caption then - footer.add{ - name = 'footer_label', - type = 'label', - style = 'frame_title', - caption = caption, - tooltip = tooltip - } - end + -- Draw the caption label + if caption then + footer.add{ + name = "footer_label", + type = "label", + style = "frame_title", + caption = caption, + tooltip = tooltip, + } + end - -- Return either the footer or the added alignment - return add_alignment and Gui.alignment(footer) or footer -end) + -- Return either the footer or the added alignment + return add_alignment and Gui.alignment(footer) or footer + end) --[[-- Used for left frames to give them a nice boarder @element Gui.container @@ -194,29 +194,29 @@ local container = Gui.container(parent, 'my_container', 200) ]] Gui.container = -Gui.element(function(_, parent, name, _) - -- Draw the external container - local frame = - parent.add{ - name = name, - type = 'frame' - } - frame.style.horizontally_stretchable = false + Gui.element(function(_, parent, name, _) + -- Draw the external container + local frame = + parent.add{ + name = name, + type = "frame", + } + frame.style.horizontally_stretchable = false - -- Return the container - return frame.add{ - name = 'container', - type = 'frame', - direction = 'vertical', - style = 'inside_shallow_frame_packed' - } -end) -:style(function(style, element, _,width) - style.vertically_stretchable = false - local frame_style = element.parent.style - frame_style.padding = 2 - frame_style.minimal_width = width -end) + -- Return the container + return frame.add{ + name = "container", + type = "frame", + direction = "vertical", + style = "inside_shallow_frame_packed", + } + end) + :style(function(style, element, _, width) + style.vertically_stretchable = false + local frame_style = element.parent.style + frame_style.padding = 2 + frame_style.minimal_width = width + end) --[[-- Used to make a solid white bar in a gui @element Gui.bar @@ -228,19 +228,22 @@ local bar = Gui.bar(parent, 100) ]] Gui.bar = -Gui.element(function(_, parent) - return parent.add{ - type = 'progressbar', - size = 1, - value = 1 - } -end) -:style(function(style, _,width) - style.height = 3 - style.color = {r=255, g=255, b=255} - if width then style.width = width - else style.horizontally_stretchable = true end -end) + Gui.element(function(_, parent) + return parent.add{ + type = "progressbar", + size = 1, + value = 1, + } + end) + :style(function(style, _, width) + style.height = 3 + style.color = { r = 255, g = 255, b = 255 } + if width then + style.width = width + else + style.horizontally_stretchable = true + end + end) --[[-- Used to make a label which is centered and of a certian size @element Gui.centered_label @@ -254,20 +257,20 @@ local label = Gui.centered_label(parent, 100, 'This is centered') ]] Gui.centered_label = -Gui.element(function(_, parent, width, caption, tooltip) - local label = parent.add{ - type = 'label', - caption = caption, - tooltip = tooltip, - } + Gui.element(function(_, parent, width, caption, tooltip) + local label = parent.add{ + type = "label", + caption = caption, + tooltip = tooltip, + } - local style = label.style - style.horizontal_align = 'center' - style.single_line = false - style.width = width + local style = label.style + style.horizontal_align = "center" + style.single_line = false + style.width = width - return label -end) + return label + end) --[[-- Used to make a title which has two bars on either side @element Gui.title_label @@ -281,18 +284,18 @@ local label = Gui.centered_label(parent, 100, 'This is centered') ]] Gui.title_label = -Gui.element(function(_, parent, width, caption, tooltip) - local title_flow = parent.add{ type='flow' } - title_flow.style.vertical_align = 'center' + Gui.element(function(_, parent, width, caption, tooltip) + local title_flow = parent.add{ type = "flow" } + title_flow.style.vertical_align = "center" - Gui.bar(title_flow, width) - local title_label = title_flow.add{ - type = 'label', - caption = caption, - tooltip = tooltip, - style = 'frame_title' - } - Gui.bar(title_flow) + Gui.bar(title_flow, width) + local title_label = title_flow.add{ + type = "label", + caption = caption, + tooltip = tooltip, + style = "frame_title", + } + Gui.bar(title_flow) - return title_label -end) \ No newline at end of file + return title_label + end) diff --git a/exp_legacy/module/expcore/gui/helper_functions.lua b/exp_legacy/module/expcore/gui/helper_functions.lua index fb14f1a7..6cfb37db 100644 --- a/exp_legacy/module/expcore/gui/helper_functions.lua +++ b/exp_legacy/module/expcore/gui/helper_functions.lua @@ -88,4 +88,4 @@ function Gui.sprite_style(size, padding, style) style.height = size style.width = size return style -end \ No newline at end of file +end diff --git a/exp_legacy/module/expcore/gui/left_flow.lua b/exp_legacy/module/expcore/gui/left_flow.lua index bf1801f3..460c5ef3 100644 --- a/exp_legacy/module/expcore/gui/left_flow.lua +++ b/exp_legacy/module/expcore/gui/left_flow.lua @@ -4,7 +4,7 @@ ]] local Gui = require("modules.exp_legacy.expcore.gui.prototype") -local mod_gui = require 'mod-gui' +local mod_gui = require "mod-gui" local hide_left_flow = Gui.core_defines.hide_left_flow.name @@ -12,7 +12,7 @@ local hide_left_flow = Gui.core_defines.hide_left_flow.name -- @section leftFlow -- Triggered when a user changed the visibility of a left flow element by clicking a button -Gui.events.on_visibility_changed_by_click = 'on_visibility_changed_by_click' +Gui.events.on_visibility_changed_by_click = "on_visibility_changed_by_click" --- Contains the uids of the elements that will shown on the left flow and their join functions -- @table left_elements @@ -68,7 +68,7 @@ function Gui.left_toolbar_button(sprite, tooltip, element_define, authenticator) button:raise_event{ name = Gui.events.on_visibility_changed_by_click, element = Gui.get_top_element(player, button), - state = Gui.toggle_left_element(player, element_define) + state = Gui.toggle_left_element(player, element_define), } end) @@ -90,8 +90,8 @@ function Gui.inject_left_flow_order(provider) Gui.get_left_flow_order = provider local debug_info = debug.getinfo(2, "Sn") local file_name = debug_info.short_src:sub(10, -5) - local func_name = debug_info.name or ("") - Gui._left_flow_order_src = file_name..":"..func_name + local func_name = debug_info.name or ("") + Gui._left_flow_order_src = file_name .. ":" .. func_name end --[[-- Draw all the left elements onto the left flow, internal use only with on join @@ -121,17 +121,17 @@ function Gui.draw_left_flow(player) end, debug.traceback) if not draw_success then - log('There as been an error with an element draw function: '..element_define.defined_at..'\n\t'..left_element) + log("There as been an error with an element draw function: " .. element_define.defined_at .. "\n\t" .. left_element) goto continue end -- Check if it should be open by default local open_on_join = element_define.open_on_join - local visible = type(open_on_join) == 'boolean' and open_on_join or false - if type(open_on_join) == 'function' then + local visible = type(open_on_join) == "boolean" and open_on_join or false + if type(open_on_join) == "function" then local success, err = xpcall(open_on_join, debug.traceback, player) if not success then - log('There as been an error with an open on join hander for a gui element:\n\t'..err) + log("There as been an error with an open on join hander for a gui element:\n\t" .. err) goto continue end visible = err @@ -166,7 +166,7 @@ function Gui.reorder_left_flow(player) -- Reorder the elements, index 1 is the core ui buttons so +1 is required for index, element_define in ipairs(flow_order) do local element = left_flow[element_define.name] - left_flow.swap_children(index+1, element.get_index_in_parent()) + left_flow.swap_children(index + 1, element.get_index_in_parent()) end end @@ -188,6 +188,7 @@ function Gui.update_left_flow(player) return true end end + hide_button.visible = false return false end @@ -220,7 +221,7 @@ function Gui.hide_left_flow(player) element_define.toolbar_button:raise_event{ name = Gui.events.on_visibility_changed_by_click, element = button, - state = false + state = false, } end end @@ -272,4 +273,4 @@ function Gui.toggle_left_element(player, element_define, state) Gui.toggle_toolbar_button(player, element_define.toolbar_button, state) end return state -end \ No newline at end of file +end diff --git a/exp_legacy/module/expcore/gui/prototype.lua b/exp_legacy/module/expcore/gui/prototype.lua index 463d24da..f6cfcfbf 100644 --- a/exp_legacy/module/expcore/gui/prototype.lua +++ b/exp_legacy/module/expcore/gui/prototype.lua @@ -23,7 +23,7 @@ local Gui = { --- The prototype used to store the functions of an element define _prototype_element = {}, --- The prototype metatable applied to new element defines - _mt_element = {} + _mt_element = {}, } --- Allow access to the element prototype methods @@ -37,14 +37,14 @@ function Gui._mt_element.__call(self, parent, ...) -- Asserts to catch common errors if element then if self.name and self.name ~= element.name then - error("Static name \""..self.name.."\" expected but got: "..tostring(element.name)) + error("Static name \"" .. self.name .. "\" expected but got: " .. tostring(element.name)) end local event_triggers = element.tags and element.tags.ExpGui_event_triggers if event_triggers and table.array_contains(event_triggers, self.uid) then error("Element::triggers_events should not be called on the value you return from the definition") end elseif self.name then - error("Static name \""..self.name.."\" expected but no element was returned from the definition") + error("Static name \"" .. self.name .. "\" expected but no element was returned from the definition") end -- Register events by default, but allow skipping them @@ -59,8 +59,8 @@ end local function get_defined_at(level) local debug_info = debug.getinfo(level, "Sn") local file_name = debug_info.short_src:sub(10, -5) - local func_name = debug_info.name or ("") - return file_name..":"..func_name + local func_name = debug_info.name or ("") + return file_name .. ":" .. func_name end --- Element Define. @@ -115,19 +115,20 @@ function Gui.element(element_define) local uid = Gui.uid + 1 Gui.uid = uid element.uid = uid - Gui.debug_info[uid] = { draw = 'None', style = 'None', events = {} } + Gui.debug_info[uid] = { draw = "None", style = "None", events = {} } -- Add the definition function - if type(element_define) == 'table' then + if type(element_define) == "table" then Gui.debug_info[uid].draw = element_define if element_define.name == Gui.unique_static_name then - element_define.name = "ExpGui_"..tostring(uid) + element_define.name = "ExpGui_" .. tostring(uid) end for k, v in pairs(element_define) do if element[k] == nil then element[k] = v end end + element._draw = function(_, parent) return parent.add(element_define) end @@ -183,7 +184,7 @@ end) function Gui._prototype_element:style(style_define) _C.error_if_runtime() -- Add the definition function - if type(style_define) == 'table' then + if type(style_define) == "table" then Gui.debug_info[self.uid].style = style_define self._style = function(style) for key, value in pairs(style_define) do @@ -206,7 +207,7 @@ end function Gui._prototype_element:static_name(name) _C.error_if_runtime() if name == Gui.unique_static_name then - self.name = "ExpGui_"..tostring(self.uid) + self.name = "ExpGui_" .. tostring(self.uid) else self.name = name end @@ -295,7 +296,7 @@ function Gui._prototype_element:raise_event(event) local success, err = xpcall(handler, debug.traceback, player, element, event) if not success then - error('There as been an error with an event handler for a gui element:\n\t'..err) + error("There as been an error with an event handler for a gui element:\n\t" .. err) end return self end @@ -328,84 +329,84 @@ end -- @tparam function handler the event handler which will be called -- @usage element_define:on_open(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_open = event_handler_factory(defines.events.on_gui_opened) --- Called when the player closes the GUI they have open. -- @tparam function handler the event handler which will be called -- @usage element_define:on_close(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_close = event_handler_factory(defines.events.on_gui_closed) --- Called when LuaGuiElement is clicked. -- @tparam function handler the event handler which will be called -- @usage element_define:on_click(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_click = event_handler_factory(defines.events.on_gui_click) --- Called when a LuaGuiElement is confirmed, for example by pressing Enter in a textfield. -- @tparam function handler the event handler which will be called -- @usage element_define:on_confirmed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_confirmed = event_handler_factory(defines.events.on_gui_confirmed) --- Called when LuaGuiElement checked state is changed (related to checkboxes and radio buttons). -- @tparam function handler the event handler which will be called -- @usage element_define:on_checked_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_checked_changed = event_handler_factory(defines.events.on_gui_checked_state_changed) --- Called when LuaGuiElement element value is changed (related to choose element buttons). -- @tparam function handler the event handler which will be called -- @usage element_define:on_elem_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_elem_changed = event_handler_factory(defines.events.on_gui_elem_changed) --- Called when LuaGuiElement element location is changed (related to frames in player.gui.screen). -- @tparam function handler the event handler which will be called -- @usage element_define:on_location_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_location_changed = event_handler_factory(defines.events.on_gui_location_changed) --- Called when LuaGuiElement selected tab is changed (related to tabbed-panes). -- @tparam function handler the event handler which will be called -- @usage element_define:on_tab_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_tab_changed = event_handler_factory(defines.events.on_gui_selected_tab_changed) --- Called when LuaGuiElement selection state is changed (related to drop-downs and listboxes). -- @tparam function handler the event handler which will be called -- @usage element_define:on_selection_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_selection_changed = event_handler_factory(defines.events.on_gui_selection_state_changed) --- Called when LuaGuiElement switch state is changed (related to switches). -- @tparam function handler the event handler which will be called -- @usage element_define:on_switch_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_switch_changed = event_handler_factory(defines.events.on_gui_switch_state_changed) --- Called when LuaGuiElement text is changed by the player. -- @tparam function handler the event handler which will be called -- @usage element_define:on_text_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_text_changed = event_handler_factory(defines.events.on_gui_text_changed) --- Called when LuaGuiElement slider value is changed (related to the slider element). -- @tparam function handler the event handler which will be called -- @usage element_define:on_value_changed(function(event) -- event.player.print(table.inspect(event)) ---end) +-- end) Gui._prototype_element.on_value_changed = event_handler_factory(defines.events.on_gui_value_changed) -- Module return diff --git a/exp_legacy/module/expcore/gui/top_flow.lua b/exp_legacy/module/expcore/gui/top_flow.lua index a064a805..c6284f12 100644 --- a/exp_legacy/module/expcore/gui/top_flow.lua +++ b/exp_legacy/module/expcore/gui/top_flow.lua @@ -4,7 +4,7 @@ ]] local Gui = require("modules.exp_legacy.expcore.gui.prototype") -local mod_gui = require 'mod-gui' --- @dep mod-gui +local mod_gui = require "mod-gui" --- @dep mod-gui local toolbar_button_size = 36 local hide_top_flow = Gui.core_defines.hide_top_flow.name @@ -14,7 +14,7 @@ local show_top_flow = Gui.core_defines.show_top_flow.name -- @section topFlow -- Triggered when a user changed the visibility of a left flow element by clicking a button -Gui.events.on_toolbar_button_toggled = 'on_toolbar_button_toggled' +Gui.events.on_toolbar_button_toggled = "on_toolbar_button_toggled" --- Contains the uids of the elements that will shown on the top flow and their auth functions -- @table top_elements @@ -26,7 +26,7 @@ Gui.top_flow_button_style = mod_gui.button_style --- The style that should be used for buttons on the top flow when their flow is visible -- @field Gui.top_flow_button_toggled_style -Gui.top_flow_button_toggled_style = 'menu_button_continue' +Gui.top_flow_button_toggled_style = "menu_button_continue" --[[-- Styles a top flow button depending on the state given @tparam LuaGuiElement button the button element to style @@ -40,7 +40,7 @@ Gui.toolbar_button_style(button, false) ]] function Gui.toolbar_button_style(button, state, size) - ---@cast button LuaGuiElement + --- @cast button LuaGuiElement if state then button.style = Gui.top_flow_button_toggled_style else @@ -108,8 +108,8 @@ function Gui.inject_top_flow_order(provider) Gui.get_top_flow_order = provider local debug_info = debug.getinfo(2, "Sn") local file_name = debug_info.short_src:sub(10, -5) - local func_name = debug_info.name or ("") - Gui._top_flow_order_src = file_name..":"..func_name + local func_name = debug_info.name or ("") + Gui._top_flow_order_src = file_name .. ":" .. func_name end --[[-- Updates the visible state of all the elements on the players top flow, uses authenticator @@ -137,12 +137,12 @@ function Gui.update_top_flow(player) if not element then element = element_define(top_flow) else - top_flow.swap_children(index+1, element.get_index_in_parent()) + top_flow.swap_children(index + 1, element.get_index_in_parent()) end -- Set the visible state local allowed = element_define.authenticator - if type(allowed) == 'function' then allowed = allowed(player) end + if type(allowed) == "function" then allowed = allowed(player) end element.visible = allowed or false -- If its not visible and there is a left element, then hide it @@ -176,7 +176,7 @@ function Gui.reorder_top_flow(player) -- Reorder the elements, index 1 is the core ui buttons so +1 is required for index, element_define in ipairs(flow_order) do local element = top_flow[element_define.name] - top_flow.swap_children(index+1, element.get_index_in_parent()) + top_flow.swap_children(index + 1, element.get_index_in_parent()) end end @@ -243,7 +243,7 @@ function Gui.toggle_toolbar_button(player, element_define, state) name = Gui.events.on_toolbar_button_toggled, element = toolbar_button, player = player, - state = state + state = state, } return state end @@ -262,18 +262,18 @@ end) ]] function Gui.toolbar_button(sprite, tooltip, authenticator) return Gui.element{ - type = 'sprite-button', - sprite = sprite, - tooltip = tooltip, - style = Gui.top_flow_button_style, - name = Gui.unique_static_name - } - :style{ - minimal_width = toolbar_button_size, - height = toolbar_button_size, - padding = -2 - } - :add_to_top_flow(authenticator) + type = "sprite-button", + sprite = sprite, + tooltip = tooltip, + style = Gui.top_flow_button_style, + name = Gui.unique_static_name, + } + :style{ + minimal_width = toolbar_button_size, + height = toolbar_button_size, + padding = -2, + } + :add_to_top_flow(authenticator) end --[[-- Creates a toggle button on the top flow with consistent styling @@ -293,23 +293,23 @@ end) ]] function Gui.toolbar_toggle_button(sprite, tooltip, authenticator) local button = - Gui.element{ - type = 'sprite-button', - sprite = sprite, - tooltip = tooltip, - style = Gui.top_flow_button_style, - name = Gui.unique_static_name - } - :style{ - minimal_width = toolbar_button_size, - height = toolbar_button_size, - padding = -2 - } - :add_to_top_flow(authenticator) + Gui.element{ + type = "sprite-button", + sprite = sprite, + tooltip = tooltip, + style = Gui.top_flow_button_style, + name = Gui.unique_static_name, + } + :style{ + minimal_width = toolbar_button_size, + height = toolbar_button_size, + padding = -2, + } + :add_to_top_flow(authenticator) button:on_click(function(player, _, _) Gui.toggle_toolbar_button(player, button) end) return button -end \ No newline at end of file +end diff --git a/exp_legacy/module/expcore/permission_groups.lua b/exp_legacy/module/expcore/permission_groups.lua index a466734c..5f97821f 100644 --- a/exp_legacy/module/expcore/permission_groups.lua +++ b/exp_legacy/module/expcore/permission_groups.lua @@ -23,28 +23,27 @@ Permission_Groups.new_group('Restricted') -- this defines a new group called "Re ]] - local Game = require("modules.exp_legacy.utils.game") --- @dep utils.game local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Async = require("modules/exp_util/async") local Permissions_Groups = { - groups={}, -- store for the different groups that are created - _prototype={} -- stores functions that are used on group instances + groups = {}, -- store for the different groups that are created + _prototype = {}, -- stores functions that are used on group instances } -- Async function to add players to permission groups local add_to_permission_group_async = -Async.register(function(permission_group, player) - permission_group.add_player(player) -end) + Async.register(function(permission_group, player) + permission_group.add_player(player) + end) Permissions_Groups.add_to_permission_group_async = add_to_permission_group_async -- Async function to remove players from permission groups local remove_from_permission_group_async = -Async.register(function(permission_group, player) - permission_group.remove_player(player) -end) + Async.register(function(permission_group, player) + permission_group.remove_player(player) + end) Permissions_Groups.remove_from_permission_group_async = remove_from_permission_group_async --- Getters. @@ -61,11 +60,11 @@ Groups.new_group('Admin') ]] function Permissions_Groups.new_group(name) local group = setmetatable({ - name=name, - actions={}, - allow_all_actions=true + name = name, + actions = {}, + allow_all_actions = true, }, { - __index= Permissions_Groups._prototype + __index = Permissions_Groups._prototype, }) Permissions_Groups.groups[name] = group return group @@ -149,7 +148,7 @@ group:set_action('toggle_map_editor', false) function Permissions_Groups._prototype:set_action(action, state) local input_action = defines.input_action[action] if input_action == nil then input_action = action end - assert(type(input_action) == 'number', tostring(action)..' is not a valid input action') + assert(type(input_action) == "number", tostring(action) .. " is not a valid input action") self.actions[input_action] = state return self end @@ -165,12 +164,13 @@ group:allow{ ]] function Permissions_Groups._prototype:allow(actions) - if type(actions) ~= 'table' then - actions = {actions} + if type(actions) ~= "table" then + actions = { actions } end for _, action in pairs(actions) do self:set_action(action, true) end + return self end @@ -189,12 +189,13 @@ group:disallow{ ]] function Permissions_Groups._prototype:disallow(actions) - if type(actions) ~= 'table' then - actions = {actions} + if type(actions) ~= "table" then + actions = { actions } end for _, action in pairs(actions) do self:set_action(action, false) end + return self end @@ -231,7 +232,7 @@ local allowed = group:is_allowed('write_to_console') ]] function Permissions_Groups._prototype:is_allowed(action) - if type(action) == 'string' then + if type(action) == "string" then action = defines.input_action[action] end local state = self.actions[action] @@ -260,6 +261,7 @@ function Permissions_Groups._prototype:create() for _, action in pairs(defines.input_action) do group.set_allows_action(action, self:is_allowed(action)) end + return group end @@ -347,6 +349,7 @@ function Permissions_Groups._prototype:print(message) for _, player in pairs(players) do player.print(message) end + return #players end @@ -355,4 +358,4 @@ Event.on_init(function() Permissions_Groups.reload_permissions() end) -return Permissions_Groups \ No newline at end of file +return Permissions_Groups diff --git a/exp_legacy/module/expcore/player_data.lua b/exp_legacy/module/expcore/player_data.lua index d1e9394b..c7c60b17 100644 --- a/exp_legacy/module/expcore/player_data.lua +++ b/exp_legacy/module/expcore/player_data.lua @@ -48,58 +48,59 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore require("modules.exp_legacy.config.expcore.command_general_parse") --- @dep config.expcore.command_general_parse --- Common player data that acts as the root store for player data -local PlayerData = Datastore.connect('PlayerData', true) -- saveToDisk +local PlayerData = Datastore.connect("PlayerData", true) -- saveToDisk PlayerData:set_serializer(Datastore.name_serializer) -- use player name --- Store and enum for the data saving preference -local DataSavingPreference = PlayerData:combine('DataSavingPreference') -local PreferenceEnum = { 'All', 'Statistics', 'Settings', 'Required' } -for k,v in ipairs(PreferenceEnum) do PreferenceEnum[v] = k end -DataSavingPreference:set_default('All') +local DataSavingPreference = PlayerData:combine("DataSavingPreference") +local PreferenceEnum = { "All", "Statistics", "Settings", "Required" } +for k, v in ipairs(PreferenceEnum) do PreferenceEnum[v] = k end + +DataSavingPreference:set_default("All") DataSavingPreference:set_metadata{ - name = {'expcore-data.preference'}, - tooltip = {'expcore-data.preference-tooltip'}, - value_tooltip ={'expcore-data.preference-value-tooltip'} + name = { "expcore-data.preference" }, + tooltip = { "expcore-data.preference-tooltip" }, + value_tooltip = { "expcore-data.preference-value-tooltip" }, } --- Sets your data saving preference -- @command set-data-preference -Commands.new_command('set-preference', 'Allows you to set your data saving preference') -:add_param('option', false, 'string-options', PreferenceEnum) -:register(function(player, option) - DataSavingPreference:set(player, option) - return {'expcore-data.set-preference', option} -end) +Commands.new_command("set-preference", "Allows you to set your data saving preference") + :add_param("option", false, "string-options", PreferenceEnum) + :register(function(player, option) + DataSavingPreference:set(player, option) + return { "expcore-data.set-preference", option } + end) --- Gets your data saving preference -- @command data-preference -Commands.new_command('preference', 'Shows you what your current data saving preference is') -:register(function(player) - return {'expcore-data.get-preference', DataSavingPreference:get(player)} -end) +Commands.new_command("preference", "Shows you what your current data saving preference is") + :register(function(player) + return { "expcore-data.get-preference", DataSavingPreference:get(player) } + end) --- Gets your data and writes it to a file -Commands.new_command('save-data', 'Writes all your player data to a file on your computer') -:register(function(player) - player.print{'expcore-data.get-data'} - game.write_file('expgaming_player_data.json', game.table_to_json(PlayerData:get(player, {})), false, player.index) -end) +Commands.new_command("save-data", "Writes all your player data to a file on your computer") + :register(function(player) + player.print{ "expcore-data.get-data" } + game.write_file("expgaming_player_data.json", game.table_to_json(PlayerData:get(player, {})), false, player.index) + end) --- Async function called after 5 seconds with no player data loaded local check_data_loaded_async = -Async.register(function(player) - local player_data = PlayerData:get(player) - if not player_data or not player_data.valid then - player.print{'expcore-data.data-failed'} - Datastore.ingest('request', 'PlayerData', player.name, '{"valid":false}') - end -end) + Async.register(function(player) + local player_data = PlayerData:get(player) + if not player_data or not player_data.valid then + player.print{ "expcore-data.data-failed" } + Datastore.ingest("request", "PlayerData", player.name, '{"valid":false}') + end + end) --- When player data loads tell the player if the load had failed previously PlayerData:on_load(function(player_name, player_data, existing_data) if not player_data or player_data.valid == false then return end if existing_data and existing_data.valid == false then - game.players[player_name].print{'expcore-data.data-restore'} + game.players[player_name].print{ "expcore-data.data-restore" } end player_data.valid = true end) @@ -122,7 +123,7 @@ end) --- Display your data preference when your data loads DataSavingPreference:on_load(function(player_name, dataPreference) - game.players[player_name].print{'expcore-data.get-preference', dataPreference or DataSavingPreference.default} + game.players[player_name].print{ "expcore-data.get-preference", dataPreference or DataSavingPreference.default } end) --- Load player data when they join @@ -139,15 +140,17 @@ Event.add(defines.events.on_player_left_game, function(event) local player_data = PlayerData:get(player) if player_data and player_data.valid == true then PlayerData:unload(player) - else PlayerData:raw_set(player.name) end + else + PlayerData:raw_set(player.name) + end end) ----- Module Return ----- return { All = PlayerData, -- Root for all of a players data - Statistics = PlayerData:combine('Statistics'), -- Common place for stats - Settings = PlayerData:combine('Settings'), -- Common place for settings - Required = PlayerData:combine('Required'), -- Common place for required data + Statistics = PlayerData:combine("Statistics"), -- Common place for stats + Settings = PlayerData:combine("Settings"), -- Common place for settings + Required = PlayerData:combine("Required"), -- Common place for required data DataSavingPreference = DataSavingPreference, -- Stores what data groups will be saved - PreferenceEnum = PreferenceEnum -- Enum for the allowed options for data saving preference -} \ No newline at end of file + PreferenceEnum = PreferenceEnum, -- Enum for the allowed options for data saving preference +} diff --git a/exp_legacy/module/expcore/roles.lua b/exp_legacy/module/expcore/roles.lua index 7e0cfaff..8bb93f74 100644 --- a/exp_legacy/module/expcore/roles.lua +++ b/exp_legacy/module/expcore/roles.lua @@ -119,24 +119,24 @@ local write_json = _C.write_json --- @dep expcore.common local Roles = { _prototype = {}, config = { - order = {}, -- Contains the order of the roles, lower index is better - roles = {}, -- Contains the raw info for the roles, indexed by role name - flags = {}, -- Contains functions that run when a flag is added/removed from a player - internal = {}, -- Contains all internally accessed roles, such as root, default - players = {}, -- Contains the roles that players have - auto_assign = {}, -- Contains references to all roles which have auto assign conditions + order = {}, -- Contains the order of the roles, lower index is better + roles = {}, -- Contains the raw info for the roles, indexed by role name + flags = {}, -- Contains functions that run when a flag is added/removed from a player + internal = {}, -- Contains all internally accessed roles, such as root, default + players = {}, -- Contains the roles that players have + auto_assign = {}, -- Contains references to all roles which have auto assign conditions deferred_roles = {}, -- Contains the roles that are to be assigned to players when they are unjailed }, events = { - on_role_assigned = script.generate_event_name(), + on_role_assigned = script.generate_event_name(), on_role_unassigned = script.generate_event_name(), - } + }, } --- When global is loaded it will have the metatable re-assigned to the roles Storage.register({ Roles.config.players, - Roles.config.deferred_roles + Roles.config.deferred_roles, }, function(tbl) Roles.config.players = tbl[1] Roles.config.deferred_roles = tbl[2] @@ -150,12 +150,12 @@ end) -- this is the raw internal trigger as the other function is called at other times -- there is a second half called role_update which triggers after the event call, it also is called when a player joins local function emit_player_roles_updated(player, type, roles, by_player_name, skip_game_print) - by_player_name = by_player_name or game.player and game.player.name or '' + by_player_name = by_player_name or game.player and game.player.name or "" local by_player = game.players[by_player_name] local by_player_index = by_player and by_player.index or 0 -- get the event id from the type of emit local event = Roles.events.on_role_assigned - if type == 'unassign' then + if type == "unassign" then event = Roles.events.on_role_unassigned end -- Get the names of the roles @@ -163,27 +163,28 @@ local function emit_player_roles_updated(player, type, roles, by_player_name, sk for index, role in ipairs(roles) do role_names[index] = role.name end + -- output to all the different locations: game print, player sound, event trigger and role log if not skip_game_print then - game.print({'expcore-roles.game-message-'..type, player.name, table.concat(role_names, ', '), by_player_name}, Colours.cyan) + game.print({ "expcore-roles.game-message-" .. type, player.name, table.concat(role_names, ", "), by_player_name }, Colours.cyan) end - if type == 'assign' then - player.play_sound{path='utility/achievement_unlocked'} + if type == "assign" then + player.play_sound{ path = "utility/achievement_unlocked" } else - player.play_sound{path='utility/game_lost'} + player.play_sound{ path = "utility/game_lost" } end script.raise_event(event, { - name=event, - tick=game.tick, - player_index=player.index, - by_player_index=by_player_index, - roles=role_names + name = event, + tick = game.tick, + player_index = player.index, + by_player_index = by_player_index, + roles = role_names, }) - write_json('log/roles.log', { - player_name=player.name, - by_player_name=by_player_name, - type=type, - roles_changed=role_names + write_json("log/roles.log", { + player_name = player.name, + by_player_name = by_player_name, + type = type, + roles_changed = role_names, }) end @@ -195,13 +196,14 @@ game.player.print(Roles.debug()) ]] function Roles.debug() - local output = '' + local output = "" for index, role_name in ipairs(Roles.config.order) do local role = Roles.config.roles[role_name] local color = role.custom_color or Colours.white - color = string.format('[color=%d, %d, %d]', color.r, color.g, color.b) - output = output..string.format('\n%s %s) %s[/color]', color, index, serpent.line(role)) + color = string.format("[color=%d, %d, %d]", color.r, color.g, color.b) + output = output .. string.format("\n%s %s) %s[/color]", color, index, serpent.line(role)) end + return output end @@ -234,9 +236,10 @@ function Roles.print_to_roles_higher(role, message) local roles = {} for index, role_name in ipairs(Roles.config.order) do if index <= role.index and role_name ~= Roles.config.internal.default then - roles[#roles+1] = role_name + roles[#roles + 1] = role_name end end + Roles.print_to_roles(roles, message) end @@ -254,9 +257,10 @@ function Roles.print_to_roles_lower(role, message) local roles = {} for index, role_name in ipairs(Roles.config.order) do if index >= role.index and role_name ~= Roles.config.internal.default then - roles[#roles+1] = role_name + roles[#roles + 1] = role_name end end + Roles.print_to_roles(roles, message) end @@ -296,12 +300,12 @@ local role = Roles.get_role_from_any('Moderator') ]] function Roles.get_role_from_any(any) local t_any = type(any) - if t_any == 'number' or tonumber(any) then + if t_any == "number" or tonumber(any) then any = tonumber(any) return Roles.get_role_by_order(any) - elseif t_any == 'string' then + elseif t_any == "string" then return Roles.get_role_by_name(any) - elseif t_any == 'table' then + elseif t_any == "table" then return Roles.get_role_by_name(any.name) end end @@ -316,13 +320,14 @@ local roles = Roles.get_player_roles(game.player) ]] function Roles.get_player_roles(player) player = Game.get_player_from_any(player) - if not player then return {Roles.config.roles[Roles.config.internal.root]} end + if not player then return { Roles.config.roles[Roles.config.internal.root] } end local roles = Roles.config.players[player.name] or {} local default = Roles.config.roles[Roles.config.internal.default] - local rtn = {default} + local rtn = { default } for index, role_name in ipairs(roles) do - rtn[index+1] = Roles.config.roles[role_name] + rtn[index + 1] = Roles.config.roles[role_name] end + return rtn end @@ -343,6 +348,7 @@ function Roles.get_player_highest_role(player) highest = role end end + return highest end @@ -370,7 +376,7 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent) if not player then return end -- Convert the roles into a table (allows for optional array) - if type(roles) ~= 'table' or roles.name then + if type(roles) ~= "table" or roles.name then roles = { roles } end @@ -394,10 +400,11 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent) end else assign_later[role.name] = { - count = 1, by_player_name = by_player_name or "", silent = silent + count = 1, by_player_name = by_player_name or "", silent = silent, } end end + Roles.config.deferred_roles[valid_player.name] = assign_later return end @@ -407,7 +414,7 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent) end if valid_player then - emit_player_roles_updated(valid_player, 'assign', role_objects, by_player_name, silent) + emit_player_roles_updated(valid_player, "assign", role_objects, by_player_name, silent) end end @@ -431,7 +438,7 @@ function Roles.unassign_player(player, roles, by_player_name, skip_checks, silen if not player then return end -- Convert the roles into a table (allows for optional array) - if type(roles) ~= 'table' or roles.name then + if type(roles) ~= "table" or roles.name then roles = { roles } end @@ -456,10 +463,11 @@ function Roles.unassign_player(player, roles, by_player_name, skip_checks, silen end else assign_later[role.name] = { - count = -1, by_player_name = by_player_name or "", silent = silent + count = -1, by_player_name = by_player_name or "", silent = silent, } end end + Roles.config.deferred_roles[valid_player.name] = assign_later end @@ -490,17 +498,20 @@ function Roles.unassign_player(player, roles, by_player_name, skip_checks, silen end end end + for assign_by_player_name, assign_roles in pairs(assigns) do - if #assign_roles > 0 then emit_player_roles_updated(valid_player, 'assign', assign_roles, assign_by_player_name) end + if #assign_roles > 0 then emit_player_roles_updated(valid_player, "assign", assign_roles, assign_by_player_name) end end + for unassign_by_player_name, unassign_roles in pairs(unassigns) do - if #unassign_roles > 0 then emit_player_roles_updated(valid_player, 'unassign', unassign_roles, unassign_by_player_name) end + if #unassign_roles > 0 then emit_player_roles_updated(valid_player, "unassign", unassign_roles, unassign_by_player_name) end end + Roles.config.deferred_roles[player.name] = nil end if valid_player and #role_changes > 0 then - emit_player_roles_updated(valid_player, 'unassign', role_changes, by_player_name, silent) + emit_player_roles_updated(valid_player, "unassign", role_changes, by_player_name, silent) end end @@ -518,10 +529,11 @@ Roles.override_player_roles{ } ]] -function Roles.override_player_roles(player_name,roles) +function Roles.override_player_roles(player_name, roles) local player_roles = Roles.config.players if not roles then for k in pairs(player_roles) do player_roles[k] = nil end + for k, new_roles in pairs(player_name) do player_roles[k] = new_roles end else Roles.config.players[player_name] = roles @@ -549,6 +561,7 @@ function Roles.player_has_role(player, search_role) for _, role in ipairs(roles) do if role.name == search_role.name then return true end end + return false end @@ -569,6 +582,7 @@ function Roles.player_has_flag(player, flag_name) return true end end + return false end @@ -589,6 +603,7 @@ function Roles.player_allowed(player, action) return true end end + return false end @@ -616,7 +631,7 @@ function Roles.define_role_order(order) Roles.config.order = {} local done = {} for index, role in ipairs(order) do - if type(role) == 'table' and role.name then + if type(role) == "table" and role.name then done[role.name] = true Roles.config.order[index] = role.name else @@ -624,22 +639,24 @@ function Roles.define_role_order(order) Roles.config.order[index] = role end end + -- Check no roles were missed for role_name in pairs(Roles.config.roles) do if not done[role_name] then - error('Role missing '..role_name..' from role order, all defined roles must be included.', 2) + error("Role missing " .. role_name .. " from role order, all defined roles must be included.", 2) end end + -- Re-links roles to they parents as this is called at the end of the config for index, role_name in pairs(Roles.config.order) do local role = Roles.config.roles[role_name] if not role then - error('Role with name '..role_name..' has not beed defined, either define it or remove it from the order list.', 2) + error("Role with name " .. role_name .. " has not beed defined, either define it or remove it from the order list.", 2) end role.index = index local parent = Roles.config.roles[role.parent] if parent then - setmetatable(role.allowed_actions, {__index=parent.allowed_actions}) + setmetatable(role.allowed_actions, { __index = parent.allowed_actions }) end end end @@ -696,14 +713,14 @@ local role = Roles.new_role('Moderator', 'Mod') ]] function Roles.new_role(name, short_hand) _C.error_if_runtime() - if Roles.config.roles[name] then return error('Role name is non unique') end + if Roles.config.roles[name] then return error("Role name is non unique") end local role = setmetatable({ - name=name, - short_hand=short_hand or name, - allowed_actions={}, - allow_all_actions=false, - flags={} - }, {__index=Roles._prototype}) + name = name, + short_hand = short_hand or name, + allowed_actions = {}, + allow_all_actions = false, + flags = {}, + }, { __index = Roles._prototype }) Roles.config.roles[name] = role return role end @@ -738,12 +755,13 @@ role:allow{ ]] function Roles._prototype:allow(actions) - if type(actions) ~= 'table' then - actions = {actions} + if type(actions) ~= "table" then + actions = { actions } end for _, action in ipairs(actions) do - self.allowed_actions[action]=true + self.allowed_actions[action] = true end + return self end @@ -759,12 +777,13 @@ role:disallow{ ]] function Roles._prototype:disallow(actions) - if type(actions) ~= 'table' then - actions = {actions} + if type(actions) ~= "table" then + actions = { actions } end for _, action in ipairs(actions) do - self.allowed_actions[action]=false + self.allowed_actions[action] = false end + return self end @@ -850,7 +869,7 @@ role:set_custom_color{ r=255, g=100, b=100} ]] function Roles._prototype:set_custom_color(color) - if type(color) ~= 'table' then + if type(color) ~= "table" then color = Colours[color] end self.custom_color = color @@ -869,7 +888,7 @@ role:set_permission_group('Admin') function Roles._prototype:set_permission_group(name, use_factorio_api) _C.error_if_runtime() if use_factorio_api then - self.permission_group = {true, name} + self.permission_group = { true, name } else local group = Groups.get_group_by_name(name) if not group then return end @@ -892,7 +911,7 @@ function Roles._prototype:set_parent(role) self.parent = role role = Roles.get_role_from_any(role) if not role then return self end - setmetatable(self.allowed_actions, {__index=role.allowed_actions}) + setmetatable(self.allowed_actions, { __index = role.allowed_actions }) return self end @@ -972,13 +991,14 @@ function Roles._prototype:add_player(player, skip_check, skip_event) for _, role_name in ipairs(player_roles) do if role_name == self.name then return false end end - player_roles[#player_roles+1] = self.name + + player_roles[#player_roles + 1] = self.name else - Roles.config.players[player_name] = {self.name} + Roles.config.players[player_name] = { self.name } end -- Emits event if required if valid_player and not skip_event then - emit_player_roles_updated(valid_player, 'assign', {self}) + emit_player_roles_updated(valid_player, "assign", { self }) end return true end @@ -1018,13 +1038,14 @@ function Roles._prototype:remove_player(player, skip_check, skip_event) break end end + if #player_roles == 0 then Roles.config.players[player_name] = nil end end -- Emits event if required if valid_player and not skip_event then - emit_player_roles_updated(valid_player, 'unassign', {self}) + emit_player_roles_updated(valid_player, "unassign", { self }) end return found end @@ -1049,12 +1070,13 @@ function Roles._prototype:get_players(online) local player = game.players[player_name] -- Filter by online state if required if player and (online == nil or player.connected == online) then - players[#players+1] = player + players[#players + 1] = player end break end end end + return players end @@ -1071,6 +1093,7 @@ function Roles._prototype:print(message) for _, player in ipairs(players) do player.print(message) end + return #players end @@ -1082,6 +1105,7 @@ local function role_update(event) local state = Roles.player_has_flag(player, flag) async_function(player, state) end + -- Updates the players permission group local highest = Roles.get_player_highest_role(player) if highest.permission_group then @@ -1114,7 +1138,7 @@ local function auto_assign(event) if not lookup[role] then local success, rtn = pcall(condition, player) if not success then - log{'expcore-roles.error-log-format-assign', role.name, rtn} + log{ "expcore-roles.error-log-format-assign", role.name, rtn } elseif rtn == true then ctn = ctn + 1 assigns[ctn] = role @@ -1139,6 +1163,5 @@ Event.on_nth_tick(3600, function() end end) - -- Return Roles -return Roles \ No newline at end of file +return Roles diff --git a/exp_legacy/module/modules/addons/advanced-start.lua b/exp_legacy/module/modules/addons/advanced-start.lua index 7e462c53..9126dbe8 100644 --- a/exp_legacy/module/modules/addons/advanced-start.lua +++ b/exp_legacy/module/modules/addons/advanced-start.lua @@ -13,42 +13,42 @@ Event.add(defines.events.on_player_created, function(event) game.map_settings.enemy_expansion.enabled = config.enemy_expansion local r = config.chart_radius local p = player.position - player.force.chart(player.surface, {{p.x-r, p.y-r}, {p.x+r, p.y+r}}) + player.force.chart(player.surface, { { p.x - r, p.y - r }, { p.x + r, p.y + r } }) end -- spawn items for item, callback in pairs(items) do - if type(callback) == 'function' then + if type(callback) == "function" then local stats = player.force.get_item_production_statistics(player.surface) local made = stats.get_input_count(item) local success, count = pcall(callback, made, stats.get_input_count, player) count = math.floor(count) if success and count > 0 then - player.insert{name=item, count=count} + player.insert{ name = item, count = count } end end end if config.armor.enable then - player.insert{name=config.armor.main, count=1} + player.insert{ name = config.armor.main, count = 1 } for _, item in pairs(config.armor.item) do - player.insert{name=item.equipment, count=item.count} + player.insert{ name = item.equipment, count = item.count } end end end) Event.on_init(function() - remote.call('freeplay', 'set_created_items', {}) - remote.call('freeplay', 'set_chart_distance', 0) - remote.call('freeplay', 'set_skip_intro', config.skip_intro) + remote.call("freeplay", "set_created_items", {}) + remote.call("freeplay", "set_chart_distance", 0) + remote.call("freeplay", "set_skip_intro", config.skip_intro) if config.research_queue_from_start then for _, force in pairs(game.forces) do - --force.research_queue_enabled = true + -- force.research_queue_enabled = true end end if not config.disable_base_game_silo_script then if config.skip_victory then - remote.call('silo_script', 'set_no_victory', true) + remote.call("silo_script", "set_no_victory", true) end end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/addons/afk-kick.lua b/exp_legacy/module/modules/addons/afk-kick.lua index a597f669..fa62fd36 100644 --- a/exp_legacy/module/modules/addons/afk-kick.lua +++ b/exp_legacy/module/modules/addons/afk-kick.lua @@ -20,10 +20,10 @@ end) --- Kicks an afk player, used to add a delay so the gui has time to appear local kick_player_async = -Async.register(function(player) - if game.tick - primitives.last_active < config.kick_time then return end -- Safety Catch - game.kick_player(player, 'AFK while no active players on the server') -end) + Async.register(function(player) + if game.tick - primitives.last_active < config.kick_time then return end -- Safety Catch + game.kick_player(player, "AFK while no active players on the server") + end) --- Check for an active player every update_time number of ticks Event.on_nth_tick(config.update_time, function() @@ -48,10 +48,10 @@ Event.on_nth_tick(config.update_time, function() local res = player.display_resolution local uis = player.display_scale player.gui.screen.add{ - type = 'frame', - name = 'afk-kick', - caption = {'afk-kick.message'}, - }.location = { x=res.width*(0.5 - 0.11*uis), y=res.height*(0.5 - 0.14*uis) } + type = "frame", + name = "afk-kick", + caption = { "afk-kick.message" }, + }.location = { x = res.width * (0.5 - 0.11 * uis), y = res.height * (0.5 - 0.14 * uis) } -- Kick the player, some delay needed because network delay kick_player_async:start_after(10, player) diff --git a/exp_legacy/module/modules/addons/chat-popups.lua b/exp_legacy/module/modules/addons/chat-popups.lua index c78a7b4d..f636993d 100644 --- a/exp_legacy/module/modules/addons/chat-popups.lua +++ b/exp_legacy/module/modules/addons/chat-popups.lua @@ -18,7 +18,7 @@ Event.add(defines.events.on_console_chat, function(event) -- Sends the message as text above them if config.show_player_messages then - send_text(player, {'chat-popup.message', player.name, event.message}) + send_text(player, { "chat-popup.message", player.name, event.message }) end if not config.show_player_mentions then return end @@ -30,9 +30,8 @@ Event.add(defines.events.on_console_chat, function(event) for _, mentioned_player in pairs(game.connected_players) do if mentioned_player.index ~= player.index then if search_string:find(mentioned_player.name:lower(), 1, true) then - send_text(mentioned_player, {'chat-popup.ping', player.name}) + send_text(mentioned_player, { "chat-popup.ping", player.name }) end end end - -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/addons/chat-reply.lua b/exp_legacy/module/modules/addons/chat-reply.lua index aed97a25..d0ab85cb 100644 --- a/exp_legacy/module/modules/addons/chat-reply.lua +++ b/exp_legacy/module/modules/addons/chat-reply.lua @@ -17,17 +17,17 @@ Event.add(defines.events.on_console_chat, function(event) local prefix = config.command_prefix for key_word, reply in pairs(config.messages) do if message:find(key_word) then - local is_command = message:find(prefix..key_word) - if type(reply) == 'function' then + local is_command = message:find(prefix .. key_word) + if type(reply) == "function" then reply = reply(player, is_command) end if is_command and allowed then - game.print{'chat-bot.reply', reply} + game.print{ "chat-bot.reply", reply } elseif is_command then - player.print{'chat-bot.disallow'} + player.print{ "chat-bot.disallow" } elseif not allowed then - player.print{'chat-bot.reply', reply} + player.print{ "chat-bot.reply", reply } end end end @@ -35,18 +35,16 @@ Event.add(defines.events.on_console_chat, function(event) if not allowed then return end for key_word, reply in pairs(config.commands) do - if message:find(prefix..key_word) then - if type(reply) == 'function' then + if message:find(prefix .. key_word) then + if type(reply) == "function" then local msg = reply(player, true) if reply then - game.print{'chat-bot.reply', msg} + game.print{ "chat-bot.reply", msg } end - else - game.print{'chat-bot.reply', reply} + game.print{ "chat-bot.reply", reply } end - end end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/addons/compilatron.lua b/exp_legacy/module/modules/addons/compilatron.lua index 7e9b3cce..5105b898 100644 --- a/exp_legacy/module/modules/addons/compilatron.lua +++ b/exp_legacy/module/modules/addons/compilatron.lua @@ -9,33 +9,33 @@ local messages = config.messages local locations = config.locations local Public = { - compilatrons={}, - current_messages={} + compilatrons = {}, + current_messages = {}, } Storage.register({ compilatrons = Public.compilatrons, - current_messages = Public.current_messages + current_messages = Public.current_messages, }, function(tbl) Public.compilatrons = tbl.compilatrons Public.current_messages = tbl.current_messages end) local speech_bubble_async = -Async.register(function(data) - local message = - data.ent.surface.create_entity{ - name = 'compi-speech-bubble', - text = messages[data.name][data.msg_number], - source = data.ent, - position = {0, 0}, - } + Async.register(function(data) + local message = + data.ent.surface.create_entity{ + name = "compi-speech-bubble", + text = messages[data.name][data.msg_number], + source = data.ent, + position = { 0, 0 }, + } - Public.current_messages[data.name] = { - message = message, - msg_number = data.msg_number - } -end) + Public.current_messages[data.name] = { + message = message, + msg_number = data.msg_number, + } + end) --- This will move the messages onto the next message in the loop local function circle_messages() @@ -57,7 +57,7 @@ local function circle_messages() msg_number = 1 end -- this calls the callback above to re-spawn the message after some time - speech_bubble_async:start_after(300, {ent = ent, name = name, msg_number = msg_number}) + speech_bubble_async:start_after(300, { ent = ent, name = name, msg_number = msg_number }) end end @@ -77,10 +77,10 @@ function Public.add_compilatron(entity, name) Public.compilatrons[name] = entity local message = - entity.surface.create_entity( - {name = 'compi-speech-bubble', text = messages[name][1], position = {0, 0}, source = entity} - ) - Public.current_messages[name] = {message = message, msg_number = 1} + entity.surface.create_entity + { name = "compi-speech-bubble", text = messages[name][1], position = { 0, 0 }, source = entity } + + Public.current_messages[name] = { message = message, msg_number = 1 } end --- This spawns a new compilatron on a surface with the given location tag (not a position) @@ -88,8 +88,8 @@ end -- @tparam string location the location tag that is in the config file function Public.spawn_compilatron(surface, location) local position = locations[location] - local pos = surface.find_non_colliding_position('small-biter', position, 1.5, 0.5) - local compi = surface.create_entity {name='small-biter', position=pos, force=game.forces.neutral} + local pos = surface.find_non_colliding_position("small-biter", position, 1.5, 0.5) + local compi = surface.create_entity{ name = "small-biter", position = pos, force = game.forces.neutral } Public.add_compilatron(compi, location) end diff --git a/exp_legacy/module/modules/addons/damage-popups.lua b/exp_legacy/module/modules/addons/damage-popups.lua index b5a141c4..cdc430c6 100644 --- a/exp_legacy/module/modules/addons/damage-popups.lua +++ b/exp_legacy/module/modules/addons/damage-popups.lua @@ -12,21 +12,21 @@ Event.add(defines.events.on_entity_damaged, function(event) local damage = math.floor(event.original_damage_amount) local health = math.floor(entity.health) local health_percentage = entity.get_health_ratio() - local text_colour = {r=1-health_percentage, g=health_percentage, b=0} + local text_colour = { r = 1 - health_percentage, g = health_percentage, b = 0 } -- Gets the location of the text local size = entity.get_radius() if size < 1 then size = 1 end - local r = (math.random()-0.5)*size*config.damage_location_variance + local r = (math.random() - 0.5) * size * config.damage_location_variance local p = entity.position - local position = {x=p.x+r, y=p.y-size} + local position = { x = p.x + r, y = p.y - size } -- Sets the message local message - if entity.name == 'character' and config.show_player_health then - message = {'damage-popup.player-health', health} - elseif entity.name ~= 'character' and cause and cause.name == 'character' and config.show_player_damage then - message = {'damage-popup.player-damage', damage} + if entity.name == "character" and config.show_player_health then + message = { "damage-popup.player-health", health } + elseif entity.name ~= "character" and cause and cause.name == "character" and config.show_player_damage then + message = { "damage-popup.player-damage", damage } end -- Outputs the message as floating text @@ -38,5 +38,4 @@ Event.add(defines.events.on_entity_damaged, function(event) text_colour ) end - -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/addons/death-logger.lua b/exp_legacy/module/modules/addons/death-logger.lua index 70cc4583..0865b38e 100644 --- a/exp_legacy/module/modules/addons/death-logger.lua +++ b/exp_legacy/module/modules/addons/death-logger.lua @@ -7,11 +7,11 @@ local config = require("modules.exp_legacy.config.death_logger") --- @dep config local format_time, move_items = _C.format_time, _C.move_items_stack --- @dep expcore.common -- Max amount of ticks a corpse can be alive -local corpse_lifetime = 60*60*15 +local corpse_lifetime = 60 * 60 * 15 local deaths = { - archive={} -- deaths moved here after body is gone - --{player_name='Cooldude2606', time_of_death='15H 15M', position={x=0, y=0}, corpse=LuaEntity, tag=LuaCustomChartTag} + archive = {}, -- deaths moved here after body is gone + -- {player_name='Cooldude2606', time_of_death='15H 15M', position={x=0, y=0}, corpse=LuaEntity, tag=LuaCustomChartTag} } Storage.register(deaths, function(tbl) deaths = tbl @@ -20,15 +20,15 @@ end) --- Creates a new death marker and saves it to the given death local function create_map_tag(death) local player = game.players[death.player_name] - local message = player.name..' died' + local message = player.name .. " died" if config.include_time_of_death then - local time = format_time(death.time_of_death, {hours=true, minutes=true, string=true}) - message = message..' at '..time + local time = format_time(death.time_of_death, { hours = true, minutes = true, string = true }) + message = message .. " at " .. time end death.tag = player.force.add_chart_tag(player.surface, { - position=death.position, - icon=config.map_icon, - text=message + position = death.position, + icon = config.map_icon, + text = message, }) end @@ -62,7 +62,7 @@ end -- when a player dies a new death is added to the records and a map marker is made Event.add(defines.events.on_player_died, function(event) local player = game.players[event.player_index] - local corpse = player.surface.find_entity('character-corpse', player.position) + local corpse = player.surface.find_entity("character-corpse", player.position) if config.use_chests_as_bodies then local items = corpse.get_inventory(defines.inventory.character_corpse) local chest = move_items(items, corpse.surface, corpse.position) @@ -74,7 +74,7 @@ Event.add(defines.events.on_player_died, function(event) player_name = player.name, time_of_death = event.tick, position = player.position, - corpse = corpse + corpse = corpse, } if config.show_map_markers then create_map_tag(death) @@ -84,11 +84,11 @@ Event.add(defines.events.on_player_died, function(event) -- Draw a light attached to the corpse with the player color if config.show_light_at_corpse then rendering.draw_light{ - sprite = 'utility/light_medium', + sprite = "utility/light_medium", color = player.color, target = corpse, force = player.force, - surface = player.surface + surface = player.surface, } end end) @@ -122,7 +122,7 @@ if config.show_line_to_corpse then dash_length = 1, gap_length = 1, surface = player.surface, - draw_on_ground = true + draw_on_ground = true, } end end @@ -131,7 +131,7 @@ end -- every 5 min all bodies are checked for valid map tags if config.show_map_markers then - local check_period = 60*60*5 -- five minutes + local check_period = 60 * 60 * 5 -- five minutes Event.on_nth_tick(check_period, function() check_map_tags() end) @@ -141,9 +141,9 @@ if config.auto_collect_bodies then Event.add(defines.events.on_character_corpse_expired, function(event) local corpse = event.corpse local items = corpse.get_inventory(defines.inventory.character_corpse) - move_items(items, corpse.surface, {x=0, y=0}) + move_items(items, corpse.surface, { x = 0, y = 0 }) end) end -- this is so other modules can access the logs -return deaths \ No newline at end of file +return deaths diff --git a/exp_legacy/module/modules/addons/deconlog.lua b/exp_legacy/module/modules/addons/deconlog.lua index e00449fd..3f3a4298 100644 --- a/exp_legacy/module/modules/addons/deconlog.lua +++ b/exp_legacy/module/modules/addons/deconlog.lua @@ -10,19 +10,19 @@ local config = require("modules.exp_legacy.config.deconlog") --- @dep config.dec local filepath = "log/decon.log" local function add_log(data) - game.write_file(filepath, data .. "\n", true, 0) -- write data + game.write_file(filepath, data .. "\n", true, 0) -- write data end local function get_secs() - return format_time(game.tick, { hours = true, minutes = true, seconds = true, string = true }) + return format_time(game.tick, { hours = true, minutes = true, seconds = true, string = true }) end local function pos_to_string(pos) - return tostring(pos.x) .. "," .. tostring(pos.y) + return tostring(pos.x) .. "," .. tostring(pos.y) end local function pos_to_gps_string(pos) - return '[gps=' .. string.format('%.1f', pos.x) .. ',' .. string.format('%.1f', pos.y) .. ']' + return "[gps=" .. string.format("%.1f", pos.x) .. "," .. string.format("%.1f", pos.y) .. "]" end --- Print a message to all players who match the value of admin @@ -35,107 +35,107 @@ local function print_to_players(admin, message) end Event.on_init(function() - game.write_file(filepath, "\n", false, 0) -- write data + game.write_file(filepath, "\n", false, 0) -- write data end) if config.decon_area then - Event.add(defines.events.on_player_deconstructed_area, function(e) - if e.alt then - return - end + Event.add(defines.events.on_player_deconstructed_area, function(e) + if e.alt then + return + end - local player = game.get_player(e.player_index) + local player = game.get_player(e.player_index) - if Roles.player_has_flag(player, 'deconlog-bypass') then - return - end + if Roles.player_has_flag(player, "deconlog-bypass") then + return + end - local items = e.surface.find_entities_filtered{area=e.area, force=player.force} + local items = e.surface.find_entities_filtered{ area = e.area, force = player.force } - if #items > 250 then - print_to_players(true, {'deconlog.decon', player.name, e.surface.name, pos_to_gps_string(e.area.left_top), pos_to_gps_string(e.area.right_bottom), format_number(#items)}) - end + if #items > 250 then + print_to_players(true, { "deconlog.decon", player.name, e.surface.name, pos_to_gps_string(e.area.left_top), pos_to_gps_string(e.area.right_bottom), format_number(#items) }) + end - add_log(get_secs() .. ',' .. player.name .. ',decon_area,' .. e.surface.name .. ',' .. pos_to_string(e.area.left_top) .. ',' .. pos_to_string(e.area.right_bottom)) - end) + add_log(get_secs() .. "," .. player.name .. ",decon_area," .. e.surface.name .. "," .. pos_to_string(e.area.left_top) .. "," .. pos_to_string(e.area.right_bottom)) + end) end if config.built_entity then - Event.add(defines.events.on_built_entity, function (e) - if not e.player_index then return end - local player = game.get_player(e.player_index) - if Roles.player_has_flag(player, "deconlog-bypass") then - return - end - local ent = e.created_entity - add_log(get_secs() .. "," .. player.name .. ",built_entity," .. ent.name .. "," .. pos_to_string(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation)) - end) + Event.add(defines.events.on_built_entity, function(e) + if not e.player_index then return end + local player = game.get_player(e.player_index) + if Roles.player_has_flag(player, "deconlog-bypass") then + return + end + local ent = e.created_entity + add_log(get_secs() .. "," .. player.name .. ",built_entity," .. ent.name .. "," .. pos_to_string(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation)) + end) end if config.mined_entity then - Event.add(defines.events.on_player_mined_entity, function (e) - local player = game.get_player(e.player_index) - if Roles.player_has_flag(player, "deconlog-bypass") then - return - end - local ent = e.entity - add_log(get_secs() .. "," .. player.name .. ",mined_entity," .. ent.name .. "," .. pos_to_string(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation)) - end) + Event.add(defines.events.on_player_mined_entity, function(e) + local player = game.get_player(e.player_index) + if Roles.player_has_flag(player, "deconlog-bypass") then + return + end + local ent = e.entity + add_log(get_secs() .. "," .. player.name .. ",mined_entity," .. ent.name .. "," .. pos_to_string(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation)) + end) end if config.fired_rocket then - Event.add(defines.events.on_player_ammo_inventory_changed, function (e) - local player = game.get_player(e.player_index) - if Roles.player_has_flag(player, "deconlog-bypass") then - return - end - local ammo_inv = player.get_inventory(defines.inventory.character_ammo) - local item = ammo_inv[player.character.selected_gun_index] - if not item or not item.valid or not item.valid_for_read then - return - end - if item.name == "rocket" then - add_log(get_secs() .. "," .. player.name .. ",shot-rocket," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position)) - end - end) + Event.add(defines.events.on_player_ammo_inventory_changed, function(e) + local player = game.get_player(e.player_index) + if Roles.player_has_flag(player, "deconlog-bypass") then + return + end + local ammo_inv = player.get_inventory(defines.inventory.character_ammo) + local item = ammo_inv[player.character.selected_gun_index] + if not item or not item.valid or not item.valid_for_read then + return + end + if item.name == "rocket" then + add_log(get_secs() .. "," .. player.name .. ",shot-rocket," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position)) + end + end) end if config.fired_explosive_rocket then - Event.add(defines.events.on_player_ammo_inventory_changed, function (e) - local player = game.get_player(e.player_index) + Event.add(defines.events.on_player_ammo_inventory_changed, function(e) + local player = game.get_player(e.player_index) - if Roles.player_has_flag(player, "deconlog-bypass") then - return - end - local ammo_inv = player.get_inventory(defines.inventory.character_ammo) - local item = ammo_inv[player.character.selected_gun_index] + if Roles.player_has_flag(player, "deconlog-bypass") then + return + end + local ammo_inv = player.get_inventory(defines.inventory.character_ammo) + local item = ammo_inv[player.character.selected_gun_index] - if not item or not item.valid or not item.valid_for_read then - return - end - if item.name == "explosive-rocket" then - add_log(get_secs() .. "," .. player.name .. ",shot-explosive-rocket," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position)) - end - end) + if not item or not item.valid or not item.valid_for_read then + return + end + if item.name == "explosive-rocket" then + add_log(get_secs() .. "," .. player.name .. ",shot-explosive-rocket," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position)) + end + end) end if config.fired_nuke then - Event.add(defines.events.on_player_ammo_inventory_changed, function (e) - local player = game.get_player(e.player_index) + Event.add(defines.events.on_player_ammo_inventory_changed, function(e) + local player = game.get_player(e.player_index) - if Roles.player_has_flag(player, "deconlog-bypass") then - return - end + if Roles.player_has_flag(player, "deconlog-bypass") then + return + end - local ammo_inv = player.get_inventory(defines.inventory.character_ammo) - local item = ammo_inv[player.character.selected_gun_index] + local ammo_inv = player.get_inventory(defines.inventory.character_ammo) + local item = ammo_inv[player.character.selected_gun_index] - if not item or not item.valid or not item.valid_for_read then - return - end + if not item or not item.valid or not item.valid_for_read then + return + end - if item.name == "atomic-bomb" then - add_log(get_secs() .. "," .. player.name .. ",shot-nuke," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position)) - end - end) + if item.name == "atomic-bomb" then + add_log(get_secs() .. "," .. player.name .. ",shot-nuke," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position)) + end + end) end diff --git a/exp_legacy/module/modules/addons/discord-alerts.lua b/exp_legacy/module/modules/addons/discord-alerts.lua index e52a750d..75e50976 100644 --- a/exp_legacy/module/modules/addons/discord-alerts.lua +++ b/exp_legacy/module/modules/addons/discord-alerts.lua @@ -6,7 +6,7 @@ local Colors = require("modules/exp_util/include/color") local write_json, format_time = _C.write_json, _C.format_time --- @dep expcore.common local config = require("modules.exp_legacy.config.discord_alerts") --- @dep config.discord_alerts -local playtime_format = {hours = true, minutes = true, short = true, string = true} +local playtime_format = { hours = true, minutes = true, short = true, string = true } local function append_playtime(player_name) if not config.show_playtime then @@ -19,7 +19,7 @@ local function append_playtime(player_name) return player_name end - return player.name ..' (' .. format_time(player.online_time, playtime_format) .. ')' + return player.name .. " (" .. format_time(player.online_time, playtime_format) .. ")" end local function get_player_name(event) @@ -28,27 +28,27 @@ local function get_player_name(event) end local function to_hex(color) - local hex_digits = '0123456789ABCDEF' + local hex_digits = "0123456789ABCDEF" local function hex(bit) - local major, minor = math.modf(bit/16) - major, minor = major+1, minor*16+1 + local major, minor = math.modf(bit / 16) + major, minor = major + 1, minor * 16 + 1 return hex_digits:sub(major, major) .. hex_digits:sub(minor, minor) end - return '0x' .. hex(color.r) .. hex(color.g) .. hex(color.b) + return "0x" .. hex(color.r) .. hex(color.g) .. hex(color.b) end local function emit_event(args) - local title = args.title or '' - local color = args.color or '0x0' - local description = args.description or '' + local title = args.title or "" + local color = args.color or "0x0" + local description = args.description or "" - if type(color) == 'table' then + if type(color) == "table" then color = to_hex(color) end local tick = args.tick or game.tick - local tick_formatted = format_time(tick, {days = false, hours = true, minutes = true, short = true, string = true}) + local tick_formatted = format_time(tick, { days = false, hours = true, minutes = true, short = true, string = true }) local players_online = 0 local admins_online = 0 @@ -61,22 +61,22 @@ local function emit_event(args) end end - local done = {title=true, color=true, description=true} - local fields = {{ - name='Server Details', - value=string.format('Server: ${serverName} Time: %s\nTotal: %d Online: %d Admins: %d', tick_formatted, #game.players, players_online, admins_online) - }} + local done = { title = true, color = true, description = true } + local fields = { { + name = "Server Details", + value = string.format("Server: ${serverName} Time: %s\nTotal: %d Online: %d Admins: %d", tick_formatted, #game.players, players_online, admins_online), + } } for key, value in pairs(args) do if not done[key] then done[key] = true local field = { - name=key, - value=value, - inline=false + name = key, + value = value, + inline = false, } - local new_value, inline = value:gsub('', '', 1) + local new_value, inline = value:gsub("", "", 1) if inline > 0 then field.value = new_value field.inline = true @@ -86,11 +86,11 @@ local function emit_event(args) end end - write_json('ext/discord.out',{ - title=title, - description=description, - color=color, - fields=fields + write_json("ext/discord.out", { + title = title, + description = description, + color = color, + fields = fields, }) end @@ -100,12 +100,12 @@ if config.entity_protection then Event.add(EntityProtection.events.on_repeat_violation, function(event) local player_name = get_player_name(event) emit_event{ - title='Entity Protection', - description='A player removed protected entities', - color=Colors.yellow, - ['Player']='' .. append_playtime(player_name), - ['Entity']='' .. event.entity.name, - ['Location']='X ' .. event.entity.position.x .. ' Y ' .. event.entity.position.y + title = "Entity Protection", + description = "A player removed protected entities", + color = Colors.yellow, + ["Player"] = "" .. append_playtime(player_name), + ["Entity"] = "" .. event.entity.name, + ["Location"] = "X " .. event.entity.position.x .. " Y " .. event.entity.position.y, } end) end @@ -116,25 +116,25 @@ if config.player_reports then Event.add(Reports.events.on_player_reported, function(event) local player_name, by_player_name = get_player_name(event) emit_event{ - title='Report', - description='A player was reported', - color=Colors.yellow, - ['Player']='' .. append_playtime(player_name), - ['By']='' .. append_playtime(by_player_name), - ['Report Count']='' .. Reports.count_reports(player_name), - ['Reason']=event.reason + title = "Report", + description = "A player was reported", + color = Colors.yellow, + ["Player"] = "" .. append_playtime(player_name), + ["By"] = "" .. append_playtime(by_player_name), + ["Report Count"] = "" .. Reports.count_reports(player_name), + ["Reason"] = event.reason, } end) Event.add(Reports.events.on_report_removed, function(event) if event.batch ~= 1 then return end local player_name = get_player_name(event) emit_event{ - title='Reports Removed', - description='A player has a report removed', - color=Colors.green, - ['Player']='' .. player_name, - ['By']='' .. event.removed_by_name, - ['Report Count']='' .. event.batch_count + title = "Reports Removed", + description = "A player has a report removed", + color = Colors.green, + ["Player"] = "" .. player_name, + ["By"] = "" .. event.removed_by_name, + ["Report Count"] = "" .. event.batch_count, } end) end @@ -146,25 +146,25 @@ if config.player_warnings then local player_name, by_player_name = get_player_name(event) local player = game.get_player(player_name) emit_event{ - title='Warning', - description='A player has been given a warning', - color=Colors.yellow, - ['Player']='' .. player_name, - ['By']='' .. by_player_name, - ['Warning Count']='' .. Warnings.count_warnings(player), - ['Reason']=event.reason + title = "Warning", + description = "A player has been given a warning", + color = Colors.yellow, + ["Player"] = "" .. player_name, + ["By"] = "" .. by_player_name, + ["Warning Count"] = "" .. Warnings.count_warnings(player), + ["Reason"] = event.reason, } end) Event.add(Warnings.events.on_warning_removed, function(event) if event.batch ~= 1 then return end local player_name = get_player_name(event) emit_event{ - title='Warnings Removed', - description='A player has a warning removed', - color=Colors.green, - ['Player']='' .. player_name, - ['By']='' .. event.removed_by_name, - ['Warning Count']='' .. event.batch_count + title = "Warnings Removed", + description = "A player has a warning removed", + color = Colors.green, + ["Player"] = "" .. player_name, + ["By"] = "" .. event.removed_by_name, + ["Warning Count"] = "" .. event.batch_count, } end) end @@ -175,22 +175,22 @@ if config.player_jail then Event.add(Jail.events.on_player_jailed, function(event) local player_name, by_player_name = get_player_name(event) emit_event{ - title='Jail', - description='A player has been jailed', - color=Colors.yellow, - ['Player']='' .. player_name, - ['By']='' .. by_player_name, - ['Reason']=event.reason + title = "Jail", + description = "A player has been jailed", + color = Colors.yellow, + ["Player"] = "" .. player_name, + ["By"] = "" .. by_player_name, + ["Reason"] = event.reason, } end) Event.add(Jail.events.on_player_unjailed, function(event) local player_name, by_player_name = get_player_name(event) emit_event{ - title='Unjail', - description='A player has been unjailed', - color=Colors.green, - ['Player']='' .. player_name, - ['By']='' .. by_player_name + title = "Unjail", + description = "A player has been unjailed", + color = Colors.green, + ["Player"] = "" .. player_name, + ["By"] = "" .. by_player_name, } end) end @@ -201,12 +201,12 @@ if config.player_bans then if event.by_player then local by_player = game.players[event.by_player] emit_event{ - title='Banned', - description='A player has been banned', - color=Colors.red, - ['Player']='' .. event.player_name, - ['By']='' .. by_player.name, - ['Reason']=event.reason + title = "Banned", + description = "A player has been banned", + color = Colors.red, + ["Player"] = "" .. event.player_name, + ["By"] = "" .. by_player.name, + ["Reason"] = event.reason, } end end) @@ -214,11 +214,11 @@ if config.player_bans then if event.by_player then local by_player = game.players[event.by_player] emit_event{ - title='Un-Banned', - description='A player has been un-banned', - color=Colors.green, - ['Player']='' .. event.player_name, - ['By']='' .. by_player.name + title = "Un-Banned", + description = "A player has been un-banned", + color = Colors.green, + ["Player"] = "" .. event.player_name, + ["By"] = "" .. by_player.name, } end end) @@ -229,19 +229,19 @@ if config.player_mutes then Event.add(defines.events.on_player_muted, function(event) local player_name = get_player_name(event) emit_event{ - title='Muted', - description='A player has been muted', - color=Colors.yellow, - ['Player']='' .. player_name + title = "Muted", + description = "A player has been muted", + color = Colors.yellow, + ["Player"] = "" .. player_name, } end) Event.add(defines.events.on_player_unmuted, function(event) local player_name = get_player_name(event) emit_event{ - title='Un-Muted', - description='A player has been un-muted', - color=Colors.green, - ['Player']='' .. player_name + title = "Un-Muted", + description = "A player has been un-muted", + color = Colors.green, + ["Player"] = "" .. player_name, } end) end @@ -253,12 +253,12 @@ if config.player_kicks then local player_name = get_player_name(event) local by_player = game.players[event.by_player] emit_event{ - title='Kick', - description='A player has been kicked', - color=Colors.orange, - ['Player']='' .. player_name, - ['By']='' .. by_player.name, - ['Reason']=event.reason + title = "Kick", + description = "A player has been kicked", + color = Colors.orange, + ["Player"] = "" .. player_name, + ["By"] = "" .. by_player.name, + ["Reason"] = event.reason, } end end) @@ -269,19 +269,19 @@ if config.player_promotes then Event.add(defines.events.on_player_promoted, function(event) local player_name = get_player_name(event) emit_event{ - title='Promote', - description='A player has been promoted', - color=Colors.green, - ['Player']='' .. player_name + title = "Promote", + description = "A player has been promoted", + color = Colors.green, + ["Player"] = "" .. player_name, } end) Event.add(defines.events.on_player_demoted, function(event) local player_name = get_player_name(event) emit_event{ - title='Demote', - description='A player has been demoted', - color=Colors.yellow, - ['Player']='' .. player_name + title = "Demote", + description = "A player has been demoted", + color = Colors.yellow, + ["Player"] = "" .. player_name, } end) end @@ -292,11 +292,11 @@ Event.add(defines.events.on_console_command, function(event) local player_name = get_player_name(event) if config[event.command] then emit_event{ - title=event.command:gsub('^%l', string.upper), - description='/' .. event.command .. ' was used', - color=Colors.grey, - ['By']='' .. player_name, - ['Details'] = event.parameters ~= '' and event.parameters or nil + title = event.command:gsub("^%l", string.upper), + description = "/" .. event.command .. " was used", + color = Colors.grey, + ["By"] = "" .. player_name, + ["Details"] = event.parameters ~= "" and event.parameters or nil, } end end diff --git a/exp_legacy/module/modules/addons/fagc.lua b/exp_legacy/module/modules/addons/fagc.lua index 6bcdcf9f..7432fcc4 100644 --- a/exp_legacy/module/modules/addons/fagc.lua +++ b/exp_legacy/module/modules/addons/fagc.lua @@ -5,15 +5,15 @@ local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event -- Clear the file on startup to minimize its size Event.on_init(function() - game.write_file("fagc-actions.txt", "", false, 0) + game.write_file("fagc-actions.txt", "", false, 0) end) Event.add(defines.events.on_player_banned, function(e) - local text = "ban;" .. e.player_name .. ";" .. (e.by_player or "") .. ";" .. (e.reason or "") .. "\n" - game.write_file("fagc-actions.txt", text, true, 0) + local text = "ban;" .. e.player_name .. ";" .. (e.by_player or "") .. ";" .. (e.reason or "") .. "\n" + game.write_file("fagc-actions.txt", text, true, 0) end) Event.add(defines.events.on_player_unbanned, function(e) - local text = "unban;" .. e.player_name .. ";" .. (e.by_player or "") .. ";" .. (e.reason or "") .. "\n" - game.write_file("fagc-actions.txt", text, true, 0) + local text = "unban;" .. e.player_name .. ";" .. (e.by_player or "") .. ";" .. (e.reason or "") .. "\n" + game.write_file("fagc-actions.txt", text, true, 0) end) diff --git a/exp_legacy/module/modules/addons/inserter.lua b/exp_legacy/module/modules/addons/inserter.lua index dc03c514..39fe4d82 100644 --- a/exp_legacy/module/modules/addons/inserter.lua +++ b/exp_legacy/module/modules/addons/inserter.lua @@ -1,23 +1,23 @@ local Event = require("modules/exp_legacy/utils/event") local controllers_with_inventory = { - [defines.controllers.character] = true, - [defines.controllers.god] = true, - [defines.controllers.editor] = true, + [defines.controllers.character] = true, + [defines.controllers.god] = true, + [defines.controllers.editor] = true, } Event.add(defines.events.on_player_mined_entity, function(event) - if (not event.entity.valid) or (event.entity.type ~= 'inserter') or event.entity.drop_target then + if (not event.entity.valid) or (event.entity.type ~= "inserter") or event.entity.drop_target then return end - 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 - local player = game.get_player(event.player_index) + if item_entity then + local player = game.get_player(event.player_index) - if controllers_with_inventory[player.controller_type] then - player.mine_entity(item_entity) - end - end + if controllers_with_inventory[player.controller_type] then + player.mine_entity(item_entity) + end + end end) diff --git a/exp_legacy/module/modules/addons/lawnmower.lua b/exp_legacy/module/modules/addons/lawnmower.lua index e0d8c355..8c91f4f2 100644 --- a/exp_legacy/module/modules/addons/lawnmower.lua +++ b/exp_legacy/module/modules/addons/lawnmower.lua @@ -8,52 +8,52 @@ local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local config = require("modules.exp_legacy.config.lawnmower") --- @dep config.lawnmower require("modules.exp_legacy.config.expcore.command_general_parse") -Commands.new_command('lawnmower', {'expcom-lawnmower.description'}, 'Clean up biter corpse, decoratives and nuclear hole') -:add_param('range', false, 'integer-range', 1, 200) -:register(function(player, range) - local tile_to_do = {} +Commands.new_command("lawnmower", "Clean up biter corpse, decoratives and nuclear hole") + :add_param("range", false, "integer-range", 1, 200) + :register(function(player, range) + local tile_to_do = {} - player.surface.destroy_decoratives({position=player.position, radius=range}) + player.surface.destroy_decoratives{ position = player.position, radius = range } - local entities = player.surface.find_entities_filtered{position=player.position, radius=range, type='corpse'} + local entities = player.surface.find_entities_filtered{ position = player.position, radius = range, type = "corpse" } - for _, entity in pairs(entities) do - if (entity.name ~= 'transport-caution-corpse' and entity.name ~= 'invisible-transport-caution-corpse') then - entity.destroy() - end - end + for _, entity in pairs(entities) do + if (entity.name ~= "transport-caution-corpse" and entity.name ~= "invisible-transport-caution-corpse") then + entity.destroy() + end + end - local tiles = player.surface.find_tiles_filtered{position=player.position, radius=range, name={'nuclear-ground'}} + local tiles = player.surface.find_tiles_filtered{ position = player.position, radius = range, name = { "nuclear-ground" } } - for _, tile in pairs(tiles) do - table.insert(tile_to_do, {name='grass-1', position=tile.position}) - end + for _, tile in pairs(tiles) do + table.insert(tile_to_do, { name = "grass-1", position = tile.position }) + end - player.surface.set_tiles(tile_to_do) + player.surface.set_tiles(tile_to_do) - return Commands.success -end) + return Commands.success + end) local function destroy_decoratives(entity) - if entity.type ~= 'entity-ghost' and entity.type ~= 'tile-ghost' and entity.prototype.selectable_in_game then - entity.surface.destroy_decoratives{area=entity.selection_box} + if entity.type ~= "entity-ghost" and entity.type ~= "tile-ghost" and entity.prototype.selectable_in_game then + entity.surface.destroy_decoratives{ area = entity.selection_box } end end if config.destroy_decoratives then - Event.add(defines.events.on_built_entity, function(event) - destroy_decoratives(event.created_entity) - end) + Event.add(defines.events.on_built_entity, function(event) + destroy_decoratives(event.created_entity) + end) - Event.add(defines.events.on_robot_built_entity, function(event) - destroy_decoratives(event.created_entity) - end) + Event.add(defines.events.on_robot_built_entity, function(event) + destroy_decoratives(event.created_entity) + end) - Event.add(defines.events.script_raised_built, function(event) - destroy_decoratives(event.entity) - end) + Event.add(defines.events.script_raised_built, function(event) + destroy_decoratives(event.entity) + end) - Event.add(defines.events.script_raised_revive, function(event) - destroy_decoratives(event.entity) - end) + Event.add(defines.events.script_raised_revive, function(event) + destroy_decoratives(event.entity) + end) end diff --git a/exp_legacy/module/modules/addons/logging.lua b/exp_legacy/module/modules/addons/logging.lua index 9f5f85aa..328935af 100644 --- a/exp_legacy/module/modules/addons/logging.lua +++ b/exp_legacy/module/modules/addons/logging.lua @@ -7,17 +7,14 @@ local config = require("modules.exp_legacy.config.logging") --- @dep config.logg local config_res = require("modules.exp_legacy.config.research") --- @dep config.research local function add_log(data) - game.write_file(config.file_name, data, true, 0) - game.write_file(config.file_name, '\n', true, 0) + game.write_file(config.file_name, data, true, 0) + game.write_file(config.file_name, "\n", true, 0) end Event.add(defines.events.on_rocket_launched, function(event) if event and event.rocket and event.rocket.force and event.rocket.force.rockets_launched then - if event.rocket.force.rockets_launched >= config.rocket_launch_display_rate and event.rocket.force.rockets_launched % config.rocket_launch_display_rate == 0 then - add_log('[ROCKET] ' .. event.rocket.force.rockets_launched .. ' rockets launched') - - elseif config.rocket_launch_display[event.rocket.force.rockets_launched] then - add_log('[ROCKET] ' .. event.rocket.force.rockets_launched .. ' rockets launched') + if config.rocket_launch_display[event.rocket.force.rockets_launched] then + add_log("[ROCKET] " .. event.rocket.force.rockets_launched .. " rockets launched") end end end) @@ -25,15 +22,13 @@ end) Event.add(defines.events.on_pre_player_died, function(event) if event and event.player_index then if event.cause then - if event.cause.type and event.cause.type == 'character' and event.cause.player and event.cause.player.index then - add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (game.players[event.cause.player.index].name or 'unknown reason')) - + if event.cause.type and event.cause.type == "character" and event.cause.player and event.cause.player.index then + add_log("[DEATH] " .. game.players[event.player_index].name .. " died because of " .. (game.players[event.cause.player.index].name or "unknown reason")) else - add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (event.cause.name or 'unknown reason')) + add_log("[DEATH] " .. game.players[event.player_index].name .. " died because of " .. (event.cause.name or "unknown reason")) end - else - add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of unknown reason') + add_log("[DEATH] " .. game.players[event.player_index].name .. " died because of unknown reason") end end end) @@ -45,27 +40,25 @@ Event.add(defines.events.on_research_finished, function(event) end if (event.research.level and config_res.inf_res[event.research.name]) and (event.research.level >= config_res.inf_res[event.research.name]) then - add_log({'logging.add-l', event.research.prototype.localised_name, event.research.level - 1}) - + add_log{ "logging.add-l", event.research.prototype.localised_name, event.research.level - 1 } else - add_log({'logging.add-n', event.research.prototype.localised_name}) + add_log{ "logging.add-n", event.research.prototype.localised_name } end end end) Event.add(defines.events.on_player_joined_game, function(event) if event and event.player_index then - add_log('[JOIN] ' .. game.players[event.player_index].name .. ' joined the game') + add_log("[JOIN] " .. game.players[event.player_index].name .. " joined the game") end end) Event.add(defines.events.on_player_left_game, function(event) if event and event.player_index then if event.reason then - add_log('[LEAVE] ' .. game.players[event.player_index].name .. config.disconnect_reason[event.reason]) - + add_log("[LEAVE] " .. game.players[event.player_index].name .. config.disconnect_reason[event.reason]) else - add_log('[LEAVE] ' .. game.players[event.player_index].name .. config.disconnect_reason[defines.disconnect_reason.quit]) + add_log("[LEAVE] " .. game.players[event.player_index].name .. config.disconnect_reason[defines.disconnect_reason.quit]) end end end) diff --git a/exp_legacy/module/modules/addons/miner.lua b/exp_legacy/module/modules/addons/miner.lua index 573984ce..a691e473 100644 --- a/exp_legacy/module/modules/addons/miner.lua +++ b/exp_legacy/module/modules/addons/miner.lua @@ -12,9 +12,8 @@ miner_data.queue = {} local function drop_target(entity) if entity.drop_target then return entity.drop_target - else - local entities = entity.surface.find_entities_filtered{position=entity.drop_position} + local entities = entity.surface.find_entities_filtered{ position = entity.drop_position } if #entities > 0 then return entities[1] @@ -43,7 +42,7 @@ local function check_entity(entity) return true end - if entity.has_flag('not-deconstructable') then + if entity.has_flag("not-deconstructable") then -- if it can deconstruct return true end @@ -58,13 +57,13 @@ local function chest_check(entity) return end - if target.type ~= 'logistic-container' and target.type ~= 'container' then + if target.type ~= "logistic-container" and target.type ~= "container" then -- not a chest return end local radius = 2 - local entities = target.surface.find_entities_filtered{area={{target.position.x - radius, target.position.y - radius}, {target.position.x + radius, target.position.y + radius}}, type={'mining-drill', 'inserter'}} + local entities = target.surface.find_entities_filtered{ area = { { target.position.x - radius, target.position.y - radius }, { target.position.x + radius, target.position.y + radius } }, type = { "mining-drill", "inserter" } } for _, e in pairs(entities) do if drop_target(e) == target then @@ -75,7 +74,7 @@ local function chest_check(entity) end if check_entity(target) then - table.insert(miner_data.queue, {t=game.tick + 10, e=target}) + table.insert(miner_data.queue, { t = game.tick + 10, e = target }) end end @@ -85,7 +84,7 @@ local function miner_check(entity) local ef = entity.force local er = entity.prototype.mining_drill_radius - for _, r in pairs(entity.surface.find_entities_filtered{area={{x=ep.x - er, y=ep.y - er}, {x=ep.x + er, y=ep.y + er}}, type='resource'}) do + for _, r in pairs(entity.surface.find_entities_filtered{ area = { { x = ep.x - er, y = ep.y - er }, { x = ep.x + er, y = ep.y + er } }, type = "resource" }) do if r.amount > 0 then return end @@ -103,35 +102,32 @@ local function miner_check(entity) if config.fluid and entity.fluidbox and #entity.fluidbox > 0 then -- if require fluid to mine - table.insert(pipe_build, {x=0, y=0}) + table.insert(pipe_build, { x = 0, y = 0 }) local half = math.floor(entity.get_radius()) local r = 1 + er - local entities = es.find_entities_filtered{area={{ep.x - r, ep.y - r}, {ep.x + r, ep.y + r}}, type={'mining-drill', 'pipe', 'pipe-to-ground'}} - local entities_t = es.find_entities_filtered{area={{ep.x - r, ep.y - r}, {ep.x + r, ep.y + r}}, ghost_type={'pipe', 'pipe-to-ground'}} + local entities = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, type = { "mining-drill", "pipe", "pipe-to-ground" } } + local entities_t = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, ghost_type = { "pipe", "pipe-to-ground" } } table.array_insert(entities, entities_t) for _, e in pairs(entities) do if (e.position.x > ep.x) and (e.position.y == ep.y) then - for h=1, half do - table.insert(pipe_build, {x=h, y=0}) + for h = 1, half do + table.insert(pipe_build, { x = h, y = 0 }) end - elseif (e.position.x < ep.x) and (e.position.y == ep.y) then - for h=1, half do - table.insert(pipe_build, {x=-h, y=0}) + for h = 1, half do + table.insert(pipe_build, { x = -h, y = 0 }) end - elseif (e.position.x == ep.x) and (e.position.y > ep.y) then - for h=1, half do - table.insert(pipe_build, {x=0, y=h}) + for h = 1, half do + table.insert(pipe_build, { x = 0, y = h }) end - elseif (e.position.x == ep.x) and (e.position.y < ep.y) then - for h=1, half do - table.insert(pipe_build, {x=0, y=-h}) + for h = 1, half do + table.insert(pipe_build, { x = 0, y = -h }) end end end @@ -141,10 +137,10 @@ local function miner_check(entity) chest_check(entity) end - table.insert(miner_data.queue, {t=game.tick + 5, e=entity}) + table.insert(miner_data.queue, { t = game.tick + 5, e = entity }) for _, pos in ipairs(pipe_build) do - es.create_entity{name='entity-ghost', position={x=ep.x + pos.x, y=ep.y + pos.y}, force=ef, inner_name='pipe', raise_built=true} + es.create_entity{ name = "entity-ghost", position = { x = ep.x + pos.x, y = ep.y + pos.y }, force = ef, inner_name = "pipe", raise_built = true } end end @@ -153,7 +149,7 @@ Event.add(defines.events.on_resource_depleted, function(event) return end - local entities = event.entity.surface.find_entities_filtered{area={{event.entity.position.x - 1, event.entity.position.y - 1}, {event.entity.position.x + 1, event.entity.position.y + 1}}, type='mining-drill'} + local entities = event.entity.surface.find_entities_filtered{ area = { { event.entity.position.x - 1, event.entity.position.y - 1 }, { event.entity.position.x + 1, event.entity.position.y + 1 } }, type = "mining-drill" } if #entities == 0 then return @@ -171,7 +167,6 @@ Event.on_nth_tick(10, function(event) if not q.e or not q.e.valid then table.remove(miner_data.queue, k) break - elseif event.tick >= q.t then q.e.order_deconstruction(q.e.force) table.remove(miner_data.queue, k) diff --git a/exp_legacy/module/modules/addons/nukeprotect.lua b/exp_legacy/module/modules/addons/nukeprotect.lua index 18df9046..cc17ccdb 100644 --- a/exp_legacy/module/modules/addons/nukeprotect.lua +++ b/exp_legacy/module/modules/addons/nukeprotect.lua @@ -1,46 +1,44 @@ --- Disable new players from having certain items in their inventory, most commonly nukes -- @addon Nukeprotect -local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event -local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles -local config = require("modules.exp_legacy.config.nukeprotect") --- @dep config.nukeprotect +local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event +local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles +local config = require("modules.exp_legacy.config.nukeprotect") --- @dep config.nukeprotect local move_items_stack = _C.move_items_stack --- @dep expcore.common - local function check_items(player, type) - -- if the player has perms to be ignored, then they should be - if config.ignore_permisison and Roles.player_allowed(player, config.ignore_permisison) then return end - -- if the players - if config.ignore_admins and player.admin then return end + -- if the player has perms to be ignored, then they should be + if config.ignore_permisison and Roles.player_allowed(player, config.ignore_permisison) then return end + -- if the players + if config.ignore_admins and player.admin then return end - local inventory = player.get_inventory(type) - for i = 1, #inventory do - local item = inventory[i] - if item.valid and item.valid_for_read and config[tostring(type)][item.name] then - player.print({ "nukeprotect.found", { "item-name." .. item.name } }) - -- insert the items into the table so all items are transferred at once - move_items_stack({ item }) - end - end + local inventory = player.get_inventory(type) + for i = 1, #inventory do + local item = inventory[i] + if item.valid and item.valid_for_read and config[tostring(type)][item.name] then + player.print{ "nukeprotect.found", { "item-name." .. item.name } } + -- insert the items into the table so all items are transferred at once + move_items_stack{ item } + end + end end for _, inventory in ipairs(config.inventories) do - if #inventory.items > 0 then - Event.add(inventory.event, function(event) - local player = game.get_player(event.player_index) - if player and player.valid then - check_items(player, inventory.inventory) - end - end) - end + if #inventory.items > 0 then + Event.add(inventory.event, function(event) + local player = game.get_player(event.player_index) + if player and player.valid then + check_items(player, inventory.inventory) + end + end) + end end - if config.disable_nuke_research then - Event.add(defines.events.on_research_started, function(event) - local name = event.research.name - if config.disable_nuke_research_names[name] then - event.research.force.cancel_current_research() - end - end) + Event.add(defines.events.on_research_started, function(event) + local name = event.research.name + if config.disable_nuke_research_names[name] then + event.research.force.cancel_current_research() + end + end) end diff --git a/exp_legacy/module/modules/addons/pollution-grading.lua b/exp_legacy/module/modules/addons/pollution-grading.lua index 50d5f7ee..3d76d459 100644 --- a/exp_legacy/module/modules/addons/pollution-grading.lua +++ b/exp_legacy/module/modules/addons/pollution-grading.lua @@ -8,9 +8,9 @@ local delay = config.update_delay * 3600 -- convert from minutes to ticks Event.on_nth_tick(delay, function() local surface = game.surfaces[1] local true_max = surface.get_pollution(config.reference_point) - local max = true_max*config.max_scalar - local min = max*config.min_scalar + local max = true_max * config.max_scalar + local min = max * config.min_scalar local settings = game.map_settings.pollution settings.expected_max_per_chunk = max settings.min_to_show_per_chunk = min -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/addons/protection-jail.lua b/exp_legacy/module/modules/addons/protection-jail.lua index 53ac001f..1f0f3bec 100644 --- a/exp_legacy/module/modules/addons/protection-jail.lua +++ b/exp_legacy/module/modules/addons/protection-jail.lua @@ -1,9 +1,9 @@ --- When a player triggers protection multiple times they are automatically jailed -- @addon protection-jail -local Event = require("modules/exp_legacy/utils/event") ---@dep utils.event -local Storage = require("modules/exp_util/storage") ---@dep utils.global -local Jail = require("modules.exp_legacy.modules.control.jail") ---@dep modules.control.jail +local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event +local Storage = require("modules/exp_util/storage") --- @dep utils.global +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 format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common @@ -30,11 +30,11 @@ Event.add(Protection.events.on_repeat_violation, function(event) end local player_name_color = format_chat_player_name(player) - Jail.jail_player(player, '', 'Removed too many protected entities, please wait for a moderator.') - game.print{'protection-jail.jail', player_name_color} + Jail.jail_player(player, "", "Removed too many protected entities, please wait for a moderator.") + game.print{ "protection-jail.jail", player_name_color } end) --- Clear the counter when they leave the game (stops a build up of data) Event.add(defines.events.on_player_left_game, function(event) repeat_count[event.player_index] = nil -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/addons/report-jail.lua b/exp_legacy/module/modules/addons/report-jail.lua index 993fbcda..811f30d7 100644 --- a/exp_legacy/module/modules/addons/report-jail.lua +++ b/exp_legacy/module/modules/addons/report-jail.lua @@ -1,8 +1,8 @@ --- When a player is reported, the player is automatically jailed if the combined playtime of the reporters exceeds the reported player -- @addon report-jail -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 Event = require("modules/exp_legacy/utils/event") --- @dep utils.event +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 format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common @@ -22,7 +22,7 @@ Event.add(Reports.events.on_player_reported, function(event) -- player less than 30 min if (Reports.count_reports(player) > 1) and (total_playtime > math.max(player.online_time * 2, 108000)) then local player_name_color = format_chat_player_name(player) - Jail.jail_player(player, '', 'Reported by too many players, please wait for a moderator.') - game.print{'report-jail.jail', player_name_color} + Jail.jail_player(player, "", "Reported by too many players, please wait for a moderator.") + game.print{ "report-jail.jail", player_name_color } end end) diff --git a/exp_legacy/module/modules/addons/scorched-earth.lua b/exp_legacy/module/modules/addons/scorched-earth.lua index 90cd0d79..231d2d29 100644 --- a/exp_legacy/module/modules/addons/scorched-earth.lua +++ b/exp_legacy/module/modules/addons/scorched-earth.lua @@ -26,7 +26,7 @@ local function degrade(surface, position) local tile_name = tile.name local degrade_tile_name = config.degrade_order[tile_name] if not degrade_tile_name then return end - surface.set_tiles{{name=degrade_tile_name, position=position}} + surface.set_tiles{ { name = degrade_tile_name, position = position } } end -- Same as degrade but will degrade all tiles that are under an entity @@ -39,25 +39,26 @@ local function degrade_entity(entity) local lt = box.left_top local rb = box.right_bottom for x = lt.x, rb.x do -- x loop - local px = position.x+x + local px = position.x + x for y = lt.y, rb.y do -- y loop - local p = {x=px, y=position.y+y} + local p = { x = px, y = position.y + y } local tile = surface.get_tile(p) local tile_name = tile.name local degrade_tile_name = config.degrade_order[tile_name] if not degrade_tile_name then return end - table.insert(tiles, {name=degrade_tile_name, position=p}) + table.insert(tiles, { name = degrade_tile_name, position = p }) end end + surface.set_tiles(tiles) end -- Turns the strength of a tile into a probability (0 = impossible, 1 = certain) local function get_probability(strength) - local v1 = strength/max_strength + local v1 = strength / max_strength local dif = 1 - v1 - local v2 = dif/2 - return (1-v1+v2)/config.weakness_value + local v2 = dif / 2 + return (1 - v1 + v2) / config.weakness_value end -- Gets the mean of the strengths around a tile to give the strength at that position @@ -69,24 +70,25 @@ local function get_tile_strength(surface, position) for x = -1, 1 do -- x loop local px = position.x + x for y = -1, 1 do -- y loop - local check_tile = surface.get_tile{x=px, y=position.y+y} + local check_tile = surface.get_tile{ x = px, y = position.y + y } local check_tile_name = check_tile.name local check_strength = config.strengths[check_tile_name] or 0 strength = strength + check_strength end end - return strength/9 + + return strength / 9 end -- Same as get_tile_strength but returns to a in game text rather than as a value local function debug_get_tile_strength(surface, position) for x = -3, 3 do -- x loop - local px = position.x+x + local px = position.x + x for y = -3, 3 do -- y loop - local p = {x=px, y=position.y+y} + local p = { x = px, y = position.y + y } local strength = get_tile_strength(surface, p) or 0 local tile = surface.get_tile(p) - print_grid_value(get_probability(strength)*config.weakness_value, surface, tile.position) + print_grid_value(get_probability(strength) * config.weakness_value, surface, tile.position) end end end @@ -113,7 +115,7 @@ Event.add(defines.events.on_built_entity, function(event) local position = entity.position local strength = get_tile_strength(surface, position) if not strength then return end - if get_probability(strength)*config.weakness_value > math.random() then + if get_probability(strength) * config.weakness_value > math.random() then degrade_entity(entity) end end) @@ -125,7 +127,7 @@ Event.add(defines.events.on_robot_built_entity, function(event) local position = entity.position local strength = get_tile_strength(surface, position) if not strength then return end - if get_probability(strength)*config.weakness_value > math.random() then + if get_probability(strength) * config.weakness_value > math.random() then degrade_entity(entity) end end) @@ -135,4 +137,4 @@ return function(player_name, state) local player = game.players[player_name] clear_flying_text(player.surface) debug_players[player_name] = state -end \ No newline at end of file +end diff --git a/exp_legacy/module/modules/addons/spawn-area.lua b/exp_legacy/module/modules/addons/spawn-area.lua index 56518494..b70b683a 100644 --- a/exp_legacy/module/modules/addons/spawn-area.lua +++ b/exp_legacy/module/modules/addons/spawn-area.lua @@ -12,7 +12,7 @@ end) -- Apply an offset to a LuaPosition local function apply_offset(position, offset) - return {x=position.x + (offset.x or offset[1]), y=position.y + (offset.y or offset[2])} + return { x = position.x + (offset.x or offset[1]), y = position.y + (offset.y or offset[2]) } end -- Apply the offset to the turrets default position @@ -22,16 +22,16 @@ end -- Get or create the force used for entities in spawn local function get_spawn_force() - local force = game.forces['spawn'] + local force = game.forces["spawn"] if force and force.valid then return force end - force = game.create_force('spawn') - force.set_cease_fire('player', true) + force = game.create_force("spawn") + force.set_cease_fire("player", true) -- force.set_friend('player', true) - game.forces['player'].set_cease_fire('spawn', true) + game.forces["player"].set_cease_fire("spawn", true) -- game.forces['player'].set_friend('spawn', true) return force @@ -57,18 +57,18 @@ local function spawn_turrets() for _, turret_pos in pairs(turrets) do local surface = game.surfaces[turret_pos.surface] local pos = turret_pos.position - local turret = surface.find_entity('gun-turret', pos) + local turret = surface.find_entity("gun-turret", pos) -- Makes a new turret if it is not found if not turret or not turret.valid then - turret = surface.create_entity{name='gun-turret', position=pos, force='spawn'} + turret = surface.create_entity{ name = "gun-turret", position = pos, force = "spawn" } protect_entity(turret) end -- Adds ammo to the turret local inv = turret.get_inventory(defines.inventory.turret_ammo) - if inv.can_insert{name=config.turrets.ammo_type, count=10} then - inv.insert{name=config.turrets.ammo_type, count=10} + if inv.can_insert{ name = config.turrets.ammo_type, count = 10 } then + inv.insert{ name = config.turrets.ammo_type, count = 10 } end end end @@ -77,13 +77,13 @@ end local function spawn_belts(surface, position) position = apply_offset(position, config.afk_belts.offset) local belt_type = config.afk_belts.belt_type - local belt_details = {{-0.5, -0.5, 2}, {0.5, -0.5, 4}, {-0.5, 0.5, 0}, {0.5, 0.5, 6}} -- x, y,dir + local belt_details = { { -0.5, -0.5, 2 }, { 0.5, -0.5, 4 }, { -0.5, 0.5, 0 }, { 0.5, 0.5, 6 } } -- x, y,dir for _, belt_set in pairs(config.afk_belts.locations) do local set_position = apply_offset(position, belt_set) for _, belt in pairs(belt_details) do local pos = apply_offset(set_position, belt) - local belt_entity = surface.create_entity{name=belt_type, position=pos, force='neutral', direction=belt[3]} + local belt_entity = surface.create_entity{ name = belt_type, position = pos, force = "neutral", direction = belt[3] } if config.afk_belts.protected then protect_entity(belt_entity) @@ -99,7 +99,7 @@ local function spawn_pattern(surface, position) local pattern_tile = config.pattern.pattern_tile for _, tile in pairs(config.pattern.locations) do - table.insert(tiles_to_make, {name=pattern_tile, position=apply_offset(position, tile)}) + table.insert(tiles_to_make, { name = pattern_tile, position = apply_offset(position, tile) }) end surface.set_tiles(tiles_to_make) @@ -111,8 +111,9 @@ local function spawn_water(surface, position) local tiles_to_make = {} local water_tile = config.water.water_tile for _, tile in pairs(config.water.locations) do - table.insert(tiles_to_make, {name=water_tile, position=apply_offset(position, tile)}) + table.insert(tiles_to_make, { name = water_tile, position = apply_offset(position, tile) }) end + surface.set_tiles(tiles_to_make) end @@ -120,8 +121,8 @@ end local function spawn_entities(surface, position) position = apply_offset(position, config.entities.offset) for _, entity in pairs(config.entities.locations) do - local pos = apply_offset(position, {x=entity[2], y=entity[3]}) - entity = surface.create_entity{name=entity[1], position=pos, force='neutral'} + local pos = apply_offset(position, { x = entity[2], y = entity[3] }) + entity = surface.create_entity{ name = entity[1], position = pos, force = "neutral" } if config.entities.protected then protect_entity(entity) @@ -135,48 +136,49 @@ end local function spawn_area(surface, position) local dr = config.spawn_area.deconstruction_radius local tr = config.spawn_area.tile_radius - local tr2 = tr^2 + local tr2 = tr ^ 2 local decon_tile = config.spawn_area.deconstruction_tile local fr = config.spawn_area.landfill_radius - local fr2 = fr^2 + local fr2 = fr ^ 2 local fill_tile = surface.get_tile(position).name -- Make sure a non water tile is used for each tile - if surface.get_tile(position).collides_with('player') then fill_tile = 'landfill' end + if surface.get_tile(position).collides_with("player") then fill_tile = "landfill" end if decon_tile == nil then decon_tile = fill_tile end local tiles_to_make = {} for x = -fr, fr do -- loop over x - local x2 = (x+0.5)^2 + local x2 = (x + 0.5) ^ 2 for y = -fr, fr do -- loop over y - local y2 = (y+0.5)^2 - local dst = x2+y2 - local pos = {x=position.x+x, y=position.y+y} + local y2 = (y + 0.5) ^ 2 + local dst = x2 + y2 + local pos = { x = position.x + x, y = position.y + y } if dst < tr2 then -- If it is inside the decon radius always set the tile - table.insert(tiles_to_make, {name=decon_tile, position=pos}) - elseif dst < fr2 and surface.get_tile(pos).collides_with('player') then + table.insert(tiles_to_make, { name = decon_tile, position = pos }) + elseif dst < fr2 and surface.get_tile(pos).collides_with("player") then -- If it is inside the fill radius only set the tile if it is water - table.insert(tiles_to_make, {name=fill_tile, position=pos}) + table.insert(tiles_to_make, { name = fill_tile, position = pos }) end end end -- Remove entities then set the tiles - local entities_to_remove = surface.find_entities_filtered{position=position, radius=dr, name='character', invert=true} + local entities_to_remove = surface.find_entities_filtered{ position = position, radius = dr, name = "character", invert = true } for _, entity in pairs(entities_to_remove) do entity.destroy() end + surface.set_tiles(tiles_to_make) end local function spawn_resource_tiles(surface) for _, v in ipairs(config.resource_tiles.resources) do if v.enabled then - for x=v.offset[1], v.offset[1] + v.size[1] do - for y=v.offset[2], v.offset[2] + v.size[2] do - surface.create_entity({name=v.name, amount=v.amount, position={x, y}}) + for x = v.offset[1], v.offset[1] + v.size[1] do + for y = v.offset[2], v.offset[2] + v.size[2] do + surface.create_entity{ name = v.name, amount = v.amount, position = { x, y } } end end end @@ -186,8 +188,8 @@ end local function spawn_resource_patches(surface) for _, v in ipairs(config.resource_patches.resources) do if v.enabled then - for i=1, v.num_patches do - surface.create_entity({name=v.name, amount=v.amount, position={v.offset[1] + v.offset_next[1] * (i - 1), v.offset[2] + v.offset_next[2] * (i - 1)}}) + for i = 1, v.num_patches do + surface.create_entity{ name = v.name, amount = v.amount, position = { v.offset[1] + v.offset_next[1] * (i - 1), v.offset[2] + v.offset_next[2] * (i - 1) } } end end end @@ -208,7 +210,7 @@ if config.resource_refill_nearby.enabled then return end - for _, ore in pairs(game.players[1].surface.find_entities_filtered{position=game.players[1].force.get_spawn_position(game.players[1].surface), radius=config.resource_refill_nearby.range, name=config.resource_refill_nearby.resources_name}) do + for _, ore in pairs(game.players[1].surface.find_entities_filtered{ position = game.players[1].force.get_spawn_position(game.players[1].surface), radius = config.resource_refill_nearby.range, name = config.resource_refill_nearby.resources_name }) do ore.amount = ore.amount + math.random(config.resource_refill_nearby.amount[1], config.resource_refill_nearby.amount[2]) end end) @@ -218,7 +220,7 @@ end Event.add(defines.events.on_player_created, function(event) if event.player_index ~= 1 then return end local player = game.players[event.player_index] - local p = {x=0, y=0} + local p = { x = 0, y = 0 } local s = player.surface get_spawn_force() spawn_area(s, p) diff --git a/exp_legacy/module/modules/addons/station-auto-name.lua b/exp_legacy/module/modules/addons/station-auto-name.lua index 813e4be8..aea718d8 100644 --- a/exp_legacy/module/modules/addons/station-auto-name.lua +++ b/exp_legacy/module/modules/addons/station-auto-name.lua @@ -1,86 +1,85 @@ ----LuaPlayerBuiltEntityEventFilters ----Events.set_event_filter(defines.events.on_built_entity, {{filter = "name", name = "fast-inserter"}}) +--- LuaPlayerBuiltEntityEventFilters +--- Events.set_event_filter(defines.events.on_built_entity, {{filter = "name", name = "fast-inserter"}}) local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local config = require("modules.exp_legacy.config.station_auto_name") --- @dep config.chat_reply ---Credit to Cooldude2606 for using his lua magic to make this function. +-- Credit to Cooldude2606 for using his lua magic to make this function. local directions = { - ['W'] = -0.875, - ['NW'] = -0.625, - ['N'] = -0.375, - ['NE'] = -0.125, - ['E'] = 0.125, - ['SE'] = 0.375, - ['S'] = 0.625, - ['SW'] = 0.875 + ["W"] = -0.875, + ["NW"] = -0.625, + ["N"] = -0.375, + ["NE"] = -0.125, + ["E"] = 0.125, + ["SE"] = 0.375, + ["S"] = 0.625, + ["SW"] = 0.875, } local function Angle(entity) - local angle = math.atan2(entity.position.y, entity.position.x)/math.pi + local angle = math.atan2(entity.position.y, entity.position.x) / math.pi for direction, requiredAngle in pairs(directions) do if angle < requiredAngle then return direction end end - return 'W' + + return "W" end -local custom_string = ' *' +local custom_string = " *" local custom_string_len = #custom_string local function station_name_changer(event) local entity = event.created_entity local name = entity.name - if name == "entity-ghost" then + if name == "entity-ghost" then if entity.ghost_name ~= "train-stop" then return end local backername = entity.backer_name - if backername ~= '' then - entity.backer_name = backername..custom_string + if backername ~= "" then + entity.backer_name = backername .. custom_string end - - elseif name == "train-stop" then --only do the event if its a train stop + elseif name == "train-stop" then -- only do the event if its a train stop local backername = entity.backer_name if backername:sub(-custom_string_len) == custom_string then - entity.backer_name = backername:sub(1, -custom_string_len-1) + entity.backer_name = backername:sub(1, -custom_string_len - 1) return end local boundingBox = entity.bounding_box -- expanded box for recourse search: - local bounding2 = {{boundingBox.left_top.x-100 ,boundingBox.left_top.y-100} , {boundingBox.right_bottom.x+100, boundingBox.right_bottom.y+100 }} + local bounding2 = { { boundingBox.left_top.x - 100, boundingBox.left_top.y - 100 }, { boundingBox.right_bottom.x + 100, boundingBox.right_bottom.y + 100 } } -- gets all resources in bounding_box2: - local recourses = game.surfaces[1].find_entities_filtered{area = bounding2, type = "resource"} + local recourses = game.surfaces[1].find_entities_filtered{ area = bounding2, type = "resource" } if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2 local closest_distance local px, py = boundingBox.left_top.x, boundingBox.left_top.y local recourse_closed - --Check which recourse is closest + -- Check which recourse is closest for i, item in ipairs(recourses) do local dx, dy = px - item.bounding_box.left_top.x, py - item.bounding_box.left_top.y - local distance = (dx*dx)+(dy*dy) - if not closest_distance or distance < closest_distance then + local distance = (dx * dx) + (dy * dy) + if not closest_distance or distance < closest_distance then recourse_closed = item closest_distance = distance end - end local item_name = recourse_closed.name if item_name then -- prevent errors if something went wrong - local item_name2 = item_name:gsub("^%l", string.upper):gsub('-', ' ') -- removing the - and making first letter capital + local item_name2 = item_name:gsub("^%l", string.upper):gsub("-", " ") -- removing the - and making first letter capital - local item_type = 'item' - if item_name == 'crude-oil' then - item_type = 'fluid' + local item_type = "item" + if item_name == "crude-oil" then + item_type = "fluid" end - entity.backer_name = config.station_name:gsub('__icon__', '[img=' .. item_type .. '.' .. item_name .. ']') - :gsub('__item_name__', item_name2) - :gsub('__backer_name__', entity.backer_name) - :gsub('__direction__', Angle(entity)) - :gsub('__x__', math.floor(entity.position.x)) - :gsub('__y__', math.floor(entity.position.y)) + entity.backer_name = config.station_name:gsub("__icon__", "[img=" .. item_type .. "." .. item_name .. "]") + :gsub("__item_name__", item_name2) + :gsub("__backer_name__", entity.backer_name) + :gsub("__direction__", Angle(entity)) + :gsub("__x__", math.floor(entity.position.x)) + :gsub("__y__", math.floor(entity.position.y)) end end end diff --git a/exp_legacy/module/modules/addons/tree-decon.lua b/exp_legacy/module/modules/addons/tree-decon.lua index 6d02701e..aa72774d 100644 --- a/exp_legacy/module/modules/addons/tree-decon.lua +++ b/exp_legacy/module/modules/addons/tree-decon.lua @@ -9,8 +9,8 @@ local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep ex -- Storage queue used to store trees that need to be removed, also cache for player roles local cache = {} -local tree_queue = { _head=0 } -Storage.register({tree_queue, cache}, function(tbl) +local tree_queue = { _head = 0 } +Storage.register({ tree_queue, cache }, function(tbl) tree_queue = tbl[1] cache = tbl[2] end) @@ -18,26 +18,29 @@ end) local function get_permission(player_index) if cache[player_index] == nil then local player = game.players[player_index] - if Roles.player_allowed(player, 'fast-tree-decon') then cache[player_index] = 'fast' - elseif Roles.player_allowed(player, 'standard-decon') then cache[player_index] = 'standard' - else cache[player_index] = player.force end + if Roles.player_allowed(player, "fast-tree-decon") then + cache[player_index] = "fast" + elseif Roles.player_allowed(player, "standard-decon") then + cache[player_index] = "standard" + else + cache[player_index] = player.force + end end return cache[player_index] end -- Left menu button to toggle between fast decon and normal decon marking -local HasEnabledDecon = PlayerData.Settings:combine('HasEnabledDecon') +local HasEnabledDecon = PlayerData.Settings:combine("HasEnabledDecon") HasEnabledDecon:set_default(false) -Gui.toolbar_toggle_button("entity/tree-01", {'tree-decon.main-tooltip'}, function (player) - return Roles.player_allowed(player, "fast-tree-decon") +Gui.toolbar_toggle_button("entity/tree-01", { "tree-decon.main-tooltip" }, function(player) + return Roles.player_allowed(player, "fast-tree-decon") end) -:on_event(Gui.events.on_toolbar_button_toggled, function(player, _, event) - HasEnabledDecon:set(player, event.state) - player.print{'tree-decon.toggle-msg', event.state and {'tree-decon.enabled'} or {'tree-decon.disabled'}} -end) - + :on_event(Gui.events.on_toolbar_button_toggled, function(player, _, event) + HasEnabledDecon:set(player, event.state) + player.print{ "tree-decon.toggle-msg", event.state and { "tree-decon.enabled" } or { "tree-decon.disabled" } } + end) -- Add trees to queue when marked, only allows simple entities and for players with role permission Event.add(defines.events.on_marked_for_deconstruction, function(event) @@ -52,24 +55,23 @@ Event.add(defines.events.on_marked_for_deconstruction, function(event) -- Not allowed to decon this entity local last_user = entity.last_user local allow = get_permission(index) - if last_user and allow ~= 'standard' and allow ~= 'fast' then + if last_user and allow ~= "standard" and allow ~= "fast" then entity.cancel_deconstruction(allow) return end -- Allowed to decon this entity, but not fast - if allow ~= 'fast' then return end + if allow ~= "fast" then return end local player = game.get_player(index) if not HasEnabledDecon:get(player) then return end -- Allowed fast decon on this entity, just trees local head = tree_queue._head + 1 - if not last_user and entity.type ~= 'cliff' then + if not last_user and entity.type ~= "cliff" then tree_queue[head] = entity tree_queue._head = head end - end) -- Remove trees at random till the queue is empty @@ -77,7 +79,7 @@ Event.add(defines.events.on_tick, function() local head = tree_queue._head if head == 0 then return end - local max_remove = math.floor(head/100)+1 + local max_remove = math.floor(head / 100) + 1 local remove_count = math.random(0, max_remove) while remove_count > 0 and head > 0 do local remove_index = math.random(1, head) @@ -89,6 +91,7 @@ Event.add(defines.events.on_tick, function() entity.destroy() end end + tree_queue._head = head end) @@ -101,24 +104,24 @@ end) -- Clear trees when hit with a car Event.add(defines.events.on_entity_damaged, function(event) - if not (event.damage_type.name == 'impact' and event.force) then - return - end + if not (event.damage_type.name == "impact" and event.force) then + return + end - if not (event.entity.type == 'tree' or event.entity.type == 'simple-entity') then - return - end + if not (event.entity.type == "tree" or event.entity.type == "simple-entity") then + return + end - if (not event.cause) or (event.cause.type ~= 'car')then - return - end + if (not event.cause) or (event.cause.type ~= "car") then + return + end local driver = event.cause.get_driver() if not driver then return end local allow = get_permission(driver.player.index) if allow == "fast" and HasEnabledDecon:get(driver.player) then - event.entity.destroy() + event.entity.destroy() else event.entity.order_deconstruction(event.force, driver.player) end diff --git a/exp_legacy/module/modules/commands/admin-chat.lua b/exp_legacy/module/modules/commands/admin-chat.lua index d6f1dbbe..ff988e8c 100644 --- a/exp_legacy/module/modules/commands/admin-chat.lua +++ b/exp_legacy/module/modules/commands/admin-chat.lua @@ -10,17 +10,18 @@ require("modules.exp_legacy.config.expcore.command_general_parse") --- Sends a message in chat that only admins can see -- @command admin-chat -- @tparam string message the message to send in the admin chat -Commands.new_command('admin-chat', {'expcom-admin-chat.description'}, 'Sends a message in chat that only admins can see.') -:add_param('message', false) -:enable_auto_concat() -:set_flag('admin_only') -:add_alias('ac') -:register(function(player, message) - local player_name_colour = format_chat_player_name(player) - for _, return_player in pairs(game.connected_players) do - if return_player.admin then - return_player.print{'expcom-admin-chat.format', player_name_colour, message} +Commands.new_command("admin-chat", { "expcom-admin-chat.description" }, "Sends a message in chat that only admins can see.") + :add_param("message", false) + :enable_auto_concat() + :set_flag("admin_only") + :add_alias("ac") + :register(function(player, message) + local player_name_colour = format_chat_player_name(player) + for _, return_player in pairs(game.connected_players) do + if return_player.admin then + return_player.print{ "expcom-admin-chat.format", player_name_colour, message } + end end - end - return Commands.success -- prevents command complete message from showing -end) + + return Commands.success -- prevents command complete message from showing + end) diff --git a/exp_legacy/module/modules/commands/admin-markers.lua b/exp_legacy/module/modules/commands/admin-markers.lua index 62291590..54cd992a 100644 --- a/exp_legacy/module/modules/commands/admin-markers.lua +++ b/exp_legacy/module/modules/commands/admin-markers.lua @@ -13,7 +13,7 @@ local markers = {} -- Stores all admin markers --- Storage variables Storage.register({ admins = admins, - markers = markers + markers = markers, }, function(tbl) admins = tbl.admins markers = tbl.markers @@ -21,20 +21,20 @@ end) --- Toggle admin marker mode, can only be applied to yourself -- @command admin-marker -Commands.new_command('admin-marker', {'expcom-admin-marker.description'}, 'Toggles admin marker mode, new markers can only be edited by admins') -:set_flag('admin_only') -:add_alias('am', 'admin-markers') -:register(function(player) - if admins[player.name] then - -- Exit admin mode - admins[player.name] = nil - return Commands.success{'expcom-admin-marker.exit'} - else - -- Enter admin mode - admins[player.name] = true - return Commands.success{'expcom-admin-marker.enter'} - end -end) +Commands.new_command("admin-marker", { "expcom-admin-marker.description" }, "Toggles admin marker mode, new markers can only be edited by admins") + :set_flag("admin_only") + :add_alias("am", "admin-markers") + :register(function(player) + if admins[player.name] then + -- Exit admin mode + admins[player.name] = nil + return Commands.success{ "expcom-admin-marker.exit" } + else + -- Enter admin mode + admins[player.name] = true + return Commands.success{ "expcom-admin-marker.enter" } + end + end) --- 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) @@ -42,8 +42,8 @@ Event.add(defines.events.on_chart_tag_added, function(event) local player = game.get_player(event.player_index) if not admins[player.name] then return end local tag = event.tag - markers[tag.force.name..tag.tag_number] = true - Commands.print({'expcom-admin-marker.place'}, nil, player) + markers[tag.force.name .. tag.tag_number] = true + Commands.print({ "expcom-admin-marker.place" }, nil, player) end) --- Listen for players leaving the game, leave admin mode to avoid unexpected admin markers @@ -57,30 +57,30 @@ end) local function maintain_tag(event) local tag = event.tag if not event.player_index then return end - if not markers[tag.force.name..tag.tag_number] then return end + if not markers[tag.force.name .. tag.tag_number] then return end local player = game.get_player(event.player_index) if player.admin then -- Player is admin, tell them it was an admin marker - Commands.print({'expcom-admin-marker.edit'}, nil, player) + Commands.print({ "expcom-admin-marker.edit" }, nil, player) elseif event.name == defines.events.on_chart_tag_modified then -- Tag was modified, revert the changes tag.text = event.old_text tag.last_user = event.old_player if event.old_icon then tag.icon = event.old_icon end - player.play_sound{path='utility/wire_pickup'} - Commands.print({'expcom-admin-marker.revert'}, nil, player) + player.play_sound{ path = "utility/wire_pickup" } + Commands.print({ "expcom-admin-marker.revert" }, nil, player) else -- Tag was removed, remake the tag - player.play_sound{path='utility/wire_pickup'} - Commands.print({'expcom-admin-marker.revert'}, 'orange_red', player) + player.play_sound{ path = "utility/wire_pickup" } + Commands.print({ "expcom-admin-marker.revert" }, "orange_red", player) local new_tag = tag.force.add_chart_tag(tag.surface, { last_user = tag.last_user, position = tag.position, icon = tag.icon, text = tag.text, }) - markers[tag.force.name..tag.tag_number] = nil - markers[new_tag.force.name..new_tag.tag_number] = true + markers[tag.force.name .. tag.tag_number] = nil + markers[new_tag.force.name .. new_tag.tag_number] = true end end diff --git a/exp_legacy/module/modules/commands/artillery.lua b/exp_legacy/module/modules/commands/artillery.lua index 5050a3a1..cd252559 100644 --- a/exp_legacy/module/modules/commands/artillery.lua +++ b/exp_legacy/module/modules/commands/artillery.lua @@ -6,21 +6,17 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection -local SelectionArtyArea = 'ArtyArea' +local SelectionArtyArea = "ArtyArea" local function location_break(player, pos) - if player.force.is_chunk_charted(player.surface, {x=math.floor(pos.left_top.x / 32), y=math.floor(pos.left_top.y / 32)}) then + if player.force.is_chunk_charted(player.surface, { x = math.floor(pos.left_top.x / 32), y = math.floor(pos.left_top.y / 32) }) then return true - - elseif player.force.is_chunk_charted(player.surface, {x=math.floor(pos.left_top.x / 32), y=math.floor(pos.right_bottom.y / 32)}) then + elseif player.force.is_chunk_charted(player.surface, { x = math.floor(pos.left_top.x / 32), y = math.floor(pos.right_bottom.y / 32) }) then return true - - elseif player.force.is_chunk_charted(player.surface, {x=math.floor(pos.right_bottom.x / 32), y=math.floor(pos.left_top.y / 32)}) then + elseif player.force.is_chunk_charted(player.surface, { x = math.floor(pos.right_bottom.x / 32), y = math.floor(pos.left_top.y / 32) }) then return true - - elseif player.force.is_chunk_charted(player.surface, {x=math.floor(pos.right_bottom.x / 32), y=math.floor(pos.right_bottom.y / 32)}) then + elseif player.force.is_chunk_charted(player.surface, { x = math.floor(pos.right_bottom.x / 32), y = math.floor(pos.right_bottom.y / 32) }) then return true - else return false end @@ -29,8 +25,8 @@ end --- align an aabb to the grid by expanding it local function aabb_align_expand(aabb) return { - left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)}, - right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)} + left_top = { x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y) }, + right_bottom = { x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y) }, } end @@ -50,7 +46,7 @@ Selection.on_selection(SelectionArtyArea, function(event) local count = 0 local hit = {} - for _, e in pairs(player.surface.find_entities_filtered({area=area, type={'unit-spawner', 'turret'}, force='enemy'})) do + for _, e in pairs(player.surface.find_entities_filtered{ area = area, type = { "unit-spawner", "turret" }, force = "enemy" }) do local skip = false for _, pos in ipairs(hit) do @@ -61,7 +57,7 @@ Selection.on_selection(SelectionArtyArea, function(event) end if not skip then - player.surface.create_entity{name='artillery-flare', position=e.position, force=player.force, life_time=240, movement={0, 0}, height=0, vertical_speed=0, frame_speed=0} + player.surface.create_entity{ name = "artillery-flare", position = e.position, force = player.force, life_time = 240, movement = { 0, 0 }, height = 0, vertical_speed = 0, frame_speed = 0 } table.insert(hit, e.position) count = count + 1 @@ -72,13 +68,13 @@ Selection.on_selection(SelectionArtyArea, function(event) end end) -Commands.new_command('artillery-target-remote', {'expcom-artillery.description'}, 'Artillery Target Remote') -:register(function(player) - if Selection.is_selecting(player, SelectionArtyArea) then - Selection.stop(player) - else - Selection.start(player, SelectionArtyArea) - end +Commands.new_command("artillery-target-remote", { "expcom-artillery.description" }, "Artillery Target Remote") + :register(function(player) + if Selection.is_selecting(player, SelectionArtyArea) then + Selection.stop(player) + else + Selection.start(player, SelectionArtyArea) + end - return Commands.success -end) + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/bot-queue.lua b/exp_legacy/module/modules/commands/bot-queue.lua index 8313ad8d..2da11bc2 100644 --- a/exp_legacy/module/modules/commands/bot-queue.lua +++ b/exp_legacy/module/modules/commands/bot-queue.lua @@ -6,20 +6,20 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") -Commands.new_command('bot-queue-get', {'expcom-bot-queue.description-get'}, 'Get bot queue') -:set_flag('admin_only') -:register(function(player) - local s = player.force.max_successful_attempts_per_tick_per_construction_queue - local f = player.force.max_failed_attempts_per_tick_per_construction_queue - return Commands.success{'expcom-bot-queue.result', player.name, s, f} -end) +Commands.new_command("bot-queue-get", { "expcom-bot-queue.description-get" }, "Get bot queue") + :set_flag("admin_only") + :register(function(player) + local s = player.force.max_successful_attempts_per_tick_per_construction_queue + local f = player.force.max_failed_attempts_per_tick_per_construction_queue + return Commands.success{ "expcom-bot-queue.result", player.name, s, f } + end) -Commands.new_command('bot-queue-set', {'expcom-bot-queue.description-set'}, 'Set bot queue') -:add_param('amount', 'integer-range', 1, 20) -:set_flag('admin_only') -:register(function(player, amount) - player.force.max_successful_attempts_per_tick_per_construction_queue = 3 * amount - player.force.max_failed_attempts_per_tick_per_construction_queue = 1 * amount - game.print{'expcom-bot-queue.result', player.name, 3 * amount, 1 * amount} - return Commands.success -end) +Commands.new_command("bot-queue-set", { "expcom-bot-queue.description-set" }, "Set bot queue") + :add_param("amount", "integer-range", 1, 20) + :set_flag("admin_only") + :register(function(player, amount) + player.force.max_successful_attempts_per_tick_per_construction_queue = 3 * amount + player.force.max_failed_attempts_per_tick_per_construction_queue = 1 * amount + game.print{ "expcom-bot-queue.result", player.name, 3 * amount, 1 * amount } + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/cheat-mode.lua b/exp_legacy/module/modules/commands/cheat-mode.lua index c3903b64..8bf2ac92 100644 --- a/exp_legacy/module/modules/commands/cheat-mode.lua +++ b/exp_legacy/module/modules/commands/cheat-mode.lua @@ -9,37 +9,37 @@ require("modules.exp_legacy.config.expcore.command_general_parse") --- Toggles cheat mode for your player, or another player. -- @command toggle-cheat-mode -- @tparam[opt=self] LuaPlayer player player to toggle chest mode of, can be nil for self -Commands.new_command('toggle-cheat-mode', {'expcom-cheat.description-cheat'}, 'Toggles cheat mode for your player, or another player.') -:add_param('player', true, 'player') -:set_defaults{player=function(player) - return player -- default is the user using the command -end} -:set_flag('admin_only') -:register(function(_, player) - player.cheat_mode = not player.cheat_mode - return Commands.success -end) +Commands.new_command("toggle-cheat-mode", { "expcom-cheat.description-cheat" }, "Toggles cheat mode for your player, or another player.") + :add_param("player", true, "player") + :set_defaults{ player = function(player) + return player -- default is the user using the command + end } + :set_flag("admin_only") + :register(function(_, player) + player.cheat_mode = not player.cheat_mode + return Commands.success + end) -Commands.new_command('research-all', {'expcom-cheat.description-res'}, 'Set all research for your force.') -:set_flag('admin_only') -:add_param('force', true, 'force') -:set_defaults{force=function(player) - return player.force -end} -:register(function(player, force) - force.research_all_technologies() - game.print{'expcom-cheat.res', player.name} - return Commands.success -end) +Commands.new_command("research-all", { "expcom-cheat.description-res" }, "Set all research for your force.") + :set_flag("admin_only") + :add_param("force", true, "force") + :set_defaults{ force = function(player) + return player.force + end } + :register(function(player, force) + force.research_all_technologies() + game.print{ "expcom-cheat.res", player.name } + return Commands.success + end) -Commands.new_command('toggle-always-day', {'expcom-cheat.description-day'}, 'Toggles always day in surface.') -:set_flag('admin_only') -:add_param('surface', true, 'surface') -:set_defaults{surface=function(player) - return player.surface -end} -:register(function(player, surface) - surface.always_day = not surface.always_day - game.print{'expcom-cheat.day', player.name, surface.always_day} - return Commands.success -end) +Commands.new_command("toggle-always-day", { "expcom-cheat.description-day" }, "Toggles always day in surface.") + :set_flag("admin_only") + :add_param("surface", true, "surface") + :set_defaults{ surface = function(player) + return player.surface + end } + :register(function(player, surface) + surface.always_day = not surface.always_day + game.print{ "expcom-cheat.day", player.name, surface.always_day } + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/clear-inventory.lua b/exp_legacy/module/modules/commands/clear-inventory.lua index a87a50aa..f364f54a 100644 --- a/exp_legacy/module/modules/commands/clear-inventory.lua +++ b/exp_legacy/module/modules/commands/clear-inventory.lua @@ -10,14 +10,14 @@ require("modules.exp_legacy.config.expcore.command_role_parse") --- Clears a players inventory -- @command clear-inventory -- @tparam LuaPlayer player the player to clear the inventory of -Commands.new_command('clear-inventory', {'expcom-clr-inv.description'}, 'Clears a players inventory') -:add_param('player', false, 'player-role') -:add_alias('clear-inv', 'move-inventory', 'move-inv') -:register(function(_, player) - local inv = player.get_main_inventory() - if not inv then - return Commands.error{'expcore-commands.reject-player-alive'} - end - move_items_stack(inv) - inv.clear() -end) +Commands.new_command("clear-inventory", { "expcom-clr-inv.description" }, "Clears a players inventory") + :add_param("player", false, "player-role") + :add_alias("clear-inv", "move-inventory", "move-inv") + :register(function(_, player) + local inv = player.get_main_inventory() + if not inv then + return Commands.error{ "expcore-commands.reject-player-alive" } + end + move_items_stack(inv) + inv.clear() + end) diff --git a/exp_legacy/module/modules/commands/connect.lua b/exp_legacy/module/modules/commands/connect.lua index d48c950c..e61fbd16 100644 --- a/exp_legacy/module/modules/commands/connect.lua +++ b/exp_legacy/module/modules/commands/connect.lua @@ -30,20 +30,20 @@ local function get_server_id(server) end if server_count > 1 then - return false, Commands.error{'expcom-connect.too-many-matching', concat(server_names, ', ')} + return false, Commands.error{ "expcom-connect.too-many-matching", concat(server_names, ", ") } elseif server_count == 1 then local server_id, server_details = next(servers) local status = External.get_server_status(server_id) if server_id == current_server.id then - return false, Commands.error{'expcom-connect.same-server', server_details.name} - elseif status == 'Offline' then - return false, Commands.error{'expcom-connect.offline', server_details.name} + return false, Commands.error{ "expcom-connect.same-server", server_details.name } + elseif status == "Offline" then + return false, Commands.error{ "expcom-connect.offline", server_details.name } end return true, server_id elseif server_count_before > 0 then - return false, Commands.error{'expcom-connect.wrong-version', concat(server_names_before, ', ')} + return false, Commands.error{ "expcom-connect.wrong-version", concat(server_names_before, ", ") } else - return false, Commands.error{'expcom-connect.none-matching'} + return false, Commands.error{ "expcom-connect.none-matching" } end end @@ -51,57 +51,57 @@ end -- @command connect -- @tparam string server The address or name of the server to connect to -- @tparam[opt=false] boolean is_address If an address was given for the server param -Commands.new_command('connect', {'expcom-connect.description'}, 'Connect to another server') -:add_param('server') -:add_param('is_address', true, 'boolean') -:add_alias('join', 'server') -:register(function(player, server, is_address) - local server_id = server - if not is_address and External.valid() then - local success, new_server_id = get_server_id(server) - if not success then return new_server_id end - server_id = new_server_id - end +Commands.new_command("connect", { "expcom-connect.description" }, "Connect to another server") + :add_param("server") + :add_param("is_address", true, "boolean") + :add_alias("join", "server") + :register(function(player, server, is_address) + local server_id = server + if not is_address and External.valid() then + local success, new_server_id = get_server_id(server) + if not success then return new_server_id end + server_id = new_server_id + end - Async(request_connection, player, server_id, true) -end) + Async(request_connection, player, server_id, true) + end) --- Connect a player to a different server -- @command connect-player -- @tparam string address The address or name of the server to connect to -- @tparam LuaPlayer player The player to connect to a different server -- @tparam[opt=false] boolean is_address If an address was given for the server param -Commands.new_command('connect-player', {'expcom-connect.description-player'}, 'Send a player to a different server') -:add_param('player', 'player-role') -:add_param('server') -:add_param('is_address', true, 'boolean') -:register(function(_, player, server, is_address) - local server_id = server - if not is_address and External.valid() then - local success, new_server_id = get_server_id(server) - if not success then return new_server_id end - server_id = new_server_id - end +Commands.new_command("connect-player", { "expcom-connect.description-player" }, "Send a player to a different server") + :add_param("player", "player-role") + :add_param("server") + :add_param("is_address", true, "boolean") + :register(function(_, player, server, is_address) + local server_id = server + if not is_address and External.valid() then + local success, new_server_id = get_server_id(server) + if not success then return new_server_id end + server_id = new_server_id + end - External.request_connection(player, server_id) -end) + External.request_connection(player, server_id) + end) --- Connect all players to a different server -- @command connect-all -- @tparam string address The address or name of the server to connect to -- @tparam[opt=false] boolean is_address If an address was given for the server param -Commands.new_command('connect-all', {'expcom-connect.description-all'}, 'Connect all players to another server') -:add_param('server') -:add_param('is_address', true, 'boolean') -:register(function(_, server, is_address) - local server_id = server - if not is_address and External.valid() then - local success, new_server_id = get_server_id(server) - if not success then return new_server_id end - server_id = new_server_id - end +Commands.new_command("connect-all", { "expcom-connect.description-all" }, "Connect all players to another server") + :add_param("server") + :add_param("is_address", true, "boolean") + :register(function(_, server, is_address) + local server_id = server + if not is_address and External.valid() then + local success, new_server_id = get_server_id(server) + if not success then return new_server_id end + server_id = new_server_id + end - for _, player in pairs(game.connected_players) do - External.request_connection(player, server_id) - end -end) + for _, player in pairs(game.connected_players) do + External.request_connection(player, server_id) + end + end) diff --git a/exp_legacy/module/modules/commands/debug.lua b/exp_legacy/module/modules/commands/debug.lua index 59835009..ef7c2106 100644 --- a/exp_legacy/module/modules/commands/debug.lua +++ b/exp_legacy/module/modules/commands/debug.lua @@ -8,7 +8,7 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore --- Opens the debug pannel for viewing tables. -- @command debug -Commands.new_command('debug', {'expcom-debug.description'}, 'Opens the debug pannel for viewing tables.') -:register(function(player) - DebugView.open_dubug(player) -end) +Commands.new_command("debug", { "expcom-debug.description" }, "Opens the debug pannel for viewing tables.") + :register(function(player) + DebugView.open_dubug(player) + end) diff --git a/exp_legacy/module/modules/commands/enemy.lua b/exp_legacy/module/modules/commands/enemy.lua index 427a9ff3..9ccdf5c5 100644 --- a/exp_legacy/module/modules/commands/enemy.lua +++ b/exp_legacy/module/modules/commands/enemy.lua @@ -6,24 +6,24 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") -Commands.new_command('kill-biters', {'expcom-enemy.description-kill'}, 'Kill all biters only') -:set_flag('admin_only') -:register(function(_, _) - game.forces['enemy'].kill_all_units() - return Commands.success -end) +Commands.new_command("kill-biters", { "expcom-enemy.description-kill" }, "Kill all biters only") + :set_flag("admin_only") + :register(function(_, _) + game.forces["enemy"].kill_all_units() + return Commands.success + end) -Commands.new_command('remove-biters', {'expcom-enemy.description-remove'}, 'Remove biters and prevent generation') -:set_flag('admin_only') -:add_param('surface', true, 'surface') -:set_defaults{surface=function(player) - return player.surface -end} -:register(function(_, surface) - for _, entity in pairs(surface.find_entities_filtered({force='enemy'})) do - entity.destroy() - end +Commands.new_command("remove-biters", { "expcom-enemy.description-remove" }, "Remove biters and prevent generation") + :set_flag("admin_only") + :add_param("surface", true, "surface") + :set_defaults{ surface = function(player) + return player.surface + end } + :register(function(_, surface) + for _, entity in pairs(surface.find_entities_filtered{ force = "enemy" }) do + entity.destroy() + end - surface.map_gen_settings.autoplace_controls['enemy-base'].size = 'none' - return Commands.success -end) + surface.map_gen_settings.autoplace_controls["enemy-base"].size = "none" + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/find.lua b/exp_legacy/module/modules/commands/find.lua index f2dd6a90..c57fbaf2 100644 --- a/exp_legacy/module/modules/commands/find.lua +++ b/exp_legacy/module/modules/commands/find.lua @@ -9,11 +9,11 @@ require("modules.exp_legacy.config.expcore.command_general_parse") --- Find a player on your map. -- @command find-on-map -- @tparam LuaPlayer the player to find on the map -Commands.new_command('find-on-map', {'expcom-find.description'}, 'Find a player on your map.') -:add_param('player', false, 'player-online') -:add_alias('find', 'zoom-to') -:register(function(player, action_player) - local position = action_player.position - player.zoom_to_world(position, 1.75) - return Commands.success -- prevents command complete message from showing -end) +Commands.new_command("find-on-map", { "expcom-find.description" }, "Find a player on your map.") + :add_param("player", false, "player-online") + :add_alias("find", "zoom-to") + :register(function(player, action_player) + local position = action_player.position + player.zoom_to_world(position, 1.75) + return Commands.success -- prevents command complete message from showing + end) diff --git a/exp_legacy/module/modules/commands/friendly-fire.lua b/exp_legacy/module/modules/commands/friendly-fire.lua index d8452f1f..18421cf9 100644 --- a/exp_legacy/module/modules/commands/friendly-fire.lua +++ b/exp_legacy/module/modules/commands/friendly-fire.lua @@ -7,13 +7,13 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore require("modules.exp_legacy.config.expcore.command_general_parse") -- For Modded Server Use -Commands.new_command('toggle-friendly-fire', {'expcom-ff.description'}, 'Toggle friendly fire') -:add_param('force', true, 'force') -:set_defaults{force=function(player) - return player.force -end} -:register(function(player, force) - force.friendly_fire = not force.friendly_fire - game.print{'expcom-ff.ff', player.name, force.friendly_fire} - return Commands.success -end) +Commands.new_command("toggle-friendly-fire", { "expcom-ff.description" }, "Toggle friendly fire") + :add_param("force", true, "force") + :set_defaults{ force = function(player) + return player.force + end } + :register(function(player, force) + force.friendly_fire = not force.friendly_fire + game.print{ "expcom-ff.ff", player.name, force.friendly_fire } + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/help.lua b/exp_legacy/module/modules/commands/help.lua index 13dba196..b35a4b12 100644 --- a/exp_legacy/module/modules/commands/help.lua +++ b/exp_legacy/module/modules/commands/help.lua @@ -18,78 +18,77 @@ end) -- @command chelp -- @tparam string keyword the keyword that will be looked for -- @tparam number page the page of help to view, must be in range of pages -Commands.new_command('search-help', {'expcom-chelp.description'}, 'Searches for a keyword in all commands you are allowed to use.') -:add_alias('chelp', 'shelp', 'commands') -:add_param('keyword', true) -:add_param('page', true, 'integer') -:set_defaults{keyword='', page=1} -:register(function(player, keyword, page) - local player_index = player and player.index or 0 - -- if keyword is a number then treat it as page number - if tonumber(keyword) then - page = math.floor(tonumber(keyword)) - keyword = '' - end +Commands.new_command("search-help", { "expcom-chelp.description" }, "Searches for a keyword in all commands you are allowed to use.") + :add_alias("chelp", "shelp", "commands") + :add_param("keyword", true) + :add_param("page", true, "integer") + :set_defaults{ keyword = "", page = 1 } + :register(function(player, keyword, page) + local player_index = player and player.index or 0 + -- if keyword is a number then treat it as page number + if tonumber(keyword) then + page = math.floor(tonumber(keyword)) + keyword = "" + end - -- gets a value for pages, might have result in cache - local pages - local found = 0 + -- gets a value for pages, might have result in cache + local pages + local found = 0 - if search_cache[player_index] and search_cache[player_index].keyword == keyword:lower() then - pages = search_cache[player_index].pages - found = search_cache[player_index].found - - else - pages = {{}} - local current_page = 1 - local page_count = 0 - local commands = Commands.search(keyword, player) - -- loops other all commands returned by search, includes game commands - for _, command_data in pairs(commands) do - -- if the number of results if greater than the number already added then it moves onto a new page - if page_count >= results_per_page then - page_count = 0 - current_page = current_page + 1 - table.insert(pages, {}) + if search_cache[player_index] and search_cache[player_index].keyword == keyword:lower() then + pages = search_cache[player_index].pages + found = search_cache[player_index].found + else + pages = { {} } + local current_page = 1 + local page_count = 0 + local commands = Commands.search(keyword, player) + -- loops other all commands returned by search, includes game commands + for _, command_data in pairs(commands) do + -- if the number of results if greater than the number already added then it moves onto a new page + if page_count >= results_per_page then + page_count = 0 + current_page = current_page + 1 + table.insert(pages, {}) + end + -- adds the new command to the page + page_count = page_count + 1 + found = found + 1 + local alias_format = #command_data.aliases > 0 and { "expcom-chelp.alias", table.concat(command_data.aliases, ", ") } or "" + table.insert(pages[current_page], { + "expcom-chelp.format", + command_data.name, + command_data.description, + command_data.help, + alias_format, + }) end - -- adds the new command to the page - page_count = page_count + 1 - found = found + 1 - local alias_format = #command_data.aliases > 0 and {'expcom-chelp.alias', table.concat(command_data.aliases, ', ')} or '' - table.insert(pages[current_page], { - 'expcom-chelp.format', - command_data.name, - command_data.description, - command_data.help, - alias_format - }) - end - -- adds the result to the cache - search_cache[player_index] = { - keyword=keyword:lower(), - pages=pages, - found=found - } - end - -- print the requested page - keyword = keyword == '' and '' or keyword - Commands.print({'expcom-chelp.title', keyword}, 'cyan') - - if pages[page] then - for _, command in pairs(pages[page]) do - Commands.print(command) + -- adds the result to the cache + search_cache[player_index] = { + keyword = keyword:lower(), + pages = pages, + found = found, + } end - Commands.print({'expcom-chelp.footer', found, page, #pages}, 'cyan') + -- print the requested page + keyword = keyword == "" and "" or keyword + Commands.print({ "expcom-chelp.title", keyword }, "cyan") - else - Commands.print({'expcom-chelp.footer', found, page, #pages}, 'cyan') - return Commands.error{'expcom-chelp.out-of-range', page} - end - -- blocks command complete message - return Commands.success -end) + if pages[page] then + for _, command in pairs(pages[page]) do + Commands.print(command) + end + + Commands.print({ "expcom-chelp.footer", found, page, #pages }, "cyan") + else + Commands.print({ "expcom-chelp.footer", found, page, #pages }, "cyan") + return Commands.error{ "expcom-chelp.out-of-range", page } + end + -- blocks command complete message + return Commands.success + end) -- way to access global return search_cache diff --git a/exp_legacy/module/modules/commands/home.lua b/exp_legacy/module/modules/commands/home.lua index 621783cf..f34567a4 100644 --- a/exp_legacy/module/modules/commands/home.lua +++ b/exp_legacy/module/modules/commands/home.lua @@ -14,7 +14,7 @@ end) local function teleport(player, position) local surface = player.surface - local pos = surface.find_non_colliding_position('character', position, 32, 1) + local pos = surface.find_non_colliding_position("character", position, 32, 1) if not position then return false end if player.driving then player.driving = false end -- kicks a player out a vehicle if in one player.teleport(pos, surface) @@ -23,61 +23,61 @@ end local function floor_pos(position) return { - x=math.floor(position.x), - y=math.floor(position.y) + x = math.floor(position.x), + y = math.floor(position.y), } end --- Teleports you to your home location -- @command home -Commands.new_command('home', {'expcom-home.description-home'}, 'Teleports you to your home location') -:register(function(player) - local home = homes[player.index] - if not home or not home[1] then - return Commands.error{'expcom-home.no-home'} - end - local rtn = floor_pos(player.position) - teleport(player, home[1]) - home[2] = rtn - Commands.print{'expcom-home.return-set', rtn.x, rtn.y} -end) +Commands.new_command("home", { "expcom-home.description-home" }, "Teleports you to your home location") + :register(function(player) + local home = homes[player.index] + if not home or not home[1] then + return Commands.error{ "expcom-home.no-home" } + end + local rtn = floor_pos(player.position) + teleport(player, home[1]) + home[2] = rtn + Commands.print{ "expcom-home.return-set", rtn.x, rtn.y } + end) --- Sets your home location to your current position -- @command home-set -Commands.new_command('home-set', {'expcom-home.description-home-set'}, 'Sets your home location to your current position') -:register(function(player) - local home = homes[player.index] - if not home then - home = {} - homes[player.index] = home - end - local pos = floor_pos(player.position) - home[1] = pos - Commands.print{'expcom-home.home-set', pos.x, pos.y} -end) +Commands.new_command("home-set", { "expcom-home.description-home-set" }, "Sets your home location to your current position") + :register(function(player) + local home = homes[player.index] + if not home then + home = {} + homes[player.index] = home + end + local pos = floor_pos(player.position) + home[1] = pos + Commands.print{ "expcom-home.home-set", pos.x, pos.y } + end) --- Returns your current home location -- @command home-get -Commands.new_command('home-get', {'expcom-home.description-home-get'}, 'Returns your current home location') -:register(function(player) - local home = homes[player.index] - if not home or not home[1] then - return Commands.error{'expcom-home.no-home'} - end - local pos = home[1] - Commands.print{'expcom-home.home-get', pos.x, pos.y} -end) +Commands.new_command("home-get", { "expcom-home.description-home-get" }, "Returns your current home location") + :register(function(player) + local home = homes[player.index] + if not home or not home[1] then + return Commands.error{ "expcom-home.no-home" } + end + local pos = home[1] + Commands.print{ "expcom-home.home-get", pos.x, pos.y } + end) --- Teleports you to previous location -- @command return -Commands.new_command('return', {'expcom-home.description-return'}, 'Teleports you to previous location') -:register(function(player) - local home = homes[player.index] - if not home or not home[2] then - return Commands.error{'expcom-home.no-return'} - end - local rtn = floor_pos(player.position) - teleport(player, home[2]) - home[2] = rtn - Commands.print{'expcom-home.return-set', rtn.x, rtn.y} -end) +Commands.new_command("return", { "expcom-home.description-return" }, "Teleports you to previous location") + :register(function(player) + local home = homes[player.index] + if not home or not home[2] then + return Commands.error{ "expcom-home.no-return" } + end + local rtn = floor_pos(player.position) + teleport(player, home[2]) + home[2] = rtn + Commands.print{ "expcom-home.return-set", rtn.x, rtn.y } + end) diff --git a/exp_legacy/module/modules/commands/interface.lua b/exp_legacy/module/modules/commands/interface.lua index 552ab763..7b3ecafb 100644 --- a/exp_legacy/module/modules/commands/interface.lua +++ b/exp_legacy/module/modules/commands/interface.lua @@ -8,18 +8,18 @@ local Storage = require("modules/exp_util/storage") -- modules that are loaded into the interface env to be accessed local interface_modules = { - ['Commands'] = Commands, - ['output'] = _C.player_return, - ['Group'] = 'expcore.permission_groups', - ['Roles'] = 'expcore.roles', - ['Gui'] = 'expcore.gui', - ['Datastore'] = 'expcore.datastore', - ['External'] = 'expcore.external' + ["Commands"] = Commands, + ["output"] = _C.player_return, + ["Group"] = "expcore.permission_groups", + ["Roles"] = "expcore.roles", + ["Gui"] = "expcore.gui", + ["Datastore"] = "expcore.datastore", + ["External"] = "expcore.external", } -- loads all the modules given in the above table for key, value in pairs(interface_modules) do - if type(value) == 'string' then + if type(value) == "string" then interface_modules[key] = _C.opt_require(value) end end @@ -42,7 +42,7 @@ end -- @tparam string name The name that the value is assigned to -- @tparam function callback The function that will be called to get the value local function add_interface_callback(name, callback) - if type(callback) == 'function' then + if type(callback) == "function" then interface_callbacks[name] = callback end end @@ -61,55 +61,55 @@ end --- Sends an invocation to be ran and returns the result. -- @command interface -- @tparam string invocation the command that will be run -Commands.new_command('interface', {'expcom-interface.description'}, 'Sends an invocation to be ran and returns the result.') -:add_param('invocation', false) -:enable_auto_concat() -:set_flag('admin_only') -:register(function(player, invocation) - -- If the invocation has no white space then prepend return to it - if not invocation:find('%s') and not invocation:find('return') then - invocation = 'return '..invocation - end - - -- _env will be the new _ENV that the invocation will run inside of - local _env = setmetatable({}, { - __index = get_index, - __newindex = interface_env - }) - - -- If the command is ran by a player then load the dynamic values - if player then - for name, callback in pairs(interface_callbacks) do - local _, rtn = pcall(callback, player) - rawset(_env, name, rtn) +Commands.new_command("interface", { "expcom-interface.description" }, "Sends an invocation to be ran and returns the result.") + :add_param("invocation", false) + :enable_auto_concat() + :set_flag("admin_only") + :register(function(player, invocation) + -- If the invocation has no white space then prepend return to it + if not invocation:find("%s") and not invocation:find("return") then + invocation = "return " .. invocation end - end - -- Compile the invocation with the custom _env value - local invocation_func, compile_error = load(invocation, 'interface', nil, _env) - if compile_error then return Commands.error(compile_error) end + -- _env will be the new _ENV that the invocation will run inside of + local _env = setmetatable({}, { + __index = get_index, + __newindex = interface_env, + }) - -- Run the invocation - local success, rtn = pcall(invocation_func) - if not success then - local err = rtn:gsub('%.%.%..-/temp/currently%-playing', '') - return Commands.error(err) - end - return Commands.success(rtn) -end) + -- If the command is ran by a player then load the dynamic values + if player then + for name, callback in pairs(interface_callbacks) do + local _, rtn = pcall(callback, player) + rawset(_env, name, rtn) + end + end + + -- Compile the invocation with the custom _env value + local invocation_func, compile_error = load(invocation, "interface", nil, _env) + if compile_error then return Commands.error(compile_error) end + + -- Run the invocation + local success, rtn = pcall(invocation_func) + if not success then + local err = rtn:gsub("%.%.%..-/temp/currently%-playing", "") + return Commands.error(err) + end + return Commands.success(rtn) + end) -- Adds some basic callbacks for the interface -add_interface_callback('player', function(player) return player end) -add_interface_callback('surface', function(player) return player.surface end) -add_interface_callback('force', function(player) return player.force end) -add_interface_callback('position', function(player) return player.position end) -add_interface_callback('entity', function(player) return player.selected end) -add_interface_callback('tile', function(player) return player.surface.get_tile(player.position) end) +add_interface_callback("player", function(player) return player end) +add_interface_callback("surface", function(player) return player.surface end) +add_interface_callback("force", function(player) return player.force end) +add_interface_callback("position", function(player) return player.position end) +add_interface_callback("entity", function(player) return player.selected end) +add_interface_callback("tile", function(player) return player.surface.get_tile(player.position) end) -- Module Return return { add_interface_module = add_interface_module, add_interface_callback = add_interface_callback, interface_env = interface_env, - clean_stack_trace = function(str) return str:gsub('%.%.%..-/temp/currently%-playing', '') end + clean_stack_trace = function(str) return str:gsub("%.%.%..-/temp/currently%-playing", "") end, } diff --git a/exp_legacy/module/modules/commands/jail.lua b/exp_legacy/module/modules/commands/jail.lua index 7a9a0444..bacd2efb 100644 --- a/exp_legacy/module/modules/commands/jail.lua +++ b/exp_legacy/module/modules/commands/jail.lua @@ -12,36 +12,36 @@ require("modules.exp_legacy.config.expcore.command_role_parse") -- @command jail -- @tparam LuaPlayer player the player that will be jailed -- @tparam[opt] string reason the reason why the player is being jailed -Commands.new_command('jail', {'expcom-jail.description-jail'}, 'Puts a player into jail and removes all other roles.') -:add_param('player', false, 'player-role') -:add_param('reason', true) -:enable_auto_concat() -:register(function(player, action_player, reason) - reason = reason or 'Non Given.' - local action_player_name_color = format_chat_player_name(action_player) - local by_player_name_color = format_chat_player_name(player) - local player_name = player and player.name or '' - if Jail.jail_player(action_player, player_name, reason) then - game.print{'expcom-jail.give', action_player_name_color, by_player_name_color, reason} - else - return Commands.error{'expcom-jail.already-jailed', action_player_name_color} - end -end) +Commands.new_command("jail", { "expcom-jail.description-jail" }, "Puts a player into jail and removes all other roles.") + :add_param("player", false, "player-role") + :add_param("reason", true) + :enable_auto_concat() + :register(function(player, action_player, reason) + reason = reason or "Non Given." + local action_player_name_color = format_chat_player_name(action_player) + local by_player_name_color = format_chat_player_name(player) + local player_name = player and player.name or "" + if Jail.jail_player(action_player, player_name, reason) then + game.print{ "expcom-jail.give", action_player_name_color, by_player_name_color, reason } + else + return Commands.error{ "expcom-jail.already-jailed", action_player_name_color } + end + end) --- Removes a player from jail. -- @command unjail -- @tparam LuaPlayer the player that will be unjailed -Commands.new_command('unjail', {'expcom-jail.description-unjail'}, 'Removes a player from jail.') -:add_param('player', false, 'player-role') -:add_alias('clear-jail', 'remove-jail') -:enable_auto_concat() -:register(function(player, action_player) - local action_player_name_color = format_chat_player_name(action_player) - local by_player_name_color = format_chat_player_name(player) - local player_name = player and player.name or '' - if Jail.unjail_player(action_player, player_name) then - game.print{'expcom-jail.remove', action_player_name_color, by_player_name_color} - else - return Commands.error{'expcom-jail.not-jailed', action_player_name_color} - end -end) +Commands.new_command("unjail", { "expcom-jail.description-unjail" }, "Removes a player from jail.") + :add_param("player", false, "player-role") + :add_alias("clear-jail", "remove-jail") + :enable_auto_concat() + :register(function(player, action_player) + local action_player_name_color = format_chat_player_name(action_player) + local by_player_name_color = format_chat_player_name(player) + local player_name = player and player.name or "" + if Jail.unjail_player(action_player, player_name) then + game.print{ "expcom-jail.remove", action_player_name_color, by_player_name_color } + else + return Commands.error{ "expcom-jail.not-jailed", action_player_name_color } + end + end) diff --git a/exp_legacy/module/modules/commands/kill.lua b/exp_legacy/module/modules/commands/kill.lua index c948c124..b5892fcc 100644 --- a/exp_legacy/module/modules/commands/kill.lua +++ b/exp_legacy/module/modules/commands/kill.lua @@ -11,26 +11,24 @@ require("modules.exp_legacy.config.expcore.command_role_parse") --- Kills yourself or another player. -- @command kill -- @tparam[opt=self] LuaPlayer player the player to kill, must be alive to be valid -Commands.new_command('kill', {'expcom-kill.description'}, 'Kills yourself or another player.') -:add_param('player', true, 'player-role-alive') -:set_defaults{player=function(player) - -- default is the player unless they are dead - if player.character and player.character.health > 0 then - return player - end -end} -:register(function(player, action_player) - if not action_player then - -- can only be nil if no player given and the user is dead - return Commands.error{'expcom-kill.already-dead'} - end - if player == action_player then - action_player.character.die() - - elseif Roles.player_allowed(player, 'command/kill/always') then - action_player.character.die() - - else - return Commands.error{'expcore-commands.unauthorized'} - end -end) +Commands.new_command("kill", { "expcom-kill.description" }, "Kills yourself or another player.") + :add_param("player", true, "player-role-alive") + :set_defaults{ player = function(player) + -- default is the player unless they are dead + if player.character and player.character.health > 0 then + return player + end + end } + :register(function(player, action_player) + if not action_player then + -- can only be nil if no player given and the user is dead + return Commands.error{ "expcom-kill.already-dead" } + end + if player == action_player then + action_player.character.die() + elseif Roles.player_allowed(player, "command/kill/always") then + action_player.character.die() + else + return Commands.error{ "expcore-commands.unauthorized" } + end + end) diff --git a/exp_legacy/module/modules/commands/last-location.lua b/exp_legacy/module/modules/commands/last-location.lua index 1b840d14..26fb8d91 100644 --- a/exp_legacy/module/modules/commands/last-location.lua +++ b/exp_legacy/module/modules/commands/last-location.lua @@ -10,10 +10,10 @@ require("modules.exp_legacy.config.expcore.command_general_parse") --- Get the last location of a player. -- @command last-location -- @tparam LuaPlayer player the player that you want a location of -Commands.new_command('last-location', {'expcom-lastlocation.description'}, 'Sends you the last location of a player') -:add_alias('location') -:add_param('player', false, 'player') -:register(function(_, action_player) - local action_player_name_color = format_chat_player_name(action_player) - return Commands.success{'expcom-lastlocation.response', action_player_name_color, string.format('%.1f', action_player.position.x), string.format('%.1f', action_player.position.y)} -end) +Commands.new_command("last-location", { "expcom-lastlocation.description" }, "Sends you the last location of a player") + :add_alias("location") + :add_param("player", false, "player") + :register(function(_, action_player) + local action_player_name_color = format_chat_player_name(action_player) + return Commands.success{ "expcom-lastlocation.response", action_player_name_color, string.format("%.1f", action_player.position.x), string.format("%.1f", action_player.position.y) } + end) diff --git a/exp_legacy/module/modules/commands/me.lua b/exp_legacy/module/modules/commands/me.lua index 899ee663..b2591f6a 100644 --- a/exp_legacy/module/modules/commands/me.lua +++ b/exp_legacy/module/modules/commands/me.lua @@ -8,10 +8,10 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore --- Sends an action message in the chat -- @command me -- @tparam string action the action that follows your name in chat -Commands.new_command('me', {'expcom-me.description'}, 'Sends an action message in the chat') -:add_param('action', false) -:enable_auto_concat() -:register(function(player, action) - local player_name = player and player.name or '' - game.print(string.format('* %s %s *', player_name, action), player.chat_color) -end) +Commands.new_command("me", { "expcom-me.description" }, "Sends an action message in the chat") + :add_param("action", false) + :enable_auto_concat() + :register(function(player, action) + local player_name = player and player.name or "" + game.print(string.format("* %s %s *", player_name, action), player.chat_color) + end) diff --git a/exp_legacy/module/modules/commands/pollution.lua b/exp_legacy/module/modules/commands/pollution.lua index c1f2f95b..a968f179 100644 --- a/exp_legacy/module/modules/commands/pollution.lua +++ b/exp_legacy/module/modules/commands/pollution.lua @@ -6,29 +6,29 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") -Commands.new_command('pollution-clear', {'expcom-pol.description-clr'}, 'Clear pollution') -:set_flag('admin_only') -:add_alias('pol-clr') -:add_param('surface', true, 'surface') -:set_defaults{surface=function(player) - return player.surface -end} -:register(function(player, surface) - surface.clear_pollution() - game.print{'expcom-pol.clr', player.name} - return Commands.success -end) +Commands.new_command("pollution-clear", { "expcom-pol.description-clr" }, "Clear pollution") + :set_flag("admin_only") + :add_alias("pol-clr") + :add_param("surface", true, "surface") + :set_defaults{ surface = function(player) + return player.surface + end } + :register(function(player, surface) + surface.clear_pollution() + game.print{ "expcom-pol.clr", player.name } + return Commands.success + end) -Commands.new_command('pollution-off', {'expcom-pol.description-off'}, 'Disable pollution') -:set_flag('admin_only') -:add_alias('pol-off') -:register(function(player) - game.map_settings.pollution.enabled = false +Commands.new_command("pollution-off", { "expcom-pol.description-off" }, "Disable pollution") + :set_flag("admin_only") + :add_alias("pol-off") + :register(function(player) + game.map_settings.pollution.enabled = false - for _, v in pairs(game.surfaces) do - v.clear_pollution() - end + for _, v in pairs(game.surfaces) do + v.clear_pollution() + end - game.print{'expcom-pol.off', player.name} - return Commands.success -end) + game.print{ "expcom-pol.off", player.name } + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/protection.lua b/exp_legacy/module/modules/commands/protection.lua index 7ac2a66a..78127b2e 100644 --- a/exp_legacy/module/modules/commands/protection.lua +++ b/exp_legacy/module/modules/commands/protection.lua @@ -11,12 +11,12 @@ local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.comm local EntityProtection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection -local SelectionProtectEntity = 'ProtectEntity' -local SelectionProtectArea = 'ProtectArea' +local SelectionProtectEntity = "ProtectEntity" +local SelectionProtectArea = "ProtectArea" local renders = {} -- Stores all renders for a player Storage.register({ - renders = renders + renders = renders, }, function(tbl) renders = tbl.renders end) @@ -36,19 +36,19 @@ end --- Align an aabb to the grid by expanding it local function aabb_align_expand(aabb) return { - left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)}, - right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)} + left_top = { x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y) }, + right_bottom = { x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y) }, } end --- Get the key used in protected_entities local function get_entity_key(entity) - return string.format('%i,%i', math.floor(entity.position.x), math.floor(entity.position.y)) + return string.format("%i,%i", math.floor(entity.position.x), math.floor(entity.position.y)) end --- Get the key used in protected_areas local function get_area_key(area) - return string.format('%i,%i', math.floor(area.left_top.x), math.floor(area.left_top.y)) + return string.format("%i,%i", math.floor(area.left_top.x), math.floor(area.left_top.y)) end --- Show a protected entity to a player @@ -57,16 +57,16 @@ local function show_protected_entity(player, entity) if renders[player.index][key] then return end local rb = entity.selection_box.right_bottom local render_id = rendering.draw_sprite{ - sprite = 'utility/notification', + sprite = "utility/notification", target = entity, target_offset = { - (rb.x-entity.position.x)*0.75, - (rb.y-entity.position.y)*0.75 + (rb.x - entity.position.x) * 0.75, + (rb.y - entity.position.y) * 0.75, }, x_scale = 2, y_scale = 2, surface = entity.surface, - players = { player } + players = { player }, } renders[player.index][key] = render_id end @@ -76,13 +76,13 @@ local function show_protected_area(player, surface, area) local key = get_area_key(area) if renders[player.index][key] then return end local render_id = rendering.draw_rectangle{ - color = {1, 1, 0, 0.5}, + color = { 1, 1, 0, 0.5 }, filled = false, width = 3, left_top = area.left_top, right_bottom = area.right_bottom, surface = surface, - players = { player } + players = { player }, } renders[player.index][key] = render_id end @@ -96,29 +96,29 @@ end --- Toggles entity protection selection -- @command protect-entity -Commands.new_command('protect-entity', {'expcom-protection.description-pe'}, 'Toggles entity protection selection, hold shift to remove protection') -:add_alias('pe') -:register(function(player) - if Selection.is_selecting(player, SelectionProtectEntity) then - Selection.stop(player) - else - Selection.start(player, SelectionProtectEntity) - return Commands.success{'expcom-protection.entered-entity-selection'} - end -end) +Commands.new_command("protect-entity", { "expcom-protection.description-pe" }, "Toggles entity protection selection, hold shift to remove protection") + :add_alias("pe") + :register(function(player) + if Selection.is_selecting(player, SelectionProtectEntity) then + Selection.stop(player) + else + Selection.start(player, SelectionProtectEntity) + return Commands.success{ "expcom-protection.entered-entity-selection" } + end + end) --- Toggles area protection selection -- @command protect-area -Commands.new_command('protect-area', {'expcom-protection.description-pa'}, 'Toggles area protection selection, hold shift to remove protection') -:add_alias('pa') -:register(function(player) - if Selection.is_selecting(player, SelectionProtectArea) then - Selection.stop(player) - else - Selection.start(player, SelectionProtectArea) - return Commands.success{'expcom-protection.entered-area-selection'} - end -end) +Commands.new_command("protect-area", { "expcom-protection.description-pa" }, "Toggles area protection selection, hold shift to remove protection") + :add_alias("pa") + :register(function(player) + if Selection.is_selecting(player, SelectionProtectArea) then + Selection.stop(player) + else + Selection.start(player, SelectionProtectArea) + return Commands.success{ "expcom-protection.entered-area-selection" } + end + end) --- When an area is selected to add protection to entities Selection.on_selection(SelectionProtectEntity, function(event) @@ -127,7 +127,8 @@ Selection.on_selection(SelectionProtectEntity, function(event) EntityProtection.add_entity(entity) show_protected_entity(player, entity) end - player.print{'expcom-protection.protected-entities', #event.entities} + + player.print{ "expcom-protection.protected-entities", #event.entities } end) --- When an area is selected to remove protection from entities @@ -137,7 +138,8 @@ Selection.on_alt_selection(SelectionProtectEntity, function(event) EntityProtection.remove_entity(entity) remove_render(player, get_entity_key(entity)) end - player.print{'expcom-protection.unprotected-entities', #event.entities} + + player.print{ "expcom-protection.unprotected-entities", #event.entities } end) --- When an area is selected to add protection to the area @@ -147,12 +149,13 @@ Selection.on_selection(SelectionProtectArea, function(event) local player = game.get_player(event.player_index) for _, next_area in pairs(areas) do if aabb_area_enclosed(area, next_area) then - return player.print{'expcom-protection.already-protected'} + return player.print{ "expcom-protection.already-protected" } end end + EntityProtection.add_area(event.surface, area) show_protected_area(player, event.surface, area) - player.print{'expcom-protection.protected-area'} + player.print{ "expcom-protection.protected-area" } end) --- When an area is selected to remove protection from the area @@ -163,7 +166,7 @@ Selection.on_alt_selection(SelectionProtectArea, function(event) for _, next_area in pairs(areas) do if aabb_area_enclosed(next_area, area) then EntityProtection.remove_area(event.surface, next_area) - player.print{'expcom-protection.unprotected-area'} + player.print{ "expcom-protection.unprotected-area" } remove_render(player, get_area_key(next_area)) end end @@ -180,6 +183,7 @@ Event.add(Selection.events.on_player_selection_start, function(event) for _, entity in pairs(entities) do show_protected_entity(player, entity) end + -- Show always protected entities by name if #EntityProtection.protected_entity_names > 0 then for _, entity in pairs(surface.find_entities_filtered{ name = EntityProtection.protected_entity_names, force = player.force }) do @@ -205,11 +209,12 @@ Event.add(Selection.events.on_player_selection_end, function(event) for _, id in pairs(renders[event.player_index]) do if rendering.is_valid(id) then rendering.destroy(id) end end + renders[event.player_index] = nil end) --- When there is a repeat offence print it in chat Event.add(EntityProtection.events.on_repeat_violation, function(event) local player_name = format_chat_player_name(event.player_index) - Roles.print_to_roles_higher('Regular', {'expcom-protection.repeat-offence', player_name, event.entity.localised_name, event.entity.position.x, event.entity.position.y}) + Roles.print_to_roles_higher("Regular", { "expcom-protection.repeat-offence", player_name, event.entity.localised_name, event.entity.position.x, event.entity.position.y }) end) diff --git a/exp_legacy/module/modules/commands/rainbow.lua b/exp_legacy/module/modules/commands/rainbow.lua index b53d3e30..7fd81dfd 100644 --- a/exp_legacy/module/modules/commands/rainbow.lua +++ b/exp_legacy/module/modules/commands/rainbow.lua @@ -8,9 +8,9 @@ local format_chat_colour = _C.format_chat_colour --- @dep expcore.common local function step_component(c1, c2) if c1 < 0 then - return 0, c2+c1 + return 0, c2 + c1 elseif c1 > 1 then - return 1, c2-c1+1 + return 1, c2 - c1 + 1 else return c1, c2 end @@ -25,17 +25,17 @@ local function step_color(color) end local function next_color(color, step) - step = step or 0.1 - local new_color = {r=0, g=0, b=0} + step = step or 0.1 + local new_color = { r = 0, g = 0, b = 0 } if color.b == 0 and color.r ~= 0 then - new_color.r = color.r-step - new_color.g = color.g+step + new_color.r = color.r - step + new_color.g = color.g + step elseif color.r == 0 and color.g ~= 0 then - new_color.g = color.g-step - new_color.b = color.b+step + new_color.g = color.g - step + new_color.b = color.b + step elseif color.g == 0 and color.b ~= 0 then - new_color.b = color.b-step - new_color.r = color.r+step + new_color.b = color.b - step + new_color.r = color.r + step end return step_color(new_color) end @@ -43,20 +43,20 @@ end --- Sends an rainbow message in the chat -- @command rainbow -- @tparam string message the message that will be printed in chat -Commands.new_command('rainbow', {'expcom-rainbow.description'}, 'Sends an rainbow message in the chat') -:add_param('message', false) -:enable_auto_concat() -:register(function(player, message) - local player_name = player and player.name or '' - local player_color = player and player.color or nil - local color_step = 3/message:len() - if color_step > 1 then color_step = 1 end - local current_color = {r=1, g=0, b=0} - local output = format_chat_colour(player_name..': ', player_color) - output = output..message:gsub('%S', function(letter) - local rtn = format_chat_colour(letter, current_color) - current_color = next_color(current_color, color_step) - return rtn +Commands.new_command("rainbow", { "expcom-rainbow.description" }, "Sends an rainbow message in the chat") + :add_param("message", false) + :enable_auto_concat() + :register(function(player, message) + local player_name = player and player.name or "" + local player_color = player and player.color or nil + local color_step = 3 / message:len() + if color_step > 1 then color_step = 1 end + local current_color = { r = 1, g = 0, b = 0 } + local output = format_chat_colour(player_name .. ": ", player_color) + output = output .. message:gsub("%S", function(letter) + local rtn = format_chat_colour(letter, current_color) + current_color = next_color(current_color, color_step) + return rtn + end) + game.print(output) end) - game.print(output) -end) diff --git a/exp_legacy/module/modules/commands/ratio.lua b/exp_legacy/module/modules/commands/ratio.lua index dffbe2dd..dc63dfa6 100644 --- a/exp_legacy/module/modules/commands/ratio.lua +++ b/exp_legacy/module/modules/commands/ratio.lua @@ -1,86 +1,83 @@ - - local Commands = require("modules.exp_legacy.expcore.commands") local function Modules(moduleInventory) -- returns the multiplier of the modules local effect1 = moduleInventory.get_item_count("productivity-module") -- type 1 - local effect2 = moduleInventory.get_item_count("productivity-module-2")-- type 2 + local effect2 = moduleInventory.get_item_count("productivity-module-2") -- type 2 local effect3 = moduleInventory.get_item_count("productivity-module-3") -- type 3 - local multi = effect1*4+effect2*6+effect3*10 - return multi/100+1 + local multi = effect1 * 4 + effect2 * 6 + effect3 * 10 + return multi / 100 + 1 end local function AmountOfMachines(itemsPerSecond, output) - if(itemsPerSecond) then - return itemsPerSecond/output + if (itemsPerSecond) then + return itemsPerSecond / output end end -Commands.new_command('ratio', {'expcom-ratio.description'}, 'This command will give the input and output ratios of the selected machine. Use the parameter for calculating the machines needed for that amount of items per second.') -:add_param('itemsPerSecond', true, 'number') -:register(function(player, itemsPerSecond) - local machine = player.selected -- selected machine +Commands.new_command("ratio", { "expcom-ratio.description" }, + "This command will give the input and output ratios of the selected machine. Use the parameter for calculating the machines needed for that amount of items per second.") + :add_param("itemsPerSecond", true, "number") + :register(function(player, itemsPerSecond) + local machine = player.selected -- selected machine - if not machine then --nil check - return Commands.error{'expcom-ratio.notSelecting'} - end - - if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then - return Commands.error{'expcom-ratio.notSelecting'} - end - - local recipe = machine.get_recipe() -- recipe - - if not recipe then --nil check - return Commands.error{'expcom-ratio.notSelecting'} - end - - local items = recipe.ingredients -- items in that recipe - local products = recipe.products -- output items - local amountOfMachines - local moduleInventory = machine.get_module_inventory()--the module Inventory of the machine - local multi = Modules(moduleInventory) --function for the productively modals - - if itemsPerSecond then - amountOfMachines = math.ceil( AmountOfMachines(itemsPerSecond, 1/recipe.energy*machine.crafting_speed*products[1].amount*multi)) -- amount of machines - end - - if not amountOfMachines then - amountOfMachines = 1 --set to 1 to make it not nil - end - - ----------------------------items---------------------------- - for i, item in ipairs(items) do - local sprite -- string to make the icon work either fluid ore item - - if item.type == "item" then - sprite = 'expcom-ratio.item-in' - - else - sprite = 'expcom-ratio.fluid-in' + if not machine then -- nil check + return Commands.error{ "expcom-ratio.notSelecting" } end - local ips = item.amount/recipe.energy*machine.crafting_speed*amountOfMachines --math on the items/fluids per second - Commands.print{sprite, math.round(ips, 3), item.name} -- full string - end - - ----------------------------products---------------------------- - for i, product in ipairs(products) do - local sprite -- string to make the icon work either fluid ore item - - if product.type == "item" then - sprite = 'expcom-ratio.item-out' - else - sprite = 'expcom-ratio.fluid-out' + if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then + return Commands.error{ "expcom-ratio.notSelecting" } end - local output = 1/recipe.energy*machine.crafting_speed*product.amount*multi --math on the outputs per second - Commands.print {sprite, math.round(output*amountOfMachines, 3), product.name} -- full string + local recipe = machine.get_recipe() -- recipe - end + if not recipe then -- nil check + return Commands.error{ "expcom-ratio.notSelecting" } + end - if amountOfMachines ~= 1 then - Commands.print{'expcom-ratio.machines', amountOfMachines} - end -end) + local items = recipe.ingredients -- items in that recipe + local products = recipe.products -- output items + local amountOfMachines + local moduleInventory = machine.get_module_inventory() -- the module Inventory of the machine + local multi = Modules(moduleInventory) -- function for the productively modals + + if itemsPerSecond then + amountOfMachines = math.ceil(AmountOfMachines(itemsPerSecond, 1 / recipe.energy * machine.crafting_speed * products[1].amount * multi)) -- amount of machines + end + + if not amountOfMachines then + amountOfMachines = 1 -- set to 1 to make it not nil + end + + ----------------------------items---------------------------- + for i, item in ipairs(items) do + local sprite -- string to make the icon work either fluid ore item + + if item.type == "item" then + sprite = "expcom-ratio.item-in" + else + sprite = "expcom-ratio.fluid-in" + end + + local ips = item.amount / recipe.energy * machine.crafting_speed * amountOfMachines -- math on the items/fluids per second + Commands.print{ sprite, math.round(ips, 3), item.name } -- full string + end + + ----------------------------products---------------------------- + for i, product in ipairs(products) do + local sprite -- string to make the icon work either fluid ore item + + if product.type == "item" then + sprite = "expcom-ratio.item-out" + else + sprite = "expcom-ratio.fluid-out" + end + + local output = 1 / recipe.energy * machine.crafting_speed * product.amount * multi -- math on the outputs per second + Commands.print{ sprite, math.round(output * amountOfMachines, 3), product.name } -- full string + end + + if amountOfMachines ~= 1 then + Commands.print{ "expcom-ratio.machines", amountOfMachines } + end + end) diff --git a/exp_legacy/module/modules/commands/repair.lua b/exp_legacy/module/modules/commands/repair.lua index ee61300d..b3c15f96 100644 --- a/exp_legacy/module/modules/commands/repair.lua +++ b/exp_legacy/module/modules/commands/repair.lua @@ -11,42 +11,42 @@ local max_time_to_live = 4294967295 -- unit32 max --- Repairs entities on your force around you -- @command repair -- @tparam number range the range to repair stuff in, there is a max limit to this -Commands.new_command('repair', {'expcom-repair.description'}, 'Repairs entities on your force around you') -:add_param('range', false, 'integer-range', 1, config.max_range) -:register(function(player, range) - local revive_count = 0 - local heal_count = 0 - local range2 = range^2 - local surface = player.surface - local center = player.position - local area = {{x=center.x-range, y=center.y-range}, {x=center.x+range, y=center.y+range}} - if config.allow_ghost_revive then - local ghosts = surface.find_entities_filtered({area=area, type='entity-ghost', force=player.force}) - for _, ghost in pairs(ghosts) do - if ghost.valid then - local x = ghost.position.x-center.x - local y = ghost.position.y-center.y - if x^2+y^2 <= range2 then - if config.allow_blueprint_repair or ghost.time_to_live ~= max_time_to_live then - revive_count = revive_count+1 - if not config.disallow[ghost.ghost_name] then ghost.revive() end +Commands.new_command("repair", { "expcom-repair.description" }, "Repairs entities on your force around you") + :add_param("range", false, "integer-range", 1, config.max_range) + :register(function(player, range) + local revive_count = 0 + local heal_count = 0 + local range2 = range ^ 2 + local surface = player.surface + local center = player.position + local area = { { x = center.x - range, y = center.y - range }, { x = center.x + range, y = center.y + range } } + if config.allow_ghost_revive then + local ghosts = surface.find_entities_filtered{ area = area, type = "entity-ghost", force = player.force } + for _, ghost in pairs(ghosts) do + if ghost.valid then + local x = ghost.position.x - center.x + local y = ghost.position.y - center.y + if x ^ 2 + y ^ 2 <= range2 then + if config.allow_blueprint_repair or ghost.time_to_live ~= max_time_to_live then + revive_count = revive_count + 1 + if not config.disallow[ghost.ghost_name] then ghost.revive() end + end end end end end - end - if config.allow_heal_entities then - local entities = surface.find_entities_filtered({area=area, force=player.force}) - for _, entity in pairs(entities) do - if entity.valid then - local x = entity.position.x-center.x - local y = entity.position.y-center.y - if entity.health and entity.get_health_ratio() ~= 1 and x^2+y^2 <= range2 then - heal_count = heal_count+1 - entity.health = max_time_to_live + if config.allow_heal_entities then + local entities = surface.find_entities_filtered{ area = area, force = player.force } + for _, entity in pairs(entities) do + if entity.valid then + local x = entity.position.x - center.x + local y = entity.position.y - center.y + if entity.health and entity.get_health_ratio() ~= 1 and x ^ 2 + y ^ 2 <= range2 then + heal_count = heal_count + 1 + entity.health = max_time_to_live + end end end end - end - return Commands.success{'expcom-repair.result', revive_count, heal_count} -end) + return Commands.success{ "expcom-repair.result", revive_count, heal_count } + end) diff --git a/exp_legacy/module/modules/commands/reports.lua b/exp_legacy/module/modules/commands/reports.lua index b08f277d..2ec9cf34 100644 --- a/exp_legacy/module/modules/commands/reports.lua +++ b/exp_legacy/module/modules/commands/reports.lua @@ -6,7 +6,7 @@ local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports -local format_chat_player_name = _C.format_chat_player_name--- @dep expcore.common +local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common require("modules.exp_legacy.config.expcore.command_general_parse") --- Print a message to all players who match the value of admin @@ -22,76 +22,77 @@ end -- @command report -- @tparam LuaPlayer player the player to report, some players are immune -- @tparam string reason the reason the player is being reported -Commands.new_command('report', {'expcom-report.description-report'}, 'Reports a player and notifies moderators') -:add_param('player', false, function(input, player, reject) - input = Commands.parse('player', input, player, reject) - if not input then return end - if Roles.player_has_flag(input, 'report-immune') then - return reject{'expcom-report.player-immune'} - elseif player == input then - return reject{'expcom-report.self-report'} - else - return input - end -end) -:add_param('reason', false) -:add_alias('report-player') -:enable_auto_concat() -:register(function(player, action_player, reason) - local action_player_name_color = format_chat_player_name(action_player) - local by_player_name_color = format_chat_player_name(player) - if Reports.report_player(action_player, player.name, reason) then - print_to_players(false, {'expcom-report.non-admin', action_player_name_color, reason}) - print_to_players(true, {'expcom-report.admin', action_player_name_color, by_player_name_color, reason}) - else - return Commands.error{'expcom-report.already-reported'} - end -end) +Commands.new_command("report", { "expcom-report.description-report" }, "Reports a player and notifies moderators") + :add_param("player", false, function(input, player, reject) + input = Commands.parse("player", input, player, reject) + if not input then return end + if Roles.player_has_flag(input, "report-immune") then + return reject{ "expcom-report.player-immune" } + elseif player == input then + return reject{ "expcom-report.self-report" } + else + return input + end + end) + :add_param("reason", false) + :add_alias("report-player") + :enable_auto_concat() + :register(function(player, action_player, reason) + local action_player_name_color = format_chat_player_name(action_player) + local by_player_name_color = format_chat_player_name(player) + if Reports.report_player(action_player, player.name, reason) then + print_to_players(false, { "expcom-report.non-admin", action_player_name_color, reason }) + print_to_players(true, { "expcom-report.admin", action_player_name_color, by_player_name_color, reason }) + else + return Commands.error{ "expcom-report.already-reported" } + end + end) --- Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them. -- @command get-reports -- @tparam LuaPlayer player the player to get the report for -Commands.new_command('get-reports', {'expcom-report.description-get-reports'}, 'Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.') -:add_param('player', true, 'player') -:add_alias('reports', 'list-reports') -:register(function(_, player) - if player then - local reports = Reports.get_reports(player) - local player_name_color = format_chat_player_name(player) - Commands.print{'expcom-report.player-report-title', player_name_color} - for player_name, reason in pairs(reports) do - local by_player_name_color = format_chat_player_name(player_name) - Commands.print{'expcom-report.list', by_player_name_color, reason} +Commands.new_command("get-reports", { "expcom-report.description-get-reports" }, + "Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.") + :add_param("player", true, "player") + :add_alias("reports", "list-reports") + :register(function(_, player) + if player then + local reports = Reports.get_reports(player) + local player_name_color = format_chat_player_name(player) + Commands.print{ "expcom-report.player-report-title", player_name_color } + for player_name, reason in pairs(reports) do + local by_player_name_color = format_chat_player_name(player_name) + Commands.print{ "expcom-report.list", by_player_name_color, reason } + end + else + local user_reports = Reports.user_reports + Commands.print{ "expcom-report.player-count-title" } + for player_name in pairs(user_reports) do + local player_name_color = format_chat_player_name(player_name) + local report_count = Reports.count_reports(player_name) + Commands.print{ "expcom-report.list", player_name_color, report_count } + end end - else - local user_reports = Reports.user_reports - Commands.print{'expcom-report.player-count-title'} - for player_name in pairs(user_reports) do - local player_name_color = format_chat_player_name(player_name) - local report_count = Reports.count_reports(player_name) - Commands.print{'expcom-report.list', player_name_color, report_count} - end - end -end) + end) --- Clears all reports from a player or just the report from one player. -- @command clear-reports -- @tparam LuaPlayer player the player to clear the report(s) from -- @tparam[opt=all] LuaPlayer from-player remove only the report made by this player -Commands.new_command('clear-reports', {'expcom-report.description-clear-reports'}, 'Clears all reports from a player or just the report from one player.') -:add_param('player', false, 'player') -:add_param('from-player', true, 'player') -:register(function(player, action_player, from_player) - if from_player then - if not Reports.remove_report(action_player, from_player.name, player.name) then - return Commands.error{'expcom-report.not-reported'} +Commands.new_command("clear-reports", { "expcom-report.description-clear-reports" }, "Clears all reports from a player or just the report from one player.") + :add_param("player", false, "player") + :add_param("from-player", true, "player") + :register(function(player, action_player, from_player) + if from_player then + if not Reports.remove_report(action_player, from_player.name, player.name) then + return Commands.error{ "expcom-report.not-reported" } + end + else + if not Reports.remove_all(action_player, player.name) then + return Commands.error{ "expcom-report.not-reported" } + end end - else - if not Reports.remove_all(action_player, player.name) then - return Commands.error{'expcom-report.not-reported'} - end - end - local action_player_name_color = format_chat_player_name(action_player) - local by_player_name_color = format_chat_player_name(player) - game.print{'expcom-report.removed', action_player_name_color, by_player_name_color} -end) + local action_player_name_color = format_chat_player_name(action_player) + local by_player_name_color = format_chat_player_name(player) + game.print{ "expcom-report.removed", action_player_name_color, by_player_name_color } + end) diff --git a/exp_legacy/module/modules/commands/research.lua b/exp_legacy/module/modules/commands/research.lua index 5f4fe417..91bbe1bd 100644 --- a/exp_legacy/module/modules/commands/research.lua +++ b/exp_legacy/module/modules/commands/research.lua @@ -10,35 +10,35 @@ end) local function res_queue(force, by_script) local res_q = force.research_queue - local res = force.technologies['mining-productivity-4'] + local res = force.technologies["mining-productivity-4"] if #res_q < config.queue_amount then - for i=1, config.queue_amount - #res_q do + for i = 1, config.queue_amount - #res_q do force.add_research(res) if not (by_script) then - game.print{'expcom-res.inf-q', res.name, res.level + i} + game.print{ "expcom-res.inf-q", res.name, res.level + i } end end end end -Commands.new_command('auto-research', {'expcom-res.description-ares'}, 'Automatically queue up research') -:add_alias('ares') -:register(function(player) - research.res_queue_enable = not research.res_queue_enable +Commands.new_command("auto-research", { "expcom-res.description-ares" }, "Automatically queue up research") + :add_alias("ares") + :register(function(player) + research.res_queue_enable = not research.res_queue_enable - if research.res_queue_enable then - res_queue(player.force, true) - end + if research.res_queue_enable then + res_queue(player.force, true) + end - game.print{'expcom-res.res', player.name, research.res_queue_enable} - return Commands.success -end) + game.print{ "expcom-res.res", player.name, research.res_queue_enable } + return Commands.success + end) Event.add(defines.events.on_research_finished, function(event) if research.res_queue_enable then - if event.research.force.rockets_launched > 0 and event.research.force.technologies['mining-productivity-4'].level > 4 then + if event.research.force.rockets_launched > 0 and event.research.force.technologies["mining-productivity-4"].level > 4 then res_queue(event.research.force, event.by_script) end end diff --git a/exp_legacy/module/modules/commands/roles.lua b/exp_legacy/module/modules/commands/roles.lua index e8a31a5d..a02f5475 100644 --- a/exp_legacy/module/modules/commands/roles.lua +++ b/exp_legacy/module/modules/commands/roles.lua @@ -12,70 +12,68 @@ local format_chat_player_name, format_chat_colour_localized = _C.format_chat_pla -- @command assign-role -- @tparam LuaPlayer player the player to assign the role to -- @tparam string role the name of the role to assign to the player, supports auto complete after enter -Commands.new_command('assign-role', {'expcom-roles.description-assign-role'}, 'Assigns a role to a player') -:add_param('player', false, 'player-role') -:add_param('role', false, 'role') -:set_flag('admin-only') -:add_alias('rpromote', 'assign', 'role', 'add-role') -:register(function(player, action_player, role) - local player_highest = Roles.get_player_highest_role(player) +Commands.new_command("assign-role", { "expcom-roles.description-assign-role" }, "Assigns a role to a player") + :add_param("player", false, "player-role") + :add_param("role", false, "role") + :set_flag("admin-only") + :add_alias("rpromote", "assign", "role", "add-role") + :register(function(player, action_player, role) + local player_highest = Roles.get_player_highest_role(player) - if player_highest.index < role.index then - Roles.assign_player(action_player, role, player.name) - - else - return Commands.error{'expcom-roles.higher-role'} - end -end) + if player_highest.index < role.index then + Roles.assign_player(action_player, role, player.name) + else + return Commands.error{ "expcom-roles.higher-role" } + end + end) --- Unassigns a role from a player -- @command unassign-role -- @tparam LuaPlayer player the player to unassign the role from -- @tparam string role the name of the role to unassign from the player, supports auto complete after enter -Commands.new_command('unassign-role', {'expcom-roles.description-unassign-role'}, 'Unassigns a role from a player') -:add_param('player', false, 'player-role') -:add_param('role', false, 'role') -:set_flag('admin-only') -:add_alias('rdemote', 'unassign', 'rerole', 'remove-role') -:register(function(player, action_player, role) - local player_highest = Roles.get_player_highest_role(player) +Commands.new_command("unassign-role", { "expcom-roles.description-unassign-role" }, "Unassigns a role from a player") + :add_param("player", false, "player-role") + :add_param("role", false, "role") + :set_flag("admin-only") + :add_alias("rdemote", "unassign", "rerole", "remove-role") + :register(function(player, action_player, role) + local player_highest = Roles.get_player_highest_role(player) - if player_highest.index < role.index then - Roles.unassign_player(action_player, role, player.name) - - else - return Commands.error{'expcom-roles.higher-role'} - end -end) + if player_highest.index < role.index then + Roles.unassign_player(action_player, role, player.name) + else + return Commands.error{ "expcom-roles.higher-role" } + end + end) --- Lists all roles in they correct order -- @command list-roles -- @tparam[opt=all] LuaPlayer player list only the roles which this player has -Commands.new_command('list-roles', {'expcom-roles.description-list-roles'}, 'Lists all roles in they correct order') -:add_param('player', true, 'player') -:add_alias('lsroles', 'roles') -:register(function(_, player) - local roles = Roles.config.order - local message = {'expcom-roles.list'} +Commands.new_command("list-roles", { "expcom-roles.description-list-roles" }, "Lists all roles in they correct order") + :add_param("player", true, "player") + :add_alias("lsroles", "roles") + :register(function(_, player) + local roles = Roles.config.order + local message = { "expcom-roles.list" } - if player then - roles = Roles.get_player_roles(player) - end - - for index, role in pairs(roles) do - role = Roles.get_role_from_any(role) - local colour = role.custom_color or Colours.white - local role_name = format_chat_colour_localized(role.name, colour) - if index == 1 then - message = {'expcom-roles.list', role_name} - if player then - local player_name_colour = format_chat_player_name(player) - message = {'expcom-roles.list-player', player_name_colour, role_name} - end - else - message = {'expcom-roles.list-element', message, role_name} + if player then + roles = Roles.get_player_roles(player) end - end - return Commands.success(message) -end) + for index, role in pairs(roles) do + role = Roles.get_role_from_any(role) + local colour = role.custom_color or Colours.white + local role_name = format_chat_colour_localized(role.name, colour) + if index == 1 then + message = { "expcom-roles.list", role_name } + if player then + local player_name_colour = format_chat_player_name(player) + message = { "expcom-roles.list-player", player_name_colour, role_name } + end + else + message = { "expcom-roles.list-element", message, role_name } + end + end + + return Commands.success(message) + end) diff --git a/exp_legacy/module/modules/commands/search.lua b/exp_legacy/module/modules/commands/search.lua index 68ccee3d..933871f5 100644 --- a/exp_legacy/module/modules/commands/search.lua +++ b/exp_legacy/module/modules/commands/search.lua @@ -12,19 +12,19 @@ require("modules.exp_legacy.config.expcore.command_general_parse") --- Input parse for items by name local function item_parse(input, _, reject) if input == nil then return end - local lower_input = input:lower():gsub(' ', '-') + local lower_input = input:lower():gsub(" ", "-") -- Simple Case - internal name is given local item = prototypes.item[lower_input] if item then return item end -- Second Case - rich text is given - local item_name = input:match('%[item=([0-9a-z-]+)%]') + local item_name = input:match("%[item=([0-9a-z-]+)%]") item = prototypes.item[item_name] if item then return item end -- No item found, we do not attempt to search all prototypes as this will be expensive - return reject{'expcom-inv-search.reject-item', lower_input} + return reject{ "expcom-inv-search.reject-item", lower_input } end --- Search all players for this item @@ -37,7 +37,7 @@ local function search_players(players, item) local item_count = player.get_item_count(item.name) if item_count > 0 then -- Add the player to the array as they have the item - found[head] = { player=player, count=item_count, online_time=player.online_time } + found[head] = { player = player, count = item_count, online_time = player.online_time } head = head + 1 end end @@ -66,9 +66,10 @@ local function sort_players(players, func) break end end + -- Insert the element, this can only be called when index <= 5 if not inserted then - sorted[#sorted+1] = player + sorted[#sorted + 1] = player end -- Update the threshold if sorted[6] then @@ -86,12 +87,12 @@ end --- Display to the player the top players which were found local function display_players(player, players, item) - player.print{'expcom-inv-search.results-heading', item.name} + player.print{ "expcom-inv-search.results-heading", item.name } for index, data in ipairs(players) do local player_name_color = format_chat_player_name(data.player) local amount = format_number(data.count) local time = format_time(data.online_time) - player.print{'expcom-inv-search.results-item', index, player_name_color, amount, time} + player.print{ "expcom-inv-search.results-item", index, player_name_color, amount, time } end end @@ -103,16 +104,16 @@ end --- Get a list of players sorted by the quantity of an item in their inventory -- @command search-amount -- @tparam LuaItemPrototype item The item to search for in players inventories -Commands.new_command('search-amount', {'expcom-inv-search.description-ia'}, 'Display players sorted by the quantity of an item held') -:add_alias('ia') -:add_param('item', false, item_parse) -:enable_auto_concat() -:register(function(player, item) - local players = search_players(game.players, item) - if #players == 0 then return {'expcom-inv-search.results-none', item.name} end - local top_players = sort_players(players, amount_sort) - display_players(player, top_players, item) -end) +Commands.new_command("search-amount", { "expcom-inv-search.description-ia" }, "Display players sorted by the quantity of an item held") + :add_alias("ia") + :add_param("item", false, item_parse) + :enable_auto_concat() + :register(function(player, item) + local players = search_players(game.players, item) + if #players == 0 then return { "expcom-inv-search.results-none", item.name } end + local top_players = sort_players(players, amount_sort) + display_players(player, top_players, item) + end) --- Return the index of the player, higher means they joined more recently local function recent_sort(data) @@ -122,46 +123,46 @@ end --- Get a list of players who have the given item, sorted by how recently they joined -- @command search-recent -- @tparam LuaItemPrototype item The item to search for in players inventories -Commands.new_command('search-recent', {'expcom-inv-search.description-ir'}, 'Display players who hold an item sorted by join time') -:add_alias('ir') -:add_param('item', false, item_parse) -:enable_auto_concat() -:register(function(player, item) - local players = search_players(game.players, item) - if #players == 0 then return {'expcom-inv-search.results-none', item.name} end - local top_players = sort_players(players, recent_sort) - display_players(player, top_players, item) -end) +Commands.new_command("search-recent", { "expcom-inv-search.description-ir" }, "Display players who hold an item sorted by join time") + :add_alias("ir") + :add_param("item", false, item_parse) + :enable_auto_concat() + :register(function(player, item) + local players = search_players(game.players, item) + if #players == 0 then return { "expcom-inv-search.results-none", item.name } end + local top_players = sort_players(players, recent_sort) + display_players(player, top_players, item) + end) --- Return the the amount of an item a player has divided by their playtime local function combined_sort(data) - return data.count/data.online_time + return data.count / data.online_time end --- Get a list of players sorted by quantity held and play time -- @command search -- @tparam LuaItemPrototype item The item to search for in players inventories -Commands.new_command('search', {'expcom-inv-search.description-i'}, 'Display players sorted by the quantity of an item held and playtime') -:add_alias('i') -:add_param('item', false, item_parse) -:enable_auto_concat() -:register(function(player, item) - local players = search_players(game.players, item) - if #players == 0 then return {'expcom-inv-search.results-none', item.name} end - local top_players = sort_players(players, combined_sort) - display_players(player, top_players, item) -end) +Commands.new_command("search", { "expcom-inv-search.description-i" }, "Display players sorted by the quantity of an item held and playtime") + :add_alias("i") + :add_param("item", false, item_parse) + :enable_auto_concat() + :register(function(player, item) + local players = search_players(game.players, item) + if #players == 0 then return { "expcom-inv-search.results-none", item.name } end + local top_players = sort_players(players, combined_sort) + display_players(player, top_players, item) + end) --- Get a list of online players sorted by quantity held and play time -- @command search-online -- @tparam LuaItemPrototype item The item to search for in players inventories -Commands.new_command('search-online', {'expcom-inv-search.description-io'}, 'Display online players sorted by the quantity of an item held and playtime') -:add_alias('io') -:add_param('item', false, item_parse) -:enable_auto_concat() -:register(function(player, item) - local players = search_players(game.connected_players, item) - if #players == 0 then return {'expcom-inv-search.results-none', item.name} end - local top_players = sort_players(players, combined_sort) - display_players(player, top_players, item) -end) +Commands.new_command("search-online", { "expcom-inv-search.description-io" }, "Display online players sorted by the quantity of an item held and playtime") + :add_alias("io") + :add_param("item", false, item_parse) + :enable_auto_concat() + :register(function(player, item) + local players = search_players(game.connected_players, item) + if #players == 0 then return { "expcom-inv-search.results-none", item.name } end + local top_players = sort_players(players, combined_sort) + display_players(player, top_players, item) + end) diff --git a/exp_legacy/module/modules/commands/spawn.lua b/exp_legacy/module/modules/commands/spawn.lua index 058c9f40..b9016ee6 100644 --- a/exp_legacy/module/modules/commands/spawn.lua +++ b/exp_legacy/module/modules/commands/spawn.lua @@ -9,7 +9,7 @@ local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles local function teleport(player) local surface = player.surface local spawn = player.force.get_spawn_position(surface) - local position = surface.find_non_colliding_position('character', spawn, 32, 1) + local position = surface.find_non_colliding_position("character", spawn, 32, 1) -- return false if no new position if not position then return false @@ -39,29 +39,28 @@ end --- Teleport to spawn -- @command go-to-spawn -- @tparam[opt=self] LuaPlayer player the player to teleport to their spawn point -Commands.new_command('go-to-spawn', {'expcom-spawn.description'}, 'Teleport to spawn') -:add_param('player', true, 'player-role-alive') -:set_defaults{ - player=function(player) - if player.connected and player.character and player.character.health > 0 then - return player +Commands.new_command("go-to-spawn", { "expcom-spawn.description" }, "Teleport to spawn") + :add_param("player", true, "player-role-alive") + :set_defaults{ + player = function(player) + if player.connected and player.character and player.character.health > 0 then + return player + end + end, + } + :add_alias("spawn", "tp-spawn") + :register(function(player, action_player) + if not action_player then + return Commands.error{ "expcom-spawn.unavailable" } + elseif action_player == player then + if not teleport(player) then + return Commands.error{ "expcom-spawn.unavailable" } + end + elseif Roles.player_allowed(player, "command/go-to-spawn/always") then + if not teleport(action_player) then + return Commands.error{ "expcom-spawn.unavailable" } + end + else + return Commands.error{ "expcore-commands.unauthorized" } end - end -} -:add_alias('spawn', 'tp-spawn') -:register(function(player, action_player) - if not action_player then - return Commands.error{'expcom-spawn.unavailable'} - elseif action_player == player then - if not teleport(player) then - return Commands.error{'expcom-spawn.unavailable'} - end - elseif Roles.player_allowed(player, 'command/go-to-spawn/always') then - if not teleport(action_player) then - return Commands.error{'expcom-spawn.unavailable'} - end - - else - return Commands.error{'expcore-commands.unauthorized'} - end -end) + end) diff --git a/exp_legacy/module/modules/commands/spectate.lua b/exp_legacy/module/modules/commands/spectate.lua index 3621e9c4..d0f2770f 100644 --- a/exp_legacy/module/modules/commands/spectate.lua +++ b/exp_legacy/module/modules/commands/spectate.lua @@ -9,26 +9,25 @@ require("modules.exp_legacy.config.expcore.command_general_parse") --- Toggles spectator mode for the caller -- @command spectate -Commands.new_command('spectate', {'expcom-spectate.description-spectate'}, 'Toggles spectator mode') -:register(function(player) - if Spectate.is_spectating(player) then - Spectate.stop_spectate(player) - else - Spectate.start_spectate(player) - end -end) +Commands.new_command("spectate", { "expcom-spectate.description-spectate" }, "Toggles spectator mode") + :register(function(player) + if Spectate.is_spectating(player) then + Spectate.stop_spectate(player) + else + Spectate.start_spectate(player) + end + end) --- Enters follow mode for the caller, following the given player. -- @command follow -- @tparam LuaPlayer player The player that will be followed -Commands.new_command('follow', {'expcom-spectate.description-follow'}, 'Start following a player in spectator') -:add_alias('f') -:add_param('player', false, 'player-online') -:register(function(player, action_player) - if player == action_player then - return Commands.error{'expcom-spectate.follow-self'} - - else - Spectate.start_follow(player, action_player) - end -end) +Commands.new_command("follow", { "expcom-spectate.description-follow" }, "Start following a player in spectator") + :add_alias("f") + :add_param("player", false, "player-online") + :register(function(player, action_player) + if player == action_player then + return Commands.error{ "expcom-spectate.follow-self" } + else + Spectate.start_follow(player, action_player) + end + end) diff --git a/exp_legacy/module/modules/commands/speed.lua b/exp_legacy/module/modules/commands/speed.lua index 868ea0a5..06c7c560 100644 --- a/exp_legacy/module/modules/commands/speed.lua +++ b/exp_legacy/module/modules/commands/speed.lua @@ -6,11 +6,11 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") -Commands.new_command('game-speed', {'expcom-speed.description'}, 'Set game speed') -:add_param('amount', 'number-range', 0.2, 8) -:set_flag('admin_only') -:register(function(player, amount) - game.speed = math.round(amount, 3) - game.print{'expcom-speed.result', player.name, string.format('%.3f', amount)} - return Commands.success -end) +Commands.new_command("game-speed", { "expcom-speed.description" }, "Set game speed") + :add_param("amount", "number-range", 0.2, 8) + :set_flag("admin_only") + :register(function(player, amount) + game.speed = math.round(amount, 3) + game.print{ "expcom-speed.result", player.name, string.format("%.3f", amount) } + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/surface-clearing.lua b/exp_legacy/module/modules/commands/surface-clearing.lua index 51ab4a2a..e85005ae 100644 --- a/exp_legacy/module/modules/commands/surface-clearing.lua +++ b/exp_legacy/module/modules/commands/surface-clearing.lua @@ -7,27 +7,27 @@ local copy_items_stack = _C.copy_items_stack --- @dep expcore.common local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") -Commands.new_command('clear-item-on-ground', {'expcom-surface-clearing.description-ci'}, 'Clear Item On Ground') -:add_param('range', false, 'integer-range', 1, 1000) -:register(function(player, range) - for _, e in pairs(player.surface.find_entities_filtered{position=player.position, radius=range, name='item-on-ground'}) do - if e.stack then - -- calling move_items_stack(e.stack) will crash to desktop - -- https://forums.factorio.com/viewtopic.php?f=7&t=110322 - copy_items_stack{e.stack} - e.stack.clear() +Commands.new_command("clear-item-on-ground", { "expcom-surface-clearing.description-ci" }, "Clear Item On Ground") + :add_param("range", false, "integer-range", 1, 1000) + :register(function(player, range) + for _, e in pairs(player.surface.find_entities_filtered{ position = player.position, radius = range, name = "item-on-ground" }) do + if e.stack then + -- calling move_items_stack(e.stack) will crash to desktop + -- https://forums.factorio.com/viewtopic.php?f=7&t=110322 + copy_items_stack{ e.stack } + e.stack.clear() + end end - end - return Commands.success -end) + return Commands.success + end) -Commands.new_command('clear-blueprint', {'expcom-surface-clearing.description-cb'}, 'Clear Blueprint') -:add_param('range', false, 'integer-range', 1, 1000) -:register(function(player, range) - for _, e in pairs(player.surface.find_entities_filtered{position=player.position, radius=range, type='entity-ghost'}) do - e.destroy() - end +Commands.new_command("clear-blueprint", { "expcom-surface-clearing.description-cb" }, "Clear Blueprint") + :add_param("range", false, "integer-range", 1, 1000) + :register(function(player, range) + for _, e in pairs(player.surface.find_entities_filtered{ position = player.position, radius = range, type = "entity-ghost" }) do + e.destroy() + end - return Commands.success -end) + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/teleport.lua b/exp_legacy/module/modules/commands/teleport.lua index a63452e4..43bcd981 100644 --- a/exp_legacy/module/modules/commands/teleport.lua +++ b/exp_legacy/module/modules/commands/teleport.lua @@ -8,7 +8,7 @@ require("modules.exp_legacy.config.expcore.command_general_parse") local function teleport(from_player, to_player) local surface = to_player.surface - local position = surface.find_non_colliding_position('character', to_player.position, 32, 1) + local position = surface.find_non_colliding_position("character", to_player.position, 32, 1) -- return false if no new position if not position then @@ -41,53 +41,53 @@ end -- @command teleport -- @tparam LuaPlayer from_player the player that will be teleported, must be alive -- @tparam LuaPlayer to_player the player to teleport to, must be online (if dead goes to where they died) -Commands.new_command('teleport', {'expcom-tp.description-tp'}, 'Teleports a player to another player.') -:add_param('from_player', false, 'player-alive') -:add_param('to_player', false, 'player-online') -:add_alias('tp') -:set_flag('admin_only') -:register(function(_, from_player, to_player) - if from_player.index == to_player.index then - -- return if attempting to teleport to self - return Commands.error{'expcom-tp.to-self'} - end - if not teleport(from_player, to_player) then - -- return if the teleport failed - return Commands.error{'expcom-tp.no-position-found'} - end -end) +Commands.new_command("teleport", { "expcom-tp.description-tp" }, "Teleports a player to another player.") + :add_param("from_player", false, "player-alive") + :add_param("to_player", false, "player-online") + :add_alias("tp") + :set_flag("admin_only") + :register(function(_, from_player, to_player) + if from_player.index == to_player.index then + -- return if attempting to teleport to self + return Commands.error{ "expcom-tp.to-self" } + end + if not teleport(from_player, to_player) then + -- return if the teleport failed + return Commands.error{ "expcom-tp.no-position-found" } + end + end) --- Teleports a player to you. -- @command bring -- @tparam LuaPlayer player the player that will be teleported, must be alive -Commands.new_command('bring', {'expcom-tp.description-bring'}, 'Teleports a player to you.') -:add_param('player', false, 'player-alive') -:set_flag('admin_only') -:register(function(player, from_player) - if from_player.index == player.index then - -- return if attempting to teleport to self - return Commands.error{'expcom-tp.to-self'} - end - if not teleport(from_player, player) then - -- return if the teleport failed - return Commands.error{'expcom-tp.no-position-found'} - end - from_player.print('Come here my friend') -end) +Commands.new_command("bring", { "expcom-tp.description-bring" }, "Teleports a player to you.") + :add_param("player", false, "player-alive") + :set_flag("admin_only") + :register(function(player, from_player) + if from_player.index == player.index then + -- return if attempting to teleport to self + return Commands.error{ "expcom-tp.to-self" } + end + if not teleport(from_player, player) then + -- return if the teleport failed + return Commands.error{ "expcom-tp.no-position-found" } + end + from_player.print("Come here my friend") + end) --- Teleports you to a player. -- @command goto -- @tparam LuaPlayer player the player to teleport to, must be online (if dead goes to where they died) -Commands.new_command('goto', {'expcom-tp.description-goto'}, 'Teleports you to a player.') -:add_param('player', false, 'player-online') -:add_alias('tp-me', 'tpme') -:register(function(player, to_player) - if to_player.index == player.index then - -- return if attempting to teleport to self - return Commands.error{'expcom-tp.to-self'} - end - if not teleport(player, to_player) then - -- return if the teleport failed - return Commands.error{'expcom-tp.no-position-found'} - end -end) +Commands.new_command("goto", { "expcom-tp.description-goto" }, "Teleports you to a player.") + :add_param("player", false, "player-online") + :add_alias("tp-me", "tpme") + :register(function(player, to_player) + if to_player.index == player.index then + -- return if attempting to teleport to self + return Commands.error{ "expcom-tp.to-self" } + end + if not teleport(player, to_player) then + -- return if the teleport failed + return Commands.error{ "expcom-tp.no-position-found" } + end + end) diff --git a/exp_legacy/module/modules/commands/train.lua b/exp_legacy/module/modules/commands/train.lua index 0a08b9cd..db51fea7 100644 --- a/exp_legacy/module/modules/commands/train.lua +++ b/exp_legacy/module/modules/commands/train.lua @@ -7,17 +7,17 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore require("modules.exp_legacy.config.expcore.command_general_parse") local format_number = require("util").format_number -Commands.new_command('set-trains-to-automatic', {'expcom-train.description'}, 'Set All Trains to Automatic') -:register(function(player) - local count = 0 +Commands.new_command("set-trains-to-automatic", { "expcom-train.description" }, "Set All Trains to Automatic") + :register(function(player) + local count = 0 - for _, v in pairs(player.force.get_trains()) do - if v.manual_mode then - count = count + 1 - v.manual_mode = false + for _, v in pairs(player.force.get_trains()) do + if v.manual_mode then + count = count + 1 + v.manual_mode = false + end end - end - game.print{'expcom-train.manual-result', player.name, format_number(count)} - return Commands.success -end) + game.print{ "expcom-train.manual-result", player.name, format_number(count) } + return Commands.success + end) diff --git a/exp_legacy/module/modules/commands/vlayer.lua b/exp_legacy/module/modules/commands/vlayer.lua index 8ceda791..885b9ade 100644 --- a/exp_legacy/module/modules/commands/vlayer.lua +++ b/exp_legacy/module/modules/commands/vlayer.lua @@ -5,11 +5,11 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore require("modules.exp_legacy.config.expcore.command_general_parse") local vlayer = require("modules.exp_legacy.modules.control.vlayer") -Commands.new_command('vlayer-info', {'vlayer.description-vi'}, 'Vlayer Info') -:register(function(_) - local c = vlayer.get_circuits() +Commands.new_command("vlayer-info", { "vlayer.description-vi" }, "Vlayer Info") + :register(function(_) + local c = vlayer.get_circuits() - for k, v in pairs(c) do - Commands.print(v .. ' : ' .. k) - end -end) + for k, v in pairs(c) do + Commands.print(v .. " : " .. k) + end + end) diff --git a/exp_legacy/module/modules/commands/warnings.lua b/exp_legacy/module/modules/commands/warnings.lua index 2caef4a3..f81e7034 100644 --- a/exp_legacy/module/modules/commands/warnings.lua +++ b/exp_legacy/module/modules/commands/warnings.lua @@ -13,62 +13,64 @@ require("modules.exp_legacy.config.expcore.command_role_parse") -- @command give-warning -- @tparam LuaPlayer player the player the will recive a warning -- @tparam string reason the reason the player is being given a warning -Commands.new_command('give-warning', {'expcom-warnings.description-give'}, 'Gives a warning to a player; may lead to automatic script action.') -:add_param('player', false, 'player-role') -:add_param('reason', false) -:add_alias('warn') -:enable_auto_concat() -:register(function(player, action_player, reason) - Warnings.add_warning(action_player, player.name, reason) - local action_player_name_color = format_chat_player_name(action_player) - local by_player_name_color = format_chat_player_name(player) - game.print{'expcom-warnings.received', action_player_name_color, by_player_name_color, reason} -end) +Commands.new_command("give-warning", { "expcom-warnings.description-give" }, "Gives a warning to a player; may lead to automatic script action.") + :add_param("player", false, "player-role") + :add_param("reason", false) + :add_alias("warn") + :enable_auto_concat() + :register(function(player, action_player, reason) + Warnings.add_warning(action_player, player.name, reason) + local action_player_name_color = format_chat_player_name(action_player) + local by_player_name_color = format_chat_player_name(player) + game.print{ "expcom-warnings.received", action_player_name_color, by_player_name_color, reason } + end) --- Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have. -- @command get-warnings -- @tparam[opt=list] LuaPlayer player the player to get the warning for, if nil all players are listed -Commands.new_command('get-warnings', {'expcom-warnings.description-get'}, 'Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have.') -:add_param('player', true, 'player') -:add_alias('warnings', 'list-warnings') -:register(function(_, player) - if player then - local warnings = Warnings.get_warnings(player) - local script_warnings = Warnings.get_script_warnings(player) - local player_name_color = format_chat_player_name(player) - Commands.print{'expcom-warnings.player', player_name_color, #warnings, #script_warnings, config.temp_warning_limit} - for _, warning in ipairs(warnings) do - Commands.print{'expcom-warnings.player-detail', format_chat_player_name(warning.by_player_name), warning.reason} - end - else - local rtn = {} - local user_script_warnings = Warnings.user_script_warnings - for player_name, warnings in pairs(Warnings.user_warnings:get_all()) do - rtn[player_name] = {#warnings, 0} - end - for player_name, warnings in pairs(user_script_warnings) do - if not rtn[player_name] then - rtn[player_name] = {0, 0} +Commands.new_command("get-warnings", { "expcom-warnings.description-get" }, "Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have.") + :add_param("player", true, "player") + :add_alias("warnings", "list-warnings") + :register(function(_, player) + if player then + local warnings = Warnings.get_warnings(player) + local script_warnings = Warnings.get_script_warnings(player) + local player_name_color = format_chat_player_name(player) + Commands.print{ "expcom-warnings.player", player_name_color, #warnings, #script_warnings, config.temp_warning_limit } + for _, warning in ipairs(warnings) do + Commands.print{ "expcom-warnings.player-detail", format_chat_player_name(warning.by_player_name), warning.reason } + end + else + local rtn = {} + local user_script_warnings = Warnings.user_script_warnings + for player_name, warnings in pairs(Warnings.user_warnings:get_all()) do + rtn[player_name] = { #warnings, 0 } + end + + for player_name, warnings in pairs(user_script_warnings) do + if not rtn[player_name] then + rtn[player_name] = { 0, 0 } + end + rtn[player_name][2] = #warnings + end + + Commands.print{ "expcom-warnings.list-title" } + for player_name, warnings in pairs(rtn) do + local player_name_color = format_chat_player_name(player_name) + Commands.print{ "expcom-warnings.list", player_name_color, warnings[1], warnings[2], config.temp_warning_limit } end - rtn[player_name][2] = #warnings end - Commands.print{'expcom-warnings.list-title'} - for player_name, warnings in pairs(rtn) do - local player_name_color = format_chat_player_name(player_name) - Commands.print{'expcom-warnings.list', player_name_color, warnings[1], warnings[2], config.temp_warning_limit} - end - end -end) + end) --- Clears all warnings (and script warnings) from a player -- @command clear-warnings -- @tparam LuaPlayer player the player to clear the warnings from -Commands.new_command('clear-warnings', {'expcom-warnings.description-clear'}, 'Clears all warnings (and script warnings) from a player') -:add_param('player', false, 'player') -:register(function(player, action_player) - Warnings.clear_warnings(action_player, player.name) - Warnings.clear_script_warnings(action_player) - local action_player_name_color = format_chat_player_name(action_player) - local by_player_name_color = format_chat_player_name(player) - game.print{'expcom-warnings.cleared', action_player_name_color, by_player_name_color} -end) +Commands.new_command("clear-warnings", { "expcom-warnings.description-clear" }, "Clears all warnings (and script warnings) from a player") + :add_param("player", false, "player") + :register(function(player, action_player) + Warnings.clear_warnings(action_player, player.name) + Warnings.clear_script_warnings(action_player) + local action_player_name_color = format_chat_player_name(action_player) + local by_player_name_color = format_chat_player_name(player) + game.print{ "expcom-warnings.cleared", action_player_name_color, by_player_name_color } + end) diff --git a/exp_legacy/module/modules/commands/waterfill.lua b/exp_legacy/module/modules/commands/waterfill.lua index 7b38b365..74a6ceb5 100644 --- a/exp_legacy/module/modules/commands/waterfill.lua +++ b/exp_legacy/module/modules/commands/waterfill.lua @@ -4,33 +4,33 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection -local SelectionConvertArea = 'ConvertArea' +local SelectionConvertArea = "ConvertArea" --- Align an aabb to the grid by expanding it local function aabb_align_expand(aabb) return { - left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)}, - right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)} + left_top = { x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y) }, + right_bottom = { x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y) }, } end -Commands.new_command('waterfill', {'expcom-waterfill.description'}, 'Change tile to water') -:register(function(player) - local inv = player.get_main_inventory() +Commands.new_command("waterfill", { "expcom-waterfill.description" }, "Change tile to water") + :register(function(player) + local inv = player.get_main_inventory() - if (inv.get_item_count('cliff-explosives')) == 0 then - return player.print{'expcom-waterfill.waterfill-cliff'} - end + if (inv.get_item_count("cliff-explosives")) == 0 then + return player.print{ "expcom-waterfill.waterfill-cliff" } + end - if Selection.is_selecting(player, SelectionConvertArea) then - Selection.stop(player) - else - Selection.start(player, SelectionConvertArea) - return Commands.success{'expcom-waterfill.entered-area-selection'} - end + if Selection.is_selecting(player, SelectionConvertArea) then + Selection.stop(player) + else + Selection.start(player, SelectionConvertArea) + return Commands.success{ "expcom-waterfill.entered-area-selection" } + end - return Commands.success -end) + return Commands.success + end) --- When an area is selected to add protection to the area Selection.on_selection(SelectionConvertArea, function(event) @@ -41,10 +41,10 @@ Selection.on_selection(SelectionConvertArea, function(event) return end - local entities = player.surface.find_entities_filtered{area=area, name='steel-chest'} + local entities = player.surface.find_entities_filtered{ area = area, name = "steel-chest" } if #entities == 0 then - player.print('No steel chest found') + player.print("No steel chest found") return end @@ -55,21 +55,21 @@ Selection.on_selection(SelectionConvertArea, function(event) return end - local clf_exp = inv.get_item_count('cliff-explosives') + local clf_exp = inv.get_item_count("cliff-explosives") for _, entity in pairs(entities) do if clf_exp >= 1 then if entity.get_inventory(defines.inventory.chest).is_empty() then if (math.floor(player.position.x) ~= math.floor(entity.position.x)) or (math.floor(player.position.y) ~= math.floor(entity.position.y)) then - table.insert(tiles_to_make, {name='water-mud', position=entity.position}) + table.insert(tiles_to_make, { name = "water-mud", position = entity.position }) entity.destroy() else - player.print{'expcom-waterfill.waterfill-distance'} + player.print{ "expcom-waterfill.waterfill-distance" } end end clf_exp = clf_exp - 1 - inv.remove({name='cliff-explosives', count=1}) + inv.remove{ name = "cliff-explosives", count = 1 } else break end diff --git a/exp_legacy/module/modules/control/jail.lua b/exp_legacy/module/modules/control/jail.lua index 14e8da64..d44da3d9 100644 --- a/exp_legacy/module/modules/control/jail.lua +++ b/exp_legacy/module/modules/control/jail.lua @@ -33,13 +33,13 @@ local Jail = { -- @tparam number player_index the index of the player who was jailed -- @tparam string by_player_name the name of the player who jailed the other player -- @tparam string reason the reason that the player was jailed - on_player_jailed=script.generate_event_name(), + on_player_jailed = script.generate_event_name(), --- When a player is unassigned from jail -- @event on_player_unjailed -- @tparam number player_index the index of the player who was unjailed -- @tparam string by_player_name the name of the player who unjailed the other player - on_player_unjailed=script.generate_event_name(), - } + on_player_unjailed = script.generate_event_name(), + }, } --- Used to emit the jail related events @@ -49,11 +49,11 @@ local Jail = { -- @tparam string reason the reason for the action (jail) local function event_emit(event, player, by_player_name, reason) script.raise_event(event, { - name=event, - tick=game.tick, - player_index=player.index, - by_player_name=by_player_name, - reason=reason + name = event, + tick = game.tick, + player_index = player.index, + by_player_name = by_player_name, + reason = reason, }) end @@ -65,7 +65,7 @@ end -- @tparam LuaPlayer player the player to check if they are in jail -- @treturn boolean whether the player is currently in jail function Jail.is_jailed(player) - return has_role(player, 'Jail') + return has_role(player, "Jail") end --- Moves a player to jail and removes all other roles @@ -78,9 +78,9 @@ function Jail.jail_player(player, by_player_name, reason) if not player then return end if not by_player_name then return end - reason = reason or 'Non given.' + reason = reason or "Non given." - if has_role(player, 'Jail') then return end + if has_role(player, "Jail") then return end local roles = get_roles(player) player.walking_state = { walking = false, direction = player.walking_state.direction } @@ -91,7 +91,7 @@ function Jail.jail_player(player, by_player_name, reason) player.repair_state = { repairing = false, position = player.repair_state.position } unassign_roles(player, roles, by_player_name, nil, true) - assign_roles(player, 'Jail', by_player_name, nil, true) + assign_roles(player, "Jail", by_player_name, nil, true) assign_roles(player, roles, by_player_name, nil, true) event_emit(Jail.events.on_player_jailed, player, by_player_name, reason) @@ -108,9 +108,9 @@ function Jail.unjail_player(player, by_player_name) if not player then return end if not by_player_name then return end - if not has_role(player, 'Jail') then return end + if not has_role(player, "Jail") then return end - unassign_roles(player, 'Jail', by_player_name, nil, true) + unassign_roles(player, "Jail", by_player_name, nil, true) event_emit(Jail.events.on_player_unjailed, player, by_player_name) diff --git a/exp_legacy/module/modules/control/production.lua b/exp_legacy/module/modules/control/production.lua index 8f17c67a..7463572a 100644 --- a/exp_legacy/module/modules/control/production.lua +++ b/exp_legacy/module/modules/control/production.lua @@ -47,13 +47,20 @@ local Production = {} -- @treturn[1] defines.flow_precision_index the next precision value -- @treturn[1] number the multiplicive difference between the values function Production.precision_up(precision) - if precision == precision_index.five_seconds then return precision_index.one_minute, 60 - elseif precision == precision_index.one_minute then return precision_index.ten_minutes, 10 - elseif precision == precision_index.ten_minutes then return precision_index.one_hour, 6 - elseif precision == precision_index.one_hour then return precision_index.ten_hours, 10 - elseif precision == precision_index.ten_hours then return precision_index.fifty_hours, 5 - elseif precision == precision_index.fifty_hours then return precision_index.two_hundred_fifty_hours, 5 - elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.one_thousand_hours, 4 + if precision == precision_index.five_seconds then + return precision_index.one_minute, 60 + elseif precision == precision_index.one_minute then + return precision_index.ten_minutes, 10 + elseif precision == precision_index.ten_minutes then + return precision_index.one_hour, 6 + elseif precision == precision_index.one_hour then + return precision_index.ten_hours, 10 + elseif precision == precision_index.ten_hours then + return precision_index.fifty_hours, 5 + elseif precision == precision_index.fifty_hours then + return precision_index.two_hundred_fifty_hours, 5 + elseif precision == precision_index.two_hundred_fifty_hours then + return precision_index.one_thousand_hours, 4 end end @@ -62,13 +69,20 @@ end -- @treturn[1] defines.flow_precision_index the next precision value -- @treturn[1] number the multiplicive difference between the values function Production.precision_down(precision) - if precision == precision_index.one_minute then return precision_index.five_seconds, 60 - elseif precision == precision_index.ten_minutes then return precision_index.one_minute, 10 - elseif precision == precision_index.one_hour then return precision_index.ten_minutes, 6 - elseif precision == precision_index.ten_hours then return precision_index.one_hour, 10 - elseif precision == precision_index.fifty_hours then return precision_index.ten_hours, 5 - elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.fifty_hours, 5 - elseif precision == precision_index.one_thousand_hours then return precision_index.two_hundred_fifty_hours, 4 + if precision == precision_index.one_minute then + return precision_index.five_seconds, 60 + elseif precision == precision_index.ten_minutes then + return precision_index.one_minute, 10 + elseif precision == precision_index.one_hour then + return precision_index.ten_minutes, 6 + elseif precision == precision_index.ten_hours then + return precision_index.one_hour, 10 + elseif precision == precision_index.fifty_hours then + return precision_index.ten_hours, 5 + elseif precision == precision_index.two_hundred_fifty_hours then + return precision_index.fifty_hours, 5 + elseif precision == precision_index.one_thousand_hours then + return precision_index.two_hundred_fifty_hours, 4 end end @@ -76,14 +90,22 @@ end -- @tparam defines.flow_precision_index precision -- @treturn number the number of ticks in this time function Production.precision_ticks(precision) - if precision == precision_index.five_seconds then return 300 - elseif precision == precision_index.one_minute then return 3600 - elseif precision == precision_index.ten_minutes then return 36000 - elseif precision == precision_index.one_hour then return 216000 - elseif precision == precision_index.ten_hours then return 2160000 - elseif precision == precision_index.fifty_hours then return 10800000 - elseif precision == precision_index.two_hundred_fifty_hours then return 54000000 - elseif precision == precision_index.one_thousand_hours then return 216000000 + if precision == precision_index.five_seconds then + return 300 + elseif precision == precision_index.one_minute then + return 3600 + elseif precision == precision_index.ten_minutes then + return 36000 + elseif precision == precision_index.one_hour then + return 216000 + elseif precision == precision_index.ten_hours then + return 2160000 + elseif precision == precision_index.fifty_hours then + return 10800000 + elseif precision == precision_index.two_hundred_fifty_hours then + return 54000000 + elseif precision == precision_index.one_thousand_hours then + return 216000000 end end @@ -104,11 +126,10 @@ function Production.get_production_total(force, item_name) end return { - made=made, - used=used, - net=made-used + made = made, + used = used, + net = made - used, } - end --- Returns the production data for the given precision game time @@ -120,16 +141,15 @@ function Production.get_production(force, item_name, precision) local made, used = 0, 0 for _, surface in pairs(game.surfaces) do local stats = force.get_item_production_statistics(surface).get_flow_count - made = made + stats{name=item_name, category="input", precision_index=precision} - used = used + stats{name=item_name, category="output", precision_index=precision} + made = made + stats{ name = item_name, category = "input", precision_index = precision } + used = used + stats{ name = item_name, category = "output", precision_index = precision } end return { - made=made, - used=used, - net=made-used + made = made, + used = used, + net = made - used, } - end --- Returns the current fluctuation from the average @@ -143,11 +163,10 @@ function Production.get_fluctuations(force, item_name, precision) local previous = Production.get_production(force, item_name, precision_up) return { - made=(current.made/previous.made)-1, - used=(current.used/previous.used)-1, - net=(current.net/previous.net)-1, + made = (current.made / previous.made) - 1, + used = (current.used / previous.used) - 1, + net = (current.net / previous.net) - 1, } - end --- Returns the amount of ticks required to produce a certain amount @@ -160,7 +179,7 @@ function Production.get_production_eta(force, item_name, precision, required) required = required or 1000 local ticks = Production.precision_ticks(precision) local production = Production.get_production(force, item_name, precision) - return production.made == 0 and -1 or ticks*required/production.made + return production.made == 0 and -1 or ticks * required / production.made end --- Returns the amount of ticks required to consume a certain amount @@ -173,7 +192,7 @@ function Production.get_consumsion_eta(force, item_name, precision, required) required = required or 1000 local ticks = Production.precision_ticks(precision) local production = Production.get_production(force, item_name, precision) - return production.used == 0 and -1 or ticks*required/production.used + return production.used == 0 and -1 or ticks * required / production.used end --- Returns the amount of ticks required to produce but not consume a certain amount @@ -186,7 +205,7 @@ function Production.get_net_eta(force, item_name, precision, required) required = required or 1000 local ticks = Production.precision_ticks(precision) local production = Production.get_production(force, item_name, precision) - return production.net == 0 and -1 or ticks*required/production.net + return production.net == 0 and -1 or ticks * required / production.net end --- Formating. @@ -223,17 +242,16 @@ function Production.format_number(value) local surfix = rtn:sub(-1) if value > 0 then - rtn = '+'..rtn - elseif value == 0 and rtn:sub(1, 1) == '-' then + rtn = "+" .. rtn + elseif value == 0 and rtn:sub(1, 1) == "-" then rtn = rtn:sub(2) end if not tonumber(surfix) then return surfix, rtn:sub(1, -2) else - return '', rtn + return "", rtn end - end -return Production \ No newline at end of file +return Production diff --git a/exp_legacy/module/modules/control/protection.lua b/exp_legacy/module/modules/control/protection.lua index 4e25fe20..a0ad50c7 100644 --- a/exp_legacy/module/modules/control/protection.lua +++ b/exp_legacy/module/modules/control/protection.lua @@ -21,11 +21,11 @@ local EntityProtection = { -- @tparam number player_index the player index of the player who got mined the entities -- @tparam LuaEntity entity the last entity which was mined on_repeat_violation = script.generate_event_name(), - } + }, } -- Convert config tables into lookup tables -for _, config_key in ipairs{'always_protected_names', 'always_protected_types', 'always_trigger_repeat_names', 'always_trigger_repeat_types'} do +for _, config_key in ipairs{ "always_protected_names", "always_protected_types", "always_trigger_repeat_names", "always_trigger_repeat_types" } do local tbl = config[config_key] for key, value in ipairs(tbl) do tbl[key] = nil @@ -49,7 +49,7 @@ local repeats = {} -- Stores repeat removals by players Storage.register({ protected_entities = protected_entities, protected_areas = protected_areas, - repeats = repeats + repeats = repeats, }, function(tbl) protected_entities = tbl.protected_entities protected_areas = tbl.protected_areas @@ -61,12 +61,12 @@ end) --- Get the key used in protected_entities local function get_entity_key(entity) - return string.format('%i,%i', math.floor(entity.position.x), math.floor(entity.position.y)) + return string.format("%i,%i", math.floor(entity.position.x), math.floor(entity.position.y)) end --- Get the key used in protected_areas local function get_area_key(area) - return string.format('%i,%i', math.floor(area.left_top.x), math.floor(area.left_top.y)) + return string.format("%i,%i", math.floor(area.left_top.x), math.floor(area.left_top.y)) end --- Check if an entity is always protected @@ -145,6 +145,7 @@ function EntityProtection.is_position_protected(surface, position) return true end end + return false end @@ -203,4 +204,4 @@ Event.add(defines.events.on_robot_pre_mined, event_remove_entity) Event.add(defines.events.on_entity_died, event_remove_entity) Event.add(defines.events.script_raised_destroy, event_remove_entity) -return EntityProtection \ No newline at end of file +return EntityProtection diff --git a/exp_legacy/module/modules/control/reports.lua b/exp_legacy/module/modules/control/reports.lua index 1ec6ebca..10dbeaa3 100644 --- a/exp_legacy/module/modules/control/reports.lua +++ b/exp_legacy/module/modules/control/reports.lua @@ -30,7 +30,7 @@ local Storage = require("modules/exp_util/storage") local valid_player = Game.get_player_from_any local Reports = { - user_reports={}, -- stores all user reports, global table + user_reports = {}, -- stores all user reports, global table events = { --- When a player is reported -- @event on_player_reported @@ -45,8 +45,8 @@ local Reports = { -- @tparam string removed_by_name the name of the player who removed the report -- @tparam number batch_count the number of reports removed in this batch, always one when not a batch -- @tparam number batch the index of this event in a batch, always one when not a batch - on_report_removed = script.generate_event_name() - } + on_report_removed = script.generate_event_name(), + }, } local user_reports = Reports.user_reports @@ -112,6 +112,7 @@ function Reports.count_reports(player, custom_count) for by_player_name, reason in pairs(reports) do ctn = ctn + custom_count(player, by_player_name, reason) end + return ctn else return table_size(reports) @@ -132,7 +133,7 @@ function Reports.report_player(player, by_player_name, reason) if not player then return end local player_name = player.name - if reason == nil or not reason:find("%S") then reason = 'No reason given' end + if reason == nil or not reason:find("%S") then reason = "No reason given" end local reports = user_reports[player_name] if not reports then @@ -151,7 +152,7 @@ function Reports.report_player(player, by_player_name, reason) tick = game.tick, player_index = player.index, by_player_name = by_player_name, - reason = reason + reason = reason, }) return true @@ -171,7 +172,7 @@ local function report_removed_event(player, reported_by_name, removed_by_name, b reported_by_name = reported_by_name, removed_by_name = removed_by_name, batch_count = batch_count or 1, - batch = batch or 1 + batch = batch or 1, }) end diff --git a/exp_legacy/module/modules/control/rockets.lua b/exp_legacy/module/modules/control/rockets.lua index fddbdaf7..5b914235 100644 --- a/exp_legacy/module/modules/control/rockets.lua +++ b/exp_legacy/module/modules/control/rockets.lua @@ -39,7 +39,7 @@ end local Rockets = { times = {}, stats = {}, - silos = {} + silos = {}, } local rocket_times = Rockets.times @@ -48,7 +48,7 @@ local rocket_silos = Rockets.silos Storage.register({ rocket_times = rocket_times, rocket_stats = rocket_stats, - rocket_silos = rocket_silos + rocket_silos = rocket_silos, }, function(tbl) Rockets.times = tbl.rocket_times Rockets.stats = tbl.rocket_stats @@ -63,7 +63,7 @@ end) -- @treturn table the data table for this silo, contains rockets launch, silo status, and its force function Rockets.get_silo_data(silo) local position = silo.position - local silo_name = math.floor(position.x)..':'..math.floor(position.y) + local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y) return rocket_silos[silo_name] end @@ -99,6 +99,7 @@ function Rockets.get_silos(force_name) table.insert(rtn, silo_data) end end + return rtn end @@ -125,6 +126,7 @@ function Rockets.get_game_rocket_count() for _, force in pairs(game.forces) do rtn = rtn + force.rockets_launched end + return rtn end @@ -139,10 +141,10 @@ function Rockets.get_rolling_average(force_name, count) local last_launch_time = rocket_times[force_name][rocket_count] local start_rocket_time = 0 if count < rocket_count then - start_rocket_time = rocket_times[force_name][rocket_count-count+1] + start_rocket_time = rocket_times[force_name][rocket_count - count + 1] rocket_count = count end - return math.floor((last_launch_time-start_rocket_time)/rocket_count) + return math.floor((last_launch_time - start_rocket_time) / rocket_count) end --- Event used to update the stats and the hui when a rocket is launched @@ -163,8 +165,8 @@ Event.add(defines.events.on_rocket_launched, function(event) if rockets_launched == 1 then stats.first_launch = event.tick stats.fastest_launch = event.tick - elseif event.tick-stats.last_launch < stats.fastest_launch then - stats.fastest_launch = event.tick-stats.last_launch + elseif event.tick - stats.last_launch < stats.fastest_launch then + stats.fastest_launch = event.tick - stats.last_launch end stats.last_launch = event.tick @@ -176,13 +178,13 @@ Event.add(defines.events.on_rocket_launched, function(event) rocket_times[force_name][rockets_launched] = event.tick - local remove_rocket = rockets_launched-largest_rolling_avg + local remove_rocket = rockets_launched - largest_rolling_avg if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then rocket_times[force_name][remove_rocket] = nil end --- Adds this 1 to the launch count for this silo - silo_data.launched = silo_data.launched+1 + silo_data.launched = silo_data.launched + 1 end) --- When a launch is reiggered it will await reset @@ -195,19 +197,19 @@ end) --- Adds a silo to the list when it is built local function on_built(event) local entity = event.created_entity - if entity.valid and entity.name == 'rocket-silo' then + if entity.valid and entity.name == "rocket-silo" then local force = entity.force local force_name = force.name local position = entity.position - local silo_name = math.floor(position.x)..':'..math.floor(position.y) + local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y) rocket_silos[silo_name] = { - name=silo_name, - force=force_name, - entity=entity, - launched=0, - awaiting_reset=false, - built=game.tick + name = silo_name, + force = force_name, + entity = entity, + launched = 0, + awaiting_reset = false, + built = game.tick, } end end @@ -215,4 +217,4 @@ end Event.add(defines.events.on_built_entity, on_built) Event.add(defines.events.on_robot_built_entity, on_built) -return Rockets \ No newline at end of file +return Rockets diff --git a/exp_legacy/module/modules/control/selection.lua b/exp_legacy/module/modules/control/selection.lua index f127a708..dba2353b 100644 --- a/exp_legacy/module/modules/control/selection.lua +++ b/exp_legacy/module/modules/control/selection.lua @@ -18,14 +18,14 @@ local Selection = { -- @tparam number player_index the player index of the player who left selection mode -- @tparam string selection the name of the selection which ended on_player_selection_end = script.generate_event_name(), - } + }, } -local selection_tool = { name='selection-tool' } +local selection_tool = { name = "selection-tool" } local selections = {} Storage.register({ - selections = selections + selections = selections, }, function(tbl) selections = tbl.selections end) @@ -42,7 +42,7 @@ function Selection.start(player, selection_name, single_use, ...) name = Selection.events.on_player_selection_end, tick = game.tick, player_index = player.index, - selection = selections[player.index].name + selection = selections[player.index].name, }) end @@ -51,7 +51,7 @@ function Selection.start(player, selection_name, single_use, ...) name = selection_name, arguments = { ... }, single_use = single_use == true, - character = player.character + character = player.character, } -- Raise the event @@ -59,7 +59,7 @@ function Selection.start(player, selection_name, single_use, ...) name = Selection.events.on_player_selection_start, tick = game.tick, player_index = player.index, - selection = selection_name + selection = selection_name, }) -- Give a selection tool if one is not in use @@ -86,7 +86,7 @@ function Selection.stop(player) name = Selection.events.on_player_selection_end, tick = game.tick, player_index = player.index, - selection = selection + selection = selection, }) -- Remove the selection tool @@ -146,7 +146,7 @@ end --- Stop selection if the selection tool is removed from the cursor Event.add(defines.events.on_player_cursor_stack_changed, function(event) - local player = game.get_player(event.player_index) ---@cast player -nil + local player = game.get_player(event.player_index) --- @cast player -nil if player.cursor_stack.is_selection_tool then return end Selection.stop(player) end) @@ -169,4 +169,4 @@ end Event.add(defines.events.on_player_selected_area, stop_after_use) Event.add(defines.events.on_player_alt_selected_area, stop_after_use) -return Selection \ No newline at end of file +return Selection diff --git a/exp_legacy/module/modules/control/spectate.lua b/exp_legacy/module/modules/control/spectate.lua index 96d937cd..371c014c 100644 --- a/exp_legacy/module/modules/control/spectate.lua +++ b/exp_legacy/module/modules/control/spectate.lua @@ -1,4 +1,3 @@ - local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Storage = require("modules/exp_util/storage") local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui @@ -12,7 +11,7 @@ local Public = {} ----- Storage data ----- Storage.register({ following = following, - spectating = spectating + spectating = spectating, }, function(tbl) following = tbl.following spectating = tbl.spectating @@ -24,7 +23,7 @@ end) -- @tparam LuaPlayer player The player to test the controller type of -- @treturn boolean Returns true if the player is in spectator mode function Public.is_spectating(player) - assert(player and player.valid, 'Invalid player given to follower') + assert(player and player.valid, "Invalid player given to follower") return player.controller_type == defines.controllers.spectator end @@ -32,7 +31,7 @@ end -- @tparam LuaPlayer player The player that will be placed into spectator mode -- @treturn boolean Returns false if the player was already in spectator mode function Public.start_spectate(player) - assert(player and player.valid, 'Invalid player given to follower') + assert(player and player.valid, "Invalid player given to follower") if spectating[player.index] or not player.character then return false end local character = player.character local opened = player.opened @@ -46,7 +45,7 @@ end --- Return a player from spectator mode back to their character, if their character was killed then respawn them -- @tparam LuaPlayer player The player that will leave spectator mode function Public.stop_spectate(player) - assert(player and player.valid, 'Invalid player given to follower') + assert(player and player.valid, "Invalid player given to follower") local character = spectating[player.index] spectating[player.index] = nil if character and character.valid then @@ -63,7 +62,7 @@ end -- @tparam LuaPlayer player The player to test the follow mode of -- @treturn boolean Returns true if the player is in follow mode function Public.is_following(player) - assert(player and player.valid, 'Invalid player given to follower') + assert(player and player.valid, "Invalid player given to follower") return following[player.index] ~= nil end @@ -71,8 +70,8 @@ end -- @tparam LuaPlayer player The player that will follow the entity -- @tparam ?LuaPlayer|LuaEntity entity The player or entity that will be followed function Public.start_follow(player, entity) - assert(player and player.valid, 'Invalid player given to follower') - assert(entity and entity.valid, 'Invalid entity given to follower') + assert(player and player.valid, "Invalid player given to follower") + assert(entity and entity.valid, "Invalid entity given to follower") local spectate = Public.start_spectate(player) player.close_map() @@ -84,7 +83,7 @@ end --- Returns camera control to the player, will return a player to their character if start_follow placed them into spectator mode -- @tparam LuaPlayer player The player that will regain control of their camera function Public.stop_follow(player) - assert(player and player.valid, 'Invalid player given to follower') + assert(player and player.valid, "Invalid player given to follower") if following[player.index] and following[player.index][4] and Public.is_spectating(player) then Public.stop_spectate(player) end @@ -105,32 +104,32 @@ end --- Label used to show that the player is following, also used to allow esc to stop following -- @element follow_label follow_label = -Gui.element(function(definition, parent, target) - Gui.destroy_if_valid(parent[definition.name]) + Gui.element(function(definition, parent, target) + Gui.destroy_if_valid(parent[definition.name]) - local label = parent.add{ - type = 'label', - style = 'frame_title', - caption = 'Following '..target.name..'.\nClick here or press esc to stop following.', - name = definition.name - } + local label = parent.add{ + type = "label", + style = "frame_title", + caption = "Following " .. target.name .. ".\nClick here or press esc to stop following.", + name = definition.name, + } - local player = Gui.get_player_from_element(parent) - local res = player.display_resolution - label.location = {0, res.height-150} - label.style.width = res.width - label.style.horizontal_align = 'center' - player.opened = label + local player = Gui.get_player_from_element(parent) + local res = player.display_resolution + label.location = { 0, res.height - 150 } + label.style.width = res.width + label.style.horizontal_align = "center" + player.opened = label - return label -end) -:static_name(Gui.unique_static_name) -:on_click(Public.stop_follow) -:on_close(function(player) - -- Don't call set_controller during on_close as it invalidates the controller - -- Setting an invalid position (as to not equal their current) will call stop_follow on the next tick - following[player.index][3] = {} -end) + return label + end) + :static_name(Gui.unique_static_name) + :on_click(Public.stop_follow) + :on_close(function(player) + -- Don't call set_controller during on_close as it invalidates the controller + -- Setting an invalid position (as to not equal their current) will call stop_follow on the next tick + following[player.index][3] = {} + end) ----- Events ----- @@ -170,4 +169,4 @@ Event.add(defines.events.on_pre_player_left_game, function(event) end) ----- Module Return ----- -return Public \ No newline at end of file +return Public diff --git a/exp_legacy/module/modules/control/tasks.lua b/exp_legacy/module/modules/control/tasks.lua index 19e66425..9489a955 100644 --- a/exp_legacy/module/modules/control/tasks.lua +++ b/exp_legacy/module/modules/control/tasks.lua @@ -14,13 +14,13 @@ local Datastore = require("modules.exp_legacy.expcore.datastore") --- @dep expco local Storage = require("modules/exp_util/storage") --- Stores all data for the warp gui -local TaskData = Datastore.connect('TaskData') +local TaskData = Datastore.connect("TaskData") TaskData:set_serializer(function(raw_key) return raw_key.task_id end) local Tasks = {} -- Storage lookup table for force name to task ids -local force_tasks = {_uid=1} +local force_tasks = { _uid = 1 } Storage.register(force_tasks, function(tbl) force_tasks = tbl end) @@ -59,11 +59,11 @@ function Tasks.add_task(force_name, player_name, task_title, task_body) TaskData:set(task_id, { task_id = task_id, force_name = force_name, - title = task_title or '', - body = task_body or '', - last_edit_name = player_name or '', + title = task_title or "", + body = task_body or "", + last_edit_name = player_name or "", last_edit_time = game.tick, - currently_editing = {} + currently_editing = {}, }) return task_id diff --git a/exp_legacy/module/modules/control/vlayer.lua b/exp_legacy/module/modules/control/vlayer.lua index b7b87dd4..757aee69 100644 --- a/exp_legacy/module/modules/control/vlayer.lua +++ b/exp_legacy/module/modules/control/vlayer.lua @@ -17,22 +17,22 @@ local vlayer_data = { energy = {}, circuit = {}, storage_input = {}, - storage_output = {} + storage_output = {}, }, properties = { total_surface_area = 0, used_surface_area = 0, production = 0, discharge = 0, - capacity = 0 + capacity = 0, }, storage = { items = {}, power_items = {}, energy = 0, - unallocated = {} + unallocated = {}, }, - surface = table.deep_copy(config.surface) + surface = table.deep_copy(config.surface), } Storage.register(vlayer_data, function(tbl) @@ -45,7 +45,7 @@ for name, properties in pairs(config.allowed_items) do if properties.power then vlayer_data.storage.power_items[name] = { value = properties.fuel_value * 1000000, - count = 0 + count = 0, } end end @@ -61,7 +61,7 @@ for item_name, properties in pairs(config.modded_items) do surface_area = (base_properties.surface_area or 0) * m, production = (base_properties.production or 0) * m, capacity = (base_properties.capacity or 0) * m, - modded = true + modded = true, } end @@ -133,7 +133,7 @@ end --[[ 25,000 / 416 s 昼 208秒 ソーラー効率100% - 夕方 83秒 1秒ごとにソーラー発電量が約1.2%ずつ下がり、やがて0%になる + 夕方 83秒 1秒ごとにソーラー発電量が約1.2%ずつ下がり、やがて0%になる 夜 41秒 ソーラー発電量が0%になる 朝方 83秒 1秒ごとにソーラー発電量が約1.2%ずつ上がり、やがて100%になる @@ -160,7 +160,6 @@ local function get_production_multiplier() if brightness >= surface.min_brightness then return mul * (brightness - surface.min_brightness) / (1 - surface.min_brightness) - else return 0 end @@ -173,16 +172,12 @@ local function get_production_multiplier() if daytime <= surface.dusk then -- Noon to Sunset return mul - elseif daytime <= surface.evening then -- Sunset to Night return mul * (1 - ((daytime - surface.dusk) / (surface.evening - surface.dusk))) - elseif daytime <= surface.morning then -- Night to Sunrise return 0 - elseif daytime <= surface.dawn then -- Sunrise to Morning return mul * ((surface.daytime - surface.morning) / (surface.dawn - surface.morning)) - else -- Morning to Noon return mul end @@ -214,7 +209,7 @@ end -- @tparam number count The count of the item to allocate function vlayer.allocate_item(item_name, count) local item_properties = config.allowed_items[item_name] - assert(item_properties, 'Item not allowed in vlayer: ' .. tostring(item_name)) + assert(item_properties, "Item not allowed in vlayer: " .. tostring(item_name)) if item_properties.production then vlayer_data.properties.production = vlayer_data.properties.production + item_properties.production * count @@ -253,7 +248,7 @@ end -- @tparam number count The count of the item to insert function vlayer.insert_item(item_name, count) local item_properties = config.allowed_items[item_name] - assert(item_properties, 'Item not allowed in vlayer: ' .. tostring(item_name)) + assert(item_properties, "Item not allowed in vlayer: " .. tostring(item_name)) vlayer_data.storage.items[item_name] = vlayer_data.storage.items[item_name] + count if not config.unlimited_surface_area and item_properties.required_area and item_properties.required_area > 0 then @@ -266,7 +261,6 @@ function vlayer.insert_item(item_name, count) end vlayer_data.storage.unallocated[item_name] = vlayer_data.storage.unallocated[item_name] + count - allocate_count - else vlayer.allocate_item(item_name, count) end @@ -279,7 +273,7 @@ end -- @treturn number The count of the item actually removed function vlayer.remove_item(item_name, count) local item_properties = config.allowed_items[item_name] - assert(item_properties, 'Item not allowed in vlayer: ' .. tostring(item_name)) + assert(item_properties, "Item not allowed in vlayer: " .. tostring(item_name)) local remove_unallocated = 0 if not config.unlimited_surface_area and item_properties.required_area and item_properties.required_area > 0 then @@ -325,7 +319,7 @@ end -- @tparam[opt] LuaPlayer player The player to show as the last user of the interface -- @treturn LuaEntity The entity that was created for the interface function vlayer.create_input_interface(surface, position, circuit, last_user) - local interface = surface.create_entity{name='logistic-chest-storage', position=position, force='neutral'} + local interface = surface.create_entity{ name = "logistic-chest-storage", position = position, force = "neutral" } table.insert(vlayer_data.entity_interfaces.storage_input, interface) if last_user then @@ -335,7 +329,7 @@ function vlayer.create_input_interface(surface, position, circuit, last_user) if circuit then for k, _ in pairs(circuit) do for _, v in pairs(circuit[k]) do - interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v}) + interface.connect_neighbour{ wire = defines.wire_type[k], target_entity = v } end end end @@ -352,7 +346,6 @@ local function handle_input_interfaces() for index, interface in pairs(vlayer_data.entity_interfaces.storage_input) do if not interface.valid then vlayer_data.entity_interfaces.storage_input[index] = nil - else local inventory = interface.get_inventory(defines.inventory.chest) @@ -361,21 +354,18 @@ local function handle_input_interfaces() if config.allowed_items[name].modded then if config.modded_auto_downgrade then vlayer.insert_item(config.modded_items[name].base_game_equivalent, count * config.modded_items[name].multiplier) - else vlayer.insert_item(name, count) end - else if vlayer_data.storage.power_items[name] then vlayer_data.storage.power_items[name].count = vlayer_data.storage.power_items[name].count + count - else vlayer.insert_item(name, count) end end - inventory.remove({name=name, count=count}) + inventory.remove{ name = name, count = count } end end end @@ -388,7 +378,7 @@ end -- @tparam[opt] LuaPlayer player The player to show as the last user of the interface -- @treturn LuaEntity The entity that was created for the interface function vlayer.create_output_interface(surface, position, circuit, last_user) - local interface = surface.create_entity{name='logistic-chest-requester', position=position, force='neutral'} + local interface = surface.create_entity{ name = "logistic-chest-requester", position = position, force = "neutral" } table.insert(vlayer_data.entity_interfaces.storage_output, interface) if last_user then @@ -398,7 +388,7 @@ function vlayer.create_output_interface(surface, position, circuit, last_user) if circuit then for k, _ in pairs(circuit) do for _, v in pairs(circuit[k]) do - interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v}) + interface.connect_neighbour{ wire = defines.wire_type[k], target_entity = v } end end end @@ -415,7 +405,6 @@ local function handle_output_interfaces() for index, interface in pairs(vlayer_data.entity_interfaces.storage_output) do if not interface.valid then vlayer_data.entity_interfaces.storage_output[index] = nil - else local inventory = interface.get_inventory(defines.inventory.chest) @@ -426,11 +415,11 @@ local function handle_output_interfaces() local current_amount = inventory.get_item_count(request.name) local request_amount = math.min(request.count - current_amount, vlayer_data.storage.items[request.name]) - if request_amount > 0 and inventory.can_insert({name=request.name, count=request_amount}) then + if request_amount > 0 and inventory.can_insert{ name = request.name, count = request_amount } then local removed_item_count = vlayer.remove_item(request.name, request_amount) if removed_item_count > 0 then - inventory.insert({name=request.name, count=removed_item_count}) + inventory.insert{ name = request.name, count = removed_item_count } end end end @@ -488,7 +477,7 @@ function vlayer.get_statistics() energy_storage = vlayer_data.storage.energy, day_time = math.floor(vlayer_data.surface.daytime * vlayer_data.surface.ticks_per_day), day_length = vlayer_data.surface.ticks_per_day, - tick = game.tick + tick = game.tick, } end @@ -500,17 +489,17 @@ end --- Circuit signals used for the statistics function vlayer.get_circuits() return { - total_surface_area = 'signal-A', - used_surface_area = 'signal-U', - remaining_surface_area = 'signal-R', - production_multiplier = 'signal-M', - energy_production = 'signal-P', - energy_sustained = 'signal-S', - energy_capacity = 'signal-C', - energy_storage = 'signal-E', - day_time = 'signal-D', - day_length = 'signal-L', - tick = 'signal-T', + total_surface_area = "signal-A", + used_surface_area = "signal-U", + remaining_surface_area = "signal-R", + production_multiplier = "signal-M", + energy_production = "signal-P", + energy_sustained = "signal-S", + energy_capacity = "signal-C", + energy_storage = "signal-E", + day_time = "signal-D", + day_length = "signal-L", + tick = "signal-T", } end @@ -520,7 +509,7 @@ end -- @tparam[opt] LuaPlayer player The player to show as the last user of the interface -- @treturn LuaEntity The entity that was created for the interface function vlayer.create_circuit_interface(surface, position, circuit, last_user) - local interface = surface.create_entity{name='constant-combinator', position=position, force='neutral'} + local interface = surface.create_entity{ name = "constant-combinator", position = position, force = "neutral" } table.insert(vlayer_data.entity_interfaces.circuit, interface) if last_user then @@ -530,7 +519,7 @@ function vlayer.create_circuit_interface(surface, position, circuit, last_user) if circuit then for k, _ in pairs(circuit) do for _, v in pairs(circuit[k]) do - interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v}) + interface.connect_neighbour{ wire = defines.wire_type[k], target_entity = v } end end end @@ -549,7 +538,6 @@ local function handle_circuit_interfaces() for index, interface in pairs(vlayer_data.entity_interfaces.circuit) do if not interface.valid then vlayer_data.entity_interfaces.circuit[index] = nil - else local circuit_oc = interface.get_or_create_control_behavior() local max_signals = circuit_oc.signals_count @@ -558,14 +546,12 @@ local function handle_circuit_interfaces() -- Set the virtual signals based on the vlayer stats for stat_name, signal_name in pairs(circuit) do - if stat_name:find('energy') then - circuit_oc.set_signal(signal_index, {signal={type='virtual', name=signal_name}, count=math.floor(stats[stat_name] / mega)}) - - elseif stat_name == 'production_multiplier' then - circuit_oc.set_signal(signal_index, {signal={type='virtual', name=signal_name}, count=math.floor(stats[stat_name] * 10000)}) - + if stat_name:find("energy") then + circuit_oc.set_signal(signal_index, { signal = { type = "virtual", name = signal_name }, count = math.floor(stats[stat_name] / mega) }) + elseif stat_name == "production_multiplier" then + circuit_oc.set_signal(signal_index, { signal = { type = "virtual", name = signal_name }, count = math.floor(stats[stat_name] * 10000) }) else - circuit_oc.set_signal(signal_index, {signal={type='virtual', name=signal_name}, count=math.floor(stats[stat_name])}) + circuit_oc.set_signal(signal_index, { signal = { type = "virtual", name = signal_name }, count = math.floor(stats[stat_name]) }) end signal_index = signal_index + 1 @@ -574,7 +560,7 @@ local function handle_circuit_interfaces() -- Set the item signals based on stored items for item_name, count in pairs(vlayer_data.storage.items) do if prototypes.item[item_name] and count > 0 then - circuit_oc.set_signal(signal_index, {signal={type='item', name=item_name}, count=count}) + circuit_oc.set_signal(signal_index, { signal = { type = "item", name = item_name }, count = count }) signal_index = signal_index + 1 if signal_index > max_signals then return -- No more signals can be added @@ -600,11 +586,11 @@ end -- @tparam[opt] LuaPlayer player The player to show as the last user of the interface -- @treturn LuaEntity The entity that was created for the interface, or nil if it could not be created function vlayer.create_energy_interface(surface, position, last_user) - if not surface.can_place_entity{name='electric-energy-interface', position=position} then + if not surface.can_place_entity{ name = "electric-energy-interface", position = position } then return nil end - local interface = surface.create_entity{name='electric-energy-interface', position=position, force='neutral'} + local interface = surface.create_entity{ name = "electric-energy-interface", position = position, force = "neutral" } table.insert(vlayer_data.entity_interfaces.energy, interface) if last_user then @@ -635,7 +621,6 @@ local function handle_energy_interfaces() for index, interface in pairs(vlayer_data.entity_interfaces.energy) do if not interface.valid then vlayer_data.entity_interfaces.energy[index] = nil - else available_energy = available_energy + interface.energy end @@ -657,7 +642,7 @@ local function handle_energy_interfaces() if not config.unlimited_capacity and vlayer_data.storage.energy > vlayer_data.properties.capacity * mega then vlayer_data.storage.energy = vlayer_data.properties.capacity * mega - -- burn the trash to produce power + -- burn the trash to produce power elseif vlayer_data.storage.power_items then for k, v in pairs(vlayer_data.storage.power_items) do local max_burning = (vlayer_data.properties.capacity * mega / 2) - vlayer_data.storage.energy @@ -679,11 +664,11 @@ end -- @treturn MapPosition The position the interface was at, or nil if no interface was found function vlayer.remove_interface(surface, position) local entities = surface.find_entities_filtered{ - name = {'logistic-chest-storage', 'logistic-chest-requester', 'constant-combinator', 'electric-energy-interface'}, - force = 'neutral', + name = { "logistic-chest-storage", "logistic-chest-requester", "constant-combinator", "electric-energy-interface" }, + force = "neutral", position = position, radius = 2, - limit = 1 + limit = 1, } -- Get the details which will be returned @@ -696,32 +681,29 @@ function vlayer.remove_interface(surface, position) local pos = interface.position -- Return the type of interface removed and do some clean up - if name == 'logistic-chest-storage' then + if name == "logistic-chest-storage" then move_items_stack(interface.get_inventory(defines.inventory.chest).get_contents()) table.remove_element(vlayer_data.entity_interfaces.storage_input, interface) interface.destroy() - return 'storage-input', pos - - elseif name == 'logistic-chest-requester' then + return "storage-input", pos + elseif name == "logistic-chest-requester" then move_items_stack(interface.get_inventory(defines.inventory.chest).get_contents()) table.remove_element(vlayer_data.entity_interfaces.storage_output, interface) interface.destroy() - return 'storage-output', pos - - elseif name == 'constant-combinator' then + return "storage-output", pos + elseif name == "constant-combinator" then table.remove_element(vlayer_data.entity_interfaces.circuit, interface) interface.destroy() - return 'circuit', pos - - elseif name == 'electric-energy-interface' then + return "circuit", pos + elseif name == "electric-energy-interface" then vlayer_data.storage.energy = vlayer_data.storage.energy + interface.energy table.remove_element(vlayer_data.entity_interfaces.energy, interface) interface.destroy() - return 'energy', pos + return "energy", pos end end diff --git a/exp_legacy/module/modules/control/warnings.lua b/exp_legacy/module/modules/control/warnings.lua index ca7e0ff7..53f467ad 100644 --- a/exp_legacy/module/modules/control/warnings.lua +++ b/exp_legacy/module/modules/control/warnings.lua @@ -30,19 +30,20 @@ local valid_player = Game.get_player_from_any --- Stores the quickbar filters for a player local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local PlayerWarnings = PlayerData.Required:combine('Warnings') +local PlayerWarnings = PlayerData.Required:combine("Warnings") PlayerWarnings:set_metadata{ stringify = function(value) - if not value then return 'You have no warnings' end + if not value then return "You have no warnings" end local count = 0 for _ in pairs(value) do count = count + 1 end - return 'You have '..count..' warnings' - end + + return "You have " .. count .. " warnings" + end, } local Warnings = { - user_warnings=PlayerWarnings, - user_script_warnings={}, + user_warnings = PlayerWarnings, + user_script_warnings = {}, events = { --- When a warning is added to a player -- @event on_warning_added @@ -71,7 +72,7 @@ local Warnings = { -- @tparam number player_index the index of the player who is having the warning removed -- @tparam number warning_count the new number of warnings that the player has on_script_warning_removed = script.generate_event_name(), - } + }, } local user_script_warnings = Warnings.user_script_warnings @@ -105,18 +106,18 @@ function Warnings.add_warning(player, by_player_name, reason) if not player then return end if not by_player_name then return end - reason = reason or 'None given.' + reason = reason or "None given." local warning_count PlayerWarnings:update(player.name, function(_, warnings) local warning = { by_player_name = by_player_name, - reason = reason + reason = reason, } if not warnings then warning_count = 1 - return {warning} + return { warning } else table.insert(warnings, warning) warning_count = #warnings @@ -129,20 +130,20 @@ function Warnings.add_warning(player, by_player_name, reason) player_index = player.index, warning_count = warning_count, by_player_name = by_player_name, - reason = reason + reason = reason, }) local action = config.actions[warning_count] if action then local _type = type(action) - if _type == 'function' then + if _type == "function" then action(player, by_player_name, warning_count) - elseif _type == 'table' then + elseif _type == "table" then local current = table.deepcopy(action) - table.insert(current, 2,by_player_name) - table.insert(current, 3,warning_count) + table.insert(current, 2, by_player_name) + table.insert(current, 3, warning_count) player.print(current) - elseif type(action) == 'string' then + elseif type(action) == "string" then player.print(action) end end @@ -166,7 +167,7 @@ local function warning_removed_event(player, warning_by_name, removed_by_name, w warning_by_name = warning_by_name, removed_by_name = removed_by_name, batch_count = batch_count or 1, - batch = batch or 1 + batch = batch or 1, }) end @@ -206,7 +207,7 @@ function Warnings.clear_warnings(player, by_player_name) local warning_count = #warnings for n, warning in pairs(warnings) do - warning_removed_event(player, warning.by_player_name, by_player_name, warning_count-n, n, warning_count) + warning_removed_event(player, warning.by_player_name, by_player_name, warning_count - n, n, warning_count) end PlayerWarnings:remove(player) @@ -236,7 +237,7 @@ function Warnings.add_script_warning(player, reason) player = valid_player(player) if not player then return end - reason = reason or 'Non given.' + reason = reason or "Non given." local warnings = user_script_warnings[player.name] if not warnings then @@ -246,7 +247,7 @@ function Warnings.add_script_warning(player, reason) table.insert(warnings, { tick = game.tick, - reason = reason + reason = reason, }) local warning_count = #warnings @@ -256,11 +257,11 @@ function Warnings.add_script_warning(player, reason) tick = game.tick, player_index = player.index, warning_count = warning_count, - reason = reason + reason = reason, }) if warning_count > config.script_warning_limit then - Warnings.add_warning(player, '', reason) + Warnings.add_warning(player, "", reason) end return warning_count @@ -274,7 +275,7 @@ local function script_warning_removed_event(player, warning_count) name = Warnings.events.on_script_warning_removed, tick = game.tick, player_index = player.index, - warning_count = warning_count + warning_count = warning_count, }) end @@ -306,7 +307,7 @@ function Warnings.clear_script_warnings(player) local warning_count = #warnings for n, _ in pairs(warnings) do - script_warning_removed_event(player, warning_count-n) + script_warning_removed_event(player, warning_count - n) end user_script_warnings[player.name] = nil @@ -314,8 +315,8 @@ function Warnings.clear_script_warnings(player) end -- script warnings are removed after a certain amount of time to make them even more lienient -local script_warning_cool_down = config.script_warning_cool_down*3600 -Event.on_nth_tick(script_warning_cool_down/4, function() +local script_warning_cool_down = config.script_warning_cool_down * 3600 +Event.on_nth_tick(script_warning_cool_down / 4, function() local cutoff = game.tick - script_warning_cool_down for player_name, script_warnings in pairs(user_script_warnings) do if #script_warnings > 0 then @@ -328,4 +329,4 @@ Event.on_nth_tick(script_warning_cool_down/4, function() end end) -return Warnings \ No newline at end of file +return Warnings diff --git a/exp_legacy/module/modules/control/warps.lua b/exp_legacy/module/modules/control/warps.lua index 038b3b0a..9ada9f1d 100644 --- a/exp_legacy/module/modules/control/warps.lua +++ b/exp_legacy/module/modules/control/warps.lua @@ -26,14 +26,14 @@ local Storage = require("modules/exp_util/storage") local config = require("modules.exp_legacy.config.gui.warps") --- @dep config.warps --- Stores all data for the warp system -local WrapData = Datastore.connect('WrapData') +local WrapData = Datastore.connect("WrapData") WrapData:set_serializer(function(raw_key) return raw_key.warp_id end) local Warps = {} -- Storage lookup table for force name to task ids -local force_warps = {_uid=1} ----@cast force_warps table +local force_warps = { _uid = 1 } +--- @cast force_warps table Storage.register(force_warps, function(tbl) force_warps = tbl end) @@ -65,13 +65,13 @@ WrapData:on_update(function(warp_id, warp, old_warp) for _, next_warp_id in pairs(warp_ids) do local next_warp = WrapData:get(next_warp_id) if next_warp_id ~= spawn_id then - warp_names[next_warp.name..next_warp_id] = next_warp_id + warp_names[next_warp.name .. next_warp_id] = next_warp_id end end -- Sort the warp names in alphabetical order local new_warp_ids = table.get_values(table.keysort(warp_names)) - table.insert(new_warp_ids, 1,spawn_id) + table.insert(new_warp_ids, 1, spawn_id) new_warp_ids.spawn = spawn_id force_warps[force_name] = new_warp_ids end @@ -98,7 +98,7 @@ function Warps.make_warp_tag(warp_id) local tag = warp.tag if tag and tag.valid then - tag.text = 'Warp: ' .. name + tag.text = "Warp: " .. name tag.icon = icon return false end @@ -109,9 +109,9 @@ function Warps.make_warp_tag(warp_id) local position = warp.position tag = force.add_chart_tag(surface, { - position = {position.x+0.5, position.y+0.5}, - text = 'Warp: ' .. name, - icon = icon + position = { position.x + 0.5, position.y + 0.5 }, + text = "Warp: " .. name, + icon = icon, }) -- Add the tag to this warp, store.update not needed as we dont want it to trigger @@ -165,16 +165,17 @@ function Warps.make_warp_area(warp_id) -- Add a tile pattern on top of the base local tiles = {} for _, tile in pairs(config.tiles) do - table.insert(tiles, {name=tile[1], position={tile[2]+posx, tile[3]+posy}}) + table.insert(tiles, { name = tile[1], position = { tile[2] + posx, tile[3] + posy } }) end + surface.set_tiles(tiles) -- Add entities to the warp structure for _, entity in pairs(config.entities) do entity = surface.create_entity{ - name=entity[1], - position={entity[2]+posx, entity[3]+posy}, - force='neutral' + name = entity[1], + position = { entity[2] + posx, entity[3] + posy }, + force = "neutral", } entity.destructible = false entity.health = 0 @@ -182,7 +183,7 @@ function Warps.make_warp_area(warp_id) entity.rotatable = false -- Save reference of the last power pole - if entity.type == 'electric-pole' then + if entity.type == "electric-pole" then warp.electric_pole = entity end end @@ -209,18 +210,18 @@ function Warps.remove_warp_area(warp_id) local tiles = {} for _, tile in pairs(config.tiles) do - table.insert(tiles, {name=old_tile, position={tile[2]+position.x, tile[3]+position.y}}) + table.insert(tiles, { name = old_tile, position = { tile[2] + position.x, tile[3] + position.y } }) end surface.set_tiles(tiles) local area = { - {position.x-radius, position.y-radius}, - {position.x+radius, position.y+radius} + { position.x - radius, position.y - radius }, + { position.x + radius, position.y + radius }, } -- Remove warp structure entities - local entities = surface.find_entities_filtered{ force='neutral', area=area, name = remove_warp_area_entity_names } + local entities = surface.find_entities_filtered{ force = "neutral", area = area, name = remove_warp_area_entity_names } for _, entity in pairs(entities) do -- Destroy them, this will leave corpses of the entities that it destroyed. if entity and entity.valid and entity.destructible == false then @@ -228,6 +229,7 @@ function Warps.remove_warp_area(warp_id) entity.die(entity.force) end end + -- Rechart map area, useful if warp is not covered by a radar game.forces[warp.force_name].chart(surface, area) end @@ -269,8 +271,8 @@ function Warps.teleport_player(warp_id, player) local warp = WrapData:get(warp_id) local surface = warp.surface local position = { - x=warp.position.x+0.5, - y=warp.position.y+0.5 + x = warp.position.x + 0.5, + y = warp.position.y + 0.5, } if player.vehicle then @@ -285,13 +287,13 @@ function Warps.teleport_player(warp_id, player) if not entity.teleport(goto_position) then player.driving = false -- Need to calculate new goto_position because entities have different collision boxes - goto_position = surface.find_non_colliding_position('character', position, 32, 1) + goto_position = surface.find_non_colliding_position("character", position, 32, 1) player.teleport(goto_position, surface) end end else -- Teleport the player - local goto_position = surface.find_non_colliding_position('character', position, 32, 1) + local goto_position = surface.find_non_colliding_position("character", position, 32, 1) if player.driving then player.driving = false end player.teleport(goto_position, surface) end @@ -318,7 +320,7 @@ function Warps.add_warp(force_name, surface, position, player_name, warp_name) -- Get new warp id local warp_id = tostring(force_warps._uid) force_warps._uid = force_warps._uid + 1 - warp_name = warp_name or 'New warp' + warp_name = warp_name or "New warp" -- Get the existing warps for this force local warp_ids = force_warps[force_name] @@ -345,9 +347,9 @@ function Warps.add_warp(force_name, surface, position, player_name, warp_name) surface = surface, position = { x = math.floor(position.x), - y = math.floor(position.y) + y = math.floor(position.y), }, - last_edit_name = player_name or '', + last_edit_name = player_name or "", last_edit_time = game.tick, currently_editing = editing, updates = 0, @@ -389,7 +391,7 @@ function Warps.update_warp(warp_id, new_name, new_icon, player_name) new_icon = warp.icon end - warp.last_edit_name = player_name or '' + warp.last_edit_name = player_name or "" warp.last_edit_time = game.tick warp.name = new_name or warp.name warp.icon = new_icon or warp.icon diff --git a/exp_legacy/module/modules/data/alt-view.lua b/exp_legacy/module/modules/data/alt-view.lua index 518a514f..8a8a2cf9 100644 --- a/exp_legacy/module/modules/data/alt-view.lua +++ b/exp_legacy/module/modules/data/alt-view.lua @@ -1,14 +1,14 @@ --- Stores if you use alt mode or not and auto applies it -- @data Alt-View -local Event = require("modules/exp_legacy/utils/event") ---@dep utils.event +local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event --- Stores the visible state of alt mode local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local UsesAlt = PlayerData.Settings:combine('UsesAlt') +local UsesAlt = PlayerData.Settings:combine("UsesAlt") UsesAlt:set_default(false) UsesAlt:set_metadata{ - stringify = function(value) return value and 'Visible' or 'Hidden' end + stringify = function(value) return value and "Visible" or "Hidden" end, } --- When your data loads apply alt view if you have it enabled @@ -21,4 +21,4 @@ end) Event.add(defines.events.on_player_toggled_alt_mode, function(event) local player = game.players[event.player_index] UsesAlt:set(player, player.game_view_settings.show_entity_info) -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/data/bonus.lua b/exp_legacy/module/modules/data/bonus.lua index ae4dfa61..3ace723d 100644 --- a/exp_legacy/module/modules/data/bonus.lua +++ b/exp_legacy/module/modules/data/bonus.lua @@ -11,17 +11,17 @@ require("modules.exp_legacy.config.expcore.command_general_parse") -- Stores the bonus for the player local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local PlayerBonus = PlayerData.Settings:combine('Bonus') +local PlayerBonus = PlayerData.Settings:combine("Bonus") PlayerBonus:set_default(0) PlayerBonus:set_metadata{ - permission = 'command/bonus', + permission = "command/bonus", stringify = function(value) if not value or value == 0 then - return 'None set' + return "None set" end return value - end + end, } --- Apply a bonus to a player @@ -34,7 +34,7 @@ local function apply_bonus(player, stage) player[k] = v.value * stage / 10 if v.combined_bonus then - for i=1, #v.combined_bonus, 1 do + for i = 1, #v.combined_bonus, 1 do player[v.combined_bonus[i]] = v.value * stage / 10 end end @@ -49,18 +49,18 @@ end) --- Changes the amount of bonus you receive -- @command bonus -- @tparam number amount range 0-10 the increase for your bonus -Commands.new_command('bonus', {'expcom-bonus.description'}, 'Changes the amount of bonus you receive') -:add_param('amount', 'integer-range', 0, 10) -:register(function(player, amount) - if not Roles.player_allowed(player, 'command/bonus') then - Commands.print{'expcom-bonus.perm', 1} - return - end +Commands.new_command("bonus", "Changes the amount of bonus you receive") + :add_param("amount", "integer-range", 0, 10) + :register(function(player, amount) + if not Roles.player_allowed(player, "command/bonus") then + Commands.print{ "expcom-bonus.perm", 1 } + return + end - PlayerBonus:set(player, amount) + PlayerBonus:set(player, amount) - Commands.print{'expcom-bonus.set', amount} -end) + Commands.print{ "expcom-bonus.set", amount } + end) --- When a player respawns re-apply bonus Event.add(defines.events.on_player_respawned, function(event) @@ -71,7 +71,7 @@ end) --- Remove bonus if a player no longer has access to the command local function role_update(event) local player = game.players[event.player_index] - if not Roles.player_allowed(player, 'command/bonus') then + if not Roles.player_allowed(player, "command/bonus") then apply_bonus(player, 0) end end @@ -80,7 +80,7 @@ end Event.add(defines.events.on_player_died, function(event) local player = game.players[event.player_index] - if Roles.player_has_flag(player, 'instant-respawn') then + if Roles.player_has_flag(player, "instant-respawn") then player.ticks_to_respawn = 120 end end) diff --git a/exp_legacy/module/modules/data/greetings.lua b/exp_legacy/module/modules/data/greetings.lua index 1b8cfd88..3bd720e5 100644 --- a/exp_legacy/module/modules/data/greetings.lua +++ b/exp_legacy/module/modules/data/greetings.lua @@ -2,14 +2,14 @@ -- @data Greetings local config = require("modules.exp_legacy.config.join_messages") --- @dep config.join_messages -local Commands = require("modules.exp_legacy.expcore.commands") ---@dep expcore.commands +local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands require("modules.exp_legacy.config.expcore.command_general_parse") --- Stores the join message that the player have local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local CustomMessages = PlayerData.Settings:combine('JoinMessage') +local CustomMessages = PlayerData.Settings:combine("JoinMessage") CustomMessages:set_metadata{ - permission = 'command/join-message' + permission = "command/join-message", } --- When a players data loads show their message @@ -19,25 +19,25 @@ CustomMessages:on_load(function(player_name, player_message) if custom_message then game.print(custom_message, player.color) else - player.print{'join-message.greet', {'links.discord'}} + player.print{ "join-message.greet", { "links.discord" } } end end) --- Set your custom join message -- @command join-message -- @tparam string message The custom join message that will be used -Commands.new_command('join-message', 'Sets your custom join message') -:add_param('message', false, 'string-max-length', 255) -:enable_auto_concat() -:register(function(player, message) - if not player then return end - CustomMessages:set(player, message) - return {'join-message.message-set'} -end) +Commands.new_command("join-message", "Sets your custom join message") + :add_param("message", false, "string-max-length", 255) + :enable_auto_concat() + :register(function(player, message) + if not player then return end + CustomMessages:set(player, message) + return { "join-message.message-set" } + end) -Commands.new_command('join-message-clear', 'Clear your join message') -:register(function(player) - if not player then return end - CustomMessages:remove(player) - return {'join-message.message-cleared'} -end) +Commands.new_command("join-message-clear", "Clear your join message") + :register(function(player) + if not player then return end + CustomMessages:remove(player) + return { "join-message.message-cleared" } + end) diff --git a/exp_legacy/module/modules/data/language.lua b/exp_legacy/module/modules/data/language.lua index 7ae93c47..76b45c6f 100644 --- a/exp_legacy/module/modules/data/language.lua +++ b/exp_legacy/module/modules/data/language.lua @@ -1,15 +1,15 @@ --- Stores the language used to join the server -- @data Language -local Event = require("modules/exp_legacy/utils/event") ---@dep utils.event +local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local LocalLanguage = PlayerData.Statistics:combine('LocalLanguage') +local LocalLanguage = PlayerData.Statistics:combine("LocalLanguage") LocalLanguage:set_default("Unknown") --- Creates translation request on_load of a player LocalLanguage:on_load(function(player_name, _) local player = game.players[player_name] - player.request_translation({"language.local-language"}) + player.request_translation{ "language.local-language" } end) --- Resolves translation request for language setting @@ -31,4 +31,4 @@ Event.add(defines.events.on_string_translated, function(event) -- Change LocalLanguage value for the player to the recognized one local language = event.result LocalLanguage:set(player, language) -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/data/personal-logistic.lua b/exp_legacy/module/modules/data/personal-logistic.lua index 777fb32d..53345dfd 100644 --- a/exp_legacy/module/modules/data/personal-logistic.lua +++ b/exp_legacy/module/modules/data/personal-logistic.lua @@ -1,26 +1,22 @@ local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands local config = require("modules.exp_legacy.config.personal_logistic") --- @dep config.personal-logistic -local pl = {} - -function pl.pl(type, target, amount) +local function pl(type, target, amount) local c local s - if type == 'p' then + if type == "p" then c = target.clear_personal_logistic_slot s = target.set_personal_logistic_slot - - elseif type == 's' then + elseif type == "s" then c = target.clear_vehicle_logistic_slot s = target.set_vehicle_logistic_slot - else return end for _, v in pairs(config.request) do - c(v.key) + c(config.start + v.key) end if (amount < 0) then @@ -33,65 +29,58 @@ function pl.pl(type, target, amount) local v_min = math.ceil(v.min * amount) local v_max = math.ceil(v.max * amount) - if v.stack and v.stack ~= 1 and v.type ~= 'weapon' then + if v.stack ~= nil and v.stack ~= 1 and v.type ~= "weapon" then v_min = math.floor(v_min / v.stack) * v.stack v_max = math.ceil(v_max / v.stack) * v.stack end if v.upgrade_of == nil then - if v.type then + if v.type ~= nil then if stats.get_input_count(k) < config.production_required[v.type] then if v_min > 0 then if v_min == v_max then v_min = math.floor((v_max * 0.5) / v.stack) * v.stack end - else v_min = 0 end end end - s(v.key, {name=k, min=v_min, max=v_max}) - + s(config.start + v.key, { name = k, min = v_min, max = v_max }) else - if v.type then + if v.type ~= nil then if stats.get_input_count(k) >= config.production_required[v.type] then - s(v.key, {name=k, min=v_min, max=v_max}) + s(config.start + v.key, { name = k, min = v_min, max = v_max }) local vuo = v.upgrade_of - while vuo do - s(config.request[vuo].key, {name=vuo, min=0, max=0}) + while (vuo ~= nil) do + s(config.start + config.request[vuo].key, { name = vuo, min = 0, max = 0 }) vuo = config.request[vuo].upgrade_of end - else - s(v.key, {name=k, min=0, max=v_max}) + s(config.start + v.key, { name = k, min = 0, max = v_max }) end end end end end -Commands.new_command('personal-logistic', {'expcom-personal-logistics'}, 'Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)') -:add_param('amount', 'integer-range', -1, 10) -:add_alias('pl') -:register(function(player, amount) - if player.force.technologies['logistic-robotics'].researched then - if player.selected then - if player.selected.name == 'spidertron' then - pl.pl('s', player.selected, amount / 10) +Commands.new_command("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)") + :add_param("amount", "integer-range", -1, 10) + :add_alias("pl") + :register(function(player, amount) + if player.force.technologies["logistic-robotics"].researched then + if player.selected ~= nil then + if player.selected.name == "spidertron" then + pl("s", player.selected, amount / 10) + return Commands.success + end + else + pl("p", player, amount / 10) return Commands.success end - else - pl.pl('p', player, amount / 10) - return Commands.success + player.print("Personal Logistic not researched") end - - else - player.print('Personal Logistic not researched') - end -end) - -return pl + end) diff --git a/exp_legacy/module/modules/data/player-colours.lua b/exp_legacy/module/modules/data/player-colours.lua index 7f97a7dc..6aa3540c 100644 --- a/exp_legacy/module/modules/data/player-colours.lua +++ b/exp_legacy/module/modules/data/player-colours.lua @@ -7,13 +7,13 @@ local config = require("modules.exp_legacy.config.preset_player_colours") --- @d --- Stores the colour that the player wants local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local PlayerColours = PlayerData.Settings:combine('Colour') +local PlayerColours = PlayerData.Settings:combine("Colour") PlayerColours:set_metadata{ stringify = function(value) - if not value then return 'None set' end + if not value then return "None set" end local c = value[1] - return string.format('Red: %d Green: %d Blue: %d', c[1], c[2], c[3]) - end + return string.format("Red: %d Green: %d Blue: %d", c[1], c[2], c[3]) + end, } --- Used to compact player colours to take less space @@ -22,13 +22,13 @@ local function compact(colour) return { floor(colour.r * 255), floor(colour.g * 255), - floor(colour.b * 255) + floor(colour.b * 255), } end --- Returns a colour that is a bit lighter than the one given local function lighten(c) - return {r = 255 - (255 - c.r) * 0.5, g = 255 - (255 - c.g) * 0.5, b = 255 - (255 - c.b) * 0.5, a = 255} + return { r = 255 - (255 - c.r) * 0.5, g = 255 - (255 - c.g) * 0.5, b = 255 - (255 - c.b) * 0.5, a = 255 } end --- When your data loads apply the players colour, or a random on if none is saved @@ -36,13 +36,14 @@ PlayerColours:on_load(function(player_name, player_colour) if not player_colour then local preset = config.players[player_name] if preset then - player_colour = {preset, lighten(preset)} + player_colour = { preset, lighten(preset) } else - local colour_name = 'white' + local colour_name = "white" while config.disallow[colour_name] do colour_name = table.get_random_dictionary_entry(Colours, true) end - player_colour = {Colours[colour_name], lighten(Colours[colour_name])} + + player_colour = { Colours[colour_name], lighten(Colours[colour_name]) } end end @@ -53,10 +54,10 @@ end) --- Save the players color when they use the color command Event.add(defines.events.on_console_command, function(event) - if event.command ~= 'color' then return end - if event.parameters == '' then return end + if event.command ~= "color" then return end + if event.parameters == "" then return end if not event.player_index then return end local player = game.players[event.player_index] if not player or not player.valid then return end - PlayerColours:set(player, {compact(player.color), compact(player.chat_color)}) -end) \ No newline at end of file + PlayerColours:set(player, { compact(player.color), compact(player.chat_color) }) +end) diff --git a/exp_legacy/module/modules/data/quickbar.lua b/exp_legacy/module/modules/data/quickbar.lua index 6b73e9d9..b32b596e 100644 --- a/exp_legacy/module/modules/data/quickbar.lua +++ b/exp_legacy/module/modules/data/quickbar.lua @@ -8,15 +8,16 @@ local config = require("modules.exp_legacy.config.preset_player_quickbar") --- @ --- Stores the quickbar filters for a player local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local PlayerFilters = PlayerData.Settings:combine('QuickbarFilters') +local PlayerFilters = PlayerData.Settings:combine("QuickbarFilters") PlayerFilters:set_metadata{ - permission = 'command/save-quickbar', + permission = "command/save-quickbar", stringify = function(value) - if not value then return 'No filters set' end + if not value then return "No filters set" end local count = 0 for _ in pairs(value) do count = count + 1 end - return count..' filters set' - end + + return count .. " filters set" + end, } --- Loads your quickbar preset @@ -25,7 +26,7 @@ PlayerFilters:on_load(function(player_name, filters) if not filters then return end local player = game.players[player_name] for i, item_name in pairs(filters) do - if item_name ~= nil and item_name ~= '' then + if item_name ~= nil and item_name ~= "" then player.set_quick_bar_slot(i, item_name) end end @@ -36,32 +37,32 @@ local ignoredItems = { ["blueprint-book"] = true, ["deconstruction-planner"] = true, ["spidertron-remote"] = true, - ["upgrade-planner"] = true + ["upgrade-planner"] = true, } --- Saves your quickbar preset to the script-output folder -- @command save-quickbar -Commands.new_command('save-quickbar', 'Saves your Quickbar preset items to file') -:add_alias('save-toolbar') -:register(function(player) - local filters = {} +Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file") + :add_alias("save-toolbar") + :register(function(player) + local filters = {} - for i = 1, 100 do - local slot = player.get_quick_bar_slot(i) - -- Need to filter out blueprint and blueprint books because the slot is a LuaItemPrototype and does not contain a way to export blueprint data - if slot ~= nil then - local ignored = ignoredItems[slot.name] - if ignored ~= true then - filters[i] = slot.name + for i = 1, 100 do + local slot = player.get_quick_bar_slot(i) + -- Need to filter out blueprint and blueprint books because the slot is a LuaItemPrototype and does not contain a way to export blueprint data + if slot ~= nil then + local ignored = ignoredItems[slot.name] + if ignored ~= true then + filters[i] = slot.name + end end end - end - if next(filters) then - PlayerFilters:set(player, filters) - else - PlayerFilters:remove(player) - end + if next(filters) then + PlayerFilters:set(player, filters) + else + PlayerFilters:remove(player) + end - return {'quickbar.saved'} -end) + return { "quickbar.saved" } + end) diff --git a/exp_legacy/module/modules/data/statistics.lua b/exp_legacy/module/modules/data/statistics.lua index 6c546fef..8ceb5b2a 100644 --- a/exp_legacy/module/modules/data/statistics.lua +++ b/exp_legacy/module/modules/data/statistics.lua @@ -1,10 +1,9 @@ - -local Event = require("modules/exp_legacy/utils/event") ---@dep utils.event -local Storage = require("modules/exp_util/storage") ---@dep utils.global -local config = require("modules.exp_legacy.config.statistics") ---@dep config.statistics +local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event +local Storage = require("modules/exp_util/storage") --- @dep utils.global +local config = require("modules.exp_legacy.config.statistics") --- @dep config.statistics local format_time = _C.format_time local floor = math.floor -local afk_required = 5*3600 -- 5 minutes +local afk_required = 5 * 3600 -- 5 minutes --- Stores players who have been created, required to avoid loss of data local new_players = {} @@ -17,7 +16,7 @@ local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep ex local AllPlayerData = PlayerData.All local Statistics = PlayerData.Statistics Statistics:set_metadata{ - display_order = config.display_order + display_order = config.display_order, } --- Update your statistics with any which happened before the data was valid @@ -49,27 +48,27 @@ end) --- Used to format time in minute format local function format_minutes(value) - return format_time(value*3600, { + return format_time(value * 3600, { long = true, hours = true, - minutes = true + minutes = true, }) end --- Used to format time into a clock local function format_clock(value) - return format_time(value*3600, { - hours=true, - minutes=true, - seconds=false, - time=false, - string=true + return format_time(value * 3600, { + hours = true, + minutes = true, + seconds = false, + time = false, + string = true, }) end --- Add MapsPlayed if it is enabled if config.MapsPlayed then - Statistics:combine('MapsPlayed') + Statistics:combine("MapsPlayed") Event.add(defines.events.on_player_created, function(event) local player = game.players[event.player_index] new_players[player.name] = true @@ -79,8 +78,14 @@ end --- Add Playtime and AfkTime if it is enabled if config.Playtime or config.AfkTime then local playtime, afk_time - if config.Playtime then playtime = Statistics:combine('Playtime') playtime:set_metadata{stringify=format_minutes, stringify_short=format_clock} end - if config.AfkTime then afk_time = Statistics:combine('AfkTime') afk_time:set_metadata{stringify=format_minutes, stringify_short=format_clock} end + if config.Playtime then + playtime = Statistics:combine("Playtime") + playtime:set_metadata{ stringify = format_minutes, stringify_short = format_clock } + end + if config.AfkTime then + afk_time = Statistics:combine("AfkTime") + afk_time:set_metadata{ stringify = format_minutes, stringify_short = format_clock } + end Event.on_nth_tick(3600, function() if game.tick == 0 then return end for _, player in pairs(game.connected_players) do @@ -92,8 +97,8 @@ end --- Add DistanceTravelled if it is enabled if config.DistanceTravelled then - local stat = Statistics:combine('DistanceTravelled') - stat:set_metadata{unit=' tiles'} + local stat = Statistics:combine("DistanceTravelled") + stat:set_metadata{ unit = " tiles" } Event.add(defines.events.on_player_changed_position, function(event) local player = game.players[event.player_index] if not player.valid or not player.connected or player.afk_time > afk_required then return end @@ -104,18 +109,22 @@ end --- Add MachinesRemoved and TreesDestroyed and config.OreMined if it is enabled if config.MachinesRemoved or config.TreesDestroyed or config.OreMined then local machines, trees, ore - if config.MachinesRemoved then machines = Statistics:combine('MachinesRemoved') end - if config.TreesDestroyed then trees = Statistics:combine('TreesDestroyed') end - if config.OreMined then ore = Statistics:combine('OreMined') end + if config.MachinesRemoved then machines = Statistics:combine("MachinesRemoved") end + if config.TreesDestroyed then trees = Statistics:combine("TreesDestroyed") end + if config.OreMined then ore = Statistics:combine("OreMined") end local function on_event(event) - if not event.player_index then return end -- Check player is valid + if not event.player_index then return end -- Check player is valid local player = game.players[event.player_index] if not player.valid or not player.connected then return end local entity = event.entity -- Check entity is valid if not entity.valid then return end - if entity.type == 'resource' then ore:increment(player) - elseif entity.type == 'tree' then trees:increment(player) - elseif entity.force == player.force then machines:increment(player) end + if entity.type == "resource" then + ore:increment(player) + elseif entity.type == "tree" then + trees:increment(player) + elseif entity.force == player.force then + machines:increment(player) + end end Event.add(defines.events.on_marked_for_deconstruction, on_event) Event.add(defines.events.on_player_mined_entity, on_event) @@ -123,35 +132,35 @@ end --- Add DamageDealt if it is enabled if config.DamageDealt then - local stat = Statistics:combine('DamageDealt') + local stat = Statistics:combine("DamageDealt") Event.add(defines.events.on_entity_damaged, function(event) local character = event.cause -- Check character is valid - if not character or not character.valid or character.type ~= 'character' then return end + if not character or not character.valid or character.type ~= "character" then return end local player = character.player -- Check player is valid if not player.valid or not player.connected then return end local entity = event.entity -- Check entity is valid - if not entity.valid or entity.force == player.force or entity.force.name == 'neutral' then return end + if not entity.valid or entity.force == player.force or entity.force.name == "neutral" then return end stat:increment(player, floor(event.final_damage_amount)) end) end --- Add Kills if it is enabled if config.Kills then - local stat = Statistics:combine('Kills') + local stat = Statistics:combine("Kills") Event.add(defines.events.on_entity_died, function(event) local character = event.cause -- Check character is valid - if not character or not character.valid or character.type ~= 'character' then return end + if not character or not character.valid or character.type ~= "character" then return end local player = character.player -- Check player is valid if not player or not player.valid or not player.connected then return end local entity = event.entity -- Check entity is valid - if not entity.valid or entity.force == player.force or entity.force.name == 'neutral' then return end + if not entity.valid or entity.force == player.force or entity.force.name == "neutral" then return end stat:increment(player) end) end --- Add RocketsLaunched if it is enabled if config.RocketsLaunched then - local stat = Statistics:combine('RocketsLaunched') + local stat = Statistics:combine("RocketsLaunched") Event.add(defines.events.on_rocket_launched, function(event) local silo = event.rocket_silo -- Check silo is valid if not silo or not silo.valid then return end @@ -165,9 +174,9 @@ end --- Add RocketsLaunched if it is enabled if config.ResearchCompleted then - local stat = Statistics:combine('ResearchCompleted') + local stat = Statistics:combine("ResearchCompleted") Event.add(defines.events.on_research_finished, function(event) - local research = event.research -- Check research is valid + local research = event.research -- Check research is valid if event.by_script or not research or not research.valid then return end local force = research.force -- Check force is valid if not force or not force.valid then return end diff --git a/exp_legacy/module/modules/data/tag.lua b/exp_legacy/module/modules/data/tag.lua index 5e00e381..1d251e6a 100644 --- a/exp_legacy/module/modules/data/tag.lua +++ b/exp_legacy/module/modules/data/tag.lua @@ -11,22 +11,22 @@ require("modules.exp_legacy.config.expcore.command_color_parse") --- Stores the tag for a player local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local PlayerTags = PlayerData.Settings:combine('Tag') -local PlayerTagColors = PlayerData.Settings:combine('TagColor') +local PlayerTags = PlayerData.Settings:combine("Tag") +local PlayerTagColors = PlayerData.Settings:combine("TagColor") PlayerTags:set_metadata{ - permission = 'command/tag' + permission = "command/tag", } PlayerTagColors:set_metadata{ - permission = 'command/tag-color' + permission = "command/tag-color", } -local set_tag = function (player, tag, color) - if tag == nil or tag == '' then - player.tag = '' +local set_tag = function(player, tag, color) + if tag == nil or tag == "" then + player.tag = "" elseif color then - player.tag = '- [color='.. color ..']'..tag..'[/color]' + player.tag = "- [color=" .. color .. "]" .. tag .. "[/color]" else - player.tag = '- '..tag + player.tag = "- " .. tag end end @@ -49,40 +49,40 @@ end) --- Sets your player tag. -- @command tag -- @tparam string tag the tag that will be after the name, there is a max length -Commands.new_command('tag', 'Sets your player tag.') -:add_param('tag', false, 'string-max-length', 20) -:enable_auto_concat() -:register(function(player, tag) - PlayerTags:set(player, tag) -end) +Commands.new_command("tag", "Sets your player tag.") + :add_param("tag", false, "string-max-length", 20) + :enable_auto_concat() + :register(function(player, tag) + PlayerTags:set(player, tag) + end) --- Sets your player tag color. -- @command tag -- @tparam string color name. -Commands.new_command('tag-color', 'Sets your player tag color.') -:add_param('color', false, 'color') -:enable_auto_concat() -:register(function(player, color) - PlayerTagColors:set(player, color) -end) +Commands.new_command("tag-color", "Sets your player tag color.") + :add_param("color", false, "color") + :enable_auto_concat() + :register(function(player, color) + PlayerTagColors:set(player, color) + end) --- Clears your tag. Or another player if you are admin. -- @command tag-clear -- @tparam[opt=self] LuaPlayer player the player to remove the tag from, nil will apply to self -Commands.new_command('tag-clear', 'Clears your tag. Or another player if you are admin.') -:add_param('player', true, 'player-role') -:set_defaults{player=function(player) - return player -- default is the user using the command -end} -:register(function(player, action_player) - if action_player.index == player.index then - -- no player given so removes your tag - PlayerTags:remove(action_player) - elseif Roles.player_allowed(player, 'command/clear-tag/always') then - -- player given and user is admin so clears that player's tag - PlayerTags:remove(action_player) - else - -- user is not admin and tried to clear another users tag - return Commands.error{'expcore-commands.unauthorized'} - end -end) +Commands.new_command("tag-clear", "Clears your tag. Or another player if you are admin.") + :add_param("player", true, "player-role") + :set_defaults{ player = function(player) + return player -- default is the user using the command + end } + :register(function(player, action_player) + if action_player.index == player.index then + -- no player given so removes your tag + PlayerTags:remove(action_player) + elseif Roles.player_allowed(player, "command/clear-tag/always") then + -- player given and user is admin so clears that player's tag + PlayerTags:remove(action_player) + else + -- user is not admin and tried to clear another users tag + return Commands.error{ "expcore-commands.unauthorized" } + end + end) diff --git a/exp_legacy/module/modules/factorio-control.lua b/exp_legacy/module/modules/factorio-control.lua index 243829f8..009a9d7d 100644 --- a/exp_legacy/module/modules/factorio-control.lua +++ b/exp_legacy/module/modules/factorio-control.lua @@ -22,7 +22,7 @@ local created_items = function() ["pistol"] = 1, ["firearm-magazine"] = 10, ["burner-mining-drill"] = 1, - ["stone-furnace"] = 1 + ["stone-furnace"] = 1, } end @@ -30,13 +30,13 @@ local respawn_items = function() return { ["pistol"] = 1, - ["firearm-magazine"] = 10 + ["firearm-magazine"] = 10, } end if use_silo_script then for k, v in pairs(silo_script.get_events()) do - Event.add(k, v) + Event.add(k, v) end end @@ -45,13 +45,13 @@ Event.add(defines.events.on_player_created, function(event) util.insert_safe(player, global.created_items) local r = global.chart_distance or 200 - player.force.chart(player.surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}}) + player.force.chart(player.surface, { { player.position.x - r, player.position.y - r }, { player.position.x + r, player.position.y + r } }) if not global.skip_intro then if game.is_multiplayer() then - player.print({"msg-intro"}) + player.print{ "msg-intro" } else - game.show_message_dialog{text = {"msg-intro"}} + game.show_message_dialog{ text = { "msg-intro" } } end end @@ -88,37 +88,37 @@ if use_silo_script then end remote.add_interface("freeplay", -{ - get_created_items = function() - return global.created_items - end, - set_created_items = function(map) - global.created_items = map - end, - get_respawn_items = function() - return global.respawn_items - end, - set_respawn_items = function(map) - global.respawn_items = map - end, - set_skip_intro = function(bool) - global.skip_intro = bool - end, - set_chart_distance = function(value) - global.chart_distance = tonumber(value) - end, - set_disable_crashsite = function() - end, - get_ship_items = function() - return {} - end, - set_ship_items = function() - return - end, - get_debris_items = function () - return {} - end, - set_debris_items = function () - return - end -}) + { + get_created_items = function() + return global.created_items + end, + set_created_items = function(map) + global.created_items = map + end, + get_respawn_items = function() + return global.respawn_items + end, + set_respawn_items = function(map) + global.respawn_items = map + end, + set_skip_intro = function(bool) + global.skip_intro = bool + end, + set_chart_distance = function(value) + global.chart_distance = tonumber(value) + end, + set_disable_crashsite = function() + end, + get_ship_items = function() + return {} + end, + set_ship_items = function() + return + end, + get_debris_items = function() + return {} + end, + set_debris_items = function() + return + end, + }) diff --git a/exp_legacy/module/modules/graftorio/forcestats.lua b/exp_legacy/module/modules/graftorio/forcestats.lua index d2a30f3e..48941fce 100644 --- a/exp_legacy/module/modules/graftorio/forcestats.lua +++ b/exp_legacy/module/modules/graftorio/forcestats.lua @@ -5,186 +5,192 @@ local config = require("modules.exp_legacy.config.graftorio") local lib = {} lib.collect_production = function() - for _, force in pairs(game.forces) do - general.data.output[force.name].production = {} - for _, surface in pairs(game.surfaces) do - ---@class ItemStats - ---@field count number + for _, force in pairs(game.forces) do + general.data.output[force.name].production = {} + for _, surface in pairs(game.surfaces) do + --- @class ItemStats + --- @field count number - ---@class ProductionStatistics - ---@field item_input table - ---@field item_output table - ---@field fluid_input table - ---@field fluid_output table - ---@field kill_input table - ---@field kill_output table - ---@field build_input table - ---@field build_output table - local stats = { - item_input = {}, - item_output = {}, - fluid_input = {}, - fluid_output = {}, - kill_input = {}, - kill_output = {}, - build_input = {}, - build_output = {}, - } + --- @class ProductionStatistics + --- @field item_input table + --- @field item_output table + --- @field fluid_input table + --- @field fluid_output table + --- @field kill_input table + --- @field kill_output table + --- @field build_input table + --- @field build_output table + local stats = { + item_input = {}, + item_output = {}, + fluid_input = {}, + fluid_output = {}, + kill_input = {}, + kill_output = {}, + build_input = {}, + build_output = {}, + } - for name, count in pairs(force.get_item_production_statistics(surface).input_counts) do - local itemstats = stats.item_input[name] or {} - itemstats.count = count - stats.item_input[name] = itemstats - end - for name, count in pairs(force.get_item_production_statistics(surface).output_counts) do - local itemstats = stats.item_output[name] or {} - itemstats.count = count - stats.item_output[name] = itemstats - end + for name, count in pairs(force.get_item_production_statistics(surface).input_counts) do + local itemstats = stats.item_input[name] or {} + itemstats.count = count + stats.item_input[name] = itemstats + end - for name, count in pairs(force.get_fluid_production_statistics(surface).input_counts) do - local fluidstats = stats.fluid_input[name] or {} - fluidstats.count = count - stats.fluid_input[name] = fluidstats - end - for name, count in pairs(force.get_fluid_production_statistics(surface).output_counts) do - local fluidstats = stats.fluid_output[name] or {} - fluidstats.count = count - stats.fluid_output[name] = fluidstats - end + for name, count in pairs(force.get_item_production_statistics(surface).output_counts) do + local itemstats = stats.item_output[name] or {} + itemstats.count = count + stats.item_output[name] = itemstats + end - for name, count in pairs(force.get_kill_count_statistics(surface).input_counts) do - local killstats = stats.kill_input[name] or {} - killstats.count = count - stats.kill_input[name] = killstats - end - for name, count in pairs(force.get_kill_count_statistics(surface).output_counts) do - local killstats = stats.kill_output[name] or {} - killstats.count = count - stats.kill_output[name] = killstats - end + for name, count in pairs(force.get_fluid_production_statistics(surface).input_counts) do + local fluidstats = stats.fluid_input[name] or {} + fluidstats.count = count + stats.fluid_input[name] = fluidstats + end - for name, count in pairs(force.get_entity_build_count_statistics(surface).input_counts) do - local buildstats = stats.build_input[name] or {} - buildstats.count = count - stats.build_input[name] = buildstats - end - for name, count in pairs(force.get_entity_build_count_statistics(surface).output_counts) do - local buildstats = stats.build_output[name] or {} - buildstats.count = count - stats.build_output[name] = buildstats - end + for name, count in pairs(force.get_fluid_production_statistics(surface).output_counts) do + local fluidstats = stats.fluid_output[name] or {} + fluidstats.count = count + stats.fluid_output[name] = fluidstats + end - general.data.output[force.name].production[surface.name] = stats - end - end + for name, count in pairs(force.get_kill_count_statistics(surface).input_counts) do + local killstats = stats.kill_input[name] or {} + killstats.count = count + stats.kill_input[name] = killstats + end + + for name, count in pairs(force.get_kill_count_statistics(surface).output_counts) do + local killstats = stats.kill_output[name] or {} + killstats.count = count + stats.kill_output[name] = killstats + end + + for name, count in pairs(force.get_entity_build_count_statistics(surface).input_counts) do + local buildstats = stats.build_input[name] or {} + buildstats.count = count + stats.build_input[name] = buildstats + end + + for name, count in pairs(force.get_entity_build_count_statistics(surface).output_counts) do + local buildstats = stats.build_output[name] or {} + buildstats.count = count + stats.build_output[name] = buildstats + end + + general.data.output[force.name].production[surface.name] = stats + end + end end lib.collect_loginet = function() - for _, force in pairs(game.forces) do - ---@class RobotStatistics - ---@field all_construction_robots uint - ---@field available_construction_robot uint - ---@field all_logistic_robots uint - ---@field available_logistic_robots uint - ---@field charging_robot_count uint - ---@field to_charge_robot_count uint - ---@field items table - ---@field pickups table - ---@field deliveries table - local stats = { - all_construction_robots = 0, - available_construction_robots = 0, + for _, force in pairs(game.forces) do + --- @class RobotStatistics + --- @field all_construction_robots uint + --- @field available_construction_robot uint + --- @field all_logistic_robots uint + --- @field available_logistic_robots uint + --- @field charging_robot_count uint + --- @field to_charge_robot_count uint + --- @field items table + --- @field pickups table + --- @field deliveries table + local stats = { + all_construction_robots = 0, + available_construction_robots = 0, - all_logistic_robots = 0, - available_logistic_robots = 0, + all_logistic_robots = 0, + available_logistic_robots = 0, - charging_robot_count = 0, - to_charge_robot_count = 0, + charging_robot_count = 0, + to_charge_robot_count = 0, - items = {}, - pickups = {}, - deliveries = {}, - } - for _, networks in pairs(force.logistic_networks) do - for _, network in pairs(networks) do - stats.available_construction_robots = network.available_construction_robots - stats.all_construction_robots = network.all_construction_robots + items = {}, + pickups = {}, + deliveries = {}, + } + for _, networks in pairs(force.logistic_networks) do + for _, network in pairs(networks) do + stats.available_construction_robots = network.available_construction_robots + stats.all_construction_robots = network.all_construction_robots - stats.available_logistic_robots = network.available_logistic_robots - stats.all_logistic_robots = network.all_logistic_robots + stats.available_logistic_robots = network.available_logistic_robots + stats.all_logistic_robots = network.all_logistic_robots - stats.charging_robot_count = 0 - stats.to_charge_robot_count = 0 - for _, cell in pairs(network.cells) do - stats.charging_robot_count = (stats.charging_robot_count) + cell.charging_robot_count - stats.to_charge_robot_count = (stats.to_charge_robot_count) + cell.to_charge_robot_count - end + stats.charging_robot_count = 0 + stats.to_charge_robot_count = 0 + for _, cell in pairs(network.cells) do + stats.charging_robot_count = (stats.charging_robot_count) + cell.charging_robot_count + stats.to_charge_robot_count = (stats.to_charge_robot_count) + cell.to_charge_robot_count + end - if config.modules.logistorage then - for name, v in pairs(network.get_contents()) do - stats.items[name] = (stats.items[name] or 0) + v - end + if config.modules.logistorage then + for name, v in pairs(network.get_contents()) do + stats.items[name] = (stats.items[name] or 0) + v + end - -- pickups and deliveries of items - for _, point_list in pairs({ network.provider_points, network.requester_points, network.storage_points }) do - for _, point in pairs(point_list) do - for name, qty in pairs(point.targeted_items_pickup) do - stats.pickups[name] = (stats.pickups[name] or 0) + qty - end - for name, qty in pairs(point.targeted_items_deliver) do - stats.deliveries[name] = (stats.deliveries[name] or 0) + qty - end - end - end - end - end - end - general.data.output[force.name].robots = stats - end + -- pickups and deliveries of items + for _, point_list in pairs{ network.provider_points, network.requester_points, network.storage_points } do + for _, point in pairs(point_list) do + for name, qty in pairs(point.targeted_items_pickup) do + stats.pickups[name] = (stats.pickups[name] or 0) + qty + end + + for name, qty in pairs(point.targeted_items_deliver) do + stats.deliveries[name] = (stats.deliveries[name] or 0) + qty + end + end + end + end + end + end + + general.data.output[force.name].robots = stats + end end ----@class Research ----@field name string ----@field level uint ----@field progress double +--- @class Research +--- @field name string +--- @field level uint +--- @field progress double Event.add(defines.events.on_research_finished, function(evt) - local research = evt.research - if not general.data.output[research.force.name] then general.data.output[research.force.name] = {} end - if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end + local research = evt.research + if not general.data.output[research.force.name] then general.data.output[research.force.name] = {} end + if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end - local force_research = general.data.output[research.force.name].research or {} - table.remove(force_research, 1) - general.data.output[research.force.name].research = force_research + local force_research = general.data.output[research.force.name].research or {} + table.remove(force_research, 1) + general.data.output[research.force.name].research = force_research end) Event.add(defines.events.on_research_started, function(evt) - -- move queue up - local research = evt.research - if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end + -- move queue up + local research = evt.research + if not general.data.output[research.force.name].research then general.data.output[research.force.name].research = {} end - local force_research = general.data.output[research.force.name].research or {} - table.remove(force_research, 1) - general.data.output[research.force.name].research = force_research + local force_research = general.data.output[research.force.name].research or {} + table.remove(force_research, 1) + general.data.output[research.force.name].research = force_research end) Event.on_nth_tick(60, function() - for _, force in pairs(game.forces) do - if not general.data.output[force.name].research then general.data.output[force.name].research = {} end + for _, force in pairs(game.forces) do + if not general.data.output[force.name].research then general.data.output[force.name].research = {} end - local force_research = {} - -- this works even if the queue is disabled, but it will always be just 1 long in that case - for _, research in pairs(force.research_queue) do - table.insert(force_research, { - name = research.name, - level = research.level, - progress = force.get_saved_technology_progress(research) or 0, - }) - end + local force_research = {} + -- this works even if the queue is disabled, but it will always be just 1 long in that case + for _, research in pairs(force.research_queue) do + table.insert(force_research, { + name = research.name, + level = research.level, + progress = force.get_saved_technology_progress(research) or 0, + }) + end - general.data.output[force.name].research = force_research - end + general.data.output[force.name].research = force_research + end end) return lib diff --git a/exp_legacy/module/modules/graftorio/general.lua b/exp_legacy/module/modules/graftorio/general.lua index 820acac4..4a9f84e5 100644 --- a/exp_legacy/module/modules/graftorio/general.lua +++ b/exp_legacy/module/modules/graftorio/general.lua @@ -4,60 +4,60 @@ local Storage = require("modules/exp_util/storage") local lib = {} lib.data = { - output = {} + output = {}, } Storage.register(lib.data, function(tbl) - lib.data = tbl + lib.data = tbl end) ----@class Statistics ----@field production ProductionStatistics? ----@field robots RobotStatistics? ----@field other OtherStatistics? ----@field research Research[]? +--- @class Statistics +--- @field production ProductionStatistics? +--- @field robots RobotStatistics? +--- @field other OtherStatistics? +--- @field research Research[]? Event.on_init(function() - ---@type table - lib.data.output = {} - for _, force in pairs(game.forces) do - lib.data.output[force.name] = {} - end + --- @type table + lib.data.output = {} + for _, force in pairs(game.forces) do + lib.data.output[force.name] = {} + end end) ----@class OtherStatistics ----@field tick uint ----@field evolution EvolutionStatistics +--- @class OtherStatistics +--- @field tick uint +--- @field evolution EvolutionStatistics ----@class EvolutionStatistics ----@field evolution_factor double ----@field evolution_factor_by_pollution double ----@field evolution_factor_by_time double ----@field evolution_factor_by_killing_spawners double +--- @class EvolutionStatistics +--- @field evolution_factor double +--- @field evolution_factor_by_pollution double +--- @field evolution_factor_by_time double +--- @field evolution_factor_by_killing_spawners double lib.collect_other = function() - for _, force in pairs(game.forces) do - ---@type OtherStatistics - local other = lib.data.output[force.name].other or {} + for _, force in pairs(game.forces) do + --- @type OtherStatistics + local other = lib.data.output[force.name].other or {} - other.evolution = { - evolution_factor = force.evolution_factor, - evolution_factor_by_pollution = force.evolution_factor_by_pollution, - evolution_factor_by_time = force.evolution_factor_by_time, - evolution_factor_by_killing_spawners = force.evolution_factor_by_killing_spawners - } - for k, v in pairs(other) do - lib.data.output[force.name].other[k] = v - end - end + other.evolution = { + evolution_factor = force.evolution_factor, + evolution_factor_by_pollution = force.evolution_factor_by_pollution, + evolution_factor_by_time = force.evolution_factor_by_time, + evolution_factor_by_killing_spawners = force.evolution_factor_by_killing_spawners, + } + for k, v in pairs(other) do + lib.data.output[force.name].other[k] = v + end + end end Event.add(defines.events.on_force_created, function(evt) - lib.data.output[evt.force.name] = {} + lib.data.output[evt.force.name] = {} end) Event.add(defines.events.on_forces_merged, function(evt) - lib.data.output[evt.source_name] = nil + lib.data.output[evt.source_name] = nil end) return lib diff --git a/exp_legacy/module/modules/graftorio/require.lua b/exp_legacy/module/modules/graftorio/require.lua index 5f8eae65..4b95fbce 100644 --- a/exp_legacy/module/modules/graftorio/require.lua +++ b/exp_legacy/module/modules/graftorio/require.lua @@ -5,23 +5,23 @@ local general = require("modules.exp_legacy.modules.graftorio.general") local forcestats = nil if config.modules.forcestats then - forcestats = require("modules.exp_legacy.modules.graftorio.forcestats") + forcestats = require("modules.exp_legacy.modules.graftorio.forcestats") end Commands.new_command("collectdata", "Collect data for RCON usage") -:add_param("location", true) -:register(function() - -- this must be first as it overwrites the stats - -- also makes the .other table for all forces - statics.collect_statics() - if config.modules.other then - general.collect_other() - end - if config.modules.forcestats then - ---@cast forcestats -nil - forcestats.collect_production() - forcestats.collect_loginet() - end - rcon.print(game.table_to_json(general.data.output)) - return Commands.success() -end) + :add_param("location", true) + :register(function() + -- this must be first as it overwrites the stats + -- also makes the .other table for all forces + statics.collect_statics() + if config.modules.other then + general.collect_other() + end + if config.modules.forcestats then + --- @cast forcestats -nil + forcestats.collect_production() + forcestats.collect_loginet() + end + rcon.print(game.table_to_json(general.data.output)) + return Commands.success() + end) diff --git a/exp_legacy/module/modules/graftorio/statics.lua b/exp_legacy/module/modules/graftorio/statics.lua index df238718..680a3e7b 100644 --- a/exp_legacy/module/modules/graftorio/statics.lua +++ b/exp_legacy/module/modules/graftorio/statics.lua @@ -2,34 +2,35 @@ local general = require("modules.exp_legacy.modules.graftorio.general") local lib = {} ----@class StaticStatistics ----@field tick uint ----@field online_players string[] ----@field mods table ----@field seed table +--- @class StaticStatistics +--- @field tick uint +--- @field online_players string[] +--- @field mods table +--- @field seed table lib.collect_statics = function() - local stats = {} - stats.tick = game.tick + local stats = {} + stats.tick = game.tick - stats.online_players = {} - for _, player in pairs(game.connected_players) do - table.insert(stats.online_players, player.name) - end + stats.online_players = {} + for _, player in pairs(game.connected_players) do + table.insert(stats.online_players, player.name) + end - stats.mods = {} - for name, version in pairs(game.active_mods) do - stats.mods[name] = version - end + stats.mods = {} + for name, version in pairs(game.active_mods) do + stats.mods[name] = version + end - -- reason behind this is that the map gen settings can be changed during runtime so just get them fresh - stats.seed = {} - for _, surface in pairs(game.surfaces) do - stats.seed[surface.name] = surface.map_gen_settings.seed - end - for _, force in pairs(game.forces) do - general.data.output[force.name].other = stats - end + -- reason behind this is that the map gen settings can be changed during runtime so just get them fresh + stats.seed = {} + for _, surface in pairs(game.surfaces) do + stats.seed[surface.name] = surface.map_gen_settings.seed + end + + for _, force in pairs(game.forces) do + general.data.output[force.name].other = stats + end end return lib diff --git a/exp_legacy/module/modules/gui/autofill.lua b/exp_legacy/module/modules/gui/autofill.lua index 5ad860fa..2e0eb005 100644 --- a/exp_legacy/module/modules/gui/autofill.lua +++ b/exp_legacy/module/modules/gui/autofill.lua @@ -23,279 +23,277 @@ end) local autofill_container local function rich_img(type, value) - return '[img='..type..'/'..value..']' + return "[img=" .. type .. "/" .. value .. "]" end --- Toggle entity section visibility -- @element toggle_item_button local toggle_section = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/expand', - tooltip = {'autofill.toggle-section-tooltip'}, - style = "frame_action_button", - name = Gui.unique_static_name -} -:style(Gui.sprite_style(20)) -:on_click(function(_, element, _) - local header_flow = element.parent - local flow_name = header_flow.caption - local flow = header_flow.parent.parent[flow_name] - if Gui.toggle_visible_state(flow) then - element.sprite = 'utility/collapse' - element.tooltip = {'autofill.toggle-section-collapse-tooltip'} - else - element.sprite = 'utility/expand' - element.tooltip = {'autofill.toggle-section-tooltip'} - end -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/expand", + tooltip = { "autofill.toggle-section-tooltip" }, + style = "frame_action_button", + name = Gui.unique_static_name, + } + :style(Gui.sprite_style(20)) + :on_click(function(_, element, _) + local header_flow = element.parent + local flow_name = header_flow.caption + local flow = header_flow.parent.parent[flow_name] + if Gui.toggle_visible_state(flow) then + element.sprite = "utility/collapse" + element.tooltip = { "autofill.toggle-section-collapse-tooltip" } + else + element.sprite = "utility/expand" + element.tooltip = { "autofill.toggle-section-tooltip" } + end + end) --- Toggle enitity button, used for toggling autofill for the specific entity -- All entity autofill settings will be ignored if its disabled -- @element entity_toggle local entity_toggle = -Gui.element(function(_, parent, entity_name) - return parent.add{ - type = 'sprite-button', - sprite = 'utility/confirm_slot', - tooltip = {'autofill.toggle-entity-tooltip', rich_img('item', entity_name)}, - style = 'shortcut_bar_button_green' - } -end) -:style(Gui.sprite_style(22)) -:on_click(function(player, element, _) - local entity_name = string.match(element.parent.parent.name,'(.*)%-header') - if not autofill_player_settings[player.name] then return end - local setting = autofill_player_settings[player.name][entity_name] - if not setting then return end - if setting.enabled then - setting.enabled = false - element.sprite = 'utility/close_black' - element.style = 'shortcut_bar_button_red' - else - setting.enabled = true - element.sprite = 'utility/confirm_slot' - element.style = 'shortcut_bar_button_green' - end - -- Correct the button size - local style = element.style - style.padding = -2 - style.height = 22 - style.width = 22 -end) + Gui.element(function(_, parent, entity_name) + return parent.add{ + type = "sprite-button", + sprite = "utility/confirm_slot", + tooltip = { "autofill.toggle-entity-tooltip", rich_img("item", entity_name) }, + style = "shortcut_bar_button_green", + } + end) + :style(Gui.sprite_style(22)) + :on_click(function(player, element, _) + local entity_name = string.match(element.parent.parent.name, "(.*)%-header") + if not autofill_player_settings[player.name] then return end + local setting = autofill_player_settings[player.name][entity_name] + if not setting then return end + if setting.enabled then + setting.enabled = false + element.sprite = "utility/close_black" + element.style = "shortcut_bar_button_red" + else + setting.enabled = true + element.sprite = "utility/confirm_slot" + element.style = "shortcut_bar_button_green" + end + -- Correct the button size + local style = element.style + style.padding = -2 + style.height = 22 + style.width = 22 + end) --- Draw a section header and main scroll -- @element autofill_section_container local section = -Gui.element(function(definition, parent, section_name, table_size) - -- Draw the header for the section - local header = Gui.header( - parent, - {'autofill.toggle-section-caption', rich_img('item', section_name), {'entity-name.'..section_name}}, - {'autofill.toggle-section-tooltip'}, - true, - section_name..'-header' - ) + Gui.element(function(definition, parent, section_name, table_size) + -- Draw the header for the section + local header = Gui.header( + parent, + { "autofill.toggle-section-caption", rich_img("item", section_name), { "entity-name." .. section_name } }, + { "autofill.toggle-section-tooltip" }, + true, + section_name .. "-header" + ) - definition:triggers_events(header.parent.header_label) + definition:triggers_events(header.parent.header_label) - -- Right aligned button to toggle the section - header.caption = section_name - entity_toggle(header, section_name) - toggle_section(header) + -- Right aligned button to toggle the section + header.caption = section_name + entity_toggle(header, section_name) + toggle_section(header) - local section_table = parent.add{ - type = 'table', - name = section_name, - column_count = table_size - } + local section_table = parent.add{ + type = "table", + name = section_name, + column_count = table_size, + } - section_table.visible = false + section_table.visible = false - return definition:no_events(section_table) -end) -:on_click(function(_, element, event) - event.element = element.parent.alignment[toggle_section.name] - toggle_section:raise_event(event) -end) + return definition:no_events(section_table) + end) + :on_click(function(_, element, event) + event.element = element.parent.alignment[toggle_section.name] + toggle_section:raise_event(event) + end) --- Toggle item button, used for toggling autofill for the specific item -- @element toggle_item_button local toggle_item_button = -Gui.element(function(_, parent, item) - return parent.add{ - type = 'sprite-button', - sprite = 'item/'..item.name, - tooltip = {'autofill.toggle-tooltip', rich_img('item', item.name), item.category}, - style = 'shortcut_bar_button_red' - } -end) -:style(Gui.sprite_style(32, nil, { right_margin = -3 })) -:on_click(function(player, element) - local item_name = element.parent.tooltip - local entity_name = element.parent.parent.parent.name - if not autofill_player_settings[player.name] then return end - local setting = autofill_player_settings[player.name][entity_name] - if not setting then return end - local item = setting.items[item_name] - if not item then return end - if item.enabled then - item.enabled = false - element.style = 'shortcut_bar_button_red' - else - item.enabled = true - element.style = 'shortcut_bar_button_green' - end - -- Correct the button size - local style = element.style - style.right_margin = -3 - style.padding = -2 - style.height = 32 - style.width = 32 -end) - + Gui.element(function(_, parent, item) + return parent.add{ + type = "sprite-button", + sprite = "item/" .. item.name, + tooltip = { "autofill.toggle-tooltip", rich_img("item", item.name), item.category }, + style = "shortcut_bar_button_red", + } + end) + :style(Gui.sprite_style(32, nil, { right_margin = -3 })) + :on_click(function(player, element) + local item_name = element.parent.tooltip + local entity_name = element.parent.parent.parent.name + if not autofill_player_settings[player.name] then return end + local setting = autofill_player_settings[player.name][entity_name] + if not setting then return end + local item = setting.items[item_name] + if not item then return end + if item.enabled then + item.enabled = false + element.style = "shortcut_bar_button_red" + else + item.enabled = true + element.style = "shortcut_bar_button_green" + end + -- Correct the button size + local style = element.style + style.right_margin = -3 + style.padding = -2 + style.height = 32 + style.width = 32 + end) --- Amount text field for a autofill item -- @element amount_textfield local amount_textfield = -Gui.element(function(_, parent, item) - return parent.add{ - type = 'textfield', - text = item.amount, - tooltip = {'autofill.amount-tooltip', item.category }, - clear_and_focus_on_right_click = true, - numeric = true, - allow_decimal = false, - allow_negative = false + Gui.element(function(_, parent, item) + return parent.add{ + type = "textfield", + text = item.amount, + tooltip = { "autofill.amount-tooltip", item.category }, + clear_and_focus_on_right_click = true, + numeric = true, + allow_decimal = false, + allow_negative = false, + } + end) + :style{ + maximal_width = 40, + height = 31, + padding = -2, } -end) -:style{ - maximal_width = 40, - height = 31, - padding = -2 -} -:on_text_changed(function(player, element, _) - local value = tonumber(element.text) - if not value then value = 0 end - local clamped = math.clamp(value, 0, 1000) - local item_name = element.parent.tooltip - local entity_name = element.parent.parent.parent.name - if not autofill_player_settings[player.name] then return end - local setting = autofill_player_settings[player.name][entity_name] - if not setting then return end - local item = setting.items[item_name] - if not item then return end - item.amount = clamped - if clamped ~= value then - element.text = clamped - player.print{'autofill.invalid', item.amount, rich_img('item', item.name), rich_img('entity', entity_name) } - return - end -end) + :on_text_changed(function(player, element, _) + local value = tonumber(element.text) + if not value then value = 0 end + local clamped = math.clamp(value, 0, 1000) + local item_name = element.parent.tooltip + local entity_name = element.parent.parent.parent.name + if not autofill_player_settings[player.name] then return end + local setting = autofill_player_settings[player.name][entity_name] + if not setting then return end + local item = setting.items[item_name] + if not item then return end + item.amount = clamped + if clamped ~= value then + element.text = clamped + player.print{ "autofill.invalid", item.amount, rich_img("item", item.name), rich_img("entity", entity_name) } + return + end + end) --- Autofill setting, contains a button and a textbox -- @element add_autofill_setting local add_autofill_setting = -Gui.element(function(_, parent, item) - local toggle_flow = parent.add{ type = 'flow', name = 'toggle-setting-'..item.name, tooltip = item.name } - local amount_flow = parent.add{ type = 'flow', name = 'amount-setting-'..item.name, tooltip = item.name } - toggle_flow.style.padding = 0 - amount_flow.style.padding = 0 - toggle_item_button(toggle_flow, item) - amount_textfield(amount_flow, item) -end) + Gui.element(function(_, parent, item) + local toggle_flow = parent.add{ type = "flow", name = "toggle-setting-" .. item.name, tooltip = item.name } + local amount_flow = parent.add{ type = "flow", name = "amount-setting-" .. item.name, tooltip = item.name } + toggle_flow.style.padding = 0 + amount_flow.style.padding = 0 + toggle_item_button(toggle_flow, item) + amount_textfield(amount_flow, item) + end) --- Autofill setting empty, contains filler button and textfield gui elements -- @element add_empty_autofill_setting local add_empty_autofill_setting = -Gui.element(function(_, parent) - local toggle_element = parent.add{ - type = 'sprite-button' - } - toggle_element.style.right_margin = -3 - toggle_element.style.width = 32 - toggle_element.style.height = 32 - toggle_element.enabled = false - local amount_element = parent.add{ - type = 'textfield' - } - amount_element.style.maximal_width = 40 - amount_element.style.height = 31 - amount_element.style.padding = -2 - amount_element.enabled = false -end) - + Gui.element(function(_, parent) + local toggle_element = parent.add{ + type = "sprite-button", + } + toggle_element.style.right_margin = -3 + toggle_element.style.width = 32 + toggle_element.style.height = 32 + toggle_element.enabled = false + local amount_element = parent.add{ + type = "textfield", + } + amount_element.style.maximal_width = 40 + amount_element.style.height = 31 + amount_element.style.padding = -2 + amount_element.enabled = false + end) --- Main gui container for the left flow -- @element autofill_container autofill_container = -Gui.element(function(definition, parent) - -- Draw the internal container - local container = Gui.container(parent, definition.name) - -- Draw the scroll container - local scroll_table = Gui.scroll_table(container, 400, 1, 'autofill-scroll-table') - -- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size) - scroll_table.parent.vertical_scroll_policy = 'always' - -- Scroll panel has by default padding - scroll_table.parent.style.padding = 0 - -- Remove the default gap that is added in a table between elements - scroll_table.style.vertical_spacing = 0 - -- Center the first collumn in the table - scroll_table.style.column_alignments[1] = 'center' - -- Loop over each default entity config - for _, setting in pairs(config.default_entities) do - local table_sizes = {} - local tables = {} - -- Draw a section for the element - local entity_table = section(scroll_table, setting.entity, 3) - -- Add some padding around the table - entity_table.style.padding = 3 - -- Make sure each collumn is alignment top center - entity_table.style.column_alignments[1] = 'top-center' - entity_table.style.column_alignments[2] = 'top-center' - entity_table.style.column_alignments[3] = 'top-center' - -- Loop over each item category - for _, category in pairs(config.categories) do - if not table_sizes[category] then table_sizes[category] = 0 end - -- Draw table - local category_table = entity_table.add{ - type = 'table', - name = category..'-category', - column_count = 2 - } - -- Add padding between each item - category_table.style.vertical_spacing = 1 - tables[category] = category_table - -- Add item autofill setting gui elements to the table - for _, item in pairs(setting.items) do - if item.category == category then - add_autofill_setting(category_table, item) - table_sizes[category] = table_sizes[category] + 1 + Gui.element(function(definition, parent) + -- Draw the internal container + local container = Gui.container(parent, definition.name) + -- Draw the scroll container + local scroll_table = Gui.scroll_table(container, 400, 1, "autofill-scroll-table") + -- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size) + scroll_table.parent.vertical_scroll_policy = "always" + -- Scroll panel has by default padding + scroll_table.parent.style.padding = 0 + -- Remove the default gap that is added in a table between elements + scroll_table.style.vertical_spacing = 0 + -- Center the first collumn in the table + scroll_table.style.column_alignments[1] = "center" + -- Loop over each default entity config + for _, setting in pairs(config.default_entities) do + local table_sizes = {} + local tables = {} + -- Draw a section for the element + local entity_table = section(scroll_table, setting.entity, 3) + -- Add some padding around the table + entity_table.style.padding = 3 + -- Make sure each collumn is alignment top center + entity_table.style.column_alignments[1] = "top-center" + entity_table.style.column_alignments[2] = "top-center" + entity_table.style.column_alignments[3] = "top-center" + -- Loop over each item category + for _, category in pairs(config.categories) do + if not table_sizes[category] then table_sizes[category] = 0 end + -- Draw table + local category_table = entity_table.add{ + type = "table", + name = category .. "-category", + column_count = 2, + } + -- Add padding between each item + category_table.style.vertical_spacing = 1 + tables[category] = category_table + -- Add item autofill setting gui elements to the table + for _, item in pairs(setting.items) do + if item.category == category then + add_autofill_setting(category_table, item) + table_sizes[category] = table_sizes[category] + 1 + end + end + end + + -- Add empty gui elements for the categories with less items than the other categories + local t = table.get_values(table_sizes) + table.sort(t) + local biggest = t[#t] + for category, size in pairs(table_sizes) do + for i = biggest - size, 1, -1 do + add_empty_autofill_setting(tables[category]) end end end - -- Add empty gui elements for the categories with less items than the other categories - local t = table.get_values(table_sizes) - table.sort(t) - local biggest = t[#t] - for category, size in pairs(table_sizes) do - for i=biggest-size,1,-1 do - add_empty_autofill_setting(tables[category]) - end - end - end - - -- Return the external container - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + -- Return the external container + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() --- Button on the top flow used to toggle autofill container -- @element autofill_toggle -Gui.left_toolbar_button(config.icon, {'autofill.main-tooltip'}, autofill_container, function(player) - return Roles.player_allowed(player, 'gui/autofill') +Gui.left_toolbar_button(config.icon, { "autofill.main-tooltip" }, autofill_container, function(player) + return Roles.player_allowed(player, "gui/autofill") end) --- When a player is created make sure they have the default autofill settings @@ -341,19 +339,19 @@ local function entity_build(event) if item_amount ~= 0 then local inserted text_position.y = text_position.y - 0.5 - local color = { r = 0, g = 255, b = 0, a = 1} + local color = { r = 0, g = 255, b = 0, a = 1 } if item_amount >= preferd_amount then -- Can item be inserted? no, goto next item! - if not entity_inventory.can_insert{name=item.name, count=preferd_amount} then + if not entity_inventory.can_insert{ name = item.name, count = preferd_amount } then goto end_item end - inserted = entity_inventory.insert{name=item.name, count=preferd_amount} + inserted = entity_inventory.insert{ name = item.name, count = preferd_amount } else - inserted = entity_inventory.insert{name=item.name, count=item_amount} - color = { r = 255, g = 165, b = 0, a = 1} + inserted = entity_inventory.insert{ name = item.name, count = item_amount } + color = { r = 255, g = 165, b = 0, a = 1 } end - player_inventory.remove{name=item.name, count=inserted} - print_text(entity.surface, text_position, {'autofill.inserted', inserted, rich_img('item', item.name), rich_img('entity', entity.name) }, color) + player_inventory.remove{ name = item.name, count = inserted } + print_text(entity.surface, text_position, { "autofill.inserted", inserted, rich_img("item", item.name), rich_img("entity", entity.name) }, color) end ::end_item:: end diff --git a/exp_legacy/module/modules/gui/bonus.lua b/exp_legacy/module/modules/gui/bonus.lua index 5e0a75af..b61790ee 100644 --- a/exp_legacy/module/modules/gui/bonus.lua +++ b/exp_legacy/module/modules/gui/bonus.lua @@ -13,25 +13,26 @@ local bonus_container local function bonus_gui_pts_needed(player) local frame = Gui.get_left_element(player, bonus_container) - local disp = frame.container['bonus_st_2'].disp.table + local disp = frame.container["bonus_st_2"].disp.table local total = 0 for k, v in pairs(config.conversion) do - total = total + (disp['bonus_display_' .. k .. '_slider'].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost) + total = total + (disp["bonus_display_" .. k .. "_slider"].slider_value / config.player_bonus[v].cost_scale * config.player_bonus[v].cost) end - total = total + (disp['bonus_display_personal_battery_recharge_slider'].slider_value / config.player_special_bonus['personal_battery_recharge'].cost_scale * config.player_special_bonus['personal_battery_recharge'].cost) + total = total + + (disp["bonus_display_personal_battery_recharge_slider"].slider_value / config.player_special_bonus["personal_battery_recharge"].cost_scale * config.player_special_bonus["personal_battery_recharge"].cost) return total end local function apply_bonus(player) - if not Roles.player_allowed(player, 'gui/bonus') then + if not Roles.player_allowed(player, "gui/bonus") then for k, v in pairs(config.player_bonus) do player[k] = 0 if v.combined_bonus then - for i=1, #v.combined_bonus do + for i = 1, #v.combined_bonus do player[v.combined_bonus[i]] = 0 end end @@ -45,21 +46,21 @@ local function apply_bonus(player) end local frame = Gui.get_left_element(player, bonus_container) - local disp = frame.container['bonus_st_2'].disp.table + local disp = frame.container["bonus_st_2"].disp.table for k, v in pairs(config.conversion) do - player[v] = disp['bonus_display_' .. k .. '_slider'].slider_value + player[v] = disp["bonus_display_" .. k .. "_slider"].slider_value if config.player_bonus[v].combined_bonus then - for i=1, #config.player_bonus[v].combined_bonus do - player[config.player_bonus[v].combined_bonus[i]] = disp['bonus_display_' .. k .. '_slider'].slider_value + for i = 1, #config.player_bonus[v].combined_bonus do + player[config.player_bonus[v].combined_bonus[i]] = disp["bonus_display_" .. k .. "_slider"].slider_value end end end end local function apply_periodic_bonus(player) - if not Roles.player_allowed(player, 'gui/bonus') then + if not Roles.player_allowed(player, "gui/bonus") then return end @@ -68,19 +69,19 @@ local function apply_periodic_bonus(player) end local frame = Gui.get_left_element(player, bonus_container) - local disp = frame.container['bonus_st_2'].disp.table + local disp = frame.container["bonus_st_2"].disp.table - if vlayer.get_statistics()['energy_sustained'] > 0 then + if vlayer.get_statistics()["energy_sustained"] > 0 then local armor = player.get_inventory(defines.inventory.character_armor)[1].grid if armor then - local slider = disp['bonus_display_personal_battery_recharge_slider'].slider_value * 100000 * config.player_special_bonus_rate / 6 + local slider = disp["bonus_display_personal_battery_recharge_slider"].slider_value * 100000 * config.player_special_bonus_rate / 6 - for i=1, #armor.equipment do + for i = 1, #armor.equipment do if armor.equipment[i].energy < armor.equipment[i].max_energy then - local energy_required = math.min(math.floor(armor.equipment[i].max_energy - armor.equipment[i].energy), vlayer.get_statistics()['energy_storage'], slider) + local energy_required = math.min(math.floor(armor.equipment[i].max_energy - armor.equipment[i].energy), vlayer.get_statistics()["energy_storage"], slider) armor.equipment[i].energy = armor.equipment[i].energy + energy_required - vlayer.energy_changed(- energy_required) + vlayer.energy_changed(-energy_required) slider = slider - energy_required end @@ -92,250 +93,248 @@ end --- Control label for the bonus points available -- @element bonus_gui_control_pts_a local bonus_gui_control_pts_a = -Gui.element{ - type = 'label', - name = 'bonus_control_pts_a', - caption = {'bonus.control-pts-a'}, - style = 'heading_2_label' -}:style{ - width = config.gui_display_width['half'] -} + Gui.element{ + type = "label", + name = "bonus_control_pts_a", + caption = { "bonus.control-pts-a" }, + style = "heading_2_label", + }:style{ + width = config.gui_display_width["half"], + } local bonus_gui_control_pts_a_count = -Gui.element{ - type = 'label', - name = 'bonus_control_pts_a_count', - caption = config.pts.base, - style = 'heading_2_label' -}:style{ - width = config.gui_display_width['half'] -} + Gui.element{ + type = "label", + name = "bonus_control_pts_a_count", + caption = config.pts.base, + style = "heading_2_label", + }:style{ + width = config.gui_display_width["half"], + } --- Control label for the bonus points needed -- @element bonus_gui_control_pts_n local bonus_gui_control_pts_n = -Gui.element{ - type = 'label', - name = 'bonus_control_pts_n', - caption = {'bonus.control-pts-n'}, - style = 'heading_2_label' -}:style{ - width = config.gui_display_width['half'] -} + Gui.element{ + type = "label", + name = "bonus_control_pts_n", + caption = { "bonus.control-pts-n" }, + style = "heading_2_label", + }:style{ + width = config.gui_display_width["half"], + } local bonus_gui_control_pts_n_count = -Gui.element{ - type = 'label', - name = 'bonus_control_pts_n_count', - caption = '0', - style = 'heading_2_label' -}:style{ - width =config.gui_display_width['half'] -} + Gui.element{ + type = "label", + name = "bonus_control_pts_n_count", + caption = "0", + style = "heading_2_label", + }:style{ + width = config.gui_display_width["half"], + } --- Control label for the bonus points remaining -- @element bonus_gui_control_pts_r local bonus_gui_control_pts_r = -Gui.element{ - type = 'label', - name = 'bonus_control_pts_r', - caption = {'bonus.control-pts-r'}, - style = 'heading_2_label' -}:style{ - width = config.gui_display_width['half'] -} + Gui.element{ + type = "label", + name = "bonus_control_pts_r", + caption = { "bonus.control-pts-r" }, + style = "heading_2_label", + }:style{ + width = config.gui_display_width["half"], + } local bonus_gui_control_pts_r_count = -Gui.element{ - type = 'label', - name = 'bonus_control_pts_r_count', - caption = '0', - style = 'heading_2_label' -}:style{ - width = config.gui_display_width['half'] -} + Gui.element{ + type = "label", + name = "bonus_control_pts_r_count", + caption = "0", + style = "heading_2_label", + }:style{ + width = config.gui_display_width["half"], + } --- A button used for pts calculations -- @element bonus_gui_control_refresh local bonus_gui_control_reset = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = {'bonus.control-reset'} -}:style{ - width = config.gui_display_width['half'] -}:on_click(function(player, element, _) - local frame = Gui.get_left_element(player, bonus_container) - local disp = frame.container['bonus_st_2'].disp.table + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "bonus.control-reset" }, + }:style{ + width = config.gui_display_width["half"], + }:on_click(function(player, element, _) + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container["bonus_st_2"].disp.table - for k, v in pairs(config.conversion) do - local s = 'bonus_display_' .. k .. '_slider' - disp[s].slider_value = config.player_bonus[v].value + for k, v in pairs(config.conversion) do + local s = "bonus_display_" .. k .. "_slider" + disp[s].slider_value = config.player_bonus[v].value - if config.player_bonus[v].is_percentage then - disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100) .. ' %' - - else - disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value) + if config.player_bonus[v].is_percentage then + disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value * 100) .. " %" + else + disp[disp[s].tags.counter].caption = format_number(disp[s].slider_value) + end end - end - local slider = disp['bonus_display_personal_battery_recharge_slider'] - slider.slider_value = config.player_special_bonus['personal_battery_recharge'].value - disp[slider.tags.counter].caption = format_number(slider.slider_value) + local slider = disp["bonus_display_personal_battery_recharge_slider"] + slider.slider_value = config.player_special_bonus["personal_battery_recharge"].value + disp[slider.tags.counter].caption = format_number(slider.slider_value) - local r = bonus_gui_pts_needed(player) - element.parent[bonus_gui_control_pts_n_count.name].caption = r - element.parent[bonus_gui_control_pts_r_count.name].caption = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - r -end) + local r = bonus_gui_pts_needed(player) + element.parent[bonus_gui_control_pts_n_count.name].caption = r + element.parent[bonus_gui_control_pts_r_count.name].caption = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - r + end) --- A button used for pts apply -- @element bonus_gui_control_apply local bonus_gui_control_apply = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = {'bonus.control-apply'} -}:style{ - width = config.gui_display_width['half'] -}:on_click(function(player, element, _) - local n = bonus_gui_pts_needed(player) - element.parent[bonus_gui_control_pts_n_count.name].caption = n - local r = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - n - element.parent[bonus_gui_control_pts_r_count.name].caption = r + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "bonus.control-apply" }, + }:style{ + width = config.gui_display_width["half"], + }:on_click(function(player, element, _) + local n = bonus_gui_pts_needed(player) + element.parent[bonus_gui_control_pts_n_count.name].caption = n + local r = tonumber(element.parent[bonus_gui_control_pts_a_count.name].caption) - n + element.parent[bonus_gui_control_pts_r_count.name].caption = r - if r >= 0 then - apply_bonus(player) - end -end) + if r >= 0 then + apply_bonus(player) + end + end) --- A vertical flow containing all the bonus control -- @element bonus_control_set local bonus_control_set = -Gui.element(function(_, parent, name) - local bonus_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(bonus_set, config.gui_display_width['half'] * 2, 2, 'disp') + Gui.element(function(_, parent, name) + local bonus_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(bonus_set, config.gui_display_width["half"] * 2, 2, "disp") - bonus_gui_control_pts_a(disp) - bonus_gui_control_pts_a_count(disp) + bonus_gui_control_pts_a(disp) + bonus_gui_control_pts_a_count(disp) - bonus_gui_control_pts_n(disp) - bonus_gui_control_pts_n_count(disp) + bonus_gui_control_pts_n(disp) + bonus_gui_control_pts_n_count(disp) - bonus_gui_control_pts_r(disp) - bonus_gui_control_pts_r_count(disp) + bonus_gui_control_pts_r(disp) + bonus_gui_control_pts_r_count(disp) - bonus_gui_control_reset(disp) - bonus_gui_control_apply(disp) + bonus_gui_control_reset(disp) + bonus_gui_control_apply(disp) - return bonus_set -end) + return bonus_set + end) --- Display group -- @element bonus_gui_slider local bonus_gui_slider = -Gui.element(function(_definition, parent, name, caption, tooltip, bonus) - local label = parent.add{ - type = 'label', - caption = caption, - tooltip = tooltip, - style = 'heading_2_label' - } - label.style.width = config.gui_display_width['label'] - - local value = bonus.value - - if bonus.is_percentage then - value = format_number(value * 100) .. ' %' - - else - value = format_number(value) - end - - local slider = parent.add{ - type = 'slider', - name = name .. '_slider', - value = bonus.value, - maximum_value = bonus.max, - value_step = bonus.scale, - discrete_values = true, - style = 'notched_slider', - tags = { - counter = name .. '_count', - is_percentage = bonus.is_percentage + Gui.element(function(_definition, parent, name, caption, tooltip, bonus) + local label = parent.add{ + type = "label", + caption = caption, + tooltip = tooltip, + style = "heading_2_label", } - } - slider.style.width = config.gui_display_width['slider'] - slider.style.horizontally_stretchable = true + label.style.width = config.gui_display_width["label"] - local count = parent.add{ - type = 'label', - name = name .. '_count', - caption = value, - style = 'heading_2_label', - } - count.style.width = config.gui_display_width['count'] + local value = bonus.value - return slider -end) -:on_value_changed(function(player, element, _event) - if element.tags.is_percentage then - element.parent[element.tags.counter].caption = format_number(element.slider_value * 100) .. ' %' + if bonus.is_percentage then + value = format_number(value * 100) .. " %" + else + value = format_number(value) + end - else - element.parent[element.tags.counter].caption = format_number(element.slider_value) - end + local slider = parent.add{ + type = "slider", + name = name .. "_slider", + value = bonus.value, + maximum_value = bonus.max, + value_step = bonus.scale, + discrete_values = true, + style = "notched_slider", + tags = { + counter = name .. "_count", + is_percentage = bonus.is_percentage, + }, + } + slider.style.width = config.gui_display_width["slider"] + slider.style.horizontally_stretchable = true - local r = bonus_gui_pts_needed(player) - local frame = Gui.get_left_element(player, bonus_container) - local disp = frame.container['bonus_st_1'].disp.table - disp[bonus_gui_control_pts_n_count.name].caption = r - disp[bonus_gui_control_pts_r_count.name].caption = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - r -end) + local count = parent.add{ + type = "label", + name = name .. "_count", + caption = value, + style = "heading_2_label", + } + count.style.width = config.gui_display_width["count"] + + return slider + end) + :on_value_changed(function(player, element, _event) + if element.tags.is_percentage then + element.parent[element.tags.counter].caption = format_number(element.slider_value * 100) .. " %" + else + element.parent[element.tags.counter].caption = format_number(element.slider_value) + end + + local r = bonus_gui_pts_needed(player) + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container["bonus_st_1"].disp.table + disp[bonus_gui_control_pts_n_count.name].caption = r + disp[bonus_gui_control_pts_r_count.name].caption = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - r + end) --- A vertical flow containing all the bonus data -- @element bonus_data_set local bonus_data_set = -Gui.element(function(_, parent, name) - local bonus_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(bonus_set, config.gui_display_width['half'] * 2, 3, 'disp') + Gui.element(function(_, parent, name) + local bonus_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(bonus_set, config.gui_display_width["half"] * 2, 3, "disp") - for k, v in pairs(config.conversion) do - bonus_gui_slider(disp, 'bonus_display_' .. k, {'bonus.display-' .. k}, {'bonus.display-' .. k .. '-tooltip'}, config.player_bonus[v]) - end + for k, v in pairs(config.conversion) do + bonus_gui_slider(disp, "bonus_display_" .. k, { "bonus.display-" .. k }, { "bonus.display-" .. k .. "-tooltip" }, config.player_bonus[v]) + end - bonus_gui_slider(disp, 'bonus_display_personal_battery_recharge', {'bonus.display-personal-battery-recharge'}, {'bonus.display-personal-battery-recharge-tooltip'}, config.player_special_bonus['personal_battery_recharge']) + bonus_gui_slider(disp, "bonus_display_personal_battery_recharge", { "bonus.display-personal-battery-recharge" }, { "bonus.display-personal-battery-recharge-tooltip" }, + config.player_special_bonus["personal_battery_recharge"]) - return bonus_set -end) + return bonus_set + end) --- The main container for the bonus gui -- @element bonus_container bonus_container = -Gui.element(function(definition, parent) - local player = Gui.get_player_from_element(parent) - local container = Gui.container(parent, definition.name, config.gui_display_width['half'] * 2) + Gui.element(function(definition, parent) + local player = Gui.get_player_from_element(parent) + local container = Gui.container(parent, definition.name, config.gui_display_width["half"] * 2) - bonus_control_set(container, 'bonus_st_1') - bonus_data_set(container, 'bonus_st_2') + bonus_control_set(container, "bonus_st_1") + bonus_data_set(container, "bonus_st_2") - local frame = Gui.get_left_element(player, bonus_container) - local disp = frame.container['bonus_st_1'].disp.table - local n = bonus_gui_pts_needed(player) - disp[bonus_gui_control_pts_n_count.name].caption = n - local r = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - n - disp[bonus_gui_control_pts_r_count.name].caption = r + local frame = Gui.get_left_element(player, bonus_container) + local disp = frame.container["bonus_st_1"].disp.table + local n = bonus_gui_pts_needed(player) + disp[bonus_gui_control_pts_n_count.name].caption = n + local r = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - n + disp[bonus_gui_control_pts_r_count.name].caption = r - apply_bonus(player) - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + apply_bonus(player) + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() --- Button on the top flow used to toggle the bonus container -- @element toggle_left_element -Gui.left_toolbar_button('item/exoskeleton-equipment', {'bonus.main-tooltip'}, bonus_container, function(player) - return Roles.player_allowed(player, 'gui/bonus') +Gui.left_toolbar_button("item/exoskeleton-equipment", { "bonus.main-tooltip" }, bonus_container, function(player) + return Roles.player_allowed(player, "gui/bonus") end) Event.add(defines.events.on_player_created, function(event) @@ -364,7 +363,7 @@ end) Event.add(defines.events.on_player_respawned, function(event) local player = game.players[event.player_index] local frame = Gui.get_left_element(player, bonus_container) - local disp = frame.container['bonus_st_1'].disp.table + local disp = frame.container["bonus_st_1"].disp.table local n = bonus_gui_pts_needed(player) disp[bonus_gui_control_pts_n_count.name].caption = n local r = tonumber(disp[bonus_gui_control_pts_a_count.name].caption) - n @@ -379,7 +378,7 @@ end) Event.add(defines.events.on_player_died, function(event) local player = game.players[event.player_index] - if Roles.player_has_flag(player, 'instant-respawn') then + if Roles.player_has_flag(player, "instant-respawn") then player.ticks_to_respawn = 120 end end) diff --git a/exp_legacy/module/modules/gui/debug/_g_view.lua b/exp_legacy/module/modules/gui/debug/_g_view.lua index 6802d4b8..107f9e14 100644 --- a/exp_legacy/module/modules/gui/debug/_g_view.lua +++ b/exp_legacy/module/modules/gui/debug/_g_view.lua @@ -30,7 +30,7 @@ local ignore = { type = true, xpcall = true, _VERSION = true, - ['module'] = true, + ["module"] = true, require = true, package = true, unpack = true, @@ -51,31 +51,31 @@ local ignore = { util = true, mod_gui = true, game = true, - rendering = true + rendering = true, } local header_name = Gui.uid_name() local left_panel_name = Gui.uid_name() local right_panel_name = Gui.uid_name() -Public.name = '_G' +Public.name = "_G" function Public.show(container) - local main_flow = container.add {type = 'flow', direction = 'horizontal'} + local main_flow = container.add{ type = "flow", direction = "horizontal" } - local left_panel = main_flow.add {type = 'scroll-pane', name = left_panel_name} + local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name } local left_panel_style = left_panel.style left_panel_style.width = 300 for key, value in pairs(_G) do if not ignore[key] then local header = - left_panel.add({type = 'flow'}).add {type = 'label', name = header_name, caption = tostring(key)} + left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = tostring(key) } Gui.set_data(header, value) end end - local right_panel = main_flow.add {type = 'text-box', name = right_panel_name} + local right_panel = main_flow.add{ type = "text-box", name = right_panel_name } right_panel.read_only = true right_panel.selectable = true @@ -85,7 +85,7 @@ function Public.show(container) right_panel_style.maximal_width = 1000 right_panel_style.maximal_height = 1000 - Gui.set_data(left_panel, {right_panel = right_panel, selected_header = nil}) + Gui.set_data(left_panel, { right_panel = right_panel, selected_header = nil }) end Gui.on_click( diff --git a/exp_legacy/module/modules/gui/debug/event_view.lua b/exp_legacy/module/modules/gui/debug/event_view.lua index 20df146b..6867cc59 100644 --- a/exp_legacy/module/modules/gui/debug/event_view.lua +++ b/exp_legacy/module/modules/gui/debug/event_view.lua @@ -13,7 +13,7 @@ local events_to_keep = 10 -- Local vars local Public = { - name = 'Events' + name = "Events", } local name_lookup = {} @@ -28,7 +28,7 @@ local last_events = {} storage.debug_event_view = { enabled = enabled, last_events = last_events, - filter = '' + filter = "", } function Public.on_open_debug() @@ -42,7 +42,7 @@ function Public.on_open_debug() storage.debug_event_view = { enabled = enabled, - last_events = last_events + last_events = last_events, } end @@ -65,7 +65,7 @@ local function event_callback(event) last_events[name][events_to_keep + 1] = nil event.name = nil - local str = format('%s (id = %s): %s', name, id, Model.dump(event)) + local str = format("%s (id = %s): %s", name, id, Model.dump(event)) game.print(str) log(str) end @@ -95,13 +95,13 @@ table.sort(grid_builder) local function redraw_event_table(gui_table, filter) for _, event_name in pairs(grid_builder) do - if filter == '' or event_name:find(filter) then + if filter == "" or event_name:find(filter) then local index = events[event_name] - gui_table.add({type = 'flow'}).add { + gui_table.add{ type = "flow" }.add{ name = checkbox_name, - type = 'checkbox', + type = "checkbox", state = enabled[index] or false, - caption = event_name + caption = event_name, } end end @@ -110,18 +110,18 @@ end function Public.show(container) local filter = storage.debug_event_view.filter - local main_frame_flow = container.add({type = 'flow', direction = 'vertical'}) + local main_frame_flow = container.add{ type = "flow", direction = "vertical" } - local filter_flow = main_frame_flow.add({type = 'flow', direction = 'horizontal'}) - filter_flow.add({type = 'label', caption = 'filter'}) - local filter_textfield = filter_flow.add({type = 'textfield', name = filter_name, text = filter}) - local clear_button = filter_flow.add({type = 'button', name = clear_filter_name, caption = 'clear'}) + local filter_flow = main_frame_flow.add{ type = "flow", direction = "horizontal" } + filter_flow.add{ type = "label", caption = "filter" } + local filter_textfield = filter_flow.add{ type = "textfield", name = filter_name, text = filter } + local clear_button = filter_flow.add{ type = "button", name = clear_filter_name, caption = "clear" } - local scroll_pane = main_frame_flow.add({type = 'scroll-pane'}) - local gui_table = scroll_pane.add({type = 'table', column_count = 3, draw_horizontal_lines = true}) + local scroll_pane = main_frame_flow.add{ type = "scroll-pane" } + local gui_table = scroll_pane.add{ type = "table", column_count = 3, draw_horizontal_lines = true } Gui.set_data(filter_textfield, gui_table) - Gui.set_data(clear_button, {gui_table = gui_table, filter_textfield = filter_textfield}) + Gui.set_data(clear_button, { gui_table = gui_table, filter_textfield = filter_textfield }) redraw_event_table(gui_table, filter) end @@ -134,7 +134,7 @@ Gui.on_text_changed( local element = event.element local gui_table = Gui.get_data(element) - local filter = element.text:gsub(' ', '_') + local filter = element.text:gsub(" ", "_") storage.debug_event_view.filter = filter element.text = filter @@ -152,11 +152,11 @@ Gui.on_click( local filter_textfield = data.filter_textfield local gui_table = data.gui_table - filter_textfield.text = '' - storage.debug_event_view.filter = '' + filter_textfield.text = "" + storage.debug_event_view.filter = "" gui_table.clear() - redraw_event_table(gui_table, '') + redraw_event_table(gui_table, "") end ) diff --git a/exp_legacy/module/modules/gui/debug/expcore_datastore_view.lua b/exp_legacy/module/modules/gui/debug/expcore_datastore_view.lua index 611aa1f7..e28f4784 100644 --- a/exp_legacy/module/modules/gui/debug/expcore_datastore_view.lua +++ b/exp_legacy/module/modules/gui/debug/expcore_datastore_view.lua @@ -14,37 +14,37 @@ local right_panel_name = Gui.uid_name() local input_text_box_name = Gui.uid_name() local refresh_name = Gui.uid_name() -Public.name = 'Datastore' +Public.name = "Datastore" function Public.show(container) - local main_flow = container.add {type = 'flow', direction = 'horizontal'} + local main_flow = container.add{ type = "flow", direction = "horizontal" } - local left_panel = main_flow.add {type = 'scroll-pane', name = left_panel_name} + local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name } local left_panel_style = left_panel.style left_panel_style.width = 300 for name in pairs(table.keysort(Datastore.debug())) do - local header = left_panel.add({type = 'flow'}).add {type = 'label', name = header_name, caption = name} + local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = name } Gui.set_data(header, name) end - local right_flow = main_flow.add {type = 'flow', direction = 'vertical'} + local right_flow = main_flow.add{ type = "flow", direction = "vertical" } - local right_top_flow = right_flow.add {type = 'flow', direction = 'horizontal'} + local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" } - local input_text_box = right_top_flow.add {type = 'text-box', name = input_text_box_name} + local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name } local input_text_box_style = input_text_box.style input_text_box_style.horizontally_stretchable = true input_text_box_style.height = 32 input_text_box_style.maximal_width = 1000 local refresh_button = - right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'} + right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" } local refresh_button_style = refresh_button.style refresh_button_style.width = 32 refresh_button_style.height = 32 - local right_panel = right_flow.add {type = 'text-box', name = right_panel_name} + local right_panel = right_flow.add{ type = "text-box", name = right_panel_name } right_panel.read_only = true right_panel.selectable = true @@ -57,7 +57,7 @@ function Public.show(container) local data = { right_panel = right_panel, input_text_box = input_text_box, - selected_header = nil + selected_header = nil, } Gui.set_data(input_text_box, data) @@ -90,9 +90,10 @@ Gui.on_click( local content = Datastore.debug(tableName) local content_string = {} for key, value in pairs(content) do - content_string[#content_string+1] = key:gsub('^%l', string.upper)..' = '..dump(value) + content_string[#content_string + 1] = key:gsub("^%l", string.upper) .. " = " .. dump(value) end - right_panel.text = concat(content_string, '\n') + + right_panel.text = concat(content_string, "\n") end ) @@ -100,9 +101,10 @@ local function update_dump(text_input, data) local content = Datastore.debug(text_input.text) local content_string = {} for key, value in pairs(content) do - content_string[#content_string+1] = key:gsub('^%l', string.upper)..' = '..dump(value) + content_string[#content_string + 1] = key:gsub("^%l", string.upper) .. " = " .. dump(value) end - data.right_panel.text = concat(content_string, '\n') + + data.right_panel.text = concat(content_string, "\n") end Gui.on_text_changed( diff --git a/exp_legacy/module/modules/gui/debug/expcore_gui_view.lua b/exp_legacy/module/modules/gui/debug/expcore_gui_view.lua index 68a57f99..baf3d352 100644 --- a/exp_legacy/module/modules/gui/debug/expcore_gui_view.lua +++ b/exp_legacy/module/modules/gui/debug/expcore_gui_view.lua @@ -15,37 +15,37 @@ local right_panel_name = Gui.uid_name() local input_text_box_name = Gui.uid_name() local refresh_name = Gui.uid_name() -Public.name = 'Elements' +Public.name = "Elements" function Public.show(container) - local main_flow = container.add {type = 'flow', direction = 'horizontal'} + local main_flow = container.add{ type = "flow", direction = "horizontal" } - local left_panel = main_flow.add {type = 'scroll-pane', name = left_panel_name} + local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name } local left_panel_style = left_panel.style left_panel_style.width = 300 for element_id, file_path in pairs(ExpGui.file_paths) do - local header = left_panel.add({type = 'flow'}).add {type = 'label', name = header_name, caption = element_id..' - '..file_path} + local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = element_id .. " - " .. file_path } Gui.set_data(header, element_id) end - local right_flow = main_flow.add {type = 'flow', direction = 'vertical'} + local right_flow = main_flow.add{ type = "flow", direction = "vertical" } - local right_top_flow = right_flow.add {type = 'flow', direction = 'horizontal'} + local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" } - local input_text_box = right_top_flow.add {type = 'text-box', name = input_text_box_name} + local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name } local input_text_box_style = input_text_box.style input_text_box_style.horizontally_stretchable = true input_text_box_style.height = 32 input_text_box_style.maximal_width = 1000 local refresh_button = - right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'} + right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" } local refresh_button_style = refresh_button.style refresh_button_style.width = 32 refresh_button_style.height = 32 - local right_panel = right_flow.add {type = 'text-box', name = right_panel_name} + local right_panel = right_flow.add{ type = "text-box", name = right_panel_name } right_panel.read_only = true right_panel.selectable = true @@ -58,7 +58,7 @@ function Public.show(container) local data = { right_panel = right_panel, input_text_box = input_text_box, - selected_header = nil + selected_header = nil, } Gui.set_data(input_text_box, data) @@ -85,10 +85,10 @@ Gui.on_click( element.style.font_color = Color.orange data.selected_header = element - input_text_box.text = concat {'Gui.defines[', element_id, ']'} + input_text_box.text = concat{ "Gui.defines[", element_id, "]" } input_text_box.style.font_color = Color.black - local content = dump(ExpGui.debug_info[element_id]) or 'nil' + local content = dump(ExpGui.debug_info[element_id]) or "nil" right_panel.text = content end ) diff --git a/exp_legacy/module/modules/gui/debug/global_view.lua b/exp_legacy/module/modules/gui/debug/global_view.lua index 7deba872..03da4ae9 100644 --- a/exp_legacy/module/modules/gui/debug/global_view.lua +++ b/exp_legacy/module/modules/gui/debug/global_view.lua @@ -8,7 +8,7 @@ local concat = table.concat local Public = {} -local ignore = {tokens = true, data_store = true, datastores = true} +local ignore = { tokens = true, data_store = true, datastores = true } local header_name = Gui.uid_name() local left_panel_name = Gui.uid_name() @@ -16,40 +16,40 @@ local right_panel_name = Gui.uid_name() local input_text_box_name = Gui.uid_name() local refresh_name = Gui.uid_name() -Public.name = 'storage' +Public.name = "storage" function Public.show(container) - local main_flow = container.add {type = 'flow', direction = 'horizontal'} + local main_flow = container.add{ type = "flow", direction = "horizontal" } - local left_panel = main_flow.add {type = 'scroll-pane', name = left_panel_name} + local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name } local left_panel_style = left_panel.style left_panel_style.width = 300 for key, _ in pairs(storage) do if not ignore[key] then local header = - left_panel.add({type = 'flow'}).add {type = 'label', name = header_name, caption = tostring(key)} + left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = tostring(key) } Gui.set_data(header, key) end end - local right_flow = main_flow.add {type = 'flow', direction = 'vertical'} + local right_flow = main_flow.add{ type = "flow", direction = "vertical" } - local right_top_flow = right_flow.add {type = 'flow', direction = 'horizontal'} + local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" } - local input_text_box = right_top_flow.add {type = 'text-box', name = input_text_box_name} + local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name } local input_text_box_style = input_text_box.style input_text_box_style.horizontally_stretchable = true input_text_box_style.height = 32 input_text_box_style.maximal_width = 1000 local refresh_button = - right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'} + right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" } local refresh_button_style = refresh_button.style refresh_button_style.width = 32 refresh_button_style.height = 32 - local right_panel = right_flow.add {type = 'text-box', name = right_panel_name} + local right_panel = right_flow.add{ type = "text-box", name = right_panel_name } right_panel.read_only = true right_panel.selectable = true @@ -63,7 +63,7 @@ function Public.show(container) right_panel = right_panel, input_text_box = input_text_box, selected_header = nil, - selected_token_id = nil + selected_token_id = nil, } Gui.set_data(input_text_box, data) @@ -90,10 +90,10 @@ Gui.on_click( element.style.font_color = Color.orange data.selected_header = element - input_text_box.text = concat {"storage['", key, "']"} + input_text_box.text = concat{ "storage['", key, "']" } input_text_box.style.font_color = Color.black - local content = dump(storage[key]) or 'nil' + local content = dump(storage[key]) or "nil" right_panel.text = content end ) diff --git a/exp_legacy/module/modules/gui/debug/main_view.lua b/exp_legacy/module/modules/gui/debug/main_view.lua index c15c47d3..349ec282 100644 --- a/exp_legacy/module/modules/gui/debug/main_view.lua +++ b/exp_legacy/module/modules/gui/debug/main_view.lua @@ -10,7 +10,7 @@ local pages = { require("modules.exp_legacy.modules.gui.debug.global_view"), require("modules.exp_legacy.modules.gui.debug.package_view"), require("modules.exp_legacy.modules.gui.debug._g_view"), - require("modules.exp_legacy.modules.gui.debug.event_view") + require("modules.exp_legacy.modules.gui.debug.event_view"), } local main_frame_name = Gui.uid_name() @@ -40,23 +40,23 @@ function Public.open_dubug(player) frame.auto_center = true ]] - frame = center.add {type = 'frame', name = main_frame_name, caption = 'Debuggertron 3002', direction = 'vertical'} + frame = center.add{ type = "frame", name = main_frame_name, caption = "Debuggertron 3002", direction = "vertical" } local frame_style = frame.style frame_style.height = 600 frame_style.width = 900 - local tab_flow = frame.add {type = 'flow', direction = 'horizontal'} - local container = frame.add {type = 'flow'} + local tab_flow = frame.add{ type = "flow", direction = "horizontal" } + local container = frame.add{ type = "flow" } container.style.vertically_stretchable = true local data = {} for i = 1, #pages do local page = pages[i] - local tab_button = tab_flow.add({type = 'flow'}).add {type = 'button', name = tab_name, caption = page.name} + local tab_button = tab_flow.add{ type = "flow" }.add{ type = "button", name = tab_name, caption = page.name } local tab_button_style = tab_button.style - Gui.set_data(tab_button, {index = i, frame_data = data}) + Gui.set_data(tab_button, { index = i, frame_data = data }) if i == 1 then tab_button_style.font_color = Color.orange @@ -70,7 +70,7 @@ function Public.open_dubug(player) end end - frame.add {type = 'button', name = close_name, caption = 'Close'} + frame.add{ type = "button", name = close_name, caption = "Close" } end Gui.on_click( diff --git a/exp_legacy/module/modules/gui/debug/model.lua b/exp_legacy/module/modules/gui/debug/model.lua index 951d14d8..80082369 100644 --- a/exp_legacy/module/modules/gui/debug/model.lua +++ b/exp_legacy/module/modules/gui/debug/model.lua @@ -6,72 +6,72 @@ local type = type local concat = table.concat local inspect = table.inspect local pcall = pcall -local loadstring = loadstring ---@diagnostic disable-line +local loadstring = loadstring --- @diagnostic disable-line local rawset = rawset local Public = {} -local luaObject = {'{', nil, ", name = '", nil, "'}"} -local luaPlayer = {"{LuaPlayer, name = '", nil, "', index = ", nil, '}'} -local luaEntity = {"{LuaEntity, name = '", nil, "', unit_number = ", nil, '}'} -local luaGuiElement = {"{LuaGuiElement, name = '", nil, "'}"} +local luaObject = { "{", nil, ", name = '", nil, "'}" } +local luaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" } +local luaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" } +local luaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" } local function get(obj, prop) return obj[prop] end local function get_name_safe(obj) - local s, r = pcall(get, obj, 'name') + local s, r = pcall(get, obj, "name") if not s then - return 'nil' + return "nil" else - return r or 'nil' + return r or "nil" end end local function get_lua_object_type_safe(obj) - local s, r = pcall(get, obj, 'help') + local s, r = pcall(get, obj, "help") if not s then return end - return r():match('Lua%a+') + return r():match("Lua%a+") end local function inspect_process(item) - if type(item) ~= 'table' or type(item.__self) ~= 'userdata' then + if type(item) ~= "table" or type(item.__self) ~= "userdata" then return item end - local suc, valid = pcall(get, item, 'valid') + local suc, valid = pcall(get, item, "valid") if not suc then -- no 'valid' property - return get_lua_object_type_safe(item) or '{NoHelp LuaObject}' + return get_lua_object_type_safe(item) or "{NoHelp LuaObject}" end if not valid then - return '{Invalid LuaObject}' + return "{Invalid LuaObject}" end local obj_type = get_lua_object_type_safe(item) if not obj_type then - return '{NoHelp LuaObject}' + return "{NoHelp LuaObject}" end - if obj_type == 'LuaPlayer' then - luaPlayer[2] = item.name or 'nil' - luaPlayer[4] = item.index or 'nil' + if obj_type == "LuaPlayer" then + luaPlayer[2] = item.name or "nil" + luaPlayer[4] = item.index or "nil" return concat(luaPlayer) - elseif obj_type == 'LuaEntity' then - luaEntity[2] = item.name or 'nil' - luaEntity[4] = item.unit_number or 'nil' + elseif obj_type == "LuaEntity" then + luaEntity[2] = item.name or "nil" + luaEntity[4] = item.unit_number or "nil" return concat(luaEntity) - elseif obj_type == 'LuaGuiElement' then + elseif obj_type == "LuaGuiElement" then local name = item.name - luaGuiElement[2] = gui_names and gui_names[name] or name or 'nil' + luaGuiElement[2] = gui_names and gui_names[name] or name or "nil" return concat(luaGuiElement) else @@ -82,10 +82,11 @@ local function inspect_process(item) end end -local inspect_options = {process = inspect_process} +local inspect_options = { process = inspect_process } function Public.dump(data) return inspect(data, inspect_options) end + local dump = Public.dump function Public.dump_ignore_builder(ignore) @@ -97,14 +98,14 @@ function Public.dump_ignore_builder(ignore) return inspect_process(item) end - local options = {process = process} + local options = { process = process } return function(data) return inspect(data, options) end end function Public.dump_function(func) - local res = {'upvalues:\n'} + local res = { "upvalues:\n" } local i = 1 while true do @@ -112,11 +113,11 @@ function Public.dump_function(func) if n == nil then break - elseif n ~= '_ENV' then + elseif n ~= "_ENV" then res[#res + 1] = n - res[#res + 1] = ' = ' + res[#res + 1] = " = " res[#res + 1] = dump(v) - res[#res + 1] = '\n' + res[#res + 1] = "\n" end i = i + 1 @@ -126,16 +127,16 @@ function Public.dump_function(func) end function Public.dump_text(text, player) - local func = loadstring('return ' .. text) + local func = loadstring("return " .. text) if not func then return false end - rawset(game, 'player', player) + rawset(game, "player", player) local suc, var = pcall(func) - rawset(game, 'player', nil) + rawset(game, "player", nil) if not suc then return false diff --git a/exp_legacy/module/modules/gui/debug/package_view.lua b/exp_legacy/module/modules/gui/debug/package_view.lua index 11b50c0d..689462c8 100644 --- a/exp_legacy/module/modules/gui/debug/package_view.lua +++ b/exp_legacy/module/modules/gui/debug/package_view.lua @@ -17,9 +17,9 @@ local ignore = { math = true, debug = true, serpent = true, - ['overrides.math'] = true, + ["overrides.math"] = true, util = true, - ['mod-gui'] = true + ["mod-gui"] = true, } local file_label_name = Gui.uid_name() @@ -29,34 +29,34 @@ local top_panel_name = Gui.uid_name() local variable_label_name = Gui.uid_name() local text_box_name = Gui.uid_name() -Public.name = 'package' +Public.name = "package" function Public.show(container) - local main_flow = container.add {type = 'flow', direction = 'horizontal'} + local main_flow = container.add{ type = "flow", direction = "horizontal" } - local left_panel = main_flow.add {type = 'scroll-pane', name = left_panel_name} + local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name } local left_panel_style = left_panel.style left_panel_style.width = 300 for name, file in pairs(loaded) do if not ignore[name] then local file_label = - left_panel.add({type = 'flow'}).add {type = 'label', name = file_label_name, caption = name} + left_panel.add{ type = "flow" }.add{ type = "label", name = file_label_name, caption = name } Gui.set_data(file_label, file) end end - local right_flow = main_flow.add {type = 'flow', direction = 'vertical'} + local right_flow = main_flow.add{ type = "flow", direction = "vertical" } - local breadcrumbs = right_flow.add {type = 'label', name = breadcrumbs_name} + local breadcrumbs = right_flow.add{ type = "label", name = breadcrumbs_name } - local top_panel = right_flow.add {type = 'scroll-pane', name = top_panel_name} + local top_panel = right_flow.add{ type = "scroll-pane", name = top_panel_name } local top_panel_style = top_panel.style top_panel_style.height = 200 top_panel_style.maximal_width = 1000 top_panel_style.horizontally_stretchable = true - local text_box = right_flow.add {type = 'text-box', name = text_box_name} + local text_box = right_flow.add{ type = "text-box", name = text_box_name } text_box.read_only = true text_box.selectable = true @@ -72,7 +72,7 @@ function Public.show(container) top_panel = top_panel, text_box = text_box, selected_file_label = nil, - selected_variable_label = nil + selected_variable_label = nil, } Gui.set_data(left_panel, data) @@ -104,13 +104,13 @@ Gui.on_click( local file_type = type(file) - if file_type == 'table' then + if file_type == "table" then for k, v in pairs(file) do local label = - top_panel.add({type = 'flow'}).add {type = 'label', name = variable_label_name, caption = k} + top_panel.add{ type = "flow" }.add{ type = "label", name = variable_label_name, caption = k } Gui.set_data(label, v) end - elseif file_type == 'function' then + elseif file_type == "function" then text_box.text = dump_function(file) else text_box.text = tostring(file) @@ -130,13 +130,14 @@ Gui.on_click( local variable_type = type(variable) - if variable_type == 'table' then + if variable_type == "table" then Gui.clear(top_panel) for k, v in pairs(variable) do local label = - top_panel.add({type = 'flow'}).add {type = 'label', name = variable_label_name, caption = k} + top_panel.add{ type = "flow" }.add{ type = "label", name = variable_label_name, caption = k } Gui.set_data(label, v) end + return end @@ -149,7 +150,7 @@ Gui.on_click( element.style.font_color = Color.orange data.selected_variable_label = element - if variable_type == 'function' then + if variable_type == "function" then text_box.text = dump_function(variable) else text_box.text = tostring(variable) diff --git a/exp_legacy/module/modules/gui/debug/redmew_global_view.lua b/exp_legacy/module/modules/gui/debug/redmew_global_view.lua index 40284939..10349dd8 100644 --- a/exp_legacy/module/modules/gui/debug/redmew_global_view.lua +++ b/exp_legacy/module/modules/gui/debug/redmew_global_view.lua @@ -15,37 +15,37 @@ local right_panel_name = Gui.uid_name() local input_text_box_name = Gui.uid_name() local refresh_name = Gui.uid_name() -Public.name = 'Storage' +Public.name = "Storage" function Public.show(container) - local main_flow = container.add {type = 'flow', direction = 'horizontal'} + local main_flow = container.add{ type = "flow", direction = "horizontal" } - local left_panel = main_flow.add {type = 'scroll-pane', name = left_panel_name} + local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name } local left_panel_style = left_panel.style left_panel_style.width = 300 for token_id in pairs(Storage.registered) do - local header = left_panel.add({type = 'flow'}).add {type = 'label', name = header_name, caption = token_id} + local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = token_id } Gui.set_data(header, token_id) end - local right_flow = main_flow.add {type = 'flow', direction = 'vertical'} + local right_flow = main_flow.add{ type = "flow", direction = "vertical" } - local right_top_flow = right_flow.add {type = 'flow', direction = 'horizontal'} + local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" } - local input_text_box = right_top_flow.add {type = 'text-box', name = input_text_box_name} + local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name } local input_text_box_style = input_text_box.style input_text_box_style.horizontally_stretchable = true input_text_box_style.height = 32 input_text_box_style.maximal_width = 1000 local refresh_button = - right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'} + right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" } local refresh_button_style = refresh_button.style refresh_button_style.width = 32 refresh_button_style.height = 32 - local right_panel = right_flow.add {type = 'text-box', name = right_panel_name} + local right_panel = right_flow.add{ type = "text-box", name = right_panel_name } right_panel.read_only = true right_panel.selectable = true @@ -58,7 +58,7 @@ function Public.show(container) local data = { right_panel = right_panel, input_text_box = input_text_box, - selected_header = nil + selected_header = nil, } Gui.set_data(input_text_box, data) @@ -85,10 +85,10 @@ Gui.on_click( element.style.font_color = Color.orange data.selected_header = element - input_text_box.text = concat {'storage.exp_storage[', token_id, ']'} + input_text_box.text = concat{ "storage.exp_storage[", token_id, "]" } input_text_box.style.font_color = Color.black - local content = dump(storage.exp_storage[token_id]) or 'nil' + local content = dump(storage.exp_storage[token_id]) or "nil" right_panel.text = content end ) diff --git a/exp_legacy/module/modules/gui/landfill.lua b/exp_legacy/module/modules/gui/landfill.lua index b6271830..0e6415ab 100644 --- a/exp_legacy/module/modules/gui/landfill.lua +++ b/exp_legacy/module/modules/gui/landfill.lua @@ -11,7 +11,7 @@ local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles local rolling_stocks = {} local function landfill_init() - for name, _ in pairs(prototypes.get_entity_filtered{{filter = 'rolling-stock'}}) do + for name, _ in pairs(prototypes.get_entity_filtered{ { filter = "rolling-stock" } }) do rolling_stocks[name] = true end end @@ -20,50 +20,50 @@ local function rotate_bounding_box(box) return { left_top = { x = -box.right_bottom.y, - y = box.left_top.x + y = box.left_top.x, }, right_bottom = { x = -box.left_top.y, - y = box.right_bottom.x - } + y = box.right_bottom.x, + }, } end local function curve_flip_lr(oc) - local nc = table.deepcopy(oc) + local nc = table.deepcopy(oc) - for r=1, 8 do - for c=1, 8 do - nc[r][c] = oc[r][9 - c] - end - end + for r = 1, 8 do + for c = 1, 8 do + nc[r][c] = oc[r][9 - c] + end + end - return nc + return nc end local function curve_flip_d(oc) - local nc = table.deepcopy(oc) + local nc = table.deepcopy(oc) - for r=1, 8 do - for c=1, 8 do - nc[r][c] = oc[c][r] - end - end + for r = 1, 8 do + for c = 1, 8 do + nc[r][c] = oc[c][r] + end + end - return nc + return nc end local curves = {} curves[1] = { - {0, 0, 0, 0, 0, 1, 0, 0}, - {0, 0, 0, 0, 1, 1, 1, 0}, - {0, 0, 0, 1, 1, 1, 1, 0}, - {0, 0, 0, 1, 1, 1, 0, 0}, - {0, 0, 1, 1, 1, 0, 0, 0}, - {0, 0, 1, 1, 1, 0, 0, 0}, - {0, 0, 1, 1, 0, 0, 0, 0}, - {0, 0, 1, 1, 0, 0, 0, 0} + { 0, 0, 0, 0, 0, 1, 0, 0 }, + { 0, 0, 0, 0, 1, 1, 1, 0 }, + { 0, 0, 0, 1, 1, 1, 1, 0 }, + { 0, 0, 0, 1, 1, 1, 0, 0 }, + { 0, 0, 1, 1, 1, 0, 0, 0 }, + { 0, 0, 1, 1, 1, 0, 0, 0 }, + { 0, 0, 1, 1, 0, 0, 0, 0 }, + { 0, 0, 1, 1, 0, 0, 0, 0 }, } curves[6] = curve_flip_d(curves[1]) curves[3] = curve_flip_lr(curves[6]) @@ -79,12 +79,12 @@ for i, map in ipairs(curves) do curve_n[i] = {} local index = 1 - for r=1, 8 do - for c=1, 8 do + for r = 1, 8 do + for c = 1, 8 do if map[r][c] == 1 then curve_n[i][index] = { - ['x'] = c - 5, - ['y'] = r - 5 + ["x"] = c - 5, + ["y"] = r - 5, } index = index + 1 @@ -100,13 +100,13 @@ local function landfill_gui_add_landfill(blueprint) for _, ent in pairs(entities) do -- vehicle - if not (rolling_stocks[ent.name] or ent.name == 'offshore-pump') then + if not (rolling_stocks[ent.name] or ent.name == "offshore-pump") then -- curved rail, special - if ent.name ~= 'curved-rail' then + if ent.name ~= "curved-rail" then local proto = prototypes.entity[ent.name] local box = proto.collision_box or proto.selection_box - if proto.collision_mask['ground-tile'] == nil then + if proto.collision_mask["ground-tile"] == nil then if ent.direction then if ent.direction ~= defines.direction.north then box = rotate_bounding_box(box) @@ -125,21 +125,21 @@ local function landfill_gui_add_landfill(blueprint) for x = math.floor(ent.position.x + box.left_top.x), math.floor(ent.position.x + box.right_bottom.x), 1 do tile_index = tile_index + 1 new_tiles[tile_index] = { - name = 'landfill', - position = {x, y} + name = "landfill", + position = { x, y }, } end end end - -- curved rail + -- curved rail else local curve_mask = curve_n[ent.direction or 8] - for m=1, #curve_mask do + for m = 1, #curve_mask do new_tiles[tile_index + 1] = { - name = 'landfill', - position = {curve_mask[m].x + ent.position.x, curve_mask[m].y + ent.position.y} + name = "landfill", + position = { curve_mask[m].x + ent.position.x, curve_mask[m].y + ent.position.y }, } tile_index = tile_index + 1 @@ -153,34 +153,33 @@ local function landfill_gui_add_landfill(blueprint) if old_tiles then for _, old_tile in pairs(old_tiles) do new_tiles[tile_index + 1] = { - name = 'landfill', - position = {old_tile.position.x, old_tile.position.y} + name = "landfill", + position = { old_tile.position.x, old_tile.position.y }, } tile_index = tile_index + 1 end end - return {tiles = new_tiles} + return { tiles = new_tiles } end -- @element toolbar_button -Gui.toolbar_button('item/landfill', {'landfill.main-tooltip'}, function(player) - return Roles.player_allowed(player, 'gui/landfill') +Gui.toolbar_button("item/landfill", { "landfill.main-tooltip" }, function(player) + return Roles.player_allowed(player, "gui/landfill") end) -:on_click(function(player, _, _) - if player.cursor_stack and player.cursor_stack.valid_for_read then - if player.cursor_stack.type == 'blueprint' and player.cursor_stack.is_blueprint_setup() then - local modified = landfill_gui_add_landfill(player.cursor_stack) + :on_click(function(player, _, _) + if player.cursor_stack and player.cursor_stack.valid_for_read then + if player.cursor_stack.type == "blueprint" and player.cursor_stack.is_blueprint_setup() then + local modified = landfill_gui_add_landfill(player.cursor_stack) - if modified and next(modified.tiles) then - player.cursor_stack.set_blueprint_tiles(modified.tiles) + if modified and next(modified.tiles) then + player.cursor_stack.set_blueprint_tiles(modified.tiles) + end end + else + player.print{ "landfill.cursor-none" } end - - else - player.print{'landfill.cursor-none'} - end -end) + end) Event.add(defines.events.on_player_joined_game, landfill_init) diff --git a/exp_legacy/module/modules/gui/module.lua b/exp_legacy/module/modules/gui/module.lua index 553d383c..8bf531de 100644 --- a/exp_legacy/module/modules/gui/module.lua +++ b/exp_legacy/module/modules/gui/module.lua @@ -6,19 +6,19 @@ local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles local config = require("modules.exp_legacy.config.module") --- @dep config.module local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection -local SelectionModuleArea = 'ModuleArea' +local SelectionModuleArea = "ModuleArea" --- align an aabb to the grid by expanding it local function aabb_align_expand(aabb) return { left_top = { x = math.floor(aabb.left_top.x), - y = math.floor(aabb.left_top.y) + y = math.floor(aabb.left_top.y), }, right_bottom = { x = math.ceil(aabb.right_bottom.x), - y = math.ceil(aabb.right_bottom.y) - } + y = math.ceil(aabb.right_bottom.y), + }, } end @@ -40,30 +40,30 @@ local function get_module_name() end local elem_filter = { - name = {{ - filter = 'name', - name = machine_name - }}, - normal = {{ - filter = 'type', - type = 'module' + name = { { + filter = "name", + name = machine_name, + } }, + normal = { { + filter = "type", + type = "module", }, { - filter = 'name', + filter = "name", name = prod_module_names, - mode = 'and', - invert = true - }}, - prod = {{ - filter = 'type', - type = 'module' - }} + mode = "and", + invert = true, + } }, + prod = { { + filter = "type", + type = "module", + } }, } local function clear_module(player, area, machine) - for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do - for _, r in pairs(player.surface.find_entities_filtered{position=entity.position, name='item-request-proxy', force=player.force}) do + for _, entity in pairs(player.surface.find_entities_filtered{ area = area, name = machine, force = player.force }) do + for _, r in pairs(player.surface.find_entities_filtered{ position = entity.position, name = "item-request-proxy", force = player.force }) do if r then - r.destroy{raise_destroy=true} + r.destroy{ raise_destroy = true } end end @@ -74,7 +74,7 @@ local function clear_module(player, area, machine) if m_current_module_content then for k, m in pairs(m_current_module_content) do - player.surface.spill_item_stack(entity.bounding_box.left_top, {name=k, count=m}, true, player.force, false) + player.surface.spill_item_stack(entity.bounding_box.left_top, { name = k, count = m }, true, player.force, false) end end @@ -84,25 +84,23 @@ local function clear_module(player, area, machine) end local function apply_module(player, area, machine, modules) - for _, entity in pairs(player.surface.find_entities_filtered{area=area, name=machine, force=player.force}) do + for _, entity in pairs(player.surface.find_entities_filtered{ area = area, name = machine, force = player.force }) do local m_current_recipe if entity.prototype.crafting_speed then - m_current_recipe= entity.get_recipe() + m_current_recipe = entity.get_recipe() end if m_current_recipe then if config.module_allowed[m_current_recipe.name] then - entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules['n']} + entity.surface.create_entity{ name = "item-request-proxy", target = entity, position = entity.position, force = entity.force, modules = modules["n"] } entity.last_user = player - else - entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules['p']} + entity.surface.create_entity{ name = "item-request-proxy", target = entity, position = entity.position, force = entity.force, modules = modules["p"] } entity.last_user = player end - else - entity.surface.create_entity{name='item-request-proxy', target=entity, position=entity.position, force=entity.force, modules=modules['n']} + entity.surface.create_entity{ name = "item-request-proxy", target = entity, position = entity.position, force = entity.force, modules = modules["n"] } entity.last_user = player end end @@ -115,35 +113,34 @@ Selection.on_selection(SelectionModuleArea, function(event) local frame = Gui.get_left_element(player, module_container) local scroll_table = frame.container.scroll.table - for i=1, config.default_module_row_count do - local mma = scroll_table['module_mm_' .. i .. '_0'].elem_value + for i = 1, config.default_module_row_count do + local mma = scroll_table["module_mm_" .. i .. "_0"].elem_value if mma then local mm = { - ['n'] = {}, - ['p'] = {} + ["n"] = {}, + ["p"] = {}, } - for j=1, prototypes.entity[mma].module_inventory_size, 1 do - local mmo = scroll_table['module_mm_' .. i .. '_' .. j].elem_value + for j = 1, prototypes.entity[mma].module_inventory_size, 1 do + local mmo = scroll_table["module_mm_" .. i .. "_" .. j].elem_value if mmo then - if mm['n'][mmo] then - mm['n'][mmo] = mm['n'][mmo] + 1 - mm['p'][mmo] = mm['p'][mmo] + 1 - + if mm["n"][mmo] then + mm["n"][mmo] = mm["n"][mmo] + 1 + mm["p"][mmo] = mm["p"][mmo] + 1 else - mm['n'][mmo] = 1 - mm['p'][mmo] = 1 + mm["n"][mmo] = 1 + mm["p"][mmo] = 1 end end end - for k, v in pairs(mm['p']) do - if k:find('productivity') then - local module_name = k:gsub('productivity', 'effectivity') - mm['p'][module_name] = (mm['p'][module_name] or 0) + v - mm['p'][k] = nil + for k, v in pairs(mm["p"]) do + if k:find("productivity") then + local module_name = k:gsub("productivity", "effectivity") + mm["p"][module_name] = (mm["p"][module_name] or 0) + v + mm["p"][k] = nil end end @@ -159,29 +156,26 @@ local function row_set(player, element) local frame = Gui.get_left_element(player, module_container) local scroll_table = frame.container.scroll.table - if scroll_table[element .. '0'].elem_value then - for i=1, config.module_slot_max do - if i <= prototypes.entity[scroll_table[element .. '0'].elem_value].module_inventory_size then - if config.machine[scroll_table[element .. '0'].elem_value].prod then + if scroll_table[element .. "0"].elem_value then + for i = 1, config.module_slot_max do + if i <= prototypes.entity[scroll_table[element .. "0"].elem_value].module_inventory_size then + if config.machine[scroll_table[element .. "0"].elem_value].prod then scroll_table[element .. i].elem_filters = elem_filter.prod - else scroll_table[element .. i].elem_filters = elem_filter.normal end scroll_table[element .. i].enabled = true - scroll_table[element .. i].elem_value = config.machine[scroll_table[element .. '0'].elem_value].module - + scroll_table[element .. i].elem_value = config.machine[scroll_table[element .. "0"].elem_value].module else scroll_table[element .. i].enabled = false scroll_table[element .. i].elem_value = nil end end - else local mf = elem_filter.normal - for i=1, config.module_slot_max do + for i = 1, config.module_slot_max do scroll_table[element .. i].enabled = false scroll_table[element .. i].elem_filters = mf scroll_table[element .. i].elem_value = nil @@ -190,61 +184,61 @@ local function row_set(player, element) end local button_apply = -Gui.element{ - type = 'button', - caption = 'Apply', - style = 'button' -}:on_click(function(player) - if Selection.is_selecting(player, SelectionModuleArea) then - Selection.stop(player) - else - Selection.start(player, SelectionModuleArea) - end -end) + Gui.element{ + type = "button", + caption = "Apply", + style = "button", + }:on_click(function(player) + if Selection.is_selecting(player, SelectionModuleArea) then + Selection.stop(player) + else + Selection.start(player, SelectionModuleArea) + end + end) module_container = -Gui.element(function(definition, parent) - local container = Gui.container(parent, definition.name, (config.module_slot_max + 2) * 36) - Gui.header(container, 'Module Inserter', '', true) + Gui.element(function(definition, parent) + local container = Gui.container(parent, definition.name, (config.module_slot_max + 2) * 36) + Gui.header(container, "Module Inserter", "", true) - local scroll_table = Gui.scroll_table(container, (config.module_slot_max + 2) * 36, config.module_slot_max + 1) + local scroll_table = Gui.scroll_table(container, (config.module_slot_max + 2) * 36, config.module_slot_max + 1) - for i=1, config.default_module_row_count do - scroll_table.add{ - name = 'module_mm_' .. i .. '_0', - type = 'choose-elem-button', - elem_type = 'entity', - elem_filters = elem_filter.name, - style = 'slot_button' - } - - for j=1, config.module_slot_max do + for i = 1, config.default_module_row_count do scroll_table.add{ - name = 'module_mm_' .. i .. '_' .. j, - type = 'choose-elem-button', - elem_type = 'item', - elem_filters = elem_filter.normal, - style = 'slot_button', - enabled = false + name = "module_mm_" .. i .. "_0", + type = "choose-elem-button", + elem_type = "entity", + elem_filters = elem_filter.name, + style = "slot_button", } + + for j = 1, config.module_slot_max do + scroll_table.add{ + name = "module_mm_" .. i .. "_" .. j, + type = "choose-elem-button", + elem_type = "item", + elem_filters = elem_filter.normal, + style = "slot_button", + enabled = false, + } + end end - end - button_apply(container) + button_apply(container) - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() -Gui.left_toolbar_button('item/productivity-module-3', {'module.main-tooltip'}, module_container, function(player) - return Roles.player_allowed(player, 'gui/module') +Gui.left_toolbar_button("item/productivity-module-3", { "module.main-tooltip" }, module_container, function(player) + return Roles.player_allowed(player, "gui/module") end) Event.add(defines.events.on_gui_elem_changed, function(event) - if event.element.name:sub(1, 10) == 'module_mm_' then - if event.element.name:sub(-1) == '0' then - row_set(game.players[event.player_index], 'module_mm_' .. event.element.name:sub(-3):sub(1, 1) .. '_') + if event.element.name:sub(1, 10) == "module_mm_" then + if event.element.name:sub(-1) == "0" then + row_set(game.players[event.player_index], "module_mm_" .. event.element.name:sub(-3):sub(1, 1) .. "_") end end end) @@ -271,7 +265,7 @@ Event.add(defines.events.on_entity_settings_pasted, function(event) -- rotate machine also if config.copy_paste_rotation then if (source.name == destination.name or source.prototype.fast_replaceable_group == destination.prototype.fast_replaceable_group) then - if source.supports_direction and destination.supports_direction and source.type ~= 'transport-belt' then + if source.supports_direction and destination.supports_direction and source.type ~= "transport-belt" then local destination_box = destination.bounding_box local ltx = destination_box.left_top.x @@ -309,7 +303,7 @@ Event.add(defines.events.on_entity_settings_pasted, function(event) clear_module(player, destination.bounding_box, destination.name) if next(source_inventory_content) ~= nil then - apply_module(player, destination.bounding_box, destination.name, {['n']=source_inventory_content, ['p']=source_inventory_content}) + apply_module(player, destination.bounding_box, destination.name, { ["n"] = source_inventory_content, ["p"] = source_inventory_content }) end end end) diff --git a/exp_legacy/module/modules/gui/player-list.lua b/exp_legacy/module/modules/gui/player-list.lua index 69ef2cfb..e4ad676c 100644 --- a/exp_legacy/module/modules/gui/player-list.lua +++ b/exp_legacy/module/modules/gui/player-list.lua @@ -14,10 +14,10 @@ local Colors = require("modules/exp_util/include/color") local format_time = _C.format_time --- @dep expcore.common --- Stores all data for the warp gui -local PlayerListData = Datastore.connect('PlayerListData') +local PlayerListData = Datastore.connect("PlayerListData") PlayerListData:set_serializer(Datastore.name_serializer) -local SelectedPlayer = PlayerListData:combine('SelectedPlayer') -local SelectedAction = PlayerListData:combine('SelectedAction') +local SelectedPlayer = PlayerListData:combine("SelectedPlayer") +local SelectedAction = PlayerListData:combine("SelectedAction") -- Set the config to use these stores config.set_datastores(SelectedPlayer, SelectedAction) @@ -25,118 +25,118 @@ config.set_datastores(SelectedPlayer, SelectedAction) --- Button used to open the action bar -- @element open_action_bar local open_action_bar = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/expand_dots', - tooltip = {'player-list.open-action-bar'}, - style = 'frame_button', - name = Gui.unique_static_name -} -:style{ - padding = -2, - width = 8, - height = 14 -} -:on_click(function(player, element, _) - local selected_player_name = element.parent.name - local old_selected_player_name = SelectedPlayer:get(player) - if selected_player_name == old_selected_player_name then - SelectedPlayer:remove(player) - else - SelectedPlayer:set(player, selected_player_name) - end -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/expand_dots", + tooltip = { "player-list.open-action-bar" }, + style = "frame_button", + name = Gui.unique_static_name, + } + :style{ + padding = -2, + width = 8, + height = 14, + } + :on_click(function(player, element, _) + local selected_player_name = element.parent.name + local old_selected_player_name = SelectedPlayer:get(player) + if selected_player_name == old_selected_player_name then + SelectedPlayer:remove(player) + else + SelectedPlayer:set(player, selected_player_name) + end + end) --- Button used to close the action bar -- @element close_action_bar local close_action_bar = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/close_black', - tooltip = {'player-list.close-action-bar'}, - style = 'slot_sized_button_red' -} -:style(Gui.sprite_style(30, -1, { top_margin = -1, right_margin = -1 })) -:on_click(function(player, _) - SelectedPlayer:remove(player) - SelectedAction:remove(player) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/close_black", + tooltip = { "player-list.close-action-bar" }, + style = "slot_sized_button_red", + } + :style(Gui.sprite_style(30, -1, { top_margin = -1, right_margin = -1 })) + :on_click(function(player, _) + SelectedPlayer:remove(player) + SelectedAction:remove(player) + end) --- Button used to confirm a reason -- @element reason_confirm local reason_confirm = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/confirm_slot', - tooltip = {'player-list.reason-confirm'}, - style = 'slot_sized_button_green' -} -:style(Gui.sprite_style(30, -1, { left_margin = -2, right_margin = -1 })) -:on_click(function(player, element) - local reason = element.parent.entry.text - local action_name = SelectedAction:get(player) - local reason_callback = config.buttons[action_name].reason_callback - if reason == nil or not reason:find("%S") then reason = 'no reason given' end - reason_callback(player, reason) - SelectedPlayer:remove(player) - SelectedAction:remove(player) - element.parent.entry.text = '' -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/confirm_slot", + tooltip = { "player-list.reason-confirm" }, + style = "slot_sized_button_green", + } + :style(Gui.sprite_style(30, -1, { left_margin = -2, right_margin = -1 })) + :on_click(function(player, element) + local reason = element.parent.entry.text + local action_name = SelectedAction:get(player) + local reason_callback = config.buttons[action_name].reason_callback + if reason == nil or not reason:find("%S") then reason = "no reason given" end + reason_callback(player, reason) + SelectedPlayer:remove(player) + SelectedAction:remove(player) + element.parent.entry.text = "" + end) --- Set of elements that are used to make up a row of the player table -- @element add_player_base local add_player_base = -Gui.element(function(_, parent, player_data) - -- Add the button to open the action bar - local toggle_action_bar_flow = parent.add{ type = 'flow', name = player_data.name } - open_action_bar(toggle_action_bar_flow) + Gui.element(function(_, parent, player_data) + -- Add the button to open the action bar + local toggle_action_bar_flow = parent.add{ type = "flow", name = player_data.name } + open_action_bar(toggle_action_bar_flow) - -- Add the player name - local player_name = parent.add{ - type = 'label', - name = 'player-name-'..player_data.index, - caption = player_data.name, - tooltip = {'player-list.open-map', player_data.name, player_data.tag, player_data.role_name} - } - player_name.style.padding = {0, 2,0, 0} - player_name.style.font_color = player_data.chat_color + -- Add the player name + local player_name = parent.add{ + type = "label", + name = "player-name-" .. player_data.index, + caption = player_data.name, + tooltip = { "player-list.open-map", player_data.name, player_data.tag, player_data.role_name }, + } + player_name.style.padding = { 0, 2, 0, 0 } + player_name.style.font_color = player_data.chat_color - -- Add the time played label - local alignment = Gui.alignment(parent, 'player-time-'..player_data.index) - local time_label = alignment.add{ - name = 'label', - type = 'label', - caption = player_data.caption, - tooltip = player_data.tooltip - } - time_label.style.padding = 0 + -- Add the time played label + local alignment = Gui.alignment(parent, "player-time-" .. player_data.index) + local time_label = alignment.add{ + name = "label", + type = "label", + caption = player_data.caption, + tooltip = player_data.tooltip, + } + time_label.style.padding = 0 - return player_name -end) -:on_click(function(player, element, event) - local selected_player_name = element.caption - local selected_player = game.players[selected_player_name] - if event.button == defines.mouse_button_type.left then - -- LMB will open the map to the selected player - local position = selected_player.position - event.player.zoom_to_world(position, 1.75) - else - -- RMB will toggle the settings - local old_selected_player_name = SelectedPlayer:get(player) - if selected_player_name == old_selected_player_name then - SelectedPlayer:remove(player) - SelectedAction:remove(player) + return player_name + end) + :on_click(function(player, element, event) + local selected_player_name = element.caption + local selected_player = game.players[selected_player_name] + if event.button == defines.mouse_button_type.left then + -- LMB will open the map to the selected player + local position = selected_player.position + event.player.zoom_to_world(position, 1.75) else - SelectedPlayer:set(player, selected_player_name) + -- RMB will toggle the settings + local old_selected_player_name = SelectedPlayer:get(player) + if selected_player_name == old_selected_player_name then + SelectedPlayer:remove(player) + SelectedAction:remove(player) + else + SelectedPlayer:set(player, selected_player_name) + end end - end -end) + end) -- Removes the three elements that are added as part of the base local function remove_player_base(parent, player) Gui.destroy_if_valid(parent[player.name]) - Gui.destroy_if_valid(parent['player-name-'..player.index]) - Gui.destroy_if_valid(parent['player-time-'..player.index]) + Gui.destroy_if_valid(parent["player-name-" .. player.index]) + Gui.destroy_if_valid(parent["player-time-" .. player.index]) end -- Update the time label for a player using there player time data @@ -151,21 +151,21 @@ end --- Adds all the buttons and flows that make up the action bar -- @element add_action_bar local add_action_bar_buttons = -Gui.element(function(_, parent) - close_action_bar(parent) - -- Loop over all the buttons in the config - for action_name, button_data in pairs(config.buttons) do - -- Added the permission flow - local permission_flow = parent.add{ type = 'flow', name = action_name } - permission_flow.visible = false - -- Add the buttons under that permission - for _, button in ipairs(button_data) do - button(permission_flow) + Gui.element(function(_, parent) + close_action_bar(parent) + -- Loop over all the buttons in the config + for action_name, button_data in pairs(config.buttons) do + -- Added the permission flow + local permission_flow = parent.add{ type = "flow", name = action_name } + permission_flow.visible = false + -- Add the buttons under that permission + for _, button in ipairs(button_data) do + button(permission_flow) + end end - end - return parent -end) + return parent + end) --- Updates the visible state of the action bar buttons local function update_action_bar(element) @@ -175,7 +175,6 @@ local function update_action_bar(element) if not selected_player_name then -- Hide the action bar when no player is selected element.visible = false - else local selected_player = game.players[selected_player_name] if not selected_player.connected then @@ -183,7 +182,6 @@ local function update_action_bar(element) element.visible = false SelectedPlayer:remove(player) SelectedAction:remove(player) - else -- Otherwise check what actions the player is allowed to use element.visible = true @@ -194,7 +192,6 @@ local function update_action_bar(element) element[action_name].visible = true end end - end end end @@ -202,74 +199,74 @@ end --- Main player list container for the left flow -- @element player_list_container local player_list_container = -Gui.element(function(definition, parent) - -- Draw the internal container - local container = Gui.container(parent, definition.name, 200) + Gui.element(function(definition, parent) + -- Draw the internal container + local container = Gui.container(parent, definition.name, 200) - -- Draw the scroll table for the players - local scroll_table = Gui.scroll_table(container, 184, 3) + -- Draw the scroll table for the players + local scroll_table = Gui.scroll_table(container, 184, 3) - -- Change the style of the scroll table - local scroll_table_style = scroll_table.style - scroll_table_style.padding = {1, 0,1, 2} + -- Change the style of the scroll table + local scroll_table_style = scroll_table.style + scroll_table_style.padding = { 1, 0, 1, 2 } - -- Add the action bar - local action_bar = Gui.footer(container, nil, nil, false, 'action_bar') + -- Add the action bar + local action_bar = Gui.footer(container, nil, nil, false, "action_bar") - -- Change the style of the action bar - local action_bar_style = action_bar.style - action_bar_style.height = 35 - action_bar_style.padding = {1, 3} - action_bar.visible = false + -- Change the style of the action bar + local action_bar_style = action_bar.style + action_bar_style.height = 35 + action_bar_style.padding = { 1, 3 } + action_bar.visible = false - -- Add the buttons to the action bar - add_action_bar_buttons(action_bar) + -- Add the buttons to the action bar + add_action_bar_buttons(action_bar) - -- Add the reason bar - local reason_bar = Gui.footer(container, nil, nil, false, 'reason_bar') + -- Add the reason bar + local reason_bar = Gui.footer(container, nil, nil, false, "reason_bar") - -- Change the style of the reason bar - local reason_bar_style = reason_bar.style - reason_bar_style.height = 35 - reason_bar_style.padding = {-1, 3} - reason_bar.visible = false + -- Change the style of the reason bar + local reason_bar_style = reason_bar.style + reason_bar_style.height = 35 + reason_bar_style.padding = { -1, 3 } + reason_bar.visible = false - -- Add the text entry for the reason bar - local reason_field = - reason_bar.add{ - name = 'entry', - type = 'textfield', - style = 'stretchable_textfield', - tooltip = {'player-list.reason-entry'} - } + -- Add the text entry for the reason bar + local reason_field = + reason_bar.add{ + name = "entry", + type = "textfield", + style = "stretchable_textfield", + tooltip = { "player-list.reason-entry" }, + } - -- Change the style of the text entry - local reason_entry_style = reason_field.style - reason_entry_style.padding = 0 - reason_entry_style.height = 28 - reason_entry_style.minimal_width = 160 + -- Change the style of the text entry + local reason_entry_style = reason_field.style + reason_entry_style.padding = 0 + reason_entry_style.height = 28 + reason_entry_style.minimal_width = 160 - -- Add the confirm reason button - reason_confirm(reason_bar) + -- Add the confirm reason button + reason_confirm(reason_bar) - -- Return the exteral container - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow(true) + -- Return the exteral container + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow(true) --- Button on the top flow used to toggle the player list container -- @element toggle_player_list -Gui.left_toolbar_button('entity/character', {'player-list.main-tooltip'}, player_list_container, function(player) - return Roles.player_allowed(player, 'gui/player-list') +Gui.left_toolbar_button("entity/character", { "player-list.main-tooltip" }, player_list_container, function(player) + return Roles.player_allowed(player, "gui/player-list") end) -- Get caption and tooltip format for a player local function get_time_formats(online_time, afk_time) local tick = game.tick > 0 and game.tick or 1 - local percent = math.round(online_time/tick, 3)*100 + local percent = math.round(online_time / tick, 3) * 100 local caption = format_time(online_time) - local tooltip = {'player-list.afk-time', percent, format_time(afk_time, {minutes=true, long=true})} + local tooltip = { "player-list.afk-time", percent, format_time(afk_time, { minutes = true, long = true }) } return caption, tooltip end @@ -282,9 +279,9 @@ local function get_player_times() -- Add the player time details to the array local caption, tooltip = get_time_formats(player.online_time, player.afk_time) player_times[ctn] = { - element_name = 'player-time-'..player.index, + element_name = "player-time-" .. player.index, caption = caption, - tooltip = tooltip + tooltip = tooltip, } end @@ -319,7 +316,7 @@ local function get_player_list_order() role_name = role_name, chat_color = player.chat_color, caption = caption, - tooltip = tooltip + tooltip = tooltip, } end end @@ -398,9 +395,9 @@ SelectedPlayer:on_update(function(player_name, selected_player) update_action_bar(frame.container.action_bar) for _, next_player in pairs(game.connected_players) do local element = scroll_table[next_player.name][open_action_bar.name] - local style = 'frame_button' + local style = "frame_button" if next_player.name == selected_player then - style = 'tool_button' + style = "tool_button" end element.style = style local element_style = element.style @@ -426,9 +423,7 @@ SelectedAction:on_update(function(player_name, selected_action) SelectedPlayer:remove(player) SelectedAction:remove(player) end - else element.visible = false - end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/gui/playerdata.lua b/exp_legacy/module/modules/gui/playerdata.lua index bd905f8f..62969f39 100644 --- a/exp_legacy/module/modules/gui/playerdata.lua +++ b/exp_legacy/module/modules/gui/playerdata.lua @@ -11,21 +11,21 @@ local format_number = require("util").format_number --- @dep util local pd_container local label_width = { - ['name'] = 135, - ['count'] = 105, - ['total'] = 480 + ["name"] = 135, + ["count"] = 105, + ["total"] = 480, } local function format_time_short(value) - return format_time(value*3600, { - hours=true, - minutes=true, - seconds=false + return format_time(value * 3600, { + hours = true, + minutes = true, + seconds = false, }) end local function format_number_n(n) - return format_number(math.floor(n)) .. string.format('%.2f', n % 1):sub(2) + return format_number(math.floor(n)) .. string.format("%.2f", n % 1):sub(2) end local playerStats = PlayerData.Statistics @@ -33,87 +33,87 @@ local computed_stats = { DamageDeathRatio = { default = format_number_n(0), calculate = function(player_name) - return format_number_n(playerStats['DamageDealt']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1)) - end + return format_number_n(playerStats["DamageDealt"]:get(player_name, 0) / playerStats["Deaths"]:get(player_name, 1)) + end, }, KillDeathRatio = { default = format_number_n(0), calculate = function(player_name) - return format_number_n(playerStats['Kills']:get(player_name, 0) / playerStats['Deaths']:get(player_name, 1)) - end + return format_number_n(playerStats["Kills"]:get(player_name, 0) / playerStats["Deaths"]:get(player_name, 1)) + end, }, SessionTime = { default = format_time_short(0), calculate = function(player_name) - return format_time_short((playerStats['Playtime']:get(player_name, 0) - playerStats['AfkTime']:get(player_name, 0)) / playerStats['JoinCount']:get(player_name, 1)) - end + return format_time_short((playerStats["Playtime"]:get(player_name, 0) - playerStats["AfkTime"]:get(player_name, 0)) / playerStats["JoinCount"]:get(player_name, 1)) + end, }, BuildRatio = { default = format_number_n(0), calculate = function(player_name) - return format_number_n(playerStats['MachinesBuilt']:get(player_name, 0) / playerStats['MachinesRemoved']:get(player_name, 1)) - end + return format_number_n(playerStats["MachinesBuilt"]:get(player_name, 0) / playerStats["MachinesRemoved"]:get(player_name, 1)) + end, }, RocketPerHour = { default = format_number_n(0), calculate = function(player_name) - return format_number_n(playerStats['RocketsLaunched']:get(player_name, 0) * 60 / playerStats['Playtime']:get(player_name, 1)) - end + return format_number_n(playerStats["RocketsLaunched"]:get(player_name, 0) * 60 / playerStats["Playtime"]:get(player_name, 1)) + end, }, TreeKillPerMinute = { default = format_number_n(0), calculate = function(player_name) - return format_number_n(playerStats['TreesDestroyed']:get(player_name, 0) / playerStats['Playtime']:get(player_name, 1)) - end + return format_number_n(playerStats["TreesDestroyed"]:get(player_name, 0) / playerStats["Playtime"]:get(player_name, 1)) + end, }, NetPlayTime = { default = format_time_short(0), calculate = function(player_name) - return format_time_short((playerStats['Playtime']:get(player_name, 0) - playerStats['AfkTime']:get(player_name, 0))) - end + return format_time_short((playerStats["Playtime"]:get(player_name, 0) - playerStats["AfkTime"]:get(player_name, 0))) + end, }, AFKTimeRatio = { default = format_number_n(0), calculate = function(player_name) - return format_number_n(playerStats['AfkTime']:get(player_name, 0) * 100 / playerStats['Playtime']:get(player_name, 1)) - end + return format_number_n(playerStats["AfkTime"]:get(player_name, 0) * 100 / playerStats["Playtime"]:get(player_name, 1)) + end, }, } local label = -Gui.element(function(_, parent, width, caption, tooltip, name) - local new_label = parent.add{ - type = 'label', - caption = caption, - tooltip = tooltip, - name = name, - style = 'heading_2_label' - } + Gui.element(function(_, parent, width, caption, tooltip, name) + local new_label = parent.add{ + type = "label", + caption = caption, + tooltip = tooltip, + name = name, + style = "heading_2_label", + } - new_label.style.width = width - return new_label -end) + new_label.style.width = width + return new_label + end) local pd_data_set = -Gui.element(function(_, parent, name) - local pd_data_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(pd_data_set, label_width['total'], 4, 'disp') + Gui.element(function(_, parent, name) + local pd_data_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(pd_data_set, label_width["total"], 4, "disp") - for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do - local child = PlayerData.Statistics[stat_name] - local metadata = child.metadata - local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0) - label(disp, label_width['name'], metadata.name or {'exp-statistics.'..stat_name}, metadata.tooltip or {'exp-statistics.'..stat_name..'-tooltip'}) - label(disp, label_width['count'], {'readme.data-format', value, metadata.unit or ''}, metadata.value_tooltip or {'exp-statistics.'..stat_name..'-tooltip'}, stat_name) - end + for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do + local child = PlayerData.Statistics[stat_name] + local metadata = child.metadata + local value = metadata.stringify_short and metadata.stringify_short(0) or metadata.stringify and metadata.stringify(0) or format_number(0) + label(disp, label_width["name"], metadata.name or { "exp-statistics." .. stat_name }, metadata.tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }) + label(disp, label_width["count"], { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name) + end - for stat_name, data in pairs(computed_stats) do - label(disp, label_width['name'], {'exp-statistics.'..stat_name}, {'exp-statistics.'..stat_name..'-tooltip'}) - label(disp, label_width['count'], {'readme.data-format', data.default, ''}, {'exp-statistics.'..stat_name..'-tooltip'}, stat_name) - end + for stat_name, data in pairs(computed_stats) do + label(disp, label_width["name"], { "exp-statistics." .. stat_name }, { "exp-statistics." .. stat_name .. "-tooltip" }) + label(disp, label_width["count"], { "readme.data-format", data.default, "" }, { "exp-statistics." .. stat_name .. "-tooltip" }, stat_name) + end - return pd_data_set -end) + return pd_data_set + end) local function pd_update(table, player_name) for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do @@ -127,79 +127,79 @@ local function pd_update(table, player_name) else value = format_number(value or 0) end - table[stat_name].caption = {'readme.data-format', value, metadata.unit or ''} + table[stat_name].caption = { "readme.data-format", value, metadata.unit or "" } end for stat_name, data in pairs(computed_stats) do - table[stat_name].caption = {'readme.data-format', data.calculate(player_name), ''} + table[stat_name].caption = { "readme.data-format", data.calculate(player_name), "" } end end local pd_username_player = -Gui.element(function(definition, parent, player_list) - return parent.add{ - name = definition.name, - type = 'drop-down', - items = player_list, - selected_index = #player_list > 0 and 1 - } -end) -:style{ - horizontally_stretchable = true -}:on_selection_changed(function(_, element, _) - local player_name = game.connected_players[element.selected_index] - local table = element.parent.parent.parent.parent['pd_st_2'].disp.table - pd_update(table, player_name) -end) -:static_name(Gui.unique_static_name) + Gui.element(function(definition, parent, player_list) + return parent.add{ + name = definition.name, + type = "drop-down", + items = player_list, + selected_index = #player_list > 0 and 1, + } + end) + :style{ + horizontally_stretchable = true, + }:on_selection_changed(function(_, element, _) + local player_name = game.connected_players[element.selected_index] + local table = element.parent.parent.parent.parent["pd_st_2"].disp.table + pd_update(table, player_name) + end) + :static_name(Gui.unique_static_name) local pd_username_update = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = 'update' -}:style{ - width = 128 -}:on_click(function(_, element, _) - local player_index = element.parent[pd_username_player.name].selected_index + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = "update", + }:style{ + width = 128, + }:on_click(function(_, element, _) + local player_index = element.parent[pd_username_player.name].selected_index - if player_index > 0 then - local player_name = game.connected_players[player_index] - local table = element.parent.parent.parent.parent['pd_st_2'].disp.table - pd_update(table, player_name) - end -end) + if player_index > 0 then + local player_name = game.connected_players[player_index] + local table = element.parent.parent.parent.parent["pd_st_2"].disp.table + pd_update(table, player_name) + end + end) local pd_username_set = -Gui.element(function(_, parent, name, player_list) - local pd_username_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(pd_username_set, label_width['total'], 2, 'disp') + Gui.element(function(_, parent, name, player_list) + local pd_username_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(pd_username_set, label_width["total"], 2, "disp") - pd_username_player(disp, player_list) - pd_username_update(disp) + pd_username_player(disp, player_list) + pd_username_update(disp) - return pd_username_set -end) + return pd_username_set + end) pd_container = -Gui.element(function(definition, parent) - local container = Gui.container(parent, definition.name, label_width['total']) - local player_list = {} + Gui.element(function(definition, parent) + local container = Gui.container(parent, definition.name, label_width["total"]) + local player_list = {} - for _, player in pairs(game.connected_players) do - table.insert(player_list, player.name) - end + for _, player in pairs(game.connected_players) do + table.insert(player_list, player.name) + end - pd_username_set(container, 'pd_st_1', player_list) - pd_data_set(container, 'pd_st_2') + pd_username_set(container, "pd_st_1", player_list) + pd_data_set(container, "pd_st_2") - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() -Gui.left_toolbar_button('item/power-armor-mk2', 'Player Data GUI', pd_container, function(player) - return Roles.player_allowed(player, 'gui/playerdata') +Gui.left_toolbar_button("item/power-armor-mk2", "Player Data GUI", pd_container, function(player) + return Roles.player_allowed(player, "gui/playerdata") end) local function gui_player_list_update() @@ -211,7 +211,7 @@ local function gui_player_list_update() for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, pd_container) - frame.container['pd_st_1'].disp.table[pd_username_player.name].items = player_list + frame.container["pd_st_1"].disp.table[pd_username_player.name].items = player_list end end diff --git a/exp_legacy/module/modules/gui/production.lua b/exp_legacy/module/modules/gui/production.lua index d69a7eb0..6c6026cb 100644 --- a/exp_legacy/module/modules/gui/production.lua +++ b/exp_legacy/module/modules/gui/production.lua @@ -12,153 +12,150 @@ local precision = { [2] = defines.flow_precision_index.one_minute, [3] = defines.flow_precision_index.ten_minutes, [4] = defines.flow_precision_index.one_hour, - [5] = defines.flow_precision_index.ten_hours + [5] = defines.flow_precision_index.ten_hours, } local font_color = { -- positive - [1] = {r = 0.3, g = 1, b = 0.3}, + [1] = { r = 0.3, g = 1, b = 0.3 }, -- negative - [2] = {r = 1, g = 0.3, b = 0.3} + [2] = { r = 1, g = 0.3, b = 0.3 }, } local function format_n(n) - local _i, _j, m, i, f = string.format('%.1f', n):find('([-]?)(%d+)([.]?%d*)') - i = i:reverse():gsub('(%d%d%d)', '%1,') + local _i, _j, m, i, f = tostring(n):find("([-]?)(%d+)([.]?%d*)") + i = i:reverse():gsub("(%d%d%d)", "%1,") - if f ~= '' then - return m .. i:reverse():gsub('^,', '') .. f + if f ~= "" then + return m .. i:reverse():gsub("^,", "") .. f else - return m .. i:reverse():gsub('^,', '') .. '.0' + return m .. i:reverse():gsub("^,", "") .. ".0" end end --- Display group -- @element production_data_group local production_data_group = -Gui.element(function(_definition, parent, i) - local item + Gui.element(function(_definition, parent, i) + local item - if i == 0 then - item = parent.add{ - type = 'drop-down', - name = 'production_0_e', - items = {'5s', '1m', '10m', '1h', '10h'}, - selected_index = 3 + if i == 0 then + item = parent.add{ + type = "drop-down", + name = "production_0_e", + items = { "5s", "1m", "10m", "1h", "10h" }, + selected_index = 3, + } + item.style.width = 80 + else + item = parent.add{ + type = "choose-elem-button", + name = "production_" .. i .. "_e", + elem_type = "item", + style = "slot_button", + } + item.style.height = 32 + item.style.width = 32 + end + + local data_1 = parent.add{ + type = "label", + name = "production_" .. i .. "_1", + caption = "0.0", + style = "heading_2_label", } - item.style.width = 80 + data_1.style.width = 90 + data_1.style.horizontal_align = "right" + data_1.style.font_color = font_color[1] - else - item = parent.add{ - type = 'choose-elem-button', - name = 'production_' .. i .. '_e', - elem_type = 'item', - style = 'slot_button' + local data_2 = parent.add{ + type = "label", + name = "production_" .. i .. "_2", + caption = "0.0", + style = "heading_2_label", } - item.style.height = 32 - item.style.width = 32 - end + data_2.style.width = 90 + data_2.style.horizontal_align = "right" + data_2.style.font_color = font_color[2] - local data_1 = parent.add{ - type = 'label', - name = 'production_' .. i .. '_1', - caption = '0.0', - style = 'heading_2_label' - } - data_1.style.width = 90 - data_1.style.horizontal_align = 'right' - data_1.style.font_color = font_color[1] + local data_3 = parent.add{ + type = "label", + name = "production_" .. i .. "_3", + caption = "0.0", + style = "heading_2_label", + } + data_3.style.width = 90 + data_3.style.horizontal_align = "right" + data_3.style.font_color = font_color[1] - local data_2 = parent.add{ - type = 'label', - name = 'production_' .. i .. '_2', - caption = '0.0', - style = 'heading_2_label' - } - data_2.style.width = 90 - data_2.style.horizontal_align = 'right' - data_2.style.font_color = font_color[2] - - local data_3 = parent.add{ - type = 'label', - name = 'production_' .. i .. '_3', - caption = '0.0', - style = 'heading_2_label' - } - data_3.style.width = 90 - data_3.style.horizontal_align = 'right' - data_3.style.font_color = font_color[1] - - return item -end) + return item + end) --- A vertical flow containing all the production data -- @element production_data_set local production_data_set = -Gui.element(function(_, parent, name) - local production_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(production_set, 350, 4, 'disp') + Gui.element(function(_, parent, name) + local production_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(production_set, 350, 4, "disp") - production_data_group(disp, 0) + production_data_group(disp, 0) - disp['production_0_1'].caption = {'production.label-prod'} - disp['production_0_2'].caption = {'production.label-con'} - disp['production_0_3'].caption = {'production.label-bal'} + disp["production_0_1"].caption = { "production.label-prod" } + disp["production_0_2"].caption = { "production.label-con" } + disp["production_0_3"].caption = { "production.label-bal" } - for i=1, 8 do - production_data_group(disp, i) - end + for i = 1, 8 do + production_data_group(disp, i) + end - return production_set -end) + return production_set + end) production_container = -Gui.element(function(definition, parent) - local container = Gui.container(parent, definition.name, 350) + Gui.element(function(definition, parent) + local container = Gui.container(parent, definition.name, 350) - production_data_set(container, 'production_st') + production_data_set(container, "production_st") - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() -Gui.left_toolbar_button('entity/assembling-machine-3', {'production.main-tooltip'}, production_container, function(player) - return Roles.player_allowed(player, 'gui/production') +Gui.left_toolbar_button("entity/assembling-machine-3", { "production.main-tooltip" }, production_container, function(player) + return Roles.player_allowed(player, "gui/production") end) Event.on_nth_tick(60, function() for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, production_container) local stat = player.force.get_item_production_statistics(player.surface) - local precision_value = precision[frame.container['production_st'].disp.table['production_0_e'].selected_index] - local table = frame.container['production_st'].disp.table + local precision_value = precision[frame.container["production_st"].disp.table["production_0_e"].selected_index] + local table = frame.container["production_st"].disp.table - for i=1, 8 do - local production_prefix = 'production_' .. i - local item = table[production_prefix .. '_e'].elem_value + for i = 1, 8 do + local production_prefix = "production_" .. i + local item = table[production_prefix .. "_e"].elem_value if item then - local add = math.floor(stat.get_flow_count{name=item, category="input", precision_index=precision_value, count=false} / 6) / 10 - local minus = math.floor(stat.get_flow_count{name=item, category="output", precision_index=precision_value, count=false} / 6) / 10 + local add = math.floor(stat.get_flow_count{ name = item, category = "input", precision_index = precision_value, count = false } / 6) / 10 + local minus = math.floor(stat.get_flow_count{ name = item, category = "output", precision_index = precision_value, count = false } / 6) / 10 local sum = add - minus - table[production_prefix .. '_1'].caption = format_n(add) - table[production_prefix .. '_2'].caption = format_n(minus) - table[production_prefix .. '_3'].caption = format_n(sum) + table[production_prefix .. "_1"].caption = format_n(add) + table[production_prefix .. "_2"].caption = format_n(minus) + table[production_prefix .. "_3"].caption = format_n(sum) if sum < 0 then - table[production_prefix .. '_3'].style.font_color = font_color[2] - + table[production_prefix .. "_3"].style.font_color = font_color[2] else - table[production_prefix .. '_3'].style.font_color = font_color[1] + table[production_prefix .. "_3"].style.font_color = font_color[1] end - else - table[production_prefix .. '_1'].caption = '0.0' - table[production_prefix .. '_2'].caption = '0.0' - table[production_prefix .. '_3'].caption = '0.0' - table[production_prefix .. '_3'].style.font_color = font_color[1] + table[production_prefix .. "_1"].caption = "0.0" + table[production_prefix .. "_2"].caption = "0.0" + table[production_prefix .. "_3"].caption = "0.0" + table[production_prefix .. "_3"].style.font_color = font_color[1] end end end diff --git a/exp_legacy/module/modules/gui/readme.lua b/exp_legacy/module/modules/gui/readme.lua index fd6c816b..2db8fc59 100644 --- a/exp_legacy/module/modules/gui/readme.lua +++ b/exp_legacy/module/modules/gui/readme.lua @@ -15,7 +15,7 @@ local format_number = require("util").format_number --- @dep util local tabs = {} local function Tab(caption, tooltip, element_define) - tabs[#tabs+1] = {caption, tooltip, element_define} + tabs[#tabs + 1] = { caption, tooltip, element_define } end local frame_width = 595 -- controls width of top descriptions @@ -25,441 +25,445 @@ local scroll_height = 275 -- controls the height of the scrolls --- Sub content area used within the content areas -- @element sub_content local sub_content = -Gui.element{ - type = 'frame', - direction = 'vertical', - style = 'inside_deep_frame' -} -:style{ - horizontally_stretchable = true, - horizontal_align = 'center', - padding = {2, 2}, - top_margin = 2 -} + Gui.element{ + type = "frame", + direction = "vertical", + style = "inside_deep_frame", + } + :style{ + horizontally_stretchable = true, + horizontal_align = "center", + padding = { 2, 2 }, + top_margin = 2, + } --- Table which has a title above it above it -- @element title_table local title_table = -Gui.element(function(_, parent, bar_size, caption, column_count) - Gui.title_label(parent, bar_size, caption) + Gui.element(function(_, parent, bar_size, caption, column_count) + Gui.title_label(parent, bar_size, caption) - return parent.add{ - type = 'table', - column_count = column_count, - style = 'bordered_table' + return parent.add{ + type = "table", + column_count = column_count, + style = "bordered_table", + } + end) + :style{ + padding = 0, + cell_padding = 0, + vertical_align = "center", + horizontally_stretchable = true, } -end) -:style{ - padding = 0, - cell_padding = 0, - vertical_align = 'center', - horizontally_stretchable = true -} --- Scroll to be used with Gui.title_label tables -- @element title_table_scroll local title_table_scroll = -Gui.element{ - type = 'scroll-pane', - direction = 'vertical', - horizontal_scroll_policy = 'never', - vertical_scroll_policy = 'auto', - style = 'scroll_pane_under_subheader' -} -:style{ - padding = {1, 3}, - maximal_height = scroll_height, - horizontally_stretchable = true, -} + Gui.element{ + type = "scroll-pane", + direction = "vertical", + horizontal_scroll_policy = "never", + vertical_scroll_policy = "auto", + style = "scroll_pane_under_subheader", + } + :style{ + padding = { 1, 3 }, + maximal_height = scroll_height, + horizontally_stretchable = true, + } --- Used to connect to servers in server list -- @element join_server local join_server = -Gui.element(function(_, parent, server_id, wrong_version) - local status = External.get_server_status(server_id) or 'Offline' - if wrong_version then status = 'Version' end - local flow = parent.add{ name = server_id, type = 'flow' } - local button = flow.add{ - type = 'sprite-button', - sprite = 'utility/circuit_network_panel', - hovered_sprite = 'utility/circuit_network_panel', - tooltip = {'readme.servers-connect-'..status, wrong_version}, - style = "frame_action_button" - } + Gui.element(function(_, parent, server_id, wrong_version) + local status = External.get_server_status(server_id) or "Offline" + if wrong_version then status = "Version" end + local flow = parent.add{ name = server_id, type = "flow" } + local button = flow.add{ + type = "sprite-button", + sprite = "utility/circuit_network_panel", + hovered_sprite = "utility/circuit_network_panel", + tooltip = { "readme.servers-connect-" .. status, wrong_version }, + style = "frame_action_button", + } - if status == 'Offline' or status == 'Current' then - button.enabled = false - button.sprite = 'utility/circuit_network_panel' - elseif status == 'Version' then - button.enabled = false - button.sprite = 'utility/shuffle' - elseif status == 'Password' then - button.sprite = 'utility/warning_white' - button.hovered_sprite = 'utility/warning' - elseif status == 'Modded' then - button.sprite = 'utility/downloading_white' - button.hovered_sprite = 'utility/downloading' - end + if status == "Offline" or status == "Current" then + button.enabled = false + button.sprite = "utility/circuit_network_panel" + elseif status == "Version" then + button.enabled = false + button.sprite = "utility/shuffle" + elseif status == "Password" then + button.sprite = "utility/warning_white" + button.hovered_sprite = "utility/warning" + elseif status == "Modded" then + button.sprite = "utility/downloading_white" + button.hovered_sprite = "utility/downloading" + end - return button -end) -:style(Gui.sprite_style(20, -1)) -:on_click(function(player, element, _) - local server_id = element.parent.name - External.request_connection(player, server_id, true) -end) + return button + end) + :style(Gui.sprite_style(20, -1)) + :on_click(function(player, element, _) + local server_id = element.parent.name + External.request_connection(player, server_id, true) + end) --- Content area for the welcome tab -- @element welcome_content -Tab({'readme.welcome-tab'}, {'readme.welcome-tooltip'}, -Gui.element(function(_, parent) - local server_details = { name='ExpGaming S0 - Local', welcome='Failed to load description: disconnected from external api.', reset_time='Non Set', branch='Unknown'} - if External.valid() then server_details = External.get_current_server() end - local container = parent.add{ type='flow', direction='vertical' } - local player = Gui.get_player_from_element(parent) +Tab({ "readme.welcome-tab" }, { "readme.welcome-tooltip" }, + Gui.element(function(_, parent) + local server_details = { name = "ExpGaming S0 - Local", welcome = "Failed to load description: disconnected from external api.", reset_time = "Non Set", branch = "Unknown" } + if External.valid() then server_details = External.get_current_server() end + local container = parent.add{ type = "flow", direction = "vertical" } + local player = Gui.get_player_from_element(parent) - -- Set up the top flow with logos - local top_flow = container.add{ type='flow' } - top_flow.add{ type='sprite', sprite='file/modules/exp_legacy/modules/gui/logo.png' } - local top_vertical_flow = top_flow.add{ type='flow', direction='vertical' } - top_flow.add{ type='sprite', sprite='file/modules/exp_legacy/modules/gui/logo.png' } - top_vertical_flow.style.horizontal_align = 'center' + -- Set up the top flow with logos + local top_flow = container.add{ type = "flow" } + top_flow.add{ type = "sprite", sprite = "file/modules/exp_legacy/modules/gui/logo.png" } + local top_vertical_flow = top_flow.add{ type = "flow", direction = "vertical" } + top_flow.add{ type = "sprite", sprite = "file/modules/exp_legacy/modules/gui/logo.png" } + top_vertical_flow.style.horizontal_align = "center" - -- Add the title and description to the top flow - Gui.title_label(top_vertical_flow, 62, 'Welcome to '..server_details.name) - Gui.centered_label(top_vertical_flow, 380, server_details.welcome) - Gui.bar(container) + -- Add the title and description to the top flow + Gui.title_label(top_vertical_flow, 62, "Welcome to " .. server_details.name) + Gui.centered_label(top_vertical_flow, 380, server_details.welcome) + Gui.bar(container) - -- Get the names of the roles the player has - local player_roles = Roles.get_player_roles(player) - local role_names = {} - for i, role in ipairs(player_roles) do - role_names[i] = role.name - end + -- Get the names of the roles the player has + local player_roles = Roles.get_player_roles(player) + local role_names = {} + for i, role in ipairs(player_roles) do + role_names[i] = role.name + end - -- Add the other information to the gui - container.add{ type='flow' }.style.height = 4 - local online_time = format_time(game.tick, {days=true, hours=true, minutes=true, long=true}) - Gui.centered_label(sub_content(container), frame_width, {'readme.welcome-general', server_details.reset_time, online_time}) - Gui.centered_label(sub_content(container), frame_width, {'readme.welcome-roles', table.concat(role_names, ', ')}) - Gui.centered_label(sub_content(container), frame_width, {'readme.welcome-chat'}) + -- Add the other information to the gui + container.add{ type = "flow" }.style.height = 4 + local online_time = format_time(game.tick, { days = true, hours = true, minutes = true, long = true }) + Gui.centered_label(sub_content(container), frame_width, { "readme.welcome-general", server_details.reset_time, online_time }) + Gui.centered_label(sub_content(container), frame_width, { "readme.welcome-roles", table.concat(role_names, ", ") }) + Gui.centered_label(sub_content(container), frame_width, { "readme.welcome-chat" }) - return container -end)) + return container + end)) --- Content area for the rules tab -- @element rules_content -Tab({'readme.rules-tab'}, {'readme.rules-tooltip'}, -Gui.element(function(_, parent) - local container = parent.add{ type='flow', direction='vertical' } +Tab({ "readme.rules-tab" }, { "readme.rules-tooltip" }, + Gui.element(function(_, parent) + local container = parent.add{ type = "flow", direction = "vertical" } - -- Add the title and description to the content - Gui.title_label(container, title_width-3, {'readme.rules-tab'}) - Gui.centered_label(container, frame_width, {'readme.rules-general'}) - Gui.bar(container) - container.add{ type='flow' } + -- Add the title and description to the content + Gui.title_label(container, title_width - 3, { "readme.rules-tab" }) + Gui.centered_label(container, frame_width, { "readme.rules-general" }) + Gui.bar(container) + container.add{ type = "flow" } - -- Add a table for the rules - local rules = Gui.scroll_table(container, scroll_height, 1) - rules.style = 'bordered_table' - rules.style.cell_padding = 4 + -- Add a table for the rules + local rules = Gui.scroll_table(container, scroll_height, 1) + rules.style = "bordered_table" + rules.style.cell_padding = 4 - -- Add the rules to the table - for i = 1, 15 do - Gui.centered_label(rules, 565, {'readme.rules-'..i}) - end + -- Add the rules to the table + for i = 1, 15 do + Gui.centered_label(rules, 565, { "readme.rules-" .. i }) + end - return container -end)) + return container + end)) --- Content area for the commands tab -- @element commands_content -Tab({'readme.commands-tab'}, {'readme.commands-tooltip'}, -Gui.element(function(_, parent) - local container = parent.add{ type='flow', direction='vertical' } - local player = Gui.get_player_from_element(parent) +Tab({ "readme.commands-tab" }, { "readme.commands-tooltip" }, + Gui.element(function(_, parent) + local container = parent.add{ type = "flow", direction = "vertical" } + local player = Gui.get_player_from_element(parent) - -- Add the title and description to the content - Gui.title_label(container, title_width-20, {'readme.commands-tab'}) - Gui.centered_label(container, frame_width, {'readme.commands-general'}) - Gui.bar(container) - container.add{ type='flow' } + -- Add the title and description to the content + Gui.title_label(container, title_width - 20, { "readme.commands-tab" }) + Gui.centered_label(container, frame_width, { "readme.commands-general" }) + Gui.bar(container) + container.add{ type = "flow" } - -- Add a table for the commands - local commands = Gui.scroll_table(container, scroll_height, 2) - commands.style = 'bordered_table' - commands.style.cell_padding = 0 + -- Add a table for the commands + local commands = Gui.scroll_table(container, scroll_height, 2) + commands.style = "bordered_table" + commands.style.cell_padding = 0 - -- Add the rules to the table - for name, command in pairs(Commands.get(player)) do - Gui.centered_label(commands, 120, name) - Gui.centered_label(commands, 450, command.help) - end + -- Add the rules to the table + for name, command in pairs(Commands.get(player)) do + Gui.centered_label(commands, 120, name) + Gui.centered_label(commands, 450, command.help) + end - return container -end)) + return container + end)) --- Content area for the servers tab -- @element servers_content -Tab({'readme.servers-tab'}, {'readme.servers-tooltip'}, -Gui.element(function(_, parent) - local container = parent.add{ type='flow', direction='vertical' } +Tab({ "readme.servers-tab" }, { "readme.servers-tooltip" }, + Gui.element(function(_, parent) + local container = parent.add{ type = "flow", direction = "vertical" } - -- Add the title and description to the content - Gui.title_label(container, title_width-10, {'readme.servers-tab'}) - Gui.centered_label(container, frame_width, {'readme.servers-general'}) - Gui.bar(container) - container.add{ type='flow' } + -- Add the title and description to the content + Gui.title_label(container, title_width - 10, { "readme.servers-tab" }) + Gui.centered_label(container, frame_width, { "readme.servers-general" }) + Gui.bar(container) + container.add{ type = "flow" } - -- Draw the scroll - local scroll_pane = title_table_scroll(container) - scroll_pane.style.maximal_height = scroll_height + 20 -- the text is a bit shorter + -- Draw the scroll + local scroll_pane = title_table_scroll(container) + scroll_pane.style.maximal_height = scroll_height + 20 -- the text is a bit shorter - -- Add the factorio servers - if External.valid() then - local factorio_servers = title_table(scroll_pane, 225, {'readme.servers-factorio'}, 3) - local current_version = External.get_current_server().version - for server_id, server in pairs(External.get_servers()) do - Gui.centered_label(factorio_servers, 110, server.short_name) - Gui.centered_label(factorio_servers, 436, server.description) - join_server(factorio_servers, server_id, current_version ~= server.version and server.version) + -- Add the factorio servers + if External.valid() then + local factorio_servers = title_table(scroll_pane, 225, { "readme.servers-factorio" }, 3) + local current_version = External.get_current_server().version + for server_id, server in pairs(External.get_servers()) do + Gui.centered_label(factorio_servers, 110, server.short_name) + Gui.centered_label(factorio_servers, 436, server.description) + join_server(factorio_servers, server_id, current_version ~= server.version and server.version) + end + else + local factorio_servers = title_table(scroll_pane, 225, { "readme.servers-factorio" }, 2) + for i = 1, 8 do + Gui.centered_label(factorio_servers, 110, { "readme.servers-" .. i }) + Gui.centered_label(factorio_servers, 460, { "readme.servers-d" .. i }) + end end - else - local factorio_servers = title_table(scroll_pane, 225, {'readme.servers-factorio'}, 2) - for i = 1, 8 do - Gui.centered_label(factorio_servers, 110, {'readme.servers-'..i}) - Gui.centered_label(factorio_servers, 460, {'readme.servers-d'..i}) + + -- Add the external links + local external_links = title_table(scroll_pane, 235, { "readme.servers-external" }, 2) + for _, key in ipairs{ "discord", "website", "patreon", "status", "github" } do + local upper_key = key:gsub("^%l", string.upper) + Gui.centered_label(external_links, 110, upper_key) + Gui.centered_label(external_links, 460, { "links." .. key }, { "readme.servers-open-in-browser" }) end - end - -- Add the external links - local external_links = title_table(scroll_pane, 235, {'readme.servers-external'}, 2) - for _, key in ipairs{'discord', 'website', 'patreon', 'status', 'github'} do - local upper_key = key:gsub("^%l", string.upper) - Gui.centered_label(external_links, 110, upper_key) - Gui.centered_label(external_links, 460, {'links.'..key}, {'readme.servers-open-in-browser'}) - end - - return container -end)) + return container + end)) --- Content area for the servers tab -- @element backers_content -Tab({'readme.backers-tab'}, {'readme.backers-tooltip'}, -Gui.element(function(_, parent) - local container = parent.add{ type='flow', direction='vertical' } +Tab({ "readme.backers-tab" }, { "readme.backers-tooltip" }, + Gui.element(function(_, parent) + local container = parent.add{ type = "flow", direction = "vertical" } - -- Add the title and description to the content - Gui.title_label(container, title_width-10, {'readme.backers-tab'}) - Gui.centered_label(container, frame_width, {'readme.backers-general'}) - Gui.bar(container) - container.add{ type='flow' } + -- Add the title and description to the content + Gui.title_label(container, title_width - 10, { "readme.backers-tab" }) + Gui.centered_label(container, frame_width, { "readme.backers-general" }) + Gui.bar(container) + container.add{ type = "flow" } - -- Find which players will go where - local done = {} - local groups = { - { _roles={'Senior Administrator', 'Administrator'}, _title={'readme.backers-management'}, _width=230 }, - { _roles={'Board Member', 'Senior Backer'}, _title={'readme.backers-board'}, _width=145 }, -- change role to board - { _roles={'Sponsor', 'Supporter'}, _title={'readme.backers-backers'}, _width=196 }, -- change to backer - { _roles={'Moderator', 'Trainee'}, _title={'readme.backers-staff'}, _width=235 }, - { _roles={}, _time=3*3600*60, _title={'readme.backers-active'}, _width=235 }, - } + -- Find which players will go where + local done = {} + local groups = { + { _roles = { "Senior Administrator", "Administrator" }, _title = { "readme.backers-management" }, _width = 230 }, + { _roles = { "Board Member", "Senior Backer" }, _title = { "readme.backers-board" }, _width = 145 }, -- change role to board + { _roles = { "Sponsor", "Supporter" }, _title = { "readme.backers-backers" }, _width = 196 }, -- change to backer + { _roles = { "Moderator", "Trainee" }, _title = { "readme.backers-staff" }, _width = 235 }, + { _roles = {}, _time = 3 * 3600 * 60, _title = { "readme.backers-active" }, _width = 235 }, + } - -- Fill by player roles - for player_name, player_roles in pairs(Roles.config.players) do - for _, players in ipairs(groups) do - for _, role_name in pairs(players._roles) do - if table.contains(player_roles, role_name) then - done[player_name] = true - table.insert(players, player_name) - break - end - end - end - end - - -- Fill by active times - for _, player in pairs(game.players) do - if not done[player.name] then + -- Fill by player roles + for player_name, player_roles in pairs(Roles.config.players) do for _, players in ipairs(groups) do - if players._time and player.online_time > players._time then - table.insert(players, player.name) + for _, role_name in pairs(players._roles) do + if table.contains(player_roles, role_name) then + done[player_name] = true + table.insert(players, player_name) + break + end end end end - end - -- Add the different tables - local scroll_pane = title_table_scroll(container) - for _, players in ipairs(groups) do - local table = title_table(scroll_pane, players._width, players._title, 4) - for _, player_name in ipairs(players) do - Gui.centered_label(table, 140, player_name) - end - - if #players < 4 then - for i = 1, 4-#players do - Gui.centered_label(table, 140) + -- Fill by active times + for _, player in pairs(game.players) do + if not done[player.name] then + for _, players in ipairs(groups) do + if players._time and player.online_time > players._time then + table.insert(players, player.name) + end + end end end - end - return container -end)) + -- Add the different tables + local scroll_pane = title_table_scroll(container) + for _, players in ipairs(groups) do + local table = title_table(scroll_pane, players._width, players._title, 4) + for _, player_name in ipairs(players) do + Gui.centered_label(table, 140, player_name) + end + + if #players < 4 then + for i = 1, 4 - #players do + Gui.centered_label(table, 140) + end + end + end + + return container + end)) --- Content area for the player data tab -- @element commands_content -Tab({'readme.data-tab'}, {'readme.data-tooltip'}, -Gui.element(function(_, parent) - local container = parent.add{ type='flow', direction='vertical' } - local player = Gui.get_player_from_element(parent) - local player_name = player.name +Tab({ "readme.data-tab" }, { "readme.data-tooltip" }, + Gui.element(function(_, parent) + local container = parent.add{ type = "flow", direction = "vertical" } + local player = Gui.get_player_from_element(parent) + local player_name = player.name - local enum = PlayerData.PreferenceEnum - local preference = PlayerData.DataSavingPreference:get(player_name) - local preference_meta = PlayerData.DataSavingPreference.metadata - preference = enum[preference] + local enum = PlayerData.PreferenceEnum + local preference = PlayerData.DataSavingPreference:get(player_name) + local preference_meta = PlayerData.DataSavingPreference.metadata + preference = enum[preference] - -- Add the title and description to the content - Gui.title_label(container, title_width, {'readme.data-tab'}) - Gui.centered_label(container, frame_width, {'readme.data-general'}) - Gui.bar(container) - container.add{ type='flow' } - local scroll_pane = title_table_scroll(container) + -- Add the title and description to the content + Gui.title_label(container, title_width, { "readme.data-tab" }) + Gui.centered_label(container, frame_width, { "readme.data-general" }) + Gui.bar(container) + container.add{ type = "flow" } + local scroll_pane = title_table_scroll(container) - -- Add the required area - local required = title_table(scroll_pane, 250, {'readme.data-required'}, 2) - Gui.centered_label(required, 150, preference_meta.name, preference_meta.tooltip) - Gui.centered_label(required, 420, {'expcore-data.preference-'..enum[preference]}, preference_meta.value_tooltip) + -- Add the required area + local required = title_table(scroll_pane, 250, { "readme.data-required" }, 2) + Gui.centered_label(required, 150, preference_meta.name, preference_meta.tooltip) + Gui.centered_label(required, 420, { "expcore-data.preference-" .. enum[preference] }, preference_meta.value_tooltip) - for name, child in pairs(PlayerData.Required.children) do - local metadata = child.metadata - local value = child:get(player_name) - if value ~= nil or metadata.show_always then - if metadata.stringify then value = metadata.stringify(value) end - Gui.centered_label(required, 150, metadata.name or {'exp-required.'..name}, metadata.tooltip or {'exp-required.'..name..'-tooltip'}) - Gui.centered_label(required, 420, tostring(value), metadata.value_tooltip or {'exp-required.'..name..'-value-tooltip'}) - end - end - - -- Add the settings area - if preference <= enum.Settings then - local settings = title_table(scroll_pane, 255, {'readme.data-settings'}, 2) - for name, child in pairs(PlayerData.Settings.children) do - local metadata = child.metadata - local value = child:get(player_name) - if not metadata.permission or Roles.player_allowed(player, metadata.permission) then - if metadata.stringify then value = metadata.stringify(value) end - if value == nil then value = 'None set' end - Gui.centered_label(settings, 150, metadata.name or {'exp-settings.'..name}, metadata.tooltip or {'exp-settings.'..name..'-tooltip'}) - Gui.centered_label(settings, 420, tostring(value), metadata.value_tooltip or {'exp-settings.'..name..'-value-tooltip'}) - end - end - end - - -- Add the statistics area - if preference <= enum.Statistics then - local count = 4 - local statistics = title_table(scroll_pane, 250, {'readme.data-statistics'}, 4) - for _, name in pairs(PlayerData.Statistics.metadata.display_order) do - local child = PlayerData.Statistics[name] + for name, child in pairs(PlayerData.Required.children) do local metadata = child.metadata local value = child:get(player_name) if value ~= nil or metadata.show_always then - count = count - 2 - if metadata.stringify then value = metadata.stringify(value) - else value = format_number(value or 0) end - Gui.centered_label(statistics, 150, metadata.name or {'exp-statistics.'..name}, metadata.tooltip or {'exp-statistics.'..name..'-tooltip'}) - Gui.centered_label(statistics, 130, {'readme.data-format', value, metadata.unit or ''}, metadata.value_tooltip or {'exp-statistics.'..name..'-tooltip'}) + if metadata.stringify then value = metadata.stringify(value) end + Gui.centered_label(required, 150, metadata.name or { "exp-required." .. name }, metadata.tooltip or { "exp-required." .. name .. "-tooltip" }) + Gui.centered_label(required, 420, tostring(value), metadata.value_tooltip or { "exp-required." .. name .. "-value-tooltip" }) end end - if count > 0 then for i = 1, count do Gui.centered_label(statistics, 140) end end - end - -- Add the misc area - local skip = {DataSavingPreference=true, Settings=true, Statistics=true, Required=true} - local count = 0; for _ in pairs(PlayerData.All.children) do count = count + 1 end - if preference <= enum.All and count > 4 then - local misc = title_table(scroll_pane, 232, {'readme.data-misc'}, 2) - for name, child in pairs(PlayerData.All.children) do - if not skip[name] then + -- Add the settings area + if preference <= enum.Settings then + local settings = title_table(scroll_pane, 255, { "readme.data-settings" }, 2) + for name, child in pairs(PlayerData.Settings.children) do local metadata = child.metadata local value = child:get(player_name) - if value ~= nil or metadata.show_always then + if not metadata.permission or Roles.player_allowed(player, metadata.permission) then if metadata.stringify then value = metadata.stringify(value) end - Gui.centered_label(misc, 150, metadata.name or name, metadata.tooltip) - Gui.centered_label(misc, 420, tostring(value), metadata.value_tooltip) + if value == nil then value = "None set" end + Gui.centered_label(settings, 150, metadata.name or { "exp-settings." .. name }, metadata.tooltip or { "exp-settings." .. name .. "-tooltip" }) + Gui.centered_label(settings, 420, tostring(value), metadata.value_tooltip or { "exp-settings." .. name .. "-value-tooltip" }) end end end - end - return container -end)) + -- Add the statistics area + if preference <= enum.Statistics then + local count = 4 + local statistics = title_table(scroll_pane, 250, { "readme.data-statistics" }, 4) + for _, name in pairs(PlayerData.Statistics.metadata.display_order) do + local child = PlayerData.Statistics[name] + local metadata = child.metadata + local value = child:get(player_name) + if value ~= nil or metadata.show_always then + count = count - 2 + if metadata.stringify then + value = metadata.stringify(value) + else + value = format_number(value or 0) + end + Gui.centered_label(statistics, 150, metadata.name or { "exp-statistics." .. name }, metadata.tooltip or { "exp-statistics." .. name .. "-tooltip" }) + Gui.centered_label(statistics, 130, { "readme.data-format", value, metadata.unit or "" }, metadata.value_tooltip or { "exp-statistics." .. name .. "-tooltip" }) + end + end + if count > 0 then for i = 1, count do Gui.centered_label(statistics, 140) end end + end + + -- Add the misc area + local skip = { DataSavingPreference = true, Settings = true, Statistics = true, Required = true } + local count = 0; for _ in pairs(PlayerData.All.children) do count = count + 1 end + + if preference <= enum.All and count > 4 then + local misc = title_table(scroll_pane, 232, { "readme.data-misc" }, 2) + for name, child in pairs(PlayerData.All.children) do + if not skip[name] then + local metadata = child.metadata + local value = child:get(player_name) + if value ~= nil or metadata.show_always then + if metadata.stringify then value = metadata.stringify(value) end + Gui.centered_label(misc, 150, metadata.name or name, metadata.tooltip) + Gui.centered_label(misc, 420, tostring(value), metadata.value_tooltip) + end + end + end + end + + return container + end)) --- Main readme container for the center flow -- @element readme local readme_toggle local readme = -Gui.element(function(definition, parent) - local container = parent.add{ - name = definition.name, - type = 'frame', - style = 'invisible_frame' - } + Gui.element(function(definition, parent) + local container = parent.add{ + name = definition.name, + type = "frame", + style = "invisible_frame", + } - -- Add the left hand side of the frame back, removed because of frame_tabbed_pane style - local left_alignment = Gui.alignment(container, nil, nil, 'bottom') - left_alignment.style.padding = {32, 0,0, 0} + -- Add the left hand side of the frame back, removed because of frame_tabbed_pane style + local left_alignment = Gui.alignment(container, nil, nil, "bottom") + left_alignment.style.padding = { 32, 0, 0, 0 } - local left_side = - left_alignment.add{ - type = 'frame', - style = 'character_gui_left_side' - } - left_side.style.vertically_stretchable = true - left_side.style.padding = 0 - left_side.style.width = 5 + local left_side = + left_alignment.add{ + type = "frame", + style = "character_gui_left_side", + } + left_side.style.vertically_stretchable = true + left_side.style.padding = 0 + left_side.style.width = 5 - -- Add the tab pane - local tab_pane = container.add{ - name = 'pane', - type = 'tabbed-pane', - style = 'frame_tabbed_pane' - } + -- Add the tab pane + local tab_pane = container.add{ + name = "pane", + type = "tabbed-pane", + style = "frame_tabbed_pane", + } - -- Add the different content areas - for _, tab_details in ipairs(tabs) do - local tab = tab_pane.add{ type = 'tab', style = 'frame_tab', caption = tab_details[1], tooltip = tab_details[2] } - tab_pane.add_tab(tab, tab_details[3](tab_pane)) - end + -- Add the different content areas + for _, tab_details in ipairs(tabs) do + local tab = tab_pane.add{ type = "tab", style = "frame_tab", caption = tab_details[1], tooltip = tab_details[2] } + tab_pane.add_tab(tab, tab_details[3](tab_pane)) + end - return container -end) -:static_name(Gui.unique_static_name) -:on_open(function(player) - Gui.toggle_toolbar_button(player, readme_toggle, true) -end) -:on_close(function(player, element) - Gui.toggle_toolbar_button(player, readme_toggle, false) - Gui.destroy_if_valid(element) -end) + return container + end) + :static_name(Gui.unique_static_name) + :on_open(function(player) + Gui.toggle_toolbar_button(player, readme_toggle, true) + end) + :on_close(function(player, element) + Gui.toggle_toolbar_button(player, readme_toggle, false) + Gui.destroy_if_valid(element) + end) --- Toggle button for the readme gui -- @element readme_toggle readme_toggle = -Gui.toolbar_button('virtual-signal/signal-info', {'readme.main-tooltip'}, function(player) - return Roles.player_allowed(player, 'gui/readme') -end) -:on_click(function(player, _) - local center = player.gui.center - if center[readme.name] then - player.opened = nil - else - player.opened = readme(center) - end -end) + Gui.toolbar_button("virtual-signal/signal-info", { "readme.main-tooltip" }, function(player) + return Roles.player_allowed(player, "gui/readme") + end) + :on_click(function(player, _) + local center = player.gui.center + if center[readme.name] then + player.opened = nil + else + player.opened = readme(center) + end + end) --- When a player joins the game for the first time show this gui Event.add(defines.events.on_player_created, function(event) @@ -483,4 +487,4 @@ Event.add(defines.events.on_player_respawned, function(event) if not player.opened then player.gui.center.clear() end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/gui/research.lua b/exp_legacy/module/modules/gui/research.lua index 0e58d21d..4a1aa26d 100644 --- a/exp_legacy/module/modules/gui/research.lua +++ b/exp_legacy/module/modules/gui/research.lua @@ -17,312 +17,307 @@ research.time = {} research.res_queue_enable = false local research_time_format = { - hours=true, - minutes=true, - seconds=true, - time=true, - string=true + hours = true, + minutes = true, + seconds = true, + time = true, + string = true, } local empty_time = format_time(0, { - hours=true, - minutes=true, - seconds=true, - time=true, - string=true, - null=true + hours = true, + minutes = true, + seconds = true, + time = true, + string = true, + null = true, }) local font_color = { - -- positive - [1] = {r = 0.3, g = 1, b = 0.3}, - -- negative - [2] = {r = 1, g = 0.3, b = 0.3} + -- positive + [1] = { r = 0.3, g = 1, b = 0.3 }, + -- negative + [2] = { r = 1, g = 0.3, b = 0.3 }, } local res = { - ['lookup_name'] = {}, - ['disp'] = {} + ["lookup_name"] = {}, + ["disp"] = {}, } do - local res_total = 0 - local i = 1 + local res_total = 0 + local i = 1 - for k, v in pairs(config.milestone) do - research.time[i] = 0 - res['lookup_name'][k] = i - res_total = res_total + v * 60 + for k, v in pairs(config.milestone) do + research.time[i] = 0 + res["lookup_name"][k] = i + res_total = res_total + v * 60 - res['disp'][i] = { - raw_name = k, - target = res_total, - target_disp = format_time(res_total, research_time_format), - } + res["disp"][i] = { + raw_name = k, + target = res_total, + target_disp = format_time(res_total, research_time_format), + } - i = i + 1 - end + i = i + 1 + end end local function research_add_log() - local result_data = {} + local result_data = {} - for i=1, #research.time, 1 do - result_data[res['disp'][i]['raw_name']] = research.time[i] - end + for i = 1, #research.time, 1 do + result_data[res["disp"][i]["raw_name"]] = research.time[i] + end - game.write_file(config.file_name, game.table_to_json(result_data) .. '\n', true, 0) + game.write_file(config.file_name, game.table_to_json(result_data) .. "\n", true, 0) end local function research_res_n(res_) - local res_n = 1 + local res_n = 1 - for k, _ in pairs(res_) do - if research.time[k] == 0 then - res_n = k - 1 - break - end - end + for k, _ in pairs(res_) do + if research.time[k] == 0 then + res_n = k - 1 + break + end + end - if research.time[#res_] and research.time[#res_] > 0 then - if res_n == 1 then - res_n = #res_ - end - end + if research.time[#res_] and research.time[#res_] > 0 then + if res_n == 1 then + res_n = #res_ + end + end - if res_n < 3 then - res_n = 3 + if res_n < 3 then + res_n = 3 + elseif res_n > (#research.time - 5) then + res_n = #research.time - 5 + end - elseif res_n > (#research.time - 5) then - res_n = #research.time - 5 - end - - return res_n + return res_n end local function research_notification(event) if config.inf_res[event.research.name] then - if event.research.name == 'mining-productivity-4' then - if event.research.level == 5 then - -- Add run result to log - research_add_log() - end + if event.research.name == "mining-productivity-4" then + if event.research.level == 5 then + -- Add run result to log + research_add_log() + end - if config.bonus_inventory.enabled then - if (event.research.level - 1) <= math.ceil(config.bonus_inventory.limit / config.bonus_inventory.rate) then - event.research.force[config.bonus_inventory.name] = math.max((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit) - end - end + if config.bonus_inventory.enabled then + if (event.research.level - 1) <= math.ceil(config.bonus_inventory.limit / config.bonus_inventory.rate) then + event.research.force[config.bonus_inventory.name] = math.max((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit) + end + end - if config.pollution_ageing_by_research then - game.map_settings.pollution.ageing = math.min(10, event.research.level / 5) - end - - else - if not (event.by_script) then - game.print{'expcom-res.inf', format_time(game.tick, research_time_format), event.research.name, event.research.level - 1} - end - end - - else + if config.pollution_ageing_by_research then + game.map_settings.pollution.ageing = math.min(10, event.research.level / 5) + end + else + if not (event.by_script) then + game.print{ "expcom-res.inf", format_time(game.tick, research_time_format), event.research.name, event.research.level - 1 } + end + end + else if not (event.by_script) then - game.print{'expcom-res.msg', format_time(game.tick, research_time_format), event.research.name} + game.print{ "expcom-res.msg", format_time(game.tick, research_time_format), event.research.name } end - if config.bonus_inventory.enabled then - if event.research.name == 'mining-productivity-1' or event.research.name == 'mining-productivity-2' or event.research.name == 'mining-productivity-3' then - event.research.force[config.bonus_inventory.name] = event.research.level * config.bonus_inventory.rate - end - end + if config.bonus_inventory.enabled then + if event.research.name == "mining-productivity-1" or event.research.name == "mining-productivity-2" or event.research.name == "mining-productivity-3" then + event.research.force[config.bonus_inventory.name] = event.research.level * config.bonus_inventory.rate + end + end end end local function research_gui_update() - local res_disp = {} - local res_n = research_res_n(res['disp']) + local res_disp = {} + local res_n = research_res_n(res["disp"]) - for i=1, 8, 1 do - res_disp[i] = { - ['name'] = '', - ['target'] = '', - ['attempt'] = '', - ['difference'] = '', - ['difference_color'] = font_color[1] - } + for i = 1, 8, 1 do + res_disp[i] = { + ["name"] = "", + ["target"] = "", + ["attempt"] = "", + ["difference"] = "", + ["difference_color"] = font_color[1], + } - local res_i = res_n + i - 3 + local res_i = res_n + i - 3 - if res['disp'][res_i] then - res_disp[i]['name'] = {'expcom-res.res-name', res['disp'][res_i]['raw_name'], prototypes.technology[res['disp'][res_i]['raw_name']].localised_name} + if res["disp"][res_i] then + res_disp[i]["name"] = { "expcom-res.res-name", res["disp"][res_i]["raw_name"], prototypes.technology[res["disp"][res_i]["raw_name"]].localised_name } - if research.time[res_i] == 0 then - res_disp[i]['target'] = res['disp'][res_i].target_disp - res_disp[i]['attempt'] = empty_time - res_disp[i]['difference'] = empty_time - res_disp[i]['difference_color'] = font_color[1] + if research.time[res_i] == 0 then + res_disp[i]["target"] = res["disp"][res_i].target_disp + res_disp[i]["attempt"] = empty_time + res_disp[i]["difference"] = empty_time + res_disp[i]["difference_color"] = font_color[1] + else + res_disp[i]["target"] = res["disp"][res_i].target_disp + res_disp[i]["attempt"] = format_time(research.time[res_i], research_time_format) - else - res_disp[i]['target'] = res['disp'][res_i].target_disp - res_disp[i]['attempt'] = format_time(research.time[res_i], research_time_format) + if research.time[res_i] < res["disp"][res_i].target then + res_disp[i]["difference"] = "-" .. format_time(res["disp"][res_i].target - research.time[res_i], research_time_format) + res_disp[i]["difference_color"] = font_color[1] + else + res_disp[i]["difference"] = format_time(research.time[res_i] - res["disp"][res_i].target, research_time_format) + res_disp[i]["difference_color"] = font_color[2] + end + end + end + end - if research.time[res_i] < res['disp'][res_i].target then - res_disp[i]['difference'] = '-' .. format_time(res['disp'][res_i].target - research.time[res_i], research_time_format) - res_disp[i]['difference_color'] = font_color[1] - - else - res_disp[i]['difference'] = format_time(research.time[res_i] - res['disp'][res_i].target, research_time_format) - res_disp[i]['difference_color'] = font_color[2] - end - end - end - end - - return res_disp + return res_disp end --- Display label for the clock display -- @element research_gui_clock_display local research_gui_clock = -Gui.element{ - type = 'label', - name = Gui.unique_static_name, - caption = empty_time, - style = 'heading_2_label' -} + Gui.element{ + type = "label", + name = Gui.unique_static_name, + caption = empty_time, + style = "heading_2_label", + } --- A vertical flow containing the clock -- @element research_clock_set local research_clock_set = -Gui.element(function(_, parent, name) - local research_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(research_set, 390, 1, 'disp') + Gui.element(function(_, parent, name) + local research_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(research_set, 390, 1, "disp") - research_gui_clock(disp) + research_gui_clock(disp) - return research_set -end) + return research_set + end) --- Display group -- @element research_data_group local research_data_group = -Gui.element(function(_definition, parent, i) - local name = parent.add{ - type = 'label', - name = 'research_' .. i .. '_name', - caption = '', - style = 'heading_2_label' - } - name.style.width = 180 - name.style.horizontal_align = 'left' + Gui.element(function(_definition, parent, i) + local name = parent.add{ + type = "label", + name = "research_" .. i .. "_name", + caption = "", + style = "heading_2_label", + } + name.style.width = 180 + name.style.horizontal_align = "left" - local target = parent.add{ - type = 'label', - name = 'research_' .. i .. '_target', - caption = '', - style = 'heading_2_label' - } - target.style.width = 70 - target.style.horizontal_align = 'right' + local target = parent.add{ + type = "label", + name = "research_" .. i .. "_target", + caption = "", + style = "heading_2_label", + } + target.style.width = 70 + target.style.horizontal_align = "right" - local attempt = parent.add{ - type = 'label', - name = 'research_' .. i .. '_attempt', - caption = '', - style = 'heading_2_label' - } - attempt.style.width = 70 - attempt.style.horizontal_align = 'right' + local attempt = parent.add{ + type = "label", + name = "research_" .. i .. "_attempt", + caption = "", + style = "heading_2_label", + } + attempt.style.width = 70 + attempt.style.horizontal_align = "right" - local difference = parent.add{ - type = 'label', - name = 'research_' .. i .. '_difference', - caption = '', - style = 'heading_2_label' - } - difference.style.width = 70 - difference.style.horizontal_align = 'right' - difference.style.font_color = font_color[1] -end) + local difference = parent.add{ + type = "label", + name = "research_" .. i .. "_difference", + caption = "", + style = "heading_2_label", + } + difference.style.width = 70 + difference.style.horizontal_align = "right" + difference.style.font_color = font_color[1] + end) --- A vertical flow containing the data -- @element research_data_set local research_data_set = -Gui.element(function(_, parent, name) - local research_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(research_set, 390, 4, 'disp') - local res_disp = research_gui_update() + Gui.element(function(_, parent, name) + local research_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(research_set, 390, 4, "disp") + local res_disp = research_gui_update() - research_data_group(disp, 0) - disp['research_0_name'].caption = {'expcom-res.name'} - disp['research_0_target'].caption = {'expcom-res.target'} - disp['research_0_attempt'].caption = {'expcom-res.attempt'} - disp['research_0_difference'].caption = {'expcom-res.difference'} + research_data_group(disp, 0) + disp["research_0_name"].caption = { "expcom-res.name" } + disp["research_0_target"].caption = { "expcom-res.target" } + disp["research_0_attempt"].caption = { "expcom-res.attempt" } + disp["research_0_difference"].caption = { "expcom-res.difference" } - for i=1, 8, 1 do - research_data_group(disp, i) + for i = 1, 8, 1 do + research_data_group(disp, i) - local research_name_i = 'research_' .. i + local research_name_i = "research_" .. i - disp[research_name_i .. '_name'].caption = res_disp[i]['name'] - disp[research_name_i .. '_target'].caption = res_disp[i]['target'] - disp[research_name_i .. '_attempt'].caption = res_disp[i]['attempt'] - disp[research_name_i .. '_difference'].caption = res_disp[i]['difference'] - disp[research_name_i .. '_difference'].style.font_color = res_disp[i]['difference_color'] - end + disp[research_name_i .. "_name"].caption = res_disp[i]["name"] + disp[research_name_i .. "_target"].caption = res_disp[i]["target"] + disp[research_name_i .. "_attempt"].caption = res_disp[i]["attempt"] + disp[research_name_i .. "_difference"].caption = res_disp[i]["difference"] + disp[research_name_i .. "_difference"].style.font_color = res_disp[i]["difference_color"] + end - return research_set -end) + return research_set + end) local research_container = -Gui.element(function(definition, parent) - local container = Gui.container(parent, definition.name, 390) + Gui.element(function(definition, parent) + local container = Gui.container(parent, definition.name, 390) - research_clock_set(container, 'research_st_1') - research_data_set(container, 'research_st_2') + research_clock_set(container, "research_st_1") + research_data_set(container, "research_st_2") - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() -Gui.left_toolbar_button('item/space-science-pack', {'expcom-res.main-tooltip'}, research_container, function(player) - return Roles.player_allowed(player, 'gui/research') +Gui.left_toolbar_button("item/space-science-pack", { "expcom-res.main-tooltip" }, research_container, function(player) + return Roles.player_allowed(player, "gui/research") end) Event.add(defines.events.on_research_finished, function(event) - research_notification(event) + research_notification(event) - if res['lookup_name'][event.research.name] == nil then - return - end + if res["lookup_name"][event.research.name] == nil then + return + end - local n_i = res['lookup_name'][event.research.name] - research.time[n_i] = game.tick + local n_i = res["lookup_name"][event.research.name] + research.time[n_i] = game.tick - local res_disp = research_gui_update() + local res_disp = research_gui_update() - for _, player in pairs(game.connected_players) do - local frame = Gui.get_left_element(player, research_container) - local disp = frame.container['research_st_2'].disp.table + for _, player in pairs(game.connected_players) do + local frame = Gui.get_left_element(player, research_container) + local disp = frame.container["research_st_2"].disp.table - for i=1, 8, 1 do - local research_name_i = 'research_' .. i + for i = 1, 8, 1 do + local research_name_i = "research_" .. i - disp[research_name_i .. '_name'].caption = res_disp[i]['name'] - disp[research_name_i .. '_target'].caption = res_disp[i]['target'] - disp[research_name_i .. '_attempt'].caption = res_disp[i]['attempt'] - disp[research_name_i .. '_difference'].caption = res_disp[i]['difference'] - disp[research_name_i .. '_difference'].style.font_color = res_disp[i]['difference_color'] - end - end + disp[research_name_i .. "_name"].caption = res_disp[i]["name"] + disp[research_name_i .. "_target"].caption = res_disp[i]["target"] + disp[research_name_i .. "_attempt"].caption = res_disp[i]["attempt"] + disp[research_name_i .. "_difference"].caption = res_disp[i]["difference"] + disp[research_name_i .. "_difference"].style.font_color = res_disp[i]["difference_color"] + end + end end) Event.on_nth_tick(60, function() - local current_time = format_time(game.tick, research_time_format) + local current_time = format_time(game.tick, research_time_format) - for _, player in pairs(game.connected_players) do + for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, research_container) - local disp = frame.container['research_st_1'].disp.table - disp[research_gui_clock.name].caption = current_time + local disp = frame.container["research_st_1"].disp.table + disp[research_gui_clock.name].caption = current_time end end) diff --git a/exp_legacy/module/modules/gui/rocket-info.lua b/exp_legacy/module/modules/gui/rocket-info.lua index 96bd5cfb..c16951d3 100644 --- a/exp_legacy/module/modules/gui/rocket-info.lua +++ b/exp_legacy/module/modules/gui/rocket-info.lua @@ -13,24 +13,24 @@ local Rockets = require("modules.exp_legacy.modules.control.rockets") --- @dep m local format_time = _C.format_time --- @dep expcore.common local time_formats = { - caption = function(value) return format_time(value, {minutes=true, seconds=true}) end, - caption_hours = function(value) return format_time(value) end, - tooltip = function(value) return format_time(value, {minutes=true, seconds=true, long=true}) end, - tooltip_hours = function(value) return format_time(value, {hours=true, minutes=true, seconds=true, long=true}) end + caption = function(value) return format_time(value, { minutes = true, seconds = true }) end, + caption_hours = function(value) return format_time(value) end, + tooltip = function(value) return format_time(value, { minutes = true, seconds = true, long = true }) end, + tooltip_hours = function(value) return format_time(value, { hours = true, minutes = true, seconds = true, long = true }) end, } --- Check if a player is allowed to use certain interactions local function check_player_permissions(player, action) - if not config.progress['allow_'..action] then + if not config.progress["allow_" .. action] then return false end - if config.progress[action..'_admins_only'] and not player.admin then + if config.progress[action .. "_admins_only"] and not player.admin then return false end - if config.progress[action..'_role_permission'] - and not Roles.player_allowed(player, config.progress[action..'_role_permission']) then + if config.progress[action .. "_role_permission"] + and not Roles.player_allowed(player, config.progress[action .. "_role_permission"]) then return false end @@ -40,542 +40,543 @@ end --- Button to toggle the auto launch on a rocket silo -- @element toggle_launch local toggle_launch = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/play', - tooltip = {'rocket-info.toggle-rocket-tooltip'}, - name = Gui.unique_static_name -} -:style(Gui.sprite_style(16)) -:on_click(function(_, element, _) - local rocket_silo_name = element.parent.name:sub(8) - local rocket_silo = Rockets.get_silo_entity(rocket_silo_name) - if rocket_silo.auto_launch then - element.sprite = 'utility/play' - element.tooltip = {'rocket-info.toggle-rocket-tooltip'} - rocket_silo.auto_launch = false - else - element.sprite = 'utility/stop' - element.tooltip = {'rocket-info.toggle-rocket-tooltip-disabled'} - rocket_silo.auto_launch = true - end -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/play", + tooltip = { "rocket-info.toggle-rocket-tooltip" }, + name = Gui.unique_static_name, + } + :style(Gui.sprite_style(16)) + :on_click(function(_, element, _) + local rocket_silo_name = element.parent.name:sub(8) + local rocket_silo = Rockets.get_silo_entity(rocket_silo_name) + if rocket_silo.auto_launch then + element.sprite = "utility/play" + element.tooltip = { "rocket-info.toggle-rocket-tooltip" } + rocket_silo.auto_launch = false + else + element.sprite = "utility/stop" + element.tooltip = { "rocket-info.toggle-rocket-tooltip-disabled" } + rocket_silo.auto_launch = true + end + end) --- Button to remotely launch a rocket from a silo -- @element launch_rocket local launch_rocket = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/center', - tooltip = {'rocket-info.launch-tooltip'}, - name = Gui.unique_static_name -} -:style(Gui.sprite_style(16, -1)) -:on_click(function(player, element, _) - local rocket_silo_name = element.parent.name:sub(8) - local silo_data = Rockets.get_silo_data_by_name(rocket_silo_name) - if silo_data.entity.launch_rocket() then - element.enabled = false - else - player.print({'rocket-info.launch-failed'}, Colors.orange_red) - end -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/center", + tooltip = { "rocket-info.launch-tooltip" }, + name = Gui.unique_static_name, + } + :style(Gui.sprite_style(16, -1)) + :on_click(function(player, element, _) + local rocket_silo_name = element.parent.name:sub(8) + local silo_data = Rockets.get_silo_data_by_name(rocket_silo_name) + if silo_data.entity.launch_rocket() then + element.enabled = false + else + player.print({ "rocket-info.launch-failed" }, Colors.orange_red) + end + end) --- XY cords that allow zoom to map when pressed -- @element silo_cords local silo_cords = -Gui.element(function(definition, parent, silo_data) - local silo_name = silo_data.silo_name - local pos = silo_data.position - local tooltip = config.progress.allow_zoom_to_map and {'rocket-info.progress-label-tooltip'} or nil + Gui.element(function(definition, parent, silo_data) + local silo_name = silo_data.silo_name + local pos = silo_data.position + local tooltip = config.progress.allow_zoom_to_map and { "rocket-info.progress-label-tooltip" } or nil - -- Add the x cord flow - local flow_x = parent.add{ - type ='flow', - name = 'label-x-'..silo_name, - caption = silo_name - } - flow_x.style.padding = {0, 2,0, 1} + -- Add the x cord flow + local flow_x = parent.add{ + type = "flow", + name = "label-x-" .. silo_name, + caption = silo_name, + } + flow_x.style.padding = { 0, 2, 0, 1 } - -- Add the x cord label - local label_x = flow_x.add{ - type = 'label', - caption = {'rocket-info.progress-x-pos', pos.x}, - tooltip = tooltip - } + -- Add the x cord label + local label_x = flow_x.add{ + type = "label", + caption = { "rocket-info.progress-x-pos", pos.x }, + tooltip = tooltip, + } - -- Add the y cord flow - local flow_y = parent.add{ - type ='flow', - name = 'label-y-'..silo_name, - caption = silo_name - } - flow_y.style.padding = {0, 2,0, 1} + -- Add the y cord flow + local flow_y = parent.add{ + type = "flow", + name = "label-y-" .. silo_name, + caption = silo_name, + } + flow_y.style.padding = { 0, 2, 0, 1 } - -- Add the y cord label - local label_y = flow_y.add{ - type = 'label', - caption = {'rocket-info.progress-y-pos', pos.y}, - tooltip = tooltip - } + -- Add the y cord label + local label_y = flow_y.add{ + type = "label", + caption = { "rocket-info.progress-y-pos", pos.y }, + tooltip = tooltip, + } - if config.progress.allow_zoom_to_map then - definition:triggers_events(label_x) - definition:triggers_events(label_y) - end -end) -:on_click(function(player, element, _) - local rocket_silo_name = element.parent.caption - local rocket_silo = Rockets.get_silo_entity(rocket_silo_name) - player.zoom_to_world(rocket_silo.position, 2) -end) + if config.progress.allow_zoom_to_map then + definition:triggers_events(label_x) + definition:triggers_events(label_y) + end + end) + :on_click(function(player, element, _) + local rocket_silo_name = element.parent.caption + local rocket_silo = Rockets.get_silo_entity(rocket_silo_name) + player.zoom_to_world(rocket_silo.position, 2) + end) --- Base element for each rocket in the progress list -- @element rocket_entry local rocket_entry = -Gui.element(function(_, parent, silo_data) - local silo_name = silo_data.silo_name - local player = Gui.get_player_from_element(parent) + Gui.element(function(_, parent, silo_data) + local silo_name = silo_data.silo_name + local player = Gui.get_player_from_element(parent) - -- Add the toggle auto launch if the player is allowed it - if check_player_permissions(player, 'toggle_active') then - local flow = parent.add{ type = 'flow', name = 'toggle-'..silo_name} - local button = toggle_launch(flow) - button.tooltip = silo_data.toggle_tooltip - button.sprite = silo_data.toggle_sprite - end + -- Add the toggle auto launch if the player is allowed it + if check_player_permissions(player, "toggle_active") then + local flow = parent.add{ type = "flow", name = "toggle-" .. silo_name } + local button = toggle_launch(flow) + button.tooltip = silo_data.toggle_tooltip + button.sprite = silo_data.toggle_sprite + end - -- Add the remote launch if the player is allowed it - if check_player_permissions(player, 'remote_launch') then - local flow = parent.add{ type = 'flow', name = 'launch-'..silo_name} - local button = launch_rocket(flow) - button.enabled = silo_data.allow_launch - end + -- Add the remote launch if the player is allowed it + if check_player_permissions(player, "remote_launch") then + local flow = parent.add{ type = "flow", name = "launch-" .. silo_name } + local button = launch_rocket(flow) + button.enabled = silo_data.allow_launch + end - -- Draw the silo cords element - silo_cords(parent, silo_data) + -- Draw the silo cords element + silo_cords(parent, silo_data) - -- Add a progress label - local alignment = Gui.alignment(parent, silo_name) - local element = - alignment.add{ - type = 'label', - name = 'label', - caption = silo_data.progress_caption, - tooltip = silo_data.progress_tooltip - } + -- Add a progress label + local alignment = Gui.alignment(parent, silo_name) + local element = + alignment.add{ + type = "label", + name = "label", + caption = silo_data.progress_caption, + tooltip = silo_data.progress_tooltip, + } - -- Return the progress label - return element -end) + -- Return the progress label + return element + end) --- Data label which contains a name and a value label pair -- @element data_label local data_label = -Gui.element(function(_, parent, label_data) - local data_name = label_data.name - local data_subname = label_data.subname - local data_fullname = data_subname and data_name..data_subname or data_name + Gui.element(function(_, parent, label_data) + local data_name = label_data.name + local data_subname = label_data.subname + local data_fullname = data_subname and data_name .. data_subname or data_name - -- Add the name label - local name_label = parent.add{ - type = 'label', - name = data_fullname..'-label', - caption = {'rocket-info.data-caption-'..data_name, data_subname}, - tooltip = {'rocket-info.data-tooltip-'..data_name, data_subname} - } - name_label.style.padding = {0, 2} + -- Add the name label + local name_label = parent.add{ + type = "label", + name = data_fullname .. "-label", + caption = { "rocket-info.data-caption-" .. data_name, data_subname }, + tooltip = { "rocket-info.data-tooltip-" .. data_name, data_subname }, + } + name_label.style.padding = { 0, 2 } - --- Right aligned label to store the data - local alignment = Gui.alignment(parent, data_fullname) - local element = - alignment.add{ - type = 'label', - name = 'label', - caption = label_data.value, - tooltip = label_data.tooltip - } - element.style.padding = {0, 2} + --- Right aligned label to store the data + local alignment = Gui.alignment(parent, data_fullname) + local element = + alignment.add{ + type = "label", + name = "label", + caption = label_data.value, + tooltip = label_data.tooltip, + } + element.style.padding = { 0, 2 } - return element -end) + return element + end) -- Used to update the captions and tooltips on the data labels local function update_data_labels(parent, data_label_data) - for _, label_data in ipairs(data_label_data) do - local data_name = label_data.subname and label_data.name..label_data.subname or label_data.name - if not parent[data_name] then - data_label(parent, label_data) - else - local data_label_element = parent[data_name].label - data_label_element.tooltip = label_data.tooltip - data_label_element.caption = label_data.value - end - end + for _, label_data in ipairs(data_label_data) do + local data_name = label_data.subname and label_data.name .. label_data.subname or label_data.name + if not parent[data_name] then + data_label(parent, label_data) + else + local data_label_element = parent[data_name].label + data_label_element.tooltip = label_data.tooltip + data_label_element.caption = label_data.value + end + end end local function get_progress_data(force_name) - local force_silos = Rockets.get_silos(force_name) - local progress_data = {} + local force_silos = Rockets.get_silos(force_name) + local progress_data = {} - for _, silo_data in pairs(force_silos) do - local rocket_silo = silo_data.entity - if not rocket_silo or not rocket_silo.valid then - -- Remove from list if not valid - force_silos[silo_data.name] = nil - table.insert(progress_data, { - silo_name = silo_data.name, - remove = true - }) + for _, silo_data in pairs(force_silos) do + local rocket_silo = silo_data.entity + if not rocket_silo or not rocket_silo.valid then + -- Remove from list if not valid + force_silos[silo_data.name] = nil + table.insert(progress_data, { + silo_name = silo_data.name, + remove = true, + }) + else + -- Get the progress caption and tooltip + local progress_color = Colors.white + local progress_caption = { "rocket-info.progress-caption", rocket_silo.rocket_parts } + local progress_tooltip = { "rocket-info.progress-tooltip", silo_data.launched or 0 } + local status = rocket_silo.status == defines.entity_status.waiting_to_launch_rocket + if status and silo_data.awaiting_reset then + progress_caption = { "rocket-info.progress-launched" } + progress_color = Colors.green + elseif status then + progress_caption = { "rocket-info.progress-caption", 100 } + progress_color = Colors.cyan + else + silo_data.awaiting_reset = false + end - else - -- Get the progress caption and tooltip - local progress_color = Colors.white - local progress_caption = {'rocket-info.progress-caption', rocket_silo.rocket_parts} - local progress_tooltip = {'rocket-info.progress-tooltip', silo_data.launched or 0} - local status = rocket_silo.status == defines.entity_status.waiting_to_launch_rocket - if status and silo_data.awaiting_reset then - progress_caption = {'rocket-info.progress-launched'} - progress_color = Colors.green - elseif status then - progress_caption = {'rocket-info.progress-caption', 100} - progress_color = Colors.cyan - else - silo_data.awaiting_reset = false - end + -- Get the toggle button data + local toggle_tooltip = { "rocket-info.toggle-rocket-tooltip-disabled" } + local toggle_sprite = "utility/play" + if rocket_silo.auto_launch then + toggle_tooltip = { "rocket-info.toggle-rocket-tooltip" } + toggle_sprite = "utility/stop" + end - -- Get the toggle button data - local toggle_tooltip = {'rocket-info.toggle-rocket-tooltip-disabled'} - local toggle_sprite = 'utility/play' - if rocket_silo.auto_launch then - toggle_tooltip = {'rocket-info.toggle-rocket-tooltip'} - toggle_sprite = 'utility/stop' - end + -- Insert the gui data + table.insert(progress_data, { + silo_name = silo_data.name, + position = rocket_silo.position, + allow_launch = not silo_data.awaiting_reset and status or false, + progress_color = progress_color, + progress_caption = progress_caption, + progress_tooltip = progress_tooltip, + toggle_tooltip = toggle_tooltip, + toggle_sprite = toggle_sprite, + }) + end + end - -- Insert the gui data - table.insert(progress_data, { - silo_name = silo_data.name, - position = rocket_silo.position, - allow_launch = not silo_data.awaiting_reset and status or false, - progress_color = progress_color, - progress_caption = progress_caption, - progress_tooltip = progress_tooltip, - toggle_tooltip = toggle_tooltip, - toggle_sprite = toggle_sprite - }) - end - end - - return progress_data + return progress_data end --- Update the build progress section local function update_build_progress(parent, progress_data) - local show_message = true - for _, silo_data in ipairs(progress_data) do - parent.parent.no_silos.visible = false - parent.visible = true - local silo_name = silo_data.silo_name - local progress_label = parent[silo_name] - if silo_data.remove then - -- Remove the rocket from the list - Gui.destroy_if_valid(parent['toggle-'..silo_name]) - Gui.destroy_if_valid(parent['launch-'..silo_name]) - Gui.destroy_if_valid(parent['label-x-'..silo_name]) - Gui.destroy_if_valid(parent['label-y-'..silo_name]) - Gui.destroy_if_valid(parent[silo_name]) + local show_message = true + for _, silo_data in ipairs(progress_data) do + parent.parent.no_silos.visible = false + parent.visible = true + local silo_name = silo_data.silo_name + local progress_label = parent[silo_name] + if silo_data.remove then + -- Remove the rocket from the list + Gui.destroy_if_valid(parent["toggle-" .. silo_name]) + Gui.destroy_if_valid(parent["launch-" .. silo_name]) + Gui.destroy_if_valid(parent["label-x-" .. silo_name]) + Gui.destroy_if_valid(parent["label-y-" .. silo_name]) + Gui.destroy_if_valid(parent[silo_name]) + elseif not progress_label then + -- Add the rocket to the list + show_message = false + rocket_entry(parent, silo_data) + else + show_message = false + -- Update the existing labels + progress_label = progress_label.label + progress_label.caption = silo_data.progress_caption + progress_label.tooltip = silo_data.progress_tooltip + progress_label.style.font_color = silo_data.progress_color - elseif not progress_label then - -- Add the rocket to the list - show_message = false - rocket_entry(parent, silo_data) + -- Update the toggle button + local toggle_button = parent["toggle-" .. silo_name] + if toggle_button then + toggle_button = toggle_button[toggle_launch.name] + toggle_button.tooltip = silo_data.toggle_tooltip + toggle_button.sprite = silo_data.toggle_sprite + end - else - show_message = false - -- Update the existing labels - progress_label = progress_label.label - progress_label.caption = silo_data.progress_caption - progress_label.tooltip = silo_data.progress_tooltip - progress_label.style.font_color = silo_data.progress_color + -- Update the launch button + local launch_button = parent["launch-" .. silo_name] + if launch_button then + launch_button = launch_button[launch_rocket.name] + launch_button.enabled = silo_data.allow_launch + end + end + end - -- Update the toggle button - local toggle_button = parent['toggle-'..silo_name] - if toggle_button then - toggle_button = toggle_button[toggle_launch.name] - toggle_button.tooltip = silo_data.toggle_tooltip - toggle_button.sprite = silo_data.toggle_sprite - end - - -- Update the launch button - local launch_button = parent['launch-'..silo_name] - if launch_button then - launch_button = launch_button[launch_rocket.name] - launch_button.enabled = silo_data.allow_launch - end - end - end - if show_message then parent.parent.no_silos.visible = true parent.visible = false end + if show_message then + parent.parent.no_silos.visible = true + parent.visible = false + end end --- Gets the label data for all the different stats local function get_stats_data(force_name) local force_rockets = Rockets.get_rocket_count(force_name) - local stats = Rockets.get_stats(force_name) - local stats_data = {} + local stats = Rockets.get_stats(force_name) + local stats_data = {} - -- Format the first launch data - if config.stats.show_first_rocket then - local value = stats.first_launch or 0 - table.insert(stats_data, { - name = 'first-launch', - value = time_formats.caption_hours(value), - tooltip = time_formats.tooltip_hours(value) - }) - end - - -- Format the last launch data - if config.stats.show_last_rocket then - local value = stats.last_launch or 0 - table.insert(stats_data, { - name = 'last-launch', - value = time_formats.caption_hours(value), - tooltip = time_formats.tooltip_hours(value) - }) + -- Format the first launch data + if config.stats.show_first_rocket then + local value = stats.first_launch or 0 + table.insert(stats_data, { + name = "first-launch", + value = time_formats.caption_hours(value), + tooltip = time_formats.tooltip_hours(value), + }) end - -- Format fastest launch data - if config.stats.show_fastest_rocket then - local value = stats.fastest_launch or 0 - table.insert(stats_data, { - name = 'fastest-launch', - value = time_formats.caption_hours(value), - tooltip = time_formats.tooltip_hours(value) - }) + -- Format the last launch data + if config.stats.show_last_rocket then + local value = stats.last_launch or 0 + table.insert(stats_data, { + name = "last-launch", + value = time_formats.caption_hours(value), + tooltip = time_formats.tooltip_hours(value), + }) end - -- Format total rocket data + -- Format fastest launch data + if config.stats.show_fastest_rocket then + local value = stats.fastest_launch or 0 + table.insert(stats_data, { + name = "fastest-launch", + value = time_formats.caption_hours(value), + tooltip = time_formats.tooltip_hours(value), + }) + end + + -- Format total rocket data if config.stats.show_total_rockets then local total_rockets = Rockets.get_game_rocket_count() total_rockets = total_rockets == 0 and 1 or total_rockets - local percentage = math.round(force_rockets/total_rockets, 3)*100 - table.insert(stats_data, { - name = 'total-rockets', - value = force_rockets, - tooltip = {'rocket-info.value-tooltip-total-rockets', percentage} - }) + local percentage = math.round(force_rockets / total_rockets, 3) * 100 + table.insert(stats_data, { + name = "total-rockets", + value = force_rockets, + tooltip = { "rocket-info.value-tooltip-total-rockets", percentage }, + }) end - -- Format game avg data + -- Format game avg data if config.stats.show_game_avg then - local avg = force_rockets > 0 and math.floor(game.tick/force_rockets) or 0 - table.insert(stats_data, { - name = 'avg-launch', - value = time_formats.caption(avg), - tooltip = time_formats.tooltip(avg) - }) + local avg = force_rockets > 0 and math.floor(game.tick / force_rockets) or 0 + table.insert(stats_data, { + name = "avg-launch", + value = time_formats.caption(avg), + tooltip = time_formats.tooltip(avg), + }) end - -- Format rolling avg data + -- Format rolling avg data for _, avg_over in pairs(config.stats.rolling_avg) do - local avg = Rockets.get_rolling_average(force_name, avg_over) - table.insert(stats_data, { - name = 'avg-launch-n', - subname = avg_over, - value = time_formats.caption(avg), - tooltip = time_formats.tooltip(avg) - }) - end + local avg = Rockets.get_rolling_average(force_name, avg_over) + table.insert(stats_data, { + name = "avg-launch-n", + subname = avg_over, + value = time_formats.caption(avg), + tooltip = time_formats.tooltip(avg), + }) + end - -- Return formated data - return stats_data + -- Return formated data + return stats_data end --- Gets the label data for the milestones local function get_milestone_data(force_name) - local force_rockets = Rockets.get_rocket_count(force_name) - local milestone_data = {} + local force_rockets = Rockets.get_rocket_count(force_name) + local milestone_data = {} - for _, milestone in ipairs(config.milestones) do + for _, milestone in ipairs(config.milestones) do if milestone <= force_rockets then - local time = Rockets.get_rocket_time(force_name, milestone) - table.insert(milestone_data, { - name = 'milestone-n', - subname = milestone, - value = time_formats.caption_hours(time), - tooltip = time_formats.tooltip_hours(time) - }) - else - table.insert(milestone_data, { - name = 'milestone-n', - subname = milestone, - value = {'rocket-info.data-caption-milestone-next'}, - tooltip = {'rocket-info.data-tooltip-milestone-next'} - }) + local time = Rockets.get_rocket_time(force_name, milestone) + table.insert(milestone_data, { + name = "milestone-n", + subname = milestone, + value = time_formats.caption_hours(time), + tooltip = time_formats.tooltip_hours(time), + }) + else + table.insert(milestone_data, { + name = "milestone-n", + subname = milestone, + value = { "rocket-info.data-caption-milestone-next" }, + tooltip = { "rocket-info.data-tooltip-milestone-next" }, + }) break end - end + end - return milestone_data + return milestone_data end -- Button to toggle a section dropdown -- @element toggle_section local toggle_section = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/expand', - hovered_sprite = 'utility/expand', - tooltip = {'rocket-info.toggle-section-tooltip'}, - style = "frame_action_button", - name = Gui.unique_static_name -} -:style(Gui.sprite_style(20)) -:on_click(function(_, element, _) - local header_flow = element.parent - local flow_name = header_flow.caption - local flow = header_flow.parent.parent[flow_name] - if Gui.toggle_visible_state(flow) then - element.sprite = 'utility/collapse' - element.tooltip = {'rocket-info.toggle-section-collapse-tooltip'} - else - element.sprite = 'utility/expand' - element.tooltip = {'rocket-info.toggle-section-tooltip'} - end -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/expand", + hovered_sprite = "utility/expand", + tooltip = { "rocket-info.toggle-section-tooltip" }, + style = "frame_action_button", + name = Gui.unique_static_name, + } + :style(Gui.sprite_style(20)) + :on_click(function(_, element, _) + local header_flow = element.parent + local flow_name = header_flow.caption + local flow = header_flow.parent.parent[flow_name] + if Gui.toggle_visible_state(flow) then + element.sprite = "utility/collapse" + element.tooltip = { "rocket-info.toggle-section-collapse-tooltip" } + else + element.sprite = "utility/expand" + element.tooltip = { "rocket-info.toggle-section-tooltip" } + end + end) -- Draw a section header and main scroll -- @element rocket_list_container local section = -Gui.element(function(definition, parent, section_name, table_size) - -- Draw the header for the section - local header = Gui.header( - parent, - {'rocket-info.section-caption-'..section_name}, - {'rocket-info.section-tooltip-'..section_name}, - true, - section_name..'-header' - ) - definition:triggers_events(header.parent.header_label) + Gui.element(function(definition, parent, section_name, table_size) + -- Draw the header for the section + local header = Gui.header( + parent, + { "rocket-info.section-caption-" .. section_name }, + { "rocket-info.section-tooltip-" .. section_name }, + true, + section_name .. "-header" + ) + definition:triggers_events(header.parent.header_label) - -- Right aligned button to toggle the section - header.caption = section_name - toggle_section(header) + -- Right aligned button to toggle the section + header.caption = section_name + toggle_section(header) - -- Table used to store the data - local scroll_table = Gui.scroll_table(parent, 215, table_size, section_name) - scroll_table.parent.visible = false + -- Table used to store the data + local scroll_table = Gui.scroll_table(parent, 215, table_size, section_name) + scroll_table.parent.visible = false - -- Return the flow table - return definition:no_events(scroll_table) -end) -:on_click(function(_, element, event) - event.element = element.parent.alignment[toggle_section.name] - toggle_section:raise_event(event) -end) + -- Return the flow table + return definition:no_events(scroll_table) + end) + :on_click(function(_, element, event) + event.element = element.parent.alignment[toggle_section.name] + toggle_section:raise_event(event) + end) --- Main gui container for the left flow -- @element rocket_list_container local rocket_list_container = -Gui.element(function(definition, parent) - -- Draw the internal container - local container = Gui.container(parent, definition.name, 200) + Gui.element(function(definition, parent) + -- Draw the internal container + local container = Gui.container(parent, definition.name, 200) - -- Set the container style - local style = container.style - style.padding = 0 + -- Set the container style + local style = container.style + style.padding = 0 - local player = Gui.get_player_from_element(parent) - local force_name = player.force.name - -- Draw stats section - if config.stats.show_stats then - update_data_labels(section(container, 'stats', 2), get_stats_data(force_name)) - end + local player = Gui.get_player_from_element(parent) + local force_name = player.force.name + -- Draw stats section + if config.stats.show_stats then + update_data_labels(section(container, "stats", 2), get_stats_data(force_name)) + end - -- Draw milestones section - if config.milestones.show_milestones then - update_data_labels(section(container, 'milestones', 2), get_milestone_data(force_name)) - end + -- Draw milestones section + if config.milestones.show_milestones then + update_data_labels(section(container, "milestones", 2), get_milestone_data(force_name)) + end - -- Draw build progress list - if config.progress.show_progress then - local col_count = 3 - if check_player_permissions(player, 'remote_launch') then col_count = col_count+1 end - if check_player_permissions(player, 'toggle_active') then col_count = col_count+1 end - local progress = section(container, 'progress', col_count) - -- Label used when there are no active silos - local no_silos = progress.parent.add{ - type = 'label', - name = 'no_silos', - caption = {'rocket-info.progress-no-silos'} - } - no_silos.style.padding = {1, 2} - update_build_progress(progress, get_progress_data(force_name)) - end + -- Draw build progress list + if config.progress.show_progress then + local col_count = 3 + if check_player_permissions(player, "remote_launch") then col_count = col_count + 1 end + if check_player_permissions(player, "toggle_active") then col_count = col_count + 1 end + local progress = section(container, "progress", col_count) + -- Label used when there are no active silos + local no_silos = progress.parent.add{ + type = "label", + name = "no_silos", + caption = { "rocket-info.progress-no-silos" }, + } + no_silos.style.padding = { 1, 2 } + update_build_progress(progress, get_progress_data(force_name)) + end - -- Return the exteral container - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow(function(player) - return player.force.rockets_launched > 0 and Roles.player_allowed(player, 'gui/rocket-info') -end) + -- Return the exteral container + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow(function(player) + return player.force.rockets_launched > 0 and Roles.player_allowed(player, "gui/rocket-info") + end) --- Button on the top flow used to toggle the container -- @element toggle_rocket_info -Gui.left_toolbar_button('item/rocket-silo', {'rocket-info.main-tooltip'}, rocket_list_container, function(player) - return Roles.player_allowed(player, 'gui/rocket-info') +Gui.left_toolbar_button("item/rocket-silo", { "rocket-info.main-tooltip" }, rocket_list_container, function(player) + return Roles.player_allowed(player, "gui/rocket-info") end) --- Update the gui for all players on a force local function update_rocket_gui_all(force_name) - local stats = get_stats_data(force_name) - local milestones = get_milestone_data(force_name) - local progress = get_progress_data(force_name) - for _, player in pairs(game.forces[force_name].players) do + local stats = get_stats_data(force_name) + local milestones = get_milestone_data(force_name) + local progress = get_progress_data(force_name) + for _, player in pairs(game.forces[force_name].players) do local frame = Gui.get_left_element(player, rocket_list_container) - local container = frame.container - update_data_labels(container.stats.table, stats) - update_data_labels(container.milestones.table, milestones) - update_build_progress(container.progress.table, progress) - end + local container = frame.container + update_data_labels(container.stats.table, stats) + update_data_labels(container.milestones.table, milestones) + update_build_progress(container.progress.table, progress) + end end --- Event used to update the stats when a rocket is launched Event.add(defines.events.on_rocket_launched, function(event) local force = event.rocket_silo.force - update_rocket_gui_all(force.name) + update_rocket_gui_all(force.name) end) --- Update only the progress gui for a force local function update_rocket_gui_progress(force_name) - local progress = get_progress_data(force_name) - for _, player in pairs(game.forces[force_name].players) do + local progress = get_progress_data(force_name) + for _, player in pairs(game.forces[force_name].players) do local frame = Gui.get_left_element(player, rocket_list_container) - local container = frame.container - update_build_progress(container.progress.table, progress) - end + local container = frame.container + update_build_progress(container.progress.table, progress) + end end --- Event used to set a rocket silo to be awaiting reset Event.add(defines.events.on_rocket_launch_ordered, function(event) - local silo = event.rocket_silo - local silo_data = Rockets.get_silo_data(silo) - silo_data.awaiting_reset = true - update_rocket_gui_progress(silo.force.name) + local silo = event.rocket_silo + local silo_data = Rockets.get_silo_data(silo) + silo_data.awaiting_reset = true + update_rocket_gui_progress(silo.force.name) end) Event.on_nth_tick(150, function() - for _, force in pairs(game.forces) do - if #Rockets.get_silos(force.name) > 0 then - update_rocket_gui_progress(force.name) - end - end + for _, force in pairs(game.forces) do + if #Rockets.get_silos(force.name) > 0 then + update_rocket_gui_progress(force.name) + end + end end) --- Adds a silo to the list when it is built local function on_built(event) local entity = event.created_entity - if entity.valid and entity.name == 'rocket-silo' then + if entity.valid and entity.name == "rocket-silo" then update_rocket_gui_progress(entity.force.name) end end @@ -585,25 +586,25 @@ Event.add(defines.events.on_robot_built_entity, on_built) --- Redraw the progress section on role change local function role_update_event(event) - if not config.progress.show_progress then return end - local player = game.players[event.player_index] - local container = Gui.get_left_element(player, rocket_list_container).container - local progress_scroll = container.progress - Gui.destroy_if_valid(progress_scroll.table) + if not config.progress.show_progress then return end + local player = game.players[event.player_index] + local container = Gui.get_left_element(player, rocket_list_container).container + local progress_scroll = container.progress + Gui.destroy_if_valid(progress_scroll.table) - local col_count = 3 - if check_player_permissions(player, 'remote_launch') then col_count = col_count+1 end - if check_player_permissions(player, 'toggle_active') then col_count = col_count+1 end - local progress = progress_scroll.add{ - type = 'table', - name = 'table', - column_count = col_count + local col_count = 3 + if check_player_permissions(player, "remote_launch") then col_count = col_count + 1 end + if check_player_permissions(player, "toggle_active") then col_count = col_count + 1 end + local progress = progress_scroll.add{ + type = "table", + name = "table", + column_count = col_count, } - update_build_progress(progress, get_progress_data(player.force.name)) + update_build_progress(progress, get_progress_data(player.force.name)) end Event.add(Roles.events.on_role_assigned, role_update_event) Event.add(Roles.events.on_role_unassigned, role_update_event) -return rocket_list_container \ No newline at end of file +return rocket_list_container diff --git a/exp_legacy/module/modules/gui/science-info.lua b/exp_legacy/module/modules/gui/science-info.lua index be456b6a..58f02a47 100644 --- a/exp_legacy/module/modules/gui/science-info.lua +++ b/exp_legacy/module/modules/gui/science-info.lua @@ -11,49 +11,49 @@ local config = require("modules.exp_legacy.config.gui.science") --- @dep config. local Production = require("modules.exp_legacy.modules.control.production") --- @dep modules.control.production local format_time = _C.format_time --- @dep expcore.common -local null_time_short = {'science-info.eta-time', format_time(0, {hours=true, minutes=true, seconds=true, time=true, null=true})} -local null_time_long = format_time(0, {hours=true, minutes=true, seconds=true, long=true, null=true}) +local null_time_short = { "science-info.eta-time", format_time(0, { hours = true, minutes = true, seconds = true, time = true, null = true }) } +local null_time_long = format_time(0, { hours = true, minutes = true, seconds = true, long = true, null = true }) --- Data label that contains the value and the surfix -- @element production_label local production_label = -Gui.element(function(_, parent, production_label_data) - local name = production_label_data.name - local tooltip = production_label_data.tooltip - local color = production_label_data.color + Gui.element(function(_, parent, production_label_data) + local name = production_label_data.name + local tooltip = production_label_data.tooltip + local color = production_label_data.color - -- Add an alignment for the number - local alignment = Gui.alignment(parent, name) + -- Add an alignment for the number + local alignment = Gui.alignment(parent, name) - -- Add the main value label - local element = - alignment.add{ - name = 'label', - type = 'label', - caption = production_label_data.caption, - tooltip = tooltip - } + -- Add the main value label + local element = + alignment.add{ + name = "label", + type = "label", + caption = production_label_data.caption, + tooltip = tooltip, + } - -- Change the style - element.style.font_color = color + -- Change the style + element.style.font_color = color - -- Add the surfix label - local surfix_element = - parent.add{ - name = 'surfix-'..name, - type = 'label', - caption = {'science-info.unit', production_label_data.surfix}, - tooltip = tooltip - } + -- Add the surfix label + local surfix_element = + parent.add{ + name = "surfix-" .. name, + type = "label", + caption = { "science-info.unit", production_label_data.surfix }, + tooltip = tooltip, + } - -- Change the style - local surfix_element_style = surfix_element.style - surfix_element_style.font_color = color - surfix_element_style.right_margin = 1 + -- Change the style + local surfix_element_style = surfix_element.style + surfix_element_style.font_color = color + surfix_element_style.right_margin = 1 - -- Return the value label - return element -end) + -- Return the value label + return element + end) -- Get the data that is used with the production label local function get_production_label_data(name, tooltip, value, cutout, secondary) @@ -65,7 +65,7 @@ local function get_production_label_data(name, tooltip, value, cutout, secondary caption = caption, surfix = surfix, tooltip = tooltip, - color = data_colour + color = data_colour, } end @@ -82,65 +82,64 @@ local function update_production_label(parent, production_label_data) production_label_element.style.font_color = color -- Update the surfix label - local surfix_element = parent['surfix-'..name] - surfix_element.caption = {'science-info.unit', production_label_data.surfix} + local surfix_element = parent["surfix-" .. name] + surfix_element.caption = { "science-info.unit", production_label_data.surfix } surfix_element.tooltip = tooltip surfix_element.style.font_color = color - end --- Adds 4 elements that show the data for a science pack -- @element science_pack_base local science_pack_base = -Gui.element(function(_, parent, science_pack_data) - local science_pack = science_pack_data.science_pack + Gui.element(function(_, parent, science_pack_data) + local science_pack = science_pack_data.science_pack - -- Draw the icon for the science pack - local icon_style = science_pack_data.icon_style - local pack_icon = - parent.add{ - name = 'icon-'..science_pack, - type = 'sprite-button', - sprite = 'item/'..science_pack, - tooltip = {'item-name.'..science_pack}, - style = icon_style - } + -- Draw the icon for the science pack + local icon_style = science_pack_data.icon_style + local pack_icon = + parent.add{ + name = "icon-" .. science_pack, + type = "sprite-button", + sprite = "item/" .. science_pack, + tooltip = { "item-name." .. science_pack }, + style = icon_style, + } - -- Change the style of the icon - local pack_icon_style = pack_icon.style - pack_icon.ignored_by_interaction = true - pack_icon_style.height = 55 - if icon_style == 'slot_button' then - pack_icon_style.padding = {0, -2} - pack_icon_style.width = 36 - end + -- Change the style of the icon + local pack_icon_style = pack_icon.style + pack_icon.ignored_by_interaction = true + pack_icon_style.height = 55 + if icon_style == "slot_button" then + pack_icon_style.padding = { 0, -2 } + pack_icon_style.width = 36 + end - -- Draw the delta flow - local delta_flow = - parent.add{ - name = 'delta-'..science_pack, - type = 'frame', - style = 'bordered_frame' - } - delta_flow.style.padding = {0, 3} + -- Draw the delta flow + local delta_flow = + parent.add{ + name = "delta-" .. science_pack, + type = "frame", + style = "bordered_frame", + } + delta_flow.style.padding = { 0, 3 } - -- Draw the delta flow table - local delta_table = - delta_flow.add{ - name = 'table', - type = 'table', - column_count = 2 - } - delta_table.style.padding = 0 + -- Draw the delta flow table + local delta_table = + delta_flow.add{ + name = "table", + type = "table", + column_count = 2, + } + delta_table.style.padding = 0 - -- Draw the production labels - update_production_label(delta_table, science_pack_data.positive) - update_production_label(delta_table, science_pack_data.negative) - update_production_label(parent, science_pack_data.net) + -- Draw the production labels + update_production_label(delta_table, science_pack_data.positive) + update_production_label(delta_table, science_pack_data.negative) + update_production_label(parent, science_pack_data.net) - -- Return the pack icon - return pack_icon -end) + -- Return the pack icon + return pack_icon + end) local function get_science_pack_data(player, science_pack) local force = player.force @@ -152,14 +151,14 @@ local function get_science_pack_data(player, science_pack) local hour = Production.get_production(force, science_pack, defines.flow_precision_index.one_hour) -- Get the icon style - local icon_style = 'slot_button' + local icon_style = "slot_button" local flux = Production.get_fluctuations(force, science_pack, defines.flow_precision_index.one_minute) - if minute.net > 0 and flux.net > -config.color_flux/2 then - icon_style = 'slot_sized_button_green' + if minute.net > 0 and flux.net > -config.color_flux / 2 then + icon_style = "slot_sized_button_green" elseif flux.net < -config.color_flux then - icon_style = 'slot_sized_button_red' + icon_style = "slot_sized_button_red" elseif minute.made > 0 then - icon_style = 'yellow_slot_button' + icon_style = "yellow_slot_button" end -- Return the pack data @@ -167,23 +166,22 @@ local function get_science_pack_data(player, science_pack) science_pack = science_pack, icon_style = icon_style, positive = get_production_label_data( - 'pos-'..science_pack, - {'science-info.pos-tooltip', total.made}, + "pos-" .. science_pack, + { "science-info.pos-tooltip", total.made }, minute.made, hour.made ), negative = get_production_label_data( - 'neg-'..science_pack, - {'science-info.neg-tooltip', total.used}, + "neg-" .. science_pack, + { "science-info.neg-tooltip", total.used }, -minute.used, hour.used ), net = get_production_label_data( - 'net-'..science_pack, - {'science-info.net-tooltip', total.net}, + "net-" .. science_pack, + { "science-info.net-tooltip", total.net }, minute.net, minute.net > 0 and hour.net or 0, - minute.made+minute.used - ) + minute.made + minute.used + ), } - end local function update_science_pack(pack_table, science_pack_data) @@ -192,23 +190,22 @@ local function update_science_pack(pack_table, science_pack_data) pack_table.parent.non_made.visible = false -- Update the icon - local pack_icon = pack_table['icon-'..science_pack] or science_pack_base(pack_table, science_pack_data) + local pack_icon = pack_table["icon-" .. science_pack] or science_pack_base(pack_table, science_pack_data) local icon_style = science_pack_data.icon_style pack_icon.style = icon_style local pack_icon_style = pack_icon.style pack_icon_style.height = 55 - if icon_style == 'slot_button' then - pack_icon_style.padding = {0, -2} + if icon_style == "slot_button" then + pack_icon_style.padding = { 0, -2 } pack_icon_style.width = 36 end -- Update the production labels - local delta_table = pack_table['delta-'..science_pack].table + local delta_table = pack_table["delta-" .. science_pack].table update_production_label(delta_table, science_pack_data.positive) update_production_label(delta_table, science_pack_data.negative) update_production_label(pack_table, science_pack_data.net) - end --- Gets the data that is used with the eta label @@ -223,7 +220,7 @@ local function get_eta_label_data(player) local limit local progress = force.research_progress - local remaining = research.research_unit_count*(1-progress) + local remaining = research.research_unit_count * (1 - progress) -- Check for the limiting science pack for _, ingredient in pairs(research.research_unit_ingredients) do @@ -238,10 +235,9 @@ local function get_eta_label_data(player) -- Return the caption and tooltip return limit and limit > 0 and { research = true, - caption = format_time(limit, {hours=true, minutes=true, seconds=true, time=true}), - tooltip = format_time(limit, {hours=true, minutes=true, seconds=true, long=true}) + caption = format_time(limit, { hours = true, minutes = true, seconds = true, time = true }), + tooltip = format_time(limit, { hours = true, minutes = true, seconds = true, long = true }), } or { research = false } - end -- Updates the eta label @@ -254,74 +250,73 @@ local function update_eta_label(element, eta_label_data) end -- Update the element - element.caption = {'science-info.eta-time', eta_label_data.caption} + element.caption = { "science-info.eta-time", eta_label_data.caption } element.tooltip = eta_label_data.tooltip end --- Main task list container for the left flow -- @element task_list_container local science_info_container = -Gui.element(function(definition, parent) - local player = Gui.get_player_from_element(parent) + Gui.element(function(definition, parent) + local player = Gui.get_player_from_element(parent) - -- Draw the internal container - local container = Gui.container(parent, definition.name, 200) + -- Draw the internal container + local container = Gui.container(parent, definition.name, 200) - -- Draw the header - Gui.header(container, {'science-info.main-caption'}, {'science-info.main-tooltip'}) + -- Draw the header + Gui.header(container, { "science-info.main-caption" }, { "science-info.main-tooltip" }) - -- Draw the scroll table for the tasks - local scroll_table = Gui.scroll_table(container, 178, 4) + -- Draw the scroll table for the tasks + local scroll_table = Gui.scroll_table(container, 178, 4) - -- Draw the no packs label - local no_packs_label = - scroll_table.parent.add{ - name = 'non_made', - type = 'label', - caption = {'science-info.no-packs'} - } + -- Draw the no packs label + local no_packs_label = + scroll_table.parent.add{ + name = "non_made", + type = "label", + caption = { "science-info.no-packs" }, + } - -- Change the style of the no packs label - local no_packs_style = no_packs_label.style - no_packs_style.padding = {2, 4} - no_packs_style.single_line = false - no_packs_style.width = 200 + -- Change the style of the no packs label + local no_packs_style = no_packs_label.style + no_packs_style.padding = { 2, 4 } + no_packs_style.single_line = false + no_packs_style.width = 200 - -- Add the footer and eta - if config.show_eta then - -- Draw the footer - local footer = Gui.footer(container, {'science-info.eta-caption'}, {'science-info.eta-tooltip'}, true) + -- Add the footer and eta + if config.show_eta then + -- Draw the footer + local footer = Gui.footer(container, { "science-info.eta-caption" }, { "science-info.eta-tooltip" }, true) - -- Draw the eta label - local eta_label = - footer.add{ - name = 'label', - type = 'label', - caption = null_time_short, - tooltip = null_time_long, - style = 'frame_title' - } + -- Draw the eta label + local eta_label = + footer.add{ + name = "label", + type = "label", + caption = null_time_short, + tooltip = null_time_long, + style = "frame_title", + } - -- Update the eta - update_eta_label(eta_label, get_eta_label_data(player)) + -- Update the eta + update_eta_label(eta_label, get_eta_label_data(player)) + end - end + -- Add packs which have been made + for _, science_pack in ipairs(config) do + update_science_pack(scroll_table, get_science_pack_data(player, science_pack)) + end - -- Add packs which have been made - for _, science_pack in ipairs(config) do - update_science_pack(scroll_table, get_science_pack_data(player, science_pack)) - end - - -- Return the exteral container - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + -- Return the exteral container + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() --- Button on the top flow used to toggle the task list container -- @element toggle_science_info -Gui.left_toolbar_button('entity/lab', {'science-info.main-tooltip'}, science_info_container, function(player) - return Roles.player_allowed(player, 'gui/science-info') +Gui.left_toolbar_button("entity/lab", { "science-info.main-tooltip" }, science_info_container, function(player) + return Roles.player_allowed(player, "gui/science-info") end) --- Updates the gui every 1 second @@ -345,13 +340,11 @@ Event.on_nth_tick(60, function() pack_data[science_pack] = next_data update_science_pack(scroll_table, next_data) end - else -- Data found in cache is no need to generate it for _, next_data in pairs(pack_data) do update_science_pack(scroll_table, next_data) end - end -- Update the eta times @@ -363,12 +356,9 @@ Event.on_nth_tick(60, function() eta_data = get_eta_label_data(player) force_eta_data[force_name] = eta_data update_eta_label(eta_label, eta_data) - else -- Data found in chache is no need to generate it update_eta_label(eta_label, eta_data) - end - end -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/gui/server-ups.lua b/exp_legacy/module/modules/gui/server-ups.lua index c80c5f78..14e00c3b 100644 --- a/exp_legacy/module/modules/gui/server-ups.lua +++ b/exp_legacy/module/modules/gui/server-ups.lua @@ -11,24 +11,24 @@ local External = require("modules.exp_legacy.expcore.external") --- @dep expcore --- Stores the visible state of server ups local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local UsesServerUps = PlayerData.Settings:combine('UsesServerUps') +local UsesServerUps = PlayerData.Settings:combine("UsesServerUps") UsesServerUps:set_default(false) UsesServerUps:set_metadata{ - permission = 'command/server-ups', - stringify = function(value) return value and 'Visible' or 'Hidden' end + permission = "command/server-ups", + stringify = function(value) return value and "Visible" or "Hidden" end, } --- Label to show the server ups -- @element server_ups local server_ups = -Gui.element{ - type = 'label', - caption = 'SUPS = 60.0', - name = Gui.unique_static_name -} -:style{ - font = 'default-game' -} + Gui.element{ + type = "label", + caption = "SUPS = 60.0", + name = Gui.unique_static_name, + } + :style{ + font = "default-game", + } --- Change the visible state when your data loads UsesServerUps:on_load(function(player_name, visible) @@ -40,17 +40,17 @@ end) --- Toggles if the server ups is visbile -- @command server-ups -Commands.new_command('server-ups', 'Toggle the server UPS display') -:add_alias('sups', 'ups') -:register(function(player) - local label = player.gui.screen[server_ups.name] - if not External.valid() then - label.visible = false - return Commands.error{'expcom-server-ups.no-ext'} - end - label.visible = not label.visible - UsesServerUps:set(player, label.visible) -end) +Commands.new_command("server-ups", "Toggle the server UPS display") + :add_alias("sups", "ups") + :register(function(player) + local label = player.gui.screen[server_ups.name] + if not External.valid() then + label.visible = false + return Commands.error{ "expcom-server-ups.no-ext" } + end + label.visible = not label.visible + UsesServerUps:set(player, label.visible) + end) -- Set the location of the label -- 1920x1080: x=1455, y=30 (ui scale 100%) @@ -61,7 +61,7 @@ local function set_location(event) local uis = player.display_scale -- below ups and clock -- label.location = {x=res.width-423*uis, y=50*uis} - label.location = {x=res.width-363*uis, y=31*uis} + label.location = { x = res.width - 363 * uis, y = 31 * uis } end -- Draw the label when the player joins @@ -76,7 +76,7 @@ end) -- percentage of game speed Event.on_nth_tick(60, function() if External.valid() then - local caption = External.get_server_ups() .. ' (' .. string.format('%.1f', External.get_server_ups() * 5 / 3) .. '%)' + local caption = External.get_server_ups() .. " (" .. string.format("%.1f", External.get_server_ups() * 5 / 3) .. "%)" for _, player in pairs(game.connected_players) do player.gui.screen[server_ups.name].caption = caption end @@ -85,4 +85,4 @@ end) -- Update when res or ui scale changes Event.add(defines.events.on_player_display_resolution_changed, set_location) -Event.add(defines.events.on_player_display_scale_changed, set_location) \ No newline at end of file +Event.add(defines.events.on_player_display_scale_changed, set_location) diff --git a/exp_legacy/module/modules/gui/surveillance.lua b/exp_legacy/module/modules/gui/surveillance.lua index 82bbe346..4aaa5a59 100644 --- a/exp_legacy/module/modules/gui/surveillance.lua +++ b/exp_legacy/module/modules/gui/surveillance.lua @@ -6,130 +6,130 @@ local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event local cctv_player = -Gui.element(function(definition, parent, player_list) - return parent.add{ - name = definition.name, - type = 'drop-down', - items = player_list, - selected_index = #player_list > 0 and 1 + Gui.element(function(definition, parent, player_list) + return parent.add{ + name = definition.name, + type = "drop-down", + items = player_list, + selected_index = #player_list > 0 and 1, + } + end) + :style{ + horizontally_stretchable = true, } -end) -:style{ - horizontally_stretchable = true -} -:static_name(Gui.unique_static_name) + :static_name(Gui.unique_static_name) local cctv_status = -Gui.element{ - type = 'drop-down', - items = {{'surveillance.status-enable'}, {'surveillance.status-disable'}}, - selected_index = 2 -}:style{ - width = 96 -}:on_selection_changed(function(_, element, _) - if element.selected_index == 1 then - element.parent.parent.parent.cctv_display.visible = true - else - element.parent.parent.parent.cctv_display.visible = false - end -end) + Gui.element{ + type = "drop-down", + items = { { "surveillance.status-enable" }, { "surveillance.status-disable" } }, + selected_index = 2, + }:style{ + width = 96, + }:on_selection_changed(function(_, element, _) + if element.selected_index == 1 then + element.parent.parent.parent.cctv_display.visible = true + else + element.parent.parent.parent.cctv_display.visible = false + end + end) local cctv_type = -Gui.element{ - type = 'drop-down', - name = Gui.unique_static_name, - items = {{'surveillance.type-player'}, {'surveillance.type-static'}, {'surveillance.type-player-loop'}}, - selected_index = 1 -}:style{ - width = 96 -} - -local cctv_location = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = {'surveillance.func-set'} -}:style{ - width = 48 -}:on_click(function(player, element, _) - element.parent.parent.parent.cctv_display.position = player.position -end) - -local zoom_in = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = '+' -}:style{ - width = 32 -}:on_click(function(_, element, _) - local display = element.parent.parent.parent.cctv_display - if display.zoom < 2.0 then - display.zoom = display.zoom + 0.05 - end -end) - -local zoom_out = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = '-' -}:style{ - width = 32 -}:on_click(function(_, element, _) - local display = element.parent.parent.parent.cctv_display - if display.zoom > 0.2 then - display.zoom = display.zoom - 0.05 - end -end) - -local camera_set = -Gui.element(function(_, parent, name, player_list) - local camera_set = parent.add{type='flow', direction='vertical', name=name} - local buttons = Gui.scroll_table(camera_set, 480, 6, 'buttons') - - cctv_player(buttons, player_list) - cctv_status(buttons) - cctv_type(buttons) - cctv_location(buttons) - zoom_out(buttons) - zoom_in(buttons) - - local camera = camera_set.add{ - type = 'camera', - name = 'cctv_display', - position = {x=0, y=0}, - surface_index = game.surfaces['nauvis'].index, - zoom = 0.75, + Gui.element{ + type = "drop-down", + name = Gui.unique_static_name, + items = { { "surveillance.type-player" }, { "surveillance.type-static" }, { "surveillance.type-player-loop" } }, + selected_index = 1, + }:style{ + width = 96, } - camera.visible = false - camera.style.minimal_width = 480 - camera.style.minimal_height = 290 - return camera_set -end) +local cctv_location = + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "surveillance.func-set" }, + }:style{ + width = 48, + }:on_click(function(player, element, _) + element.parent.parent.parent.cctv_display.position = player.position + end) + +local zoom_in = + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = "+", + }:style{ + width = 32, + }:on_click(function(_, element, _) + local display = element.parent.parent.parent.cctv_display + if display.zoom < 2.0 then + display.zoom = display.zoom + 0.05 + end + end) + +local zoom_out = + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = "-", + }:style{ + width = 32, + }:on_click(function(_, element, _) + local display = element.parent.parent.parent.cctv_display + if display.zoom > 0.2 then + display.zoom = display.zoom - 0.05 + end + end) + +local camera_set = + Gui.element(function(_, parent, name, player_list) + local camera_set = parent.add{ type = "flow", direction = "vertical", name = name } + local buttons = Gui.scroll_table(camera_set, 480, 6, "buttons") + + cctv_player(buttons, player_list) + cctv_status(buttons) + cctv_type(buttons) + cctv_location(buttons) + zoom_out(buttons) + zoom_in(buttons) + + local camera = camera_set.add{ + type = "camera", + name = "cctv_display", + position = { x = 0, y = 0 }, + surface_index = game.surfaces["nauvis"].index, + zoom = 0.75, + } + + camera.visible = false + camera.style.minimal_width = 480 + camera.style.minimal_height = 290 + return camera_set + end) local cctv_container = -Gui.element(function(definition, parent) - local container = Gui.container(parent, definition.name, 480) - local scroll = container.add{name='scroll', type='scroll-pane', direction='vertical'} - scroll.style.maximal_height = 704 - local player_list = {} + Gui.element(function(definition, parent) + local container = Gui.container(parent, definition.name, 480) + local scroll = container.add{ name = "scroll", type = "scroll-pane", direction = "vertical" } + scroll.style.maximal_height = 704 + local player_list = {} - for _, player in pairs(game.connected_players) do - table.insert(player_list, player.name) - end + for _, player in pairs(game.connected_players) do + table.insert(player_list, player.name) + end - camera_set(scroll, 'cctv_st_1', player_list) - camera_set(scroll, 'cctv_st_2', player_list) + camera_set(scroll, "cctv_st_1", player_list) + camera_set(scroll, "cctv_st_2", player_list) - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() -Gui.left_toolbar_button('entity/radar', {'surveillance.main-tooltip'}, cctv_container, function(player) - return Roles.player_allowed(player, 'gui/surveillance') +Gui.left_toolbar_button("entity/radar", { "surveillance.main-tooltip" }, cctv_container, function(player) + return Roles.player_allowed(player, "gui/surveillance") end) local function gui_update() @@ -141,8 +141,8 @@ local function gui_update() for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) - frame.container.scroll['cctv_st_1'].buttons.table[cctv_player.name].items = player_list - frame.container.scroll['cctv_st_2'].buttons.table[cctv_player.name].items = player_list + frame.container.scroll["cctv_st_1"].buttons.table[cctv_player.name].items = player_list + frame.container.scroll["cctv_st_2"].buttons.table[cctv_player.name].items = player_list end end @@ -153,8 +153,8 @@ Event.add(defines.events.on_tick, function(_) for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) - for i=1, 2 do - local scroll_table_name = 'cctv_st_' .. i + for i = 1, 2 do + local scroll_table_name = "cctv_st_" .. i local current_camera_set = frame.container.scroll[scroll_table_name] local switch_index = current_camera_set.buttons.table[cctv_type.name].selected_index @@ -163,12 +163,11 @@ Event.add(defines.events.on_tick, function(_) if selected_index ~= 0 then selected_index = current_camera_set.buttons.table[cctv_player.name].items[selected_index] - current_camera_set['cctv_display'].position = game.players[selected_index].position - current_camera_set['cctv_display'].surface_index = game.players[selected_index].surface_index - + current_camera_set["cctv_display"].position = game.players[selected_index].position + current_camera_set["cctv_display"].surface_index = game.players[selected_index].surface_index else - current_camera_set['cctv_display'].position = {x=0, y=0} - current_camera_set['cctv_display'].surface_index = game.surfaces['nauvis'].index + current_camera_set["cctv_display"].position = { x = 0, y = 0 } + current_camera_set["cctv_display"].surface_index = game.surfaces["nauvis"].index end end end @@ -179,8 +178,8 @@ Event.on_nth_tick(600, function(_) for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, cctv_container) - for i=1, 2 do - local current_camera_set = frame.container.scroll['cctv_st_' .. i] + for i = 1, 2 do + local current_camera_set = frame.container.scroll["cctv_st_" .. i] if current_camera_set.buttons.table[cctv_type.name].selected_index == 3 then local item_n = #current_camera_set.buttons.table[cctv_player.name].items @@ -188,7 +187,6 @@ Event.on_nth_tick(600, function(_) if item_n ~= 0 then if current_camera_set.buttons.table[cctv_player.name].selected_index < item_n then current_camera_set.buttons.table[cctv_player.name].selected_index = current_camera_set.buttons.table[cctv_player.name].selected_index + 1 - else current_camera_set.buttons.table[cctv_player.name].selected_index = 1 end diff --git a/exp_legacy/module/modules/gui/task-list.lua b/exp_legacy/module/modules/gui/task-list.lua index 59d7725f..fb0ba461 100644 --- a/exp_legacy/module/modules/gui/task-list.lua +++ b/exp_legacy/module/modules/gui/task-list.lua @@ -26,14 +26,14 @@ local Styles = { sprite22 = { height = 22, width = 22, - padding = -2 + padding = -2, }, footer_button = { height = 29, maximal_width = 268, horizontally_stretchable = true, - padding = -2 - } + padding = -2, + }, } --- If a player is allowed to use the edit buttons @@ -81,242 +81,242 @@ end --- Button displayed in the header bar, used to add a new task -- @element add_new_task local add_new_task = - Gui.element { - type = "sprite-button", - sprite = "utility/add", - tooltip = {"task-list.add-tooltip"}, - style = "tool_button", - name = Gui.unique_static_name -}:style(Styles.sprite22):on_click( - function(player, _, _) - -- Disable editing - PlayerIsEditing:set(player, false) - -- Clear selected - PlayerSelected:set(player, nil) - -- Open task create footer - PlayerIsCreating:set(player, true) - end -) + Gui.element{ + type = "sprite-button", + sprite = "utility/add", + tooltip = { "task-list.add-tooltip" }, + style = "tool_button", + name = Gui.unique_static_name, + }:style(Styles.sprite22):on_click( + function(player, _, _) + -- Disable editing + PlayerIsEditing:set(player, false) + -- Clear selected + PlayerSelected:set(player, nil) + -- Open task create footer + PlayerIsCreating:set(player, true) + end + ) --- Header displayed when no tasks are in the task list -- @element no_tasks_found local no_tasks_found = Gui.element( - function(_, parent) - local header = - parent.add { - name = "no_tasks_found_element", - type = "frame", - style = "negative_subheader_frame" - } - header.style.horizontally_stretchable = true - -- Flow used for centering the content in the subheader - local center = - header.add { - type = "flow", - } - center.style.vertical_align = "center" - center.style.horizontal_align = "center" - center.style.horizontally_stretchable = true - center.add { - name = "header_label", - type = "label", - style = "bold_label", - caption = {"", "[img=utility/warning_white] ", {"task-list.no-tasks"}}, - tooltip = {"task-list.no-tasks-tooltip"} - } - return header - end -) + function(_, parent) + local header = + parent.add{ + name = "no_tasks_found_element", + type = "frame", + style = "negative_subheader_frame", + } + header.style.horizontally_stretchable = true + -- Flow used for centering the content in the subheader + local center = + header.add{ + type = "flow", + } + center.style.vertical_align = "center" + center.style.horizontal_align = "center" + center.style.horizontally_stretchable = true + center.add{ + name = "header_label", + type = "label", + style = "bold_label", + caption = { "", "[img=utility/warning_white] ", { "task-list.no-tasks" } }, + tooltip = { "task-list.no-tasks-tooltip" }, + } + return header + end + ) --- Frame element with the right styling -- @element subfooter_frame local subfooter_frame = Gui.element( - function(_, parent, name) - return parent.add { - type = "frame", - name = name, - direction = "vertical", - style = "subfooter_frame" + function(_, parent, name) + return parent.add{ + type = "frame", + name = name, + direction = "vertical", + style = "subfooter_frame", + } + end + ):style + { + padding = 5, + use_header_filler = false, + horizontally_stretchable = true, } - end -):style( - { - padding = 5, - use_header_filler = false, - horizontally_stretchable = true - } -) + --- Label element preset -- @element subfooter_label local subfooter_label = Gui.element( - function(_, parent, caption) - return parent.add { - name = "footer_label", - type = "label", - style = "frame_title", - caption = caption - } - end -) + function(_, parent, caption) + return parent.add{ + name = "footer_label", + type = "label", + style = "frame_title", + caption = caption, + } + end + ) --- Action flow that contains action buttons -- @element subfooter_actions local subfooter_actions = - Gui.element { - type = "flow", - name = "actions" -} + Gui.element{ + type = "flow", + name = "actions", + } --- Button element with a flow around it to fix duplicate name inside of the scroll flow -- @element task_list_item local task_list_item = Gui.element( - function(definition, parent, task) - local flow = parent.add { - type = "flow", - name = "task-" .. task.task_id, - caption = task.task_id - } + function(definition, parent, task) + local flow = parent.add{ + type = "flow", + name = "task-" .. task.task_id, + caption = task.task_id, + } - flow.style.horizontally_stretchable = true + flow.style.horizontally_stretchable = true - local button = flow.add { - name = definition.name, - type = "button", - style = "list_box_item", - caption = task.title, - tooltip = { "task-list.last-edit", task.last_edit_name, format_time(task.last_edit_time) } - } + local button = flow.add{ + name = definition.name, + type = "button", + style = "list_box_item", + caption = task.title, + tooltip = { "task-list.last-edit", task.last_edit_name, format_time(task.last_edit_time) }, + } - button.style.horizontally_stretchable = true - button.style.horizontally_squashable = true + button.style.horizontally_stretchable = true + button.style.horizontally_squashable = true - return button - end -):on_click( - function(player, element, _) - local task_id = element.parent.caption - PlayerSelected:set(player, task_id) - end -):static_name(Gui.unique_static_name) + return button + end + ):on_click( + function(player, element, _) + local task_id = element.parent.caption + PlayerSelected:set(player, task_id) + end + ):static_name(Gui.unique_static_name) --- Scrollable list of all tasks -- @element task_list local task_list = Gui.element( - function(_, parent) - local scroll_pane = - parent.add { - name = "scroll", - type = "scroll-pane", - direction = "vertical", - horizontal_scroll_policy = "never", - vertical_scroll_policy = "auto", - style = "scroll_pane_under_subheader" - } - scroll_pane.style.horizontally_stretchable = true - scroll_pane.style.padding = 0 - scroll_pane.style.maximal_height = 224 + function(_, parent) + local scroll_pane = + parent.add{ + name = "scroll", + type = "scroll-pane", + direction = "vertical", + horizontal_scroll_policy = "never", + vertical_scroll_policy = "auto", + style = "scroll_pane_under_subheader", + } + scroll_pane.style.horizontally_stretchable = true + scroll_pane.style.padding = 0 + scroll_pane.style.maximal_height = 224 - local flow = - scroll_pane.add { - name = "task_list", - type = "flow", - direction = "vertical" - } - flow.style.vertical_spacing = 0 - flow.style.horizontally_stretchable = true + local flow = + scroll_pane.add{ + name = "task_list", + type = "flow", + direction = "vertical", + } + flow.style.vertical_spacing = 0 + flow.style.horizontally_stretchable = true - return flow - end -) + return flow + end + ) --- Button element inside the task view footer to start editing a task -- @element task_view_edit_button local task_view_edit_button = - Gui.element { - type = "button", - name = Gui.unique_static_name, - caption = {"", "[img=utility/rename_icon] ", {"task-list.edit"}}, - tooltip = {"task-list.edit-tooltip"}, - style = "shortcut_bar_button" -}:style(Styles.footer_button):on_click( - function(player, _, _) - local selected = PlayerSelected:get(player) - PlayerIsEditing:set(player, true) + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "", "[img=utility/rename_icon] ", { "task-list.edit" } }, + tooltip = { "task-list.edit-tooltip" }, + style = "shortcut_bar_button", + }:style(Styles.footer_button):on_click( + function(player, _, _) + local selected = PlayerSelected:get(player) + PlayerIsEditing:set(player, true) - Tasks.set_editing(selected, player.name, true) - end -) + Tasks.set_editing(selected, player.name, true) + end + ) --- Button to close the task view footer -- @element task_view_close_button local task_view_close_button = -Gui.element{ - type = "sprite-button", - sprite = "utility/collapse", - style = "frame_action_button", - tooltip = {"task-list.close-tooltip"} -} -:style(Styles.sprite22):on_click( - function(player, _, _) - PlayerSelected:set(player, nil) - end -) + Gui.element{ + type = "sprite-button", + sprite = "utility/collapse", + style = "frame_action_button", + tooltip = { "task-list.close-tooltip" }, + } + :style(Styles.sprite22):on_click( + function(player, _, _) + PlayerSelected:set(player, nil) + end + ) --- Button to delete the task inside the task view footer -- @element task_view_delete_button local task_view_delete_button = - Gui.element { - type = "button", - name = Gui.unique_static_name, - caption = {"", "[img=utility/trash] ", {"task-list.delete"}}, - tooltip = {"task-list.delete-tooltip"}, - style = "shortcut_bar_button_red" -}:style(Styles.footer_button):on_click( - function(player, _, _) - local selected = PlayerSelected:get(player) - PlayerSelected:set(player, nil) - Tasks.remove_task(selected) - end -) + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "", "[img=utility/trash] ", { "task-list.delete" } }, + tooltip = { "task-list.delete-tooltip" }, + style = "shortcut_bar_button_red", + }:style(Styles.footer_button):on_click( + function(player, _, _) + local selected = PlayerSelected:get(player) + PlayerSelected:set(player, nil) + Tasks.remove_task(selected) + end + ) --- Subfooter inside the tasklist container that holds all the elements for viewing a task -- @element task_view_footer local task_view_footer = Gui.element( - function(_, parent) - local footer = subfooter_frame(parent, "view") - local flow = footer.add{ type = "flow" } - subfooter_label(flow, {"task-list.view-footer-header"}) - local alignment = Gui.alignment(flow) - task_view_close_button(alignment) - local title_label = - footer.add { - type = "label", - name = "title" - } - title_label.style.padding = 4 - title_label.style.font = "default-bold" - title_label.style.single_line = false - local body_label = - footer.add { - type = "label", - name = "body" - } - body_label.style.padding = 4 - body_label.style.single_line = false + function(_, parent) + local footer = subfooter_frame(parent, "view") + local flow = footer.add{ type = "flow" } + subfooter_label(flow, { "task-list.view-footer-header" }) + local alignment = Gui.alignment(flow) + task_view_close_button(alignment) + local title_label = + footer.add{ + type = "label", + name = "title", + } + title_label.style.padding = 4 + title_label.style.font = "default-bold" + title_label.style.single_line = false + local body_label = + footer.add{ + type = "label", + name = "body", + } + body_label.style.padding = 4 + body_label.style.single_line = false - local action_flow = subfooter_actions(footer) - task_view_delete_button(action_flow) - task_view_edit_button(action_flow) - return footer - end -) + local action_flow = subfooter_actions(footer) + task_view_delete_button(action_flow) + task_view_edit_button(action_flow) + return footer + end + ) local message_pattern = "(.-)\n(.*)" @@ -344,138 +344,138 @@ local task_create_confirm_button --- Textfield element used in both the task create and edit footers -- @element task_message_textfield local task_message_textfield = - Gui.element { - name = Gui.unique_static_name, - type = "text-box", - text = "" -}:style( - { - maximal_width = 268, - minimal_height = 100, - horizontally_stretchable = true - } -):on_text_changed( - function(player, element, _) - local isEditing = PlayerIsEditing:get(player) - local isCreating = PlayerIsCreating:get(player) + Gui.element{ + name = Gui.unique_static_name, + type = "text-box", + text = "", + }:style + { + maximal_width = 268, + minimal_height = 100, + horizontally_stretchable = true, + } + :on_text_changed( + function(player, element, _) + local isEditing = PlayerIsEditing:get(player) + local isCreating = PlayerIsCreating:get(player) - local valid = string.len(element.text) > 5 + local valid = string.len(element.text) > 5 - if isCreating then - element.parent.actions[task_create_confirm_button.name].enabled = valid - elseif isEditing then - element.parent.actions[task_edit_confirm_button.name].enabled = valid + if isCreating then + element.parent.actions[task_create_confirm_button.name].enabled = valid + elseif isEditing then + element.parent.actions[task_edit_confirm_button.name].enabled = valid + end end - end -) + ) --- Button to confirm the changes inside the task edit footer -- @element task_edit_confirm_button task_edit_confirm_button = - Gui.element { - type = "button", - name = Gui.unique_static_name, - caption = {"", "[img=utility/check_mark] ", {"task-list.confirm"}}, - tooltip = {"task-list.confirm-tooltip"}, - style = "shortcut_bar_button_green" -}:style(Styles.footer_button):on_click( - function(player, element, _) - local selected = PlayerSelected:get(player) - PlayerIsEditing:set(player, false) - local new_message = element.parent.parent[task_message_textfield.name].text - local parsed = parse_message(new_message) - Tasks.update_task(selected, player.name, parsed.title, parsed.body) - Tasks.set_editing(selected, player.name, nil) - end -) + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } }, + tooltip = { "task-list.confirm-tooltip" }, + style = "shortcut_bar_button_green", + }:style(Styles.footer_button):on_click( + function(player, element, _) + local selected = PlayerSelected:get(player) + PlayerIsEditing:set(player, false) + local new_message = element.parent.parent[task_message_textfield.name].text + local parsed = parse_message(new_message) + Tasks.update_task(selected, player.name, parsed.title, parsed.body) + Tasks.set_editing(selected, player.name, nil) + end + ) --- Button to discard the changes inside the task edit footer -- @element edit_task_discard_button local edit_task_discard_button = - Gui.element { - type = "button", - caption = {"", "[img=utility/close_black] ", {"task-list.discard"}}, - tooltip = {"task-list.discard-tooltip"}, - style = "shortcut_bar_button_red" -}:style(Styles.footer_button):on_click( - function(player, _, _) - local selected = PlayerSelected:get(player) - Tasks.set_editing(selected, player.name, nil) - PlayerIsEditing:set(player, false) - end -) + Gui.element{ + type = "button", + caption = { "", "[img=utility/close_black] ", { "task-list.discard" } }, + tooltip = { "task-list.discard-tooltip" }, + style = "shortcut_bar_button_red", + }:style(Styles.footer_button):on_click( + function(player, _, _) + local selected = PlayerSelected:get(player) + Tasks.set_editing(selected, player.name, nil) + PlayerIsEditing:set(player, false) + end + ) --- Subfooter inside the tasklist container that holds all the elements for editing a task -- @element task_edit_footer local task_edit_footer = Gui.element( - function(_, parent) - local footer = subfooter_frame(parent, "edit") - subfooter_label(footer, {"task-list.edit-footer-header"}) + function(_, parent) + local footer = subfooter_frame(parent, "edit") + subfooter_label(footer, { "task-list.edit-footer-header" }) - task_message_textfield(footer) + task_message_textfield(footer) - local action_flow = subfooter_actions(footer) + local action_flow = subfooter_actions(footer) - edit_task_discard_button(action_flow) - task_edit_confirm_button(action_flow) + edit_task_discard_button(action_flow) + task_edit_confirm_button(action_flow) - return footer - end -) + return footer + end + ) --- Button to confirm the changes inside the task create footer -- @element task_create_confirm_button task_create_confirm_button = - Gui.element { - type = "button", - name = Gui.unique_static_name, - caption = {"", "[img=utility/check_mark] ", {"task-list.confirm"}}, - tooltip = {"task-list.confirm-tooltip"}, - style = "shortcut_bar_button_green", - enabled = false -}:style(Styles.footer_button):on_click( - function(player, element, _) - local message = element.parent.parent[task_message_textfield.name].text - PlayerIsCreating:set(player, false) - local parsed = parse_message(message) - local task_id = Tasks.add_task(player.force.name, player.name, parsed.title, parsed.body) - PlayerSelected:set(player, task_id) - end -) + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "", "[img=utility/check_mark] ", { "task-list.confirm" } }, + tooltip = { "task-list.confirm-tooltip" }, + style = "shortcut_bar_button_green", + enabled = false, + }:style(Styles.footer_button):on_click( + function(player, element, _) + local message = element.parent.parent[task_message_textfield.name].text + PlayerIsCreating:set(player, false) + local parsed = parse_message(message) + local task_id = Tasks.add_task(player.force.name, player.name, parsed.title, parsed.body) + PlayerSelected:set(player, task_id) + end + ) --- Button to discard the changes inside the task create footer -- @element task_create_discard_button local task_create_discard_button = - Gui.element { - type = "button", - caption = {"", "[img=utility/close_black] ", {"task-list.discard"}}, - tooltip = {"task-list.discard-tooltip"}, - style = "shortcut_bar_button_red" -}:style(Styles.footer_button):on_click( - function(player, _, _) - PlayerIsCreating:set(player, false) - end -) + Gui.element{ + type = "button", + caption = { "", "[img=utility/close_black] ", { "task-list.discard" } }, + tooltip = { "task-list.discard-tooltip" }, + style = "shortcut_bar_button_red", + }:style(Styles.footer_button):on_click( + function(player, _, _) + PlayerIsCreating:set(player, false) + end + ) --- Subfooter inside the tasklist container that holds all the elements to create a new task -- @element task_create_footer local task_create_footer = Gui.element( - function(_, parent) - local footer = subfooter_frame(parent, "create") - subfooter_label(footer, {"task-list.create-footer-header"}) + function(_, parent) + local footer = subfooter_frame(parent, "create") + subfooter_label(footer, { "task-list.create-footer-header" }) - task_message_textfield(footer) + task_message_textfield(footer) - local action_flow = subfooter_actions(footer) + local action_flow = subfooter_actions(footer) - task_create_discard_button(action_flow) - task_create_confirm_button(action_flow) + task_create_discard_button(action_flow) + task_create_confirm_button(action_flow) - return footer - end -) + return footer + end + ) --- Clear and repopulate the task list with all current tasks local repopulate_task_list = function(task_list_element) @@ -498,48 +498,48 @@ end -- @element task_list_container local task_list_container = Gui.element( - function(definition, parent) - -- Draw the internal container - local container = Gui.container(parent, definition.name, 268) - container.style.maximal_width = 268 - container.style.minimal_width = 268 + function(definition, parent) + -- Draw the internal container + local container = Gui.container(parent, definition.name, 268) + container.style.maximal_width = 268 + container.style.minimal_width = 268 - -- Draw the header - local header = Gui.header(container, {"task-list.main-caption"}, {"task-list.sub-tooltip"}, true) + -- Draw the header + local header = Gui.header(container, { "task-list.main-caption" }, { "task-list.sub-tooltip" }, true) - -- Draw the new task button - local player = Gui.get_player_from_element(parent) - local add_new_task_element = add_new_task(header) - add_new_task_element.visible = check_player_permissions(player) + -- Draw the new task button + local player = Gui.get_player_from_element(parent) + local add_new_task_element = add_new_task(header) + add_new_task_element.visible = check_player_permissions(player) - -- Draw no task found element - no_tasks_found(container) + -- Draw no task found element + no_tasks_found(container) - -- Draw task list element - local task_list_element = task_list(container) - repopulate_task_list(task_list_element) + -- Draw task list element + local task_list_element = task_list(container) + repopulate_task_list(task_list_element) - local task_view_footer_element = task_view_footer(container) - local task_edit_footer_element = task_edit_footer(container) - local task_create_footer_element = task_create_footer(container) - task_view_footer_element.visible = false - task_edit_footer_element.visible = false - task_create_footer_element.visible = false - -- Return the external container - return container.parent - end -):static_name(Gui.unique_static_name):add_to_left_flow( - function(player) - local task_ids = Tasks.get_force_task_ids(player.force.name) - return #task_ids > 0 - end -) + local task_view_footer_element = task_view_footer(container) + local task_edit_footer_element = task_edit_footer(container) + local task_create_footer_element = task_create_footer(container) + task_view_footer_element.visible = false + task_edit_footer_element.visible = false + task_create_footer_element.visible = false + -- Return the external container + return container.parent + end + ):static_name(Gui.unique_static_name):add_to_left_flow( + function(player) + local task_ids = Tasks.get_force_task_ids(player.force.name) + return #task_ids > 0 + end + ) --- Button on the top flow used to toggle the task list container -- @element toggle_left_element Gui.left_toolbar_button( "utility/not_enough_repair_packs_icon", - {"task-list.main-tooltip"}, + { "task-list.main-tooltip" }, task_list_container, function(player) return Roles.player_allowed(player, "gui/task-list") @@ -567,7 +567,7 @@ local update_task = function(player, task_list_element, task_id) -- If the task exists update the caption and tooltip local button = flow[task_list_item.name] button.caption = task.title - button.tooltip = {"task-list.last-edit", task.last_edit_name, format_time(task.last_edit_time)} + button.tooltip = { "task-list.last-edit", task.last_edit_name, format_time(task.last_edit_time) } end end @@ -602,9 +602,9 @@ local update_task_view_footer = function(player, task_id) local players_editing = table.get_keys(task.currently_editing) if #players_editing > 0 then - edit_button_element.tooltip = {"task-list.edit-tooltip", table.concat(players_editing, ", ")} + edit_button_element.tooltip = { "task-list.edit-tooltip", table.concat(players_editing, ", ") } else - edit_button_element.tooltip = {"task-list.edit-tooltip-none"} + edit_button_element.tooltip = { "task-list.edit-tooltip-none" } end end @@ -780,4 +780,4 @@ local function reset_task_list(event) end Event.add(defines.events.on_player_joined_game, reset_task_list) -Event.add(defines.events.on_player_changed_force, reset_task_list) \ No newline at end of file +Event.add(defines.events.on_player_changed_force, reset_task_list) diff --git a/exp_legacy/module/modules/gui/toolbar.lua b/exp_legacy/module/modules/gui/toolbar.lua index 9587a0eb..19025424 100644 --- a/exp_legacy/module/modules/gui/toolbar.lua +++ b/exp_legacy/module/modules/gui/toolbar.lua @@ -2,7 +2,7 @@ local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -- Used to store the state of the toolbar when a player leaves -local ToolbarState = PlayerData.Settings:combine('ToolbarState') +local ToolbarState = PlayerData.Settings:combine("ToolbarState") ToolbarState:set_metadata{ stringify = function(value) local buttons, favourites = 0, 0 @@ -12,15 +12,16 @@ ToolbarState:set_metadata{ favourites = favourites + 1 end end + return string.format("Buttons: %d, Favourites: %d", buttons, favourites) - end + end, } -- Styles used for sprite buttons local button_size = 20 local Styles = { header = Gui.sprite_style(22), - item = Gui.sprite_style(button_size) + item = Gui.sprite_style(button_size), } --- Set the style of the fake toolbar element @@ -46,7 +47,7 @@ local function move_toolbar_button(player, item, offset) -- Swap the position in the top flow, offset by 1 because of settings button local top_flow = Gui.get_top_flow(player) - top_flow.swap_children(old_index+1, new_index+1) + top_flow.swap_children(old_index + 1, new_index + 1) -- Check if the element has a left element to move local element_define = Gui.defines[item.tags.top_element_uid] @@ -100,7 +101,7 @@ local function reorder_toolbar_menu(player) -- Check if the player is allowed to see the button local allowed = element_define.authenticator - if type(allowed) == 'function' then allowed = allowed(player) end + if type(allowed) == "function" then allowed = allowed(player) end -- Update the checkbox state and item visibility local toolbar_button = Gui.get_top_element(player, element_define) @@ -121,210 +122,210 @@ end --- Resets the toolbar to its default state when pressed -- @element reset_toolbar local reset_toolbar = -Gui.element { - type = "sprite-button", - sprite = "utility/reset", - style = "shortcut_bar_button_red", - tooltip = {"toolbar.reset"}, - name = Gui.unique_static_name -} -:style(Gui.sprite_style(Styles.header.width, -1)) -:on_click(function(player) - ToolbarState:set(player, nil) - Gui.toggle_top_flow(player, true) - reorder_toolbar_menu(player) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/reset", + style = "shortcut_bar_button_red", + tooltip = { "toolbar.reset" }, + name = Gui.unique_static_name, + } + :style(Gui.sprite_style(Styles.header.width, -1)) + :on_click(function(player) + ToolbarState:set(player, nil) + Gui.toggle_top_flow(player, true) + reorder_toolbar_menu(player) + end) --- Replaces the default method for opening and closing the toolbar -- @element toggle_toolbar toggle_toolbar = -Gui.element { - type = "sprite-button", - sprite = "utility/bookmark", - tooltip = {"toolbar.toggle"}, - style = "tool_button", - auto_toggle = true, - name = Gui.unique_static_name -} -:style(Styles.header) -:on_click(function(player, element) - Gui.toggle_top_flow(player, element.toggled) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/bookmark", + tooltip = { "toolbar.toggle" }, + style = "tool_button", + auto_toggle = true, + name = Gui.unique_static_name, + } + :style(Styles.header) + :on_click(function(player, element) + Gui.toggle_top_flow(player, element.toggled) + end) --- Move an element up the list -- @element move_up move_up = -Gui.element { - type = "sprite-button", - sprite = "utility/speed_up", - tooltip = {"toolbar.move-up"}, - name = Gui.unique_static_name -} -:style(Styles.item) -:on_click(function(player, element) - local item = element.parent.parent - move_toolbar_button(player, item, -1) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/speed_up", + tooltip = { "toolbar.move-up" }, + name = Gui.unique_static_name, + } + :style(Styles.item) + :on_click(function(player, element) + local item = element.parent.parent + move_toolbar_button(player, item, -1) + end) --- Move an element down the list -- @element move_down move_down = -Gui.element { - type = "sprite-button", - sprite = "utility/speed_down", - tooltip = {"toolbar.move-down"}, - name = Gui.unique_static_name -} -:style(Styles.item) -:on_click(function(player, element) - local item = element.parent.parent - move_toolbar_button(player, item, 1) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/speed_down", + tooltip = { "toolbar.move-down" }, + name = Gui.unique_static_name, + } + :style(Styles.item) + :on_click(function(player, element) + local item = element.parent.parent + move_toolbar_button(player, item, 1) + end) --- A flow which represents one item in the toolbar list -- @element toolbar_list_item local toolbar_list_item = -Gui.element(function(definition, parent, element_define) - local flow = parent.add { - type = "frame", - style = "shortcut_selection_row", - name = element_define.name, - tags = { - top_element_uid = element_define.uid + Gui.element(function(definition, parent, element_define) + local flow = parent.add{ + type = "frame", + style = "shortcut_selection_row", + name = element_define.name, + tags = { + top_element_uid = element_define.uid, + }, } - } - flow.style.horizontally_stretchable = true - flow.style.vertical_align = "center" + flow.style.horizontally_stretchable = true + flow.style.vertical_align = "center" - -- Add the button and the icon edit button - local element = element_define(flow) - local player = Gui.get_player_from_element(parent) - local top_element = Gui.get_top_element(player, element_define) - copy_style(top_element, element) + -- Add the button and the icon edit button + local element = element_define(flow) + local player = Gui.get_player_from_element(parent) + local top_element = Gui.get_top_element(player, element_define) + copy_style(top_element, element) - -- Add the checkbox that can toggle the visibility - local checkbox = flow.add{ - type = "checkbox", - name = "checkbox", - caption = element_define.tooltip or element_define.caption or "None", - state = top_element.visible or false, - tags = { - top_element_name = element_define.name + -- Add the checkbox that can toggle the visibility + local checkbox = flow.add{ + type = "checkbox", + name = "checkbox", + caption = element_define.tooltip or element_define.caption or "None", + state = top_element.visible or false, + tags = { + top_element_name = element_define.name, + }, } - } - definition:triggers_events(checkbox) - checkbox.style.width = 180 + definition:triggers_events(checkbox) + checkbox.style.width = 180 - -- Add the buttons used to move the flow up and down - local move_flow = flow.add{ type = "flow", name = "move" } - move_flow.style.horizontal_spacing = 0 - move_up(move_flow) - move_down(move_flow) + -- Add the buttons used to move the flow up and down + local move_flow = flow.add{ type = "flow", name = "move" } + move_flow.style.horizontal_spacing = 0 + move_up(move_flow) + move_down(move_flow) - return definition:no_events(flow) -end) -:on_checked_changed(function(player, element) - local top_flow = Gui.get_top_flow(player) - local top_element = top_flow[element.tags.top_element_name] - local had_visible = Gui.top_flow_has_visible_elements(player) - top_element.visible = element.state - - -- Check if we are on the edge case between 0 and 1 visible elements - if element.state and not had_visible then - Gui.toggle_top_flow(player, true) - local container = element.parent.parent.parent.parent - local button = container.header.alignment[toggle_toolbar.name] - button.toggled = true - button.enabled = true - elseif not element.state and not Gui.top_flow_has_visible_elements(player) then - Gui.toggle_top_flow(player, false) - local container = element.parent.parent.parent.parent - local button = container.header.alignment[toggle_toolbar.name] - button.toggled = false - button.enabled = false - end - - -- Update the datastore state - ToolbarState:update(player, function(_, order) - local index = element.parent.get_index_in_parent() - order[index].favourite = element.state + return definition:no_events(flow) + end) + :on_checked_changed(function(player, element) + local top_flow = Gui.get_top_flow(player) + local top_element = top_flow[element.tags.top_element_name] + local had_visible = Gui.top_flow_has_visible_elements(player) + top_element.visible = element.state + + -- Check if we are on the edge case between 0 and 1 visible elements + if element.state and not had_visible then + Gui.toggle_top_flow(player, true) + local container = element.parent.parent.parent.parent + local button = container.header.alignment[toggle_toolbar.name] + button.toggled = true + button.enabled = true + elseif not element.state and not Gui.top_flow_has_visible_elements(player) then + Gui.toggle_top_flow(player, false) + local container = element.parent.parent.parent.parent + local button = container.header.alignment[toggle_toolbar.name] + button.toggled = false + button.enabled = false + end + + -- Update the datastore state + ToolbarState:update(player, function(_, order) + local index = element.parent.get_index_in_parent() + order[index].favourite = element.state + end) end) -end) --- Scrollable list of all toolbar buttons -- @element toolbar_list local toolbar_list = -Gui.element(function(_, parent) - -- This is a scroll pane for the list - local scroll_pane = parent.add { - name = "scroll", - type = "scroll-pane", - direction = "vertical", - horizontal_scroll_policy = "never", - vertical_scroll_policy = "auto", - style = "scroll_pane_under_subheader" - } - scroll_pane.style.horizontally_stretchable = true - scroll_pane.style.padding = 0 - scroll_pane.style.maximal_height = 224 + Gui.element(function(_, parent) + -- This is a scroll pane for the list + local scroll_pane = parent.add{ + name = "scroll", + type = "scroll-pane", + direction = "vertical", + horizontal_scroll_policy = "never", + vertical_scroll_policy = "auto", + style = "scroll_pane_under_subheader", + } + scroll_pane.style.horizontally_stretchable = true + scroll_pane.style.padding = 0 + scroll_pane.style.maximal_height = 224 - -- This flow is the list, we need a linear list because of get_index_in_parent - local flow = scroll_pane.add { - name = "list", - type = "flow", - direction = "vertical" - } - flow.style.vertical_spacing = 0 - flow.style.horizontally_stretchable = true + -- This flow is the list, we need a linear list because of get_index_in_parent + local flow = scroll_pane.add{ + name = "list", + type = "flow", + direction = "vertical", + } + flow.style.vertical_spacing = 0 + flow.style.horizontally_stretchable = true - return flow -end) + return flow + end) --- Main toolbar container for the left flow -- @element toolbar_container toolbar_container = -Gui.element(function(definition, parent) - -- Draw the internal container - local container = Gui.container(parent, definition.name, 268) - container.style.maximal_width = 268 - container.style.minimal_width = 268 + Gui.element(function(definition, parent) + -- Draw the internal container + local container = Gui.container(parent, definition.name, 268) + container.style.maximal_width = 268 + container.style.minimal_width = 268 - -- Draw the header - local player = Gui.get_player_from_element(parent) - local header = Gui.header(container, {"toolbar.main-caption"}, {"toolbar.main-tooltip"}, true) + -- Draw the header + local player = Gui.get_player_from_element(parent) + local header = Gui.header(container, { "toolbar.main-caption" }, { "toolbar.main-tooltip" }, true) - -- Draw the toolbar control buttons - local toggle_element = toggle_toolbar(header) - toggle_element.toggled = Gui.get_top_flow(player).visible - reset_toolbar(header) + -- Draw the toolbar control buttons + local toggle_element = toggle_toolbar(header) + toggle_element.toggled = Gui.get_top_flow(player).visible + reset_toolbar(header) - -- Draw toolbar list element - local list_element = toolbar_list(container) - local flow_order = Gui.get_top_flow_order(player) + -- Draw toolbar list element + local list_element = toolbar_list(container) + local flow_order = Gui.get_top_flow_order(player) - for _, element_define in ipairs(flow_order) do - -- Ensure the element exists - local element = list_element[element_define.name] - if not element then - element = toolbar_list_item(list_element, element_define) + for _, element_define in ipairs(flow_order) do + -- Ensure the element exists + local element = list_element[element_define.name] + if not element then + element = toolbar_list_item(list_element, element_define) + end + + -- Set the visible state + local allowed = element_define.authenticator + if type(allowed) == "function" then allowed = allowed(player) end + element.visible = allowed or false end - -- Set the visible state - local allowed = element_define.authenticator - if type(allowed) == 'function' then allowed = allowed(player) end - element.visible = allowed or false - end + -- Set the state of the move buttons for the first and last element + local children = list_element.children + children[1].move[move_up.name].enabled = false + children[#children].move[move_down.name].enabled = false - -- Set the state of the move buttons for the first and last element - local children = list_element.children - children[1].move[move_up.name].enabled = false - children[#children].move[move_down.name].enabled = false - - -- Return the external container - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow(false) + -- Return the external container + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow(false) --- Set the default value for the datastore local datastore_id_map = {} @@ -353,7 +354,10 @@ for index, element_define in ipairs(Gui.top_elements) do if prev_handler then prev_handler(player, element, event) end -- Kind of hacky but works local frame = Gui.get_left_element(player, toolbar_container) if not frame then return end -- Gui might not be loaded yet - if not frame.container then log(frame.name) log(frame.parent.name) end + if not frame.container then + log(frame.name) + log(frame.parent.name) + end local button = frame.container.scroll.list[element_define.name][element_define.name] local toolbar_button = Gui.get_top_element(player, element_define) copy_style(toolbar_button, button) @@ -521,4 +525,4 @@ ToolbarState:on_save(function(player_name, value) end return { order, favourites, left_flows, top_flow_open } -end) \ No newline at end of file +end) diff --git a/exp_legacy/module/modules/gui/vlayer.lua b/exp_legacy/module/modules/gui/vlayer.lua index c50501bd..f9f11dec 100644 --- a/exp_legacy/module/modules/gui/vlayer.lua +++ b/exp_legacy/module/modules/gui/vlayer.lua @@ -11,13 +11,13 @@ local format_number = require("util").format_number --- @dep util local config = require("modules.exp_legacy.config.vlayer") --- @dep config.vlayer local vlayer = require("modules.exp_legacy.modules.control.vlayer") local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection -local SelectionConvertArea = 'VlayerConvertChest' +local SelectionConvertArea = "VlayerConvertChest" --- Align an aabb to the grid by expanding it local function aabb_align_expand(aabb) return { - left_top = {x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y)}, - right_bottom = {x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y)} + left_top = { x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y) }, + right_bottom = { x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y) }, } end @@ -26,32 +26,32 @@ local vlayer_gui_control_type local vlayer_gui_control_list local vlayer_control_type_list = { - [1] = 'energy', - [2] = 'circuit', - [3] = 'storage_input', - [4] = 'storage_output' + [1] = "energy", + [2] = "circuit", + [3] = "storage_input", + [4] = "storage_output", } local function pos_to_gps_string(pos) - return '[gps=' .. string.format('%.1f', pos.x) .. ',' .. string.format('%.1f', pos.y) .. ']' + return "[gps=" .. string.format("%.1f", pos.x) .. "," .. string.format("%.1f", pos.y) .. "]" end local function format_energy(amount, unit) if amount < 1 then - return '0 ' .. unit + return "0 " .. unit end - local suffix = '' + local suffix = "" local suffix_list = { - ['T'] = 1000000000000, - ['G'] = 1000000000, - ['M'] = 1000000, - ['k'] = 1000 + ["T"] = 1000000000000, + ["G"] = 1000000000, + ["M"] = 1000000, + ["k"] = 1000, } - for letter, limit in pairs (suffix_list) do + for letter, limit in pairs(suffix_list) do if math.abs(amount) >= limit then - amount = string.format('%.1f', amount / limit) + amount = string.format("%.1f", amount / limit) suffix = letter break end @@ -61,14 +61,14 @@ local function format_energy(amount, unit) local formatted = amount while true do - formatted, k = string.gsub(formatted, '^(-?%d+)(%d%d%d)', '%1,%2') + formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", "%1,%2") if (k == 0) then break end end - return formatted .. ' ' .. suffix .. unit + return formatted .. " " .. suffix .. unit end --- When an area is selected to add protection to the area @@ -80,17 +80,16 @@ Selection.on_selection(SelectionConvertArea, function(event) return nil end - local entities = player.surface.find_entities_filtered{area=area, name='steel-chest', force=player.force} + local entities = player.surface.find_entities_filtered{ area = area, name = "steel-chest", force = player.force } local frame = Gui.get_left_element(player, vlayer_container) - local disp = frame.container['vlayer_st_2'].disp.table + local disp = frame.container["vlayer_st_2"].disp.table local target = vlayer_control_type_list[disp[vlayer_gui_control_type.name].selected_index] if #entities == 0 then - player.print{'vlayer.steel-chest-detect'} + player.print{ "vlayer.steel-chest-detect" } return nil - elseif #entities > 1 then - player.print{'vlayer.result-unable', {'vlayer.control-type-' .. target:gsub('_', '-')}, {'vlayer.result-multiple'}} + player.print{ "vlayer.result-unable", { "vlayer.control-type-" .. target:gsub("_", "-") }, { "vlayer.result-multiple" } } return nil end @@ -99,222 +98,219 @@ Selection.on_selection(SelectionConvertArea, function(event) end 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 if not e.get_inventory(defines.inventory.chest).is_empty() then - player.print{'vlayer.steel-chest-empty'} + player.print{ "vlayer.steel-chest-empty" } return nil end if (vlayer.get_interface_counts()[target] >= config.interface_limit[target]) then - player.print{'vlayer.result-unable', {'vlayer.control-type-' .. target:gsub('_', '-')}, {'vlayer.result-limit'}} + player.print{ "vlayer.result-unable", { "vlayer.control-type-" .. target:gsub("_", "-") }, { "vlayer.result-limit" } } return nil end e.destroy() - if target == 'energy' then + if target == "energy" then if not vlayer.create_energy_interface(player.surface, e_pos, player) then - player.print{'vlayer.result-unable', {'vlayer.control-type-energy'}, {'vlayer.result-space'}} + player.print{ "vlayer.result-unable", { "vlayer.control-type-energy" }, { "vlayer.result-space" } } return nil end - - elseif target == 'circuit' then + elseif target == "circuit" then vlayer.create_circuit_interface(player.surface, e_pos, e_circ, player) - - elseif target == 'storage_input' then + elseif target == "storage_input" then vlayer.create_input_interface(player.surface, e_pos, e_circ, player) - - elseif target == 'storage_output' then + elseif target == "storage_output" then vlayer.create_output_interface(player.surface, e_pos, e_circ, player) end - game.print{'vlayer.interface-result', player.name, pos_to_gps_string(e_pos), {'vlayer.result-build'}, {'vlayer.control-type-' .. target:gsub('_', '-')}} + game.print{ "vlayer.interface-result", player.name, pos_to_gps_string(e_pos), { "vlayer.result-build" }, { "vlayer.control-type-" .. target:gsub("_", "-") } } end) --- Display label for the number of solar panels -- @element vlayer_gui_display_item_solar_name local vlayer_gui_display_item_solar_name = -Gui.element{ - type = 'label', - name = 'vlayer_display_item_solar_name', - caption = {'vlayer.display-item-solar'}, - style = 'heading_2_label' -}:style{ - width = 200 -} + Gui.element{ + type = "label", + name = "vlayer_display_item_solar_name", + caption = { "vlayer.display-item-solar" }, + style = "heading_2_label", + }:style{ + width = 200, + } local vlayer_gui_display_item_solar_count = -Gui.element{ - type = 'progressbar', - name = 'vlayer_display_item_solar_count', - caption = '', - value = 0, - style = 'electric_satisfaction_statistics_progressbar' -}:style{ - width = 200, - font = 'heading-2' -} + Gui.element{ + type = "progressbar", + name = "vlayer_display_item_solar_count", + caption = "", + value = 0, + style = "electric_satisfaction_statistics_progressbar", + }:style{ + width = 200, + font = "heading-2", + } --- Display label for the number of accumulators -- @element vlayer_gui_display_item_accumulator_name local vlayer_gui_display_item_accumulator_name = -Gui.element{ - type = 'label', - name = 'vlayer_display_item_accumulator_name', - caption = {'vlayer.display-item-accumulator'}, - style = 'heading_2_label' -}:style{ - width = 200 -} + Gui.element{ + type = "label", + name = "vlayer_display_item_accumulator_name", + caption = { "vlayer.display-item-accumulator" }, + style = "heading_2_label", + }:style{ + width = 200, + } local vlayer_gui_display_item_accumulator_count = -Gui.element{ - type = 'progressbar', - name = 'vlayer_display_item_accumulator_count', - caption = '', - value = 0, - style = 'electric_satisfaction_statistics_progressbar' -}:style{ - width = 200, - font = 'heading-2' -} + Gui.element{ + type = "progressbar", + name = "vlayer_display_item_accumulator_count", + caption = "", + value = 0, + style = "electric_satisfaction_statistics_progressbar", + }:style{ + width = 200, + font = "heading-2", + } --- Display label for the remaining surface area -- @element vlayer_gui_display_signal_remaining_surface_area_name local vlayer_gui_display_signal_remaining_surface_area_name = -Gui.element{ - type = 'label', - name = 'vlayer_display_signal_remaining_surface_area_name', - caption = {'vlayer.display-remaining-surface-area'}, - tooltip = {'vlayer.display-remaining-surface-area-tooltip'}, - style = 'heading_2_label' -}:style{ - width = 200 -} + Gui.element{ + type = "label", + name = "vlayer_display_signal_remaining_surface_area_name", + caption = { "vlayer.display-remaining-surface-area" }, + tooltip = { "vlayer.display-remaining-surface-area-tooltip" }, + style = "heading_2_label", + }:style{ + width = 200, + } local vlayer_gui_display_signal_remaining_surface_area_count = -Gui.element{ - type = 'label', - name = 'vlayer_display_signal_remaining_surface_area_count', - caption = '0', - style = 'heading_2_label' -}:style{ - width = 200, - height = 28, - horizontal_align = 'right' -} + Gui.element{ + type = "label", + name = "vlayer_display_signal_remaining_surface_area_count", + caption = "0", + style = "heading_2_label", + }:style{ + width = 200, + height = 28, + horizontal_align = "right", + } --- Display label for the sustained energy production -- @element vlayer_gui_display_signal_sustained_name local vlayer_gui_display_signal_sustained_name = -Gui.element{ - type = 'label', - name = 'vlayer_display_signal_sustained_name', - caption = {'vlayer.display-sustained-production'}, - tooltip = {'vlayer.display-sustained-production-tooltip'}, - style = 'heading_2_label' -}:style{ - width = 200 -} + Gui.element{ + type = "label", + name = "vlayer_display_signal_sustained_name", + caption = { "vlayer.display-sustained-production" }, + tooltip = { "vlayer.display-sustained-production-tooltip" }, + style = "heading_2_label", + }:style{ + width = 200, + } local vlayer_gui_display_signal_sustained_count = -Gui.element{ - type = 'label', - name = 'vlayer_display_signal_sustained_count', - caption = '0', - style = 'heading_2_label' -}:style{ - width = 200, - height = 28, - horizontal_align = 'right' -} + Gui.element{ + type = "label", + name = "vlayer_display_signal_sustained_count", + caption = "0", + style = "heading_2_label", + }:style{ + width = 200, + height = 28, + horizontal_align = "right", + } --- Display label for the current energy production -- @element vlayer_gui_display_signal_production_name local vlayer_gui_display_signal_production_name = -Gui.element{ - type = 'label', - name = 'vlayer_display_signal_production_name', - caption = {'vlayer.display-current-production'}, - tooltip = {'vlayer.display-current-production-tooltip'}, - style = 'heading_2_label' -}:style{ - width = 200 -} + Gui.element{ + type = "label", + name = "vlayer_display_signal_production_name", + caption = { "vlayer.display-current-production" }, + tooltip = { "vlayer.display-current-production-tooltip" }, + style = "heading_2_label", + }:style{ + width = 200, + } local vlayer_gui_display_signal_production_count = -Gui.element{ - type = 'progressbar', - name = 'vlayer_display_signal_production_count', - caption = '', - value = 0, - style = 'electric_satisfaction_statistics_progressbar' -}:style{ - width = 200, - font = 'heading-2' -} + Gui.element{ + type = "progressbar", + name = "vlayer_display_signal_production_count", + caption = "", + value = 0, + style = "electric_satisfaction_statistics_progressbar", + }:style{ + width = 200, + font = "heading-2", + } --- Display label for the sustained energy capacity -- @element vlayer_gui_display_signal_capacity_name local vlayer_gui_display_signal_capacity_name = -Gui.element{ - type = 'label', - name = 'vlayer_display_signal_capacity_name', - caption = {'vlayer.display-current-capacity'}, - tooltip = {'vlayer.display-current-capacity-tooltip'}, - style = 'heading_2_label' -}:style{ - width = 200 -} + Gui.element{ + type = "label", + name = "vlayer_display_signal_capacity_name", + caption = { "vlayer.display-current-capacity" }, + tooltip = { "vlayer.display-current-capacity-tooltip" }, + style = "heading_2_label", + }:style{ + width = 200, + } local vlayer_gui_display_signal_capacity_count = -Gui.element{ - type = 'progressbar', - name = 'vlayer_display_signal_capacity_count', - caption = '', - value = 0, - style = 'electric_satisfaction_statistics_progressbar' -}:style{ - width = 200, - font = 'heading-2' -} + Gui.element{ + type = "progressbar", + name = "vlayer_display_signal_capacity_count", + caption = "", + value = 0, + style = "electric_satisfaction_statistics_progressbar", + }:style{ + width = 200, + font = "heading-2", + } --- A vertical flow containing all the displays labels and their counts -- @element vlayer_display_set local vlayer_display_set = -Gui.element(function(_, parent, name) - local vlayer_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(vlayer_set, 400, 2, 'disp') + Gui.element(function(_, parent, name) + local vlayer_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(vlayer_set, 400, 2, "disp") - vlayer_gui_display_item_solar_name(disp) - vlayer_gui_display_item_solar_count(disp) - vlayer_gui_display_item_accumulator_name(disp) - vlayer_gui_display_item_accumulator_count(disp) - vlayer_gui_display_signal_remaining_surface_area_name(disp) - vlayer_gui_display_signal_remaining_surface_area_count(disp) - vlayer_gui_display_signal_sustained_name(disp) - vlayer_gui_display_signal_sustained_count(disp) - vlayer_gui_display_signal_production_name(disp) - vlayer_gui_display_signal_production_count(disp) - vlayer_gui_display_signal_capacity_name(disp) - vlayer_gui_display_signal_capacity_count(disp) + vlayer_gui_display_item_solar_name(disp) + vlayer_gui_display_item_solar_count(disp) + vlayer_gui_display_item_accumulator_name(disp) + vlayer_gui_display_item_accumulator_count(disp) + vlayer_gui_display_signal_remaining_surface_area_name(disp) + vlayer_gui_display_signal_remaining_surface_area_count(disp) + vlayer_gui_display_signal_sustained_name(disp) + vlayer_gui_display_signal_sustained_count(disp) + vlayer_gui_display_signal_production_name(disp) + vlayer_gui_display_signal_production_count(disp) + vlayer_gui_display_signal_capacity_name(disp) + vlayer_gui_display_signal_capacity_count(disp) - return vlayer_set -end) + return vlayer_set + end) local function vlayer_gui_list_refresh(player) local frame = Gui.get_left_element(player, vlayer_container) - local disp = frame.container['vlayer_st_2'].disp.table + local disp = frame.container["vlayer_st_2"].disp.table local target = disp[vlayer_gui_control_type.name].selected_index local full_list = {} if target then local interface = vlayer.get_interfaces()[vlayer_control_type_list[target]] - for i=1, vlayer.get_interface_counts()[vlayer_control_type_list[target]], 1 do - table.insert(full_list, i .. ' X ' .. interface[i].position.x .. ' Y '.. interface[i].position.y) + for i = 1, vlayer.get_interface_counts()[vlayer_control_type_list[target]], 1 do + table.insert(full_list, i .. " X " .. interface[i].position.x .. " Y " .. interface[i].position.y) end disp[vlayer_gui_control_list.name].items = full_list @@ -324,160 +320,160 @@ end --- A drop down list filter by this type -- @element vlayer_gui_control_type vlayer_gui_control_type = -Gui.element{ - type = 'drop-down', - name = Gui.unique_static_name, - items = {{'vlayer.control-type-energy'}, {'vlayer.control-type-circuit'}, {'vlayer.control-type-storage-input'}, {'vlayer.control-type-storage-output'}}, - selected_index = 1 -}:style{ - width = 200 -}:on_selection_changed(function(player, _, _) - vlayer_gui_list_refresh(player) -end) + Gui.element{ + type = "drop-down", + name = Gui.unique_static_name, + items = { { "vlayer.control-type-energy" }, { "vlayer.control-type-circuit" }, { "vlayer.control-type-storage-input" }, { "vlayer.control-type-storage-output" } }, + selected_index = 1, + }:style{ + width = 200, + }:on_selection_changed(function(player, _, _) + vlayer_gui_list_refresh(player) + end) --- A drop down list to see the exact item to remove -- @element vlayer_gui_control_list vlayer_gui_control_list = -Gui.element{ - type = 'drop-down', - name = Gui.unique_static_name -}:style{ - width = 200 -} + Gui.element{ + type = "drop-down", + name = Gui.unique_static_name, + }:style{ + width = 200, + } --- A button to refresh the remove list -- @element vlayer_gui_control_refresh local vlayer_gui_control_refresh = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = {'vlayer.control-refresh'} -}:style{ - width = 200 -}:on_click(function(player, _, _) - vlayer_gui_list_refresh(player) -end) + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "vlayer.control-refresh" }, + }:style{ + width = 200, + }:on_click(function(player, _, _) + vlayer_gui_list_refresh(player) + end) --- A button to check if the item is the one wanted to remove -- @element vlayer_gui_control_see local vlayer_gui_control_see = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = {'vlayer.control-see'} -}:style{ - width = 200 -}:on_click(function(player, element, _) - local target = element.parent[vlayer_gui_control_type.name].selected_index - local n = element.parent[vlayer_gui_control_list.name].selected_index + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "vlayer.control-see" }, + }:style{ + width = 200, + }:on_click(function(player, element, _) + local target = element.parent[vlayer_gui_control_type.name].selected_index + local n = element.parent[vlayer_gui_control_list.name].selected_index - if target and vlayer_control_type_list[target] and n > 0 then - local i = vlayer.get_interfaces() + if target and vlayer_control_type_list[target] and n > 0 then + local i = vlayer.get_interfaces() - if i and i[vlayer_control_type_list[target]] and i[vlayer_control_type_list[target]][n] then - local pos = i[vlayer_control_type_list[target]][n].position + if i and i[vlayer_control_type_list[target]] and i[vlayer_control_type_list[target]][n] then + local pos = i[vlayer_control_type_list[target]][n].position - if pos then - player.zoom_to_world(pos, 2) - player.print{'vlayer.result-interface-location', {'vlayer.control-type-' .. vlayer_control_type_list[target]:gsub('_', '-')}, pos_to_gps_string(pos)} + if pos then + player.zoom_to_world(pos, 2) + player.print{ "vlayer.result-interface-location", { "vlayer.control-type-" .. vlayer_control_type_list[target]:gsub("_", "-") }, pos_to_gps_string(pos) } + end end end - end -end) + end) --- A button used to build the vlayer interface -- @element vlayer_gui_control_build local vlayer_gui_control_build = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = {'vlayer.control-build'} -}:style{ - width = 200 -}:on_click(function(player, _, _) - if Selection.is_selecting(player, SelectionConvertArea) then - Selection.stop(player) - else - Selection.start(player, SelectionConvertArea) - player.print{'expcom-waterfill.entered-area-selection'} - end + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "vlayer.control-build" }, + }:style{ + width = 200, + }:on_click(function(player, _, _) + if Selection.is_selecting(player, SelectionConvertArea) then + Selection.stop(player) + else + Selection.start(player, SelectionConvertArea) + player.print{ "expcom-waterfill.entered-area-selection" } + end - vlayer_gui_list_refresh(player) -end) + vlayer_gui_list_refresh(player) + end) --- A button used to remove the vlayer interface -- @element vlayer_gui_control_remove local vlayer_gui_control_remove = -Gui.element{ - type = 'button', - name = Gui.unique_static_name, - caption = {'vlayer.control-remove'} -}:style{ - width = 200 -}:on_click(function(player, element, _) - local target = element.parent[vlayer_gui_control_type.name].selected_index - local n = element.parent[vlayer_gui_control_list.name].selected_index + Gui.element{ + type = "button", + name = Gui.unique_static_name, + caption = { "vlayer.control-remove" }, + }:style{ + width = 200, + }:on_click(function(player, element, _) + local target = element.parent[vlayer_gui_control_type.name].selected_index + local n = element.parent[vlayer_gui_control_list.name].selected_index - if target and vlayer_control_type_list[target] and n > 0 then - local i = vlayer.get_interfaces() + if target and vlayer_control_type_list[target] and n > 0 then + local i = vlayer.get_interfaces() - if i and i[vlayer_control_type_list[target]] then - local interface_type, interface_position = vlayer.remove_interface(i[vlayer_control_type_list[target]][n].surface, i[vlayer_control_type_list[target]][n].position) + if i and i[vlayer_control_type_list[target]] then + local interface_type, interface_position = vlayer.remove_interface(i[vlayer_control_type_list[target]][n].surface, i[vlayer_control_type_list[target]][n].position) - if interface_type then - game.print{'vlayer.interface-result', player.name, pos_to_gps_string(interface_position), {'vlayer.result-remove'}, {'vlayer.control-type-' .. interface_type}} + if interface_type then + game.print{ "vlayer.interface-result", player.name, pos_to_gps_string(interface_position), { "vlayer.result-remove" }, { "vlayer.control-type-" .. interface_type } } + end end end - end - vlayer_gui_list_refresh(player) -end) + vlayer_gui_list_refresh(player) + end) --- A vertical flow containing all the control buttons -- @element vlayer_control_set local vlayer_control_set = -Gui.element(function(_, parent, name) - local vlayer_set = parent.add{type='flow', direction='vertical', name=name} - local disp = Gui.scroll_table(vlayer_set, 400, 2, 'disp') + Gui.element(function(_, parent, name) + local vlayer_set = parent.add{ type = "flow", direction = "vertical", name = name } + local disp = Gui.scroll_table(vlayer_set, 400, 2, "disp") - vlayer_gui_control_type(disp) - vlayer_gui_control_list(disp) - vlayer_gui_control_refresh(disp) - vlayer_gui_control_see(disp) - vlayer_gui_control_build(disp) - vlayer_gui_control_remove(disp) + vlayer_gui_control_type(disp) + vlayer_gui_control_list(disp) + vlayer_gui_control_refresh(disp) + vlayer_gui_control_see(disp) + vlayer_gui_control_build(disp) + vlayer_gui_control_remove(disp) - return vlayer_set -end) + return vlayer_set + end) --- The main container for the vlayer gui -- @element vlayer_container vlayer_container = -Gui.element(function(definition, parent) - local player = Gui.get_player_from_element(parent) - local container = Gui.container(parent, definition.name, 400) + Gui.element(function(definition, parent) + local player = Gui.get_player_from_element(parent) + local container = Gui.container(parent, definition.name, 400) - vlayer_display_set(container, 'vlayer_st_1') - local control_set = vlayer_control_set(container, 'vlayer_st_2') - control_set.visible = Roles.player_allowed(player, 'gui/vlayer-edit') + vlayer_display_set(container, "vlayer_st_1") + local control_set = vlayer_control_set(container, "vlayer_st_2") + control_set.visible = Roles.player_allowed(player, "gui/vlayer-edit") - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() --- Button on the top flow used to toggle the task list container -- @element toggle_left_element -Gui.left_toolbar_button('entity/solar-panel', {'vlayer.main-tooltip'}, vlayer_container, function(player) - return Roles.player_allowed(player, 'gui/vlayer') +Gui.left_toolbar_button("entity/solar-panel", { "vlayer.main-tooltip" }, vlayer_container, function(player) + return Roles.player_allowed(player, "gui/vlayer") end) --- Update the visibly of the buttons based on a players roles local function role_update_event(event) local player = game.players[event.player_index] - local visible = Roles.player_allowed(player, 'gui/vlayer-edit') + local visible = Roles.player_allowed(player, "gui/vlayer-edit") local frame = Gui.get_left_element(player, vlayer_container) - frame.container['vlayer_st_2'].visible = visible + frame.container["vlayer_st_2"].visible = visible end Event.add(Roles.events.on_role_assigned, role_update_event) @@ -490,32 +486,32 @@ Event.on_nth_tick(config.update_tick_gui, function(_) local vlayer_display = { [vlayer_gui_display_item_solar_count.name] = { - val = (items_alloc['solar-panel'] / math.max(items['solar-panel'], 1)), - cap = format_number(items_alloc['solar-panel']) .. ' / ' .. format_number(items['solar-panel']) + val = (items_alloc["solar-panel"] / math.max(items["solar-panel"], 1)), + cap = format_number(items_alloc["solar-panel"]) .. " / " .. format_number(items["solar-panel"]), }, [vlayer_gui_display_item_accumulator_count.name] = { - val = (items_alloc['accumulator'] / math.max(items['accumulator'], 1)), - cap = format_number(items_alloc['accumulator']) .. ' / ' .. format_number(items['accumulator']) + val = (items_alloc["accumulator"] / math.max(items["accumulator"], 1)), + cap = format_number(items_alloc["accumulator"]) .. " / " .. format_number(items["accumulator"]), }, [vlayer_gui_display_signal_remaining_surface_area_count.name] = { - cap = format_number(stats.remaining_surface_area) + cap = format_number(stats.remaining_surface_area), }, [vlayer_gui_display_signal_sustained_count.name] = { - cap = format_energy(stats.energy_sustained, 'W') + cap = format_energy(stats.energy_sustained, "W"), }, [vlayer_gui_display_signal_production_count.name] = { val = (stats.energy_production / math.max(stats.energy_max, 1)), - cap = format_energy(stats.energy_production, 'W') .. ' / ' .. format_energy(stats.energy_max, 'W') + cap = format_energy(stats.energy_production, "W") .. " / " .. format_energy(stats.energy_max, "W"), }, [vlayer_gui_display_signal_capacity_count.name] = { val = (stats.energy_storage / math.max(stats.energy_capacity, 1)), - cap = format_energy(stats.energy_storage, 'J') .. ' / ' .. format_energy(stats.energy_capacity, 'J') - } + cap = format_energy(stats.energy_storage, "J") .. " / " .. format_energy(stats.energy_capacity, "J"), + }, } for _, player in pairs(game.connected_players) do local frame = Gui.get_left_element(player, vlayer_container) - local disp = frame.container['vlayer_st_1'].disp.table + local disp = frame.container["vlayer_st_1"].disp.table for k, v in pairs(vlayer_display) do disp[k].caption = v.cap diff --git a/exp_legacy/module/modules/gui/warp-list.lua b/exp_legacy/module/modules/gui/warp-list.lua index 19fbdea9..146a0e35 100644 --- a/exp_legacy/module/modules/gui/warp-list.lua +++ b/exp_legacy/module/modules/gui/warp-list.lua @@ -15,11 +15,11 @@ local Warps = require("modules.exp_legacy.modules.control.warps") --- @dep modul local format_time, player_return = _C.format_time, _C.player_return --- @dep expcore.common --- Stores all data for the warp gui -local WrapGuiData = Datastore.connect('WrapGuiData') +local WrapGuiData = Datastore.connect("WrapGuiData") WrapGuiData:set_serializer(Datastore.name_serializer) -local PlayerInRange = WrapGuiData:combine('PlayerInRange') +local PlayerInRange = WrapGuiData:combine("PlayerInRange") PlayerInRange:set_default(false) -local PlayerCooldown = WrapGuiData:combine('PlayerCooldown') +local PlayerCooldown = WrapGuiData:combine("PlayerCooldown") PlayerCooldown:set_default(0) --- Table that stores a boolean value of weather to keep the warp gui open @@ -31,23 +31,23 @@ end) --- Styles used for sprite buttons local Styles = { sprite22 = { height = 22, width = 22, padding = -2 }, - sprite32 = { height = 32, width = 32, left_margin = 1 } + sprite32 = { height = 32, width = 32, left_margin = 1 }, } --- Status icon of a warp local warp_status_icons = { - cooldown = '[img=utility/multiplayer_waiting_icon]', - not_available = '[img=utility/set_bar_slot]', - bypass = '[img=utility/side_menu_bonus_icon]', - current = '[img=utility/side_menu_map_icon]', - connected = '[img=utility/logistic_network_panel_white]', - different = '[img=utility/warning_white]', + cooldown = "[img=utility/multiplayer_waiting_icon]", + not_available = "[img=utility/set_bar_slot]", + bypass = "[img=utility/side_menu_bonus_icon]", + current = "[img=utility/side_menu_map_icon]", + connected = "[img=utility/logistic_network_panel_white]", + different = "[img=utility/warning_white]", } --- Returns if a player is allowed to edit the given warp --- If a player is allowed to use the edit buttons local function check_player_permissions(player, action, warp) -- Check if the action is allow edit and then check bypass settings - if action == 'allow_edit_warp' then + if action == "allow_edit_warp" then -- Check if the warp is the spawn then it cant be edited local spawn_id = Warps.get_spawn_warp_id(player.force.name) if spawn_id == warp.warp_id then @@ -62,12 +62,12 @@ local function check_player_permissions(player, action, warp) -- Check player has permission based on value in the config local action_config = config[action] - if action_config == 'all' then + if action_config == "all" then return true - elseif action_config == 'admin' then + elseif action_config == "admin" then return player.admin - elseif action_config == 'expcore.roles' then - return Roles.player_allowed(player, config['expcore_roles_'..action]) + elseif action_config == "expcore.roles" then + return Roles.player_allowed(player, config["expcore_roles_" .. action]) end -- Return false as all other conditions have not been met @@ -77,346 +77,345 @@ end --- Will add a new warp to the list, checks if the player is too close to an existing one -- @element add_new_warp local add_new_warp = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/add', - tooltip = {'warp-list.add-tooltip'}, - style = 'shortcut_bar_button', - name = Gui.unique_static_name -} -:style(Styles.sprite22) -:on_click(function(player, _) - -- Add the new warp - local force_name = player.force.name - local surface = player.surface - local position = player.position - - -- Check if the warp is too close to water - local water_tiles = surface.find_tiles_filtered{ collision_mask = "water-tile", radius = config.standard_proximity_radius + 1, position = position } - if #water_tiles > 0 then - player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-water', config.standard_proximity_radius + 1}}, 'orange_red', player) - if game.player then game.player.play_sound{ path = 'utility/wire_pickup' } end - for _, tile in pairs(water_tiles) do - rendering.draw_sprite{ - sprite = 'utility/rail_path_not_possible', - x_scale = 0.5, - y_scale = 0.5, - target = tile.position, - surface = surface, - players = {player}, - time_to_live = 60 - } - end - return - end - - -- Check if there are player entities in the way (has a bigger radius because the enities that can be placed by a player are larger) - local entities = surface.find_entities_filtered{ - radius = config.standard_proximity_radius + 2.5, - position = position, - collision_mask = { - 'item', 'object', 'player', 'water_tile' - } + Gui.element{ + type = "sprite-button", + sprite = "utility/add", + tooltip = { "warp-list.add-tooltip" }, + style = "shortcut_bar_button", + name = Gui.unique_static_name, } - -- Remove 1 because that is the current player - if #entities > 1 then - player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-entities', config.standard_proximity_radius + 2.5}}, 'orange_red', player) - if game.player then game.player.play_sound{path='utility/wire_pickup'} end - local character = player.character - for _, entity in pairs(entities) do - if entity ~= character then + :style(Styles.sprite22) + :on_click(function(player, _) + -- Add the new warp + local force_name = player.force.name + local surface = player.surface + local position = player.position + + -- Check if the warp is too close to water + local water_tiles = surface.find_tiles_filtered{ collision_mask = "water-tile", radius = config.standard_proximity_radius + 1, position = position } + if #water_tiles > 0 then + player_return({ "expcore-commands.command-fail", { "warp-list.too-close-to-water", config.standard_proximity_radius + 1 } }, "orange_red", player) + if game.player then game.player.play_sound{ path = "utility/wire_pickup" } end + for _, tile in pairs(water_tiles) do rendering.draw_sprite{ - sprite = 'utility/rail_path_not_possible', + sprite = "utility/rail_path_not_possible", x_scale = 0.5, y_scale = 0.5, - target = entity, + target = tile.position, surface = surface, - players = {player}, - time_to_live = 60 + players = { player }, + time_to_live = 60, } end + + return end - return - end - -- Create the warp - local warp_id = Warps.add_warp(force_name, surface, position, player.name) - Warps.make_warp_tag(warp_id) - Warps.make_warp_area(warp_id) -end) + -- Check if there are player entities in the way (has a bigger radius because the enities that can be placed by a player are larger) + local entities = surface.find_entities_filtered{ + radius = config.standard_proximity_radius + 2.5, + position = position, + collision_mask = { + "item", "object", "player", "water_tile", + }, + } + -- Remove 1 because that is the current player + if #entities > 1 then + player_return({ "expcore-commands.command-fail", { "warp-list.too-close-to-entities", config.standard_proximity_radius + 2.5 } }, "orange_red", player) + if game.player then game.player.play_sound{ path = "utility/wire_pickup" } end + local character = player.character + for _, entity in pairs(entities) do + if entity ~= character then + rendering.draw_sprite{ + sprite = "utility/rail_path_not_possible", + x_scale = 0.5, + y_scale = 0.5, + target = entity, + surface = surface, + players = { player }, + time_to_live = 60, + } + end + end + return + end + + -- Create the warp + local warp_id = Warps.add_warp(force_name, surface, position, player.name) + Warps.make_warp_tag(warp_id) + Warps.make_warp_area(warp_id) + end) --- Warp icon button, this will trigger a warp when the player is able to -- @element warp_icon_button local warp_icon_button = -Gui.element(function(definition, parent, warp) - local warp_position = warp.position + Gui.element(function(definition, parent, warp) + local warp_position = warp.position - -- The SpritePath type is not the same as the SignalID type - local sprite = warp.icon.type .. '/' ..warp.icon.name - if warp.icon.type == 'virtual' then - sprite = 'virtual-signal/' ..warp.icon.name - end + -- The SpritePath type is not the same as the SignalID type + local sprite = warp.icon.type .. "/" .. warp.icon.name + if warp.icon.type == "virtual" then + sprite = "virtual-signal/" .. warp.icon.name + end - -- Draw the element - return parent.add{ - type = 'sprite-button', - sprite = sprite, - name = definition.name, - tooltip = {'warp-list.goto-tooltip', warp_position.x, warp_position.y}, - style = 'slot_button' - } -end) -:style(Styles.sprite32) -:static_name(Gui.unique_static_name) -:on_click(function(player, element, _) - if element.type == 'choose-elem-button' then return end - local warp_id = element.parent.caption - Warps.teleport_player(warp_id, player) + -- Draw the element + return parent.add{ + type = "sprite-button", + sprite = sprite, + name = definition.name, + tooltip = { "warp-list.goto-tooltip", warp_position.x, warp_position.y }, + style = "slot_button", + } + end) + :style(Styles.sprite32) + :static_name(Gui.unique_static_name) + :on_click(function(player, element, _) + if element.type == "choose-elem-button" then return end + local warp_id = element.parent.caption + Warps.teleport_player(warp_id, player) - -- Reset the warp cooldown if the player does not have unlimited warps - if not check_player_permissions(player, 'bypass_warp_cooldown') then - PlayerCooldown:set(player, config.update_smoothing*config.cooldown_duration) - end + -- Reset the warp cooldown if the player does not have unlimited warps + if not check_player_permissions(player, "bypass_warp_cooldown") then + PlayerCooldown:set(player, config.update_smoothing * config.cooldown_duration) + end - PlayerInRange:set(player, warp_id) -end) + PlayerInRange:set(player, warp_id) + end) --- The button that is visible when the warp is in edit state -- @element warp_icon_editing local warp_icon_editing = -Gui.element(function(definition, parent, warp) - return parent.add{ - name = definition.name, - type = 'choose-elem-button', - elem_type = 'signal', - signal = {type = warp.icon.type, name = warp.icon.name}, - tooltip = {'warp-list.goto-edit'} - } -end) -:static_name(Gui.unique_static_name) -:style(Styles.sprite32) + Gui.element(function(definition, parent, warp) + return parent.add{ + name = definition.name, + type = "choose-elem-button", + elem_type = "signal", + signal = { type = warp.icon.type, name = warp.icon.name }, + tooltip = { "warp-list.goto-edit" }, + } + end) + :static_name(Gui.unique_static_name) + :style(Styles.sprite32) --- Warp label, visible if the player is not in edit state -- @element warp_label local warp_label = -Gui.element(function(definition, parent, warp) - local last_edit_name = warp.last_edit_name - local last_edit_time = warp.last_edit_time - -- Draw the element - return parent.add{ - type = 'label', - caption = warp.name, - tooltip = {'warp-list.last-edit', last_edit_name, format_time(last_edit_time)}, - name = definition.name + Gui.element(function(definition, parent, warp) + local last_edit_name = warp.last_edit_name + local last_edit_time = warp.last_edit_time + -- Draw the element + return parent.add{ + type = "label", + caption = warp.name, + tooltip = { "warp-list.last-edit", last_edit_name, format_time(last_edit_time) }, + name = definition.name, + } + end) + :style{ + single_line = true, + left_padding = 2, + right_padding = 2, + horizontally_stretchable = true, } -end) -:style{ - single_line = true, - left_padding = 2, - right_padding = 2, - horizontally_stretchable = true -} -:on_click(function(player, element, _) - local warp_id = element.parent.caption - local warp = Warps.get_warp(warp_id) - local position = warp.position - player.zoom_to_world(position, 1.5) -end) -:static_name(Gui.unique_static_name) + :on_click(function(player, element, _) + local warp_id = element.parent.caption + local warp = Warps.get_warp(warp_id) + local position = warp.position + player.zoom_to_world(position, 1.5) + end) + :static_name(Gui.unique_static_name) --- Warp status, visible if the player is not in edit state --- This will show if the warp is connected or not -- @element warp_status local warp_status = -Gui.element{ - type = 'label', - caption = '[img=utility/electricity_icon_unplugged]', -- Temporary icon - name = Gui.unique_static_name -} -:style{ - -- When editing mode because textbox is larger the icon would move up. - top_padding = 1, - single_line = false, -} + Gui.element{ + type = "label", + caption = "[img=utility/electricity_icon_unplugged]", -- Temporary icon + name = Gui.unique_static_name, + } + :style{ + -- When editing mode because textbox is larger the icon would move up. + top_padding = 1, + single_line = false, + } --- Warp textfield, visible if the player is in edit state -- @element warp_textfield local warp_textfield = -Gui.element(function(definition, parent, warp) - -- Draw the element - return parent.add{ - type = 'textfield', - text = warp.name, - clear_and_focus_on_right_click = true, - name = definition.name + Gui.element(function(definition, parent, warp) + -- Draw the element + return parent.add{ + type = "textfield", + text = warp.name, + clear_and_focus_on_right_click = true, + name = definition.name, + } + end) + :style{ + -- Required fields to make it squashable and strechable. + minimal_width = 10, + maximal_width = 300, + horizontally_squashable = true, + horizontally_stretchable = true, + -- Other styling + height = 22, + padding = -2, + left_margin = 2, + right_margin = 2, } -end) -:style{ - -- Required fields to make it squashable and strechable. - minimal_width = 10, - maximal_width = 300, - horizontally_squashable = true, - horizontally_stretchable = true, - -- Other styling - height = 22, - padding = -2, - left_margin = 2, - right_margin = 2, -} -:on_confirmed(function(player, element, _) - local warp_id = element.parent.caption - local warp_name = element.text - local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_editing.name].elem_value - Warps.set_editing(warp_id, player.name) - Warps.update_warp(warp_id, warp_name, warp_icon, player.name) -end) -:static_name(Gui.unique_static_name) - + :on_confirmed(function(player, element, _) + local warp_id = element.parent.caption + local warp_name = element.text + local warp_icon = element.parent.parent["icon-" .. warp_id][warp_icon_editing.name].elem_value + Warps.set_editing(warp_id, player.name) + Warps.update_warp(warp_id, warp_name, warp_icon, player.name) + end) + :static_name(Gui.unique_static_name) --- Confirms the edit to name or icon of the warp -- @element confirm_edit_button local confirm_edit_button = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/confirm_slot', - tooltip = {'warp-list.confirm-tooltip'}, - style = 'shortcut_bar_button_green', - name = Gui.unique_static_name -} -:style(Styles.sprite22) -:on_click(function(player, element) - local warp_id = element.parent.caption - local warp_name = element.parent.parent['name-'..warp_id][warp_textfield.name].text - local warp_icon = element.parent.parent['icon-'..warp_id][warp_icon_editing.name].elem_value - Warps.set_editing(warp_id, player.name) - Warps.update_warp(warp_id, warp_name, warp_icon, player.name) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/confirm_slot", + tooltip = { "warp-list.confirm-tooltip" }, + style = "shortcut_bar_button_green", + name = Gui.unique_static_name, + } + :style(Styles.sprite22) + :on_click(function(player, element) + local warp_id = element.parent.caption + local warp_name = element.parent.parent["name-" .. warp_id][warp_textfield.name].text + local warp_icon = element.parent.parent["icon-" .. warp_id][warp_icon_editing.name].elem_value + Warps.set_editing(warp_id, player.name) + Warps.update_warp(warp_id, warp_name, warp_icon, player.name) + end) --- Cancels the editing changes of the selected warp name or icon -- @element cancel_edit_button local cancel_edit_button = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/close_black', - tooltip = {'warp-list.cancel-tooltip'}, - style = 'shortcut_bar_button_red', - name = Gui.unique_static_name -} -:style(Styles.sprite22) -:on_click(function(player, element) - local warp_id = element.parent.caption - -- Check if this is the first edit, if so remove the warp. - local warp = Warps.get_warp(warp_id) - if warp.updates == 1 then - Warps.remove_warp(warp_id) - return - end - Warps.set_editing(warp_id, player.name) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/close_black", + tooltip = { "warp-list.cancel-tooltip" }, + style = "shortcut_bar_button_red", + name = Gui.unique_static_name, + } + :style(Styles.sprite22) + :on_click(function(player, element) + local warp_id = element.parent.caption + -- Check if this is the first edit, if so remove the warp. + local warp = Warps.get_warp(warp_id) + if warp.updates == 1 then + Warps.remove_warp(warp_id) + return + end + Warps.set_editing(warp_id, player.name) + end) --- Removes a warp from the list, including the physical area and map tag -- @element remove_warp_button local remove_warp_button = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/trash', - tooltip = {'warp-list.remove-tooltip'}, - style = 'shortcut_bar_button_red', - name = Gui.unique_static_name -} -:style(Styles.sprite22) -:on_click(function(_, element) - local warp_id = element.parent.caption - Warps.remove_warp(warp_id) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/trash", + tooltip = { "warp-list.remove-tooltip" }, + style = "shortcut_bar_button_red", + name = Gui.unique_static_name, + } + :style(Styles.sprite22) + :on_click(function(_, element) + local warp_id = element.parent.caption + Warps.remove_warp(warp_id) + end) --- Opens edit mode for the warp -- @element edit_warp_button local edit_warp_button = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/rename_icon', - tooltip = {'warp-list.edit-tooltip-none'}, - style = 'shortcut_bar_button', - name = Gui.unique_static_name -} -:style(Styles.sprite22) -:on_click(function(player, element) - local warp_id = element.parent.caption - Warps.set_editing(warp_id, player.name, true) -end) + Gui.element{ + type = "sprite-button", + sprite = "utility/rename_icon", + tooltip = { "warp-list.edit-tooltip-none" }, + style = "shortcut_bar_button", + name = Gui.unique_static_name, + } + :style(Styles.sprite22) + :on_click(function(player, element) + local warp_id = element.parent.caption + Warps.set_editing(warp_id, player.name, true) + end) local update_all_warp_elements --- Set of three elements which make up each row of the warp table -- @element add_warp_elements local add_warp_elements = -Gui.element(function(_, parent, warp) - -- Add icon flow, this will contain the warp button and warp icon edit button - local icon_flow = parent.add{ - name = 'icon-'..warp.warp_id, - type = 'flow', - caption = warp.warp_id - } - icon_flow.style.padding = 0 + Gui.element(function(_, parent, warp) + -- Add icon flow, this will contain the warp button and warp icon edit button + local icon_flow = parent.add{ + name = "icon-" .. warp.warp_id, + type = "flow", + caption = warp.warp_id, + } + icon_flow.style.padding = 0 - -- Add the button and the icon edit button - warp_icon_button(icon_flow, warp) - warp_icon_editing(icon_flow, warp) + -- Add the button and the icon edit button + warp_icon_button(icon_flow, warp) + warp_icon_editing(icon_flow, warp) - -- Add name flow, this will contain the warp label and textbox - local name_flow = parent.add{ - type = 'flow', - name = 'name-'..warp.warp_id, - caption = warp.warp_id - } - name_flow.style.padding = 0 + -- Add name flow, this will contain the warp label and textbox + local name_flow = parent.add{ + type = "flow", + name = "name-" .. warp.warp_id, + caption = warp.warp_id, + } + name_flow.style.padding = 0 - -- Add the label and textfield of the warp - warp_status(name_flow) - warp_label(name_flow, warp) - warp_textfield(name_flow, warp) + -- Add the label and textfield of the warp + warp_status(name_flow) + warp_label(name_flow, warp) + warp_textfield(name_flow, warp) + -- Add button flow, this will contain buttons to manage this specific warp + local button_flow = parent.add{ + type = "flow", + name = "button-" .. warp.warp_id, + caption = warp.warp_id, + } + button_flow.style.padding = 0 - -- Add button flow, this will contain buttons to manage this specific warp - local button_flow = parent.add{ - type = 'flow', - name = 'button-'..warp.warp_id, - caption = warp.warp_id - } - button_flow.style.padding = 0 + -- Add both edit state buttons + confirm_edit_button(button_flow) + cancel_edit_button(button_flow) + edit_warp_button(button_flow) + remove_warp_button(button_flow) - -- Add both edit state buttons - confirm_edit_button(button_flow) - cancel_edit_button(button_flow) - edit_warp_button(button_flow) - remove_warp_button(button_flow) - - -- Return the warp flow elements - return { icon_flow, name_flow, button_flow } -end) + -- Return the warp flow elements + return { icon_flow, name_flow, button_flow } + end) -- Removes the three elements that are added as part of the warp base local function remove_warp_elements(parent, warp_id) - Gui.destroy_if_valid(parent['icon-'..warp_id]) - Gui.destroy_if_valid(parent['name-'..warp_id]) - Gui.destroy_if_valid(parent['button-'..warp_id]) + Gui.destroy_if_valid(parent["icon-" .. warp_id]) + Gui.destroy_if_valid(parent["name-" .. warp_id]) + Gui.destroy_if_valid(parent["button-" .. warp_id]) end --- This timer controls when a player is able to warp, eg every 60 seconds -- @element warp_timer local warp_timer = -Gui.element{ - type = 'progressbar', - name = Gui.unique_static_name, - tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration}, - minimum_value = 0, - maximum_value = config.cooldown_duration*config.update_smoothing -} -:style{ - horizontally_stretchable = true, - color = Colors.light_blue -} + Gui.element{ + type = "progressbar", + name = Gui.unique_static_name, + tooltip = { "warp-list.timer-tooltip-zero", config.cooldown_duration }, + minimum_value = 0, + maximum_value = config.cooldown_duration * config.update_smoothing, + } + :style{ + horizontally_stretchable = true, + color = Colors.light_blue, + } local warp_list_container @@ -425,66 +424,66 @@ local function update_warp_elements(element, warp, warp_player_is_on, on_cooldow -- Check if button element is valid if not element or not element.valid then return end - local label_style = element.parent.parent['name-'..warp.warp_id][warp_label.name].style - local warp_status_element = element.parent.parent['name-'..warp.warp_id][warp_status.name] + local label_style = element.parent.parent["name-" .. warp.warp_id][warp_label.name].style + local warp_status_element = element.parent.parent["name-" .. warp.warp_id][warp_status.name] -- If player is not on a warp if not warp_player_is_on then -- If player is allowed to warp without being on a warp. If not then disable the warp location if bypass_warp_proximity then local position = warp.position - element.tooltip = {'warp-list.goto-bypass', position.x, position.y} + element.tooltip = { "warp-list.goto-bypass", position.x, position.y } element.enabled = true - warp_status_element.tooltip = {'warp-list.goto-bypass', position.x, position.y} + warp_status_element.tooltip = { "warp-list.goto-bypass", position.x, position.y } warp_status_element.caption = warp_status_icons.bypass - label_style.font = 'default-semibold' + label_style.font = "default-semibold" else - element.tooltip = {'warp-list.goto-disabled'} + element.tooltip = { "warp-list.goto-disabled" } element.enabled = false - warp_status_element.tooltip = {'warp-list.goto-disabled'} + warp_status_element.tooltip = { "warp-list.goto-disabled" } warp_status_element.caption = warp_status_icons.not_available - label_style.font = 'default' + label_style.font = "default" end - -- If player is on the warp that is being updated + -- If player is on the warp that is being updated elseif warp_player_is_on.warp_id == warp.warp_id then - element.tooltip = {'warp-list.goto-same-warp'} + element.tooltip = { "warp-list.goto-same-warp" } element.enabled = false - warp_status_element.tooltip = {'warp-list.goto-same-warp'} + warp_status_element.tooltip = { "warp-list.goto-same-warp" } warp_status_element.caption = warp_status_icons.current - label_style.font = 'default' - -- If player is on cooldown + label_style.font = "default" + -- If player is on cooldown elseif on_cooldown then - element.tooltip = {'warp-list.goto-cooldown'} + element.tooltip = { "warp-list.goto-cooldown" } element.enabled = false - warp_status_element.tooltip = {'warp-list.goto-cooldown'} + warp_status_element.tooltip = { "warp-list.goto-cooldown" } warp_status_element.caption = warp_status_icons.cooldown - label_style.font = 'default' + label_style.font = "default" else -- If the warp the player is standing on is the same as the warp that is being updated local warp_electric_network_id = warp.electric_pole and warp.electric_pole.electric_network_id or -1 local player_warp_electric_network_id = warp_player_is_on.electric_pole and warp_player_is_on.electric_pole.electric_network_id or -2 if warp_electric_network_id == player_warp_electric_network_id then local position = warp.position - element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} + element.tooltip = { "warp-list.goto-tooltip", position.x, position.y } element.enabled = true - warp_status_element.tooltip = {'warp-list.goto-tooltip', position.x, position.y} + warp_status_element.tooltip = { "warp-list.goto-tooltip", position.x, position.y } warp_status_element.caption = warp_status_icons.connected - label_style.font = 'default-semibold' - -- If the warp is not on the same network but the player is allowed to warp without being on a warp + label_style.font = "default-semibold" + -- If the warp is not on the same network but the player is allowed to warp without being on a warp elseif bypass_warp_proximity then local position = warp.position - element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} + element.tooltip = { "warp-list.goto-bypass-different-network", position.x, position.y } element.enabled = true - warp_status_element.tooltip = {'warp-list.goto-bypass-different-network', position.x, position.y} + warp_status_element.tooltip = { "warp-list.goto-bypass-different-network", position.x, position.y } warp_status_element.caption = warp_status_icons.bypass - label_style.font = 'default-semibold' - -- If the warp is on a different network than the one the player is standing on + label_style.font = "default-semibold" + -- If the warp is on a different network than the one the player is standing on else - element.tooltip = {'warp-list.goto-different-network'} + element.tooltip = { "warp-list.goto-different-network" } element.enabled = false - warp_status_element.tooltip = {'warp-list.goto-different-network'} + warp_status_element.tooltip = { "warp-list.goto-different-network" } warp_status_element.caption = warp_status_icons.different - label_style.font = 'default' + label_style.font = "default" end end end @@ -502,12 +501,12 @@ function update_all_warp_elements(player, timer, warp_id) warp_id = warp_id or PlayerInRange:get(player) local warp_player_is_on = warp_id and Warps.get_warp(warp_id) or nil -- Check player permission - local bypass_warp_proximity = check_player_permissions(player, 'bypass_warp_proximity') + local bypass_warp_proximity = check_player_permissions(player, "bypass_warp_proximity") -- Change the enabled state of the warp buttons local warp_ids = Warps.get_force_warp_ids(player.force.name) for _, next_warp_id in pairs(warp_ids) do - local element = scroll_table['icon-'..next_warp_id][warp_icon_button.name] + local element = scroll_table["icon-" .. next_warp_id][warp_icon_button.name] local next_warp = Warps.get_warp(next_warp_id) update_warp_elements(element, next_warp, warp_player_is_on, on_cooldown, bypass_warp_proximity) end @@ -524,12 +523,12 @@ local function update_warp(player, warp_table, warp_id) end -- Create the warp elements if they do not already exist - if not warp_table['icon-'..warp_id] then + if not warp_table["icon-" .. warp_id] then add_warp_elements(warp_table, warp) end - local icon_flow = warp_table['icon-'..warp_id] - local name_flow = warp_table['name-'..warp_id] - local button_flow = warp_table['button-'..warp_id] + local icon_flow = warp_table["icon-" .. warp_id] + local name_flow = warp_table["name-" .. warp_id] + local button_flow = warp_table["button-" .. warp_id] -- Create local references to the elements for this warp local warp_icon_element = icon_flow[warp_icon_button.name] @@ -545,17 +544,17 @@ local function update_warp(player, warp_table, warp_id) local remove_warp_element = button_flow[remove_warp_button.name] -- Hide the edit button if the player is not allowed to edit the warp - local player_allowed_edit = check_player_permissions(player, 'allow_edit_warp', warp) + local player_allowed_edit = check_player_permissions(player, "allow_edit_warp", warp) local players_editing = table.get_keys(warp.currently_editing) edit_warp_element.visible = player_allowed_edit -- Set the tooltip of the edit button if #players_editing > 0 then - edit_warp_element.hovered_sprite = 'utility/warning_icon' - edit_warp_element.tooltip = {'warp-list.edit-tooltip', table.concat(players_editing, ', ')} + edit_warp_element.hovered_sprite = "utility/warning_icon" + edit_warp_element.tooltip = { "warp-list.edit-tooltip", table.concat(players_editing, ", ") } else edit_warp_element.hovered_sprite = edit_warp_element.sprite - edit_warp_element.tooltip = {'warp-list.edit-tooltip-none'} + edit_warp_element.tooltip = { "warp-list.edit-tooltip-none" } end -- Set the visibility of the warp elements based on whether the user is editing or not @@ -568,7 +567,7 @@ local function update_warp(player, warp_table, warp_id) label_element.visible = false textfield_element.visible = true textfield_element.focus() - warp_table.parent.scroll_to_element(textfield_element, 'top-third') + warp_table.parent.scroll_to_element(textfield_element, "top-third") -- Set the edit buttons cancel_edit_element.visible = true confirm_edit_element.visible = true @@ -579,9 +578,9 @@ local function update_warp(player, warp_table, warp_id) -- Set the icon elements visibility warp_icon_element.visible = true -- The SpritePath type is not the same as the SignalID type - local sprite = warp.icon.type .. '/' ..warp.icon.name - if warp.icon.type == 'virtual' then - sprite = 'virtual-signal/' ..warp.icon.name + local sprite = warp.icon.type .. "/" .. warp.icon.name + if warp.icon.type == "virtual" then + sprite = "virtual-signal/" .. warp.icon.name end warp_icon_element.sprite = sprite -- Set icon edit to the warps icon @@ -603,7 +602,7 @@ local function update_warp(player, warp_table, warp_id) local timer = PlayerCooldown:get(player) local current_warp_id = PlayerInRange:get(player) local to_warp = current_warp_id and Warps.get_warp(current_warp_id) or nil - local bypass_warp_proximity = check_player_permissions(player, 'bypass_warp_proximity') + local bypass_warp_proximity = check_player_permissions(player, "bypass_warp_proximity") update_warp_elements(warp_icon_element, warp, to_warp, timer > 0, bypass_warp_proximity) end @@ -633,77 +632,77 @@ end --- Main warp list container for the left flow -- @element warp_list_container warp_list_container = -Gui.element(function(definition, parent) - local player = Gui.get_player_from_element(parent) - -- Check if user has permission to add warps - local allow_add_warp = check_player_permissions(player, 'allow_add_warp') + Gui.element(function(definition, parent) + local player = Gui.get_player_from_element(parent) + -- Check if user has permission to add warps + local allow_add_warp = check_player_permissions(player, "allow_add_warp") - -- Draw the internal container - local container = Gui.container(parent, definition.name, allow_add_warp and 268 or 220) + -- Draw the internal container + local container = Gui.container(parent, definition.name, allow_add_warp and 268 or 220) - -- Draw the header - local header = Gui.header( - container, - {'warp-list.main-caption'}, - { - 'warp-list.sub-tooltip', - config.cooldown_duration, - config.standard_proximity_radius, - {'warp-list.sub-tooltip-current',warp_status_icons.current}, - {'warp-list.sub-tooltip-connected',warp_status_icons.connected}, - {'warp-list.sub-tooltip-different',warp_status_icons.different}, - {'warp-list.sub-tooltip-cooldown',warp_status_icons.cooldown}, - {'warp-list.sub-tooltip-not_available',warp_status_icons.not_available}, - {'warp-list.sub-tooltip-bypass',warp_status_icons.bypass}, - }, - true - ) + -- Draw the header + local header = Gui.header( + container, + { "warp-list.main-caption" }, + { + "warp-list.sub-tooltip", + config.cooldown_duration, + config.standard_proximity_radius, + { "warp-list.sub-tooltip-current", warp_status_icons.current }, + { "warp-list.sub-tooltip-connected", warp_status_icons.connected }, + { "warp-list.sub-tooltip-different", warp_status_icons.different }, + { "warp-list.sub-tooltip-cooldown", warp_status_icons.cooldown }, + { "warp-list.sub-tooltip-not_available", warp_status_icons.not_available }, + { "warp-list.sub-tooltip-bypass", warp_status_icons.bypass }, + }, + true + ) - -- Draw the new warp button - local add_new_warp_element = add_new_warp(header) - add_new_warp_element.visible = allow_add_warp + -- Draw the new warp button + local add_new_warp_element = add_new_warp(header) + add_new_warp_element.visible = allow_add_warp - -- Draw the scroll table for the warps - local scroll_table = Gui.scroll_table(container, 250, 3) - -- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size) - scroll_table.parent.vertical_scroll_policy = 'always' + -- Draw the scroll table for the warps + local scroll_table = Gui.scroll_table(container, 250, 3) + -- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size) + scroll_table.parent.vertical_scroll_policy = "always" - -- Change the style of the scroll table - local scroll_table_style = scroll_table.style - scroll_table_style.top_cell_padding = 3 - scroll_table_style.bottom_cell_padding = 3 + -- Change the style of the scroll table + local scroll_table_style = scroll_table.style + scroll_table_style.top_cell_padding = 3 + scroll_table_style.bottom_cell_padding = 3 - -- Draw the warp cooldown progress bar - local warp_timer_element = warp_timer(container) + -- Draw the warp cooldown progress bar + local warp_timer_element = warp_timer(container) - -- Change the progress of the warp timer - local timer = PlayerCooldown:get(player) - if timer > 0 then - warp_timer_element.tooltip = {'warp-list.timer-tooltip', math.floor(timer/config.update_smoothing)} - warp_timer_element.value = 1 - (timer/config.update_smoothing/config.cooldown_duration) - else - warp_timer_element.tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration} - warp_timer_element.value = 1 - end + -- Change the progress of the warp timer + local timer = PlayerCooldown:get(player) + if timer > 0 then + warp_timer_element.tooltip = { "warp-list.timer-tooltip", math.floor(timer / config.update_smoothing) } + warp_timer_element.value = 1 - (timer / config.update_smoothing / config.cooldown_duration) + else + warp_timer_element.tooltip = { "warp-list.timer-tooltip-zero", config.cooldown_duration } + warp_timer_element.value = 1 + end - -- Add any existing warps - update_all_warps(player, scroll_table) + -- Add any existing warps + update_all_warps(player, scroll_table) - -- Return the external container - return container.parent -end) -:static_name(Gui.unique_static_name) -:add_to_left_flow() + -- Return the external container + return container.parent + end) + :static_name(Gui.unique_static_name) + :add_to_left_flow() --- Button on the top flow used to toggle the warp list container -- @element toggle_warp_list -Gui.left_toolbar_button(config.default_icon.type ..'/'..config.default_icon.name, {'warp-list.main-tooltip'}, warp_list_container, function(player) - return Roles.player_allowed(player, 'gui/warp-list') -end) -:on_event(Gui.events.on_visibility_changed_by_click, function(player, _,event) - -- Set gui keep open state for player that clicked the button: true if visible, false if invisible - keep_gui_open[player.name] = event.state +Gui.left_toolbar_button(config.default_icon.type .. "/" .. config.default_icon.name, { "warp-list.main-tooltip" }, warp_list_container, function(player) + return Roles.player_allowed(player, "gui/warp-list") end) + :on_event(Gui.events.on_visibility_changed_by_click, function(player, _, event) + -- Set gui keep open state for player that clicked the button: true if visible, false if invisible + keep_gui_open[player.name] = event.state + end) --- When the name of a warp is updated this is triggered Warps.on_update(function(_, warp, old_warp) @@ -736,10 +735,10 @@ PlayerCooldown:on_update(function(player_name, player_cooldown) -- Set the progress if player_cooldown and player_cooldown > 0 then - warp_timer_element.tooltip = {'warp-list.timer-tooltip', math.floor(player_cooldown/config.update_smoothing)} - warp_timer_element.value = 1 - (player_cooldown/config.update_smoothing/config.cooldown_duration) + warp_timer_element.tooltip = { "warp-list.timer-tooltip", math.floor(player_cooldown / config.update_smoothing) } + warp_timer_element.value = 1 - (player_cooldown / config.update_smoothing / config.cooldown_duration) else - warp_timer_element.tooltip = {'warp-list.timer-tooltip-zero', config.cooldown_duration} + warp_timer_element.tooltip = { "warp-list.timer-tooltip-zero", config.cooldown_duration } warp_timer_element.value = 1 end @@ -750,10 +749,10 @@ PlayerCooldown:on_update(function(player_name, player_cooldown) end) --- Handles updating the timer and checking distance from a warp -local r2 = config.standard_proximity_radius^2 -local rs2 = config.spawn_proximity_radius^2 -local mr2 = config.minimum_distance^2 -Event.on_nth_tick(math.floor(60/config.update_smoothing), function() +local r2 = config.standard_proximity_radius ^ 2 +local rs2 = config.spawn_proximity_radius ^ 2 +local mr2 = config.minimum_distance ^ 2 +Event.on_nth_tick(math.floor(60 / config.update_smoothing), function() PlayerCooldown:update_all(function(_, player_cooldown) if player_cooldown > 0 then return player_cooldown - 1 end end) @@ -791,8 +790,8 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing), function() -- Check if the player is within range local warp_pos = warp.position if warp.surface == surface then - local dx, dy = px-warp_pos.x, py-warp_pos.y - local dist = (dx*dx)+(dy*dy) + local dx, dy = px - warp_pos.x, py - warp_pos.y + local dist = (dx * dx) + (dy * dy) if closest_distance == nil or dist < closest_distance then closest_warp = warp closest_distance = dist @@ -806,7 +805,7 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing), function() if was_in_range and not in_range then PlayerInRange:set(player, nil) elseif not was_in_range and in_range then - ---@cast closest_warp -nil + --- @cast closest_warp -nil PlayerInRange:set(player, closest_warp.warp_id) end @@ -818,16 +817,14 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing), function() local can_make_warp = closest_distance == nil or closest_distance > mr2 if can_make_warp and not was_able_to_make_warp then add_warp_element.enabled = true - add_warp_element.tooltip = {'warp-list.add-tooltip'} + add_warp_element.tooltip = { "warp-list.add-tooltip" } elseif not can_make_warp and was_able_to_make_warp or closest_warp and (old_closest_warp_name ~= closest_warp.name) then - ---@cast closest_warp -nil + --- @cast closest_warp -nil add_warp_element.enabled = false - add_warp_element.tooltip = {'warp-list.too-close', closest_warp.name} + add_warp_element.tooltip = { "warp-list.too-close", closest_warp.name } end end - end - end) --- When a player is created make sure that there is a spawn warp created @@ -838,11 +835,11 @@ Event.add(defines.events.on_player_created, function(event) local spawn_id = Warps.get_spawn_warp_id(force.name) if not spawn_id then local spawn_position = force.get_spawn_position(player.surface) - spawn_id = Warps.add_warp(force.name, player.surface, spawn_position, nil, 'Spawn') + spawn_id = Warps.add_warp(force.name, player.surface, spawn_position, nil, "Spawn") Warps.set_spawn_warp(spawn_id, force) Warps.make_warp_tag(spawn_id) - local entities = player.surface.find_entities_filtered{type='electric-pole', position=spawn_position, radius=20, limit=1} + local entities = player.surface.find_entities_filtered{ type = "electric-pole", position = spawn_position, radius = 20, limit = 1 } if entities and entities[1] then local warp = Warps.get_warp(spawn_id) warp.electric_pole = entities[1] @@ -864,7 +861,7 @@ local function role_update_event(event) local container = Gui.get_left_element(player, warp_list_container).container -- Check if user has permission to add warps - local allow_add_warp = check_player_permissions(player, 'allow_add_warp') + local allow_add_warp = check_player_permissions(player, "allow_add_warp") -- Update container size depending on whether the player is allowed to add warps container.parent.style.width = allow_add_warp and 268 or 220 diff --git a/exp_legacy/module/overrides/table.lua b/exp_legacy/module/overrides/table.lua index d9c35483..98f92988 100644 --- a/exp_legacy/module/overrides/table.lua +++ b/exp_legacy/module/overrides/table.lua @@ -1,4 +1,4 @@ ---luacheck:ignore global table +-- luacheck:ignore global table local random = math.random local floor = math.floor local remove = table.remove @@ -66,17 +66,18 @@ function table.array_insert(tbl, start_index, values) if start_index then local starting_length = #tbl local adding_length = #values - local move_to = start_index+adding_length+1 - for offset = starting_length-start_index, 0, -1 do - tbl[move_to+offset] = tbl[starting_length+offset] + local move_to = start_index + adding_length + 1 + for offset = starting_length - start_index, 0, -1 do + tbl[move_to + offset] = tbl[starting_length + offset] end - start_index = start_index-1 + + start_index = start_index - 1 else start_index = #tbl end for offset, item in ipairs(values) do - tbl[start_index+offset] = item + tbl[start_index + offset] = item end return tbl @@ -119,6 +120,7 @@ function table.get_key(t, e) return k end end + return nil end @@ -132,6 +134,7 @@ function table.get_index(t, e) return i end end + return nil end @@ -158,9 +161,10 @@ end -- @return the keys in the order given function table.extract_keys(tbl, ...) local values = {} - for _, key in pairs({...}) do + for _, key in pairs{ ... } do table.insert(values, tbl[key]) end + return table.unpack(values) end @@ -177,7 +181,8 @@ function table.set(t, index, element) end i = i + 1 end - error('Index out of bounds', 2) + + error("Index out of bounds", 2) end --- Chooses a random entry from a table @@ -249,7 +254,7 @@ function table.shuffle_table(t, rng) local rand = rng or math.random local iterations = #t if iterations == 0 then - error('Not a sequential table') + error("Not a sequential table") return end local j @@ -265,19 +270,19 @@ end -- @param x one comparator operand -- @param y the other comparator operand -- @return true if x logically comes before y in a list, false otherwise -local function sortFunc(x, y) --sorts tables with mixed index types. +local function sortFunc(x, y) -- sorts tables with mixed index types. local tx = type(x) local ty = type(y) if tx == ty then - if type(x) == 'string' then + if type(x) == "string" then return string.lower(x) < string.lower(y) else return x < y end - elseif tx == 'number' then - return true --only x is a number and goes first + elseif tx == "number" then + return true -- only x is a number and goes first else - return false --only y is a number and goes first + return false -- only y is a number and goes first end end @@ -290,7 +295,7 @@ function table.get_values(tbl, sorted, as_string) if not tbl then return {} end local valueset = {} local n = 0 - if as_string then --checking as_string /before/ looping is faster + if as_string then -- checking as_string /before/ looping is faster for _, v in pairs(tbl) do n = n + 1 valueset[n] = tostring(v) @@ -316,7 +321,7 @@ function table.get_keys(tbl, sorted, as_string) if not tbl then return {} end local keyset = {} local n = 0 - if as_string then --checking as_string /before/ looping is faster + if as_string then -- checking as_string /before/ looping is faster for k, _ in pairs(tbl) do n = n + 1 keyset[n] = tostring(k) @@ -338,13 +343,17 @@ end -- @treturn table the sorted table function table.alphanumsort(tbl) local o = table.get_keys(tbl) - local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)") - return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end + local function padnum(d) + local dec, n = string.match(d, "(%.?)0*(.+)") + return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) + end table.sort(o, function(a, b) - return tostring(a):gsub("%.?%d+", padnum)..("%3d"):format(#b) - < tostring(b):gsub("%.?%d+", padnum)..("%3d"):format(#a) end) + return tostring(a):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) + < tostring(b):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) + end) local _tbl = {} for _, k in pairs(o) do _tbl[k] = tbl[k] end + return _tbl end @@ -355,6 +364,7 @@ function table.keysort(tbl) local o = table.get_keys(tbl, true) local _tbl = {} for _, k in pairs(o) do _tbl[k] = tbl[k] end + return _tbl end @@ -375,7 +385,7 @@ end end ]] function table.binary_search(t, target) - --For some reason bit32.bnot doesn't return negative numbers so I'm using ~x = -1 - x instead. + -- For some reason bit32.bnot doesn't return negative numbers so I'm using ~x = -1 - x instead. local lower = 1 local upper = #t @@ -434,4 +444,4 @@ table.merge = util.merge -- @return table.equals = table.compare -return table \ No newline at end of file +return table diff --git a/exp_legacy/module/overrides/version.lua b/exp_legacy/module/overrides/version.lua index dd56f2c7..8f2b824c 100644 --- a/exp_legacy/module/overrides/version.lua +++ b/exp_legacy/module/overrides/version.lua @@ -1,5 +1,5 @@ return { - expgaming_lua = '6.2.0', - expgaming_api = '2.0.0', - redmew_lua = '2019-02-24-76871ee' -} \ No newline at end of file + expgaming_lua = "6.2.0", + expgaming_api = "2.0.0", + redmew_lua = "2019-02-24-76871ee", +} diff --git a/exp_legacy/module/utils/event.lua b/exp_legacy/module/utils/event.lua index b39aec93..216eac16 100644 --- a/exp_legacy/module/utils/event.lua +++ b/exp_legacy/module/utils/event.lua @@ -1,7 +1,6 @@ local Clustorio = require("modules/clusterio/api") local ExpUtil = require("modules/exp_util") - local Event = { real_handlers = { events = {}, @@ -14,7 +13,7 @@ local Event = { on_nth_tick = {}, on_init = nil, on_load = nil, - } + }, } local function call_handlers_factory(handlers) @@ -37,7 +36,7 @@ function Event.add(event_name, handler) Event.real_handlers.events[event_name] = call_handlers_factory(handlers) end - handlers[#handlers+1] = handler + handlers[#handlers + 1] = handler end function Event.on_nth_tick(tick, handler) @@ -52,7 +51,7 @@ function Event.on_nth_tick(tick, handler) Event.real_handlers.on_nth_tick[tick] = call_handlers_factory(handlers) end - handlers[#handlers+1] = handler + handlers[#handlers + 1] = handler end function Event.on_init(handler) @@ -66,7 +65,7 @@ function Event.on_init(handler) Event.real_handlers.on_init = call_handlers_factory(handlers) end - handlers[#handlers+1] = handler + handlers[#handlers + 1] = handler Event.add(Clustorio.events.on_server_startup, handler) end @@ -81,7 +80,7 @@ function Event.on_load(handler) Event.real_handlers.on_load = call_handlers_factory(handlers) end - handlers[#handlers+1] = handler + handlers[#handlers + 1] = handler end return Event diff --git a/exp_legacy/module/utils/game.lua b/exp_legacy/module/utils/game.lua index c1fec710..62174cb5 100644 --- a/exp_legacy/module/utils/game.lua +++ b/exp_legacy/module/utils/game.lua @@ -1,4 +1,3 @@ - local Color = require("modules/exp_util/include/color") local Game = {} @@ -27,9 +26,9 @@ always true: game.players[name].name == name; game.players[index].index == index -- obj function Game.get_player_from_any(obj) local o_type, p = type(obj) - if o_type == 'table' then + if o_type == "table" then p = obj - elseif o_type == 'string' or o_type == 'number' then + elseif o_type == "string" or o_type == "number" then p = game.players[obj] end @@ -38,4 +37,4 @@ function Game.get_player_from_any(obj) end end -return Game \ No newline at end of file +return Game diff --git a/exp_legacy/module/utils/gui.lua b/exp_legacy/module/utils/gui.lua index 1e48be7d..49245e8e 100644 --- a/exp_legacy/module/utils/gui.lua +++ b/exp_legacy/module/utils/gui.lua @@ -1,6 +1,6 @@ local Storage = require("modules/exp_util/storage") local Event = require("modules/exp_legacy/utils/event") --- @dep expcore.gui -local mod_gui = require 'mod-gui' --- @dep mod-gui +local mod_gui = require "mod-gui" --- @dep mod-gui local Gui = {} local data = {} @@ -15,7 +15,7 @@ Storage.register( function Gui.uid_name() uid = uid + 1 - return "Redmew_"..uid + return "Redmew_" .. uid end -- Associates data with the LuaGuiElement. If data is nil then removes the data @@ -85,43 +85,43 @@ end -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_checked_state_changed = handler_factory('on_gui_checked_state_changed') +Gui.on_checked_state_changed = handler_factory("on_gui_checked_state_changed") -- Register a handler for the on_gui_click event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_click = handler_factory('on_gui_click') +Gui.on_click = handler_factory("on_gui_click") -- Register a handler for the on_gui_closed event for a custom LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_custom_close = handler_factory('on_gui_closed') +Gui.on_custom_close = handler_factory("on_gui_closed") -- Register a handler for the on_gui_elem_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_elem_changed = handler_factory('on_gui_elem_changed') +Gui.on_elem_changed = handler_factory("on_gui_elem_changed") -- Register a handler for the on_gui_selection_state_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_selection_state_changed = handler_factory('on_gui_selection_state_changed') +Gui.on_selection_state_changed = handler_factory("on_gui_selection_state_changed") -- Register a handler for the on_gui_text_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_text_changed = handler_factory('on_gui_text_changed') +Gui.on_text_changed = handler_factory("on_gui_text_changed") -- Register a handler for the on_gui_value_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_value_changed = handler_factory('on_gui_value_changed') +Gui.on_value_changed = handler_factory("on_gui_value_changed") --- Returns the flow where top elements can be added and will be effected by google visibility -- For the toggle to work it must be registed with Gui.allow_player_to_toggle_top_element_visibility(element_name) @@ -129,4 +129,4 @@ Gui.on_value_changed = handler_factory('on_gui_value_changed') -- @treturn LuaGuiElement the top element flow Gui.get_top_element_flow = mod_gui.get_button_flow -return Gui \ No newline at end of file +return Gui diff --git a/exp_util/module/async.lua b/exp_util/module/async.lua index e1e83da7..487f975f 100644 --- a/exp_util/module/async.lua +++ b/exp_util/module/async.lua @@ -80,13 +80,13 @@ local Async = { -- @event on_function_complete -- @tparam AsyncFunction async_id The function which finished execution, comparable to the return of register -- @tparam table return_values An array representing the values returned by the completed function - on_function_complete = script.generate_event_name() + on_function_complete = script.generate_event_name(), } Async._metatable = { __call = function(self, ...) Async._prototype.start_soon(self, ...) end, __index = Async._prototype, - __class = "AsyncFunction" + __class = "AsyncFunction", } script.register_metatable("AsyncFunction", Async._metatable) @@ -98,16 +98,17 @@ local on_tick_mutex = false -- It is not safe to modify the globals while this v --- Insert an item into the priority queue local function add_to_queue(pending) - local tick = pending.tick - for index = #async_queue, 1, -1 do - if async_queue[index].tick >= tick then - async_queue[index + 1] = pending - return - else - async_queue[index + 1] = async_queue[index] - end - end - async_queue[1] = pending + local tick = pending.tick + for index = #async_queue, 1, -1 do + if async_queue[index].tick >= tick then + async_queue[index + 1] = pending + return + else + async_queue[index + 1] = async_queue[index] + end + end + + async_queue[1] = pending end --- Static Methods. @@ -119,7 +120,7 @@ end -- @treturn AsyncFunction The newly registered async function function Async.register(func) ExpUtil.assert_not_runtime() - ExpUtil.assert_argument_type(func, "function", 1, "func") + ExpUtil.assert_argument_type(func, "function", 1, "func") local id = ExpUtil.get_function_name(func) Async._functions[id] = func @@ -135,13 +136,13 @@ end --- Run an async function on the next tick, this is the default and can be used to bypass permission groups -- @param ... The arguments to call the function with function Async._prototype:start_soon(...) - assert(not on_tick_mutex, "Cannot queue new async call during execution of another") + assert(not on_tick_mutex, "Cannot queue new async call during execution of another") assert(Async._functions[self.id], "Async function is not registered") Async._queue_pressure[self.id] = Async._queue_pressure[self.id] + 1 async_next[#async_next + 1] = { id = self.id, - args = {...} + args = { ... }, } end @@ -149,22 +150,22 @@ end -- @tparam number ticks The number of ticks to call the function after -- @param ... The arguments to call the function with function Async._prototype:start_after(ticks, ...) - ExpUtil.assert_argument_type(ticks, "number", 1, "ticks") - assert(not on_tick_mutex, "Cannot queue new async call during execution of another") + ExpUtil.assert_argument_type(ticks, "number", 1, "ticks") + assert(not on_tick_mutex, "Cannot queue new async call during execution of another") assert(Async._functions[self.id], "Async function is not registered") Async._queue_pressure[self.id] = Async._queue_pressure[self.id] + 1 - add_to_queue({ + add_to_queue{ id = self.id, - args = {...}, - tick = game.tick + ticks - }) + args = { ... }, + tick = game.tick + ticks, + } end --- Run an async function on the next tick if the function is not already queued, allows singleton task/thread behaviour -- @param ... The arguments to call the function with function Async._prototype:start_task(...) - assert(not on_tick_mutex, "Cannot queue new async call during execution of another") + assert(not on_tick_mutex, "Cannot queue new async call during execution of another") assert(Async._functions[self.id], "Async function is not registered") if Async._queue_pressure[self.id] > 0 then return end self:start_soon(...) @@ -173,9 +174,9 @@ end --- Run an async function on this tick, then queue it based on its return value -- @param ... The arguments to call the function with function Async._prototype:start_now(...) - assert(not on_tick_mutex, "Cannot queue new async call during execution of another") + assert(not on_tick_mutex, "Cannot queue new async call during execution of another") assert(Async._functions[self.id], "Async function is not registered") - local status, rtn1, rtn2 = Async._functions[self.id](...) + local status, rtn1, rtn2 = Async._functions[self.id](...) if status == Async.status.continue then self:start_soon(table.unpack(rtn1)) elseif status == Async.status.delay then @@ -186,10 +187,10 @@ function Async._prototype:start_now(...) event = Async.on_function_complete, tick = game.tick, async_id = self.id, - returned = rtn1 + returned = rtn1, }) - else - error("Async function " .. self.id .. " returned an invalid status: " .. table.inspect(status)) + else + error("Async function " .. self.id .. " returned an invalid status: " .. table.inspect(status)) end end @@ -198,35 +199,35 @@ end -- @section async-status local empty_table = setmetatable({}, { - __index = function() error("Field 'Returned' is Immutable") end + __index = function() error("Field 'Returned' is Immutable") end, }) -- File scope to allow for reuse --- Default status, will raise on_function_complete -- @param ... The return value of the async call function Async.status.complete(...) - if ... == nil then - return Async.status.complete, empty_table - end - return Async.status.complete, {...} + if ... == nil then + return Async.status.complete, empty_table + end + return Async.status.complete, { ... } end --- Will queue the function to be called again on the next tick using the new arguments -- @param ... The arguments to call the function with function Async.status.continue(...) - if ... == nil then - return Async.status.continue, empty_table - end - return Async.status.continue, {...} + if ... == nil then + return Async.status.continue, empty_table + end + return Async.status.continue, { ... } end --- Will queue the function to be called again on a later tick using the new arguments -- @param ... The arguments to call the function with function Async.status.delay(ticks, ...) - ExpUtil.assert_argument_type(ticks, "number", 1, "ticks") - if ... == nil then - return Async.status.continue, ticks, empty_table - end - return Async.status.delay, ticks, {...} + ExpUtil.assert_argument_type(ticks, "number", 1, "ticks") + if ... == nil then + return Async.status.continue, ticks, empty_table + end + return Async.status.delay, ticks, { ... } end --- Executes an async function and processes the return value @@ -237,49 +238,51 @@ local function exec(pending, tick, new_next, new_queue) pending.tick = nil pending.args = rtn1 elseif status == Async.status.delay then - new_queue[#new_queue + 1] = pending + new_queue[#new_queue + 1] = pending pending.tick = tick + rtn1 pending.args = rtn2 - elseif status == Async.status.complete or status == nil then + elseif status == Async.status.complete or status == nil then -- The function has finished execution, raise the custom event Async._queue_pressure[pending.id] = Async._queue_pressure[pending.id] - 1 script.raise_event(Async.on_function_complete, { event = Async.on_function_complete, tick = tick, async_id = pending.id, - returned = rtn1 + returned = rtn1, }) - else - error("Async function " .. pending.id .. " returned an invalid status: " .. table.inspect(status)) + else + error("Async function " .. pending.id .. " returned an invalid status: " .. table.inspect(status)) end end local new_next, new_queue = {}, {} -- File scope to allow for reuse --- Each tick, run all next tick functions, then check if any in the queue need to be executed local function on_tick() - if async_next == nil then return end + if async_next == nil then return end local tick = game.tick - -- Execute all pending functions + -- Execute all pending functions for index = 1, #async_next, 1 do exec(async_next[index], tick, new_next, new_queue) async_next[index] = nil end + for index = #async_queue, 1, -1 do - local pending = async_queue[index] + local pending = async_queue[index] if pending.tick > tick then - break; - end + break + end exec(pending, tick, new_next, new_queue) async_queue[index] = nil end - -- Queue any functions that did not complete - for index = 1, #new_next, 1 do + -- Queue any functions that did not complete + for index = 1, #new_next, 1 do async_next[index] = new_next[index] new_next[index] = nil end - for index = 1, #new_queue, 1 do + + for index = 1, #new_queue, 1 do add_to_queue(new_next[index]) new_next[index] = nil end @@ -287,36 +290,37 @@ end --- On load, check the queue status and update the pressure values function Async.on_load() - if storage.exp_async_next == nil then return end + if storage.exp_async_next == nil then return end async_next = storage.exp_async_next - async_queue = storage.exp_async_queue + async_queue = storage.exp_async_queue for _, pending in ipairs(async_next) do local count = Async._queue_pressure[pending.id] - if count == nil then - log("Warning: Pending async function missing after load: " .. pending.id) - Async._functions[pending.id] = function() end -- NOP - count = 0 - end - Async._queue_pressure[pending.id] = count + 1 - end + if count == nil then + log("Warning: Pending async function missing after load: " .. pending.id) + Async._functions[pending.id] = function() end -- NOP + count = 0 + end + Async._queue_pressure[pending.id] = count + 1 + end + for _, pending in ipairs(async_queue) do local count = Async._queue_pressure[pending.id] - if count == nil then - log("Warning: Pending async function missing after load: " .. pending.id) - Async._functions[pending.id] = function() end -- NOP - count = 0 - end - Async._queue_pressure[pending.id] = count + 1 + if count == nil then + log("Warning: Pending async function missing after load: " .. pending.id) + Async._functions[pending.id] = function() end -- NOP + count = 0 + end + Async._queue_pressure[pending.id] = count + 1 end end --- On server startup initialise the storage data function Async.on_init() - if storage.exp_async_next == nil then - storage.exp_async_next = {} - storage.exp_async_queue = {} - end - Async.on_load() + if storage.exp_async_next == nil then + storage.exp_async_next = {} + storage.exp_async_queue = {} + end + Async.on_load() end Async.events[defines.events.on_tick] = on_tick diff --git a/exp_util/module/common.lua b/exp_util/module/common.lua index aa7a0856..dccd5f0f 100644 --- a/exp_util/module/common.lua +++ b/exp_util/module/common.lua @@ -12,7 +12,7 @@ local concat = table.concat local Common = { --- A large mapping of colour rgb values by their common name - color = require("modules/exp_util/include/color") + color = require("modules/exp_util/include/color"), } --- Raise an error if we are not in runtime @@ -36,22 +36,22 @@ end]] --- Check the type of a value, also considers LuaObject.object_name and metatable.__class --- Returns true when the check failed and an error should be raised local function check_type(value, type_name) - local value_type = type(value) --[[@as string]] - if value_type == "userdata" then - if type_name == "userdata" then - return false, value_type - end - value_type = value.object_name - elseif value_type == "table" then - if type_name == "table" then - return false, value_type - end - local mt = getmetatable(value) - if mt and mt.__class then - value_type = mt.__class - end - end - return value == nil or value_type ~= type_name, value_type + local value_type = type(value) --[[@as string]] + if value_type == "userdata" then + if type_name == "userdata" then + return false, value_type + end + value_type = value.object_name + elseif value_type == "table" then + if type_name == "table" then + return false, value_type + end + local mt = getmetatable(value) + if mt and mt.__class then + value_type = mt.__class + end + end + return value == nil or value_type ~= type_name, value_type end local assert_type_fmt = "%s expected to be of type %s but got %s" @@ -60,7 +60,7 @@ local assert_type_fmt = "%s expected to be of type %s but got %s" -- @tparam string type_name The name of the type that value is expected to be -- @tparam[opt=Value] string value_name The name of the value being tested, this is included in the error message function Common.assert_type(value, type_name, value_name) - local failed, actual_type = check_type(value, type_name) + local failed, actual_type = check_type(value, type_name) if failed then error(assert_type_fmt:format(value_name or "Value", type_name, actual_type), 2) end @@ -73,7 +73,7 @@ local assert_argument_fmt = "Bad argument #%d to %s; %s expected to be of type % -- @tparam number arg_index The index of the argument being tested, this is included in the error message -- @tparam[opt=Argument] string arg_name The name of the argument being tested, this is included in the error message function Common.assert_argument_type(arg_value, type_name, arg_index, arg_name) - local failed, actual_type = check_type(arg_value, type_name) + local failed, actual_type = check_type(arg_value, type_name) if failed then local func_name = getinfo(2, "n").name or "" error(assert_argument_fmt:format(arg_index, func_name, arg_name or "Argument", type_name, actual_type), 2) @@ -87,9 +87,9 @@ end -- @tparam[opt=0] number player_index The player's machine to write on, -1 means all, 0 means host only function Common.write_json(path, tbl, overwrite, player_index) if player_index == -1 then - return game.write_file(path, game.table_to_json(tbl).."\n", not overwrite) + return game.write_file(path, game.table_to_json(tbl) .. "\n", not overwrite) end - return game.write_file(path, game.table_to_json(tbl).."\n", not overwrite, player_index or 0) + return game.write_file(path, game.table_to_json(tbl) .. "\n", not overwrite, player_index or 0) end --- Clear a file by replacing its contents with an empty string @@ -118,17 +118,17 @@ end -- @treturn string The relative filepath of the given stack frame function Common.safe_file_path(level) level = level or 1 - return getinfo(level+1, 'S').short_src:sub(10, -5) + return getinfo(level + 1, "S").short_src:sub(10, -5) end --- Returns the name of your module, this assumes your module is stored within /modules (which it is for clustorio) -- @tparam[opt=1] number level The level of the stack to get the module of, a value of 1 is the caller of this function -- @treturn string The name of the module at the given stack frame function Common.get_module_name(level) - local file_within_module = getinfo((level or 1)+1, 'S').short_src:sub(18, -5) + local file_within_module = getinfo((level or 1) + 1, "S").short_src:sub(18, -5) local next_slash = file_within_module:find("/") if next_slash then - return file_within_module:sub(1, next_slash-1) + return file_within_module:sub(1, next_slash - 1) else return file_within_module end @@ -139,12 +139,12 @@ end -- @tparam boolean raw When true there will not be any < > around the name -- @treturn string The name of the function at the given stack frame or provided as an argument function Common.get_function_name(func, raw) - local debug_info = getinfo(func, "Sn") - local safe_source = debug_info.source:find('__level__') + local debug_info = getinfo(func, "Sn") + 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 func_name = debug_info.name or debug_info.linedefined - if raw then return file_name .. ":" .. func_name end - return "<" .. file_name .. ":" .. func_name .. ">" + if raw then return file_name .. ":" .. func_name end + return "<" .. file_name .. ":" .. func_name .. ">" end --- Attempt a simple autocomplete search from a set of options @@ -175,25 +175,25 @@ end -- @return The formated version of the value -- @return True if value is a locale string, nil otherwise function Common.safe_value(value) - if type(value) == "table" or type(value) == "userdata" then + if type(value) == "table" or type(value) == "userdata" then if type(value.__self) == "userdata" or type(value) == "userdata" then - local success, rtn = pcall(function() -- some userdata doesnt contain "valid" - if value.valid then -- userdata - return "" - else -- invalid userdata - return "" - end - end) - return success and rtn or "" + local success, rtn = pcall(function() -- some userdata doesnt contain "valid" + if value.valid then -- userdata + return "" + else -- invalid userdata + return "" + end + end) + return success and rtn or "" elseif type(value[1]) == "string" and string.find(value[1], ".+[.].+") and not string.find(value[1], "%s") then return value, true -- locale string elseif tostring(value) ~= "table" then return tostring(value) -- has __tostring metamethod - else -- plain table + else -- plain table return value end elseif type(value) == "function" then -- function - return "" + return "" else -- not: table, userdata, or function return tostring(value) end @@ -205,17 +205,17 @@ end -- @param[opt] maxLineCount If table newline count exceeds provided then it will be inlined -- @return The formated version of the value function Common.format_any(value, tableAsJson, maxLineCount) - 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 tableAsJson then - local success, rtn = pcall(game.table_to_json, value) - if success then return rtn end - end - local rtn = table.inspect(value, {depth=5, indent=' ', newline='\n', process=Common.safe_value}) - if maxLineCount == nil or select(2, rtn:gsub("\n", "")) < maxLineCount then return rtn end - return table.inspect(value, {depth=5, indent='', newline='', process=Common.safe_value}) - end - return formatted + if tableAsJson then + local success, rtn = pcall(game.table_to_json, value) + if success then return rtn end + end + local rtn = table.inspect(value, { depth = 5, indent = " ", newline = "\n", process = Common.safe_value }) + if maxLineCount == nil or select(2, rtn:gsub("\n", "")) < maxLineCount then return rtn end + return table.inspect(value, { depth = 5, indent = "", newline = "", process = Common.safe_value }) + end + return formatted end --- Format a tick value into one of a selection of pre-defined formats (short, long, clock) @@ -229,39 +229,39 @@ function Common.format_time(ticks, format, units) if ticks ~= nil then -- Calculate the values to be determine the display values - local max_days, max_hours, max_minutes, max_seconds = ticks/5184000, ticks/216000, ticks/3600, ticks/60 - local days, hours = max_days, max_hours-floor(max_days)*24 - local minutes, seconds = max_minutes-floor(max_hours)*60, max_seconds-floor(max_minutes)*60 + local max_days, max_hours, max_minutes, max_seconds = ticks / 5184000, ticks / 216000, ticks / 3600, ticks / 60 + local days, hours = max_days, max_hours - floor(max_days) * 24 + local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60 -- Calculate rhw units to be displayed rtn_days, rtn_hours, rtn_minutes, rtn_seconds = floor(days), floor(hours), floor(minutes), floor(seconds) - if not units.days then rtn_hours = rtn_hours + rtn_days*24 end - if not units.hours then rtn_minutes = rtn_minutes + rtn_hours*60 end - if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes*60 end + if not units.days then rtn_hours = rtn_hours + rtn_days * 24 end + if not units.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end + if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end end local rtn = {} if format == "clock" then -- Example 12:34:56 or --:--:-- - if units.days then rtn[#rtn+1] = rtn_days end - if units.hours then rtn[#rtn+1] = rtn_hours end - if units.minutes then rtn[#rtn+1] = rtn_minutes end - if units.seconds then rtn[#rtn+1] = rtn_seconds end + if units.days then rtn[#rtn + 1] = rtn_days end + if units.hours then rtn[#rtn + 1] = rtn_hours end + if units.minutes then rtn[#rtn + 1] = rtn_minutes end + if units.seconds then rtn[#rtn + 1] = rtn_seconds end return concat(rtn, ":") elseif format == "short" then -- Example 12d 34h 56m or --d --h --m - if units.days then rtn[#rtn+1] = rtn_days.."d" end - if units.hours then rtn[#rtn+1] = rtn_hours.."h" end - if units.minutes then rtn[#rtn+1] = rtn_minutes.."m" end - if units.seconds then rtn[#rtn+1] = rtn_seconds.."s" end + if units.days then rtn[#rtn + 1] = rtn_days .. "d" end + if units.hours then rtn[#rtn + 1] = rtn_hours .. "h" end + if units.minutes then rtn[#rtn + 1] = rtn_minutes .. "m" end + if units.seconds then rtn[#rtn + 1] = rtn_seconds .. "s" end return concat(rtn, " ") else -- Example 12 days, 34 hours, and 56 minutes or -- days, -- hours, and -- minutes - if units.days then rtn[#rtn+1] = rtn_days.." days" end - if units.hours then rtn[#rtn+1] = rtn_hours.." hours" end - if units.minutes then rtn[#rtn+1] = rtn_minutes.." minutes" end - if units.seconds then rtn[#rtn+1] = rtn_seconds.." seconds" end - rtn[#rtn] = "and "..rtn[#rtn] + if units.days then rtn[#rtn + 1] = rtn_days .. " days" end + if units.hours then rtn[#rtn + 1] = rtn_hours .. " hours" end + if units.minutes then rtn[#rtn + 1] = rtn_minutes .. " minutes" end + if units.seconds then rtn[#rtn + 1] = rtn_seconds .. " seconds" end + rtn[#rtn] = "and " .. rtn[#rtn] return concat(rtn, ", ") end end @@ -277,47 +277,48 @@ function Common.format_locale_time(ticks, format, units) if ticks ~= nil then -- Calculate the values to be determine the display values - local max_days, max_hours, max_minutes, max_seconds = ticks/5184000, ticks/216000, ticks/3600, ticks/60 - local days, hours = max_days, max_hours-floor(max_days)*24 - local minutes, seconds = max_minutes-floor(max_hours)*60, max_seconds-floor(max_minutes)*60 + local max_days, max_hours, max_minutes, max_seconds = ticks / 5184000, ticks / 216000, ticks / 3600, ticks / 60 + local days, hours = max_days, max_hours - floor(max_days) * 24 + local minutes, seconds = max_minutes - floor(max_hours) * 60, max_seconds - floor(max_minutes) * 60 -- Calculate rhw units to be displayed rtn_days, rtn_hours, rtn_minutes, rtn_seconds = floor(days), floor(hours), floor(minutes), floor(seconds) - if not units.days then rtn_hours = rtn_hours + rtn_days*24 end - if not units.hours then rtn_minutes = rtn_minutes + rtn_hours*60 end - if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes*60 end + if not units.days then rtn_hours = rtn_hours + rtn_days * 24 end + if not units.hours then rtn_minutes = rtn_minutes + rtn_hours * 60 end + if not units.minutes then rtn_seconds = rtn_seconds + rtn_minutes * 60 end end local rtn = {} local join = ", " if format == "clock" then -- Example 12:34:56 or --:--:-- - if units.days then rtn[#rtn+1] = rtn_days end - if units.hours then rtn[#rtn+1] = rtn_hours end - if units.minutes then rtn[#rtn+1] = rtn_minutes end - if units.seconds then rtn[#rtn+1] = rtn_seconds end + if units.days then rtn[#rtn + 1] = rtn_days end + if units.hours then rtn[#rtn + 1] = rtn_hours end + if units.minutes then rtn[#rtn + 1] = rtn_minutes end + if units.seconds then rtn[#rtn + 1] = rtn_seconds end join = { "colon" } elseif format == "short" then -- Example 12d 34h 56m or --d --h --m - if units.days then rtn[#rtn+1] = {"?", {"time-symbol-days-short", rtn_days}, rtn_days.."d"} end - if units.hours then rtn[#rtn+1] = {"time-symbol-hours-short", rtn_hours} end - if units.minutes then rtn[#rtn+1] = {"time-symbol-minutes-short", rtn_minutes} end - if units.seconds then rtn[#rtn+1] = {"time-symbol-seconds-short", rtn_seconds} end + if units.days then rtn[#rtn + 1] = { "?", { "time-symbol-days-short", rtn_days }, rtn_days .. "d" } end + if units.hours then rtn[#rtn + 1] = { "time-symbol-hours-short", rtn_hours } end + if units.minutes then rtn[#rtn + 1] = { "time-symbol-minutes-short", rtn_minutes } end + if units.seconds then rtn[#rtn + 1] = { "time-symbol-seconds-short", rtn_seconds } end join = " " else -- Example 12 days, 34 hours, and 56 minutes or -- days, -- hours, and -- minutes - if units.days then rtn[#rtn+1] = {"days", rtn_days} end - if units.hours then rtn[#rtn+1] = {"hours", rtn_hours} end - if units.minutes then rtn[#rtn+1] = {"minutes", rtn_minutes} end - if units.seconds then rtn[#rtn+1] = {"seconds", rtn_seconds} end - rtn[#rtn] = {"", { "and" }, " ", rtn[#rtn]} + if units.days then rtn[#rtn + 1] = { "days", rtn_days } end + if units.hours then rtn[#rtn + 1] = { "hours", rtn_hours } end + if units.minutes then rtn[#rtn + 1] = { "minutes", rtn_minutes } end + if units.seconds then rtn[#rtn + 1] = { "seconds", rtn_seconds } end + rtn[#rtn] = { "", { "and" }, " ", rtn[#rtn] } end local joined = { "" } for k, v in ipairs(rtn) do - joined[2*k] = v - joined[2*k+1] = join + joined[2 * k] = v + joined[2 * k + 1] = join end + return joined end @@ -341,7 +342,7 @@ function Common.insert_item_stacks(items, surface, options) -- Attempt to insert the items for i = 1, count do - local entity = entities[((current+i-1)%count)+1] + local entity = entities[((current + i - 1) % count) + 1] if entity.can_insert(item) then last_entity = entity current = current + 1 @@ -361,9 +362,9 @@ function Common.insert_item_stacks(items, surface, options) elseif options.area then position = surface.find_non_colliding_position_in_box(options.name, options.area, 1, true) else - position = surface.find_non_colliding_position(options.name, {0,0}, 0, 1, true) + position = surface.find_non_colliding_position(options.name, { 0, 0 }, 0, 1, true) end - last_entity = surface.create_entity{name = options.name, position = position, force = options.force or "neutral"} + last_entity = surface.create_entity{ name = options.name, position = position, force = options.force or "neutral" } count = count + 1 entities[count] = last_entity diff --git a/exp_util/module/floating_text.lua b/exp_util/module/floating_text.lua index 175609ab..b531b162 100644 --- a/exp_util/module/floating_text.lua +++ b/exp_util/module/floating_text.lua @@ -40,9 +40,9 @@ FloatingText.color = require("modules/exp_util/include/color") function FloatingText.print(surface, position, text, color) return surface.create_entity{ text = text, - name = 'tutorial-flying-text', + name = "tutorial-flying-text", color = color or FloatingText.color.white, - position = position + position = position, } end @@ -55,12 +55,12 @@ function FloatingText.print_above_entity(entity, text, color) local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y return entity.surface.create_entity{ text = text, - name = 'tutorial-flying-text', + name = "tutorial-flying-text", color = color or FloatingText.color.white, position = { x = entity.position.x, - y = entity.position.y - size_y * 0.25 - } + y = entity.position.y - size_y * 0.25, + }, } end @@ -72,12 +72,12 @@ end function FloatingText.print_above_player(player, text, color) return player.surface.create_entity{ text = text, - name = 'tutorial-flying-text', + name = "tutorial-flying-text", color = color or FloatingText.color.white, position = { x = player.position.x, - y = player.position.y - 1.5 - } + y = player.position.y - 1.5, + }, } end @@ -88,12 +88,12 @@ end function FloatingText.print_as_player(player, text) return player.surface.create_entity{ text = text, - name = 'tutorial-flying-text', + name = "tutorial-flying-text", color = player.chat_color, position = { x = player.position.x, - y = player.position.y - 1.5 - } + y = player.position.y - 1.5, + }, } end @@ -114,7 +114,7 @@ function FloatingText.create_tag(surface, position, text, color, alt_mode) surface = surface, color = color or FloatingText.color.white, only_in_alt_mode = alt_mode, - target = position + target = position, } end @@ -133,8 +133,8 @@ function FloatingText.create_tag_above_entity(entity, text, color, alt_mode) target = entity, target_offset = { x = 0, - y = (entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y) * -0.25 - } + y = (entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y) * -0.25, + }, } end @@ -153,8 +153,8 @@ function FloatingText.create_tag_above_player(player, text, color, alt_mode) target = player.character, target_offset = { x = 0, - y = -1.5 - } + y = -1.5, + }, } end @@ -172,8 +172,8 @@ function FloatingText.create_tag_as_player(player, text, alt_mode) target = player.character, target_offset = { x = 0, - y = -1.5 - } + y = -1.5, + }, } end diff --git a/exp_util/module/include/color.lua b/exp_util/module/include/color.lua index aaa5b219..de813e91 100644 --- a/exp_util/module/include/color.lua +++ b/exp_util/module/include/color.lua @@ -1,147 +1,147 @@ -- source: https://www.rapidtables.com/web/color/RGB_Color.html return { - maroon = {r = 128, g = 0, b = 0}, - dark_red = {r = 139, g = 0, b = 0}, - brown = {r = 165, g = 42, b = 42}, - firebrick = {r = 178, g = 34, b = 34}, - crimson = {r = 220, g = 20, b = 60}, - red = {r = 255, g = 0, b = 0}, - tomato = {r = 255, g = 99, b = 71}, - coral = {r = 255, g = 127, b = 80}, - indian_red = {r = 205, g = 92, b = 92}, - light_coral = {r = 240, g = 128, b = 128}, - dark_salmon = {r = 233, g = 150, b = 122}, - salmon = {r = 250, g = 128, b = 114}, - light_salmon = {r = 255, g = 160, b = 122}, - orange_red = {r = 255, g = 69, b = 0}, - dark_orange = {r = 255, g = 140, b = 0}, - orange = {r = 255, g = 165, b = 0}, - gold = {r = 255, g = 215, b = 0}, - dark_golden_rod = {r = 184, g = 134, b = 11}, - golden_rod = {r = 218, g = 165, b = 32}, - pale_golden_rod = {r = 238, g = 232, b = 170}, - dark_khaki = {r = 189, g = 183, b = 107}, - khaki = {r = 240, g = 230, b = 140}, - olive = {r = 128, g = 128, b = 0}, - yellow = {r = 255, g = 255, b = 0}, - yellow_green = {r = 154, g = 205, b = 50}, - dark_olive_green = {r = 85, g = 107, b = 47}, - olive_drab = {r = 107, g = 142, b = 35}, - lawn_green = {r = 124, g = 252, b = 0}, - chart_reuse = {r = 127, g = 255, b = 0}, - green_yellow = {r = 173, g = 255, b = 47}, - dark_green = {r = 0, g = 100, b = 0}, - green = {r = 0, g = 128, b = 0}, - forest_green = {r = 34, g = 139, b = 34}, - lime = {r = 0, g = 255, b = 0}, - lime_green = {r = 50, g = 205, b = 50}, - light_green = {r = 144, g = 238, b = 144}, - pale_green = {r = 152, g = 251, b = 152}, - dark_sea_green = {r = 143, g = 188, b = 143}, - medium_spring_green = {r = 0, g = 250, b = 154}, - spring_green = {r = 0, g = 255, b = 127}, - sea_green = {r = 46, g = 139, b = 87}, - medium_aqua_marine = {r = 102, g = 205, b = 170}, - medium_sea_green = {r = 60, g = 179, b = 113}, - light_sea_green = {r = 32, g = 178, b = 170}, - dark_slate_gray = {r = 47, g = 79, b = 79}, - teal = {r = 0, g = 128, b = 128}, - dark_cyan = {r = 0, g = 139, b = 139}, - aqua = {r = 0, g = 255, b = 255}, - cyan = {r = 0, g = 255, b = 255}, - light_cyan = {r = 224, g = 255, b = 255}, - dark_turquoise = {r = 0, g = 206, b = 209}, - turquoise = {r = 64, g = 224, b = 208}, - medium_turquoise = {r = 72, g = 209, b = 204}, - pale_turquoise = {r = 175, g = 238, b = 238}, - aqua_marine = {r = 127, g = 255, b = 212}, - powder_blue = {r = 176, g = 224, b = 230}, - cadet_blue = {r = 95, g = 158, b = 160}, - steel_blue = {r = 70, g = 130, b = 180}, - corn_flower_blue = {r = 100, g = 149, b = 237}, - deep_sky_blue = {r = 0, g = 191, b = 255}, - dodger_blue = {r = 30, g = 144, b = 255}, - light_blue = {r = 173, g = 216, b = 230}, - sky_blue = {r = 135, g = 206, b = 235}, - light_sky_blue = {r = 135, g = 206, b = 250}, - midnight_blue = {r = 25, g = 25, b = 112}, - navy = {r = 0, g = 0, b = 128}, - dark_blue = {r = 0, g = 0, b = 139}, - medium_blue = {r = 0, g = 0, b = 205}, - blue = {r = 0, g = 0, b = 255}, - royal_blue = {r = 65, g = 105, b = 225}, - blue_violet = {r = 138, g = 43, b = 226}, - indigo = {r = 75, g = 0, b = 130}, - dark_slate_blue = {r = 72, g = 61, b = 139}, - slate_blue = {r = 106, g = 90, b = 205}, - medium_slate_blue = {r = 123, g = 104, b = 238}, - medium_purple = {r = 147, g = 112, b = 219}, - dark_magenta = {r = 139, g = 0, b = 139}, - dark_violet = {r = 148, g = 0, b = 211}, - dark_orchid = {r = 153, g = 50, b = 204}, - medium_orchid = {r = 186, g = 85, b = 211}, - purple = {r = 128, g = 0, b = 128}, - thistle = {r = 216, g = 191, b = 216}, - plum = {r = 221, g = 160, b = 221}, - violet = {r = 238, g = 130, b = 238}, - magenta = {r = 255, g = 0, b = 255}, - fuchsia = {r = 255, g = 0, b = 255}, - orchid = {r = 218, g = 112, b = 214}, - medium_violet_red = {r = 199, g = 21, b = 133}, - pale_violet_red = {r = 219, g = 112, b = 147}, - deep_pink = {r = 255, g = 20, b = 147}, - hot_pink = {r = 255, g = 105, b = 180}, - light_pink = {r = 255, g = 182, b = 193}, - pink = {r = 255, g = 192, b = 203}, - antique_white = {r = 250, g = 235, b = 215}, - beige = {r = 245, g = 245, b = 220}, - bisque = {r = 255, g = 228, b = 196}, - blanched_almond = {r = 255, g = 235, b = 205}, - wheat = {r = 245, g = 222, b = 179}, - corn_silk = {r = 255, g = 248, b = 220}, - lemon_chiffon = {r = 255, g = 250, b = 205}, - light_golden_rod_yellow = {r = 250, g = 250, b = 210}, - light_yellow = {r = 255, g = 255, b = 224}, - saddle_brown = {r = 139, g = 69, b = 19}, - sienna = {r = 160, g = 82, b = 45}, - chocolate = {r = 210, g = 105, b = 30}, - peru = {r = 205, g = 133, b = 63}, - sandy_brown = {r = 244, g = 164, b = 96}, - burly_wood = {r = 222, g = 184, b = 135}, - tan = {r = 210, g = 180, b = 140}, - rosy_brown = {r = 188, g = 143, b = 143}, - moccasin = {r = 255, g = 228, b = 181}, - navajo_white = {r = 255, g = 222, b = 173}, - peach_puff = {r = 255, g = 218, b = 185}, - misty_rose = {r = 255, g = 228, b = 225}, - lavender_blush = {r = 255, g = 240, b = 245}, - linen = {r = 250, g = 240, b = 230}, - old_lace = {r = 253, g = 245, b = 230}, - papaya_whip = {r = 255, g = 239, b = 213}, - sea_shell = {r = 255, g = 245, b = 238}, - mint_cream = {r = 245, g = 255, b = 250}, - slate_gray = {r = 112, g = 128, b = 144}, - light_slate_gray = {r = 119, g = 136, b = 153}, - light_steel_blue = {r = 176, g = 196, b = 222}, - lavender = {r = 230, g = 230, b = 250}, - floral_white = {r = 255, g = 250, b = 240}, - alice_blue = {r = 240, g = 248, b = 255}, - ghost_white = {r = 248, g = 248, b = 255}, - honeydew = {r = 240, g = 255, b = 240}, - ivory = {r = 255, g = 255, b = 240}, - azure = {r = 240, g = 255, b = 255}, - snow = {r = 255, g = 250, b = 250}, - black = {r = 0, g = 0, b = 0}, - silver = {r = 192, g = 192, b = 192}, - dim_grey = {r = 105, g = 105, b = 105}, - grey = {r = 128, g = 128, b = 128}, - dark_grey = {r = 169, g = 169, b = 169}, - light_grey = {r = 211, g = 211, b = 211}, - gainsboro = {r = 220, g = 220, b = 220}, - white_smoke = {r = 245, g = 245, b = 245}, - white = {r = 255, g = 255, b = 255}, - success = {r = 0, g = 255, b = 0}, - warning = {r = 255, g = 255, b = 0}, - fail = {r = 255, g = 0, b = 0}, - info = {r = 255, g = 255, b = 255} + maroon = { r = 128, g = 0, b = 0 }, + dark_red = { r = 139, g = 0, b = 0 }, + brown = { r = 165, g = 42, b = 42 }, + firebrick = { r = 178, g = 34, b = 34 }, + crimson = { r = 220, g = 20, b = 60 }, + red = { r = 255, g = 0, b = 0 }, + tomato = { r = 255, g = 99, b = 71 }, + coral = { r = 255, g = 127, b = 80 }, + indian_red = { r = 205, g = 92, b = 92 }, + light_coral = { r = 240, g = 128, b = 128 }, + dark_salmon = { r = 233, g = 150, b = 122 }, + salmon = { r = 250, g = 128, b = 114 }, + light_salmon = { r = 255, g = 160, b = 122 }, + orange_red = { r = 255, g = 69, b = 0 }, + dark_orange = { r = 255, g = 140, b = 0 }, + orange = { r = 255, g = 165, b = 0 }, + gold = { r = 255, g = 215, b = 0 }, + dark_golden_rod = { r = 184, g = 134, b = 11 }, + golden_rod = { r = 218, g = 165, b = 32 }, + pale_golden_rod = { r = 238, g = 232, b = 170 }, + dark_khaki = { r = 189, g = 183, b = 107 }, + khaki = { r = 240, g = 230, b = 140 }, + olive = { r = 128, g = 128, b = 0 }, + yellow = { r = 255, g = 255, b = 0 }, + yellow_green = { r = 154, g = 205, b = 50 }, + dark_olive_green = { r = 85, g = 107, b = 47 }, + olive_drab = { r = 107, g = 142, b = 35 }, + lawn_green = { r = 124, g = 252, b = 0 }, + chart_reuse = { r = 127, g = 255, b = 0 }, + green_yellow = { r = 173, g = 255, b = 47 }, + dark_green = { r = 0, g = 100, b = 0 }, + green = { r = 0, g = 128, b = 0 }, + forest_green = { r = 34, g = 139, b = 34 }, + lime = { r = 0, g = 255, b = 0 }, + lime_green = { r = 50, g = 205, b = 50 }, + light_green = { r = 144, g = 238, b = 144 }, + pale_green = { r = 152, g = 251, b = 152 }, + dark_sea_green = { r = 143, g = 188, b = 143 }, + medium_spring_green = { r = 0, g = 250, b = 154 }, + spring_green = { r = 0, g = 255, b = 127 }, + sea_green = { r = 46, g = 139, b = 87 }, + medium_aqua_marine = { r = 102, g = 205, b = 170 }, + medium_sea_green = { r = 60, g = 179, b = 113 }, + light_sea_green = { r = 32, g = 178, b = 170 }, + dark_slate_gray = { r = 47, g = 79, b = 79 }, + teal = { r = 0, g = 128, b = 128 }, + dark_cyan = { r = 0, g = 139, b = 139 }, + aqua = { r = 0, g = 255, b = 255 }, + cyan = { r = 0, g = 255, b = 255 }, + light_cyan = { r = 224, g = 255, b = 255 }, + dark_turquoise = { r = 0, g = 206, b = 209 }, + turquoise = { r = 64, g = 224, b = 208 }, + medium_turquoise = { r = 72, g = 209, b = 204 }, + pale_turquoise = { r = 175, g = 238, b = 238 }, + aqua_marine = { r = 127, g = 255, b = 212 }, + powder_blue = { r = 176, g = 224, b = 230 }, + cadet_blue = { r = 95, g = 158, b = 160 }, + steel_blue = { r = 70, g = 130, b = 180 }, + corn_flower_blue = { r = 100, g = 149, b = 237 }, + deep_sky_blue = { r = 0, g = 191, b = 255 }, + dodger_blue = { r = 30, g = 144, b = 255 }, + light_blue = { r = 173, g = 216, b = 230 }, + sky_blue = { r = 135, g = 206, b = 235 }, + light_sky_blue = { r = 135, g = 206, b = 250 }, + midnight_blue = { r = 25, g = 25, b = 112 }, + navy = { r = 0, g = 0, b = 128 }, + dark_blue = { r = 0, g = 0, b = 139 }, + medium_blue = { r = 0, g = 0, b = 205 }, + blue = { r = 0, g = 0, b = 255 }, + royal_blue = { r = 65, g = 105, b = 225 }, + blue_violet = { r = 138, g = 43, b = 226 }, + indigo = { r = 75, g = 0, b = 130 }, + dark_slate_blue = { r = 72, g = 61, b = 139 }, + slate_blue = { r = 106, g = 90, b = 205 }, + medium_slate_blue = { r = 123, g = 104, b = 238 }, + medium_purple = { r = 147, g = 112, b = 219 }, + dark_magenta = { r = 139, g = 0, b = 139 }, + dark_violet = { r = 148, g = 0, b = 211 }, + dark_orchid = { r = 153, g = 50, b = 204 }, + medium_orchid = { r = 186, g = 85, b = 211 }, + purple = { r = 128, g = 0, b = 128 }, + thistle = { r = 216, g = 191, b = 216 }, + plum = { r = 221, g = 160, b = 221 }, + violet = { r = 238, g = 130, b = 238 }, + magenta = { r = 255, g = 0, b = 255 }, + fuchsia = { r = 255, g = 0, b = 255 }, + orchid = { r = 218, g = 112, b = 214 }, + medium_violet_red = { r = 199, g = 21, b = 133 }, + pale_violet_red = { r = 219, g = 112, b = 147 }, + deep_pink = { r = 255, g = 20, b = 147 }, + hot_pink = { r = 255, g = 105, b = 180 }, + light_pink = { r = 255, g = 182, b = 193 }, + pink = { r = 255, g = 192, b = 203 }, + antique_white = { r = 250, g = 235, b = 215 }, + beige = { r = 245, g = 245, b = 220 }, + bisque = { r = 255, g = 228, b = 196 }, + blanched_almond = { r = 255, g = 235, b = 205 }, + wheat = { r = 245, g = 222, b = 179 }, + corn_silk = { r = 255, g = 248, b = 220 }, + lemon_chiffon = { r = 255, g = 250, b = 205 }, + light_golden_rod_yellow = { r = 250, g = 250, b = 210 }, + light_yellow = { r = 255, g = 255, b = 224 }, + saddle_brown = { r = 139, g = 69, b = 19 }, + sienna = { r = 160, g = 82, b = 45 }, + chocolate = { r = 210, g = 105, b = 30 }, + peru = { r = 205, g = 133, b = 63 }, + sandy_brown = { r = 244, g = 164, b = 96 }, + burly_wood = { r = 222, g = 184, b = 135 }, + tan = { r = 210, g = 180, b = 140 }, + rosy_brown = { r = 188, g = 143, b = 143 }, + moccasin = { r = 255, g = 228, b = 181 }, + navajo_white = { r = 255, g = 222, b = 173 }, + peach_puff = { r = 255, g = 218, b = 185 }, + misty_rose = { r = 255, g = 228, b = 225 }, + lavender_blush = { r = 255, g = 240, b = 245 }, + linen = { r = 250, g = 240, b = 230 }, + old_lace = { r = 253, g = 245, b = 230 }, + papaya_whip = { r = 255, g = 239, b = 213 }, + sea_shell = { r = 255, g = 245, b = 238 }, + mint_cream = { r = 245, g = 255, b = 250 }, + slate_gray = { r = 112, g = 128, b = 144 }, + light_slate_gray = { r = 119, g = 136, b = 153 }, + light_steel_blue = { r = 176, g = 196, b = 222 }, + lavender = { r = 230, g = 230, b = 250 }, + floral_white = { r = 255, g = 250, b = 240 }, + alice_blue = { r = 240, g = 248, b = 255 }, + ghost_white = { r = 248, g = 248, b = 255 }, + honeydew = { r = 240, g = 255, b = 240 }, + ivory = { r = 255, g = 255, b = 240 }, + azure = { r = 240, g = 255, b = 255 }, + snow = { r = 255, g = 250, b = 250 }, + black = { r = 0, g = 0, b = 0 }, + silver = { r = 192, g = 192, b = 192 }, + dim_grey = { r = 105, g = 105, b = 105 }, + grey = { r = 128, g = 128, b = 128 }, + dark_grey = { r = 169, g = 169, b = 169 }, + light_grey = { r = 211, g = 211, b = 211 }, + gainsboro = { r = 220, g = 220, b = 220 }, + white_smoke = { r = 245, g = 245, b = 245 }, + white = { r = 255, g = 255, b = 255 }, + success = { r = 0, g = 255, b = 0 }, + warning = { r = 255, g = 255, b = 0 }, + fail = { r = 255, g = 0, b = 0 }, + info = { r = 255, g = 255, b = 255 }, } diff --git a/exp_util/module/include/inspect.lua b/exp_util/module/include/inspect.lua index e91834d1..2b957c25 100644 --- a/exp_util/module/include/inspect.lua +++ b/exp_util/module/include/inspect.lua @@ -1,7 +1,7 @@ local inspect = { - _VERSION = 'inspect.lua 3.1.0', - _URL = 'http://github.com/kikito/inspect.lua', - _DESCRIPTION = 'human-readable representations of tables', + _VERSION = "inspect.lua 3.1.0", + _URL = "http://github.com/kikito/inspect.lua", + _DESCRIPTION = "human-readable representations of tables", _LICENSE = [[ MIT LICENSE @@ -25,13 +25,13 @@ local inspect = { CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ]] + ]], } local tostring = tostring -inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end}) -inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end}) +inspect.KEY = setmetatable({}, { __tostring = function() return "inspect.KEY" end }) +inspect.METATABLE = setmetatable({}, { __tostring = function() return "inspect.METATABLE" end }) -- Apostrophizes the string if it has quotes, but not aphostrophes -- Otherwise, it returns a regular quoted string @@ -44,51 +44,64 @@ end -- \a => '\\a', \0 => '\\0', 31 => '\31' local shortControlCharEscapes = { - ["\a"] = "\\a", ["\b"] = "\\b", ["\f"] = "\\f", ["\n"] = "\\n", - ["\r"] = "\\r", ["\t"] = "\\t", ["\v"] = "\\v" + ["\a"] = "\\a", + ["\b"] = "\\b", + ["\f"] = "\\f", + ["\n"] = "\\n", + ["\r"] = "\\r", + ["\t"] = "\\t", + ["\v"] = "\\v", } local longControlCharEscapes = {} -- \a => nil, \0 => \000, 31 => \031 -for i=0, 31 do +for i = 0, 31 do local ch = string.char(i) if not shortControlCharEscapes[ch] then - shortControlCharEscapes[ch] = "\\"..i - longControlCharEscapes[ch] = string.format("\\%03d", i) + shortControlCharEscapes[ch] = "\\" .. i + longControlCharEscapes[ch] = string.format("\\%03d", i) end end local function escape(str) return (str:gsub("\\", "\\\\") - :gsub("(%c)%f[0-9]", longControlCharEscapes) - :gsub("%c", shortControlCharEscapes)) + :gsub("(%c)%f[0-9]", longControlCharEscapes) + :gsub("%c", shortControlCharEscapes)) end local function isIdentifier(str) - return type(str) == 'string' and str:match( "^[_%a][_%a%d]*$" ) + return type(str) == "string" and str:match("^[_%a][_%a%d]*$") end local function isSequenceKey(k, sequenceLength) - return type(k) == 'number' - and 1 <= k - and k <= sequenceLength - and math.floor(k) == k + return type(k) == "number" + and 1 <= k + and k <= sequenceLength + and math.floor(k) == k end local defaultTypeOrders = { - ['number'] = 1, ['boolean'] = 2, ['string'] = 3, ['table'] = 4, - ['function'] = 5, ['userdata'] = 6, ['thread'] = 7 + ["number"] = 1, + ["boolean"] = 2, + ["string"] = 3, + ["table"] = 4, + ["function"] = 5, + ["userdata"] = 6, + ["thread"] = 7, } local function sortKeys(a, b) local ta, tb = type(a), type(b) -- strings and numbers are sorted numerically/alphabetically - if ta == tb and (ta == 'string' or ta == 'number') then return a < b end + if ta == tb and (ta == "string" or ta == "number") then return a < b end local dta, dtb = defaultTypeOrders[ta], defaultTypeOrders[tb] -- Two default types are compared according to the defaultTypeOrders table - if dta and dtb then return defaultTypeOrders[ta] < defaultTypeOrders[tb] - elseif dta then return true -- default types before custom ones - elseif dtb then return false -- custom types after default ones + if dta and dtb then + return defaultTypeOrders[ta] < defaultTypeOrders[tb] + elseif dta then + return true -- default types before custom ones + elseif dtb then + return false -- custom types after default ones end -- custom types are sorted out alphabetically @@ -104,6 +117,7 @@ local function getSequenceLength(t) len = len + 1 v = rawget(t, len) end + return len - 1 end @@ -113,30 +127,32 @@ local function getNonSequentialKeys(t) for k, _ in pairs(t) do if not isSequenceKey(k, sequenceLength) then table.insert(keys, k) end end + table.sort(keys, sortKeys) return keys, sequenceLength end local function getToStringResultSafely(t, mt) - local __tostring = type(mt) == 'table' and rawget(mt, '__tostring') + local __tostring = type(mt) == "table" and rawget(mt, "__tostring") local str, ok - if type(__tostring) == 'function' then + if type(__tostring) == "function" then ok, str = pcall(__tostring, t) - str = ok and str or 'error: ' .. tostring(str) + str = ok and str or "error: " .. tostring(str) end - if type(str) == 'string' and #str > 0 then return str end + if type(str) == "string" and #str > 0 then return str end end local function countTableAppearances(t, tableAppearances) tableAppearances = tableAppearances or {} - if type(t) == 'table' then + if type(t) == "table" then if not tableAppearances[t] then tableAppearances[t] = 1 for k, v in pairs(t) do countTableAppearances(k, tableAppearances) countTableAppearances(v, tableAppearances) end + countTableAppearances(getmetatable(t), tableAppearances) else tableAppearances[t] = tableAppearances[t] + 1 @@ -148,43 +164,44 @@ end local copySequence = function(s) local copy, len = {}, #s - for i=1, len do copy[i] = s[i] end + for i = 1, len do copy[i] = s[i] end + return copy, len end local function makePath(path, ...) - local keys = {...} + local keys = { ... } local newPath, len = copySequence(path) - for i=1, #keys do + for i = 1, #keys do newPath[len + i] = keys[i] end + return newPath end -- Cooldude2606: Modified this to respect the depth option local function processRecursive(process, item, path, visited, depth) + if item == nil then return nil end + if visited[item] then return visited[item] end - if item == nil then return nil end - if visited[item] then return visited[item] end + local processed = process(item, path) + if type(processed) == "table" and (depth == nil or depth > 0) then + local processedCopy = {} + visited[item] = processedCopy + local processedKey - local processed = process(item, path) - if type(processed) == 'table' and (depth == nil or depth > 0) then - local processedCopy = {} - visited[item] = processedCopy - local processedKey - - for k, v in pairs(processed) do - processedKey = processRecursive(process, k, makePath(path, k, inspect.KEY), visited, depth and depth - 1) - if processedKey ~= nil then - processedCopy[processedKey] = processRecursive(process, v, makePath(path, processedKey), visited, depth and depth - 1) - end + for k, v in pairs(processed) do + processedKey = processRecursive(process, k, makePath(path, k, inspect.KEY), visited, depth and depth - 1) + if processedKey ~= nil then + processedCopy[processedKey] = processRecursive(process, v, makePath(path, processedKey), visited, depth and depth - 1) end - - local mt = processRecursive(process, getmetatable(processed), makePath(path, inspect.METATABLE), visited, depth and depth - 1) - setmetatable(processedCopy, mt) - processed = processedCopy end - return processed + + local mt = processRecursive(process, getmetatable(processed), makePath(path, inspect.METATABLE), visited, depth and depth - 1) + setmetatable(processedCopy, mt) + processed = processedCopy + end + return processed end @@ -192,13 +209,13 @@ end ------------------------------------------------------------------- local Inspector = {} -local Inspector_mt = {__index = Inspector} +local Inspector_mt = { __index = Inspector } function Inspector:puts(...) - local args = {...} + local args = { ... } local buffer = self.buffer - local len = #buffer - for i=1, #args do + local len = #buffer + for i = 1, #args do len = len + 1 buffer[len] = args[i] end @@ -222,9 +239,9 @@ function Inspector:getId(v) local id = self.ids[v] if not id then local tv = type(v) - id = (self.maxIds[tv] or 0) + 1 + id = (self.maxIds[tv] or 0) + 1 self.maxIds[tv] = id - self.ids[v] = id + self.ids[v] = id end return tostring(id) end @@ -240,44 +257,44 @@ function Inspector:putTable(t) if t == inspect.KEY or t == inspect.METATABLE then self:puts(tostring(t)) elseif self:alreadyVisited(t) then - self:puts('') + self:puts("
") elseif self.level >= self.depth then - self:puts('{...}') + self:puts("{...}") else - if self.tableAppearances[t] > 1 then self:puts('<', self:getId(t), '>') end + if self.tableAppearances[t] > 1 then self:puts("<", self:getId(t), ">") end local nonSequentialKeys, sequenceLength = getNonSequentialKeys(t) - local mt = getmetatable(t) - local toStringResult = getToStringResultSafely(t, mt) + local mt = getmetatable(t) + local toStringResult = getToStringResultSafely(t, mt) - self:puts('{') + self:puts("{") self:down(function() if toStringResult then - self:puts(' -- ', escape(toStringResult)) + self:puts(" -- ", escape(toStringResult)) if sequenceLength >= 1 then self:tabify() end end local count = 0 - for i=1, sequenceLength do - if count > 0 then self:puts(', ') end - self:puts(' ') + for i = 1, sequenceLength do + if count > 0 then self:puts(", ") end + self:puts(" ") self:putValue(t[i]) count = count + 1 end for _, k in ipairs(nonSequentialKeys) do - if count > 0 then self:puts(', ') end + if count > 0 then self:puts(", ") end self:tabify() self:putKey(k) - self:puts(' = ') + self:puts(" = ") self:putValue(t[k]) count = count + 1 end if mt then - if count > 0 then self:puts(', ') end + if count > 0 then self:puts(", ") end self:tabify() - self:puts(' = ') + self:puts(" = ") self:putValue(mt) end end) @@ -285,36 +302,36 @@ function Inspector:putTable(t) if #nonSequentialKeys > 0 or mt then -- result is multi-lined. Justify closing } self:tabify() elseif sequenceLength > 0 then -- array tables have one extra space before closing } - self:puts(' ') + self:puts(" ") end - self:puts('}') + self:puts("}") end end function Inspector:putValue(v) local tv = type(v) - if tv == 'string' then + if tv == "string" then self:puts(smartQuote(escape(v))) - elseif tv == 'number' or tv == 'boolean' or tv == 'nil' or - tv == 'cdata' or tv == 'ctype' then + elseif tv == "number" or tv == "boolean" or tv == "nil" or + tv == "cdata" or tv == "ctype" then self:puts(tostring(v)) - elseif tv == 'table' then + elseif tv == "table" then self:putTable(v) else - self:puts('<', tv, ' ', self:getId(v), '>') + self:puts("<", tv, " ", self:getId(v), ">") end end ------------------------------------------------------------------- function inspect.inspect(root, options) - options = options or {} + options = options or {} - local depth = options.depth or math.huge - local newline = options.newline or '\n' - local indent = options.indent or ' ' + local depth = options.depth or math.huge + local newline = options.newline or "\n" + local indent = options.indent or " " local process = options.process if process then @@ -322,14 +339,14 @@ function inspect.inspect(root, options) end local inspector = setmetatable({ - depth = depth, - level = 0, - buffer = {}, - ids = {}, - maxIds = {}, - newline = newline, - indent = indent, - tableAppearances = countTableAppearances(root) + depth = depth, + level = 0, + buffer = {}, + ids = {}, + maxIds = {}, + newline = newline, + indent = indent, + tableAppearances = countTableAppearances(root), }, Inspector_mt) inspector:putValue(root) diff --git a/exp_util/module/include/math.lua b/exp_util/module/include/math.lua index f38e137a..69093cb0 100644 --- a/exp_util/module/include/math.lua +++ b/exp_util/module/include/math.lua @@ -1,4 +1,4 @@ ---luacheck:ignore global math +-- luacheck:ignore global math local floor = math.floor local abs = math.abs diff --git a/exp_util/module/include/package.lua b/exp_util/module/include/package.lua index de1579c9..275ae6ed 100644 --- a/exp_util/module/include/package.lua +++ b/exp_util/module/include/package.lua @@ -1,4 +1,4 @@ ---luacheck:ignore global package +-- luacheck:ignore global package local Clustorio = require("modules/clusterio/api") @@ -13,7 +13,7 @@ package.lifecycle_stage = { init = 5, load = 6, config_change = 7, - runtime = 8 + runtime = 8, } --- Stores the current lifecycle stage we are in, compare values against package.lifecycle_stage @@ -24,10 +24,10 @@ return setmetatable({ on_load = function() package.lifecycle = package.lifecycle_stage.load end, on_configuration_changed = function() package.lifecycle = package.lifecycle_stage.config_change end, events = { - -- TODO find a reliable way to set to runtime because currently it will desync if accessed before player joined + -- TODO find a reliable way to set to runtime because currently it will desync if accessed before player joined [defines.events.on_player_joined_game] = function() package.lifecycle = package.lifecycle_stage.runtime end, [Clustorio.events.on_server_startup] = function() package.lifecycle = package.lifecycle_stage.runtime end, - } + }, }, { - __index = package + __index = package, }) diff --git a/exp_util/module/include/require.lua b/exp_util/module/include/require.lua index 4b733e3c..b4cebc2a 100644 --- a/exp_util/module/include/require.lua +++ b/exp_util/module/include/require.lua @@ -1,4 +1,4 @@ ---luacheck:ignore global require +-- luacheck:ignore global require local package = require("modules/exp_util/include/package") local loaded = package.loaded @@ -6,18 +6,18 @@ local _require = require -- This replace function is used to avoid additional lines in stack traces during control stage local function replace() - require = function(path) - 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) - else - return _require(path) - end - end + require = function(path) + 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) + else + return _require(path) + end + end end return setmetatable({ on_init = replace, on_load = replace, }, { - __call = _require + __call = _require, }) diff --git a/exp_util/module/include/table.lua b/exp_util/module/include/table.lua index 51fdfff0..82a5049b 100644 --- a/exp_util/module/include/table.lua +++ b/exp_util/module/include/table.lua @@ -1,4 +1,4 @@ ---luacheck:ignore global table +-- luacheck:ignore global table local random = math.random local floor = math.floor @@ -42,17 +42,18 @@ function table.array_insert(tbl, start_index, values) if start_index then local starting_length = #tbl local adding_length = #values - local move_to = start_index+adding_length+1 - for offset = starting_length-start_index, 0, -1 do - tbl[move_to+offset] = tbl[starting_length+offset] + local move_to = start_index + adding_length + 1 + for offset = starting_length - start_index, 0, -1 do + tbl[move_to + offset] = tbl[starting_length + offset] end - start_index = start_index-1 + + start_index = start_index - 1 else start_index = #tbl end for offset, item in ipairs(values) do - tbl[start_index+offset] = item + tbl[start_index + offset] = item end return tbl @@ -125,6 +126,7 @@ function table.get_key(tbl, element) return k end end + return nil end @@ -138,6 +140,7 @@ function table.get_index(tbl, element) return i end end + return nil end @@ -166,9 +169,10 @@ local format_number, distance = table.deconstruct(require('util'), 'format_numbe ]] function table.deconstruct(tbl, ...) local values = {} - for _, key in pairs({...}) do + for _, key in pairs{ ... } do table.insert(values, tbl[key]) end + return table.unpack(values) end @@ -239,7 +243,7 @@ function table.shuffle(t, rng) local rand = rng or math.random local iterations = #t if iterations == 0 then - error('Not a sequential table') + error("Not a sequential table") return end local j @@ -255,19 +259,19 @@ end -- @param x one comparator operand -- @param y the other comparator operand -- @return true if x logically comes before y in a list, false otherwise -local function sortFunc(x, y) --sorts tables with mixed index types. +local function sortFunc(x, y) -- sorts tables with mixed index types. local tx = type(x) local ty = type(y) if tx == ty then - if type(x) == 'string' then + if type(x) == "string" then return string.lower(x) < string.lower(y) else return x < y end - elseif tx == 'number' then - return true --only x is a number and goes first + elseif tx == "number" then + return true -- only x is a number and goes first else - return false --only y is a number and goes first + return false -- only y is a number and goes first end end @@ -280,7 +284,7 @@ function table.get_values(tbl, sorted, as_string) if not tbl then return {} end local valueset = {} local n = 0 - if as_string then --checking as_string /before/ looping is faster + if as_string then -- checking as_string /before/ looping is faster for _, v in pairs(tbl) do n = n + 1 valueset[n] = tostring(v) @@ -306,7 +310,7 @@ function table.get_keys(tbl, sorted, as_string) if not tbl then return {} end local keyset = {} local n = 0 - if as_string then --checking as_string /before/ looping is faster + if as_string then -- checking as_string /before/ looping is faster for k, _ in pairs(tbl) do n = n + 1 keyset[n] = tostring(k) @@ -328,13 +332,17 @@ end -- @treturn table the sorted table function table.alphanum_sort(tbl) local o = table.get_keys(tbl) - local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)") - return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end + local function padnum(d) + local dec, n = string.match(d, "(%.?)0*(.+)") + return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) + end table.sort(o, function(a, b) - return tostring(a):gsub("%.?%d+", padnum)..("%3d"):format(#b) - < tostring(b):gsub("%.?%d+", padnum)..("%3d"):format(#a) end) + return tostring(a):gsub("%.?%d+", padnum) .. ("%3d"):format(#b) + < tostring(b):gsub("%.?%d+", padnum) .. ("%3d"):format(#a) + end) local _tbl = {} for _, k in pairs(o) do _tbl[k] = tbl[k] end + return _tbl end @@ -345,6 +353,7 @@ function table.key_sort(tbl) local o = table.get_keys(tbl, true) local _tbl = {} for _, k in pairs(o) do _tbl[k] = tbl[k] end + return _tbl end @@ -365,7 +374,7 @@ end end ]] function table.binary_search(t, target) - --For some reason bit32.bnot doesn't return negative numbers so I'm using ~x = -1 - x instead. + -- For some reason bit32.bnot doesn't return negative numbers so I'm using ~x = -1 - x instead. local lower = 1 local upper = #t @@ -390,7 +399,7 @@ function table.binary_search(t, target) end -- add table-related functions that exist in base factorio/util to the 'table' table -require 'util' +require "util" --- Similar to serpent.block, returns a string with a pretty representation of a table. -- Notice: This method is not appropriate for saving/restoring tables. It is meant to be used by the programmer mainly while debugging a program. @@ -400,7 +409,7 @@ require 'util' -- process is a function which allow altering the passed object before transforming it into a string. -- A typical way to use it would be to remove certain values so that they don't appear at all. -- return the prettied table -table.inspect = require 'modules.exp_util.include.inspect' --- @dep modules.exp_util.includes.inspect +table.inspect = require "modules.exp_util.include.inspect" --- @dep modules.exp_util.includes.inspect --- Takes a table and returns the number of entries in the table. (Slower than #table, faster than iterating via pairs) table.size = table_size diff --git a/exp_util/module/storage.lua b/exp_util/module/storage.lua index 6f28cf9e..cd2bedd4 100644 --- a/exp_util/module/storage.lua +++ b/exp_util/module/storage.lua @@ -55,7 +55,7 @@ function Storage.register(tbl, callback) Storage.registered[name] = { init = tbl, - callback = callback + callback = callback, } end @@ -63,16 +63,16 @@ end -- @tparam string name The name of the metatable to register, must be unique within your module function Storage.register_metatable(name, tbl) local module_name = ExpUtil.get_module_name(2) - script.register_metatable(module_name.."."..name, tbl) + script.register_metatable(module_name .. "." .. name, tbl) end --- Restore aliases on load, we do not need to initialise data during this event function Storage.on_load() local exp_storage = storage.exp_storage - if exp_storage == nil then return end - for name, info in pairs(Storage.registered) do + if exp_storage == nil then return end + for name, info in pairs(Storage.registered) do if exp_storage[name] ~= nil then - info.callback(exp_storage[name]) + info.callback(exp_storage[name]) end end end @@ -94,7 +94,7 @@ function Storage.on_init() end Storage.events = { - [Clustorio.events.on_server_startup] = Storage.on_init + [Clustorio.events.on_server_startup] = Storage.on_init, } return Storage