diff --git a/website/node/game-native-state.mjs b/website/node/game-native-state.mjs index 6e5c779f..de63f4b9 100644 --- a/website/node/game-native-state.mjs +++ b/website/node/game-native-state.mjs @@ -17,6 +17,7 @@ import {projectMilitaryClans} from './war-military-projection.mjs'; const digest=value=>createHash('sha256').update(JSON.stringify(value)).digest('hex'); const bounded=(rows,max)=>{if(rows.length>max)throw Error('Native inventory exceeds supported batch');return rows;}; export function nativeClanControllerIds(deed,authority){return [...new Set([deed.owner?.id,...(deed.root===deed.clan.id?[deed.heir?.id]:[]),...(authority.parentControllerIds||[])].filter(Boolean))].sort();} +export function nativeHomeBlock(snapshot,revision){return snapshot?.source==='minecraft'&&snapshot.homeBlock?{...snapshot.homeBlock,revision:Number(revision),source:'minecraft'}:null;} // A consumer view of current deeds/keys, not a new organisation or permission store. // Initial creation and later edits/deletions use this same projection. export async function readGameNativeState(db,{clock=Date.now}={}){ @@ -74,7 +75,7 @@ export async function readGameNativeState(db,{clock=Date.now}={}){ const snapshot=claim?JSON.parse(claim.snapshot_json):null; record.claimRevision=Number(claim?.revision||0); record.homeServer??=nativeServer(snapshot?.homeBlock?.worldName); - record.homeBlock=snapshot?.source==='minecraft'?{...snapshot.homeBlock,revision:Number(claim.revision),source:'minecraft'}:null; + record.homeBlock=nativeHomeBlock(snapshot,claim?.revision); record.claimTier=snapshot?.tier||null;record.claimedChunks=registeredClaimChunks(snapshot);record.usedChunks=record.claimedChunks.length; const relocation=snapshot?.relocation; if(relocation&&['cleanup','ready'].includes(relocation.phase)){ diff --git a/website/tests/game-native-state.test.mjs b/website/tests/game-native-state.test.mjs index 3b8b90a1..ddce8aff 100644 --- a/website/tests/game-native-state.test.mjs +++ b/website/tests/game-native-state.test.mjs @@ -1,6 +1,12 @@ import test from 'node:test';import assert from 'node:assert/strict'; -import {createGameNativeStateAPI,nativeClanControllerIds} from '../node/game-native-state.mjs'; +import {createGameNativeStateAPI,nativeClanControllerIds,nativeHomeBlock} from '../node/game-native-state.mjs'; import {fixture} from './rebellion-fixture.mjs'; +test('a released marker projects as null so native menus expose registration instead of a malformed Home Block',()=>{ + assert.equal(nativeHomeBlock({source:'minecraft',homeBlock:null},5),null); + const home={id:'home',worldName:'arrakis',position:{x:1,y:70,z:2}}; + assert.deepEqual(nativeHomeBlock({source:'minecraft',homeBlock:home},6),{...home,revision:6,source:'minecraft'}); + assert.equal(nativeHomeBlock({source:'web-development',homeBlock:home},6),null); +}); test('native build controllers follow the current mother deed without changing the child roster',()=>{ const child={clan:{id:'child'},root:'mother',owner:{id:'child-owner'},heir:{id:'child-heir'}}; assert.deepEqual(nativeClanControllerIds(child,{parentControllerIds:['mother-owner','mother-heir','mother-owner']}),['child-owner','mother-heir','mother-owner']);