Choose port construction location directly on the map
This commit is contained in:
parent
e6a05bc15e
commit
1a94cc4f0d
10 changed files with 133 additions and 8 deletions
|
|
@ -239,3 +239,8 @@ Clicking a friendly fleet now immediately boards the selected land group across
|
|||
Sea spaces occupied by or adjacent to pirates now have persistent dashed red borders with a pale outline in both 3D and Strategy views. Hover and tile details explain that collection and Trade Routes are blocked. The guide follows live and replayed pirate positions, excludes land and unexplored spaces, and ignores escorted Pirate Allies controlled by Carthage. Thumbnail exports omit the overlay. All 16 locales include the explanation; the rules engine is unchanged. Verified with 721 tests, locale validation, type checks, and light/dark browser previews.
|
||||
|
||||
Viewer 0.1.77 lowers the pirate blockade border to the sea-tile surface, with minimal clearance to prevent flickering. Engine 0.4.68 is unchanged.
|
||||
|
||||
|
||||
# Viewer 0.1.78 / engine unchanged (0.4.68)
|
||||
|
||||
When Port has multiple legal sea spaces, city construction offers Choose port location on map. The dialog closes, eligible sea spaces are highlighted, and clicking one constructs the port with the selected payment. Cancel returns to city management without submitting; changed game states discard stale placement choices. Single-location ports retain direct construction. Verified controller payment/cancel/state-change checks and desktop/mobile browser map clicks.
|
||||
|
|
|
|||
4
web-client/package-lock.json
generated
4
web-client/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.77",
|
||||
"version": "0.1.78",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.77",
|
||||
"version": "0.1.78",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.77",
|
||||
"version": "0.1.78",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
53
web-client/scripts/port-placement-smoke.mjs
Normal file
53
web-client/scripts/port-placement-smoke.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
import { chromium } from 'playwright';
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
const npcs = JSON.parse(await engine.init(2, [], {}, 'abilities-ui', {})).players.slice(2);
|
||||
async function fixture(name) {
|
||||
const game = JSON.parse(
|
||||
await readFile(new URL(`../../server/tests/test_games/${name}.json`, import.meta.url), 'utf8'),
|
||||
);
|
||||
for (const npc of npcs)
|
||||
if (!game.players.some((p) => p.civilization === npc.civilization))
|
||||
game.players.push({ ...npc, id: game.players.length });
|
||||
return game;
|
||||
}
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--use-gl=angle', '--use-angle=swiftshader'],
|
||||
});
|
||||
try {
|
||||
for (const [width,height] of [[1400,900],[390,740]]) {
|
||||
const state=await fixture('base/construct_port');
|
||||
const page=await browser.newPage({viewport:{width,height}}),errors=[];
|
||||
page.on('pageerror',e=>errors.push(e.message));
|
||||
await page.route('**/*',async route=>{
|
||||
const path=new URL(route.request().url()).pathname;
|
||||
if(path==='/') return route.fulfill({contentType:'text/html',body:'<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div><script src="/viewer.js"></script>'});
|
||||
if(!['/viewer.js','/server_bg.wasm'].includes(path)) return route.abort();
|
||||
return route.fulfill({contentType:path.endsWith('.wasm')?'application/wasm':'text/javascript',body:await readFile(new URL('../dist'+path,import.meta.url))});
|
||||
});
|
||||
await page.goto('http://clash.test');
|
||||
await page.evaluate(state=>{window.host=clash3d.launch('#app');window.sent=[];host.on('move',a=>sent.push(a));host.emit('player',{index:0});host.emit('theme',{dark:true});host.emit('preferences',{sound:false});host.emit('state',state)},engine.stripSecret(JSON.stringify(state),0));
|
||||
await page.getByRole('button',{name:'Manage cities',exact:true}).click();
|
||||
await page.getByRole('navigation',{name:'Choose city'}).getByRole('button',{name:/C2/}).click();
|
||||
await page.locator('.building-grid button').filter({hasText:'Port'}).click();
|
||||
await page.getByRole('button',{name:'Choose port location on map',exact:true}).click();
|
||||
await page.getByRole('region',{name:'Choose port location'}).waitFor();
|
||||
assert.equal(await page.locator('.city-dialog').count(),0);
|
||||
await page.screenshot({path:`/tmp/clash-port-map-${width}.png`});
|
||||
const target=page.locator('.map-hit-target[data-position="D2"]');
|
||||
await target.waitFor({state:'attached'});
|
||||
await page.waitForTimeout(400);
|
||||
const box=await target.boundingBox();assert(box);
|
||||
await page.mouse.click(box.x+box.width/2,box.y+box.height/2);
|
||||
await page.waitForFunction(()=>sent.length===1);
|
||||
const action=await page.evaluate(()=>sent[0]);
|
||||
const after=JSON.parse(engine.tryMove(JSON.stringify(state),typeof action==='string'?action:JSON.stringify(action),0));
|
||||
assert.equal(after.players[0].cities.find(c=>c.position==='C2').port_position,'D2');
|
||||
assert.deepEqual(errors,[]);
|
||||
await page.close();
|
||||
}
|
||||
console.log('Port placement desktop/mobile smoke passed');
|
||||
} finally {await browser.close();}
|
||||
|
|
@ -1436,6 +1436,15 @@
|
|||
><Shapes size={19} /></button
|
||||
>
|
||||
</nav>
|
||||
{#if $session.mode === 'port' && $session.portPlacement}
|
||||
<section class="action-panel floating-panel" aria-label="Choose port location">
|
||||
<button class="icon-button close-action" aria-label="Cancel port placement"
|
||||
onclick={() => controller.patch({mode:'city'})}><X size={18} /></button>
|
||||
<h2>Build Port · {$session.portPlacement.city}</h2>
|
||||
<p>Choose a highlighted sea space on the map.</p>
|
||||
<ResourceAmount pile={$session.portPlacement.payment} />
|
||||
</section>
|
||||
{/if}
|
||||
{#if choiceDecision || objectiveDecision || (!$session.playback && $session.game && !$session.view?.supportedPhase && $session.seat === $session.view?.activePlayer) || $session.mode === 'collect' || confirmEnd || ($session.error && $session.mode === 'overview')}
|
||||
<section
|
||||
class="action-panel floating-panel"
|
||||
|
|
|
|||
|
|
@ -390,12 +390,15 @@
|
|||
label={`Payment for ${selected.name}`}
|
||||
/>{/if}
|
||||
<div class="port-choices">
|
||||
{#each selected.choices as choice}<button
|
||||
{#if selected.name === 'Port' && selected.choices.length > 1}
|
||||
<button class="primary" disabled={!!$session.playback || $session.pending}
|
||||
onclick={() => controller.choosePortOnMap(buildPayment ?? selected!.payment)}>Choose port location on map</button>
|
||||
{:else}{#each selected.choices as choice}<button
|
||||
class="primary"
|
||||
disabled={!!$session.playback || $session.pending}
|
||||
onclick={() => submitBuild(choice.action)}
|
||||
>Build {selected.name}{choice.position ? ` at ${choice.position}` : ''}</button
|
||||
>{/each}
|
||||
>{/each}{/if}
|
||||
</div>
|
||||
</footer>{/if}
|
||||
{#if tab === 'recruit'}<footer class="city-confirm recruit-confirm">
|
||||
|
|
|
|||
|
|
@ -1041,11 +1041,11 @@ export class World {
|
|||
this.explorationLabel.hidden = !this.explorationPositions.length;
|
||||
this.explorationLabel.dataset.positions = this.explorationPositions.join(' ');
|
||||
// City abilities and cultural influence both choose highlighted pieces on the map.
|
||||
const abilityPositions = influence
|
||||
const abilityPositions = s.portPlacement ? s.portPlacement.choices.map(c => c.position) : influence
|
||||
? influence.positions
|
||||
: [...new Set(ability?.offers.map((offer) => offer.position!) ?? [])];
|
||||
const abilitySelected = influence ? influence.selected : s.abilityCity ? [s.abilityCity] : [];
|
||||
const choosingCity = !!ability || !!influence;
|
||||
const choosingCity = !!ability || !!influence || !!s.portPlacement;
|
||||
this.interactionPositions = exploration
|
||||
? this.explorationPositions
|
||||
: s.view?.decision?.tacticsSelection && combat
|
||||
|
|
|
|||
|
|
@ -2601,3 +2601,35 @@ for (const predictions of [true, false]) test(`boarding across two ships spends
|
|||
assert.equal(after.players[0].units.filter((u:any) => u.unit_type==='Ship').flatMap((u:any)=>u.carried_units??[]).length,3);
|
||||
} finally {app.close();}
|
||||
});
|
||||
|
||||
|
||||
test('port construction chooses a legal sea hex on the map and preserves payment', async () => {
|
||||
const app=paymentController(), c=app.controller;
|
||||
try {
|
||||
const raw=fixture('base/construct_port');
|
||||
c.setPlayer(0); await c.load(engine.stripSecret(raw,0));
|
||||
c.selectCity('C2'); c.patch({mode:'city',cityTab:'build'});
|
||||
c.choosePortOnMap({gold:3});
|
||||
assert.equal(app.session().mode,'port');
|
||||
assert.deepEqual(app.session().portPlacement!.choices.map(c=>c.position).sort(),['C3','D2']);
|
||||
c.selectTile('A1'); assert.equal(app.sent.length,0);
|
||||
c.selectTile('D2'); assert.equal(app.sent.length,1);
|
||||
const after=JSON.parse(engine.tryMove(raw,app.sent[0],0));
|
||||
assert.equal(after.players[0].cities.find((c:any)=>c.position==='C2').port_position,'D2');
|
||||
assert.deepEqual(JSON.parse(app.sent[0]).Playing.Construct.payment,{gold:3});
|
||||
assert.equal(app.session().portPlacement,undefined);
|
||||
} finally {app.close();}
|
||||
});
|
||||
|
||||
test('port map choice cancels without building and closes on changed game state', async () => {
|
||||
const app=paymentController(),c=app.controller;
|
||||
try {
|
||||
const raw=fixture('base/construct_port'); c.setPlayer(0); await c.load(engine.stripSecret(raw,0));
|
||||
c.selectCity('C2');c.choosePortOnMap({gold:3});c.patch({mode:'city'});
|
||||
assert.equal(app.session().portPlacement,undefined);assert.equal(app.sent.length,0);
|
||||
c.choosePortOnMap({gold:3});
|
||||
const changed=JSON.parse(raw);changed.actions_left=1;
|
||||
await c.load(engine.stripSecret(JSON.stringify(changed),0));
|
||||
assert.equal(app.session().portPlacement,undefined);
|
||||
} finally {app.close();}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ export class Controller {
|
|||
patch(patch: Partial<Session>) {
|
||||
this.session.update((s) => {
|
||||
const next = { ...s, ...patch };
|
||||
if (next.mode !== 'port') next.portPlacement = undefined;
|
||||
if ('scorePlayer' in patch && patch.scorePlayer !== s.scorePlayer) {
|
||||
next.scoreTab = patch.scoreTab ?? 'score';
|
||||
next.scoreObjective = patch.scoreObjective ?? null;
|
||||
|
|
@ -520,6 +521,7 @@ export class Controller {
|
|||
movementEnded ||
|
||||
turnChanged ||
|
||||
(old.mode === 'settlers' && resetMovement) ||
|
||||
(old.mode === 'port' && changed) ||
|
||||
view.decision ||
|
||||
view.objectiveDecision ||
|
||||
view.choiceDecision ||
|
||||
|
|
@ -980,9 +982,29 @@ export class Controller {
|
|||
recruitPreview: null,
|
||||
});
|
||||
}
|
||||
choosePortOnMap(payment: Pile) {
|
||||
const s = get(this.session);
|
||||
if (s.pending || s.playback || !s.city) return;
|
||||
const port = s.view?.cityActions.find(c => c.position === s.city)?.buildings.find(b => b.name === 'Port');
|
||||
const choices = port?.choices.flatMap(c => {
|
||||
if (!c.position) return [];
|
||||
const action = structuredClone(c.action) as {Playing: {Construct: {payment: Pile}}};
|
||||
action.Playing.Construct.payment = {...payment};
|
||||
return [{position:c.position, action}];
|
||||
}) ?? [];
|
||||
if (choices.length < 2) return;
|
||||
this.closeActivity();
|
||||
this.patch({mode:'port',portPlacement:{city:s.city,payment:{...payment},choices},tilePanel:false,seaRoutes:false,tradeRoutes:false,pirateSpawns:false,error:''});
|
||||
}
|
||||
selectTile(position: string, pick: MapPick = { kind: 'tile' }) {
|
||||
if (get(this.session).playback) return;
|
||||
const s = get(this.session);
|
||||
if (s.mode === 'port') {
|
||||
if (s.pending) return;
|
||||
const choice = s.portPlacement?.choices.find(c => c.position === position);
|
||||
if (choice) this.submit(choice.action);
|
||||
return;
|
||||
}
|
||||
if (mapDecisionOptions(s.view?.decision).length) {
|
||||
const index = mapDecisionIndex(s.view!.decision!, position, pick);
|
||||
// Pieces: open the clicked hex, and choose the clicked unit/building (or a lone candidate).
|
||||
|
|
|
|||
|
|
@ -524,6 +524,7 @@ export interface EventInfo {
|
|||
targets: ('all' | 'active' | 'selected')[];
|
||||
}
|
||||
export interface Session {
|
||||
portPlacement?: {city: string; payment: Pile; choices: {position: string; action: Move}[]};
|
||||
landingTargets?: string[];
|
||||
disembarkCarriers?: number[];
|
||||
analysis?: boolean;
|
||||
|
|
@ -570,7 +571,7 @@ export interface Session {
|
|||
seat?: number;
|
||||
city: string | null;
|
||||
focus: string | null;
|
||||
mode: 'overview' | 'collect' | 'research' | 'city' | 'settlers' | 'happiness';
|
||||
mode: 'port' | 'overview' | 'collect' | 'research' | 'city' | 'settlers' | 'happiness';
|
||||
selectedSettler: number | null;
|
||||
destination: string | null;
|
||||
explorationRotation: number | null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue