From 86385045505e37bed4d0fe0d4e9d95733d0013f1 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Wed, 29 May 2024 15:39:37 +0100 Subject: [PATCH] Use new linter (#294) * Use new linter * Luacheck and Sumneko Lua fixes * Bump CI action versions * Fix excludes for ldoc --- .github/workflows/docs-deploy.yml | 2 +- .github/workflows/pr-checker.yml | 17 +++++---------- .luarc.json | 5 +++++ config/chat_reply.lua | 30 +++++++++++++------------- config/graftorio.lua | 2 +- control.lua | 2 ++ docs/config.ld | 2 +- expcore/async.lua | 2 +- expcore/commands.lua | 10 ++++----- expcore/gui/left_flow.lua | 2 +- expcore/gui/prototype.lua | 2 +- expcore/gui/top_flow.lua | 3 ++- modules/addons/chat-reply.lua | 4 ++-- modules/commands/warnings.lua | 2 +- modules/control/jail.lua | 6 +++--- modules/control/selection.lua | 6 +++--- modules/control/warps.lua | 1 + modules/graftorio/forcestats.lua | 25 ++++++++++------------ modules/graftorio/general.lua | 10 ++++----- modules/graftorio/require.lua | 35 ++++++++++++++++--------------- modules/gui/debug/model.lua | 2 +- modules/gui/vlayer.lua | 3 ++- modules/gui/warp-list.lua | 2 ++ overrides/debug.lua | 2 +- overrides/table.lua | 2 +- utils/game.lua | 7 +++++-- utils/task.lua | 2 +- 27 files changed, 96 insertions(+), 92 deletions(-) create mode 100644 .luarc.json diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index 61769368..2e309b6f 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v4 - name: Install Lua - uses: leafo/gh-actions-lua@v8.0.0 + uses: leafo/gh-actions-lua@v10 - name: Install LuaRocks uses: leafo/gh-actions-luarocks@v4 diff --git a/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index aaf4242a..6a06ee36 100644 --- a/.github/workflows/pr-checker.yml +++ b/.github/workflows/pr-checker.yml @@ -7,28 +7,21 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Extract branch name - shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_BASE_REF#refs/heads/})" - id: extract_branch - - - name: Lint - uses: Roang-zero1/factorio-mod-luacheck@master - with: - luacheckrc_url: https://raw.githubusercontent.com/explosivegaming/scenario/${{ steps.extract_branch.outputs.branch }}/.luacheckrc + - name: Luacheck linter + uses: lunarmodules/luacheck@v1 docs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install Lua - uses: leafo/gh-actions-lua@v8.0.0 + uses: leafo/gh-actions-lua@v10 - name: Install LuaRocks uses: leafo/gh-actions-luarocks@v4 diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 00000000..475a7824 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,5 @@ +{ + "Lua.diagnostics.disable": [ + "luadoc-miss-type-name" + ] +} \ No newline at end of file diff --git a/config/chat_reply.lua b/config/chat_reply.lua index ce017ecb..bf3305fd 100644 --- a/config/chat_reply.lua +++ b/config/chat_reply.lua @@ -30,7 +30,7 @@ return { ['roundabout'] = {'chat-bot.loops'}, ['roundabouts'] = {'chat-bot.loops'}, ['redmew'] = {'info.redmew'}, - ['afk'] = function(player) + ['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 @@ -39,13 +39,13 @@ return { end return {'chat-bot.afk', max.name, format_time(max.afk_time, {minutes = true, seconds = true, long = true})} end, - ['players'] = function() + ['players'] = function(_player, _is_command) return {'chat-bot.players', #game.players} end, - ['online'] = function() + ['online'] = function(_player, _is_command) return {'chat-bot.players-online', #game.connected_players} end, - ['r!verify'] = function(player) + ['r!verify'] = function(player, _is_command) return {'chat-bot.verify', player.name} end, }, @@ -54,7 +54,7 @@ return { 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) + ['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 @@ -65,52 +65,52 @@ return { ['aids'] = {'chat-bot.aids'}, ['riot'] = {'chat-bot.riot'}, ['lenny'] = {'chat-bot.lenny'}, - ['hodor'] = function() + ['hodor'] = function(_player, _is_command) local options = {'?', '.', '!', '!!!'} return {'chat-bot.hodor', table.get_random_dictionary_entry(options)} end, - ['evolution'] = function() + ['evolution'] = function(_player, _is_command) return {'chat-bot.current-evolution', string.format('%.2f', game.forces['enemy'].evolution_factor)} end, - ['makepopcorn'] = function(player) + ['makepopcorn'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-popcorn-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-popcorn-2', player.name}}) end, - ['passsomesnaps'] = function(player) + ['passsomesnaps'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, player, {'chat-bot.reply', {'chat-bot.get-snaps-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-snaps-2', player.name}}) Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.get-snaps-3', player.name}}) end, - ['makecocktail'] = function(player) + ['makecocktail'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-2', player.name}}) Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-3', player.name}}) end, - ['makecoffee'] = function(player) + ['makecoffee'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, true, {'chat-bot.reply', {'chat-bot.make-coffee-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.make-coffee-2', player.name}}) end, - ['orderpizza'] = function(player) + ['orderpizza'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-2', player.name}}) Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-3', player.name}}) end, - ['maketea'] = function(player) + ['maketea'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, true, {'chat-bot.reply', {'chat-bot.make-tea-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.make-tea-2', player.name}}) end, - ['meadplease'] = function(player) + ['meadplease'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-mead-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-mead-2', player.name}}) end, - ['passabeer'] = function(player) + ['passabeer'] = function(player, _is_command) local timeout = math.floor(180*(math.random()+0.5)) Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-beer-1'}}) Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-beer-2', player.name}}) diff --git a/config/graftorio.lua b/config/graftorio.lua index 20dca369..f42f1929 100644 --- a/config/graftorio.lua +++ b/config/graftorio.lua @@ -2,6 +2,6 @@ return { modules = { ["forcestats"] = true, ["logistorage"] = false, - ["general"] = true, + ["other"] = true, } } diff --git a/control.lua b/control.lua index 5f03a842..abc2555a 100644 --- a/control.lua +++ b/control.lua @@ -16,6 +16,8 @@ global.version = require 'overrides.version' -- The current version for exp gami inspect = require 'overrides.inspect' -- Used to covert any value into human readable string Debug = require 'overrides.debug' -- Global Debug module _C = require 'expcore.common' -- _C is used to store lots of common functions expected to be used +_CHEATS = false +_DEBUG = false -- Please go to config/file_loader.lua to edit the files that are loaded log('[INFO] Reading loader config') diff --git a/docs/config.ld b/docs/config.ld index 0041cdce..10bcc3d0 100644 --- a/docs/config.ld +++ b/docs/config.ld @@ -1,4 +1,4 @@ -file = { '../', exclude = { '../.install', '../.lua', '../.luarocks' } } +file = { '../', exclude = { '../.lua', '../.luarocks' } } dir = '../docs' project = 'ExpGaming Scenario' title = 'ExpGaming Scenario' diff --git a/expcore/async.lua b/expcore/async.lua index edfb3a45..346932ca 100644 --- a/expcore/async.lua +++ b/expcore/async.lua @@ -36,7 +36,7 @@ local Async = {} local internal_run = Token.register(function(params) local func = Token.get(params.token) - return func(unpack(params.params)) + return func(table.unpack(params.params)) end) --[[-- Register a new async function, must called when the file is loaded diff --git a/expcore/commands.lua b/expcore/commands.lua index 548fdddd..18cbf289 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -692,7 +692,7 @@ nb: use error(error_message) within your callback to trigger do not trigger dire @treturn boolean The opposite of success so true means to cancel execution, used internally @usage-- Used in the command system to log handler errors -local success, err = pcall(command_data.callback, player, unpack(params)) +local success, err = pcall(command_data.callback, player, table.unpack(params)) if Commands.internal_error(success, command_data.name, err) then return command_log(player, command_data, 'Internal Error: Command Callback Fail', raw_params, command_event.parameter, err) end @@ -806,7 +806,7 @@ function Commands.run_command(command_event) end -- If its not a function throw and error - if not type(parse_callback) == 'function' then + 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 @@ -820,7 +820,7 @@ function Commands.run_command(command_event) end -- input: string, player: LuaPlayer, reject: function, ... extra args - local success, param_parsed = pcall(parse_callback, raw_params[index], player, reject, unpack(param_data.parse_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) end @@ -837,7 +837,7 @@ function Commands.run_command(command_event) 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 not param_parsed == Commands.defines.error then + 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'} end @@ -853,7 +853,7 @@ function Commands.run_command(command_event) -- Run the command -- player: LuaPlayer, ... command params, raw: string params[command_data.max_param_count+1] = raw_input - local success, rtn = pcall(command_data.callback, player, unpack(params)) + 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) end diff --git a/expcore/gui/left_flow.lua b/expcore/gui/left_flow.lua index 6e601496..3069f17a 100644 --- a/expcore/gui/left_flow.lua +++ b/expcore/gui/left_flow.lua @@ -90,7 +90,7 @@ 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.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) - local func_name = debug_info.name or "" + local func_name = debug_info.name or ("") Gui._left_flow_order_src = file_name..":"..func_name end diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index b2758e07..25b6ebdc 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -59,7 +59,7 @@ end local function get_defined_at(level) local debug_info = debug.getinfo(level, "Sn") local file_name = debug_info.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) - local func_name = debug_info.name or "" + local func_name = debug_info.name or ("") return file_name..":"..func_name end diff --git a/expcore/gui/top_flow.lua b/expcore/gui/top_flow.lua index 6e860899..0ee4f6d6 100644 --- a/expcore/gui/top_flow.lua +++ b/expcore/gui/top_flow.lua @@ -40,6 +40,7 @@ Gui.toolbar_button_style(button, false) ]] function Gui.toolbar_button_style(button, state, size) + ---@cast button LuaGuiElement if state then button.style = Gui.top_flow_button_toggled_style else @@ -107,7 +108,7 @@ 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.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) - local func_name = debug_info.name or "" + local func_name = debug_info.name or ("") Gui._top_flow_order_src = file_name..":"..func_name end diff --git a/modules/addons/chat-reply.lua b/modules/addons/chat-reply.lua index e0fc661c..2f7cf3f9 100644 --- a/modules/addons/chat-reply.lua +++ b/modules/addons/chat-reply.lua @@ -37,10 +37,10 @@ Event.add(defines.events.on_console_chat, function(event) for key_word, reply in pairs(config.commands) do if message:find(prefix..key_word) then if type(reply) == 'function' then - reply = reply(player, true) + local msg = reply(player, true) if reply then - game.print{'chat-bot.reply', reply} + game.print{'chat-bot.reply', msg} end else diff --git a/modules/commands/warnings.lua b/modules/commands/warnings.lua index ccd4d6a0..0bce9168 100644 --- a/modules/commands/warnings.lua +++ b/modules/commands/warnings.lua @@ -67,7 +67,7 @@ Commands.new_command('clear-warnings', 'Clears all warnings (and script warnings :add_param('player', false, 'player') :register(function(player, action_player) Warnings.clear_warnings(action_player, player.name) - Warnings.clear_script_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} diff --git a/modules/control/jail.lua b/modules/control/jail.lua index b5bf7df4..a171c23c 100644 --- a/modules/control/jail.lua +++ b/modules/control/jail.lua @@ -83,12 +83,12 @@ function Jail.jail_player(player, by_player_name, reason) if has_role(player, 'Jail') then return end local roles = get_roles(player) - player.walking_state = { walking = false } + player.walking_state = { walking = false, direction = player.walking_state.direction } player.riding_state = { acceleration = defines.riding.acceleration.nothing, direction = player.riding_state.direction } player.mining_state = { mining = false } - player.shooting_state = { state = defines.shooting.not_shooting } + player.shooting_state = { state = defines.shooting.not_shooting, position = player.shooting_state.position } player.picking_state = false - player.repair_state = { repairing = false } + 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) diff --git a/modules/control/selection.lua b/modules/control/selection.lua index 4939253b..eb481872 100644 --- a/modules/control/selection.lua +++ b/modules/control/selection.lua @@ -129,7 +129,7 @@ function Selection.on_selection(selection_name, handler) Event.add(defines.events.on_player_selected_area, function(event) local selection = selections[event.player_index] if not selection or selection.name ~= selection_name then return end - handler(event, unpack(selection.arguments)) + handler(event, table.unpack(selection.arguments)) end) end @@ -140,13 +140,13 @@ function Selection.on_alt_selection(selection_name, handler) Event.add(defines.events.on_player_alt_selected_area, function(event) local selection = selections[event.player_index] if not selection or selection.name ~= selection_name then return end - handler(event, unpack(selection.arguments)) + handler(event, table.unpack(selection.arguments)) end) 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) + 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) diff --git a/modules/control/warps.lua b/modules/control/warps.lua index 4c8cfbc8..bcf43074 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -33,6 +33,7 @@ local Warps = {} -- Global lookup table for force name to task ids local force_warps = {_uid=1} +---@cast force_warps table Global.register(force_warps, function(tbl) force_warps = tbl end) diff --git a/modules/graftorio/forcestats.lua b/modules/graftorio/forcestats.lua index 9839a484..2d371c24 100644 --- a/modules/graftorio/forcestats.lua +++ b/modules/graftorio/forcestats.lua @@ -6,15 +6,18 @@ local lib = {} lib.collect_production = function() for _, force in pairs(game.forces) 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 + ---@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 = {}, @@ -138,17 +141,11 @@ lib.collect_loginet = function() end end - ----@class ResearchStatistics ----@field current Research ----@field queue Research[] - ---@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 diff --git a/modules/graftorio/general.lua b/modules/graftorio/general.lua index 29c9ca1f..020ed262 100644 --- a/modules/graftorio/general.lua +++ b/modules/graftorio/general.lua @@ -12,11 +12,10 @@ Global.register(lib.data, function(tbl) end) ---@class Statistics ----@field trains TrainStatistics ----@field power PowerStatistics ----@field production ProductionStatistics ----@field robots RobotStatistics ----@field other OtherStatistics +---@field production ProductionStatistics? +---@field robots RobotStatistics? +---@field other OtherStatistics? +---@field research Research[]? Event.on_init(function() ---@type table @@ -29,7 +28,6 @@ end) ---@class OtherStatistics ---@field tick uint ---@field evolution EvolutionStatistics ----@field research ResearchStatistics ---@class EvolutionStatistics ---@field evolution_factor double diff --git a/modules/graftorio/require.lua b/modules/graftorio/require.lua index d4c05257..8d378f2b 100644 --- a/modules/graftorio/require.lua +++ b/modules/graftorio/require.lua @@ -1,26 +1,27 @@ local Commands = require("expcore.commands") local config = require("config.graftorio") local statics = require("modules.graftorio.statics") +local general = require("modules.graftorio.general") local forcestats = nil -local general = nil + if config.modules.forcestats then forcestats = require("modules.graftorio.forcestats") end -if config.modules.general then - general = require("modules.graftorio.general") -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.general then general.collect_other() end - if config.modules.forcestats then - 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/modules/gui/debug/model.lua b/modules/gui/debug/model.lua index 101ba30b..435897db 100644 --- a/modules/gui/debug/model.lua +++ b/modules/gui/debug/model.lua @@ -6,7 +6,7 @@ local type = type local concat = table.concat local inspect = table.inspect local pcall = pcall -local loadstring = loadstring +local loadstring = loadstring ---@diagnostic disable-line local rawset = rawset local Public = {} diff --git a/modules/gui/vlayer.lua b/modules/gui/vlayer.lua index 19b5d474..e4adccfa 100644 --- a/modules/gui/vlayer.lua +++ b/modules/gui/vlayer.lua @@ -32,7 +32,8 @@ local function format_energy(amount, unit) end end - local formatted, k = amount + local k + local formatted = amount while true do formatted, k = string.gsub(formatted, '^(-?%d+)(%d%d%d)', '%1,%2') diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 4e489a83..54ffb1d4 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -806,6 +806,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 PlayerInRange:set(player, closest_warp.warp_id) end @@ -819,6 +820,7 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing), function() add_warp_element.enabled = true 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 add_warp_element.enabled = false add_warp_element.tooltip = {'warp-list.too-close', closest_warp.name} end diff --git a/overrides/debug.lua b/overrides/debug.lua index 20be17a8..49bb1369 100644 --- a/overrides/debug.lua +++ b/overrides/debug.lua @@ -127,7 +127,7 @@ function Debug.object_type(object) end ---Shows the given message if debug is on. ----@param position Position +---@param position MapPosition ---@param message string function Debug.print_position(position, message) Debug.print(format('%s %s', serialize(position), message)) diff --git a/overrides/table.lua b/overrides/table.lua index 3d0233d7..f6503f0d 100644 --- a/overrides/table.lua +++ b/overrides/table.lua @@ -161,7 +161,7 @@ function table.extract_keys(tbl, ...) for _, key in pairs({...}) do table.insert(values, tbl[key]) end - return unpack(values) + return table.unpack(values) end --- Adds an element into a specific index position while shuffling the rest down diff --git a/utils/game.lua b/utils/game.lua index f2259bf6..98903554 100644 --- a/utils/game.lua +++ b/utils/game.lua @@ -51,10 +51,13 @@ function Game.player_print(str, color) end --[[ - @param Position String to display at + Creates a floating text entity at a location with the specified color. + Example: "+10 iron" or "-10 coins" + + @param surface LuaSurface + @param position String to display at @param text String to display @param color table in {r = 0~1, g = 0~1, b = 0~1}, defaults to white. - @param surface LuaSurface @return the created entity ]] diff --git a/utils/task.lua b/utils/task.lua index 6579c77e..edccfcce 100644 --- a/utils/task.lua +++ b/utils/task.lua @@ -25,7 +25,7 @@ global.tpt = global.task_queue_speed local function get_task_per_tick() if game.tick % 300 == 0 then local size = global.total_task_weight - global.tpt = math.floor(math.log10(size + 1)) * global.task_queue_speed + global.tpt = math.floor(math.log(size + 1, 10)) * global.task_queue_speed if global.tpt < 1 then global.tpt = 1 end