Apply platform player colours throughout the viewer
This commit is contained in:
parent
3bf70e351d
commit
64eba2a37d
5 changed files with 20 additions and 24 deletions
|
|
@ -20,7 +20,7 @@
|
|||
const state = $derived(store.state);
|
||||
</script>
|
||||
|
||||
<SpaceScene gameState={state} />
|
||||
<SpaceScene gameState={state} {store} />
|
||||
|
||||
{#if state}
|
||||
<div class="board">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script lang="ts">
|
||||
import { VICTORY_VP } from "outpost-engine";
|
||||
import { playerColor, type ViewerStore } from "./store.svelte";
|
||||
import { type ViewerStore } from "./store.svelte";
|
||||
|
||||
interface Props {
|
||||
store: ViewerStore;
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
<span class="dot" style="background: {playerColor(row.i)}"></span>
|
||||
<span class="dot" style="background: {store.playerColor(row.i)}"></span>
|
||||
{row.p.name}
|
||||
</td>
|
||||
<td class="score">{scores[row.i]}</td>
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
<span class="bar">
|
||||
<span
|
||||
class="fill"
|
||||
style="width: {Math.round(((scores[row.i] ?? 0) / maxScore) * 100)}%; background: {playerColor(
|
||||
style="width: {Math.round(((scores[row.i] ?? 0) / maxScore) * 100)}%; background: {store.playerColor(
|
||||
row.i
|
||||
)}"
|
||||
></span>
|
||||
|
|
|
|||
|
|
@ -18,14 +18,7 @@
|
|||
} from "outpost-engine";
|
||||
import ProductionCardView from "./ProductionCardView.svelte";
|
||||
import ResourceIcon from "./ResourceIcon.svelte";
|
||||
import {
|
||||
KICKER_EFFECTS,
|
||||
RESOURCE_LABELS,
|
||||
UPGRADE_EFFECTS,
|
||||
effectToText,
|
||||
playerColor,
|
||||
type ViewerStore,
|
||||
} from "./store.svelte";
|
||||
import { KICKER_EFFECTS, RESOURCE_LABELS, UPGRADE_EFFECTS, effectToText, type ViewerStore } from "./store.svelte";
|
||||
|
||||
interface Props {
|
||||
state: GameState;
|
||||
|
|
@ -110,7 +103,7 @@
|
|||
class:me={isMe}
|
||||
class:targetable={exchangeTargetable}
|
||||
class:targeted={exchangeTargeted}
|
||||
style="--pc: {playerColor(index)}"
|
||||
style="--pc: {store.playerColor(index)}"
|
||||
>
|
||||
{#if exchangeTargetable}
|
||||
<button
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
type Resource,
|
||||
type Upgrade,
|
||||
} from "outpost-engine";
|
||||
import { RESOURCE_LABELS, playerColor } from "./store.svelte";
|
||||
import { RESOURCE_LABELS, type ViewerStore } from "./store.svelte";
|
||||
|
||||
const RESOURCE_COLORS: Record<Resource, string> = {
|
||||
ore: "#a8b4c0",
|
||||
|
|
@ -37,9 +37,10 @@
|
|||
|
||||
interface Props {
|
||||
gameState: GameState | null;
|
||||
store: ViewerStore;
|
||||
}
|
||||
|
||||
let { gameState }: Props = $props();
|
||||
let { gameState, store }: Props = $props();
|
||||
|
||||
interface Building {
|
||||
x: number;
|
||||
|
|
@ -113,7 +114,7 @@
|
|||
const buildings: Omit<Building, "x" | "y">[] = [];
|
||||
for (const f of p.factories) {
|
||||
buildings.push({
|
||||
color: playerColor(i),
|
||||
color: store.playerColor(i),
|
||||
kind: "factory",
|
||||
type: f.type,
|
||||
resource: f.type,
|
||||
|
|
@ -129,7 +130,7 @@
|
|||
const spec = UPGRADE_SPECS[u];
|
||||
for (let n = 0; n < count; n++) {
|
||||
buildings.push({
|
||||
color: playerColor(i),
|
||||
color: store.playerColor(i),
|
||||
kind: "upgrade",
|
||||
type: u,
|
||||
resource: spec.produces ?? (spec.freeFactory as Resource) ?? "ore",
|
||||
|
|
@ -144,7 +145,7 @@
|
|||
}
|
||||
for (let n = 0; n < p.kickers[k]; n++) {
|
||||
buildings.push({
|
||||
color: playerColor(i),
|
||||
color: store.playerColor(i),
|
||||
kind: "kicker",
|
||||
type: k,
|
||||
resource: "ore",
|
||||
|
|
@ -153,7 +154,7 @@
|
|||
});
|
||||
}
|
||||
}
|
||||
return { color: playerColor(i), name: p.name, biosphere: p.kickers.biosphere > 0, buildings };
|
||||
return { color: store.playerColor(i), name: p.name, biosphere: p.kickers.biosphere > 0, buildings };
|
||||
})
|
||||
.filter((c) => c.buildings.length > 0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -66,10 +66,6 @@ export const PLAYER_COLORS = [
|
|||
"#8b94f7",
|
||||
] as const;
|
||||
|
||||
export function playerColor(index: number): string {
|
||||
return PLAYER_COLORS[index % PLAYER_COLORS.length] as string;
|
||||
}
|
||||
|
||||
export const RESOURCE_LABELS: Record<string, string> = {
|
||||
ore: "Ore",
|
||||
water: "Water",
|
||||
|
|
@ -206,6 +202,12 @@ export const KICKER_EFFECTS: Record<Kicker, EffectToken[]> = {
|
|||
};
|
||||
|
||||
export class ViewerStore {
|
||||
playerColor(index: number): string {
|
||||
const appearance = this.preferences.bgs as { playerColors?: string[] } | undefined;
|
||||
const custom = appearance?.playerColors?.[index];
|
||||
return custom && /^#[a-f0-9]{6}$/i.test(custom) ? custom : PLAYER_COLORS[index % PLAYER_COLORS.length]!;
|
||||
}
|
||||
|
||||
liveState = $state<GameState | null>(null);
|
||||
replay = $state<ReplayState>({ active: false, current: 0, end: 0, state: null });
|
||||
playerIndex = $state<number | undefined>(undefined);
|
||||
|
|
@ -1043,7 +1045,7 @@ export class ViewerStore {
|
|||
const seat =
|
||||
message.playerIndex ??
|
||||
(message.author !== undefined ? (this.liveState?.players.findIndex((p) => p.name === message.author) ?? -1) : -1);
|
||||
return seat >= 0 ? playerColor(seat) : undefined;
|
||||
return seat >= 0 ? this.playerColor(seat) : undefined;
|
||||
}
|
||||
|
||||
private send(move: Move): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue