mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-07-26 18:36:23 +09:00
clear blueprint changed to selection (#435)
* Update surface.lua * Update en.cfg * Update surface.lua * Update en.cfg * Fix description keys for ground items and blueprints * Update roles.lua * Update surface.lua * Update quick_actions.lua * Update en.cfg * Update en.cfg * Update surface.lua * Update zh-CN.cfg * Update zh-TW.cfg * . * . * . * Many fixes and reverts --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com>
This commit is contained in:
@@ -2,12 +2,17 @@
|
||||
Adds a command that clear item on ground so blueprint can deploy safely
|
||||
]]
|
||||
|
||||
local AABB = require("modules/exp_util/aabb")
|
||||
local Commands = require("modules/exp_commands")
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local move_items = ExpUtil.move_items_to_surface
|
||||
|
||||
local Commands = require("modules/exp_commands")
|
||||
local Selection = require("modules/exp_util/selection")
|
||||
local SelectArea = Selection.connect("ExpCommand_ClearBlueprint")
|
||||
local format_player_name = Commands.format_player_name_locale
|
||||
|
||||
--- @class ExpCommand_ClearBlueprint.commands
|
||||
local commands = {}
|
||||
|
||||
--- @param surface LuaSurface
|
||||
--- @return LuaItemStack[]
|
||||
local function get_ground_items(surface)
|
||||
@@ -19,71 +24,73 @@ local function get_ground_items(surface)
|
||||
return items
|
||||
end
|
||||
|
||||
--- Clear all items on the ground, optional to select a single surface
|
||||
Commands.new("clear-ground-items", { "exp-commands_surface.description-items" })
|
||||
--- Clear all items on the ground on a surface
|
||||
commands.clear_ground_items = Commands.new("clear-ground-items", { "exp-commands_surface.description-items" })
|
||||
:optional("surface", { "exp-commands_surface.arg-surface" }, Commands.types.surface)
|
||||
:defaults{
|
||||
surface = function(player) return player.surface end
|
||||
}
|
||||
:register(function(player, surface)
|
||||
--- @cast surface LuaSurface?
|
||||
local player_name = format_player_name(player)
|
||||
if surface then
|
||||
move_items{
|
||||
surface = surface,
|
||||
items = get_ground_items(surface),
|
||||
allow_creation = true,
|
||||
name = "iron-chest",
|
||||
}
|
||||
game.print{ "exp-commands_surface.items-surface", player_name, surface.localised_name }
|
||||
else
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
move_items{
|
||||
surface = surface,
|
||||
items = get_ground_items(surface),
|
||||
allow_creation = true,
|
||||
name = "iron-chest",
|
||||
}
|
||||
end
|
||||
game.print{ "exp-commands_surface.items-all", player_name }
|
||||
end
|
||||
end)
|
||||
|
||||
--- Clear all blueprints, optional to select a single surface
|
||||
Commands.new("clear-blueprints", { "exp-commands_surface.description-blueprints" })
|
||||
:optional("surface", { "exp-commands_surface.arg-surface" }, Commands.types.surface)
|
||||
:register(function(player, surface)
|
||||
--- @cast surface LuaSurface?
|
||||
local player_name = format_player_name(player)
|
||||
if surface then
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost" }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
game.print{ "exp-commands_surface.blueprint-surface", player_name, surface.localised_name }
|
||||
else
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost" }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
game.print{ "exp-commands_surface.blueprint-all", player_name }
|
||||
end
|
||||
end)
|
||||
|
||||
--- Clear all blueprints in a radius around you
|
||||
Commands.new("clear-blueprints-radius", { "exp-commands_surface.description-radius" })
|
||||
:argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 100))
|
||||
:register(function(player, radius)
|
||||
--- @cast radius number
|
||||
local player_name = format_player_name(player)
|
||||
local entities = player.surface.find_entities_filtered{
|
||||
type = "entity-ghost",
|
||||
position = player.position,
|
||||
radius = radius,
|
||||
--- @cast surface LuaSurface
|
||||
move_items{
|
||||
surface = surface,
|
||||
items = get_ground_items(surface),
|
||||
allow_creation = true,
|
||||
name = "iron-chest",
|
||||
}
|
||||
local player_name = format_player_name(player)
|
||||
game.print{ "exp-commands_surface.items", player_name, surface.localised_name }
|
||||
end)
|
||||
|
||||
--- Clear all blueprints on a surface
|
||||
commands.clear_blueprints_surface = Commands.new("clear-blueprints-surface", { "exp-commands_surface.description-blueprints-surface" })
|
||||
:optional("surface", { "exp-commands_surface.arg-surface" }, Commands.types.surface)
|
||||
:defaults{
|
||||
surface = function(player) return player.surface end
|
||||
}
|
||||
:register(function(player, surface)
|
||||
--- @cast surface LuaSurface
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost" }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
game.print{ "exp-commands_surface.blueprint-radius", player_name, radius, player.surface.localised_name }
|
||||
local player_name = format_player_name(player)
|
||||
game.print{ "exp-commands_surface.blueprints", player_name, surface.localised_name }
|
||||
end)
|
||||
|
||||
--- Clear all blueprint in the area, selected by toggle player selection mode
|
||||
--- @class ExpCommands_ClearBlueprint.commands.clear_blueprint: ExpCommand
|
||||
--- @overload fun(player: LuaPlayer)
|
||||
commands.clear_blueprints = Commands.new("clear-blueprints", { "exp-commands_surface.description-blueprints" })
|
||||
:register(function(player)
|
||||
if SelectArea:stop(player) then
|
||||
return Commands.status.success{ "exp-commands_surface.exit" }
|
||||
end
|
||||
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_surface.enter" }
|
||||
end) --[[ @as any ]]
|
||||
|
||||
--- When an area is selected
|
||||
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_surface.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
||||
return
|
||||
end
|
||||
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost", area = area }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
game.print({ "exp-commands_surface.complete", #entities }, Commands.print_settings.default)
|
||||
end)
|
||||
|
||||
return {
|
||||
commands = commands,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user