From 7ebccba19927c5a770145b3c769eebccbda9312d Mon Sep 17 00:00:00 2001 From: "azykov@mail.ru" Date: Tue, 2 Jun 2026 13:19:55 +0300 Subject: [PATCH] default voxel types --- src/model/defaultVoxelTypes.ts | 40 ++++++++++++++++++++++++++++++++++ src/model/worldFactory.ts | 6 +++-- src/state/world.ts | 15 ++++--------- 3 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/model/defaultVoxelTypes.ts diff --git a/src/model/defaultVoxelTypes.ts b/src/model/defaultVoxelTypes.ts new file mode 100644 index 0000000..c83503c --- /dev/null +++ b/src/model/defaultVoxelTypes.ts @@ -0,0 +1,40 @@ +import type { VoxelType } from "../types/voxel"; + +const stone: VoxelType = { + id: 'stone', + name: 'Stone', + opacity: 1, + collidable: true, + color: 'white', +}; + +const dirt: VoxelType = { + id: 'dirt', + name: 'Dirt', + opacity: 1, + collidable: true, + color: '302520', +}; + +const water: VoxelType = { + id: 'water', + name: 'Stone', + opacity: 0.7, + collidable: false, + color: 'c0d0ff', +}; + +const glass: VoxelType = { + id: 'glass', + name: 'Glass', + opacity: 0.4, + collidable: true, + color: 'f0f8ff', +}; + +export const DEFAULT_VOXEL_TYPES = { + [stone.id]: stone, + [dirt.id]: dirt, + [water.id]: water, + [glass.id]: glass, +} \ No newline at end of file diff --git a/src/model/worldFactory.ts b/src/model/worldFactory.ts index 9ac08ac..18a008e 100644 --- a/src/model/worldFactory.ts +++ b/src/model/worldFactory.ts @@ -1,16 +1,18 @@ import type { World } from "../types"; +import { DEFAULT_VOXEL_TYPES } from "./defaultVoxelTypes"; export class WorldFactory { public static create(): World { return { - objectTypes: [], + objectTypes: {}, + voxelTypes: DEFAULT_VOXEL_TYPES, initialScene: { character: { position: [0, 0, 0], look: [0, 0, 0], }, - objects: [], + objects: {}, }, state: { playing: false, diff --git a/src/state/world.ts b/src/state/world.ts index 5c5a080..f717c23 100644 --- a/src/state/world.ts +++ b/src/state/world.ts @@ -6,6 +6,7 @@ import type { Pos3, V3 } from "../types/3d"; import { clone, randomId } from "../utils"; import type { VoxelType } from "../types/voxel"; import { state } from "./root"; +import { DEFAULT_VOXEL_TYPES } from "../model/defaultVoxelTypes"; export class WorldState { public data: World = WorldFactory.create(); @@ -24,8 +25,8 @@ export class WorldState { public loadMock() { const objTypeId = 'test1'; - const voxelTypeId = 'red'; - const objectId = 'red'; + const voxelTypeId = 'water'; + const objectId = 'object1'; this.data = { objectTypes: { @@ -40,15 +41,7 @@ export class WorldState { ], }, }, - voxelTypes: { - [voxelTypeId]: { - id: voxelTypeId, - collidable: true, - name: 'Red', - opacity: 1, - color: 'red', - } - }, + voxelTypes: DEFAULT_VOXEL_TYPES, editorCamera: { position: [0, 2, 10], look: [0, 0, 0],