Compare commits

...

4 commits

Author SHA1 Message Date
lemz
5b6902e8e1
Merge 557d6cb667 into 0d8e4a5330 2024-11-06 19:15:24 +00:00
lemz1
557d6cb667 lol 2024-11-06 20:15:24 +01:00
lemz1
c7b9214ca8 no more registryInstance i guess 2024-11-06 19:06:54 +01:00
lemz1
dbd9e5c7e0 Update NoteStyle.hx 2024-11-06 18:48:17 +01:00
4 changed files with 30 additions and 70 deletions

View file

@ -3,6 +3,7 @@ package funkin.data.dialogue.conversation;
import funkin.play.cutscene.dialogue.Conversation;
import funkin.play.cutscene.dialogue.ScriptedConversation;
@:build(funkin.util.macro.RegistryMacro.build())
class ConversationRegistry extends BaseRegistry<Conversation, ConversationData>
{
/**
@ -14,15 +15,6 @@ class ConversationRegistry extends BaseRegistry<Conversation, ConversationData>
public static final CONVERSATION_DATA_VERSION_RULE:thx.semver.VersionRule = "1.0.x";
public static var instance(get, never):ConversationRegistry;
static var _instance:Null<ConversationRegistry> = null;
static function get_instance():ConversationRegistry
{
if (_instance == null) _instance = new ConversationRegistry();
return _instance;
}
public function new()
{
super('CONVERSATION', 'dialogue/conversations', CONVERSATION_DATA_VERSION_RULE);
@ -74,14 +66,4 @@ class ConversationRegistry extends BaseRegistry<Conversation, ConversationData>
}
return parser.value;
}
function createScriptedEntry(clsName:String):Conversation
{
return ScriptedConversation.init(clsName, "unknown");
}
function getScriptedClassNames():Array<String>
{
return ScriptedConversation.listScriptClasses();
}
}

View file

@ -30,6 +30,8 @@ import funkin.util.EaseUtil;
*
* This shit is great for modders but it's pretty elaborate for how much it'll actually be used, lolol. -Eric
*/
@:build(funkin.util.macro.EntryMacro.build(funkin.data.dialogue.conversation.ConversationRegistry, funkin.data.dialogue.speaker.SpeakerRegistry,
funkin.data.dialogue.dialoguebox.DialogueBoxRegistry))
class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass implements IRegistryEntry<ConversationData>
{
/**
@ -636,11 +638,6 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl
{
return 'Conversation($id)';
}
static function _fetchData(id:String):Null<ConversationData>
{
return ConversationRegistry.instance.parseEntryDataWithMigration(id, ConversationRegistry.instance.fetchEntryVersion(id));
}
}
// Managing things with a single enum is a lot easier than a multitude of flags.

View file

@ -35,7 +35,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
function get_fallback():Null<NoteStyle>
{
if (_data == null || _data.fallback == null) return null;
return registryInstance.fetchEntry(_data.fallback);
return NoteStyleRegistry.instance.fetchEntry(_data.fallback);
}
/**
@ -879,7 +879,7 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
static function _fetchData(id:String):NoteStyleData
{
var result = registryInstance.parseEntryDataWithMigration(id, registryInstance.fetchEntryVersion(id));
var result = NoteStyleRegistry.instance.parseEntryDataWithMigration(id, NoteStyleRegistry.instance.fetchEntryVersion(id));
if (result == null)
{

View file

@ -4,11 +4,12 @@ import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using haxe.macro.ExprTools;
using StringTools;
class EntryMacro
{
public static macro function build(registryExpr:ExprOf<Class<Dynamic>>):Array<Field>
public static macro function build(registryExpr:ExprOf<Class<Dynamic>>, ...additionalReferencedRegistries:ExprOf<Class<Dynamic>>):Array<Field>
{
var fields = Context.getBuildFields();
@ -16,13 +17,13 @@ class EntryMacro
var entryData = getEntryData(cls);
makeReferenceRegistryFieldsCallable(additionalReferencedRegistries.append(registryExpr), fields);
buildIdField(fields);
buildDataField(entryData, fields);
buildRegistryInstanceField(registryExpr, fields);
buildFetchDataField(entryData, fields);
buildFetchDataField(entryData, registryExpr, fields);
buildToStringField(cls, fields);
@ -100,52 +101,32 @@ class EntryMacro
});
}
static function buildRegistryInstanceField(registryExpr:ExprOf<Class<Dynamic>>, fields:Array<Field>):Void
static function makeReferenceRegistryFieldsCallable(registryExprs:Array<ExprOf<Class<Dynamic>>>, fields:Array<Field>):Void
{
if (!shouldBuildField('registryInstance', fields))
for (registryExpr in registryExprs)
{
return;
}
var registryCls = MacroUtil.getClassTypeFromExpr(registryExpr);
var expr:String = '${registryExpr.toString()}.instance';
var registryCls = MacroUtil.getClassTypeFromExpr(registryExpr);
fields.push(
{
name: 'registryInstance',
access: [Access.APrivate, Access.AStatic],
kind: FieldType.FProp("get", "never", ComplexType.TPath(
{
pack: registryCls.pack,
name: registryCls.name,
params: []
})),
pos: Context.currentPos()
});
fields.push(
{
name: 'get_registryInstance',
access: [Access.APrivate, Access.AStatic],
kind: FFun(
{
args: [],
expr: macro
fields.push(
{
name: '_${registryCls.pack.join('_')}_${registryCls.name}',
access: [Access.APrivate, Access.AStatic],
kind: FFun(
{
return ${registryExpr}.instance;
},
params: [],
ret: ComplexType.TPath(
args: [],
expr: macro
{
pack: registryCls.pack,
name: registryCls.name,
params: []
})
}),
pos: Context.currentPos()
});
return ${registryExpr}.instance;
},
params: []
}),
pos: Context.currentPos()
});
}
}
static function buildFetchDataField(entryData:Dynamic, fields:Array<Field>):Void
static function buildFetchDataField(entryData:Dynamic, registryExpr:ExprOf<Class<Dynamic>>, fields:Array<Field>):Void
{
if (!shouldBuildField('_fetchData', fields))
{
@ -166,7 +147,7 @@ class EntryMacro
],
expr: macro
{
return registryInstance.parseEntryDataWithMigration(id, registryInstance.fetchEntryVersion(id));
return ${registryExpr}.instance.parseEntryDataWithMigration(id, ${registryExpr}.instance.fetchEntryVersion(id));
},
params: [],
ret: ComplexType.TPath(