Skip to content

Instantly share code, notes, and snippets.

@Geokureli
Last active November 21, 2019 17:43
Show Gist options
  • Save Geokureli/06c50e9bf0e51953e9492bf2a3e54ff3 to your computer and use it in GitHub Desktop.
Save Geokureli/06c50e9bf0e51953e9492bf2a3e54ff3 to your computer and use it in GitHub Desktop.
typedef OgmoEntityData<T>
= {
name :String,
id :Int,
x :Int,
y :Int,
rotation:Float,
originX :Int,
originY :Int,
values :T
}
abstract OgmoValue(String) from String to String
{
public var isEmpty(get, never):Bool;
inline function get_isEmpty() return this == "-1";
inline public function getColor():Null<Int>
{
return isEmpty ? null : (Std.parseInt("0x" + this.substr(1)) >> 8);
}
inline public function getInt ():Null<Int > return isEmpty ? null : Std.parseInt(this);
inline public function getFloat():Null<Float> return isEmpty ? null : Std.parseFloat(this);
inline public function getBool ():Null<Bool > return isEmpty ? null : this == "true";
}
@:forward abstract OgmoInt(OgmoValue) from String to String
{
public var value(get, never):Null<Int>;
inline function get_value() return this.getInt();
}
@:forward abstract OgmoFloat(OgmoValue) from String to String
{
public var value(get, never):Null<Float>;
inline function get_value() return this.getFloat();
}
@:forward abstract OgmoBool(OgmoValue) from String to String
{
public var value(get, never):Null<Bool>;
inline function get_value() return this.getBool();
}
@:forward abstract OgmoColor(OgmoValue) from String to String
{
public var value(get, never):Null<Int>;
inline function get_value() return this.getColor();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment