24 lines
1.0 KiB
TypeScript
24 lines
1.0 KiB
TypeScript
import { eq } from 'drizzle-orm';
|
|
import type { GameDb } from './client';
|
|
import * as schema from './schema';
|
|
|
|
// v1.0.0 (ISS-105): TEMPORARY single-player economy access — resolves the local player row so all
|
|
// pre-multiplayer code keeps working while `account` is replaced by `players`. A later step
|
|
// parameterizes these by playerId for real multiplayer; until then every read/write of the
|
|
// singleton economy goes through this file and nowhere else.
|
|
|
|
export const LOCAL_PLAYER = { id: 'local', provider: 'local', username: 'kamilkrzywda' } as const;
|
|
|
|
export async function getLocalPlayer(inst: GameDb): Promise<schema.PlayerRow> {
|
|
const [row] = await inst.db.select().from(schema.players).where(eq(schema.players.id, LOCAL_PLAYER.id));
|
|
if (!row) throw new Error('local player row missing');
|
|
return row;
|
|
}
|
|
|
|
export async function updateLocalPlayerEconomy(
|
|
inst: GameDb,
|
|
patch: { cash?: number; reputation?: number },
|
|
): Promise<void> {
|
|
await inst.db.update(schema.players).set(patch).where(eq(schema.players.id, LOCAL_PLAYER.id));
|
|
}
|