Skip to content

Commit 5ea5e5f

Browse files
feat: UUID compat framework
1 parent f6717a2 commit 5ea5e5f

9 files changed

Lines changed: 76 additions & 49 deletions

File tree

objects/obj_ini/Create_0.gml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ repeat(11){
8080
}
8181
}
8282

83+
UUID_marine = {};
84+
UUID_vehicle = {};
85+
UUID_ship = {};
86+
8387
/*if (obj_creation.fleet_type=3){
8488
obj_controller.penitent=1;
8589
obj_controller.penitent_max=(obj_creation.maximum_size*1000)+300;

scripts/scr_add_man/scr_add_man.gml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ function scr_add_man(man_role, target_company, spawn_exp, spawn_name, corruption
250250
}
251251
}
252252
}
253-
obj_ini.TTRPG[target_company][good] = unit;
253+
struct_set(UUID_marine, unit.UUID, unit)
254+
obj_ini.TTRPG[target_company][good] = UUID_marine[$ unit.UUID];
254255
unit.add_exp(spawn_exp);
255256
unit.allocate_unit_to_fresh_spawn(home_spot);
256257
unit.update_role(man_role);
@@ -259,4 +260,4 @@ function scr_add_man(man_role, target_company, spawn_exp, spawn_name, corruption
259260
}
260261
}
261262

262-
}
263+
}

scripts/scr_company_order/scr_company_order.gml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function temp_marine_variables(co, unit_num){
3636
array_push(temp_mobi,mobi[co][unit_num]);
3737
array_push(temp_spe,spe[co][unit_num]);
3838
array_push(temp_god,god[co][unit_num]);
39-
array_push(temp_struct,jsonify_marine_struct(co,unit_num));
39+
array_push(temp_UUID, TTRPG[co][unit_num].UUID);
4040
scr_wipe_unit(co,unit_num);
4141
}
4242
function sort_all_companies(){
@@ -74,7 +74,7 @@ function scr_company_order(company) {
7474
temp_age=[];
7575
temp_spe=[];
7676
temp_god=[];
77-
temp_struct=[];
77+
temp_UUID=[];
7878

7979

8080
/*takes a template of a role, required role number and if there are enough
@@ -340,12 +340,11 @@ function scr_company_order(company) {
340340
age[co][i]=temp_age[i];
341341
spe[co][i]=temp_spe[i];
342342
god[co][i]=temp_god[i];
343+
obj_ini.TTRPG[co][i] = obj_ini.UUID_marine[$ temp_UUID[i]];
343344
unit = fetch_unit([co, i]);
344-
unit.load_json_data(json_parse(temp_struct[i]))
345345
unit.company = co;
346346
unit.marine_number = i;
347347
unit.movement_after_math();
348-
delete temp_struct[i];
349348
}
350349
/* i=0;repeat(300){i+=1;
351350
if (role[co][i]="Death Company"){
@@ -411,4 +410,4 @@ function role_hierarchy(){
411410
];
412411

413412
return hierarchy
414-
}
413+
}

scripts/scr_initialize_custom/scr_initialize_custom.gml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,9 @@ function scr_initialize_custom() {
22562256
loc[company, 1] = home_name;
22572257
name[company, 1] = obj_creation.chapter_master_name;
22582258
role[company, 1] = "Chapter Master";
2259-
TTRPG[company, 1] = new TTRPG_stats("chapter", company, 1, "chapter_master");
2259+
var _marine_ttrpg = new TTRPG_stats("chapter", company, 1, "chapter_master");
2260+
struct_set(UUID_marine, _marine_ttrpg.UUID, _marine_ttrpg)
2261+
TTRPG[company, 1] = UUID_marine[$ _marine_ttrpg.UUID];
22602262
var chapter_master = TTRPG[company, 1];
22612263
var chapter_master_equip = {}
22622264
switch (master_melee) {
@@ -2958,7 +2960,9 @@ function scr_initialize_custom() {
29582960
k += 1;
29592961
commands += 1; // Company Chaplain
29602962
race[company][k] = 1;
2961-
TTRPG[company][k] = new TTRPG_stats("chapter", company, k);
2963+
var _marine_ttrpg = new TTRPG_stats("chapter", company, k);
2964+
struct_set(UUID_marine, _marine_ttrpg.UUID, _marine_ttrpg )
2965+
TTRPG[company][k] = UUID_marine[$ _marine_ttrpg.UUID];
29622966
loc[company][k] = home_name;
29632967
role[company][k] = roles.chaplain;
29642968
wep1[company][k] = wep1[defaults_slot, eROLE.Chaplain];
@@ -3352,7 +3356,10 @@ function add_veh_to_company(name, company, slot, wep1, wep2, wep3, upgrade, acce
33523356
/// Use "" if you want to set weapons and gear via squad layouts.
33533357
/// "default" will set it to the value in the default slot for the given role, see `load_default_gear`
33543358
function add_unit_to_company(ttrpg_name, company, slot, role_name, role_id, wep1="default", wep2="default", gear="default", mobi="default", armour="default"){
3355-
obj_ini.TTRPG[company][slot] = new TTRPG_stats("chapter", company, slot, ttrpg_name);
3359+
var _marine_ttrpg = new TTRPG_stats("chapter", company, slot, ttrpg_name);
3360+
struct_set(obj_ini.UUID_marine, _marine_ttrpg.UUID, _marine_ttrpg)
3361+
3362+
obj_ini.TTRPG[company][slot] = obj_ini.UUID_marine[$ _marine_ttrpg.UUID];
33563363
obj_ini.race[company][slot] = 1;
33573364
obj_ini.loc[company][slot] = obj_ini.home_name;
33583365
obj_ini.role[company][slot] = role_name;

scripts/scr_kill_unit/scr_kill_unit.gml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function scr_kill_unit(company, unit_slot){
1515
scr_loyalty("Lost Standard","+");
1616
}
1717
_unit.remove_from_squad();
18+
struct_remove(obj_ini.UUID_marine, _unit.UUID)
1819
scr_wipe_unit(company, unit_slot)
1920
}
2021

@@ -32,7 +33,7 @@ function scr_wipe_unit(company, unit_slot){
3233
obj_ini.age[company][unit_slot]=0;
3334
obj_ini.mobi[company][unit_slot]="";
3435
obj_ini.bio[company][unit_slot]="";
35-
obj_ini.TTRPG[company][unit_slot].base_group="none";
36+
obj_ini.TTRPG[company][unit_slot] = new TTRPG_stats("chapter", company, unit_slot, "blank"); // create new empty unit structure
3637
}
3738

3839
function kill_and_recover(company, unit_slot, equipment=true, gene_seed_collect=true){
@@ -59,4 +60,4 @@ function kill_and_recover(company, unit_slot, equipment=true, gene_seed_collect=
5960
}
6061
}
6162
scr_kill_unit(company, unit_slot);
62-
}
63+
}

scripts/scr_load/scr_load.gml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,28 @@ function scr_load(save_part, save_id) {
347347
obj_ini.mobi[coh,mah]=ini_read_string("Mar","mb"+string(coh)+"."+string(mah),"");
348348
}
349349

350+
for (coh = 0; coh <= 10; coh++) {
351+
for (mah = 0; mah <= 500; mah++) {
352+
obj_ini.TTRPG[coh, mah] = new TTRPG_stats("chapter", coh, mah, "blank");
353+
}
354+
}
355+
356+
// We need to move these functions in these marine structs into a seperate struct
357+
var _UUID_marine_temp = return_json_from_ini("Mar", "UUID_marine", {});
358+
var _UUID_names = struct_get_names(_UUID_marine_temp);
359+
var _UUID_count = array_length(_UUID_names);
360+
for (var i = 0; i < _UUID_count; i++) {
361+
var _string_UUID = _UUID_names[i];
362+
var _UUID_marine = new TTRPG_stats("chapter", 0, 0, "blank");
363+
_UUID_marine.load_json_data(_UUID_marine_temp[$ _string_UUID]);
364+
struct_set(obj_ini.UUID_marine, _string_UUID, _UUID_marine)
365+
366+
var _UUID_root = obj_ini.UUID_marine[$ _string_UUID];
367+
var _comp = _UUID_root.company;
368+
var _mar = _UUID_root.marine_number;
369+
obj_ini.TTRPG[_comp][_mar] = _UUID_root;
370+
}
371+
350372
// TODO: When modding support is implemented, uncomment this init. Otherwise traits are initialized at compile.
351373
// initialize_marine_traits();
352374
for (coh=0;coh<=10;coh++){
@@ -380,7 +402,6 @@ function scr_load(save_part, save_id) {
380402
obj_ini.age[coh,mah]=ini_read_real("Mar","ag"+string(coh)+"."+string(mah),0);
381403
obj_ini.spe[coh,mah]=ini_read_string("Mar","spe"+string(coh)+"."+string(mah),"");
382404
obj_ini.god[coh,mah]=ini_read_real("Mar","god"+string(coh)+"."+string(mah),0);
383-
load_marine_struct(coh,mah);
384405
unit = obj_ini.TTRPG[coh,mah];
385406
if (string_length(unit.weapon_one()) != 0 && string_length(string_digits(unit.weapon_one())) == string_length(unit.weapon_one())) {
386407
obj_ini.wep1[coh, mah] = real(obj_ini.wep1[coh, mah]);

scripts/scr_marine_struct/scr_marine_struct.gml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ global.base_stats = {
404404
};
405405

406406
function TTRPG_stats(faction, comp, mar, class = "marine", other_spawn_data = {}) constructor {
407+
UUID = "";
408+
if (class != "blank") {
409+
UUID = $"U{scr_uuid_generate()}";
410+
}
407411
constitution = 0;
408412
strength = 0;
409413
luck = 0;
Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
21
function scr_move_unit_info(start_company,end_company, start_slot, end_slot, eval_squad=true){
32

4-
//eval_squad : determine whether movement of units between companies should decide to check their squad coherency or not, defaults to true
5-
6-
//this makes sure coherency of the unit's squad and the squads logging of the unit location are kept up to date
7-
var unit = obj_ini.TTRPG[start_company, start_slot];
8-
if (eval_squad){
9-
unit.movement_after_math(end_company,end_slot);
10-
}
11-
obj_ini.spe[end_company][end_slot]=obj_ini.spe[start_company][start_slot];
12-
obj_ini.race[end_company][end_slot]=obj_ini.race[start_company][start_slot];
13-
obj_ini.loc[end_company][end_slot]=obj_ini.loc[start_company][start_slot];
14-
obj_ini.name[end_company][end_slot]=obj_ini.name[start_company][start_slot];
15-
obj_ini.wep1[end_company][end_slot]=obj_ini.wep1[start_company][start_slot];
16-
obj_ini.role[end_company][end_slot]=obj_ini.role[start_company][start_slot];
17-
obj_ini.wep2[end_company][end_slot]=obj_ini.wep2[start_company][start_slot];
18-
obj_ini.gear[end_company][end_slot]=obj_ini.gear[start_company][start_slot];
19-
obj_ini.armour[end_company][end_slot]=obj_ini.armour[start_company][start_slot];
20-
obj_ini.god[end_company][end_slot]=obj_ini.god[start_company][start_slot];
21-
obj_ini.age[end_company][end_slot]=obj_ini.age[start_company][start_slot];
22-
obj_ini.mobi[end_company][end_slot]=obj_ini.mobi[start_company][start_slot];
23-
var temp_struct = jsonify_marine_struct(start_company,start_slot); //jsonified for stransfer of struct (makes a deep copy)
24-
obj_ini.TTRPG[end_company][end_slot] = new TTRPG_stats("chapter", end_company,end_slot ,"blank"); // create new empty unit structure
25-
if (is_string(temp_struct)){
26-
obj_ini.TTRPG[end_company][end_slot].load_json_data(json_parse(temp_struct)); //load in originoal marine data
27-
obj_ini.TTRPG[end_company][end_slot].company = end_company;
28-
obj_ini.TTRPG[end_company][end_slot].marine_number = end_slot;
29-
} else {
30-
obj_ini.TTRPG[end_company][end_slot] = new TTRPG_stats("chapter", end_company,end_slot ,"blank");
31-
}
3+
//eval_squad : determine whether movement of units between companies should decide to check their squad coherency or not, defaults to true
4+
5+
//this makes sure coherency of the unit's squad and the squads logging of the unit location are kept up to date
6+
var unit = obj_ini.TTRPG[start_company, start_slot];
7+
if (eval_squad){
8+
unit.movement_after_math(end_company,end_slot);
9+
}
10+
obj_ini.spe[end_company][end_slot]=obj_ini.spe[start_company][start_slot];
11+
obj_ini.race[end_company][end_slot]=obj_ini.race[start_company][start_slot];
12+
obj_ini.loc[end_company][end_slot]=obj_ini.loc[start_company][start_slot];
13+
obj_ini.name[end_company][end_slot]=obj_ini.name[start_company][start_slot];
14+
obj_ini.wep1[end_company][end_slot]=obj_ini.wep1[start_company][start_slot];
15+
obj_ini.role[end_company][end_slot]=obj_ini.role[start_company][start_slot];
16+
obj_ini.wep2[end_company][end_slot]=obj_ini.wep2[start_company][start_slot];
17+
obj_ini.gear[end_company][end_slot]=obj_ini.gear[start_company][start_slot];
18+
obj_ini.armour[end_company][end_slot]=obj_ini.armour[start_company][start_slot];
19+
obj_ini.god[end_company][end_slot]=obj_ini.god[start_company][start_slot];
20+
obj_ini.age[end_company][end_slot]=obj_ini.age[start_company][start_slot];
21+
obj_ini.mobi[end_company][end_slot]=obj_ini.mobi[start_company][start_slot];
22+
obj_ini.TTRPG[end_company][end_slot] = new TTRPG_stats("chapter", end_company, end_slot, "blank"); // create new empty unit structure
23+
obj_ini.TTRPG[end_company][end_slot] = obj_ini.TTRPG[start_company][start_slot]; //load in originoal marine data
24+
obj_ini.TTRPG[end_company][end_slot].company = end_company;
25+
obj_ini.TTRPG[end_company][end_slot].marine_number = end_slot;
3226

33-
scr_wipe_unit(start_company,start_slot);
34-
}
27+
scr_wipe_unit(start_company,start_slot);
28+
}

scripts/scr_save/scr_save.gml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,16 +476,12 @@ function scr_save(save_part,save_id) {
476476
ini_write_real("Mar",$"ag{coh}.{mah}",obj_ini.age[coh,mah]);
477477
ini_write_string("Mar",$"spe{coh}.{mah}",obj_ini.spe[coh,mah]);
478478
ini_write_real("Mar",$"god{coh}.{mah}",obj_ini.god[coh,mah]);
479-
if (!is_struct(obj_ini.TTRPG[coh][mah])){
480-
TTRPG[coh][mah] = new TTRPG_stats("chapter", coh,mah, "blank");
481-
} else{
482-
ini_write_string("Mar",$"Struct{coh}.{mah}",base64_encode(jsonify_marine_struct(coh,mah)));
483-
}
484479
} else {
485480
if (mah>0) then break;
486481
}
487482
}
488483
}
484+
ini_encode_and_json_advanced("Mar", "UUID_marine", obj_ini.UUID_marine);
489485
log_message("Saving to slot "+string(save_id)+" - Squad Saving Start");
490486
var squad_copies = [];
491487
if (array_length(obj_ini.squads)> 0){

0 commit comments

Comments
 (0)