| 1 | export const GroundType = Object.freeze({ |
| 2 | grass: 1, |
| 3 | wood: 2 |
| 4 | }); |
| 5 | |
| 6 | export const BlockType = Object.freeze({ |
| 7 | stoneWall: 1, |
| 8 | torch: 2 |
| 9 | }); |
| 10 | |
| 11 | export const GROUND_DEFINITIONS = Object.freeze({ |
| 12 | [GroundType.grass]: Object.freeze({ |
| 13 | id: GroundType.grass, |
| 14 | key: "grass", |
| 15 | displayName: "Grass", |
| 16 | sprite: "ground-grass" |
| 17 | }), |
| 18 | [GroundType.wood]: Object.freeze({ |
| 19 | id: GroundType.wood, |
| 20 | key: "wood", |
| 21 | displayName: "Wood", |
| 22 | sprite: "ground-wood" |
| 23 | }) |
| 24 | }); |
| 25 | |
| 26 | export const BLOCK_DEFINITIONS = Object.freeze({ |
| 27 | [BlockType.stoneWall]: Object.freeze({ |
| 28 | id: BlockType.stoneWall, |
| 29 | key: "stone-wall", |
| 30 | displayName: "Stone wall", |
| 31 | sprite: "block-stone-wall", |
| 32 | passable: false, |
| 33 | lightRangeTiles: 0 |
| 34 | }), |
| 35 | [BlockType.torch]: Object.freeze({ |
| 36 | id: BlockType.torch, |
| 37 | key: "torch", |
| 38 | displayName: "Torch", |
| 39 | sprite: "block-torch", |
| 40 | passable: true, |
| 41 | lightRangeTiles: 8 |
| 42 | }) |
| 43 | }); |
| 44 | |
| 45 | export function groundDefinition (typeId) |
| 46 | { |
| 47 | return GROUND_DEFINITIONS[typeId] ?? null; |
| 48 | } |
| 49 | |
| 50 | export function blockDefinition (typeId) |
| 51 | { |
| 52 | return BLOCK_DEFINITIONS[typeId] ?? null; |
| 53 | } |
| 54 | |
| 55 | export function isBlockPassable (typeId) |
| 56 | { |
| 57 | if (typeId == null) |
| 58 | { return true; } |
| 59 | |
| 60 | const def = blockDefinition(typeId); |
| 61 | return def ? def.passable : false; |
| 62 | } |
| 63 | |
| 64 | export function blockLightRange (typeId) |
| 65 | { |
| 66 | const def = blockDefinition(typeId); |
| 67 | return def ? def.lightRangeTiles : 0; |
| 68 | } |