Skip to content

Enhancement: Property support for HScript #3781

Open
@AbnormalPoof

Description

Issue Checklist

  • I have properly named my enhancement
  • I have checked the Issues/Discussions pages to see if my enhancement has already been suggested

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: pending pull requestDependent on a pull request that is currently awaiting review.topic: modsRelated to the creation or use of mods.type: enhancementInvolves an enhancement or new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions