stringify moved to SongEventSchema

This commit is contained in:
Cameron Taylor 2024-01-18 04:25:15 -05:00
parent 210088a25d
commit fa00140d23

View file

@ -15,7 +15,7 @@ abstract SongEventSchema(SongEventSchemaRaw)
} }
@:arrayAccess @:arrayAccess
public inline function getByName(name:String):SongEventSchemaField public function getByName(name:String):SongEventSchemaField
{ {
for (field in this) for (field in this)
{ {
@ -41,6 +41,32 @@ abstract SongEventSchema(SongEventSchemaRaw)
{ {
return this[k] = v; return this[k] = v;
} }
public function stringifyFieldValue(name:String, value:Dynamic):String
{
var field:SongEventSchemaField = getByName(name);
if (field == null) return 'Unknown';
switch (field.type)
{
case SongEventFieldType.STRING:
return Std.string(value);
case SongEventFieldType.INTEGER:
return Std.string(value);
case SongEventFieldType.FLOAT:
return Std.string(value);
case SongEventFieldType.BOOL:
return Std.string(value);
case SongEventFieldType.ENUM:
for (key in field.keys.keys())
{
if (field.keys.get(key) == value) return key;
}
return Std.string(value);
default:
return 'Unknown';
}
}
} }
typedef SongEventSchemaRaw = Array<SongEventSchemaField>; typedef SongEventSchemaRaw = Array<SongEventSchemaField>;