Skip to content

Commit b175d84

Browse files
committed
Pull data type from iesdp too
1 parent 68ff2ec commit b175d84

7 files changed

Lines changed: 247 additions & 7 deletions

File tree

scripts/iesdp-update.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ const TYPE_SIZE_MAP: Record<string, number> = {
5454
strref: 4,
5555
};
5656

57+
// Known types for JSDoc output
58+
const KNOWN_TYPES = new Set([
59+
"byte",
60+
"char",
61+
"word",
62+
"dword",
63+
"resref",
64+
"strref",
65+
"bytes",
66+
"char array",
67+
"byte array",
68+
]);
69+
5770
const STRUCTURE_PREFIX_MAP: Record<string, string> = {
5871
header: "",
5972
body: "",
@@ -311,10 +324,25 @@ function isStructureItemArray(data: unknown): data is StructureItem[] {
311324
return Array.isArray(data) && data.length > 0 && typeof data[0] === "object";
312325
}
313326

327+
interface StructureField {
328+
offset: number;
329+
type: string;
330+
}
331+
332+
/**
333+
* Validates that a type is known.
334+
*/
335+
function validateType(type: string): string {
336+
if (!KNOWN_TYPES.has(type)) {
337+
throw new ValidationError(`Unknown type: "${type}"`);
338+
}
339+
return type;
340+
}
341+
314342
/**
315343
* Loads a structure data file and computes offsets.
316344
*/
317-
function loadDatafile(fpath: string, prefix: string): Map<string, string> {
345+
function loadDatafile(fpath: string, prefix: string): Map<string, StructureField> {
318346
console.log(`loading ${fpath}`);
319347
const content = readFile(fpath);
320348
const parsed = yaml.load(content);
@@ -325,7 +353,7 @@ function loadDatafile(fpath: string, prefix: string): Map<string, string> {
325353

326354
const data = parsed;
327355
let curOff = data[0]?.offset ?? 0;
328-
const items = new Map<string, string>();
356+
const items = new Map<string, StructureField>();
329357

330358
for (const item of data) {
331359
if (item.offset !== undefined && item.offset !== curOff) {
@@ -341,7 +369,10 @@ function loadDatafile(fpath: string, prefix: string): Map<string, string> {
341369
}
342370

343371
const iid = generateId(item, prefix);
344-
items.set(iid, `0x${curOff.toString(16)}`);
372+
items.set(iid, {
373+
offset: curOff,
374+
type: validateType(item.type),
375+
});
345376
curOff += size;
346377
}
347378

@@ -362,16 +393,17 @@ function getOutputDirName(formatName: string): string {
362393
/**
363394
* Writes structure items to the appropriate output file.
364395
*/
365-
function writeStructureFile(formatName: string, items: Map<string, string>, structuresDir: string): void {
396+
function writeStructureFile(formatName: string, items: Map<string, StructureField>, structuresDir: string): void {
366397
const dirName = getOutputDirName(formatName);
367398
const outputDir = path.join(structuresDir, dirName);
368399
const outputFile = path.join(outputDir, "iesdp.tph");
369400

370401
fs.mkdirSync(outputDir, { recursive: true });
371402

372403
let text = "";
373-
for (const [id, offset] of items) {
374-
text += `OUTER_SET ${id} = ${offset}\n`;
404+
for (const [id, field] of items) {
405+
text += `/** @type ${field.type} */\n`;
406+
text += `OUTER_SET ${id} = 0x${field.offset.toString(16)}\n`;
375407
}
376408

377409
fs.writeFileSync(outputFile, text);
@@ -396,7 +428,7 @@ function processStructures(iesdpDir: string, structuresDir: string): void {
396428
continue;
397429
}
398430

399-
const items = new Map<string, string>();
431+
const items = new Map<string, StructureField>();
400432
const files = fs.readdirSync(ffDir).sort();
401433

402434
for (const f of files) {

structures/eff/iesdp.tph

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
/** @type word */
12
OUTER_SET EFF_effect_type = 0x0
3+
/** @type byte */
24
OUTER_SET EFF_target = 0x2
5+
/** @type byte */
36
OUTER_SET EFF_power = 0x3
7+
/** @type dword */
48
OUTER_SET EFF_parameter1 = 0x4
9+
/** @type dword */
510
OUTER_SET EFF_parameter2 = 0x8
11+
/** @type byte */
612
OUTER_SET EFF_timing_mode = 0xc
13+
/** @type byte */
714
OUTER_SET EFF_resistance = 0xd
15+
/** @type dword */
816
OUTER_SET EFF_duration = 0xe
17+
/** @type byte */
918
OUTER_SET EFF_probability1 = 0x12
19+
/** @type byte */
1020
OUTER_SET EFF_probability2 = 0x13
21+
/** @type resref */
1122
OUTER_SET EFF_resref_key = 0x14
23+
/** @type dword */
1224
OUTER_SET EFF_dice_thrown = 0x1c
25+
/** @type dword */
1326
OUTER_SET EFF_dice_sides = 0x20
27+
/** @type dword */
1428
OUTER_SET EFF_save_type = 0x24
29+
/** @type dword */
1530
OUTER_SET EFF_save_bonus = 0x28

structures/eff2/iesdp.tph

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,76 @@
1+
/** @type char array */
12
OUTER_SET EFF2_signature2 = 0x8
3+
/** @type char array */
24
OUTER_SET EFF2_version2 = 0xc
5+
/** @type dword */
36
OUTER_SET EFF2_opcode = 0x10
7+
/** @type dword */
48
OUTER_SET EFF2_target = 0x14
9+
/** @type dword */
510
OUTER_SET EFF2_power = 0x18
11+
/** @type dword */
612
OUTER_SET EFF2_parameter1 = 0x1c
13+
/** @type dword */
714
OUTER_SET EFF2_parameter2 = 0x20
15+
/** @type word */
816
OUTER_SET EFF2_timing = 0x24
17+
/** @type dword */
918
OUTER_SET EFF2_duration = 0x28
19+
/** @type word */
1020
OUTER_SET EFF2_probability1 = 0x2c
21+
/** @type word */
1122
OUTER_SET EFF2_probability2 = 0x2e
23+
/** @type resref */
1224
OUTER_SET EFF2_resource = 0x30
25+
/** @type dword */
1326
OUTER_SET EFF2_dice_thrown = 0x38
27+
/** @type dword */
1428
OUTER_SET EFF2_dice_sides = 0x3c
29+
/** @type dword */
1530
OUTER_SET EFF2_save_type = 0x40
31+
/** @type dword */
1632
OUTER_SET EFF2_save_bonus = 0x44
33+
/** @type dword */
1734
OUTER_SET EFF2_stacking_id_tobex = 0x48
35+
/** @type dword */
1836
OUTER_SET EFF2_school = 0x4c
37+
/** @type dword */
1938
OUTER_SET EFF2_resistance = 0x5c
39+
/** @type dword */
2040
OUTER_SET EFF2_parameter3 = 0x60
41+
/** @type dword */
2142
OUTER_SET EFF2_parameter4 = 0x64
43+
/** @type dword */
2244
OUTER_SET EFF2_parameter5 = 0x68
45+
/** @type dword */
2346
OUTER_SET EFF2_time_applied = 0x6c
47+
/** @type resref */
2448
OUTER_SET EFF2_resource2 = 0x70
49+
/** @type resref */
2550
OUTER_SET EFF2_resource3 = 0x78
51+
/** @type dword */
2652
OUTER_SET EFF2_caster_x_coord = 0x80
53+
/** @type dword */
2754
OUTER_SET EFF2_caster_y_coord = 0x84
55+
/** @type dword */
2856
OUTER_SET EFF2_target_x_coord = 0x88
57+
/** @type dword */
2958
OUTER_SET EFF2_target_y_coord = 0x8c
59+
/** @type dword */
3060
OUTER_SET EFF2_parent_resource_type = 0x90
61+
/** @type resref */
3162
OUTER_SET EFF2_parent_resource = 0x94
63+
/** @type dword */
3264
OUTER_SET EFF2_parent_resource_flags = 0x9c
65+
/** @type dword */
3366
OUTER_SET EFF2_projectile = 0xa0
67+
/** @type bytes */
3468
OUTER_SET EFF2_variable_name = 0xa8
69+
/** @type dword */
3570
OUTER_SET EFF2_caster_level = 0xc8
71+
/** @type dword */
3672
OUTER_SET EFF2_sectype = 0xd0
73+
/** @type char array */
3774
OUTER_SET EFF2_signature = 0x0
75+
/** @type char array */
3876
OUTER_SET EFF2_version = 0x4

structures/fx/iesdp.tph

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1+
/** @type word */
12
OUTER_SET FX_opcode = 0x0
3+
/** @type char */
24
OUTER_SET FX_target = 0x2
5+
/** @type char */
36
OUTER_SET FX_power = 0x3
7+
/** @type dword */
48
OUTER_SET FX_parameter1 = 0x4
9+
/** @type dword */
510
OUTER_SET FX_parameter2 = 0x8
11+
/** @type char */
612
OUTER_SET FX_timing = 0xc
13+
/** @type char */
714
OUTER_SET FX_resistance = 0xd
15+
/** @type dword */
816
OUTER_SET FX_duration = 0xe
17+
/** @type char */
918
OUTER_SET FX_probability1 = 0x12
19+
/** @type char */
1020
OUTER_SET FX_probability2 = 0x13
21+
/** @type resref */
1122
OUTER_SET FX_resource = 0x14
23+
/** @type dword */
1224
OUTER_SET FX_max_level = 0x1c
25+
/** @type dword */
1326
OUTER_SET FX_min_level = 0x20
27+
/** @type dword */
1428
OUTER_SET FX_save_type = 0x24
29+
/** @type dword */
1530
OUTER_SET FX_save_bonus = 0x28
31+
/** @type dword */
1632
OUTER_SET FX_stacking_id_Ex = 0x2c

structures/itm/iesdp.tph

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,132 @@
1+
/** @type char */
12
OUTER_SET ITM_HEAD_attack_type = 0x0
3+
/** @type char */
24
OUTER_SET ITM_HEAD_id_required = 0x1
5+
/** @type char */
36
OUTER_SET ITM_HEAD_location = 0x2
7+
/** @type char */
48
OUTER_SET ITM_HEAD_alt_dice_sides = 0x3
9+
/** @type resref */
510
OUTER_SET ITM_HEAD_use_icon = 0x4
11+
/** @type char */
612
OUTER_SET ITM_HEAD_target = 0xc
13+
/** @type char */
714
OUTER_SET ITM_HEAD_target_count = 0xd
15+
/** @type word */
816
OUTER_SET ITM_HEAD_range = 0xe
17+
/** @type byte */
918
OUTER_SET ITM_HEAD_projectile_type = 0x10
19+
/** @type byte */
1020
OUTER_SET ITM_HEAD_alt_dice_thrown = 0x11
21+
/** @type byte */
1122
OUTER_SET ITM_HEAD_speed = 0x12
23+
/** @type byte */
1224
OUTER_SET ITM_HEAD_alt_damage_bonus = 0x13
25+
/** @type word */
1326
OUTER_SET ITM_HEAD_thac0_bonus = 0x14
27+
/** @type byte */
1428
OUTER_SET ITM_HEAD_dice_sides = 0x16
29+
/** @type byte */
1530
OUTER_SET ITM_HEAD_primary_type = 0x17
31+
/** @type byte */
1632
OUTER_SET ITM_HEAD_dice_thrown = 0x18
33+
/** @type byte */
1734
OUTER_SET ITM_HEAD_secondary_type = 0x19
35+
/** @type word */
1836
OUTER_SET ITM_HEAD_damage_bonus = 0x1a
37+
/** @type word */
1938
OUTER_SET ITM_HEAD_damage_type = 0x1c
39+
/** @type word */
2040
OUTER_SET ITM_HEAD_feature_block_count = 0x1e
41+
/** @type word */
2142
OUTER_SET ITM_HEAD_feature_block_index = 0x20
43+
/** @type word */
2244
OUTER_SET ITM_HEAD_max_charges = 0x22
45+
/** @type word */
2346
OUTER_SET ITM_HEAD_depletion = 0x24
47+
/** @type dword */
2448
OUTER_SET ITM_HEAD_flags = 0x26
49+
/** @type word */
2550
OUTER_SET ITM_HEAD_projectile_animation = 0x2a
51+
/** @type word */
2652
OUTER_SET ITM_HEAD_melee_animation = 0x2c
53+
/** @type word */
2754
OUTER_SET ITM_HEAD_is_arrow = 0x32
55+
/** @type word */
2856
OUTER_SET ITM_HEAD_is_bolt = 0x34
57+
/** @type word */
2958
OUTER_SET ITM_HEAD_is_bullet = 0x36
59+
/** @type char array */
3060
OUTER_SET ITM_signature = 0x0
61+
/** @type char array */
3162
OUTER_SET ITM_version = 0x4
63+
/** @type strref */
3264
OUTER_SET ITM_unidentified_name = 0x8
65+
/** @type strref */
3366
OUTER_SET ITM_identified_name = 0xc
67+
/** @type resref */
3468
OUTER_SET ITM_replacement = 0x10
69+
/** @type dword */
3570
OUTER_SET ITM_flags = 0x18
71+
/** @type word */
3672
OUTER_SET ITM_type = 0x1c
73+
/** @type byte */
3774
OUTER_SET ITM_usability_flags = 0x1e
75+
/** @type char array */
3876
OUTER_SET ITM_animation = 0x22
77+
/** @type word */
3978
OUTER_SET ITM_min_level = 0x24
79+
/** @type word */
4080
OUTER_SET ITM_min_strength = 0x26
81+
/** @type byte */
4182
OUTER_SET ITM_min_strength_bonus = 0x28
83+
/** @type byte */
4284
OUTER_SET ITM_kit_usability1 = 0x29
85+
/** @type byte */
4386
OUTER_SET ITM_min_intelligence = 0x2a
87+
/** @type byte */
4488
OUTER_SET ITM_kit_usability2 = 0x2b
89+
/** @type byte */
4590
OUTER_SET ITM_min_dexterity = 0x2c
91+
/** @type byte */
4692
OUTER_SET ITM_kit_usability3 = 0x2d
93+
/** @type byte */
4794
OUTER_SET ITM_min_wisdom = 0x2e
95+
/** @type byte */
4896
OUTER_SET ITM_kit_usability4 = 0x2f
97+
/** @type byte */
4998
OUTER_SET ITM_min_constitution = 0x30
99+
/** @type byte */
50100
OUTER_SET ITM_weapon_proficiency = 0x31
101+
/** @type word */
51102
OUTER_SET ITM_min_charisma = 0x32
103+
/** @type dword */
52104
OUTER_SET ITM_price = 0x34
105+
/** @type word */
53106
OUTER_SET ITM_stack_amount = 0x38
107+
/** @type resref */
54108
OUTER_SET ITM_inventory_icon = 0x3a
109+
/** @type word */
55110
OUTER_SET ITM_lore_to_id = 0x42
111+
/** @type resref */
56112
OUTER_SET ITM_ground_icon = 0x44
113+
/** @type dword */
57114
OUTER_SET ITM_weight = 0x4c
115+
/** @type strref */
58116
OUTER_SET ITM_unidentified_desc = 0x50
117+
/** @type strref */
59118
OUTER_SET ITM_identified_desc = 0x54
119+
/** @type resref */
60120
OUTER_SET ITM_description_icon = 0x58
121+
/** @type dword */
61122
OUTER_SET ITM_enchantment = 0x60
123+
/** @type dword */
62124
OUTER_SET ITM_extended_headers_offset = 0x64
125+
/** @type word */
63126
OUTER_SET ITM_extended_headers_count = 0x68
127+
/** @type dword */
64128
OUTER_SET ITM_feature_blocks_offset = 0x6a
129+
/** @type word */
65130
OUTER_SET ITM_feature_blocks_index = 0x6e
131+
/** @type word */
66132
OUTER_SET ITM_feature_blocks_count = 0x70

0 commit comments

Comments
 (0)