35 lines
1015 B
TypeScript
35 lines
1015 B
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: {},
|
|
},
|
|
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)));
|
|
}
|
|
}
|