From a52f447ff94f775cd6439ca68fb5ec30025f6059 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sat, 16 May 2020 16:36:38 +0100 Subject: [PATCH 01/10] Added quickbar preset command --- config/expcore/roles.lua | 1 + config/preset_player_quickbar.lua | 8 ++++++++ modules/commands/quickbar.lua | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 config/preset_player_quickbar.lua create mode 100644 modules/commands/quickbar.lua diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 763fd132..2e5a1d7d 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -141,6 +141,7 @@ Roles.new_role('Sponsor','Spon') 'command/home-get', 'command/return', 'fast-tree-decon', + 'command/load-quickbar' } Roles.new_role('Supporter','Sup') diff --git a/config/preset_player_quickbar.lua b/config/preset_player_quickbar.lua new file mode 100644 index 00000000..9764291b --- /dev/null +++ b/config/preset_player_quickbar.lua @@ -0,0 +1,8 @@ +--- Preset quickbar items that players can load +-- @config Preset-Player-Quickbar + +return { + players={ --- @setting players list of all players and their quickbar items + dangerarea={'transport-belt','fast-transport-belt'} + } +} diff --git a/modules/commands/quickbar.lua b/modules/commands/quickbar.lua new file mode 100644 index 00000000..db22b6b0 --- /dev/null +++ b/modules/commands/quickbar.lua @@ -0,0 +1,26 @@ +--[[-- Commands Module - Quickbar + - Adds a command that allows players to load Quickbar presets + @commands LoadQuickbar +]] + +local Commands = require 'expcore.commands' --- @dep expcore.commands +local Roles = require 'expcore.roles' --- @dep expcore.roles +local Game = require 'utils.game' --- @dep utils.game +local config = require 'config.preset_player_quickbar' --- @dep config.preset_player_quickbar +require 'config.expcore.command_general_parse' + + +--- Changes the amount of bonus you receive +-- @command bonus +-- @tparam number amount range 0-50 the percent increase for your bonus +Commands.new_command('load-quickbar','Loads your preset Quickbar items') +:register(function(player) + if config.players[player.name] then + local custom_quickbar = config.players[player.name] + for i, item_name in ipairs(custom_quickbar) do + player.set_quick_bar_slot(i, item_name) + end + else + Commands.print('Quickbar preset not found','red') + end +end) From 54b657ca841f67c1ea38883723d793adbb1849d1 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sat, 16 May 2020 16:40:10 +0100 Subject: [PATCH 02/10] Alter documentation --- modules/commands/quickbar.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/commands/quickbar.lua b/modules/commands/quickbar.lua index db22b6b0..72886cbf 100644 --- a/modules/commands/quickbar.lua +++ b/modules/commands/quickbar.lua @@ -10,9 +10,8 @@ local config = require 'config.preset_player_quickbar' --- @dep config.preset_pl require 'config.expcore.command_general_parse' ---- Changes the amount of bonus you receive --- @command bonus --- @tparam number amount range 0-50 the percent increase for your bonus +--- Loads your quickbar preset +-- @command load-quickbar Commands.new_command('load-quickbar','Loads your preset Quickbar items') :register(function(player) if config.players[player.name] then From ffbc96fb8498032f545b0caee6c6af2a0f024634 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sat, 16 May 2020 16:44:28 +0100 Subject: [PATCH 03/10] Load module under game commands --- config/_file_loader.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/_file_loader.lua b/config/_file_loader.lua index c78f6bde..c6ea3ff9 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -27,6 +27,7 @@ return { 'modules.commands.find', 'modules.commands.bonus', 'modules.commands.home', + 'modules.commands.quickbar', -- QoL Addons 'modules.addons.station-auto-name', 'modules.addons.greetings', @@ -57,4 +58,4 @@ return { '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 -} \ No newline at end of file +} From 408b5d7abd8647372b4f9074de76574c680edcf5 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sat, 16 May 2020 17:45:10 +0100 Subject: [PATCH 04/10] Removed player config level and useing error command --- config/preset_player_quickbar.lua | 4 +--- modules/commands/quickbar.lua | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/config/preset_player_quickbar.lua b/config/preset_player_quickbar.lua index 9764291b..079ccd87 100644 --- a/config/preset_player_quickbar.lua +++ b/config/preset_player_quickbar.lua @@ -2,7 +2,5 @@ -- @config Preset-Player-Quickbar return { - players={ --- @setting players list of all players and their quickbar items - dangerarea={'transport-belt','fast-transport-belt'} - } + dangerarea={'transport-belt','fast-transport-belt'} } diff --git a/modules/commands/quickbar.lua b/modules/commands/quickbar.lua index 72886cbf..dae64e24 100644 --- a/modules/commands/quickbar.lua +++ b/modules/commands/quickbar.lua @@ -14,12 +14,12 @@ require 'config.expcore.command_general_parse' -- @command load-quickbar Commands.new_command('load-quickbar','Loads your preset Quickbar items') :register(function(player) - if config.players[player.name] then - local custom_quickbar = config.players[player.name] + if config[player.name] then + local custom_quickbar = config[player.name] for i, item_name in ipairs(custom_quickbar) do player.set_quick_bar_slot(i, item_name) end else - Commands.print('Quickbar preset not found','red') + Commands.error('Quickbar preset not found') end end) From d0a23a1a5906cd49cff7b8b6a7d61e268dc2f012 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sat, 16 May 2020 22:44:30 +0100 Subject: [PATCH 05/10] Iterate save using pairs instaid of ipairs, remove erronus require, add save fuction --- config/expcore/roles.lua | 3 ++- modules/commands/quickbar.lua | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 2e5a1d7d..7d1fd4e1 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -141,7 +141,8 @@ Roles.new_role('Sponsor','Spon') 'command/home-get', 'command/return', 'fast-tree-decon', - 'command/load-quickbar' + 'command/load-quickbar', + 'command/save-quickbar' } Roles.new_role('Supporter','Sup') diff --git a/modules/commands/quickbar.lua b/modules/commands/quickbar.lua index dae64e24..8c64f3aa 100644 --- a/modules/commands/quickbar.lua +++ b/modules/commands/quickbar.lua @@ -1,13 +1,13 @@ --[[-- Commands Module - Quickbar - Adds a command that allows players to load Quickbar presets @commands LoadQuickbar + @commands SaveQuickbar ]] local Commands = require 'expcore.commands' --- @dep expcore.commands local Roles = require 'expcore.roles' --- @dep expcore.roles local Game = require 'utils.game' --- @dep utils.game local config = require 'config.preset_player_quickbar' --- @dep config.preset_player_quickbar -require 'config.expcore.command_general_parse' --- Loads your quickbar preset @@ -16,10 +16,29 @@ Commands.new_command('load-quickbar','Loads your preset Quickbar items') :register(function(player) if config[player.name] then local custom_quickbar = config[player.name] - for i, item_name in ipairs(custom_quickbar) do - player.set_quick_bar_slot(i, item_name) + for i, item_name in pairs(custom_quickbar) do + if item_name ~= nil and item_name ~= '' then + player.set_quick_bar_slot(i, item_name) + end end else Commands.error('Quickbar preset not found') end end) + +--- Saves your quickbar preset to the script-output folder +-- @command save-quickbar +Commands.new_command('save-quickbar','Saves your Quickbar preset items to file') +:register(function(player) + local quickbar_names = {} + for i=1, 100 do + local slot = player.get_quick_bar_slot(i) + if slot ~= nil then + table.insert(quickbar_names, slot.name) + else + table.insert(quickbar_names, "") + end + end + game.write_file("quickbar_preset.txt", game.table_to_json(quickbar_names), false) + Commands.print("Quickbar saved to local script-output folder") +end) From 6481cf9755e4dae91f2961089b5784e48d216a57 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sun, 17 May 2020 11:24:13 +0100 Subject: [PATCH 06/10] Added toolbar aliases, Save as LUA table --- config/preset_player_quickbar.lua | 2 +- modules/commands/quickbar.lua | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config/preset_player_quickbar.lua b/config/preset_player_quickbar.lua index 079ccd87..fb3ad815 100644 --- a/config/preset_player_quickbar.lua +++ b/config/preset_player_quickbar.lua @@ -2,5 +2,5 @@ -- @config Preset-Player-Quickbar return { - dangerarea={'transport-belt','fast-transport-belt'} + dangerarea={"transport-belt",[2]="fast-transport-belt","express-transport-belt",[11]="transport-belt",[23]="fast-transport-belt",[33]="express-transport-belt"} } diff --git a/modules/commands/quickbar.lua b/modules/commands/quickbar.lua index 8c64f3aa..2a8e1cf8 100644 --- a/modules/commands/quickbar.lua +++ b/modules/commands/quickbar.lua @@ -13,12 +13,13 @@ local config = require 'config.preset_player_quickbar' --- @dep config.preset_pl --- Loads your quickbar preset -- @command load-quickbar Commands.new_command('load-quickbar','Loads your preset Quickbar items') +:add_alias('load-toolbar') :register(function(player) if config[player.name] then local custom_quickbar = config[player.name] for i, item_name in pairs(custom_quickbar) do if item_name ~= nil and item_name ~= '' then - player.set_quick_bar_slot(i, item_name) + player.set_quick_bar_slot(i, item_name) end end else @@ -29,16 +30,15 @@ end) --- 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 quickbar_names = {} for i=1, 100 do local slot = player.get_quick_bar_slot(i) if slot ~= nil then - table.insert(quickbar_names, slot.name) - else - table.insert(quickbar_names, "") + table.insert(quickbar_names, i, slot.name) end end - game.write_file("quickbar_preset.txt", game.table_to_json(quickbar_names), false) - Commands.print("Quickbar saved to local script-output folder") + game.write_file("quickbar_preset.txt", player.name .. " = " .. serpent.line(quickbar_names) .. "\n", true) + Commands.print("Quickbar saved") end) From 91f88b61e9d5b8565dc2f846255ec936e56cbc89 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sun, 17 May 2020 19:47:19 +0100 Subject: [PATCH 07/10] Resolve single @command --- modules/commands/quickbar.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/commands/quickbar.lua b/modules/commands/quickbar.lua index 2a8e1cf8..89974b85 100644 --- a/modules/commands/quickbar.lua +++ b/modules/commands/quickbar.lua @@ -1,7 +1,6 @@ --[[-- Commands Module - Quickbar - Adds a command that allows players to load Quickbar presets - @commands LoadQuickbar - @commands SaveQuickbar + @commands Quickbar ]] local Commands = require 'expcore.commands' --- @dep expcore.commands From af07b76d98babae0f31c0b9c460472c3d7b73cd3 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sun, 17 May 2020 19:48:07 +0100 Subject: [PATCH 08/10] Perfomance fix for adding to table --- modules/commands/quickbar.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/commands/quickbar.lua b/modules/commands/quickbar.lua index 89974b85..f03a4efc 100644 --- a/modules/commands/quickbar.lua +++ b/modules/commands/quickbar.lua @@ -35,7 +35,7 @@ Commands.new_command('save-quickbar','Saves your Quickbar preset items to file') for i=1, 100 do local slot = player.get_quick_bar_slot(i) if slot ~= nil then - table.insert(quickbar_names, i, slot.name) + quickbar_names[i] = slot.name end end game.write_file("quickbar_preset.txt", player.name .. " = " .. serpent.line(quickbar_names) .. "\n", true) From e8c9043fbc0bbd4b29c1ef82ddec22cd03bdc916 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sun, 17 May 2020 20:18:02 +0100 Subject: [PATCH 09/10] Updated preset --- config/preset_player_quickbar.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/preset_player_quickbar.lua b/config/preset_player_quickbar.lua index fb3ad815..de0ea7ef 100644 --- a/config/preset_player_quickbar.lua +++ b/config/preset_player_quickbar.lua @@ -2,5 +2,5 @@ -- @config Preset-Player-Quickbar return { - dangerarea={"transport-belt",[2]="fast-transport-belt","express-transport-belt",[11]="transport-belt",[23]="fast-transport-belt",[33]="express-transport-belt"} + 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"} } From 0c6278a57fe5ba0d9950309a8a4c004f3cb4bca9 Mon Sep 17 00:00:00 2001 From: Kevin Taylor Date: Sun, 17 May 2020 20:32:38 +0100 Subject: [PATCH 10/10] Latest luacheckrc --- Factorio-luacheckrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Factorio-luacheckrc b/Factorio-luacheckrc index 0c0518d1..53d12a83 160000 --- a/Factorio-luacheckrc +++ b/Factorio-luacheckrc @@ -1 +1 @@ -Subproject commit 0c0518d165b0fcee714f9e00b014afd7aba9fbee +Subproject commit 53d12a834fe0657e4be17df67a93c51af4e3981e