This commit is contained in:
2026-07-19 13:22:02 +09:00
63 changed files with 1391 additions and 3103 deletions
@@ -14,7 +14,7 @@ Commands.new("clear-inventory", { "exp-commands_clear-inventory.description" })
:register(function(player, other_player)
local inventory = other_player.get_main_inventory()
if not inventory then
return Commands.status.error{ "expcore-commands.reject-player-alive" }
return Commands.status.error{ "exp-commands-parse.player-alive" }
end
transfer_inventory{
+1 -1
View File
@@ -2,7 +2,7 @@
Adds a command that opens the debug frame
]]
local DebugView = require("modules.exp_legacy.modules.gui.debug.main_view") --- @dep modules.gui.debug.main_view
local DebugView = require("modules/exp_scenario/gui/debug/main_view")
local Commands = require("modules/exp_commands")
--- Opens the debug gui.
+15 -5
View File
@@ -4,10 +4,12 @@ Adds a command that allows setting and teleporting to your home position
local ExpUtil = require("modules/exp_util")
local teleport = ExpUtil.teleport_player
local Commands = require("modules/exp_commands")
local Storage = require("modules/exp_util/storage")
--- @class ExpCommand_Home.commands
local commands = {}
--- @type table<number, table<number, [MapPosition?, MapPosition?]>>
local homes = {} -- homes[player_index][surface_index] = { home_pos, return_pos }
Storage.register(homes, function(tbl)
@@ -28,7 +30,8 @@ local function align_to_grid(position)
end
--- Teleports you to your home location on the current surface
Commands.new("home", { "exp-commands_home.description-home" })
--- @class ExpCommand_Home.commands.home: ExpCommand
commands.home = Commands.new("home", { "exp-commands_home.description-home" })
:add_flags{ "character_only" }
:register(function(player)
local surface = player.surface
@@ -50,7 +53,8 @@ Commands.new("home", { "exp-commands_home.description-home" })
end)
--- Teleports you to your previous location on the current surface
Commands.new("return", { "exp-commands_home.description-return" })
--- @class ExpCommand_Home.commands._return: ExpCommand
commands.home_return = Commands.new("return", { "exp-commands_home.description-return" })
:add_flags{ "character_only" }
:register(function(player)
local surface = player.surface
@@ -72,7 +76,8 @@ Commands.new("return", { "exp-commands_home.description-return" })
end)
--- Sets your home location on your current surface to your current position
Commands.new("set-home", { "exp-commands_home.description-set" })
--- @class ExpCommand_Home.commands.set_home: ExpCommand
commands.set_home = Commands.new("set-home", { "exp-commands_home.description-set" })
:add_flags{ "character_only" }
:register(function(player)
local home_position, floor_position = align_to_grid(player.position)
@@ -97,7 +102,8 @@ Commands.new("set-home", { "exp-commands_home.description-set" })
end)
--- Gets your home location on your current surface, is allowed in remote view
Commands.new("get-home", { "exp-commands_home.description-get" })
--- @class ExpCommand_Home.commands.get_home: ExpCommand
commands.get_home = Commands.new("get-home", { "exp-commands_home.description-get" })
:register(function(player)
local surface = player.surface
@@ -114,3 +120,7 @@ Commands.new("get-home", { "exp-commands_home.description-get" })
local _, floor_position = align_to_grid(player_home[1])
return Commands.status.success{ "exp-commands_home.home-get", surface.localised_name, floor_position.x, floor_position.y }
end)
return {
commands = commands,
}
+44 -23
View File
@@ -2,32 +2,52 @@
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 config = require("modules.exp_legacy.config.lawnmower") --- @dep config.lawnmower
local Selection = require("modules/exp_util/selection")
local SelectArea = Selection.connect("ExpCommand_Lawnmower")
local config = require("modules.exp_legacy.config.lawnmower")
Commands.new("lawnmower", { "exp-commands_lawnmower.description" })
:argument("range", { "exp-commands_lawnmower.arg-range" }, Commands.types.integer_range(1, 200))
:register(function(player, range)
--- @cast range number
local surface = player.surface
-- Intentionally left as player.position to allow use in remote view
local entities = surface.find_entities_filtered{ position = player.position, radius = range, 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{ position = player.position, radius = range, name = { "nuclear-ground" } }
for i, tile in pairs(tiles) do
replace_tiles[i] = { name = "grass-1", position = tile.position }
--- @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" })
:register(function(player)
if SelectArea:stop(player) then
return Commands.status.success{ "exp-commands_lawnmower.exit" }
end
surface.set_tiles(replace_tiles)
surface.destroy_decoratives{ position = player.position, radius = range }
end)
SelectArea:start(player)
return Commands.status.success{ "exp-commands_lawnmower.enter" }
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)
@@ -48,5 +68,6 @@ if config.destroy_decoratives then
end
return {
events = events
events = events,
commands = commands,
}
+64 -47
View File
@@ -2,56 +2,73 @@
Adds a command that allows an admin to repair and revive a large area
]]
local AABB = require("modules/exp_util/aabb")
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.repair") --- @dep config.repair
local Selection = require("modules/exp_util/selection")
local SelectArea = Selection.connect("ExpCommand_Waterfill")
--- Repairs entities on your force around you
Commands.new("repair", { "exp-commands_repair.description" })
:argument("range", { "exp-commands_repair.arg-range" }, Commands.types.integer_range(1, config.max_range))
:register(function(player, range)
--- @cast range number
local force = player.force
local surface = player.surface -- Allow remote view
local position = player.position -- Allow remote view
local response = { "" } --- @type LocalisedString
--- @class ExpCommands_Repair.commands
local commands = {}
if config.allow_ghost_revive then
local revive_count = 0
local entities = surface.find_entities_filtered{
type = "entity-ghost",
position = position,
radius = range,
force = force,
}
local param = { raise_revive = true } --- @type LuaEntity.silent_revive_param
for _, entity in ipairs(entities) do
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(param)
end
end
response[#response + 1] = { "exp-commands_repair.response-revive", revive_count }
--- Toggle player selection mode
--- @class ExpCommands_Repair.commands.repair: ExpCommand
commands.repair = Commands.new("repair", { "exp-commands_repair.description" })
:register(function(player)
if SelectArea:stop(player) then
return Commands.status.success{ "exp-commands_repair.exit" }
end
if config.allow_heal_entities then
local healed_count = 0
local entities = surface.find_entities_filtered{
position = position,
radius = range,
force = force,
}
for _, entity in ipairs(entities) do
if entity.health and entity.max_health and entity.health ~= entity.max_health then
healed_count = healed_count + 1
entity.health = entity.max_health
end
end
response[#response + 1] = { "exp-commands_repair.response-heal", healed_count }
end
return Commands.status.success(response)
SelectArea:start(player)
return Commands.status.success{ "exp-commands_repair.enter" }
end)
--- When an area is selected to be converted to water
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 force = player.force
local response = { "" } --- @type LocalisedString
if config.allow_ghost_revive then
local revive_count = 0
local entities = surface.find_entities_filtered{
type = "entity-ghost",
area = area,
force = force,
}
local param = { raise_revive = true } --- @type LuaEntity.silent_revive_param
for _, entity in ipairs(entities) do
if not (entity.ghost_prototype and entity.ghost_prototype.hidden) and (config.allow_blueprint_repair or entity.created_by_corpse) then
revive_count = revive_count + 1
entity.silent_revive(param)
end
end
response[#response + 1] = { "exp-commands_repair.response-revive", revive_count }
end
if config.allow_heal_entities then
local healed_count = 0
local entities = surface.find_entities_filtered{
area = area,
force = force,
}
for _, entity in ipairs(entities) do
if entity.health and entity.max_health and entity.health ~= entity.max_health then
healed_count = healed_count + 1
entity.health = entity.max_health
end
end
response[#response + 1] = { "exp-commands_repair.response-heal", healed_count }
end
return player.print(response)
end)
return {
commands = commands,
}
-90
View File
@@ -1,90 +0,0 @@
--[[-- Commands - Research
Adds a command to enable automatic research queueing
]]
local Storage = require("modules/exp_util/storage")
local Commands = require("modules/exp_commands")
local format_player_name = Commands.format_player_name_locale
local config = require("modules.exp_legacy.config.research") --- @dep config.research
--- @class ExpCommands_Research.commands
local commands = {}
local research = {
res_queue_enable = false
}
Storage.register(research, function(tbl)
research = tbl
end)
--- @param force LuaForce
--- @param silent boolean True when no message should be printed
local function queue_research(force, silent)
local res_q = force.research_queue
local res = force.technologies[config.bonus_inventory.log[config.mod_set].name]
if #res_q < config.queue_amount then
for i = #res_q, config.queue_amount - 1 do
force.add_research(res)
if not silent then
game.print{ "exp-commands_research.queue", res.name, res.level + i }
end
end
end
end
--- @param state boolean? use nil to toggle current state
--- @return boolean # New auto research state
local function set_auto_research(state)
local new_state
if state == nil then
new_state = not research.res_queue_enable
else
new_state = state ~= false
end
research.res_queue_enable = new_state
return new_state
end
--- Sets the auto research state
--- @class ExpCommand_Artillery.commands.artillery: ExpCommand
--- @overload fun(player: LuaPlayer, state: boolean?)
commands.set_auto_research = Commands.new("set-auto-research", { "exp-commands_research.description" })
:optional("state", { "exp-commands_research.arg-state" }, Commands.types.boolean)
:add_aliases{ "auto-research" }
:register(function(player, state)
--- @cast state boolean?
local enabled = set_auto_research(state)
if enabled then
queue_research(player.force --[[@as LuaForce]], true)
end
local player_name = format_player_name(player)
game.print{ "exp-commands_research.auto-research", player_name, enabled }
end) --[[ @as any ]]
--- @param event EventData.on_research_finished
local function on_research_finished(event)
if not research.res_queue_enable then return end
local force = event.research.force
local log_research = assert(config.bonus_inventory.log[config.mod_set], "Unknown mod set: " .. tostring(config.mod_set))
local technology = assert(force.technologies[log_research.name], "Unknown technology: " .. tostring(log_research.name))
if technology.level > log_research.level then
queue_research(force, event.by_script)
end
end
local e = defines.events
return {
commands = commands,
events = {
[e.on_research_finished] = on_research_finished,
},
}
+63 -62
View File
@@ -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,67 @@ 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 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,
}
+9 -1
View File
@@ -5,8 +5,12 @@ Adds a virtual layer to store power to save space.
local Commands = require("modules/exp_commands")
local vlayer = require("modules.exp_legacy.modules.control.vlayer")
--- @class ExpCommand_vlayer.commands
local commands = {}
--- Print all vlayer information
Commands.new("vlayer-info", { "exp-commands_vlayer.description" })
--- @class ExpCommands_vlayer.commands.vlayer: ExpCommand
commands.vlayer = Commands.new("vlayer-info", { "exp-commands_vlayer.description" })
:register(function(player)
local index = 3
local response = { "", "exp-commands_vlayer.title" } --- @type LocalisedString
@@ -16,3 +20,7 @@ Commands.new("vlayer-info", { "exp-commands_vlayer.description" })
end
return Commands.status.success(response)
end)
return {
commands = commands,
}
+1 -2
View File
@@ -41,6 +41,7 @@ commands.waterfill = Commands.new("waterfill", { "exp-commands_waterfill.descrip
--- When an area is selected to be converted to water
SelectArea:on_selection(function(event)
local area = AABB.expand(event.area)
local area_size = AABB.size(area)
local player = game.players[event.player_index]
local surface = event.surface
@@ -51,8 +52,6 @@ SelectArea:on_selection(function(event)
end
]]
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_waterfill.area-too-large", 1000, area_size }, Commands.print_settings.error)
return
+3 -2
View File
@@ -11,7 +11,6 @@ require("modules/exp_scenario/commands/_types")
--- Commands with events
add(require("modules/exp_scenario/commands/protected_entities"))
add(require("modules/exp_scenario/commands/protected_tags"))
add(require("modules/exp_scenario/commands/research"))
--- Commands
require("modules/exp_scenario/commands/admin_chat")
@@ -70,9 +69,9 @@ add(require("modules/exp_scenario/control/station_auto_name"))
--- Guis
add(require("modules/exp_scenario/gui/autofill"))
add(require("modules/exp_scenario/gui/elements"))
add(require("modules/exp_scenario/gui/landfill_blueprint"))
add(require("modules/exp_scenario/gui/module_inserter"))
add(require("modules/exp_scenario/gui/player_bonus"))
add(require("modules/exp_scenario/gui/player_list"))
add(require("modules/exp_scenario/gui/player_stats"))
add(require("modules/exp_scenario/gui/production_stats"))
add(require("modules/exp_scenario/gui/quick_actions"))
@@ -82,3 +81,5 @@ add(require("modules/exp_scenario/gui/rocket_info"))
add(require("modules/exp_scenario/gui/science_production"))
add(require("modules/exp_scenario/gui/surveillance"))
add(require("modules/exp_scenario/gui/task_list"))
add(require("modules/exp_scenario/gui/debug/shim"))
add(require("modules/exp_scenario/gui/debug/event_view"))
+2 -2
View File
@@ -11,7 +11,7 @@ local config = require("modules/exp_legacy/config/bonus")
local function apply_force_bonus(event)
local force = event.force
for k, v in pairs(config.force_bonus) do
force[k] = v.initial_value
force[k] = math.floor(v.max_value / 2)
end
end
@@ -19,7 +19,7 @@ end
local function apply_surface_bonus(event)
local surface = assert(game.get_surface(event.surface_index))
for k, v in pairs(config.surface_bonus) do
surface[k] = v.initial_value
surface[k] = math.floor(v.max_value / 2)
end
end
+49 -8
View File
@@ -43,7 +43,7 @@ local function prevent_deconstruction(entity)
end
-- Not minable, selectable, or deconstructive
if not entity.minable or not entity.prototype.selectable_in_game or entity.has_flag("not-deconstructable") then
if not entity.minable_flag or not entity.prototype.selectable_in_game or entity.has_flag("not-deconstructable") then
return true
end
@@ -88,6 +88,37 @@ local function try_deconstruct_output_chest(entity)
order_deconstruction_async:start_after(10, target)
end
--- Check if beacon should be deconstructed
--- @param entity LuaEntity
local function try_deconstruct_nearby_beacon(entity)
-- Get a valid chest as the target
local beacons = entity.get_beacons()
local beacon_in_use = false
-- if beacon is not supported
if not beacons then
return
end
for _, b in pairs(beacons) do
if not b.to_be_deconstructed() then
for _, r in pairs(b.get_beacon_effect_receivers()) do
if r ~= entity then
if not r.to_be_deconstructed() then
beacon_in_use = true
break
end
end
end
-- Deconstruct the beacon
if not beacon_in_use then
order_deconstruction_async:start_after(10, { name = b.name, position = b.position })
end
end
end
end
--- Check if a miner should be deconstructed
--- @param entity LuaEntity
local function try_deconstruct_miner(entity)
@@ -117,11 +148,13 @@ local function try_deconstruct_miner(entity)
try_deconstruct_output_chest(entity)
end
--[[
TODO Fluidbox is changed to fluidbox_neighbours
-- Try deconstruct the beacon
if config.beacon then
try_deconstruct_nearby_beacon(entity)
end
-- Skip pipe build if not required
if not config.fluid or #entity.fluidbox == 0 then
if not config.fluid or entity.fluids_count > 1 then
return
end
@@ -189,11 +222,19 @@ local function try_deconstruct_miner(entity)
]]
end
local max_quality = ""
for _, q in pairs(prototypes.quality) do
if not q.next then
max_quality = q.name
end
end
--- Get the max mining radius
local max_mining_radius = 0
for _, proto in pairs(prototypes.get_entity_filtered{ { filter = "type", type = "mining-drill" } }) do
if proto.mining_drill_radius > max_mining_radius then
max_mining_radius = proto.mining_drill_radius
if proto.mining_drill_radius then
max_mining_radius = math.max(assert(proto.get_mining_drill_radius(max_quality)), max_mining_radius)
end
end
@@ -218,8 +259,8 @@ local function on_resource_depleted(event)
-- Check which could have reached this resource
for _, drill in pairs(drills) do
local radius = drill.prototype.mining_drill_radius
local dx = math.abs(drill.position.x - resource.position.x)
local dy = math.abs(drill.position.y - resource.position.y)
local dx = math.abs(drill.position.x - position.x)
local dy = math.abs(drill.position.y - position.y)
if dx <= radius and dy <= radius then
try_deconstruct_miner(drill)
end
+3 -1
View File
@@ -12,7 +12,7 @@ local function on_research_finished(event)
if config.bonus_inventory.enabled and config.bonus_inventory.res[research_name] then
event.research.force[config.bonus_inventory.name] = math.min((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit)
end
if config.pollution_ageing_by_research and config.bonus_inventory.res[research_name] then
game.map_settings.pollution.ageing = math.min(10, event.research.level / 5)
end
@@ -41,6 +41,8 @@ local e = defines.events
return {
events = {
[e.on_research_finished] = on_research_finished,
[e.on_research_reversed] = on_research_finished,
[e.on_research_started] = on_research_started,
[e.on_research_queued] = on_research_started,
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ end
local function protect_entity(entity)
if entity and entity.valid then
entity.destructible = false
entity.minable = false
entity.minable_flag = false
entity.rotatable = false
entity.operable = false
end
+114
View File
@@ -0,0 +1,114 @@
local Gui = require("modules/exp_scenario/gui/debug/shim")
local Model = require("modules/exp_scenario/gui/debug/model")
local Color = require("modules/exp_util/include/color")
local dump = Model.dump
local Public = {}
local ignore = {
_G = true,
assert = true,
collectgarbage = true,
error = true,
getmetatable = true,
ipairs = true,
load = true,
loadstring = true,
next = true,
pairs = true,
pcall = true,
print = true,
rawequal = true,
rawlen = true,
rawget = true,
rawset = true,
select = true,
setmetatable = true,
tonumber = true,
tostring = true,
type = true,
xpcall = true,
_VERSION = true,
["module"] = true,
require = true,
package = true,
unpack = true,
table = true,
string = true,
bit32 = true,
math = true,
debug = true,
serpent = true,
log = true,
table_size = true,
storage = true,
remote = true,
commands = true,
settings = true,
rcon = true,
script = true,
util = true,
mod_gui = true,
game = true,
rendering = true,
}
local header_name = Gui.uid_name()
local left_panel_name = Gui.uid_name()
local right_panel_name = Gui.uid_name()
Public.name = "_G"
function Public.show(container)
local main_flow = container.add{ type = "flow", direction = "horizontal" }
local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name }
local left_panel_style = left_panel.style
left_panel_style.width = 300
for key, value in pairs(_G) do
if not ignore[key] then
local header =
left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = tostring(key) }
Gui.set_data(header, value)
end
end
local right_panel = main_flow.add{ type = "text-box", name = right_panel_name }
right_panel.read_only = true
right_panel.selectable = true
local right_panel_style = right_panel.style
right_panel_style.vertically_stretchable = true
right_panel_style.horizontally_stretchable = true
right_panel_style.maximal_width = 1000
right_panel_style.maximal_height = 1000
Gui.set_data(left_panel, { right_panel = right_panel, selected_header = nil })
end
Gui.on_click(
header_name,
function(event)
local element = event.element
local value = Gui.get_data(element)
local left_panel = element.parent.parent
local left_panel_data = Gui.get_data(left_panel)
local right_panel = left_panel_data.right_panel
local selected_header = left_panel_data.selected_header
if selected_header then
selected_header.style.font_color = Color.white
end
element.style.font_color = Color.orange
left_panel_data.selected_header = element
local content = dump(value)
right_panel.text = content
end
)
return Public
@@ -0,0 +1,174 @@
local Storage = require("modules/exp_util/storage")
local Gui = require("modules/exp_scenario/gui/debug/shim")
local Model = require("modules/exp_scenario/gui/debug/model")
local format = string.format
local insert = table.insert
local events = defines.events
-- Constants
local events_to_keep = 10
-- Local vars
local Public = {
name = "Events",
events = {}
}
local name_lookup = {}
-- GUI names
local checkbox_name = Gui.uid_name()
local filter_name = Gui.uid_name()
local clear_filter_name = Gui.uid_name()
local storage = {}
Storage.register(storage, function(tbl)
storage = tbl
end)
-- storage tables
local enabled = {}
local last_events = {}
storage.debug_event_view = {
enabled = enabled,
last_events = last_events,
filter = "",
}
function Public.on_open_debug()
local tbl = storage.debug_event_view
if tbl then
enabled = tbl.enabled
last_events = tbl.last_events
else
enabled = {}
last_events = {}
storage.debug_event_view = {
enabled = enabled,
last_events = last_events,
}
end
Public.on_open_debug = nil
end
-- Local functions
local function event_callback(event)
local id = event.name
if not enabled[id] then
return
end
local name = name_lookup[id]
if not last_events[name] then
last_events[name] = {}
end
insert(last_events[name], 1, event)
last_events[name][events_to_keep + 1] = nil
event.name = nil
local str = format("%s (id = %s): %s", name, id, Model.dump(event))
game.print(str)
log(str)
end
local function on_gui_checked_state_changed(event)
local element = event.element
local name = element.caption
local id = events[name]
local state = element.state and true or false
element.state = state
if state then
enabled[id] = true
else
enabled[id] = false
end
end
-- GUI
-- Create a table with events sorted by their names
local grid_builder = {}
for name, _ in pairs(events) do
grid_builder[#grid_builder + 1] = name
end
table.sort(grid_builder)
local function redraw_event_table(gui_table, filter)
for _, event_name in pairs(grid_builder) do
if filter == "" or event_name:find(filter) then
local index = events[event_name]
gui_table.add{ type = "flow" }.add{
name = checkbox_name,
type = "checkbox",
state = enabled[index] or false,
caption = event_name,
}
end
end
end
function Public.show(container)
local filter = storage.debug_event_view.filter
local main_frame_flow = container.add{ type = "flow", direction = "vertical" }
local filter_flow = main_frame_flow.add{ type = "flow", direction = "horizontal" }
filter_flow.add{ type = "label", caption = "filter" }
local filter_textfield = filter_flow.add{ type = "textfield", name = filter_name, text = filter }
local clear_button = filter_flow.add{ type = "button", name = clear_filter_name, caption = "clear" }
local scroll_pane = main_frame_flow.add{ type = "scroll-pane" }
local gui_table = scroll_pane.add{ type = "table", column_count = 3, draw_horizontal_lines = true }
Gui.set_data(filter_textfield, gui_table)
Gui.set_data(clear_button, { gui_table = gui_table, filter_textfield = filter_textfield })
redraw_event_table(gui_table, filter)
end
Gui.on_checked_state_changed(checkbox_name, on_gui_checked_state_changed)
Gui.on_text_changed(
filter_name,
function(event)
local element = event.element
local gui_table = Gui.get_data(element)
local filter = element.text:gsub(" ", "_")
storage.debug_event_view.filter = filter
element.text = filter
gui_table.clear()
redraw_event_table(gui_table, filter)
end
)
Gui.on_click(
clear_filter_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
local filter_textfield = data.filter_textfield
local gui_table = data.gui_table
filter_textfield.text = ""
storage.debug_event_view.filter = ""
gui_table.clear()
redraw_event_table(gui_table, "")
end
)
-- Event registers (TODO: turn to removable hooks.. maybe)
for name, id in pairs(events) do
name_lookup[id] = name
Public.events[id] = event_callback
end
return Public
@@ -0,0 +1,132 @@
local Gui = require("modules/exp_scenario/gui/debug/shim")
local Datastore = require("modules.exp_legacy.expcore.datastore")
local Color = require("modules/exp_util/include/color")
local Model = require("modules/exp_scenario/gui/debug/model")
local dump = Model.dump
local concat = table.concat
local Public = {}
local header_name = Gui.uid_name()
local left_panel_name = Gui.uid_name()
local right_panel_name = Gui.uid_name()
local input_text_box_name = Gui.uid_name()
local refresh_name = Gui.uid_name()
Public.name = "Datastore"
function Public.show(container)
local main_flow = container.add{ type = "flow", direction = "horizontal" }
local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name }
local left_panel_style = left_panel.style
left_panel_style.width = 300
for name in pairs(table.key_sort(Datastore.debug())) do
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = name }
Gui.set_data(header, name)
end
local right_flow = main_flow.add{ type = "flow", direction = "vertical" }
local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" }
local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name }
local input_text_box_style = input_text_box.style
input_text_box_style.horizontally_stretchable = true
input_text_box_style.height = 32
input_text_box_style.maximal_width = 1000
local refresh_button =
right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" }
local refresh_button_style = refresh_button.style
refresh_button_style.width = 32
refresh_button_style.height = 32
local right_panel = right_flow.add{ type = "text-box", name = right_panel_name }
right_panel.read_only = true
right_panel.selectable = true
local right_panel_style = right_panel.style
right_panel_style.vertically_stretchable = true
right_panel_style.horizontally_stretchable = true
right_panel_style.maximal_width = 1000
right_panel_style.maximal_height = 1000
local data = {
right_panel = right_panel,
input_text_box = input_text_box,
selected_header = nil,
}
Gui.set_data(input_text_box, data)
Gui.set_data(left_panel, data)
Gui.set_data(refresh_button, data)
end
Gui.on_click(
header_name,
function(event)
local element = event.element
local table_name = Gui.get_data(element)
local left_panel = element.parent.parent
local data = Gui.get_data(left_panel)
local right_panel = data.right_panel
local selected_header = data.selected_header
local input_text_box = data.input_text_box
if selected_header then
selected_header.style.font_color = Color.white
end
element.style.font_color = Color.orange
data.selected_header = element
input_text_box.text = table_name
input_text_box.style.font_color = Color.black
local content = Datastore.debug(table_name)
local content_string = {}
for key, value in pairs(content) do
content_string[#content_string + 1] = key:gsub("^%l", string.upper) .. " = " .. dump(value)
end
right_panel.text = concat(content_string, "\n")
end
)
local function update_dump(text_input, data)
local content = Datastore.debug(text_input.text)
local content_string = {}
for key, value in pairs(content) do
content_string[#content_string + 1] = key:gsub("^%l", string.upper) .. " = " .. dump(value)
end
data.right_panel.text = concat(content_string, "\n")
end
Gui.on_text_changed(
input_text_box_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
update_dump(element, data)
end
)
Gui.on_click(
refresh_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
local input_text_box = data.input_text_box
update_dump(input_text_box, data)
end
)
return Public
@@ -0,0 +1,145 @@
local ExpElement = require("modules/exp_gui/prototype")
local ExpData = require("modules/exp_gui/data")
local ExpIter = require("modules/exp_gui/iter")
local Color = require("modules/exp_util/include/color")
local Gui = require("modules/exp_scenario/gui/debug/shim")
local Model = require("modules/exp_scenario/gui/debug/model")
local dump = Model.dump
local dump_text = Model.dump_text
local concat = table.concat
local Public = {}
local header_name = Gui.uid_name()
local left_panel_name = Gui.uid_name()
local right_panel_name = Gui.uid_name()
local input_text_box_name = Gui.uid_name()
local refresh_name = Gui.uid_name()
Public.name = "Elements"
function Public.show(container)
local main_flow = container.add{ type = "flow", direction = "horizontal" }
local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name }
local left_panel_style = left_panel.style
left_panel_style.width = 300
--- @diagnostic disable-next-line invisible
for element_name in pairs(ExpElement._elements) do
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = element_name }
Gui.set_data(header, element_name)
end
local right_flow = main_flow.add{ type = "flow", direction = "vertical" }
local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" }
local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name }
local input_text_box_style = input_text_box.style
input_text_box_style.horizontally_stretchable = true
input_text_box_style.height = 32
input_text_box_style.maximal_width = 1000
local refresh_button =
right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" }
local refresh_button_style = refresh_button.style
refresh_button_style.width = 32
refresh_button_style.height = 32
local right_panel = right_flow.add{ type = "text-box", name = right_panel_name }
right_panel.read_only = true
right_panel.selectable = true
local right_panel_style = right_panel.style
right_panel_style.vertically_stretchable = true
right_panel_style.horizontally_stretchable = true
right_panel_style.maximal_width = 1000
right_panel_style.maximal_height = 1000
local data = {
right_panel = right_panel,
input_text_box = input_text_box,
selected_header = nil,
}
Gui.set_data(input_text_box, data)
Gui.set_data(left_panel, data)
Gui.set_data(refresh_button, data)
end
Gui.on_click(
header_name,
function(event)
local element = event.element
local element_name = Gui.get_data(element)
local left_panel = element.parent.parent
local data = Gui.get_data(left_panel)
local right_panel = data.right_panel
local selected_header = data.selected_header
local input_text_box = data.input_text_box
if selected_header then
selected_header.style.font_color = Color.white
end
element.style.font_color = Color.orange
data.selected_header = element
input_text_box.text = concat{ "ExpElement._elements[\"", element_name, "\"]" }
input_text_box.style.font_color = Color.black
--- @diagnostic disable-next-line invisible
local define = ExpElement._elements[element_name]
local content = dump({
--- @diagnostic disable-next-line invisible
debug = define._debug,
--- @diagnostic disable-next-line invisible
has_handlers = define._has_handlers,
--- @diagnostic disable-next-line invisible
track_elements = define._track_elements,
--- @diagnostic disable-next-line invisible
elements = ExpIter._scopes[element_name],
--- @diagnostic disable-next-line invisible
data = ExpData._scopes[element_name]._raw,
}) or "nil"
right_panel.text = content
end
)
local function update_dump(text_input, data, player)
local suc, ouput = dump_text(text_input.text, player)
if not suc then
text_input.style.font_color = Color.red
else
text_input.style.font_color = Color.black
data.right_panel.text = ouput
end
end
Gui.on_text_changed(
input_text_box_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
update_dump(element, data, event.player)
end
)
Gui.on_click(
refresh_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
local input_text_box = data.input_text_box
update_dump(input_text_box, data, event.player)
end
)
return Public
@@ -0,0 +1,133 @@
local Gui = require("modules/exp_scenario/gui/debug/shim")
local Model = require("modules/exp_scenario/gui/debug/model")
local Color = require("modules/exp_util/include/color")
local dump = Model.dump
local dump_text = Model.dump_text
local concat = table.concat
local Public = {}
local ignore = { tokens = true, data_store = true, datastores = true }
local header_name = Gui.uid_name()
local left_panel_name = Gui.uid_name()
local right_panel_name = Gui.uid_name()
local input_text_box_name = Gui.uid_name()
local refresh_name = Gui.uid_name()
Public.name = "storage"
function Public.show(container)
local main_flow = container.add{ type = "flow", direction = "horizontal" }
local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name }
local left_panel_style = left_panel.style
left_panel_style.width = 300
for key, _ in pairs(storage) do
if not ignore[key] then
local header =
left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = tostring(key) }
Gui.set_data(header, key)
end
end
local right_flow = main_flow.add{ type = "flow", direction = "vertical" }
local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" }
local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name }
local input_text_box_style = input_text_box.style
input_text_box_style.horizontally_stretchable = true
input_text_box_style.height = 32
input_text_box_style.maximal_width = 1000
local refresh_button =
right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" }
local refresh_button_style = refresh_button.style
refresh_button_style.width = 32
refresh_button_style.height = 32
local right_panel = right_flow.add{ type = "text-box", name = right_panel_name }
right_panel.read_only = true
right_panel.selectable = true
local right_panel_style = right_panel.style
right_panel_style.vertically_stretchable = true
right_panel_style.horizontally_stretchable = true
right_panel_style.maximal_width = 1000
right_panel_style.maximal_height = 1000
local data = {
right_panel = right_panel,
input_text_box = input_text_box,
selected_header = nil,
selected_token_id = nil,
}
Gui.set_data(input_text_box, data)
Gui.set_data(left_panel, data)
Gui.set_data(refresh_button, data)
end
Gui.on_click(
header_name,
function(event)
local element = event.element
local key = Gui.get_data(element)
local left_panel = element.parent.parent
local data = Gui.get_data(left_panel)
local right_panel = data.right_panel
local selected_header = data.selected_header
local input_text_box = data.input_text_box
if selected_header then
selected_header.style.font_color = Color.white
end
element.style.font_color = Color.orange
data.selected_header = element
input_text_box.text = concat{ "storage['", key, "']" }
input_text_box.style.font_color = Color.black
local content = dump(storage[key]) or "nil"
right_panel.text = content
end
)
local function update_dump(text_input, data, player)
local suc, ouput = dump_text(text_input.text, player)
if not suc then
text_input.style.font_color = Color.red
else
text_input.style.font_color = Color.black
data.right_panel.text = ouput
end
end
Gui.on_text_changed(
input_text_box_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
update_dump(element, data, event.player)
end
)
Gui.on_click(
refresh_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
local input_text_box = data.input_text_box
update_dump(input_text_box, data, event.player)
end
)
return Public
+113
View File
@@ -0,0 +1,113 @@
local Gui = require("modules/exp_scenario/gui/debug/shim")
local Color = require("modules/exp_util/include/color")
local Public = {}
local pages = {
require("modules/exp_scenario/gui/debug/redmew_global_view"),
require("modules/exp_scenario/gui/debug/expcore_datastore_view"),
require("modules/exp_scenario/gui/debug/expcore_gui_view"),
require("modules/exp_scenario/gui/debug/global_view"),
require("modules/exp_scenario/gui/debug/package_view"),
require("modules/exp_scenario/gui/debug/_g_view"),
require("modules/exp_scenario/gui/debug/event_view"),
}
local main_frame_name = Gui.uid_name()
local close_name = Gui.uid_name()
local tab_name = Gui.uid_name()
function Public.open_debug(player)
for i = 1, #pages do
local page = pages[i]
local callback = page.on_open_debug
if callback then
callback()
end
end
local center = player.gui.center
local frame = center[main_frame_name]
if frame then
return
end
--[[
local screen_element = player.gui.screen
frame = screen_element.add{type = 'frame', name = main_frame_name, caption = 'Debuggertron 3000'}
frame.style.size = {900, 600}
frame.auto_center = true
]]
frame = center.add{ type = "frame", name = main_frame_name, caption = "Debuggertron 3002", direction = "vertical" }
local frame_style = frame.style
frame_style.height = 600
frame_style.width = 900
local tab_flow = frame.add{ type = "flow", direction = "horizontal" }
local container = frame.add{ type = "flow" }
container.style.vertically_stretchable = true
local data = {}
for i = 1, #pages do
local page = pages[i]
local tab_button = tab_flow.add{ type = "flow" }.add{ type = "button", name = tab_name, caption = page.name }
local tab_button_style = tab_button.style
Gui.set_data(tab_button, { index = i, frame_data = data })
if i == 1 then
tab_button_style.font_color = Color.orange
data.selected_index = i
data.selected_tab_button = tab_button
data.container = container
Gui.set_data(frame, data)
page.show(container)
end
end
frame.add{ type = "button", name = close_name, caption = "Close" }
end
Gui.on_click(
tab_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
local index = data.index
local frame_data = data.frame_data
local selected_index = frame_data.selected_index
if selected_index == index then
return
end
local selected_tab_button = frame_data.selected_tab_button
selected_tab_button.style.font_color = Color.black
frame_data.selected_tab_button = element
frame_data.selected_index = index
element.style.font_color = Color.orange
local container = frame_data.container
Gui.clear(container)
pages[index].show(container)
end
)
Gui.on_click(
close_name,
function(event)
local frame = event.player.gui.center[main_frame_name]
if frame then
Gui.destroy(frame)
end
end
)
return Public
+73
View File
@@ -0,0 +1,73 @@
local Gui = require("modules/exp_scenario/gui/debug/shim") --- @dep utils.gui
local ExpUtil = require("modules/exp_util")
local concat = table.concat
local inspect = table.inspect
local pcall = pcall
local loadstring = loadstring --- @diagnostic disable-line
local rawset = rawset
local Public = {}
local inspect_process = ExpUtil.safe_value
local inspect_options = { process = inspect_process }
function Public.dump(data)
return inspect(data, inspect_options)
end
local dump = Public.dump
function Public.dump_ignore_builder(ignore)
local function process(item)
if ignore[item] then
return nil
end
return inspect_process(item)
end
local options = { process = process }
return function(data)
return inspect(data, options)
end
end
function Public.dump_function(func)
local res = { "upvalues:\n", "no longer available" }
local i = 1
--[[while true do
local n, v = debug.getupvalue(func, i)
if n == nil then
break
elseif n ~= "_ENV" then
res[#res + 1] = n
res[#res + 1] = " = "
res[#res + 1] = dump(v)
res[#res + 1] = "\n"
end
i = i + 1
end]]
return concat(res)
end
function Public.dump_text(text, player)
local func = loadstring("return " .. text)
if not func then
return false
end
local suc, var = pcall(func)
if not suc then
return false
end
return true, dump(var)
end
return Public
@@ -0,0 +1,161 @@
local Gui = require("modules/exp_scenario/gui/debug/shim") --- @dep utils.gui
local Color = require("modules/exp_util/include/color")
local Model = require("modules/exp_scenario/gui/debug/model") --- @dep modules.gui.debug.model
local dump_function = Model.dump_function
local loaded = _G.package.loaded
local Public = {}
local ignore = {
_G = true,
package = true,
coroutine = true,
table = true,
string = true,
bit32 = true,
math = true,
debug = true,
serpent = true,
["overrides.math"] = true,
util = true,
["mod-gui"] = true,
}
local file_label_name = Gui.uid_name()
local left_panel_name = Gui.uid_name()
local breadcrumbs_name = Gui.uid_name()
local top_panel_name = Gui.uid_name()
local variable_label_name = Gui.uid_name()
local text_box_name = Gui.uid_name()
Public.name = "package"
function Public.show(container)
local main_flow = container.add{ type = "flow", direction = "horizontal" }
local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name }
local left_panel_style = left_panel.style
left_panel_style.width = 300
for name, file in pairs(loaded) do
if not ignore[name] then
local file_label =
left_panel.add{ type = "flow" }.add{ type = "label", name = file_label_name, caption = name }
Gui.set_data(file_label, file)
end
end
local right_flow = main_flow.add{ type = "flow", direction = "vertical" }
local breadcrumbs = right_flow.add{ type = "label", name = breadcrumbs_name }
local top_panel = right_flow.add{ type = "scroll-pane", name = top_panel_name }
local top_panel_style = top_panel.style
top_panel_style.height = 200
top_panel_style.maximal_width = 1000
top_panel_style.horizontally_stretchable = true
local text_box = right_flow.add{ type = "text-box", name = text_box_name }
text_box.read_only = true
text_box.selectable = true
local text_box_style = text_box.style
text_box_style.vertically_stretchable = true
text_box_style.horizontally_stretchable = true
text_box_style.maximal_width = 1000
text_box_style.maximal_height = 1000
local data = {
left_panel = left_panel,
breadcrumbs = breadcrumbs,
top_panel = top_panel,
text_box = text_box,
selected_file_label = nil,
selected_variable_label = nil,
}
Gui.set_data(left_panel, data)
Gui.set_data(top_panel, data)
end
Gui.on_click(
file_label_name,
function(event)
local element = event.element
local file = Gui.get_data(element)
local left_panel = element.parent.parent
local data = Gui.get_data(left_panel)
local selected_file_label = data.selected_file_label
if selected_file_label then
selected_file_label.style.font_color = Color.white
end
element.style.font_color = Color.orange
data.selected_file_label = element
local top_panel = data.top_panel
local text_box = data.text_box
Gui.clear(top_panel)
local file_type = type(file)
if file_type == "table" then
for k, v in pairs(file) do
local label =
top_panel.add{ type = "flow" }.add{ type = "label", name = variable_label_name, caption = k }
Gui.set_data(label, v)
end
elseif file_type == "function" then
text_box.text = dump_function(file)
else
text_box.text = tostring(file)
end
end
)
Gui.on_click(
variable_label_name,
function(event)
local element = event.element
local variable = Gui.get_data(element)
local top_panel = element.parent.parent
local data = Gui.get_data(top_panel)
local text_box = data.text_box
local variable_type = type(variable)
if variable_type == "table" then
Gui.clear(top_panel)
for k, v in pairs(variable) do
local label =
top_panel.add{ type = "flow" }.add{ type = "label", name = variable_label_name, caption = k }
Gui.set_data(label, v)
end
return
end
local selected_label = data.selected_variable_label
if selected_label and selected_label.valid then
selected_label.style.font_color = Color.white
end
element.style.font_color = Color.orange
data.selected_variable_label = element
if variable_type == "function" then
text_box.text = dump_function(variable)
else
text_box.text = tostring(variable)
end
end
)
return Public
@@ -0,0 +1,129 @@
local Gui = require("modules/exp_scenario/gui/debug/shim") --- @dep utils.gui
local Storage = require("modules/exp_util/storage")
local Color = require("modules/exp_util/include/color")
local Model = require("modules/exp_scenario/gui/debug/model") --- @dep modules.gui.debug.model
local dump = Model.dump
local dump_text = Model.dump_text
local concat = table.concat
local Public = {}
local header_name = Gui.uid_name()
local left_panel_name = Gui.uid_name()
local right_panel_name = Gui.uid_name()
local input_text_box_name = Gui.uid_name()
local refresh_name = Gui.uid_name()
Public.name = "Storage"
function Public.show(container)
local main_flow = container.add{ type = "flow", direction = "horizontal" }
local left_panel = main_flow.add{ type = "scroll-pane", name = left_panel_name }
local left_panel_style = left_panel.style
left_panel_style.width = 300
--- @diagnostic disable-next-line invisible
for token_id in pairs(Storage._registered) do
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = token_id }
Gui.set_data(header, token_id)
end
local right_flow = main_flow.add{ type = "flow", direction = "vertical" }
local right_top_flow = right_flow.add{ type = "flow", direction = "horizontal" }
local input_text_box = right_top_flow.add{ type = "text-box", name = input_text_box_name }
local input_text_box_style = input_text_box.style
input_text_box_style.horizontally_stretchable = true
input_text_box_style.height = 32
input_text_box_style.maximal_width = 1000
local refresh_button =
right_top_flow.add{ type = "sprite-button", name = refresh_name, sprite = "utility/reset", tooltip = "refresh" }
local refresh_button_style = refresh_button.style
refresh_button_style.width = 32
refresh_button_style.height = 32
local right_panel = right_flow.add{ type = "text-box", name = right_panel_name }
right_panel.read_only = true
right_panel.selectable = true
local right_panel_style = right_panel.style
right_panel_style.vertically_stretchable = true
right_panel_style.horizontally_stretchable = true
right_panel_style.maximal_width = 1000
right_panel_style.maximal_height = 1000
local data = {
right_panel = right_panel,
input_text_box = input_text_box,
selected_header = nil,
}
Gui.set_data(input_text_box, data)
Gui.set_data(left_panel, data)
Gui.set_data(refresh_button, data)
end
Gui.on_click(
header_name,
function(event)
local element = event.element
local token_id = Gui.get_data(element)
local left_panel = element.parent.parent
local data = Gui.get_data(left_panel)
local right_panel = data.right_panel
local selected_header = data.selected_header
local input_text_box = data.input_text_box
if selected_header then
selected_header.style.font_color = Color.white
end
element.style.font_color = Color.orange
data.selected_header = element
input_text_box.text = concat{ "storage.exp_storage['", token_id, "']" }
input_text_box.style.font_color = Color.black
local content = dump(storage.exp_storage[token_id]) or "nil"
right_panel.text = content
end
)
local function update_dump(text_input, data, player)
local suc, ouput = dump_text(text_input.text, player)
if not suc then
text_input.style.font_color = Color.red
else
text_input.style.font_color = Color.black
data.right_panel.text = ouput
end
end
Gui.on_text_changed(
input_text_box_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
update_dump(element, data, event.player)
end
)
Gui.on_click(
refresh_name,
function(event)
local element = event.element
local data = Gui.get_data(element)
local input_text_box = data.input_text_box
update_dump(input_text_box, data, event.player)
end
)
return Public
+132
View File
@@ -0,0 +1,132 @@
local Storage = require("modules/exp_util/storage")
local mod_gui = require "mod-gui"
local Gui = {}
local data = {}
local uid = 0
Storage.register(
data,
function(tbl)
data = tbl
end
)
function Gui.uid_name()
uid = uid + 1
return "Redmew_" .. uid
end
-- Associates data with the LuaGuiElement. If data is nil then removes the data
function Gui.set_data(element, value)
data[element.player_index * 0x100000000 + element.index] = value
end
-- Gets the Associated data with this LuaGuiElement if any.
function Gui.get_data(element)
return data[element.player_index * 0x100000000 + element.index]
end
-- Removes data associated with LuaGuiElement and its children recursively.
function Gui.remove_data_recursively(element)
Gui.set_data(element, nil)
local children = element.children
if not children then
return
end
for _, child in ipairs(children) do
if child.valid then
Gui.remove_data_recursively(child)
end
end
end
function Gui.remove_children_data(element)
local children = element.children
if not children then
return
end
for _, child in ipairs(children) do
if child.valid then
Gui.set_data(child, nil)
Gui.remove_children_data(child)
end
end
end
function Gui.destroy(element)
Gui.remove_data_recursively(element)
element.destroy()
end
function Gui.clear(element)
Gui.remove_children_data(element)
element.clear()
end
Gui.events = {}
local function handler_factory(event_name)
return function(element_name, handler)
Gui.events[defines.events[event_name]] = function(event)
if event.element and event.element.valid and event.element.name == element_name then
event.player = game.players[event.player_index]
handler(event)
end
end
end
end
-- Register a handler for the on_gui_checked_state_changed event for LuaGuiElements with element_name.
-- Can only have one handler per element name.
-- Guarantees that the element and the player are valid when calling the handler.
-- Adds a player field to the event table.
Gui.on_checked_state_changed = handler_factory("on_gui_checked_state_changed")
-- Register a handler for the on_gui_click event for LuaGuiElements with element_name.
-- Can only have one handler per element name.
-- Guarantees that the element and the player are valid when calling the handler.
-- Adds a player field to the event table.
Gui.on_click = handler_factory("on_gui_click")
-- Register a handler for the on_gui_closed event for a custom LuaGuiElements with element_name.
-- Can only have one handler per element name.
-- Guarantees that the element and the player are valid when calling the handler.
-- Adds a player field to the event table.
Gui.on_custom_close = handler_factory("on_gui_closed")
-- Register a handler for the on_gui_elem_changed event for LuaGuiElements with element_name.
-- Can only have one handler per element name.
-- Guarantees that the element and the player are valid when calling the handler.
-- Adds a player field to the event table.
Gui.on_elem_changed = handler_factory("on_gui_elem_changed")
-- Register a handler for the on_gui_selection_state_changed event for LuaGuiElements with element_name.
-- Can only have one handler per element name.
-- Guarantees that the element and the player are valid when calling the handler.
-- Adds a player field to the event table.
Gui.on_selection_state_changed = handler_factory("on_gui_selection_state_changed")
-- Register a handler for the on_gui_text_changed event for LuaGuiElements with element_name.
-- Can only have one handler per element name.
-- Guarantees that the element and the player are valid when calling the handler.
-- Adds a player field to the event table.
Gui.on_text_changed = handler_factory("on_gui_text_changed")
-- Register a handler for the on_gui_value_changed event for LuaGuiElements with element_name.
-- Can only have one handler per element name.
-- Guarantees that the element and the player are valid when calling the handler.
-- Adds a player field to the event table.
Gui.on_value_changed = handler_factory("on_gui_value_changed")
--- Returns the flow where top elements can be added and will be effected by google visibility
-- For the toggle to work it must be registed with Gui.allow_player_to_toggle_top_element_visibility(element_name)
-- @tparam LuaPlayer player pointer to the player who has the gui
-- @treturn LuaGuiElement the top element flow
Gui.get_top_element_flow = mod_gui.get_button_flow
return Gui
@@ -1,175 +0,0 @@
--[[-- Gui - Landfill Blueprint
Adds a button to the toolbar which adds landfill to the held blueprint
]]
local Gui = require("modules/exp_gui")
local Roles = require("modules/exp_legacy/expcore/roles")
--- @param box BoundingBox
local function rotate_bounding_box(box)
box.left_top.x, box.left_top.y, box.right_bottom.x, box.right_bottom.y
= -box.right_bottom.y, box.left_top.x, -box.left_top.y, box.right_bottom.x
end
local function curve_flip_lr(oc)
local nc = table.deep_copy(oc)
for r = 1, 8 do
for c = 1, 8 do
nc[r][c] = oc[r][9 - c]
end
end
return nc
end
local function curve_flip_d(oc)
local nc = table.deep_copy(oc)
for r = 1, 8 do
for c = 1, 8 do
nc[r][c] = oc[c][r]
end
end
return nc
end
local curve_masks = {} do
local curves = { {
{ 0, 0, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 0, 0, 1, 1, 1, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0 },
{ 0, 0, 0, 1, 1, 1, 0, 0 },
{ 0, 0, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 1, 1, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 0, 0, 0, 0 },
} }
curves[6] = curve_flip_d(curves[1])
curves[3] = curve_flip_lr(curves[6])
curves[4] = curve_flip_d(curves[3])
curves[5] = curve_flip_lr(curves[4])
curves[2] = curve_flip_d(curves[5])
curves[7] = curve_flip_lr(curves[2])
curves[8] = curve_flip_d(curves[7])
for i, map in ipairs(curves) do
local index = 0
local mask = {}
curve_masks[i] = mask
for row = 1, 8 do
for col = 1, 8 do
if map[row][col] == 1 then
index = index + 1
mask[index] = {
x = col - 5,
y = row - 5,
}
end
end
end
end
end
local rolling_stocks = {}
for name, _ in pairs(prototypes.get_entity_filtered{ { filter = "rolling-stock" } }) do
rolling_stocks[name] = true
end
--- @param blueprint LuaItemStack
--- @return table
local function landfill_gui_add_landfill(blueprint)
local entities = assert(blueprint.get_blueprint_entities())
local tile_index = 0
local new_tiles = {}
for _, entity in pairs(entities) do
if rolling_stocks[entity.name] or entity.name == "offshore-pump" then
goto continue
end
if entity.name == "curved-rail" then
-- Curved rail
local curve_mask = curve_masks[entity.direction or 8]
for _, offset in ipairs(curve_mask) do
tile_index = tile_index + 1
new_tiles[tile_index] = {
name = "landfill",
position = { entity.position.x + offset.x, entity.position.y + offset.y },
}
end
else
-- Any other entity
local proto = prototypes.entity[entity.name]
if proto.collision_mask["ground-tile"] ~= nil then
goto continue
end
-- Rotate the collision box to be north facing
local box = proto.collision_box or proto.selection_box
if entity.direction then
if entity.direction ~= defines.direction.north then
rotate_bounding_box(box)
if entity.direction ~= defines.direction.east then
rotate_bounding_box(box)
if entity.direction ~= defines.direction.south then
rotate_bounding_box(box)
end
end
end
end
-- Add the landfill
for y = math.floor(entity.position.y + box.left_top.y), math.floor(entity.position.y + box.right_bottom.y), 1 do
for x = math.floor(entity.position.x + box.left_top.x), math.floor(entity.position.x + box.right_bottom.x), 1 do
tile_index = tile_index + 1
new_tiles[tile_index] = {
name = "landfill",
position = { x, y },
}
end
end
end
::continue::
end
local old_tiles = blueprint.get_blueprint_tiles()
if old_tiles then
for _, old_tile in pairs(old_tiles) do
tile_index = tile_index + 1
new_tiles[tile_index] = {
name = "landfill",
position = old_tile.position,
}
end
end
return { tiles = new_tiles }
end
--- Add the toolbar button
Gui.toolbar.create_button{
name = "trigger_landfill_blueprint",
sprite = "item/landfill",
tooltip = { "exp-gui_landfill-blueprint.tooltip-main" },
visible = function(player, element)
return Roles.player_allowed(player, "gui/landfill")
end
}:on_click(function(def, player, element)
local stack = player.cursor_stack
if stack and stack.valid_for_read and stack.type == "blueprint" and stack.is_blueprint_setup() then
local modified = landfill_gui_add_landfill(stack)
if modified and next(modified.tiles) then
stack.set_blueprint_tiles(modified.tiles)
end
else
player.print{ "exp-gui_landfill-blueprint.error-no-blueprint" }
end
end)
return {}
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+2 -3
View File
@@ -16,7 +16,6 @@ local Elements = {}
--- @field cost number
--- @field scale number
--- @field max_value number
--- @field initial_value number
--- @field is_percentage boolean
--- @field is_special boolean
--- @field value_step number
@@ -229,7 +228,7 @@ Elements.bonus_slider = Gui.define("player_bonus/bonus_slider")
local player = Gui.get_player(parent)
local value = Elements.container.get_player_bonus(player, bonus_data.name)
if not value then
value = bonus_data.initial_value
value = math.floor(bonus_data.max_value / 2)
elements.apply_button.enabled = true
end
@@ -290,7 +289,7 @@ function Elements.bonus_slider.reset_value(slider)
local player = Gui.get_player(slider)
local element_data = Elements.bonus_slider.data[slider]
local bonus_data = element_data.bonus_data
local value = Elements.container.get_player_bonus(player, bonus_data.name) or bonus_data.initial_value
local value = Elements.container.get_player_bonus(player, bonus_data.name) or math.floor(bonus_data.max_value / 2)
slider.slider_value = value
element_data.label.caption = Elements.bonus_slider.calculate_slider_caption(bonus_data, value)
element_data.previous_value = value
+543
View File
@@ -0,0 +1,543 @@
--[[-- Gui - Player List
Adds a player list to show names and play time; also includes action buttons which can perform actions on players.
]]
local ExpUtil = require("modules/exp_util")
local Gui = require("modules/exp_gui")
local Roles = require("modules/exp_legacy/expcore/roles")
local config = require("modules/exp_legacy/config/gui/player_list_actions")
--- @class ExpGui_PlayerList.elements
local Elements = {}
local online_time_format = ExpUtil.format_time_factory_locale{ format = "short", hours = true, minutes = true }
local afk_time_format = ExpUtil.format_time_factory_locale{ format = "long", minutes = true }
--- Get the caption and tooltip for a player time
--- @param online_time number
--- @param afk_time number
--- @return LocalisedString, LocalisedString
local function get_time_formats(online_time, afk_time)
local tick = game.tick > 0 and game.tick or 1
local percent = math.round(online_time / tick, 3) * 100
local caption = online_time_format(online_time)
local tooltip = { "exp-gui_player-list.afk-time", percent, afk_time_format(afk_time) }
return caption, tooltip
end
--- Button used to open the action bar for a player
--- @class ExpGui_PlayerList.elements.open_action_bar: ExpElement
--- @field data table<LuaGuiElement, LuaPlayer>
--- @overload fun(parent: LuaGuiElement, selected_player: LuaPlayer): LuaGuiElement
Elements.open_action_bar = Gui.define("player_list/open_action_bar")
:draw{
type = "sprite-button",
sprite = "utility/expand_dots",
tooltip = { "exp-gui_player-list.open-action-bar" },
style = "frame_button",
}
:style{
padding = -2,
width = 8,
height = 14,
}
:element_data(
Gui.from_argument(1)
)
:on_click(function(def, player, element)
--- @cast def ExpGui_PlayerList.elements.open_action_bar
Elements.container.toggle_selected_player(player, def.data[element])
Elements.player_table.refresh_player(player)
end) --[[ @as any ]]
--- Set whether an open action bar button shows as highlighted
--- @param open_button LuaGuiElement
--- @param highlighted boolean
function Elements.open_action_bar.set_highlight(open_button, highlighted)
open_button.style = highlighted and "tool_button" or "frame_button"
local style = open_button.style
style.padding = -2
style.width = 8
style.height = 14
end
--- Button used to close the action bar
--- @class ExpGui_PlayerList.elements.close_action_bar: ExpElement
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
Elements.close_action_bar = Gui.define("player_list/close_action_bar")
:draw{
type = "sprite-button",
sprite = "utility/close_black",
tooltip = { "exp-gui_player-list.close-action-bar" },
style = "slot_sized_button_red",
}
:style{
size = 30,
padding = -1,
top_margin = -1,
right_margin = -1,
}
:on_click(function(_, player)
Elements.container.set_selected_player(player, nil)
Elements.player_table.refresh_player(player)
end) --[[ @as any ]]
--- Button used to confirm a reason
--- @class ExpGui_PlayerList.elements.reason_confirm: ExpElement
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
Elements.reason_confirm = Gui.define("player_list/reason_confirm")
:draw{
type = "sprite-button",
sprite = "utility/confirm_slot",
tooltip = { "exp-gui_player-list.reason-confirm" },
style = "slot_sized_button_green",
}
:style{
size = 30,
padding = -1,
left_margin = -2,
right_margin = -1,
}
:on_click(function(_, player, element)
local action_name = Elements.container.get_selected_action(player)
local button_data = action_name and config.buttons[action_name]
if button_data and button_data.reason_callback then
local reason = element.parent.entry.text
if reason == nil or not reason:find("%S") then reason = "no reason given" end
button_data.reason_callback(player, reason)
end
element.parent.entry.text = ""
Elements.container.set_selected_player(player, nil)
Elements.player_table.refresh_player(player)
end) --[[ @as any ]]
--- Clickable player name label, left click opens the map and right click toggles the action bar
--- @class ExpGui_PlayerList.elements.player_name_label: ExpElement
--- @field data table<LuaGuiElement, LuaPlayer>
--- @overload fun(parent: LuaGuiElement, opts: { name: string, player: LuaPlayer, tooltip: LocalisedString }): LuaGuiElement
Elements.player_name_label = Gui.define("player_list/player_name_label")
:draw{
type = "label",
caption = Gui.from_argument("name"),
tooltip = Gui.from_argument("tooltip"),
}
:style{
padding = { 0, 2, 0, 0 },
}
:element_data(
Gui.from_argument("player")
)
:on_click(function(def, player, element, event)
--- @cast def ExpGui_PlayerList.elements.player_name_label
local selected_player = def.data[element]
if event.button == defines.mouse_button_type.left then
-- Left click opens remote view at the player
player.set_controller{
type = defines.controllers.remote,
position = selected_player.physical_position,
surface = selected_player.physical_surface,
}
else
-- Right click toggles the action bar
Elements.container.toggle_selected_player(player, selected_player)
Elements.player_table.refresh_player(player)
end
end) --[[ @as any ]]
--- @class ExpGui_PlayerList.elements.player_table.row
--- @field open_button LuaGuiElement
--- @field name_label LuaGuiElement
--- @field time_label LuaGuiElement
--- @class ExpGui_PlayerList.elements.player_table.element_data
--- @field rows table<string, ExpGui_PlayerList.elements.player_table.row>
--- @field action_bar LuaGuiElement
--- @field reason_bar LuaGuiElement
--- Scroll table containing a row for each online player
--- @class ExpGui_PlayerList.elements.player_table: ExpElement
--- @field data table<LuaGuiElement, ExpGui_PlayerList.elements.player_table.element_data>
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
Elements.player_table = Gui.define("player_list/player_table")
:track_all_elements()
:draw(function(_, parent)
return Gui.elements.scroll_table(parent, 184, 3, "scroll")
end)
:style{
padding = { 1, 0, 1, 2 },
} --[[ @as any ]]
--- Store the action and reason bars associated with a player table
--- @param player_table LuaGuiElement
--- @param action_bar LuaGuiElement
--- @param reason_bar LuaGuiElement
function Elements.player_table.set_bars(player_table, action_bar, reason_bar)
Elements.player_table.data[player_table] = {
rows = {},
action_bar = action_bar,
reason_bar = reason_bar,
}
end
--- @class ExpGui_PlayerList.elements.player_table.row_data
--- @field player LuaPlayer
--- @field tag string
--- @field role_name string
--- @field chat_color Color
--- @field caption LocalisedString
--- @field tooltip LocalisedString
--- Calculate the ordered list of online players sorted by their highest role
--- @return ExpGui_PlayerList.elements.player_table.row_data[]
function Elements.player_table.calculate_row_data()
-- Sort all the online players into roles
local players = {}
for _, player in pairs(game.connected_players) do
local highest_role = Roles.get_player_highest_role(player)
if not players[highest_role.name] then
players[highest_role.name] = {}
end
table.insert(players[highest_role.name], player)
end
-- Flatten the roles into a single ordered list
local count = 0
local row_data = {}
for _, role_name in pairs(Roles.config.order) do
if players[role_name] then
for _, player in pairs(players[role_name]) do
count = count + 1
local caption, tooltip = get_time_formats(player.online_time, player.afk_time)
row_data[count] = {
player = player,
tag = player.tag,
role_name = role_name,
chat_color = player.chat_color,
caption = caption,
tooltip = tooltip,
}
end
end
end
return row_data
end
--- Calculate the latest play time captions for each online player keyed by name
--- @return table<string, { caption: LocalisedString, tooltip: LocalisedString }>
function Elements.player_table.calculate_time_data()
local time_data = {}
for _, player in pairs(game.connected_players) do
local caption, tooltip = get_time_formats(player.online_time, player.afk_time)
time_data[player.name] = { caption = caption, tooltip = tooltip }
end
return time_data
end
--- Add a player row to the table and store its elements
--- @param player_table LuaGuiElement
--- @param row_data ExpGui_PlayerList.elements.player_table.row_data
function Elements.player_table.add_row(player_table, row_data)
local rows = Elements.player_table.data[player_table].rows
local player = row_data.player
-- Add the button used to open the action bar
local open_flow = player_table.add{ type = "flow" }
local open_button = Elements.open_action_bar(open_flow, player)
-- Add the clickable player name
local name_label = Elements.player_name_label(player_table, {
name = player.name,
player = player,
tooltip = { "exp-gui_player-list.open-map", player.name, row_data.tag, row_data.role_name },
})
name_label.style.font_color = row_data.chat_color
-- Add the time played label
local alignment = Gui.elements.aligned_flow(player_table)
local time_label = alignment.add{
type = "label",
caption = row_data.caption,
tooltip = row_data.tooltip,
}
time_label.style.padding = 0
rows[player.name] = { open_button = open_button, name_label = name_label, time_label = time_label }
end
--- Rebuild all rows of a player table, used when the sort order changes
--- @param player_table LuaGuiElement
--- @param row_data ExpGui_PlayerList.elements.player_table.row_data[]
function Elements.player_table.rebuild(player_table, row_data)
player_table.clear()
Elements.player_table.data[player_table].rows = {}
for _, row in ipairs(row_data) do
Elements.player_table.add_row(player_table, row)
end
end
--- Remove a single player row from the table
--- @param player_table LuaGuiElement
--- @param player_name string
function Elements.player_table.remove_row(player_table, player_name)
local rows = Elements.player_table.data[player_table].rows
local row = rows[player_name]
if not row then return end
rows[player_name] = nil
Gui.destroy_if_valid(row.open_button.parent)
Gui.destroy_if_valid(row.name_label)
Gui.destroy_if_valid(row.time_label.parent)
end
--- Refresh the time labels of a player table from precomputed time data
--- @param player_table LuaGuiElement
--- @param time_data table<string, { caption: LocalisedString, tooltip: LocalisedString }>
function Elements.player_table.refresh_times(player_table, time_data)
for player_name, row in pairs(Elements.player_table.data[player_table].rows) do
local data = time_data[player_name]
if data then
row.time_label.caption = data.caption
row.time_label.tooltip = data.tooltip
end
end
end
--- Refresh the action bar, reason bar and row highlights for a player to match their selection
--- @param player LuaPlayer
function Elements.player_table.refresh_player(player)
local selected_player = Elements.container.get_selected_player(player)
local selected_action = Elements.container.get_selected_action(player)
for _, player_table in Elements.player_table:online_elements(player) do
local element_data = Elements.player_table.data[player_table]
Elements.action_bar.refresh(element_data.action_bar, player, selected_player)
Elements.reason_bar.refresh(element_data.reason_bar, selected_player, selected_action)
-- Highlight the open button of the selected player
for player_name, row in pairs(element_data.rows) do
Elements.open_action_bar.set_highlight(row.open_button, selected_player ~= nil and player_name == selected_player.name)
end
end
end
--- Action bar footer holding the close button and the per action button flows
--- @class ExpGui_PlayerList.elements.action_bar: ExpElement
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
Elements.action_bar = Gui.define("player_list/action_bar")
:draw(function(_, parent)
local action_bar = Gui.elements.subframe_base(parent, "subfooter_frame", "action_bar")
action_bar.visible = false
Elements.close_action_bar(action_bar)
for action_name, button_data in pairs(config.buttons) do
local permission_flow = action_bar.add{ type = "flow", name = action_name }
permission_flow.visible = false
for _, button in ipairs(button_data) do
button(permission_flow)
end
end
return action_bar
end)
:style{
height = 35,
padding = { 1, 3 },
} --[[ @as any ]]
--- Update the action bar buttons to match the selection for a player, hidden when nothing is selected
--- @param action_bar LuaGuiElement
--- @param player LuaPlayer
--- @param selected_player LuaPlayer?
function Elements.action_bar.refresh(action_bar, player, selected_player)
if not selected_player then
action_bar.visible = false
return
end
action_bar.visible = true
for action_name, buttons in pairs(config.buttons) do
local flow = action_bar[action_name]
if buttons.auth and not buttons.auth(player, selected_player) then
flow.visible = false
else
flow.visible = Roles.player_allowed(player, action_name)
end
end
end
--- Reason bar footer holding the reason entry and confirm button
--- @class ExpGui_PlayerList.elements.reason_bar: ExpElement
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
Elements.reason_bar = Gui.define("player_list/reason_bar")
:draw(function(_, parent)
local reason_bar = Gui.elements.subframe_base(parent, "subfooter_frame", "reason_bar")
reason_bar.visible = false
local reason_field = reason_bar.add{
name = "entry",
type = "textfield",
style = "stretchable_textfield",
tooltip = { "exp-gui_player-list.reason-entry" },
}
local entry_style = reason_field.style
entry_style.padding = 0
entry_style.height = 28
entry_style.minimal_width = 158
Elements.reason_confirm(reason_bar)
return reason_bar
end)
:style{
height = 35,
padding = { -1, 3 },
} --[[ @as any ]]
--- Update the reason bar visibility to match the selection, shown only while an action awaits a reason
--- @param reason_bar LuaGuiElement
--- @param selected_player LuaPlayer?
--- @param selected_action string?
function Elements.reason_bar.refresh(reason_bar, selected_player, selected_action)
reason_bar.visible = selected_player ~= nil and selected_action ~= nil
end
--- @class ExpGui_PlayerList.elements.container.selection
--- @field selected_player LuaPlayer?
--- @field selected_action string?
--- Container added to the left gui flow
--- @class ExpGui_PlayerList.elements.container: ExpElement
--- @field data table<LuaPlayer, ExpGui_PlayerList.elements.container.selection>
Elements.container = Gui.define("player_list/container")
:draw(function(_, parent)
local container = Gui.elements.container(parent)
local player_table = Elements.player_table(container)
local action_bar = Elements.action_bar(container)
local reason_bar = Elements.reason_bar(container)
Elements.player_table.set_bars(player_table, action_bar, reason_bar)
local row_data = Elements.player_table.calculate_row_data()
Elements.player_table.rebuild(player_table, row_data)
return Gui.elements.container.get_root_element(container)
end) --[[ @as any ]]
--- Get or create the selection state for a player
--- @param player LuaPlayer
--- @return ExpGui_PlayerList.elements.container.selection
function Elements.container._get_selection(player)
local selection = Elements.container.data[player]
if not selection then
selection = {}
Elements.container.data[player] = selection
end
return selection
end
--- Get the player that actions will be performed on
--- @param player LuaPlayer
--- @return LuaPlayer?
function Elements.container.get_selected_player(player)
return Elements.container._get_selection(player).selected_player
end
--- Get the action awaiting a reason
--- @param player LuaPlayer
--- @return string?
function Elements.container.get_selected_action(player)
return Elements.container._get_selection(player).selected_action
end
--- Set the player that actions will be performed on, nil to clear the selection
--- @param player LuaPlayer
--- @param selected_player LuaPlayer?
function Elements.container.set_selected_player(player, selected_player)
local selection = Elements.container._get_selection(player)
selection.selected_player = selected_player
if not selected_player then
selection.selected_action = nil
end
end
--- Toggle the player that actions will be performed on
--- @param player LuaPlayer
--- @param selected_player LuaPlayer
function Elements.container.toggle_selected_player(player, selected_player)
if Elements.container.get_selected_player(player) == selected_player then
Elements.container.set_selected_player(player, nil)
else
Elements.container.set_selected_player(player, selected_player)
end
end
--- Set the action awaiting a reason, nil to clear it
--- @param player LuaPlayer
--- @param selected_action string?
function Elements.container.set_selected_action(player, selected_action)
Elements.container._get_selection(player).selected_action = selected_action
end
-- Inject the accessors the actions config needs; setting an action also refreshes the gui to show the reason bar
local function select_action(player, selected_action)
Elements.container.set_selected_action(player, selected_action)
Elements.player_table.refresh_player(player)
end
config.set_accessors(Elements.container.get_selected_player, select_action)
--- Add the element to the left flow with a toolbar button
Gui.add_left_element(Elements.container, true)
Gui.toolbar.create_button{
name = "toggle_player_list",
left_element = Elements.container,
sprite = "entity/character",
tooltip = { "exp-gui_player-list.main-tooltip" },
visible = function(player, element)
return Roles.player_allowed(player, "gui/player-list")
end
}
--- Rebuild the player list for all online players, used when the sort order changes
local function redraw_player_list()
local row_data = Elements.player_table.calculate_row_data()
for _, player_table in Elements.player_table:online_elements() do
Elements.player_table.rebuild(player_table, row_data)
Elements.player_table.refresh_player(Gui.get_player(player_table))
end
end
--- Refresh the play times for all online players
local function refresh_player_times()
local time_data = Elements.player_table.calculate_time_data()
for _, player_table in Elements.player_table:online_elements() do
Elements.player_table.refresh_times(player_table, time_data)
end
end
--- Remove a player from the list when they leave and clear any selection pointing at them
--- @param event EventData.on_player_left_game
local function on_player_left_game(event)
local left_player = game.players[event.player_index]
for _, player_table in Elements.player_table:online_elements() do
Elements.player_table.remove_row(player_table, left_player.name)
local viewing_player = Gui.get_player(player_table)
if Elements.container.get_selected_player(viewing_player) == left_player then
Elements.container.set_selected_player(viewing_player, nil)
Elements.player_table.refresh_player(viewing_player)
end
end
end
local e = defines.events
return {
elements = Elements,
events = {
[e.on_player_joined_game] = redraw_player_list,
[e.on_player_left_game] = on_player_left_game,
[Roles.events.on_role_assigned] = redraw_player_list,
[Roles.events.on_role_unassigned] = redraw_player_list,
},
on_nth_tick = {
[1800] = refresh_player_times,
}
}
+34 -13
View File
@@ -7,10 +7,14 @@ local Commands = require("modules/exp_commands")
local Roles = require("modules/exp_legacy/expcore/roles")
local addon_artillery = require("modules/exp_scenario/commands/artillery")
local addon_research = require("modules/exp_scenario/commands/research")
local addon_trains = require("modules/exp_scenario/commands/trains")
local addon_teleport = require("modules/exp_scenario/commands/teleport")
local addon_waterfill = require("modules/exp_scenario/commands/waterfill")
local addon_surface = require("modules/exp_scenario/commands/surface")
local addon_lawnmower = require("modules/exp_scenario/commands/lawnmower")
local addon_home = require("modules/exp_scenario/commands/home")
local addon_vlayer = require("modules/exp_scenario/commands/vlayer")
local addon_repair = require("modules/exp_scenario/commands/repair")
--- @class ExpGui_QuickActions.elements
local Elements = {}
@@ -18,15 +22,23 @@ local Elements = {}
--- @type table<string, { command: ExpCommand, element: ExpElement }>
local Actions = {}
--- @param name string
--- @param command ExpCommand | function (this is needed because of the overload on commands)
--- @param on_click? ExpElement.EventHandler<EventData.on_gui_click>
local function new_quick_action(name, command, on_click)
local element = Gui.define("quick_actions/" .. name)
local function new_quick_action(command, on_click)
local command_name = command.name
local element = Gui.define("quick_actions/" .. command_name)
:draw{
type = "button",
caption = { "exp-gui_quick-actions.caption-" .. name },
tooltip = { "exp-gui_quick-actions.tooltip-" .. name },
caption = { "?",
{ "exp-gui_quick-actions.caption-" .. command_name },
command_name,
},
tooltip = { "?",
{ "exp-gui_quick-actions.tooltip-" .. command_name },
command.description,
""
},
}
:style{
width = 160,
@@ -35,22 +47,31 @@ local function new_quick_action(name, command, on_click)
command(player)
end)
Elements[name] = element
Actions[name] = {
Elements[command_name] = element
Actions[command_name] = {
command = command --[[ @as ExpCommand ]],
element = element,
}
end
new_quick_action("artillery", addon_artillery.commands.artillery)
new_quick_action("trains", addon_trains.commands.set_trains_to_automatic)
new_quick_action("research", addon_research.commands.set_auto_research)
new_quick_action(addon_artillery.commands.artillery)
new_quick_action(addon_trains.commands.set_trains_to_automatic)
new_quick_action("spawn", addon_teleport.commands.spawn, function(def, player, element, event)
new_quick_action(addon_teleport.commands.spawn, function(def, player, element, event)
addon_teleport.commands.spawn(player, player)
end)
new_quick_action("waterfill", addon_waterfill.commands.waterfill)
new_quick_action(addon_waterfill.commands.waterfill)
new_quick_action(addon_lawnmower.commands.lawnmower)
new_quick_action(addon_surface.commands.clear_ground_items)
new_quick_action(addon_surface.commands.clear_blueprints_surface)
new_quick_action(addon_surface.commands.clear_blueprints)
new_quick_action(addon_home.commands.home)
new_quick_action(addon_home.commands.home_return)
new_quick_action(addon_home.commands.set_home)
new_quick_action(addon_home.commands.get_home)
new_quick_action(addon_vlayer.commands.vlayer)
new_quick_action(addon_repair.commands.repair)
--- Container added to the left gui flow
--- @class ExpGui_QuickActions.elements.container: ExpElement
+2 -2
View File
@@ -200,7 +200,7 @@ define_tab(
local container = parent.add{ type = "flow", direction = "vertical" }
local top_flow = container.add{ type = "flow" }
top_flow.add{ type = "sprite", sprite = "file/modules/exp_legacy/modules/gui/logo.png" }
top_flow.add{ type = "sprite", sprite = "file/modules/exp_scenario/gui/logo.png" }
local center_flow = top_flow.add{ type = "flow", direction = "vertical" }
center_flow.style.horizontal_align = "center"
@@ -208,7 +208,7 @@ define_tab(
Gui.elements.title_label(center_flow, 62, { "exp-gui_readme.welcome-title", server_details.name })
Gui.elements.centered_label(center_flow, 380, server_details.welcome)
top_flow.add{ type = "sprite", sprite = "file/modules/exp_legacy/modules/gui/logo.png" }
top_flow.add{ type = "sprite", sprite = "file/modules/exp_scenario/gui/logo.png" }
Gui.elements.bar(container)
container.add{ type = "flow" }.style.height = 4
+28 -24
View File
@@ -103,6 +103,9 @@ lower-role=You must have a higher role than the target.
[exp-commands_lawnmower]
description=Clean up biter corpse, decoratives and nuclear hole.
arg-range=Range to clean up.
enter=Entered selection mode, select the area to fill with water.
exit=Exited selection mode.
complete=__1__ tiles were handled.
[exp-commands_locate]
description=Opens remote view at the location of the player's last location.
@@ -155,7 +158,8 @@ machine-count=And you will need __1__ machines (with the same speed as this one)
[exp-commands_repair]
description=Repairs entities on your force around you.
arg-range=Range to repair entities within.
enter=Entered selection mode, select the area.
exit=Exited selection mode.
# Intentional space left on the two lines below so they can be joined together.
response-revive=__1__ entities were revived.
response-heal=__1__ entities were healed.
@@ -182,12 +186,6 @@ list-element=__1__: __2__
removed-all=__1__ has has all of their reports removed by __2__.
removed=__1__ has a report removed by __2__.
[exp-commands_research]
description=Sets research to be automatically queued.
arg-state=State to set, default is to toggle.
auto-research=__1__ set auto research to __2__
queue=[color=255, 255, 255] Research added to queue - [technology=__1__] - __2__[/color]
[exp-commands_roles]
description-assign=Assigns a role to a player.
description-unassign=Unassigns a role from a player.
@@ -221,14 +219,13 @@ follow-self=You can not follow yourself.
[exp-commands_surface]
description-items=Clear all items on the ground.
description-blueprints=Clear all blueprints.
description-radius=Clear all blueprints in an radius around you.
description-blueprints-surface=Clear all blueprints on the current surface.
arg-surface=Surface to clear on, default all.
arg-radius=Radius to clear.
items-surface=__1__ cleared all items on the ground of __2__.
items-all=__1__ cleared all items on the ground for all surfaces.
blueprints-surface=__1__ cleared all blueprints on __2__.
blueprints-all=__1__ cleared all blueprints for all surfaces.
blueprints-radius=__1__ cleared all blueprints in a __2__ radius around them on __3__.
items=__1__ cleared all items on the ground of __2__.
blueprints=__1__ cleared all blueprints on __2__.
enter=Entered selection mode, select the area.
exit=Exited selection mode.
complete=__1__ blueprint ghost were removed.
[exp-commands_trains]
description=Set All Trains to Automatic, does not effect trains with passengers.
@@ -295,10 +292,6 @@ tooltip-amount=Amount of items to insert into the __1__ slots
invalid=Autofill set to maximum amount: __1__ __2__ for __3__
inserted=Inserted __1__ __2__ into __3__
[exp-gui_landfill-blueprint]
tooltip-main=Landfill Blueprint
error-no-blueprint=You need to hold the blueprint in cursor
[exp-gui_module-inserter]
tooltip-main=Module Inserter
caption-main=Modules
@@ -324,6 +317,22 @@ tooltip-character_reach_distance_bonus=Character reach distance bonus
caption-personal_battery_recharge=Battery
tooltip-personal_battery_recharge=Armor battery recharge
[exp-gui_player-list]
main-tooltip=Player List
open-action-bar=Options
close-action-bar=Close Options
reason-confirm=Confirm Reason
reason-entry=Enter Reason
goto-player=Goto player
bring-player=Bring player
report-player=Report player
warn-player=Warn player
jail-player=Jail player
kick-player=Kick player
ban-player=Ban player
afk-time=__1__% of total map time\nLast moved __2__ ago
open-map=__1__ __2__\n__3__\nClick to open map
[exp-gui_player-stats]
tooltip-main=Player Stats
caption-main=Player Stats
@@ -336,15 +345,10 @@ caption-net=Net
[exp-gui_quick-actions]
tooltip-main=Quick Actions
caption-artillery=Artillery
tooltip-artillery=Select artillery targets
caption-research=Auto Research
tooltip-research=Toggle auto research queue
caption-spawn=Teleport Spawn
tooltip-spawn-tooltip=Teleport to spawn
caption-trains=Set Auto Train
tooltip-trains=Set all trains to automatic
caption-waterfill=Waterfill
tooltip-waterfill=Change tiles to water
[exp-gui_readme]
main-tooltip=Information
@@ -572,4 +576,4 @@ chat-found=You cannot have __1__ in your inventory, so it was placed into the ch
chat-jailed=__1__ was jailed because they removed too many protected entities. Please wait for a moderator.
[exp_report-jail]
chat-jailed=__1__ was jailed because they were reported too many times. Please wait for a moderator.
chat-jailed=__1__ was jailed because they were reported too many times. Please wait for a moderator.
+7 -17
View File
@@ -182,12 +182,6 @@ list-element=__1__: __2__
removed-all=__1__ 被舉報的所有紀錄已被 __2__ 清除。
removed=__1__ 被舉報的一個紀錄已被 __2__ 清除。
[exp-commands_research]
description=啟用自動研究
arg-state=狀態
auto-research=__1__ 把自動研究設置為 __2__ 。
queue=[color=255, 255, 255] 研究已加入隊列 - [technology=__1__] - __2__[/color]
[exp-commands_roles]
description-assign=為用戶指配用戶組
description-unassign=為用戶取消指配用戶組
@@ -221,14 +215,14 @@ follow-self=你不能追蹤自己
[exp-commands_surface]
description-items=清除地面上的物品
description-blueprints=清除藍圖
description-radius=清除周邊的藍圖
description-blueprints-surface=清除藍圖
arg-surface=位面
arg-radius=周邊半徑
items-surface=__1__ 清除了所有在 __2__ 中地上的東西
items-all=__1__ 清除了所有掉地上的東西。
blueprints-surface=__1__ 清除了所有在 __2__ 中在地上的藍圖。
blueprints-all=__1__ 清除了所有在地上的藍圖
blueprints-radius=__1__ 清除了在 __3__ 上,周邊 __2__ 格的地上的藍圖。
items=__1__ 清除了所有在 __2__ 中掉地上的東西。
blueprints=__1__ 清除了所有在 __2__ 中地上的藍圖
enter=現在進入區域選擇
exit=已進入區域選擇
area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格
complete=__1__ 地上的藍圖已被清除
[exp-commands_trains]
description=把火車設置為自動模式
@@ -295,10 +289,6 @@ tooltip-amount=自動填入 __1__ 的數量
invalid=自動填入最大值 __1__ __2__ 給 __3__
inserted=自動填入 __1__ __2__ 到 __3__
[exp-gui_landfill-blueprint]
tooltip-main=藍圖填海
error-no-blueprint=您需要將藍圖保持在遊標處
[exp-gui_module-inserter]
tooltip-main=模組
caption-main=Modules
+7 -17
View File
@@ -182,12 +182,6 @@ list-element=__1__: __2__
removed-all=__1__ 被舉報的所有紀錄已被 __2__ 清除。
removed=__1__ 被舉報的一個紀錄已被 __2__ 清除。
[exp-commands_research]
description=啟用自動研究
arg-state=狀態
auto-research=__1__ 把自動研究設置為 __2__ 。
queue=[color=255, 255, 255] 研究已加入隊列 - [technology=__1__] - __2__[/color]
[exp-commands_roles]
description-assign=為用戶指配用戶組
description-unassign=為用戶取消指配用戶組
@@ -221,14 +215,14 @@ follow-self=你不能追蹤自己
[exp-commands_surface]
description-items=清除地面上的物品
description-blueprints=清除藍圖
description-radius=清除周邊的藍圖
description-blueprints-surface=清除藍圖
arg-surface=位面
arg-radius=周邊半徑
items-surface=__1__ 清除了所有在 __2__ 中地上的東西
items-all=__1__ 清除了所有掉地上的東西。
blueprints-surface=__1__ 清除了所有在 __2__ 中在地上的藍圖。
blueprints-all=__1__ 清除了所有在地上的藍圖
blueprints-radius=__1__ 清除了在 __3__ 上,周邊 __2__ 格的地上的藍圖。
items=__1__ 清除了所有在 __2__ 中掉地上的東西。
blueprints=__1__ 清除了所有在 __2__ 中地上的藍圖
enter=現在進入區域選擇
exit=已進入區域選擇
area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格
complete=__1__ 地上的藍圖已被清除
[exp-commands_trains]
description=把火車設置為自動模式
@@ -295,10 +289,6 @@ tooltip-amount=自動填入 __1__ 的數量
invalid=自動填入最大值 __1__ __2__ 給 __3__
inserted=自動填入 __1__ __2__ 到 __3__
[exp-gui_landfill-blueprint]
tooltip-main=藍圖填海
error-no-blueprint=您需要將藍圖保持在遊標處
[exp-gui_module-inserter]
tooltip-main=模組
caption-main=Modules
+2 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@expcluster/scenario",
"version": "0.1.0",
"version": "6.5.0",
"description": "Clusterio plugin implementing the Explosive Gaming scenario.",
"author": "Cooldude2606 <https://github.com/Cooldude2606>",
"license": "MIT",
@@ -31,6 +31,7 @@
"dependencies": {
"@expcluster/lib_commands": "workspace:^",
"@expcluster/lib_util": "workspace:^",
"@expcluster/lib_gui": "workspace:^",
"@sinclair/typebox": "catalog:"
},
"publishConfig": {