-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2da_missing_cols.tpa
67 lines (65 loc) · 2.01 KB
/
2da_missing_cols.tpa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Automatically fixes missing column entries in 2da files. Can be used as both patch and action function
DEFINE_ACTION_FUNCTION 2DA_MISSING_COLS
INT_VAR
cols = 0 //minimum amount of columns that should have values (if not set function will automatically read max number of columns in file)
STR_VAR
2da = ~~ //2da file that should be patched, e.g. kitlist
entry = ~~ //what entry should be set in missing columns (if not set function will automatically read default entry from loaded 2da, e.g. *)
BEGIN
ACTION_IF ~%2da%~ STR_EQ ~~ BEGIN
FAIL ~2DA_MISSING_COLS: %2da% STR_VAR not set~
END
COPY_EXISTING ~%2da%.2da~ ~override~
PRETTY_PRINT_2DA
PATCH_IF ~%entry%~ STR_EQ ~~ BEGIN
READ_2DA_ENTRY 1 0 1 "entry"
END
PATCH_IF cols = 0 BEGIN
COUNT_2DA_COLS "cols"
END
SET cnt = 0
REPLACE_EVALUATE ~^\(.+\)$~ BEGIN
PATCH_IF cnt >= 3 BEGIN
INNER_PATCH_SAVE MATCH1 ~%MATCH1%~ BEGIN
COUNT_REGEXP_INSTANCES ~ +~ num_matches
WHILE (num_matches < (cols - 1)) BEGIN
REPLACE_TEXTUALLY ~$~ ~ %entry%~
SET num_matches = num_matches + 1
END
END
END ELSE BEGIN
SET cnt = cnt + 1
END
END ~%MATCH1%~
PRETTY_PRINT_2DA
BUT_ONLY
END
DEFINE_PATCH_FUNCTION 2DA_MISSING_COLS
INT_VAR
cols = 0 //minimum amount of columns that should have values (if not set function will automatically read max number of columns in file)
STR_VAR
entry = ~~ //what entry should be used in missing columns (if not set function will automatically read default entry from loaded 2da, e.g. *)
BEGIN
PRETTY_PRINT_2DA
PATCH_IF ~%entry%~ STR_EQ ~~ BEGIN
READ_2DA_ENTRY 1 0 1 "entry"
END
PATCH_IF cols = 0 BEGIN
COUNT_2DA_COLS "cols"
END
SET cnt = 0
REPLACE_EVALUATE ~^\(.+\)$~ BEGIN
PATCH_IF cnt >= 3 BEGIN
INNER_PATCH_SAVE MATCH1 ~%MATCH1%~ BEGIN
COUNT_REGEXP_INSTANCES ~ +~ num_matches
WHILE (num_matches < (cols - 1)) BEGIN
REPLACE_TEXTUALLY ~$~ ~ %entry%~
SET num_matches = num_matches + 1
END
END
END ELSE BEGIN
SET cnt = cnt + 1
END
END ~%MATCH1%~
PRETTY_PRINT_2DA
END