Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 0 additions & 194 deletions exp_legacy/module/modules/control/selection.lua

This file was deleted.

30 changes: 16 additions & 14 deletions exp_legacy/module/modules/gui/vlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local format_number = require("util").format_number --- @dep util
local config = require("modules.exp_legacy.config.vlayer") --- @dep config.vlayer
local vlayer = require("modules.exp_legacy.modules.control.vlayer")
local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection
local SelectionConvertArea = "VlayerConvertChest"

local Selection = require("modules/exp_util/selection")
local SelectArea = Selection.connect("ExpGui_VLayer")

--- Align an aabb to the grid by expanding it
local function aabb_align_expand(aabb)
Expand Down Expand Up @@ -72,13 +73,15 @@ local function format_energy(amount, unit)
return formatted .. " " .. suffix .. unit
end

local ExpUtil = require("modules/exp_util")
--- When an area is selected to add protection to the area
Selection.on_selection(SelectionConvertArea, function(event)
SelectArea:on_selection(function(event)
log(ExpUtil.format_any(event))
local area = aabb_align_expand(event.area)
local player = game.players[event.player_index]

if not player then
return nil
return
end

local container = Gui.get_left_element(vlayer_container, player)
Expand All @@ -91,22 +94,22 @@ Selection.on_selection(SelectionConvertArea, function(event)
entities = event.surface.find_entities_filtered{ area = area, name = "constant-combinator", force = player.force }
else
player.print{ "vlayer.power-on-space-research", config.power_on_space_research.name, config.power_on_space_research.level }
return nil
return
end
else
entities = event.surface.find_entities_filtered{ area = area, name = "steel-chest", force = player.force }
end

if #entities == 0 then
player.print{ "vlayer.steel-chest-detect" }
return nil
return
elseif #entities > 1 then
player.print{ "vlayer.result-unable", { "vlayer.control-type-" .. target:gsub("_", "-") }, { "vlayer.result-multiple" } }
return nil
return
end

if not entities[1] then
return nil
return
end

local e = entities[1]
Expand All @@ -115,20 +118,20 @@ Selection.on_selection(SelectionConvertArea, function(event)

if e.name and e.name == "steel-chest" and (not e.get_inventory(defines.inventory.chest).is_empty()) then
player.print{ "vlayer.steel-chest-empty" }
return nil
return
end

if (vlayer.get_interface_counts()[target] >= config.interface_limit[target]) then
player.print{ "vlayer.result-unable", { "vlayer.control-type-" .. target:gsub("_", "-") }, { "vlayer.result-limit" } }
return nil
return
end

e.destroy()

if target == "energy" then
if not vlayer.create_energy_interface(event.surface, e_pos, player) then
player.print{ "vlayer.result-unable", { "vlayer.control-type-energy" }, { "vlayer.result-space" } }
return nil
return
end
elseif target == "circuit" then
vlayer.create_circuit_interface(event.surface, e_pos, e_circ, player)
Expand Down Expand Up @@ -400,11 +403,10 @@ local vlayer_gui_control_build = Gui.define("vlayer_gui_control_build")
}:style{
width = 200,
}:on_click(function(def, player, element)
if Selection.is_selecting(player, SelectionConvertArea) then
Selection.stop(player)
if SelectArea:stop(player) then
player.print{ "vlayer.exit" }
else
Selection.start(player, SelectionConvertArea)
SelectArea:start(player)
player.print{ "vlayer.enter" }
end

Expand Down
16 changes: 7 additions & 9 deletions exp_scenario/module/commands/artillery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Adds a command that helps shoot artillery

local AABB = require("modules/exp_util/aabb")
local Commands = require("modules/exp_commands")
local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection
local SelectionName = "ExpCommand_Artillery"

local Selection = require("modules/exp_util/selection")
local SelectArea = Selection.connect("ExpCommand_Artillery")

local floor = math.floor
local abs = math.abs
Expand Down Expand Up @@ -37,18 +38,15 @@ end
--- @overload fun(player: LuaPlayer)
commands.artillery = Commands.new("artillery", { "exp-commands_artillery.description" })
:register(function(player)
if Selection.is_selecting(player, SelectionName) then
Selection.stop(player)
if SelectArea:stop(player) then
return Commands.status.success{ "exp-commands_artillery.exit" }
else
Selection.start(player, SelectionName)
return Commands.status.success{ "exp-commands_artillery.enter" }
end
SelectArea:start(player)
return Commands.status.success{ "exp-commands_artillery.enter" }
end) --[[ @as any ]]

--- when an area is selected to add protection to the area
Selection.on_selection(SelectionName, function(event)
--- @cast event EventData.on_player_selected_area
SelectArea:on_selection(function(event)
local area = AABB.expand(event.area)
local player = game.players[event.player_index]
local surface = event.surface
Expand Down
Loading