mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Merge branch 'aperx' of https://github.com/PHIDIAS0303/ExpCluster into aperx
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -12,14 +12,14 @@ local Commands = require("modules/exp_commands")
|
||||
local format_player_name = Commands.format_player_name_locale
|
||||
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection
|
||||
local EntityProtection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection
|
||||
|
||||
local format_string = string.format
|
||||
local floor = math.floor
|
||||
|
||||
local SelectionNameEntity = "ExpCommand_ProtectEntity"
|
||||
local SelectionNameArea = "ExpCommand_ProtectArea"
|
||||
local Selection = require("modules/exp_util/selection")
|
||||
local SelectEntities = Selection.connect("ExpCommand_ProtectEntity")
|
||||
local SelectArea = Selection.connect("ExpCommand_ProtectArea")
|
||||
|
||||
local renders = {} --- @type table<number, table<string, LuaRenderObject>> Stores all renders for a player
|
||||
Storage.register({
|
||||
@@ -95,31 +95,26 @@ end
|
||||
Commands.new("protect-entity", { "exp-commands_entity-protection.description-entity" })
|
||||
:add_aliases{ "pe" }
|
||||
:register(function(player)
|
||||
if Selection.is_selecting(player, SelectionNameEntity) then
|
||||
Selection.stop(player)
|
||||
if SelectEntities:stop(player) then
|
||||
return Commands.status.success{ "exp-commands_entity-protection.exit-entity" }
|
||||
else
|
||||
Selection.start(player, SelectionNameEntity)
|
||||
return Commands.status.success{ "exp-commands_entity-protection.enter-entity" }
|
||||
end
|
||||
SelectEntities:start(player)
|
||||
return Commands.status.success{ "exp-commands_entity-protection.enter-entity" }
|
||||
end)
|
||||
|
||||
--- Toggles area protection selection
|
||||
Commands.new("protect-area", { "exp-commands_entity-protection.description-area" })
|
||||
:add_aliases{ "pa" }
|
||||
:register(function(player)
|
||||
if Selection.is_selecting(player, SelectionNameEntity) then
|
||||
Selection.stop(player)
|
||||
if SelectArea:stop(player) then
|
||||
return Commands.status.success{ "exp-commands_entity-protection.exit-area" }
|
||||
else
|
||||
Selection.start(player, SelectionNameEntity)
|
||||
return Commands.status.success{ "exp-commands_entity-protection.enter-area" }
|
||||
end
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_entity-protection.enter-area" }
|
||||
end)
|
||||
|
||||
--- When an area is selected to add protection to entities
|
||||
Selection.on_selection(SelectionNameEntity, function(event)
|
||||
--- @cast event EventData.on_player_selected_area
|
||||
SelectEntities:on_selection(function(event)
|
||||
local player = game.players[event.player_index]
|
||||
for _, entity in ipairs(event.entities) do
|
||||
EntityProtection.add_entity(entity)
|
||||
@@ -130,8 +125,7 @@ Selection.on_selection(SelectionNameEntity, function(event)
|
||||
end)
|
||||
|
||||
--- When an area is selected to remove protection from entities
|
||||
Selection.on_alt_selection(SelectionNameEntity, function(event)
|
||||
--- @cast event EventData.on_player_alt_selected_area
|
||||
SelectEntities:on_alt_selection(function(event)
|
||||
local player = game.players[event.player_index]
|
||||
for _, entity in ipairs(event.entities) do
|
||||
EntityProtection.remove_entity(entity)
|
||||
@@ -142,8 +136,7 @@ Selection.on_alt_selection(SelectionNameEntity, function(event)
|
||||
end)
|
||||
|
||||
--- When an area is selected to add protection to the area
|
||||
Selection.on_selection(SelectionNameArea, function(event)
|
||||
--- @cast event EventData.on_player_selected_area
|
||||
SelectArea:on_selection(function(event)
|
||||
local surface = event.surface
|
||||
local area = expand_area(event.area)
|
||||
local areas = EntityProtection.get_areas(event.surface)
|
||||
@@ -160,8 +153,7 @@ Selection.on_selection(SelectionNameArea, function(event)
|
||||
end)
|
||||
|
||||
--- When an area is selected to remove protection from the area
|
||||
Selection.on_alt_selection(SelectionNameArea, function(event)
|
||||
--- @cast event EventData.on_player_alt_selected_area
|
||||
SelectArea:on_alt_selection(function(event)
|
||||
local surface = event.surface
|
||||
local area = expand_area(event.area)
|
||||
local areas = EntityProtection.get_areas(surface)
|
||||
@@ -177,7 +169,6 @@ end)
|
||||
|
||||
--- When selection starts show all protected entities and protected areas
|
||||
local function on_player_selection_start(event)
|
||||
if event.selection ~= SelectionNameEntity and event.selection ~= SelectionNameArea then return end
|
||||
local player = game.players[event.player_index]
|
||||
local surface = player.surface -- Allow remote view
|
||||
renders[player.index] = {}
|
||||
@@ -210,8 +201,7 @@ local function on_player_selection_start(event)
|
||||
end
|
||||
|
||||
--- When selection ends hide protected entities and protected areas
|
||||
local function on_player_selection_end(event)
|
||||
if event.selection ~= SelectionNameEntity and event.selection ~= SelectionNameArea then return end
|
||||
local function on_player_selection_stop(event)
|
||||
for _, render in pairs(renders[event.player_index]) do
|
||||
if render.valid then render.destroy() end
|
||||
end
|
||||
@@ -219,6 +209,11 @@ local function on_player_selection_end(event)
|
||||
renders[event.player_index] = nil
|
||||
end
|
||||
|
||||
SelectArea:on_start(on_player_selection_start)
|
||||
SelectEntities:on_start(on_player_selection_start)
|
||||
SelectArea:on_stop(on_player_selection_stop)
|
||||
SelectEntities:on_stop(on_player_selection_stop)
|
||||
|
||||
--- When there is a repeat offence print it in chat
|
||||
local function on_repeat_violation(event)
|
||||
Roles.print_to_roles_higher("Regular", {
|
||||
@@ -232,8 +227,6 @@ end
|
||||
|
||||
return {
|
||||
events = {
|
||||
[Selection.events.on_player_selection_start] = on_player_selection_start,
|
||||
[Selection.events.on_player_selection_end] = on_player_selection_end,
|
||||
[EntityProtection.events.on_repeat_violation] = on_repeat_violation,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ Commands.new("repair", { "exp-commands_repair.description" })
|
||||
force = force,
|
||||
}
|
||||
|
||||
local param = { raise_revive = true } --- @type LuaEntity.silent_revive_param
|
||||
for _, entity in ipairs(entities) do
|
||||
-- TODO test for ghost not being a blueprint, https://forums.factorio.com/viewtopic.php?f=28&t=119736
|
||||
if not config.disallow[entity.ghost_name] and (config.allow_blueprint_repair or true) then
|
||||
if not config.disallow[entity.ghost_name] and (config.allow_blueprint_repair or entity.created_by_corpse) then
|
||||
revive_count = revive_count + 1
|
||||
entity.silent_revive()
|
||||
entity.silent_revive(param)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ Adds a command that places shallow water
|
||||
|
||||
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_Waterfill"
|
||||
|
||||
local Selection = require("modules/exp_util/selection")
|
||||
local SelectArea = Selection.connect("ExpCommand_Waterfill")
|
||||
|
||||
local planet = {
|
||||
["nauvis"] = "water-mud",
|
||||
@@ -23,25 +24,22 @@ local commands = {}
|
||||
--- @overload fun(player: LuaPlayer)
|
||||
commands.waterfill = Commands.new("waterfill", { "exp-commands_waterfill.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_waterfill.exit" }
|
||||
end
|
||||
local item_count_cliff = player.get_item_count("cliff-explosives")
|
||||
local item_count_craft = math.min(math.floor(player.get_item_count("explosives") / 10), player.get_item_count("barrel"), player.get_item_count("grenade"))
|
||||
local item_count_total = item_count_cliff + item_count_craft
|
||||
if item_count_total == 0 then
|
||||
return Commands.status.error{ "exp-commands_waterfill.requires-explosives" }
|
||||
else
|
||||
local item_count_cliff = player.get_item_count("cliff-explosives")
|
||||
local item_count_craft = math.min(math.floor(player.get_item_count("explosives") / 10), player.get_item_count("barrel"), player.get_item_count("grenade"))
|
||||
local item_count_total = item_count_cliff + item_count_craft
|
||||
if item_count_total == 0 then
|
||||
return Commands.status.error{ "exp-commands_waterfill.requires-explosives" }
|
||||
else
|
||||
Selection.start(player, SelectionName)
|
||||
return Commands.status.success{ "exp-commands_waterfill.enter" }
|
||||
end
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_waterfill.enter" }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
|
||||
--- When an area is selected to be converted to water
|
||||
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
|
||||
|
||||
@@ -9,15 +9,16 @@ local config = require("modules/exp_legacy/config/bonus")
|
||||
|
||||
--- @param event EventData.on_force_created
|
||||
local function apply_force_bonus(event)
|
||||
local force = event.force
|
||||
for k, v in pairs(config.force_bonus) do
|
||||
event.force[k] = v.initial_value
|
||||
force[k] = v.initial_value
|
||||
end
|
||||
end
|
||||
|
||||
--- @param event EventData.on_surface_created
|
||||
local function apply_surface_bonus(event)
|
||||
local surface = assert(game.get_surface(event.surface_index))
|
||||
for k, v in pairs(config.force_bonus) do
|
||||
for k, v in pairs(config.surface_bonus) do
|
||||
surface[k] = v.initial_value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,34 +7,57 @@ local Gui = require("modules/exp_gui")
|
||||
--- @class ExpGui_Elements
|
||||
local Elements = {}
|
||||
|
||||
--- To help with caching and avoid context changes the player list from the previous update is remembered
|
||||
--- @type (string?)[]
|
||||
local _player_names = {}
|
||||
|
||||
--- Dropdown which allows selecting an online player
|
||||
--- @class ExpGui_Elements.online_player_dropdown: ExpElement
|
||||
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
|
||||
Elements.online_player_dropdown = Gui.define("player_dropdown")
|
||||
:track_all_elements()
|
||||
:draw(function(def, parent)
|
||||
local player_names = Elements.online_player_dropdown._access_player_names()
|
||||
return parent.add{
|
||||
type = "drop-down",
|
||||
items = _player_names,
|
||||
selected_index = #_player_names > 0 and 1 or nil,
|
||||
items = player_names,
|
||||
selected_index = 1,
|
||||
}
|
||||
end)
|
||||
:style{
|
||||
height = 24,
|
||||
} --[[ @as any ]]
|
||||
|
||||
--- To help with caching and avoid context changes the player list from the previous update is remembered
|
||||
--- @type (string?)[]
|
||||
do local _player_names = {}
|
||||
--- Updates the player name list after a join or leave
|
||||
--- @return (string?)[]
|
||||
function Elements.online_player_dropdown._update_player_names()
|
||||
_player_names[#_player_names] = nil -- Nil last element to account for player leave
|
||||
for i, player in pairs(game.connected_players) do
|
||||
_player_names[i] = player.name
|
||||
end
|
||||
return _player_names
|
||||
end
|
||||
|
||||
--- Safely access the player name list
|
||||
--- @return (string?)[]
|
||||
function Elements.online_player_dropdown._access_player_names()
|
||||
if not _player_names[1] then
|
||||
for i, player in pairs(game.connected_players) do
|
||||
_player_names[i] = player.name
|
||||
end
|
||||
end
|
||||
return _player_names
|
||||
end
|
||||
end
|
||||
|
||||
--- Get the selected player name from a online player dropdown
|
||||
--- @param online_player_dropdown LuaGuiElement
|
||||
--- @return string
|
||||
function Elements.online_player_dropdown.get_selected_name(online_player_dropdown)
|
||||
local name = _player_names[online_player_dropdown.selected_index]
|
||||
local player_names = Elements.online_player_dropdown._access_player_names()
|
||||
local name = player_names[online_player_dropdown.selected_index]
|
||||
if not name then
|
||||
online_player_dropdown.selected_index = 1
|
||||
name = _player_names[1] --- @cast name -nil
|
||||
name = player_names[1] --- @cast name -nil
|
||||
end
|
||||
return name
|
||||
end
|
||||
@@ -43,10 +66,11 @@ end
|
||||
--- @param online_player_dropdown LuaGuiElement
|
||||
--- @return LuaPlayer
|
||||
function Elements.online_player_dropdown.get_selected(online_player_dropdown)
|
||||
local name = _player_names[online_player_dropdown.selected_index]
|
||||
local player_names = Elements.online_player_dropdown._access_player_names()
|
||||
local name = player_names[online_player_dropdown.selected_index]
|
||||
if not name then
|
||||
online_player_dropdown.selected_index = 1
|
||||
name = _player_names[1] --- @cast name -nil
|
||||
name = player_names[1] --- @cast name -nil
|
||||
end
|
||||
return assert(game.get_player(name))
|
||||
end
|
||||
@@ -55,20 +79,15 @@ end
|
||||
--- Get the number of players in the dropdown
|
||||
--- @return number
|
||||
function Elements.online_player_dropdown.get_player_count()
|
||||
return #_player_names
|
||||
return #Elements.online_player_dropdown._access_player_names()
|
||||
end
|
||||
|
||||
--- Update all player dropdowns to match the currently online players
|
||||
--- We don't split join and leave because the order would be inconsistent between players and cause desyncs
|
||||
function Elements.online_player_dropdown.refresh_online()
|
||||
_player_names[#_player_names] = nil -- Nil last element to account for player leave
|
||||
|
||||
for i, player in pairs(game.connected_players) do
|
||||
_player_names[i] = player.name
|
||||
end
|
||||
|
||||
local player_names = Elements.online_player_dropdown._update_player_names()
|
||||
for _, online_player_dropdown in Elements.online_player_dropdown:online_elements() do
|
||||
online_player_dropdown.items = _player_names
|
||||
online_player_dropdown.items = player_names
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,8 +5,9 @@ Adds a Gui which creates an selection planner to insert modules into buildings
|
||||
local Gui = require("modules/exp_gui")
|
||||
local AABB = require("modules/exp_util/aabb")
|
||||
local Roles = require("modules/exp_legacy/expcore/roles")
|
||||
local Selection = require("modules/exp_legacy/modules/control/selection")
|
||||
local SelectionModuleArea = "ModuleArea"
|
||||
|
||||
local Selection = require("modules/exp_util/selection")
|
||||
local SelectArea = Selection.connect("ModuleArea")
|
||||
|
||||
local config = require("modules/exp_legacy/config/module")
|
||||
|
||||
@@ -76,7 +77,7 @@ Elements.create_selection_planner = Gui.define("module_inserter/create_selection
|
||||
)
|
||||
:on_click(function(def, player, element)
|
||||
--- @cast def ExpGui_ModuleInserter.elements.create_selection_planner
|
||||
Selection.start(player, SelectionModuleArea, false, def.data[element])
|
||||
SelectArea:start(player, def.data[element])
|
||||
end) --[[ @as any ]]
|
||||
|
||||
--- Used to select the machine to apply modules to
|
||||
@@ -177,7 +178,7 @@ end
|
||||
function Elements.module_table.remove_row(module_table, machine_selector)
|
||||
local rows = Elements.module_table.data[module_table]
|
||||
local row = rows[machine_selector.index]
|
||||
row[machine_selector.index] = nil
|
||||
rows[machine_selector.index] = nil
|
||||
Gui.destroy_if_valid(machine_selector)
|
||||
for _, separator in pairs(row.row_separators) do
|
||||
Gui.destroy_if_valid(separator)
|
||||
@@ -311,7 +312,7 @@ end
|
||||
--- When an area is selected to have module changes applied to it
|
||||
--- @param event EventData.on_player_selected_area
|
||||
--- @param module_table LuaGuiElement
|
||||
Selection.on_selection(SelectionModuleArea, function(event, module_table)
|
||||
SelectArea:on_selection(function(event, module_table)
|
||||
local player = Gui.get_player(event)
|
||||
local area = AABB.expand(event.area)
|
||||
|
||||
|
||||
@@ -401,6 +401,9 @@ end
|
||||
--- @param player LuaPlayer
|
||||
function Elements.container.clear_player_bonus(player)
|
||||
Elements.container.data[player] = {}
|
||||
if not player.character then
|
||||
return
|
||||
end
|
||||
for _, bonus_data in pairs(config.player_bonus) do
|
||||
if not bonus_data.is_special then
|
||||
player[bonus_data.name] = 0
|
||||
|
||||
@@ -304,8 +304,9 @@ end
|
||||
--- @param force LuaForce
|
||||
--- @return number
|
||||
function Elements.container.calculate_starting_research_index(force)
|
||||
local force_data = Elements.container.data[force]
|
||||
local force_data = Elements.container.data[force] or {}
|
||||
local research_index = research_targets.length
|
||||
Elements.container.data[force] = force_data -- needed because of @clusterio/research_sync
|
||||
|
||||
-- # does not work here because it returned the array alloc size
|
||||
for i = 1, research_targets.length do
|
||||
|
||||
Reference in New Issue
Block a user