Skip to content

Commit

Permalink
registryInstance field
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Oct 13, 2024
1 parent e06b93c commit 94f4983
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 61 deletions.
27 changes: 13 additions & 14 deletions source/funkin/play/notes/notestyle/NoteStyle.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
function get_fallback():Null<NoteStyle>
{
if (_data == null || _data.fallback == null) return null;
return null;
// return NoteStyleRegistry.instance.fetchEntry(_data.fallback);
return registryInstance.fetchEntry(_data.fallback);
}

/**
Expand Down Expand Up @@ -890,16 +889,16 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
return 'NoteStyle($id)';
}

// static function _fetchData(id:String):NoteStyleData
// {
// var result = NoteStyleRegistry.instance.parseEntryDataWithMigration(id, NoteStyleRegistry.instance.fetchEntryVersion(id));
// if (result == null)
// {
// throw 'Could not parse note style data for id: $id';
// }
// else
// {
// return result;
// }
// }
static function _fetchData(id:String):NoteStyleData
{
var result = registryInstance.parseEntryDataWithMigration(id, registryInstance.fetchEntryVersion(id));
if (result == null)
{
throw 'Could not parse note style data for id: $id';
}
else
{
return result;
}
}
}
85 changes: 38 additions & 47 deletions source/funkin/util/macro/EntryMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,54 @@ class EntryMacro
{
var fields = Context.getBuildFields();

var cls = Context.getLocalClass().get();

var registryCls = MacroUtil.getClassTypeFromExpr(registryExpr);

fields.push(build_fetchDataField(registryExpr));
fields = fields.concat(buildRegistryInstanceField(registryExpr));

return fields;
}

#if macro
static function build_fetchDataField(registryExpr:ExprOf<Class<Dynamic>>):Field
static function buildRegistryInstanceField(registryExpr:ExprOf<Class<Dynamic>>):Array<Field>
{
return {
name: '_fetchData',
access: [Access.APrivate],
kind: FieldType.FFun(
{
args: [
{
name: 'id',
type: (macro :String)
}
],
expr: macro
{
var result = ${registryExpr}.instance.parseEntryDataWithMigration(id, ${registryExpr}.instance.fetchEntryVersion(id));
var fields = [];

if (result == null)
{
throw 'Could not parse note style data for id: ' + id;
}
else
{
return result;
}
},
params: [],
ret: (macro :funkin.data.notestyle.NoteStyleData)
}),
pos: Context.currentPos()
};
var registryCls = MacroUtil.getClassTypeFromExpr(registryExpr);

/**
* static function _fetchData(id:String):NoteStyleData
fields.push(
{
var result = NoteStyleRegistry.instance.parseEntryDataWithMigration(id, NoteStyleRegistry.instance.fetchEntryVersion(id));
name: 'registryInstance',
access: [Access.APrivate, Access.AStatic],
kind: FieldType.FProp("get", "never", ComplexType.TPath(
{
pack: registryCls.pack,
name: registryCls.name,
params: []
})),
pos: Context.currentPos()
});

if (result == null)
{
throw 'Could not parse note style data for id: $id';
}
else
{
return result;
}
}
*/
fields.push(
{
name: 'get_registryInstance',
access: [Access.APrivate, Access.AStatic],
kind: FFun(
{
args: [],
expr: macro
{
return ${registryExpr}.instance;
},
params: [],
ret: ComplexType.TPath(
{
pack: registryCls.pack,
name: registryCls.name,
params: []
})
}),
pos: Context.currentPos()
});

return fields;
}
#end
}

0 comments on commit 94f4983

Please sign in to comment.