Skip to content

Commit

Permalink
for the love of god
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Sep 17, 2024
1 parent 3d72c0f commit 668a313
Showing 1 changed file with 2 additions and 106 deletions.
108 changes: 2 additions & 106 deletions source/funkin/data/song/SongData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -760,119 +760,15 @@ class SongEventDataRaw implements ICloneable<SongEventDataRaw>
/**
* Wrap SongEventData in an abstract so we can overload operators.
*/
@:forward(time, eventKind, value, activated, getStepTime, clone)
@:forward(time, eventKind, value, activated, getStepTime, clone, getHandler, getSchema, getDynamic, getBool, getInt, getFloat, getString, getArray,
getBoolArray, buildTooltip, valueAsStruct)
abstract SongEventData(SongEventDataRaw) from SongEventDataRaw to SongEventDataRaw
{
public function new(time:Float, eventKind:String, value:Dynamic = null)
{
this = new SongEventDataRaw(time, eventKind, value);
}

public function valueAsStruct(?defaultKey:String = "key"):Dynamic
{
if (this.value == null) return {};
if (Std.isOfType(this.value, Array))
{
var result:haxe.DynamicAccess<Dynamic> = {};
result.set(defaultKey, this.value);
return cast result;
}
else if (Reflect.isObject(this.value))
{
// We enter this case if the value is a struct.
return cast this.value;
}
else
{
var result:haxe.DynamicAccess<Dynamic> = {};
result.set(defaultKey, this.value);
return cast result;
}
}

public function getHandler():Null<SongEvent>
{
return SongEventRegistry.getEvent(this.eventKind);
}

public function getSchema():Null<SongEventSchema>
{
return SongEventRegistry.getEventSchema(this.eventKind);
}

public function getDynamic(key:String):Null<Dynamic>
{
return this.value == null ? null : Reflect.field(this.value, key);
}

public function getBool(key:String):Null<Bool>
{
return this.value == null ? null : cast Reflect.field(this.value, key);
}

public function getInt(key:String):Null<Int>
{
if (this.value == null) return null;
var result = Reflect.field(this.value, key);
if (result == null) return null;
if (Std.isOfType(result, Int)) return result;
if (Std.isOfType(result, String)) return Std.parseInt(cast result);
return cast result;
}

public function getFloat(key:String):Null<Float>
{
if (this.value == null) return null;
var result = Reflect.field(this.value, key);
if (result == null) return null;
if (Std.isOfType(result, Float)) return result;
if (Std.isOfType(result, String)) return Std.parseFloat(cast result);
return cast result;
}

public function getString(key:String):String
{
return this.value == null ? null : cast Reflect.field(this.value, key);
}

public function getArray(key:String):Array<Dynamic>
{
return this.value == null ? null : cast Reflect.field(this.value, key);
}

public function getBoolArray(key:String):Array<Bool>
{
return this.value == null ? null : cast Reflect.field(this.value, key);
}

public function buildTooltip():String
{
var eventHandler = getHandler();
var eventSchema = getSchema();

if (eventSchema == null) return 'Unknown Event: ${this.eventKind}';

var result = '${eventHandler.getTitle()}';

var defaultKey = eventSchema.getFirstField()?.name;
var valueStruct:haxe.DynamicAccess<Dynamic> = valueAsStruct(defaultKey);

for (pair in valueStruct.keyValueIterator())
{
var key = pair.key;
var value = pair.value;

var title = eventSchema.getByName(key)?.title ?? 'UnknownField';

// if (eventSchema.stringifyFieldValue(key, value) != null) trace(eventSchema.stringifyFieldValue(key, value));
var valueStr = eventSchema.stringifyFieldValue(key, value) ?? 'UnknownValue';

result += '\n- ${title}: ${valueStr}';
}

return result;
}

public function clone():SongEventData
{
return new SongEventData(this.time, this.eventKind, this.value);
Expand Down

0 comments on commit 668a313

Please sign in to comment.