protected updateSelf(props: Props) {
this.state.tick++;
const activeIntent = props.gameState.intent.activeIntent;
let deltaX = 0;
let deltaY = 0;
const unit = 5 * props.delta;
// if we want to pan [the hud] west (i.e. the left key was pressed), action stage needs to move east
if (activeIntent[IntentName.PAN_WEST]) deltaX += unit;
if (activeIntent[IntentName.PAN_EAST]) deltaX += -unit;
// if we want to pan south (i.e. the down key was pressed), action stage needs to move north to give the impression
// the hud is moving south. note that north is negative y direction since top left is 0,0
if (activeIntent[IntentName.PAN_SOUTH]) deltaY += -unit;
if (activeIntent[IntentName.PAN_NORTH]) deltaY += unit;
this.actionStage.x += deltaX;
this.actionStage.y += deltaY;
if (props.gameState.intent.newIntent[IntentName.TRAVEL_IN]) {
this.state.playerCurrentZ--;
// scale by a factor of 9
this.actionStage.x *= ChunkGenConstants.CHUNK_DIM;
this.actionStage.y *= ChunkGenConstants.CHUNK_DIM;
console.log({ currentZ: this.state.playerCurrentZ });
}
if (props.gameState.intent.newIntent[IntentName.TRAVEL_OUT]) {
this.state.playerCurrentZ++;
this.actionStage.x /= ChunkGenConstants.CHUNK_DIM;
this.actionStage.y /= ChunkGenConstants.CHUNK_DIM;
console.log({ currentZ: this.state.playerCurrentZ });
}
}
protected renderSelf(props: Props) {
this.backdrop.width = props.appSize.x;
this.backdrop.height = props.appSize.y;
}
protected didMount() {
const { updaters } = this._staleProps;
this.backdrop.addListener('pointerdown', (event) => {
updaters.playerUI.selectedPointNode.enqueueUpdate((prev, whole) => {
return undefined;
})
});
}
protected didUpdate() {
const { updaters } = this._staleProps;
// if we find ourselves a little idle, start pregenerating other layers
if (this.state.tick > 60 && !this._staleProps.gameState.worldGen.zLevels[-1]) {
updaters.worldGen.zLevels.enqueueUpdate((prev, prevGameState) => {
if (!prev[-1]) {
prev[-1] = new ZLevelGenFactory({}).create({ seed: prevGameState.worldGen.seed, z: -1 });
return {...prev};
} else {
return prev;
}
})
}
if (this.state.tick > 120 && !this._staleProps.gameState.worldGen.zLevels[1]) {
updaters.worldGen.zLevels.enqueueUpdate((prev, prevGameState) => {
if (!prev[1]) {
prev[1] = new ZLevelGenFactory({}).create({ seed: prevGameState.worldGen.seed, z: 1 });
return {...prev};
} else {
return prev;
}
})
}
}