Drop exp_legacy player data that inventory_sync covers (#491)

Inventory sync already stores the player colour, tag, quickbar and alt
view (game view settings), so the legacy alt-view, quickbar and tag
modules and the colour persistence are removed along with
/save-quickbar and its quickbar presets.

The /tag, /tag-color and /tag-clear commands move to exp_scenario and
write player.tag directly, which inventory sync then carries between
servers. /tag-color reads the current text back out of the tag, so it
now needs a tag to be set first. It also used to concatenate the colour
table into the tag and error, it now formats it as rich text.

player-colours keeps giving new players their preset or a random
colour on creation, inventory sync replaces it with the stored one for
anyone who has played before.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BastiaanandClaude Opus 5.5 authored and GitHub committed 2026-10-11 18:29:11 +01:00
1 parent 1c5c9909cc
commit 11ccee572b
17 files changed
+103 -286

No files matched your search

@@ -1,26 +0,0 @@
--- Stores if you use alt mode or not and auto applies it
-- @data Alt-View
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
--- Stores the visible state of alt mode
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
local UsesAlt = PlayerData.Settings:combine("UsesAlt")
UsesAlt:set_default(false)
UsesAlt:set_metadata{
stringify = function(value) return value and "Visible" or "Hidden" end,
}
--- When your data loads apply alt view if you have it enabled
UsesAlt:on_load(function(player_name, uses_alt)
local player = game.players[player_name]
if uses_alt ~= nil then
player.game_view_settings.show_entity_info = uses_alt
end
end)
--- When alt view is toggled update this
Event.add(defines.events.on_player_toggled_alt_mode, function(event)
local player = game.players[event.player_index]
UsesAlt:set(player, player.game_view_settings.show_entity_info)
end)
@@ -1,63 +1,28 @@
--- Gives players random colours when they join, also applies preset colours to those who have them
--- Gives players random colours when they are created, also applies preset colours to those who have them
--- Inventory sync restores the colour of players who have played before
-- @data Player-Colours
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Colours = require("modules/exp_util/include/color")
local config = require("modules.exp_legacy.config.preset_player_colours") --- @dep config.preset_player_colours
--- Stores the colour that the player wants
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
local PlayerColours = PlayerData.Settings:combine("Colour")
PlayerColours:set_metadata{
stringify = function(value)
if not value then return "None set" end
local c = value[1]
return string.format("Red: %d Green: %d Blue: %d", c[1], c[2], c[3])
end,
}
--- Used to compact player colours to take less space
local floor = math.floor
local function compact(colour)
return {
floor(colour.r * 255),
floor(colour.g * 255),
floor(colour.b * 255),
}
end
--- Returns a colour that is a bit lighter than the one given
local function lighten(c)
return { r = 255 - (255 - c.r) * 0.5, g = 255 - (255 - c.g) * 0.5, b = 255 - (255 - c.b) * 0.5, a = 255 }
end
--- When your data loads apply the players colour, or a random on if none is saved
PlayerColours:on_load(function(player_name, player_colour)
if not player_colour then
local preset = config.players[player_name]
if preset then
player_colour = { preset, lighten(preset) }
else
local colour_name = "white"
while config.disallow[colour_name] do
colour_name = table.get_random(Colours, true)
end
player_colour = { Colours[colour_name], lighten(Colours[colour_name]) }
--- Apply the preset colour of the player, or a random one if there is none
Event.add(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
local colour = config.players[player.name]
if not colour then
local colour_name = "white"
while config.disallow[colour_name] do
colour_name = table.get_random(Colours, true)
end
colour = Colours[colour_name]
end
local player = game.players[player_name]
player.color = player_colour[1]
player.chat_color = player_colour[2]
end)
--- Save the players color when they use the color command
Event.add(defines.events.on_console_command, function(event)
if event.command ~= "color" then return end
if event.parameters == "" then return end
if not event.player_index then return end
local player = game.players[event.player_index]
if not player or not player.valid then return end
PlayerColours:set(player, { compact(player.color), compact(player.chat_color) })
player.color = colour
player.chat_color = lighten(colour)
end)
@@ -1,64 +0,0 @@
--[[-- Commands Module - Quickbar
- Adds a command that allows players to load Quickbar presets
@data Quickbar
]]
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.preset_player_quickbar") --- @dep config.preset_player_quickbar
--- Stores the quickbar filters for a player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
local PlayerFilters = PlayerData.Settings:combine("QuickbarFilters")
PlayerFilters:set_metadata{
permission = "exp_scenario.command.save_quickbar",
stringify = function(value)
if not value then return "No filters set" end
local count = 0
for _ in pairs(value) do count = count + 1 end
return count .. " filters set"
end,
}
--- Filters are stored by a single index across the ten pages of ten slots
local total_page_count = 10
local slots_per_page = 10
--- Loads your quickbar preset
PlayerFilters:on_load(function(player_name, filters)
if not filters then filters = config[player_name] end
if not filters then return end
local player = game.players[player_name]
for index, item_name in pairs(filters) do
if item_name ~= nil and item_name ~= "" then
local page = math.ceil(index / slots_per_page)
local slot = (index - 1) % slots_per_page + 1
player.set_quick_bar_slot(page, slot, item_name)
end
end
end)
--- Saves your quickbar preset, only plain item filters can be saved
Commands.new("save-quickbar", "Saves your Quickbar preset items to file")
:add_aliases{ "save-toolbar" }
:register(function(player)
local filters = {}
for page = 1, total_page_count do
for slot = 1, slots_per_page do
-- Records, remotes and specific item instances hold data which can not be saved by name
local quick_bar_slot = player.get_quick_bar_slot(page, slot)
if quick_bar_slot and quick_bar_slot.type == "filter" then
filters[(page - 1) * slots_per_page + slot] = assert(quick_bar_slot.filter).name
end
end
end
if next(filters) then
PlayerFilters:set(player, filters)
else
PlayerFilters:remove(player)
end
return Commands.status.success{ "quickbar.saved" }
end)
-82
View File
@@ -1,82 +0,0 @@
--[[-- Commands Module - Tag
- Adds a command that allows players to have a custom tag after their name
@data Tag
]]
local Commands = require("modules/exp_commands")
local Roles = require("modules/exp_roles")
--- Stores the tag for a player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
local PlayerTags = PlayerData.Settings:combine("Tag")
local PlayerTagColors = PlayerData.Settings:combine("TagColor")
PlayerTags:set_metadata{
permission = "exp_scenario.command.tag",
}
PlayerTagColors:set_metadata{
permission = "exp_scenario.command.tag_color",
}
local set_tag = function(player, tag, color)
if tag == nil or tag == "" then
player.tag = ""
elseif color then
player.tag = "- [color=" .. color .. "]" .. tag .. "[/color]"
else
player.tag = "- " .. tag
end
end
--- When your tag is updated then apply the changes
PlayerTags:on_update(function(player_name, player_tag)
local player = game.players[player_name]
local player_tag_color = PlayerTagColors:get(player)
set_tag(player, player_tag, player_tag_color)
end)
--- When your tag color is updated then apply the changes
PlayerTagColors:on_update(function(player_name, player_tag_color)
local player = game.players[player_name]
local player_tag = PlayerTags:get(player)
set_tag(player, player_tag, player_tag_color)
end)
--- Sets your player tag.
Commands.new("tag", "Sets your player tag.")
:argument("tag", "", Commands.types.string_max_length(20))
:enable_auto_concatenation()
:register(function(player, tag)
--- @cast tag string
PlayerTags:set(player, tag)
end)
--- Sets your player tag color.
Commands.new("tag-color", "Sets your player tag color.")
:argument("color", "", Commands.types.color)
:enable_auto_concatenation()
:register(function(player, color)
--- @cast color Color
PlayerTagColors:set(player, color)
end)
--- Clears your tag. Or another player if you are admin.
Commands.new("tag-clear", "Clears your tag. Or another player if you are admin.")
:optional("player", "", Commands.types.lower_role_player)
:defaults{
player = function(player) return player end
}
:register(function(player, other_player)
--- @cast other_player LuaPlayer
if other_player == player then
-- No player given so removes your tag
PlayerTags:remove(other_player)
elseif Roles.player_has_permission(player, "exp_scenario.command.tag_clear.always") then
-- Player given and user is admin so clears that player's tag
PlayerTags:remove(other_player)
else
-- User is not admin and tried to clear another users tag
return Commands.status.unauthorised()
end
end)