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.Conversation;
import funkin.play.cutscene.dialogue.ScriptedConversation; import funkin.play.cutscene.dialogue.ScriptedConversation;
@:build(funkin.util.macro.RegistryMacro.build())
class ConversationRegistry extends BaseRegistry<Conversation, ConversationData> 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 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() public function new()
{ {
super('CONVERSATION', 'dialogue/conversations', CONVERSATION_DATA_VERSION_RULE); super('CONVERSATION', 'dialogue/conversations', CONVERSATION_DATA_VERSION_RULE);
@ -74,14 +66,4 @@ class ConversationRegistry extends BaseRegistry<Conversation, ConversationData>
} }
return parser.value; 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 * 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> class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass implements IRegistryEntry<ConversationData>
{ {
/** /**
@ -636,11 +638,6 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl
{ {
return 'Conversation($id)'; 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. // 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> function get_fallback():Null<NoteStyle>
{ {
if (_data == null || _data.fallback == null) return null; 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 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) if (result == null)
{ {

View file

@ -4,11 +4,12 @@ import haxe.macro.Context;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Type; import haxe.macro.Type;
using haxe.macro.ExprTools;
using StringTools; using StringTools;
class EntryMacro 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(); var fields = Context.getBuildFields();
@ -16,13 +17,13 @@ class EntryMacro
var entryData = getEntryData(cls); var entryData = getEntryData(cls);
makeReferenceRegistryFieldsCallable(additionalReferencedRegistries.append(registryExpr), fields);
buildIdField(fields); buildIdField(fields);
buildDataField(entryData, fields); buildDataField(entryData, fields);
buildRegistryInstanceField(registryExpr, fields); buildFetchDataField(entryData, registryExpr, fields);
buildFetchDataField(entryData, fields);
buildToStringField(cls, 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(
{
fields.push( name: '_${registryCls.pack.join('_')}_${registryCls.name}',
{ access: [Access.APrivate, Access.AStatic],
name: 'registryInstance', kind: FFun(
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
{ {
return ${registryExpr}.instance; args: [],
}, expr: macro
params: [],
ret: ComplexType.TPath(
{ {
pack: registryCls.pack, return ${registryExpr}.instance;
name: registryCls.name, },
params: [] params: []
}) }),
}), pos: Context.currentPos()
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)) if (!shouldBuildField('_fetchData', fields))
{ {
@ -166,7 +147,7 @@ class EntryMacro
], ],
expr: macro expr: macro
{ {
return registryInstance.parseEntryDataWithMigration(id, registryInstance.fetchEntryVersion(id)); return ${registryExpr}.instance.parseEntryDataWithMigration(id, ${registryExpr}.instance.fetchEntryVersion(id));
}, },
params: [], params: [],
ret: ComplexType.TPath( ret: ComplexType.TPath(