colores asignados al azar y simulador de jugadores en el dashboard
This commit is contained in:
@@ -6,6 +6,23 @@ import { isUuidAllowed } from "../utils/uuidRegistry";
|
||||
export class LobbyRoom extends Room<LobbyState> {
|
||||
private updateInterval?: NodeJS.Timeout;
|
||||
private sessionToUuid: Map<string, string> = new Map();
|
||||
|
||||
// Generate a random dark-ish color (for white backgrounds)
|
||||
private randomDarkHex(): string {
|
||||
const h = Math.floor(Math.random() * 360);
|
||||
const s = 65 + Math.floor(Math.random() * 20); // 65% - 85%
|
||||
const l = 30 + Math.floor(Math.random() * 10); // 30% - 40%
|
||||
return this.hslToHex(h, s, l);
|
||||
}
|
||||
|
||||
private hslToHex(h: number, s: number, l: number): string {
|
||||
s /= 100; l /= 100;
|
||||
const k = (n: number) => (n + h / 30) % 12;
|
||||
const a = s * Math.min(l, 1 - l);
|
||||
const f = (n: number) => l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
||||
const toHex = (x: number) => Math.round(255 * x).toString(16).padStart(2, '0');
|
||||
return `#${toHex(f(0))}${toHex(f(8))}${toHex(f(4))}`;
|
||||
}
|
||||
|
||||
onCreate(options: any) {
|
||||
this.setState(new LobbyState());
|
||||
@@ -80,10 +97,14 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
// Add player temporarily to lobby state
|
||||
const existingName = NameManager.getInstance().getPlayerName(options.uuid);
|
||||
this.state.addPlayer(client.sessionId, existingName || "");
|
||||
const existingColor = NameManager.getInstance().getPlayerColor(options.uuid);
|
||||
if (existingColor) {
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) p.color = existingColor;
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) {
|
||||
let color = NameManager.getInstance().getPlayerColor(options.uuid);
|
||||
if (!color) {
|
||||
color = this.randomDarkHex();
|
||||
NameManager.getInstance().setPlayerColor(options.uuid, color);
|
||||
}
|
||||
p.color = color;
|
||||
}
|
||||
|
||||
// Send welcome first
|
||||
@@ -106,10 +127,14 @@ export class LobbyRoom extends Room<LobbyState> {
|
||||
// Check if this UUID already has a name
|
||||
const existingName = NameManager.getInstance().getPlayerName(options.uuid);
|
||||
this.state.addPlayer(client.sessionId, existingName || "");
|
||||
const existingColor = NameManager.getInstance().getPlayerColor(options.uuid);
|
||||
if (existingColor) {
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) p.color = existingColor;
|
||||
const p = this.state.players.get(client.sessionId);
|
||||
if (p) {
|
||||
let color = NameManager.getInstance().getPlayerColor(options.uuid);
|
||||
if (!color) {
|
||||
color = this.randomDarkHex();
|
||||
NameManager.getInstance().setPlayerColor(options.uuid, color);
|
||||
}
|
||||
p.color = color;
|
||||
}
|
||||
|
||||
client.send("welcome", {
|
||||
|
||||
Reference in New Issue
Block a user