From fa00140d2361b2d025e759c01ad6bfc6bfc4bad7 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Thu, 18 Jan 2024 04:25:15 -0500 Subject: [PATCH] stringify moved to SongEventSchema --- source/funkin/data/event/SongEventSchema.hx | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/source/funkin/data/event/SongEventSchema.hx b/source/funkin/data/event/SongEventSchema.hx index b5b2978d7..7ebaa5ae1 100644 --- a/source/funkin/data/event/SongEventSchema.hx +++ b/source/funkin/data/event/SongEventSchema.hx @@ -15,7 +15,7 @@ abstract SongEventSchema(SongEventSchemaRaw) } @:arrayAccess - public inline function getByName(name:String):SongEventSchemaField + public function getByName(name:String):SongEventSchemaField { for (field in this) { @@ -41,6 +41,32 @@ abstract SongEventSchema(SongEventSchemaRaw) { 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;