FunkinCrew / Funkin

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

Enhancement: Property support for HScript #3781

Open AbnormalPoof opened 5 days ago

AbnormalPoof commented 5 days ago

Issue Checklist

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

Properties are a Haxe language feature which are similar to variables, but invoke specific functions upon read/write (known as getter/setter functions).

This would be a huge improvement, especially for save data related stuff. It'd save lots of repeated lines related to saving.

Example

Before

/**
 * The character IDs.
 * This is retrieved from the save data.
 */
public var characterIDs:Dynamic;

// This is called in new()
initializeCharIDs();

// This is repeated a few times throughout the code. Mainly when characterIDs is modified.
Save.instance.modOptions.set("FunkerSelector", characterIDs);
Save.instance.flush();

After

/**
 * The character IDs.
 * This is retrieved from the save data.
 */
public var characterIDs(get, set):Dynamic;

function get_characterIDs():Dynamic {
    var defaultCharacterIDs:Dynamic = {
        bf: 'default',
        gf: 'default',
        dad: 'default'
    };

    return Save.instance.modOptions.get("FunkerSelector") != null ? Save.instance.modOptions.get("FunkerSelector") : defaultCharacterIDs;
}

function set_characterIDs(value:Dynamic):Dynamic {
    characterIDs = value;
    Save.instance.modOptions.set("FunkerSelector", characterIDs);
    Save.instance.flush();
}

Save data might not really be a good example of this, but there's a lot of other use cases out there.

github-actions[bot] commented 5 days ago

Potential duplicates:

AbnormalPoof commented 5 days ago

At least you tried

github-actions[bot] commented 5 days ago

Potential duplicates:

NotHyper-474 commented 5 days ago

I'm crying why did it do it again 😭 😭

Edit: Apparently it does this check again if you edit your issue

Keoiki commented 5 days ago

Yes please, the closer hscript is normal haxe the better, right?

This, the null coalescing and the experiment Eric has where you can just type custom class declarations and more without using scriptCall/Set/Get (this one will probably take quite a while though), then we'll be perfect.