folib 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.d.ts ADDED
@@ -0,0 +1,119 @@
1
+ // Branded types for type safety
2
+
3
+ /** Object pointer - an integer handle to a game object */
4
+ export type ObjectPtr<T extends string = string> = number & { __type: T };
5
+
6
+ /** Critter object (NPCs, player, creatures) */
7
+ export type CritterPtr = ObjectPtr<'critter'>;
8
+
9
+ /** Item object (weapons, armor, ammo, misc items, containers) */
10
+ export type ItemPtr = ObjectPtr<'item' | 'container'>;
11
+
12
+ /** Container object (lockers, chests, bags) - subtype of Item */
13
+ export type ContainerPtr = ObjectPtr<'container'>;
14
+
15
+ /** Scenery object (includes doors) */
16
+ export type SceneryPtr = ObjectPtr<'scenery' | 'door'>;
17
+
18
+ /** Door object - subtype of Scenery */
19
+ export type DoorPtr = ObjectPtr<'door'>;
20
+
21
+ /** Array ID - an integer handle to a sfall array */
22
+ export type ArrayID = number & { __brand: 'ArrayID' };
23
+
24
+ /** Hook ID - valid sfall hook identifiers (0-48, 61) */
25
+ export type HookID =
26
+ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
27
+ | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19
28
+ | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29
29
+ | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39
30
+ | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48
31
+ | 61;
32
+
33
+ /** Interface tag ID for show_iface_tag, hide_iface_tag, is_iface_tag_active */
34
+ export type IfaceTag = number & { __brand: 'IfaceTag' };
35
+
36
+ /** Game mode bitmask returned by get_game_mode() */
37
+ export type GameMode = number & { __brand: 'GameMode' };
38
+
39
+ /** Object type returned by obj_type() */
40
+ export type ObjType = 0 | 1 | 2 | 3 | 4 | 5 | 6;
41
+
42
+ /** Weapon type classification */
43
+ export type WeaponType = 0 | 1 | 2 | 3 | 4;
44
+
45
+ /** Inventory slot for critter_inven_obj */
46
+ export type InvenSlot = -2 | 0 | 1 | 2;
47
+
48
+ /** Damage type (0-6), can be combined with DMG_BYPASS_ARMOR/DMG_NOANIMATE flags */
49
+ export type DamageType = 0 | 1 | 2 | 3 | 4 | 5 | 6;
50
+
51
+ /** Float message color for float_msg */
52
+ export type FloatMsgColor = -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
53
+
54
+ /** Perk ID for has_perk, set_perk, etc. */
55
+ export type PerkID = number & { __brand: 'PerkID' };
56
+
57
+ /** Character trait ID (0-15) */
58
+ export type TraitID = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
59
+
60
+ /** Trait type for has_trait function (TRAIT_PERK=0, TRAIT_OBJECT=1, TRAIT_TRAIT=2) */
61
+ export type TraitType = 0 | 1 | 2;
62
+
63
+ /** PC-only stat ID for get_pc_stat (0-5) */
64
+ export type PcStatID = 0 | 1 | 2 | 3 | 4 | 5;
65
+
66
+ /** Roll/skill check result */
67
+ export type RollResult = 0 | 1 | 2 | 3;
68
+
69
+ /** Attack type for combat hooks (0-19) */
70
+ export type AttackType =
71
+ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
72
+ | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19;
73
+
74
+ /** Attack mode for weapons (0-8) */
75
+ export type AttackMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
76
+
77
+ /** Gender (0=male, 1=female) */
78
+ export type Gender = 0 | 1;
79
+
80
+ /** Active hand (0=left, 1=right) */
81
+ export type Hand = 0 | 1;
82
+
83
+ /** Difficulty level (0=easy, 1=normal, 2=hard) */
84
+ export type Difficulty = 0 | 1 | 2;
85
+
86
+ /** Elevation level (0-2) */
87
+ export type Elevation = 0 | 1 | 2;
88
+
89
+ /** Direction on hex grid (0-5, clockwise from NE) */
90
+ export type Direction = 0 | 1 | 2 | 3 | 4 | 5;
91
+
92
+ /** Critter state bitmask from critter_state() */
93
+ export type CritterState = number & { __brand: 'CritterState' };
94
+
95
+ /** Hit result from HOOK_AFTERHITROLL (0=critical miss, 1=miss, 2=hit, 3=critical hit) */
96
+ export type HitResult = 0 | 1 | 2 | 3;
97
+
98
+ /** Sfall list array - numeric index, iterable over values */
99
+ export type SfallList<T> = {
100
+ [index: number]: T;
101
+ readonly __brand: 'SfallList';
102
+ } & Iterable<T>;
103
+
104
+ /** Sfall map array - key/value pairs, iterable as [key, value] tuples */
105
+ export type SfallMap<K, V> = {
106
+ [key: string]: V;
107
+ [key: number]: V;
108
+ readonly __brand: 'SfallMap';
109
+ } & Iterable<[K, V]>;
110
+
111
+ /**
112
+ * Create a typed list from items. Transpiles to array literal [a, b, c].
113
+ */
114
+ export declare function list<T>(...items: T[]): SfallList<T>;
115
+
116
+ /**
117
+ * Create a typed map from object literal. Transpiles to map literal {a: 1}.
118
+ */
119
+ export declare function map<K extends string | number, V>(obj: Record<K, V>): SfallMap<K, V>;
package/src/types.ts ADDED
@@ -0,0 +1,49 @@
1
+ // Runtime constants for union types
2
+
3
+ import type { Hand, Difficulty, Elevation, Direction, HitResult, ObjectPtr } from './types.d';
4
+
5
+ /** Active hand: left */
6
+ export const LEFT_HAND: Hand = 0;
7
+ /** Active hand: right */
8
+ export const RIGHT_HAND: Hand = 1;
9
+
10
+ /** Difficulty level: easy */
11
+ export const DIFFICULTY_EASY: Difficulty = 0;
12
+ /** Difficulty level: normal */
13
+ export const DIFFICULTY_NORMAL: Difficulty = 1;
14
+ /** Difficulty level: hard */
15
+ export const DIFFICULTY_HARD: Difficulty = 2;
16
+
17
+ /** Elevation level 0 (ground floor) */
18
+ export const ELEVATION_0: Elevation = 0;
19
+ /** Elevation level 1 */
20
+ export const ELEVATION_1: Elevation = 1;
21
+ /** Elevation level 2 */
22
+ export const ELEVATION_2: Elevation = 2;
23
+ /** Special value for set_can_rest_on_map to apply to all elevations */
24
+ export const ELEVATION_ALL = -1;
25
+
26
+ /** Direction: Northeast */
27
+ export const DIRECTION_NE: Direction = 0;
28
+ /** Direction: East */
29
+ export const DIRECTION_E: Direction = 1;
30
+ /** Direction: Southeast */
31
+ export const DIRECTION_SE: Direction = 2;
32
+ /** Direction: Southwest */
33
+ export const DIRECTION_SW: Direction = 3;
34
+ /** Direction: West */
35
+ export const DIRECTION_W: Direction = 4;
36
+ /** Direction: Northwest */
37
+ export const DIRECTION_NW: Direction = 5;
38
+
39
+ /** Hit result: critical miss */
40
+ export const HITRESULT_CRITICAL_MISS: HitResult = 0;
41
+ /** Hit result: miss */
42
+ export const HITRESULT_MISS: HitResult = 1;
43
+ /** Hit result: hit */
44
+ export const HITRESULT_HIT: HitResult = 2;
45
+ /** Hit result: critical hit */
46
+ export const HITRESULT_CRITICAL_HIT: HitResult = 3;
47
+
48
+ /** Null pointer - compatible with all pointer types (ObjectPtr, CritterPtr, ItemPtr, etc.) */
49
+ export const NullPtr = 0 as ObjectPtr<never>;
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "noEmit": true,
8
+ "skipLibCheck": true
9
+ },
10
+ "include": ["src"]
11
+ }