Show platform Supporter badges and preferred player colours
This commit is contained in:
parent
f2c1c6887b
commit
2e778ca976
10 changed files with 116 additions and 26 deletions
|
|
@ -3,4 +3,4 @@ packages:
|
|||
- 'engine'
|
||||
|
||||
minimumReleaseAgeExclude:
|
||||
- '@boardgamers/protocol@0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.6.2'
|
||||
- '@boardgamers/protocol@0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.6.2 || 0.8.1'
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
"tutorial:manifest": "node scripts/tutorial-manifest.cjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.6.2",
|
||||
"@boardgamers/protocol": "0.8.1",
|
||||
"core-js": "^3.6.5",
|
||||
"lodash": "^4.17.19",
|
||||
"powergrid-engine": "workspace:../engine",
|
||||
|
|
|
|||
8
viewer/pnpm-lock.yaml
generated
8
viewer/pnpm-lock.yaml
generated
|
|
@ -1,7 +1,7 @@
|
|||
lockfileVersion: 5.4
|
||||
|
||||
specifiers:
|
||||
'@boardgamers/protocol': 0.6.2
|
||||
'@boardgamers/protocol': 0.8.1
|
||||
'@types/assert': ^1.4.7
|
||||
'@types/chai': ^4.2.11
|
||||
'@types/events': ^3.0.0
|
||||
|
|
@ -34,7 +34,7 @@ specifiers:
|
|||
zod: 4.6.4
|
||||
|
||||
dependencies:
|
||||
'@boardgamers/protocol': 0.6.2
|
||||
'@boardgamers/protocol': 0.8.1
|
||||
core-js: 3.12.1
|
||||
lodash: 4.17.21
|
||||
powergrid-engine: link:../engine
|
||||
|
|
@ -1464,10 +1464,10 @@ packages:
|
|||
to-fast-properties: 2.0.0
|
||||
dev: true
|
||||
|
||||
/@boardgamers/protocol/0.6.2:
|
||||
/@boardgamers/protocol/0.8.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-6FKgLsB4guCzNww1rkanhrsLHIdQVajDs1B4qNsYcgtUobTBRM2VPt9T4mlc8ZDX4JDQltvJVHuK7XDZ1J556A==,
|
||||
integrity: sha512-BZNj+wof1aR1nSybRMqmQ+yAVNR3ZZy+mczIz2KbXSLXMLL3Jv21yi50CRbJ2ipdkPiPatcSP0nJj+xJbFgIfQ==,
|
||||
}
|
||||
dependencies:
|
||||
zod: 4.6.4
|
||||
|
|
|
|||
|
|
@ -590,7 +590,7 @@
|
|||
<tr>
|
||||
<th><div>Player</div></th>
|
||||
<th v-for="player in sortedPlayers" :key="'FS' + player.id">
|
||||
<div :style="'background-color: ' + playerColors[player.id]">{{ player.name }}</div>
|
||||
<div :style="{ backgroundColor: playerColors[player.id], color: colorText(playerColors[player.id]) }">{{ player.name }}</div>
|
||||
</th>
|
||||
</tr>
|
||||
<tr v-for="(cat, i) in ['Cities Powered', 'Money', 'Total Cities']" :key="'FC_' + cat">
|
||||
|
|
@ -615,7 +615,7 @@
|
|||
<tr>
|
||||
<th><div>Player</div></th>
|
||||
<th v-for="player in sortedPlayers" :key="'FS' + player.id">
|
||||
<div :style="'background-color: ' + playerColors[player.id]">{{ player.name }}</div>
|
||||
<div :style="{ backgroundColor: playerColors[player.id], color: colorText(playerColors[player.id]) }">{{ player.name }}</div>
|
||||
</th>
|
||||
</tr>
|
||||
<tr v-for="row in spendingRows" :key="'FC_' + row.label">
|
||||
|
|
@ -776,6 +776,7 @@
|
|||
</template>
|
||||
<script lang="ts">
|
||||
import { isEqual } from 'lodash';
|
||||
import { resolvePlayerColors, colorText } from '../player-colors';
|
||||
import InlineLog from './InlineLog.vue';
|
||||
import { Vue, Component, Prop, Watch, Provide, ProvideReactive, Ref } from 'vue-property-decorator';
|
||||
import { MoveName, ended, playersSortedByScore, reconstructState } from 'powergrid-engine';
|
||||
|
|
@ -1017,18 +1018,14 @@ export default class Game extends Vue {
|
|||
G?: GameState | null = null;
|
||||
_futureState?: GameState;
|
||||
|
||||
colorText = colorText;
|
||||
|
||||
defaultPlayerColors = ['limegreen', 'mediumorchid', 'red', 'dodgerblue', 'yellow', 'brown'];
|
||||
|
||||
// Colors indexed by player id. Falls back to the default palette, but any color
|
||||
// a player drafted via the chooseColors option overrides their default entry.
|
||||
get playerColors() {
|
||||
const colors = [...this.defaultPlayerColors];
|
||||
if (this.G) {
|
||||
for (const p of this.G.players) {
|
||||
if (p.color) colors[p.id] = p.color;
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
return resolvePlayerColors(this.defaultPlayerColors, this.G?.players ?? [], this.preferences);
|
||||
}
|
||||
|
||||
animationQueue: Array<Function> = [];
|
||||
|
|
@ -3186,5 +3183,37 @@ text {
|
|||
.journal-and-chat {
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
}
|
||||
.journal-and-chat {
|
||||
--feed-panel-height: 280px;
|
||||
--feed-body-height: calc(var(--feed-panel-height) - 42px);
|
||||
}
|
||||
.journal-and-chat .inline-game-log,
|
||||
.journal-and-chat .bgs-game-chat {
|
||||
padding: 10px 14px;
|
||||
}
|
||||
.journal-and-chat details[open] {
|
||||
height: var(--feed-panel-height);
|
||||
}
|
||||
.journal-and-chat summary {
|
||||
line-height: 20px;
|
||||
}
|
||||
.journal-and-chat .journal-feed {
|
||||
height: calc(var(--feed-body-height) - 8px);
|
||||
max-height: none;
|
||||
}
|
||||
.journal-and-chat .chat-body {
|
||||
height: var(--feed-body-height);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.journal-and-chat .chat-messages {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: none;
|
||||
}
|
||||
.journal-and-chat .chat-composer,
|
||||
.journal-and-chat .chat-status {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,17 @@
|
|||
style="border-radius: 50%"
|
||||
/>
|
||||
</foreignObject>
|
||||
<image
|
||||
v-if="supporterBadge"
|
||||
:href="supporterBadge.url"
|
||||
x="-33"
|
||||
y="-8"
|
||||
width="13"
|
||||
height="13"
|
||||
:aria-label="supporterBadge.label"
|
||||
>
|
||||
<title>{{ supporterBadge.label }}</title>
|
||||
</image>
|
||||
<text
|
||||
:data-bgs-player="owner"
|
||||
style="pointer-events: all"
|
||||
|
|
@ -17,11 +28,13 @@
|
|||
x="5"
|
||||
y="13"
|
||||
font-weight="600"
|
||||
fill="black"
|
||||
:fill="colorText(color)"
|
||||
>
|
||||
{{ getPlayerName() }}
|
||||
</text>
|
||||
<text v-if="showMoney" x="250" y="13" font-weight="600" fill="black">Money: ${{ player.money }}</text>
|
||||
<text v-if="showMoney" x="250" y="13" font-weight="600" :fill="colorText(color)"
|
||||
>Money: ${{ player.money }}</text
|
||||
>
|
||||
|
||||
<Card
|
||||
v-for="(powerPlant, i) in player.powerPlants"
|
||||
|
|
@ -120,6 +133,7 @@
|
|||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { colorText } from '../player-colors';
|
||||
import { MoveName, Player } from 'powergrid-engine';
|
||||
import { Phase, playerTimeUsed, PowerPlant, PowerPlantType, ResourceType } from 'powergrid-engine/src/gamestate';
|
||||
import { Vue, Component, Prop, Inject } from 'vue-property-decorator';
|
||||
|
|
@ -133,10 +147,11 @@ import { Coal, Oil, Garbage, Uranium, Card } from './pieces';
|
|||
Oil,
|
||||
Garbage,
|
||||
Uranium,
|
||||
Card,
|
||||
},
|
||||
Card
|
||||
}
|
||||
})
|
||||
export default class PlayerBoard extends Vue {
|
||||
colorText = colorText;
|
||||
@Prop() color?: string;
|
||||
@Prop() avatar?: string;
|
||||
@Prop() player!: Player;
|
||||
|
|
@ -153,6 +168,12 @@ export default class PlayerBoard extends Vue {
|
|||
|
||||
@Inject() preferences!: Preferences;
|
||||
|
||||
get supporterBadge() {
|
||||
return this.owner !== undefined && this.preferences.bgs?.players?.[this.owner]?.pro
|
||||
? this.preferences.bgs.supporterBadge
|
||||
: undefined;
|
||||
}
|
||||
|
||||
powerPlantClicked?: PowerPlant;
|
||||
|
||||
// Ticks the live clock. Kept in this component rather than in Game so the
|
||||
|
|
@ -292,15 +313,15 @@ export default class PlayerBoard extends Vue {
|
|||
get canClickResources() {
|
||||
return (
|
||||
(this.player.availableMoves && this.player.availableMoves['DiscardResources']) ||
|
||||
this.player.resourcesUsed.some((r) => r == null)
|
||||
this.player.resourcesUsed.some(r => r == null)
|
||||
);
|
||||
}
|
||||
|
||||
clickResource(resourceType) {
|
||||
if (this.player.availableMoves && this.player.availableMoves['DiscardResources']) {
|
||||
this.$emit('discardResource', resourceType);
|
||||
} else if (this.player.resourcesUsed.some((r) => r == null)) {
|
||||
const index = this.player.resourcesUsed.findIndex((r) => r == null)!;
|
||||
} else if (this.player.resourcesUsed.some(r => r == null)) {
|
||||
const index = this.player.resourcesUsed.findIndex(r => r == null)!;
|
||||
this.player.resourcesUsed[index] = resourceType;
|
||||
|
||||
if (resourceType == 'coal') {
|
||||
|
|
@ -309,7 +330,7 @@ export default class PlayerBoard extends Vue {
|
|||
this.player.oilLeft--;
|
||||
}
|
||||
|
||||
if (!this.player.resourcesUsed.some((r) => r == null)) {
|
||||
if (!this.player.resourcesUsed.some(r => r == null)) {
|
||||
this.$emit('powerPlantClick', this.powerPlantClicked);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { ChatController, ChatMessage, chatSegments } from '@boardgamers/protocol/chat';
|
||||
import { mountChat } from '@boardgamers/protocol/chat/dom';
|
||||
import { attachChat, ViewerEmitter } from '@boardgamers/protocol/viewer';
|
||||
import { resolvePlayerColors, colorText } from './player-colors';
|
||||
import { playerColors } from 'powergrid-engine/src/gamestate';
|
||||
type ChatEmitter = Pick<ViewerEmitter<any, any>, 'on' | 'emit'>;
|
||||
export function mountGameChat(emitter: ViewerEmitter<any, any>, host: Element): () => void {
|
||||
|
|
@ -64,6 +65,7 @@ export function mountGameChat(emitter: ViewerEmitter<any, any>, host: Element):
|
|||
|
||||
`;
|
||||
slot.append(style);
|
||||
let colorPreferences: Parameters<typeof resolvePlayerColors>[2];
|
||||
let players: { id: number; name: string; color?: string; faction?: string }[] = [];
|
||||
let localPlayer: number | undefined;
|
||||
let chatVisible = false;
|
||||
|
|
@ -134,6 +136,14 @@ export function mountGameChat(emitter: ViewerEmitter<any, any>, host: Element):
|
|||
updateShortcut();
|
||||
},
|
||||
});
|
||||
// Keep the feed flexible while the composer stays at the bottom of the panel.
|
||||
const panel = slot.querySelector('.bgs-game-chat')!;
|
||||
const body = document.createElement('div');
|
||||
body.className = 'chat-body';
|
||||
for (const child of Array.from(panel.children)) {
|
||||
if (child.tagName !== 'SUMMARY') body.append(child);
|
||||
}
|
||||
panel.append(body);
|
||||
function renderAuthor(message: ChatMessage): Node {
|
||||
const author = document.createElement('strong');
|
||||
author.textContent = message.author || 'Game';
|
||||
|
|
@ -141,8 +151,9 @@ export function mountGameChat(emitter: ViewerEmitter<any, any>, host: Element):
|
|||
message.playerIndex ??
|
||||
(message.author === 'You' ? localPlayer : players.find((p) => p.name === message.author)?.id);
|
||||
if (index !== undefined && playerColors[index]) {
|
||||
author.style.backgroundColor = players.find((p) => p.id === index)?.color || playerColors[index];
|
||||
author.style.color = author.style.backgroundColor === 'brown' ? '#fff' : '#111';
|
||||
const color = resolvePlayerColors(playerColors, players, colorPreferences)[index];
|
||||
author.style.backgroundColor = color;
|
||||
author.style.color = colorText(color);
|
||||
}
|
||||
return author;
|
||||
}
|
||||
|
|
@ -162,6 +173,8 @@ export function mountGameChat(emitter: ViewerEmitter<any, any>, host: Element):
|
|||
const dispose = [
|
||||
detach,
|
||||
emitter.on('preferences', (preferences) => {
|
||||
colorPreferences = preferences;
|
||||
view.refresh();
|
||||
chatNotifications = preferences.chatNotifications !== false;
|
||||
analysis = preferences.analysis === true;
|
||||
slot.hidden = analysis;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ function launch(selector: string) {
|
|||
// from a non-reactive parent — plain-object mutations (the in-game sound/help
|
||||
// toggles, platform preference pushes) would only paint on the next re-render.
|
||||
preferences: Vue.observable({
|
||||
bgs: {},
|
||||
sound: true,
|
||||
colorBlind: false,
|
||||
disableHelp: false,
|
||||
|
|
@ -76,6 +77,7 @@ function launch(selector: string) {
|
|||
async onPreferences(data) {
|
||||
if (!(await localization.setLocale(data.locale))) return;
|
||||
Object.assign(params.preferences, data);
|
||||
params.preferences.bgs = (data.bgs ?? {}) as NonNullable<Preferences['bgs']>;
|
||||
app.$forceUpdate();
|
||||
},
|
||||
onAvatars(data) {
|
||||
|
|
|
|||
23
viewer/src/player-colors.ts
Normal file
23
viewer/src/player-colors.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
type ColorPreferences = { colorBlind?: boolean; bgs?: { playerColors?: unknown } };
|
||||
export function resolvePlayerColors(defaults: string[], players: { id: number; color?: string }[], preferences?: ColorPreferences): string[] {
|
||||
const colors = [...defaults];
|
||||
const preferred = preferences?.bgs?.playerColors;
|
||||
if (!preferences?.colorBlind && !players.some(p => p.color) && Array.isArray(preferred)) {
|
||||
preferred.slice(0, colors.length).forEach((color, i) => {
|
||||
if (typeof color === 'string' && /^#[a-f0-9]{6}$/i.test(color)) colors[i] = color;
|
||||
});
|
||||
}
|
||||
for (const player of players) if (player.color) colors[player.id] = player.color;
|
||||
return colors;
|
||||
}
|
||||
|
||||
export function colorText(color = ''): string {
|
||||
const names: Record<string, string> = { limegreen: '#32cd32', mediumorchid: '#ba55d3', red: '#ff0000', dodgerblue: '#1e90ff', yellow: '#ffff00', brown: '#a52a2a' };
|
||||
const hex = names[color] ?? color;
|
||||
if (!/^#[a-f0-9]{6}$/i.test(hex)) return '#111';
|
||||
const channels = [1, 3, 5].map(i => {
|
||||
const value = parseInt(hex.slice(i, i + 2), 16) / 255;
|
||||
return value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4;
|
||||
});
|
||||
return channels[0] * .2126 + channels[1] * .7152 + channels[2] * .0722 > .179 ? '#000' : '#fff';
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ export interface UIData {
|
|||
}
|
||||
|
||||
export type Preferences = {
|
||||
bgs?: { playerColors?: string[]; players?: { pro: boolean }[]; supporterBadge?: { url: string; label: string } };
|
||||
analysis?: boolean;
|
||||
sound: boolean;
|
||||
colorBlind: boolean;
|
||||
|
|
@ -51,5 +52,5 @@ export enum PieceType {
|
|||
Oil,
|
||||
Garbage,
|
||||
Uranium,
|
||||
Hybrid,
|
||||
Hybrid
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ module.exports = {
|
|||
.tap((options) => ({
|
||||
...options,
|
||||
configFile: join(__dirname, 'tsconfig.json'),
|
||||
...(process.env.NODE_ENV === 'test' ? { compilerOptions: { target: 'es2019' } } : {}),
|
||||
}));
|
||||
}
|
||||
// Webpack 4 predates package exports; resolve the published ESM entry points.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue