Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Until now, Firmament has used dynamic {} objects for storing and passing around configuration around. This worked, but validating data and handling default values was manual and a pain. To help with this, I created the FConfigHelper class, which would wrap these objects and give you methods for validating etc. However, to keep backwards compatibility, you had to instantiate these helpers on your own. But now, thanks to Haxe's abstract types, we can have all the functionality of FConfigHelpers automatically and with complete forwards and backwards compatibility with the old {} type configs!

Now, FDataLoader returns FConfig objects, instead of Dynamic type {} objects. These FConfig objects can be be implicitly cast between dynamic {} objects and FConfig objects so no backwards compatibility should be broken. You can still use the Reflect methods to read them, but now if you accept the config object as type FConfig, you have access to FConfig's methods, like get:

//Returns the field with name field, validating it has a type of type. If it's not set, returns default.
get(field:String,?type:Dynamic=null,?def:Dynamic=null)

You can also use array-access, though no validation is done when using array access:

class MyComponent extends FEntityComponent  {
	var _events:Dynamic;
	public function new(){
		super();
		
	}
	override public function init(config:Dynamic){
		if(Reflect.isObject(config.events)){
			_events = config.events;
		}else{
			throw "events property missing for sound component";
		}

 

 

  • No labels