Format victory points without Pyramid floating-point tails
This commit is contained in:
parent
bfb1e5b755
commit
6088dc4e0e
7 changed files with 52 additions and 9 deletions
|
|
@ -35,3 +35,5 @@ The viewer update following 0.4.38 makes home-at-bottom rotation an account pref
|
|||
The next viewer update makes barbarian unit badges follow the unit-badge preference in color-blind mode. Horned helmets on the models and barbarian city flags remain visible when badges are disabled. The engine is unchanged.
|
||||
|
||||
The following viewer update skips empty end-turn, raze-city and other phase transitions in visual replay and “Since your last turn”. Turn boundaries remain available to select the recap range; actual rewards, card draws, combat and board changes remain replay steps. City dock tiles use less padding and smaller decorative icons. The engine is unchanged.
|
||||
|
||||
The next viewer update formats victory points consistently to one decimal at most, preserving Great Pyramid’s extra 0.1 without floating-point tails in player cards, score breakdowns or wonder details. The engine is unchanged.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { formatPoints } from './score';
|
||||
import CollectionBonusHints from './CollectionBonusHints.svelte';
|
||||
import BarbarianIcon from './BarbarianIcon.svelte';
|
||||
import PlaybackPanel from './PlaybackPanel.svelte';
|
||||
|
|
@ -772,7 +773,7 @@
|
|||
class:active={!!turnLabel}
|
||||
style={`--player:${playerColor(player.index, $session.colorBlind, $session.playerColors)}`}
|
||||
title={`Inspect ${player.civilization} (${player.index === $session.seat ? 'You' : player.name}): advances and victory points`}
|
||||
aria-label={`${player.civilization}: ${player.score} victory points. ${player.index === $session.seat ? 'You' : player.name}.${order ? ` Turn order ${order}.` : ''}${turnLabel ? ` ${turnLabel}.` : ''}${progressLabel ? ` ${progressLabel}.` : ''} View resources, advances and scores`}
|
||||
aria-label={`${player.civilization}: ${formatPoints(player.score)} victory points. ${player.index === $session.seat ? 'You' : player.name}.${order ? ` Turn order ${order}.` : ''}${turnLabel ? ` ${turnLabel}.` : ''}${progressLabel ? ` ${progressLabel}.` : ''} View resources, advances and scores`}
|
||||
onclick={() => controller.patch({ scorePlayer: player.index })}
|
||||
onmouseenter={(e) => {
|
||||
const r = e.currentTarget.getBoundingClientRect();
|
||||
|
|
@ -825,7 +826,7 @@
|
|||
title="Army includes leaders and embarked troops; settlers are separate"
|
||||
><Swords size={13} />{forces.army}<Ship size={13} />{forces.ships}</span
|
||||
>{/if}</span
|
||||
><span class="player-score">{player.score}<Trophy size={10} /></span>
|
||||
><span class="player-score">{formatPoints(player.score)}<Trophy size={10} /></span>
|
||||
</button>{/each}
|
||||
</div>
|
||||
{#if !$session.game}<div class="map-loading">
|
||||
|
|
@ -1284,7 +1285,7 @@
|
|||
disabled={$session.pending}
|
||||
onclick={() => controller.submit(card.action)}
|
||||
>
|
||||
Claim {objectiveDecision.points} points <Check size={17} />
|
||||
Claim {formatPoints(objectiveDecision.points)} points <Check size={17} />
|
||||
</button>
|
||||
</div>
|
||||
{/each}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { formatPoints } from './score';
|
||||
import { Landmark, Trophy, X } from 'lucide-svelte';
|
||||
import { wonderIcons } from './wonder-icons';
|
||||
import { wonderName } from './wonder-names';
|
||||
|
|
@ -85,7 +86,7 @@
|
|||
</header>
|
||||
<p><ResourceText text={effect} /></p>
|
||||
{#if wonder}<small class="built-wonder-points"
|
||||
><Trophy size={14} />{Math.round(wonder.builtPoints * 10) / 10} VP for building · {wonder.ownedPoints} VP
|
||||
><Trophy size={14} />{formatPoints(wonder.builtPoints)} VP for building · {formatPoints(wonder.ownedPoints)} VP
|
||||
for owning</small
|
||||
>{/if}
|
||||
</section>{/if}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { formatPoints } from './score';
|
||||
import {
|
||||
Landmark,
|
||||
GraduationCap,
|
||||
|
|
@ -141,7 +142,7 @@
|
|||
</nav>
|
||||
{#if tab === 'score'}
|
||||
<div class="score-summary">
|
||||
<span><Trophy size={22} /> Total</span><strong>{player.score}<small> VP</small></strong>
|
||||
<span><Trophy size={22} /> Total</span><strong>{formatPoints(player.score)}<small> VP</small></strong>
|
||||
</div>
|
||||
<div class="score-breakdown">
|
||||
{#each player.scoreParts as part}
|
||||
|
|
@ -167,7 +168,7 @@
|
|||
{:else}<strong>{part.name}</strong>{/if}
|
||||
<p>{category?.description}</p>
|
||||
</div>
|
||||
<b>{part.points}</b>
|
||||
<b>{formatPoints(part.points)}</b>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
|
@ -181,7 +182,7 @@
|
|||
aria-label={objective.name}
|
||||
>
|
||||
<header>
|
||||
<Target size={19} /><strong>{objective.name}</strong><span>{objective.points} VP</span>
|
||||
<Target size={19} /><strong>{objective.name}</strong><span>{formatPoints(objective.points)} VP</span>
|
||||
</header>
|
||||
<p><ResourceText text={objective.description} /></p>
|
||||
<small>Completed</small>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { formatPoints } from './score';
|
||||
import { Landmark, GraduationCap, Check, Trophy } from 'lucide-svelte';
|
||||
import { wonderIcons } from './wonder-icons';
|
||||
import ResourceAmount from './ResourceAmount.svelte';
|
||||
|
|
@ -23,8 +24,8 @@
|
|||
<div class="wonder-cost"><span>Base construction cost</span><ResourceAmount pile={card.cost} /></div>
|
||||
<div class="wonder-points">
|
||||
<Trophy size={16} /><span
|
||||
><strong>{Math.round(card.builtPoints * 10) / 10}</strong> VP for building ·
|
||||
<strong>{card.ownedPoints}</strong> VP for owning</span
|
||||
><strong>{formatPoints(card.builtPoints)}</strong> VP for building ·
|
||||
<strong>{formatPoints(card.ownedPoints)}</strong> VP for owning</span
|
||||
>
|
||||
</div>
|
||||
</article>
|
||||
|
|
|
|||
33
web-client/src/score.test.ts
Normal file
33
web-client/src/score.test.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRequire } from 'node:module';
|
||||
import { formatPoints } from './score.ts';
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
|
||||
test('victory points hide floating-point tails without losing Pyramid tenths', () => {
|
||||
for (const [raw, displayed] of [
|
||||
[41.099998474121094, '41.1'],
|
||||
[5.099999904632568, '5.1'],
|
||||
[41.599998474121094, '41.6'],
|
||||
[8.5, '8.5'],
|
||||
[0, '0'],
|
||||
[42, '42'],
|
||||
] as const) {
|
||||
assert.equal(formatPoints(raw), displayed);
|
||||
}
|
||||
});
|
||||
|
||||
test('building the Great Pyramid adds 5.1 displayed points in public scores', async () => {
|
||||
const game = JSON.parse(await engine.init(2, [], {}, 'pyramid-score', {}));
|
||||
const scores = (state: unknown) =>
|
||||
JSON.parse(engine.webView(engine.stripSecret(JSON.stringify(state), 0), 0)).players[0];
|
||||
const before = scores(game);
|
||||
game.players[0].wonders_built = ['Pyramids'];
|
||||
const after = scores(game);
|
||||
assert.equal(formatPoints(after.score - before.score), '5.1');
|
||||
assert.equal(formatPoints(after.score), formatPoints(before.score + 5.1));
|
||||
const wonderPoints = after.scoreParts.find(
|
||||
(part: { points: number }, index: number) => part.points !== before.scoreParts[index].points,
|
||||
);
|
||||
assert.equal(formatPoints(wonderPoints.points), '5.1');
|
||||
});
|
||||
4
web-client/src/score.ts
Normal file
4
web-client/src/score.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/** Victory points use whole, half and tenth points; hide f32 serialization noise. */
|
||||
export function formatPoints(points: number): string {
|
||||
return Number(points.toFixed(1)).toString();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue