BlueGit

timfa questward

Files

questward / shared / definitions / tileSprites.js

tileSprites.js

tileSprites.js 961 B Download Raw
1export function resolveState (states, requested)
2{
3 if (!states?.length)
4 { return null; }
5 if (requested && states.includes(requested))
6 { return requested; }
7 return states[0];
8}
9
10export function cycleState (states, current, direction)
11{
12 if (!states?.length)
13 { return null; }
14 const resolved = resolveState(states, current);
15 const index = states.indexOf(resolved);
16 const step = direction < 0 ? -1 : 1;
17 return states[(index + step + states.length) % states.length];
18}
19
20export function spriteImageName (layer, key, state)
21{
22 return `${layer}:${key}:${state}`;
23}
24
25export function statesForType (catalog, layer, key)
26{
27 const group = layer === "ground" ? catalog?.grounds : catalog?.blocks;
28 return group?.[key]?.states ?? [];
29}
30
31export function defaultStateForType (catalog, layer, key)
32{
33 const group = layer === "ground" ? catalog?.grounds : catalog?.blocks;
34 return group?.[key]?.defaultState ?? resolveState(statesForType(catalog, layer, key), null);
35}