41 lines
1019 B
TypeScript
41 lines
1019 B
TypeScript
import type { World } from "../types";
|
|
import { DEFAULT_VOXEL_TYPES } from "./defaultVoxelTypes";
|
|
|
|
export class WorldFactory {
|
|
|
|
public static create(): World {
|
|
return {
|
|
objectTypes: {},
|
|
voxelTypes: DEFAULT_VOXEL_TYPES,
|
|
initialScene: {
|
|
character: {
|
|
position: [0, 0, 0],
|
|
look: [0, 0, 0],
|
|
},
|
|
objects: {},
|
|
},
|
|
state: {
|
|
playing: false,
|
|
},
|
|
gameRules: {
|
|
gravity: true,
|
|
},
|
|
editorCamera: {
|
|
position: [0, 5, 10],
|
|
look: [0, 0, 0],
|
|
},
|
|
}
|
|
}
|
|
|
|
public static load(): World | undefined {
|
|
const json = localStorage.getItem("world");
|
|
if (json) {
|
|
return JSON.parse(json) as World;
|
|
}
|
|
}
|
|
|
|
public static save(world: World): void {
|
|
localStorage.setItem("world", JSON.stringify(world));
|
|
}
|
|
}
|