mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-11 23:54:52 +09:00
- Feature.register returns the config as a second value, so files write `local feature, config = Feature.register(...)`. - The lib is ExpScenario.Features and the instance class with its fields sits on Feature._prototype, which is the __index, the same shape as exp_commands. - update_config only looks at values whose override was added, removed, or replaced. _apply_field sets one value and returns it, so the comparison happens while applying and the second loop only raises. Overrides dropped from the previous set count as candidates because the value reverts to its default. - The `@setting name` tags are gone from the config comments. - Protection is guarded as a whole instead of checking config.enabled in one handler. The handlers also forget mined entities, so get_entities and is_entity_protected now drop invalid references, which also covers entities destroyed without an event. The list getters are gone, the selection overlay builds its lists from Protection.config. - Chat and damage popups are one feature in control/popups.lua. - ignore_admins and command_admin_only are removed, roles cover them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
77 lines
2.9 KiB
Lua
77 lines
2.9 KiB
Lua
--[[-- Commands - Lawnmower
|
|
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 Feature = require("modules/exp_scenario/features")
|
|
local Selection = require("modules/exp_util/selection")
|
|
local SelectArea = Selection.connect("ExpCommand_Lawnmower")
|
|
|
|
local feature, config = Feature.register("lawnmower", {
|
|
destroy_decoratives = false, -- remove decoratives under entities when they are built
|
|
})
|
|
|
|
--- @class ExpCommand_Lawnmower.commands
|
|
local commands = {}
|
|
|
|
--- 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" })
|
|
:add_flags{ feature = feature }
|
|
:register(function(player)
|
|
if SelectArea:stop(player) then
|
|
return Commands.status.success{ "exp_util.selection_exit", { "exp-commands_lawnmower.selection-name" } }
|
|
end
|
|
|
|
SelectArea:start(player)
|
|
return Commands.status.success{ "exp_util.selection_enter", { "exp-commands_lawnmower.selection-name" } }
|
|
end) --[[@as any]]
|
|
|
|
--- 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 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)
|
|
if not config.destroy_decoratives then return end
|
|
local entity = event.entity
|
|
if entity.type ~= "entity-ghost" and entity.type ~= "tile-ghost" and entity.prototype.selectable_in_game then
|
|
entity.surface.destroy_decoratives{ area = entity.selection_box }
|
|
end
|
|
end
|
|
|
|
local e = defines.events
|
|
|
|
return feature:guard{
|
|
events = {
|
|
[e.on_built_entity] = destroy_decoratives,
|
|
[e.on_robot_built_entity] = destroy_decoratives,
|
|
[e.script_raised_built] = destroy_decoratives,
|
|
[e.script_raised_revive] = destroy_decoratives,
|
|
},
|
|
commands = commands,
|
|
}
|