BlueGit

timfa questward

Add shared protocol constants and ground/block definitions.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-08-24 · 2 months ago

Hash
7425ef061bc29ae2bd825330f436c5eb6f51c0e4
Parent
4d73d64b
2 files changed +121 −0
shared/definitions/tiles.js added +68 −0
@@ -0,0 +1,68 @@
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 }
@@ -0,0 +1,68 @@
1export const GroundType = Object.freeze({
2 grass: 1,
3 wood: 2
4});
5
6export const BlockType = Object.freeze({
7 stoneWall: 1,
8 torch: 2
9});
10
11export 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
26export 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
45export function groundDefinition (typeId)
46{
47 return GROUND_DEFINITIONS[typeId] ?? null;
48}
49
50export function blockDefinition (typeId)
51{
52 return BLOCK_DEFINITIONS[typeId] ?? null;
53}
54
55export 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
64export function blockLightRange (typeId)
65{
66 const def = blockDefinition(typeId);
67 return def ? def.lightRangeTiles : 0;
68}
shared/protocol/constants.js added +53 −0
@@ -0,0 +1,53 @@
1 export const CHUNK_SIZE = 16;
2 export const REGION_CHUNKS = 4;
3 export const SPRITE_SIZE_PX = 16;
4 export const VISIBLE_CHUNK_RADIUS = 1;
5
6 export const WORLD_YEAR_OFFSET = 1200;
7
8 export const DEFAULT_WORLD_SETTINGS = Object.freeze({
9 walkTilesPerSecond: 2,
10 simulationTickHz: 20,
11 shopPriceLerpDurationMs: 60 * 60 * 1000,
12 groundItemDespawnDurationMs: 10 * 60 * 1000,
13 regionUnloadGracePeriodMs: 30 * 1000,
14 defaultGroundTypeId: 1,
15 characterDeletionDelayMs: 24 * 60 * 60 * 1000
16 });
17
18 export const GAIT = Object.freeze({
19 walk: "walk",
20 run: "run"
21 });
22
23 export const SEX = Object.freeze({
24 male: "male",
25 female: "female"
26 });
27
28 export const MessageType = Object.freeze({
29 hello: "HELLO",
30 session: "SESSION",
31 error: "ERROR",
32 characterList: "CHARACTER_LIST",
33 createCharacter: "CREATE_CHARACTER",
34 selectCharacter: "SELECT_CHARACTER",
35 scheduleDeleteCharacter: "SCHEDULE_DELETE_CHARACTER",
36 cancelDeleteCharacter: "CANCEL_DELETE_CHARACTER",
37 leaveWorld: "LEAVE_WORLD",
38 enterWorld: "ENTER_WORLD",
39 moveTo: "MOVE_TO",
40 setGait: "SET_GAIT",
41 chunkSnapshot: "CHUNK_SNAPSHOT",
42 chunkDelta: "CHUNK_DELTA",
43 unsubscribeChunk: "UNSUBSCRIBE_CHUNK",
44 entityMove: "ENTITY_MOVE",
45 entityDespawn: "ENTITY_DESPAWN",
46 worldStatus: "WORLD_STATUS",
47 editorLoadChunk: "EDITOR_LOAD_CHUNK",
48 editorChunk: "EDITOR_CHUNK",
49 editorSaveChunk: "EDITOR_SAVE_CHUNK",
50 editorSaveSettings: "EDITOR_SAVE_SETTINGS",
51 editorApplyRevision: "EDITOR_APPLY_REVISION",
52 editorChangelog: "EDITOR_CHANGELOG"
53 });
@@ -0,0 +1,53 @@
1export const CHUNK_SIZE = 16;
2export const REGION_CHUNKS = 4;
3export const SPRITE_SIZE_PX = 16;
4export const VISIBLE_CHUNK_RADIUS = 1;
5
6export const WORLD_YEAR_OFFSET = 1200;
7
8export const DEFAULT_WORLD_SETTINGS = Object.freeze({
9 walkTilesPerSecond: 2,
10 simulationTickHz: 20,
11 shopPriceLerpDurationMs: 60 * 60 * 1000,
12 groundItemDespawnDurationMs: 10 * 60 * 1000,
13 regionUnloadGracePeriodMs: 30 * 1000,
14 defaultGroundTypeId: 1,
15 characterDeletionDelayMs: 24 * 60 * 60 * 1000
16});
17
18export const GAIT = Object.freeze({
19 walk: "walk",
20 run: "run"
21});
22
23export const SEX = Object.freeze({
24 male: "male",
25 female: "female"
26});
27
28export const MessageType = Object.freeze({
29 hello: "HELLO",
30 session: "SESSION",
31 error: "ERROR",
32 characterList: "CHARACTER_LIST",
33 createCharacter: "CREATE_CHARACTER",
34 selectCharacter: "SELECT_CHARACTER",
35 scheduleDeleteCharacter: "SCHEDULE_DELETE_CHARACTER",
36 cancelDeleteCharacter: "CANCEL_DELETE_CHARACTER",
37 leaveWorld: "LEAVE_WORLD",
38 enterWorld: "ENTER_WORLD",
39 moveTo: "MOVE_TO",
40 setGait: "SET_GAIT",
41 chunkSnapshot: "CHUNK_SNAPSHOT",
42 chunkDelta: "CHUNK_DELTA",
43 unsubscribeChunk: "UNSUBSCRIBE_CHUNK",
44 entityMove: "ENTITY_MOVE",
45 entityDespawn: "ENTITY_DESPAWN",
46 worldStatus: "WORLD_STATUS",
47 editorLoadChunk: "EDITOR_LOAD_CHUNK",
48 editorChunk: "EDITOR_CHUNK",
49 editorSaveChunk: "EDITOR_SAVE_CHUNK",
50 editorSaveSettings: "EDITOR_SAVE_SETTINGS",
51 editorApplyRevision: "EDITOR_APPLY_REVISION",
52 editorChangelog: "EDITOR_CHANGELOG"
53});