Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Until now, Firmament has used dynamic {} objects for storing and passing around configuration arounddata. 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!

...

Code Block
class MyComponent extends FEntityComponent  {
	var _eventsmyVar:DynamicFloat;
	public function new(){
		super();
		
	}
	override public function init(config:DynamicFConfig){
		if(Reflect.isObject(config.events)){
			_events = config.events;
		}else{
			throw "events property missing for sound component";
		_myVar = config.get("myVar",Float,0);
		//Same, but without validation or default:
		_myvar = config["myVar"];
		//can also write with array access:
		config["myVar"] = 2.5;
	}
}