diff --git a/exp_legacy/module/config/repair.lua b/exp_legacy/module/config/repair.lua index 2b8d86b5..e2fd69ad 100644 --- a/exp_legacy/module/config/repair.lua +++ b/exp_legacy/module/config/repair.lua @@ -2,14 +2,6 @@ -- @config Repair 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, - }, - 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_scenario/module/commands/repair.lua b/exp_scenario/module/commands/repair.lua index b52a4cfc..bef7629b 100644 --- a/exp_scenario/module/commands/repair.lua +++ b/exp_scenario/module/commands/repair.lua @@ -2,56 +2,73 @@ Adds a command that allows an admin to repair and revive a large area ]] +local AABB = require("modules/exp_util/aabb") local Commands = require("modules/exp_commands") local config = require("modules.exp_legacy.config.repair") --- @dep config.repair +local Selection = require("modules/exp_util/selection") +local SelectArea = Selection.connect("ExpCommand_Waterfill") ---- Repairs entities on your force around you -Commands.new("repair", { "exp-commands_repair.description" }) - :argument("range", { "exp-commands_repair.arg-range" }, Commands.types.integer_range(1, config.max_range)) - :register(function(player, range) - --- @cast range number - local force = player.force - local surface = player.surface -- Allow remote view - local position = player.position -- Allow remote view - local response = { "" } --- @type LocalisedString +--- @class ExpCommands_Repair.commands +local commands = {} - if config.allow_ghost_revive then - local revive_count = 0 - local entities = surface.find_entities_filtered{ - type = "entity-ghost", - position = position, - radius = range, - force = force, - } - - local param = { raise_revive = true } --- @type LuaEntity.silent_revive_param - for _, entity in ipairs(entities) do - if not config.disallow[entity.ghost_name] and (config.allow_blueprint_repair or entity.created_by_corpse) then - revive_count = revive_count + 1 - entity.silent_revive(param) - end - end - - response[#response + 1] = { "exp-commands_repair.response-revive", revive_count } +--- Toggle player selection mode +--- @class ExpCommands_Repair.commands.repair: ExpCommand +commands.repair = Commands.new("repair", { "exp-commands_repair.description" }) + :register(function(player) + if SelectArea:stop(player) then + return Commands.status.success{ "exp-commands_repair.exit" } end - - if config.allow_heal_entities then - local healed_count = 0 - local entities = surface.find_entities_filtered{ - position = position, - radius = range, - force = force, - } - - for _, entity in ipairs(entities) do - if entity.health and entity.max_health and entity.health ~= entity.max_health then - healed_count = healed_count + 1 - entity.health = entity.max_health - end - end - - response[#response + 1] = { "exp-commands_repair.response-heal", healed_count } - end - - return Commands.status.success(response) + SelectArea:start(player) + return Commands.status.success{ "exp-commands_repair.enter" } end) + +--- When an area is selected to be converted to water +SelectArea:on_selection(function(event) + local player = assert(game.get_player(event.player_index)) + local area = AABB.expand(event.area) + local surface = event.surface + local force = player.force + local response = { "" } --- @type LocalisedString + + if config.allow_ghost_revive then + local revive_count = 0 + local entities = surface.find_entities_filtered{ + type = "entity-ghost", + area = area, + force = force, + } + + local param = { raise_revive = true } --- @type LuaEntity.silent_revive_param + for _, entity in ipairs(entities) do + if not (entity.ghost_prototype and entity.ghost_prototype.hidden) and (config.allow_blueprint_repair or entity.created_by_corpse) then + revive_count = revive_count + 1 + entity.silent_revive(param) + end + end + + response[#response + 1] = { "exp-commands_repair.response-revive", revive_count } + end + + if config.allow_heal_entities then + local healed_count = 0 + local entities = surface.find_entities_filtered{ + area = area, + force = force, + } + + for _, entity in ipairs(entities) do + if entity.health and entity.max_health and entity.health ~= entity.max_health then + healed_count = healed_count + 1 + entity.health = entity.max_health + end + end + + response[#response + 1] = { "exp-commands_repair.response-heal", healed_count } + end + + return player.print(response) +end) + +return { + commands = commands, +} diff --git a/exp_scenario/module/gui/quick_actions.lua b/exp_scenario/module/gui/quick_actions.lua index 1a25af12..b8f7e605 100644 --- a/exp_scenario/module/gui/quick_actions.lua +++ b/exp_scenario/module/gui/quick_actions.lua @@ -13,6 +13,7 @@ local addon_teleport = require("modules/exp_scenario/commands/teleport") local addon_waterfill = require("modules/exp_scenario/commands/waterfill") local addon_home = require("modules/exp_scenario/commands/home") local addon_vlayer = require("modules/exp_scenario/commands/vlayer") +local addon_repair = require("modules/exp_scenario/commands/repair") --- @class ExpGui_QuickActions.elements local Elements = {} @@ -58,6 +59,7 @@ new_quick_action("return", addon_home.commands._return) new_quick_action("set-home", addon_home.commands.set_home) new_quick_action("get-home", addon_home.commands.get_home) new_quick_action("vlayer", addon_vlayer.commands.vlayer) +new_quick_action("repair", addon_repair.commands.repair) --- Container added to the left gui flow --- @class ExpGui_QuickActions.elements.container: ExpElement diff --git a/exp_scenario/module/locale/en.cfg b/exp_scenario/module/locale/en.cfg index c75a927d..731d80af 100644 --- a/exp_scenario/module/locale/en.cfg +++ b/exp_scenario/module/locale/en.cfg @@ -155,7 +155,8 @@ machine-count=And you will need __1__ machines (with the same speed as this one) [exp-commands_repair] description=Repairs entities on your force around you. -arg-range=Range to repair entities within. +enter=Entered selection mode, select the area. +exit=Exited selection mode. # Intentional space left on the two lines below so they can be joined together. response-revive=__1__ entities were revived. response-heal=__1__ entities were healed.