mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-12 23:54:53 +09:00
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>
29 lines
1.2 KiB
Lua
29 lines
1.2 KiB
Lua
--- 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
|
|
|
|
--- 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
|
|
|
|
--- 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
|
|
|
|
player.color = colour
|
|
player.chat_color = lighten(colour)
|
|
end)
|