Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

Commit 5d840df

Browse files
committed
feat(merge): Merge arrays
Signed-off-by: dark0dave <dark0dave@mykolab.com>
1 parent f900e65 commit 5d840df

5 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/tp.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ and tp_action =
194194
| TP_Outer_Text_Sprint of tp_pe_string * tp_pe_string
195195
| TP_Outer_Snprint of tp_patchexp * tp_pe_string * tp_pe_tlk_string
196196
| TP_ActionDefineAssociativeArray of tp_pe_string * ((tp_pe_string list) * tp_pe_string) list
197+
| TP_ActionMergeArrays of tp_pe_string * tp_pe_string
197198
| TP_Outer_While of tp_patchexp * (tp_action list)
198199
| TP_Require_File of string * (Dlg.tlk_string)
199200
| TP_Forbid_File of string * (Dlg.tlk_string)
@@ -326,6 +327,7 @@ and tp_patch =
326327
| TP_PatchClearArray of tp_pe_string
327328
| TP_PatchDefineArray of tp_pe_string * string list
328329
| TP_DefineAssociativeArray of tp_pe_string * ((tp_pe_string list) * tp_pe_string) list
330+
| TP_MergeArrays of tp_pe_string * tp_pe_string
329331
| TP_PatchSortArrayIndices of tp_pe_string * array_indices_sort_type
330332
| TP_PatchPHPEach of tp_pe_string * tp_pe_string * tp_pe_string * tp_patch list
331333
| TP_PatchForEach of tp_pe_string * string list * tp_patch list

src/tpaction.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ let rec process_action_real our_lang game this_tp2_filename tp a =
7777
| TP_ActionDefineAssociativeArray(arr,vals) ->
7878
run_patch (TP_DefineAssociativeArray(arr,vals))
7979

80+
| TP_ActionMergeArrays(arr1, arr2) ->
81+
run_patch (TP_MergeArrays(arr1, arr2))
82+
8083
| TP_ActionSortArrayIndices(array,sort_type) ->
8184
run_patch (TP_PatchSortArrayIndices(array,sort_type))
8285

src/tphelp.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ let action_to_str a = match a with
200200
| TP_Uninstall_Now _ -> "UNINSTALL"
201201
| TP_ActionBashFor _ -> "ACTION_BASH_FOR"
202202
| TP_ActionDefineArray _ -> "ACTION_DEFINE_ARRAY"
203+
| TP_ActionMergeArrays (_,_) -> "ACTION_MERGE_ARRAY"
203204
| TP_ActionSortArrayIndices _ -> "ACTION_SORT_ARRAY_INDICES"
204205
| TP_ActionPHPEach _ -> "ACTION_PHP_EACH"
205206
| TP_Action_For_Each _ -> "ACTION_FOR_EACH"

src/tppatch.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,15 @@ let rec process_patch2_real process_action tp our_lang patch_filename game buff
706706
(Var.get_string (eval_pe_str y));) vals;
707707
buff
708708

709+
| TP_MergeArrays(arr1, arr2) ->
710+
let (key1,key2) = ((eval_pe_str arr1),(eval_pe_str arr2)) in
711+
let key = key1^key2 in
712+
let array1 = (try Hashtbl.find !Var.arrays key1 with _ -> []) in
713+
let array2 = (try Hashtbl.find !Var.arrays key2 with _ -> []) in
714+
let combined = Var.merge_arr(array1, array2) in
715+
Hashtbl.add !Var.arrays key combined;
716+
buff
717+
709718
| TP_PatchSortArrayIndices(array,sort_type) ->
710719
let array = Var.get_string (eval_pe_str array) in
711720
let indices = (try Hashtbl.find !Var.arrays array with _ -> []) in

src/var.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ let clear_arr () =
174174
Hashtbl.iter (fun a b -> Hashtbl.remove !arrays a) arr_spec ;
175175
Hashtbl.clear !arrays
176176

177+
let rec merge_arr ((array1 : (string list list)), (array2 : (string list list))) =
178+
match (array1,array2) with
179+
| (x::xs), (y::ys) -> (x @ y)::(merge_arr (xs, ys))
180+
| [], array2 -> array2
181+
| array1, [] -> array1
182+
177183
let assoc name value =
178184
let value = Int32.of_int value in
179185
Hashtbl.replace !variables name (Int32 value)

0 commit comments

Comments
 (0)