mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-07-26 18:36:23 +09:00
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:
@@ -2,32 +2,58 @@
|
|||||||
Adds a command that clean up biter corpse and nuclear hole
|
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 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" })
|
--- @class ExpCommand_Lawnmower.commands
|
||||||
:argument("range", { "exp-commands_lawnmower.arg-range" }, Commands.types.integer_range(1, 200))
|
local commands = {}
|
||||||
:register(function(player, range)
|
|
||||||
--- @cast range number
|
|
||||||
local surface = player.surface
|
|
||||||
|
|
||||||
-- Intentionally left as player.position to allow use in remote view
|
--- Toggle player selection mode for lawnmower
|
||||||
local entities = surface.find_entities_filtered{ position = player.position, radius = range, type = "corpse" }
|
--- @class ExpCommands_Lawnmower.commands.lawnmower: ExpCommand
|
||||||
for _, entity in pairs(entities) do
|
--- @overload fun(player: LuaPlayer)
|
||||||
if (entity.name ~= "transport-caution-corpse" and entity.name ~= "invisible-transport-caution-corpse") then
|
commands.lawnmower = Commands.new("lawnmower", { "exp-commands_lawnmower.description" })
|
||||||
entity.destroy()
|
:register(function(player)
|
||||||
end
|
if SelectArea:stop(player) then
|
||||||
|
return Commands.status.success{ "exp-commands_lawnmower.exit" }
|
||||||
end
|
end
|
||||||
|
|
||||||
local replace_tiles = {}
|
SelectArea:start(player)
|
||||||
local tiles = surface.find_tiles_filtered{ position = player.position, radius = range, name = { "nuclear-ground" } }
|
return Commands.status.success{ "exp-commands_lawnmower.enter" }
|
||||||
for i, tile in pairs(tiles) do
|
end) --[[ @as any ]]
|
||||||
replace_tiles[i] = { name = "grass-1", position = tile.position }
|
|
||||||
end
|
|
||||||
|
|
||||||
surface.set_tiles(replace_tiles)
|
--- When an area is selected to be handled
|
||||||
surface.destroy_decoratives{ position = player.position, radius = range }
|
SelectArea:on_selection(function(event)
|
||||||
end)
|
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
|
--- @param event EventData.on_built_entity | EventData.on_robot_built_entity | EventData.script_raised_built | EventData.script_raised_revive
|
||||||
local function destroy_decoratives(event)
|
local function destroy_decoratives(event)
|
||||||
@@ -48,5 +74,6 @@ if config.destroy_decoratives then
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
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_trains = require("modules/exp_scenario/commands/trains")
|
||||||
local addon_teleport = require("modules/exp_scenario/commands/teleport")
|
local addon_teleport = require("modules/exp_scenario/commands/teleport")
|
||||||
local addon_waterfill = require("modules/exp_scenario/commands/waterfill")
|
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_home = require("modules/exp_scenario/commands/home")
|
||||||
local addon_vlayer = require("modules/exp_scenario/commands/vlayer")
|
local addon_vlayer = require("modules/exp_scenario/commands/vlayer")
|
||||||
local addon_repair = require("modules/exp_scenario/commands/repair")
|
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)
|
end)
|
||||||
|
|
||||||
new_quick_action("waterfill", addon_waterfill.commands.waterfill)
|
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("home", addon_home.commands.home)
|
||||||
new_quick_action("return", addon_home.commands._return)
|
new_quick_action("return", addon_home.commands._return)
|
||||||
new_quick_action("set-home", addon_home.commands.set_home)
|
new_quick_action("set-home", addon_home.commands.set_home)
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ lower-role=You must have a higher role than the target.
|
|||||||
[exp-commands_lawnmower]
|
[exp-commands_lawnmower]
|
||||||
description=Clean up biter corpse, decoratives and nuclear hole.
|
description=Clean up biter corpse, decoratives and nuclear hole.
|
||||||
arg-range=Range to clean up.
|
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]
|
[exp-commands_locate]
|
||||||
description=Opens remote view at the location of the player's last location.
|
description=Opens remote view at the location of the player's last location.
|
||||||
|
|||||||
Reference in New Issue
Block a user