Files
factorio-expcluster/exp_legacy/module/modules/data/player-colours.lua
T
BastiaanandClaude Opus 5.5 11ccee572b 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>
2026-10-11 18:29:11 +01:00

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)