Files
factorio-expcluster/exp_scenario/module/commands/lawnmower.lua
T
bbassieandClaude Opus 5.5 628e4df514 Rework features into a Feature class with per field events
Review points from Cooldude:

- Feature.register(name[, config]) is required again and returns a
  feature object. Each feature has its config, its fields, and its
  overrides, so one registry holds all the data. Only the overrides are
  stored. On load each feature points at its own stored table again.
- The methods are feature:guard(lib), feature:update_config(enabled,
  values), and feature:is_enabled(). Feature.get(name) looks up a
  feature, and commands flag the feature object.
- update_config raises on_config_updated once per changed value, with
  the feature name, path, old value, and new value. The gui refresh only
  reacts to the "enabled" path.
- apply only sets values. on_apply is gone. Lookup sets built from
  lists use Feature.to_set, which is cached by the list itself. A
  replaced list gets a new set, so the sets are also correct after a
  load. Protection exposes getters for its protected names and types.

Web: settings use small inputs, the same size as the config pages.
Fields are shaped like clusterio config field definitions. A field
with an inputComponent renders the component registered with the web
interface, so the role setting now uses core's role input, and other
plugin inputs can be used later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 13:03:11 +00:00

78 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 = Feature.register("lawnmower", {
destroy_decoratives = false, --- @setting destroy_decoratives remove decoratives under entities when they are built
})
local config = feature.config
--- @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,
}