Files
blockly3d/webclient/src/model/worldFactory.ts
T
azykov@mail.ru 579fe36e6c layered three view
game object geometries layer
2026-06-19 20:54:27 +03:00

36 lines
1.0 KiB
TypeScript

import { type RuntimeWorld, type World } from "../types";
import { depopulateRuntimeWorld, populateRuntimeWorld } from "../utils/runtime";
import { DEFAULT_VOXEL_TYPES } from "./defaultVoxelTypes";
export class WorldFactory {
public static create(): RuntimeWorld {
return populateRuntimeWorld({
objectTypes: {},
voxelTypes: DEFAULT_VOXEL_TYPES,
initialScene: {
objects: {},
playerObjectId: undefined,
},
gameRules: {
gravity: true,
},
editorCamera: {
position: [0, 5, 10],
look: [0, 0, 0],
},
});
}
public static load(): RuntimeWorld | undefined {
const json = localStorage.getItem("world");
if (json) {
return populateRuntimeWorld(JSON.parse(json) as World);
}
}
public static save(world: RuntimeWorld): void {
localStorage.setItem("world", JSON.stringify(depopulateRuntimeWorld(world)));
}
}