Split inventory definition generation by category and select chest contents deterministically. Move squadron queries, membership, and lifecycle into focused modules and enforce role permissions. Serve store and marketplace pages as static files with shared web helpers. Share profile field readers and keep response encoding in the protocol modules. Restrict cloud settings to registered blocks. Type checking and the save CLI ran successfully. In-game acceptance is pending.
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
/**
|
|
* Shared typed field readers and mutators for profile DataBlocks.
|
|
*/
|
|
import { findParam, type BlkBlock } from '@wto/blk';
|
|
|
|
export const EMPTY_BLK: BlkBlock = { name: '', params: [], blocks: [] };
|
|
|
|
export function intField(block: BlkBlock | undefined, name: string, fallback = 0): number {
|
|
const value = block && findParam(block, name)?.value;
|
|
if (value?.type === 'int') return value.value;
|
|
if (value?.type === 'int64') return Number(value.value);
|
|
return fallback;
|
|
}
|
|
|
|
export function int64Field(block: BlkBlock | undefined, name: string, fallback = 0n): bigint {
|
|
const value = block && findParam(block, name)?.value;
|
|
if (value?.type === 'int64') return value.value;
|
|
if (value?.type === 'int') return BigInt(value.value);
|
|
return fallback;
|
|
}
|
|
|
|
export function stringField(block: BlkBlock | undefined, name: string, fallback = ''): string {
|
|
const value = block && findParam(block, name)?.value;
|
|
return value?.type === 'string' ? value.value : fallback;
|
|
}
|
|
|
|
export function removeParam(block: BlkBlock, name: string): void {
|
|
block.params = block.params.filter((param) => param.name !== name);
|
|
}
|