lawnmower changed to selection (#434)

* Update lawnmower.lua

* Update quick_actions.lua

* Update lawnmower.lua

* update locale

* Update lawnmower.lua

* Fix game.get_player

---------

Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com>
This commit is contained in:
2026-06-26 11:54:05 +01:00
committed by GitHub
co-authored by Cooldude2606
parent d548cebc17
commit 21779988f0
3 changed files with 56 additions and 23 deletions
+48 -21
View File
@@ -2,32 +2,58 @@
Adds a command that clean up biter corpse and nuclear hole
]]
local AABB = require("modules/exp_util/aabb")
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.lawnmower") --- @dep config.lawnmower
local Selection = require("modules/exp_util/selection")
local SelectArea = Selection.connect("ExpCommand_Lawnmower")
local config = require("modules.exp_legacy.config.lawnmower")
Commands.new("lawnmower", { "exp-commands_lawnmower.description" })
:argument("range", { "exp-commands_lawnmower.arg-range" }, Commands.types.integer_range(1, 200))
:register(function(player, range)
--- @cast range number
local surface = player.surface
--- @class ExpCommand_Lawnmower.commands
local commands = {}
-- Intentionally left as player.position to allow use in remote view
local entities = 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
--- Toggle player selection mode for lawnmower
--- @class ExpCommands_Lawnmower.commands.lawnmower: ExpCommand
--- @overload fun(player: LuaPlayer)
commands.lawnmower = Commands.new("lawnmower", { "exp-commands_lawnmower.description" })
:register(function(player)
if SelectArea:stop(player) then
return Commands.status.success{ "exp-commands_lawnmower.exit" }
end
local replace_tiles = {}
local tiles = surface.find_tiles_filtered{ position = player.position, radius = range, name = { "nuclear-ground" } }
for i, tile in pairs(tiles) do
replace_tiles[i] = { name = "grass-1", position = tile.position }
end
SelectArea:start(player)
return Commands.status.success{ "exp-commands_lawnmower.enter" }
end) --[[ @as any ]]
surface.set_tiles(replace_tiles)
surface.destroy_decoratives{ position = player.position, radius = range }
end)
--- When an area is selected to be handled
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 area_size = (area.right_bottom.x - area.left_top.x) * (area.right_bottom.y - area.left_top.y)
if area_size > 1000 then
player.print({ "exp-commands_lawnmower.area-too-large", 1000, area_size }, Commands.print_settings.error)
return
end
local entities = surface.find_entities_filtered{ area = area, 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
local replace_tiles = {}
local tiles = surface.find_tiles_filtered{ area = area, name = { "nuclear-ground" } }
for i, tile in pairs(tiles) do
replace_tiles[i] = { name = "grass-1", position = tile.position }
end
surface.set_tiles(replace_tiles)
surface.destroy_decoratives{ area = area }
player.print({ "exp-commands_lawnmower.complete", #replace_tiles }, Commands.print_settings.default)
end)
--- @param event EventData.on_built_entity | EventData.on_robot_built_entity | EventData.script_raised_built | EventData.script_raised_revive
local function destroy_decoratives(event)
@@ -48,5 +74,6 @@ if config.destroy_decoratives then
end
return {
events = events
events = events,
commands = commands,
}
@@ -11,6 +11,7 @@ local addon_research = require("modules/exp_scenario/commands/research")
local addon_trains = require("modules/exp_scenario/commands/trains")
local addon_teleport = require("modules/exp_scenario/commands/teleport")
local addon_waterfill = require("modules/exp_scenario/commands/waterfill")
local addon_lawnmower = require("modules/exp_scenario/commands/lawnmower")
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")
@@ -54,6 +55,7 @@ new_quick_action("spawn", addon_teleport.commands.spawn, function(def, player, e
end)
new_quick_action("waterfill", addon_waterfill.commands.waterfill)
new_quick_action("lawnmower", addon_lawnmower.commands.lawnmower)
new_quick_action("home", addon_home.commands.home)
new_quick_action("return", addon_home.commands._return)
new_quick_action("set-home", addon_home.commands.set_home)
+4
View File
@@ -103,6 +103,10 @@ lower-role=You must have a higher role than the target.
[exp-commands_lawnmower]
description=Clean up biter corpse, decoratives and nuclear hole.
arg-range=Range to clean up.
enter=Entered selection mode, select the area to fill with water.
exit=Exited selection mode.
area-too-large=Selected area is too large, must be less than __1__ tiles, selected __2__.
complete=__1__ tiles were handled.
[exp-commands_locate]
description=Opens remote view at the location of the player's last location.