default voxel types

This commit is contained in:
azykov@mail.ru 2026-06-02 13:19:55 +03:00
parent e37cb08698
commit 7ebccba199
No known key found for this signature in database
3 changed files with 48 additions and 13 deletions

View File

@ -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,
}

View File

@ -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,

View File

@ -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],