From 35d77efc4c544a984fcbe2b7025ebea042bdeef2 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 28 Mar 2021 17:29:48 -0500 Subject: [PATCH] refactor: alpha hmr --- packages/universe/src/server/gen/alpha.js | 3 +++ packages/universe/src/server/index.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/universe/src/server/gen/alpha.js b/packages/universe/src/server/gen/alpha.js index 7876557..c567732 100644 --- a/packages/universe/src/server/gen/alpha.js +++ b/packages/universe/src/server/gen/alpha.js @@ -58,6 +58,9 @@ export default async (room, latus) => { [0, 0, w, h], Plains.children[1].matrix, ); + if (Object.keys(room.layer(3).entities).length > 0) { + return; + } for (let y = 0; y < 64; ++y) { for (let x = 0; x < 64; ++x) { let v = noise(Vector.scale([x, y], 5), seed); diff --git a/packages/universe/src/server/index.js b/packages/universe/src/server/index.js index 4fe7e19..c4a6ddc 100644 --- a/packages/universe/src/server/index.js +++ b/packages/universe/src/server/index.js @@ -7,6 +7,11 @@ import UniverseInput from './packets/decorators/universe-input'; export default { hooks: { + '@latus/core/hmr': (path, latus) => { + if ('@humus/universe/server' === path) { + alpha(latus.get('%universe').room('players/cha0s/index.room.json'), latus); + } + }, '@latus/core/server/up': async (latus) => { const {root} = latus.get('@humus/universe'); const {running} = latus.get('@humus/universe/server'); @@ -20,7 +25,6 @@ export default { try { const {Universe} = latus.get('%resources'); const universe = await Universe.load({extends: `/universe/${running}/index.universe.json`}); - // alpha gen alpha(universe.room('players/cha0s/index.room.json'), latus); latus.set('%universe', universe); universe.start();