v1.3.0: per-player money & reputation in engine + actions (ISS-110)
CI / build + unit + e2e (pull_request) Successful in 13m20s
CI / build + unit + e2e (pull_request) Successful in 13m20s
This commit is contained in:
+2
-1
@@ -411,7 +411,8 @@ export async function performAction(req: Request, fn: (inst: GameDb, playerId: s
|
||||
if (!auth.ok) return auth.response;
|
||||
try {
|
||||
await runAction((inst) => fn(inst, auth.player.id));
|
||||
return Response.json(await getStateSnapshot());
|
||||
// v1.3.0 (ISS-110): the response snapshot carries the ACTING player's economy in `account`.
|
||||
return Response.json(await getStateSnapshot(auth.player.id));
|
||||
} catch (err) {
|
||||
if (err instanceof GameActionError) {
|
||||
return Response.json({ error: err.message }, { status: err.status });
|
||||
|
||||
+6
-5
@@ -2,7 +2,7 @@ import { loadAirportsGeoJson } from '@/lib/airports';
|
||||
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
||||
import { weatherFor } from '@/lib/weather';
|
||||
import { getGameDb } from '@/lib/db/client';
|
||||
import { getLocalPlayer } from '@/lib/db/localPlayer';
|
||||
import { getPlayer } from '@/lib/db/localPlayer';
|
||||
import * as schema from '@/lib/db/schema';
|
||||
import { catalogEntries, FUEL_PRICE_PER_L, PLANE_TYPES, SELL_FRACTION, type CatalogEntry } from './catalog';
|
||||
import { fuelAtWeighted, progressAt, positionAt, windBurnFactor } from '@/lib/sim/movement';
|
||||
@@ -114,16 +114,17 @@ export function sseFrame(snapshot: StateSnapshot): StateSnapshot {
|
||||
return { ...snapshot, packages: snapshot.packages.filter((p) => (SSE_PACKAGE_STATUSES as readonly string[]).includes(p.status)) };
|
||||
}
|
||||
|
||||
export async function getStateSnapshot(): Promise<StateSnapshot> {
|
||||
// v1.3.0 (ISS-110): the snapshot's `account` field is the ACTING SESSION player's row — same
|
||||
// shape as before ({cash, reputation}), sourced per-player. Callers without a session context
|
||||
// (the shared SSE broadcast) pass LOCAL_PLAYER.id until per-player frames land (#112).
|
||||
export async function getStateSnapshot(playerId: string): Promise<StateSnapshot> {
|
||||
const inst = await getGameDb();
|
||||
const { db } = inst;
|
||||
// NOTE: use plain select(), not the relational db.query.* API — in drizzle-orm
|
||||
// 0.45.x the sql-js driver drops the result mapper for relational queries and
|
||||
// returns raw rows keyed by SQL column names (snake_case, no type decoding).
|
||||
// v1.0.0 (ISS-105): the snapshot's `account` field is now the local player row — same shape,
|
||||
// resolved through the temporary single-player helper until multiplayer lands.
|
||||
const [player, simRows, planeRows, packageRows] = await Promise.all([
|
||||
getLocalPlayer(inst),
|
||||
getPlayer(inst, playerId),
|
||||
db.select().from(schema.simState),
|
||||
db.select().from(schema.planes),
|
||||
db.select().from(schema.packages),
|
||||
|
||||
Reference in New Issue
Block a user