mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-18 06:43:13 +09:00
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:
1 parent
1c5c9909cc
commit
11ccee572b
17 files changed
+103
-286
No files matched your search
@@ -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)
|
||||
Reference in new issue
Block a user