FunkinCrew / Funkin

A rhythm game made with HaxeFlixel
https://www.newgrounds.com/portal/view/770371
Other
2.97k stars 2.29k forks source link

Enhancement: re-implement StructureUtil #2716

Open cyn0x8 opened 5 months ago

cyn0x8 commented 5 months ago

Please check for duplicates or similar issues before creating this issue.

What is your suggestion, and why should it be implemented?

StructureUtil was removed in the latest release, leaving no easy way to dynamically merge/deep-merge structures (iirc Reflect is blacklisted in hxc)

i was using it for backwards-compatible save data for a mod im working on... re-implementing this class would be extremely helpful so i dont have to null check a ton of variables lol

or, if anyone knows an alternative, please reply with it !!

NotHyper-474 commented 4 months ago

If it's anything of use I found out StructureUtil was originally used in the SaveDataMigrator, but now it's been replaced by thx.Objects and uses its deepCombine function. I wonder if that could be used as a replacement for mods too.

Note: I'm in no way versed in FNF modding lol

cyn0x8 commented 4 months ago

If it's anything of use I found out StructureUtil was originally used in the SaveDataMigrator, but now it's been replaced by thx.Objects and uses its deepCombine function. I wonder if that could be used as a replacement for mods too.

Note: I'm in no way versed in FNF modding lol

this works!! i was able to get it working with thx.Objects and thx.Types

// in utils hxc

public function obj_merge(a:Dynamic, b:Dynamic, exclusive:Bool = false):Dynamic {
    var ret:Dynamic = Objects.clone(a);

    for (path in obj_paths(exclusive ? a : b)) {
        Objects.setPath(ret, path, Objects.getPath(b, path));
    }

    return ret;
}

public function obj_paths(obj:Dynamic):Array<String> {
    var ret:Array<String> = [];

    for (key in Objects.fields(obj)) {
        ret.push(key);

        var val:Dynamic = Objects.getPath(obj, key);
        if (Types.isAnonymousObject(val)) {
            for (sub_key in obj_paths(val)) {
                ret.push(key + "." + sub_key);
            }
        }
    }

    return ret;
}
// in save hxc

save_data = ModuleHandler.getModule("SEVENTEEN_Util").scriptCall("obj_merge", [save_data, Save.instance.modOptions.get("17bucks"), clean_save]);

thoughhhh this essentially is doing what Reflect would be doing... i hope these classes dont get blacklisted either lol