Skip to content

Commit

Permalink
add these registries back
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 7, 2024
1 parent 488ba73 commit 273bdcf
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 207 deletions.
67 changes: 1 addition & 66 deletions source/funkin/data/dialogue/conversation/ConversationRegistry.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
{
/**
Expand All @@ -14,74 +15,8 @@ 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);
}

/**
* Read, parse, and validate the JSON data and produce the corresponding data object.
*/
public function parseEntryData(id:String):Null<ConversationData>
{
// JsonParser does not take type parameters,
// otherwise this function would be in BaseRegistry.
var parser = new json2object.JsonParser<ConversationData>();
parser.ignoreUnknownVariables = false;

switch (loadEntryFile(id))
{
case {fileName: fileName, contents: contents}:
parser.fromJson(contents, fileName);
default:
return null;
}

if (parser.errors.length > 0)
{
printErrors(parser.errors, id);
return null;
}
return parser.value;
}

/**
* Parse and validate the JSON data and produce the corresponding data object.
*
* NOTE: Must be implemented on the implementation class.
* @param contents The JSON as a string.
* @param fileName An optional file name for error reporting.
*/
public function parseEntryDataRaw(contents:String, ?fileName:String):Null<ConversationData>
{
var parser = new json2object.JsonParser<ConversationData>();
parser.ignoreUnknownVariables = false;
parser.fromJson(contents, fileName);

if (parser.errors.length > 0)
{
printErrors(parser.errors, fileName);
return null;
}
return parser.value;
}

function createScriptedEntry(clsName:String):Conversation
{
return ScriptedConversation.init(clsName, "unknown");
}

function getScriptedClassNames():Array<String>
{
return ScriptedConversation.listScriptClasses();
}
}
67 changes: 1 addition & 66 deletions source/funkin/data/notestyle/NoteStyleRegistry.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import funkin.play.notes.notestyle.NoteStyle;
import funkin.play.notes.notestyle.ScriptedNoteStyle;
import funkin.data.notestyle.NoteStyleData;

@:build(funkin.util.macro.RegistryMacro.build())
class NoteStyleRegistry extends BaseRegistry<NoteStyle, NoteStyleData>
{
/**
Expand All @@ -15,15 +16,6 @@ class NoteStyleRegistry extends BaseRegistry<NoteStyle, NoteStyleData>

public static final NOTE_STYLE_DATA_VERSION_RULE:thx.semver.VersionRule = "1.1.x";

public static var instance(get, never):NoteStyleRegistry;
static var _instance:Null<NoteStyleRegistry> = null;

static function get_instance():NoteStyleRegistry
{
if (_instance == null) _instance = new NoteStyleRegistry();
return _instance;
}

public function new()
{
super('NOTESTYLE', 'notestyles', NOTE_STYLE_DATA_VERSION_RULE);
Expand All @@ -33,61 +25,4 @@ class NoteStyleRegistry extends BaseRegistry<NoteStyle, NoteStyleData>
{
return fetchEntry(Constants.DEFAULT_NOTE_STYLE);
}

/**
* Read, parse, and validate the JSON data and produce the corresponding data object.
*/
public function parseEntryData(id:String):Null<NoteStyleData>
{
// JsonParser does not take type parameters,
// otherwise this function would be in BaseRegistry.
var parser = new json2object.JsonParser<NoteStyleData>();
parser.ignoreUnknownVariables = false;

switch (loadEntryFile(id))
{
case {fileName: fileName, contents: contents}:
parser.fromJson(contents, fileName);
default:
return null;
}

if (parser.errors.length > 0)
{
printErrors(parser.errors, id);
return null;
}
return parser.value;
}

/**
* Parse and validate the JSON data and produce the corresponding data object.
*
* NOTE: Must be implemented on the implementation class.
* @param contents The JSON as a string.
* @param fileName An optional file name for error reporting.
*/
public function parseEntryDataRaw(contents:String, ?fileName:String):Null<NoteStyleData>
{
var parser = new json2object.JsonParser<NoteStyleData>();
parser.ignoreUnknownVariables = false;
parser.fromJson(contents, fileName);

if (parser.errors.length > 0)
{
printErrors(parser.errors, fileName);
return null;
}
return parser.value;
}

function createScriptedEntry(clsName:String):NoteStyle
{
return ScriptedNoteStyle.init(clsName, "unknown");
}

function getScriptedClassNames():Array<String>
{
return ScriptedNoteStyle.listScriptClasses();
}
}
24 changes: 1 addition & 23 deletions source/funkin/data/song/SongRegistry.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import funkin.util.VersionUtil;
using funkin.data.song.migrator.SongDataMigrator;

@:nullSafety
@:build(funkin.util.macro.RegistryMacro.build())
class SongRegistry extends BaseRegistry<Song, SongMetadata>
{
/**
Expand All @@ -39,19 +40,6 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
return '${Constants.TITLE} - ${Constants.VERSION}';
}

/**
* TODO: What if there was a Singleton macro which automatically created the property for us?
*/
public static var instance(get, never):SongRegistry;

static var _instance:Null<SongRegistry> = null;

static function get_instance():SongRegistry
{
if (_instance == null) _instance = new SongRegistry();
return _instance;
}

public function new()
{
super('SONG', 'songs', SONG_METADATA_VERSION_RULE);
Expand Down Expand Up @@ -417,16 +405,6 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
}
}

function createScriptedEntry(clsName:String):Song
{
return ScriptedSong.init(clsName, "unknown");
}

function getScriptedClassNames():Array<String>
{
return ScriptedSong.listScriptClasses();
}

function loadEntryMetadataFile(id:String, ?variation:String):Null<JsonFile>
{
variation = variation == null ? Constants.DEFAULT_VARIATION : variation;
Expand Down
22 changes: 2 additions & 20 deletions source/funkin/play/cutscene/dialogue/Conversation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,15 @@ 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.dialoguebox.DialogueBoxRegistry,
funkin.data.dialogue.speaker.SpeakerRegistry))
class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass implements IRegistryEntry<ConversationData>
{
/**
* The ID of the conversation.
*/
public final id:String;

/**
* The current state of the conversation.
*/
var state:ConversationState = ConversationState.Start;

/**
* Conversation data as parsed from the JSON file.
*/
public final _data:ConversationData;

/**
* The current entry in the dialogue.
*/
Expand Down Expand Up @@ -631,16 +623,6 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl
outroTween = null;
}
}

public override function toString():String
{
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.
Expand Down
13 changes: 1 addition & 12 deletions source/funkin/play/notes/notestyle/NoteStyle.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ using funkin.data.animation.AnimationData.AnimationDataUtil;
* and provides convenience methods for building sprites based on them.
*/
@:nullSafety
@:build(funkin.util.macro.EntryMacro.build(funkin.data.notestyle.NoteStyleRegistry))
class NoteStyle implements IRegistryEntry<NoteStyleData>
{
/**
* The ID of the note style.
*/
public final id:String;

/**
* Note style data as parsed from the JSON file.
*/
Expand Down Expand Up @@ -881,13 +877,6 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
}
}

public function destroy():Void {}

public function toString():String
{
return 'NoteStyle($id)';
}

static function _fetchData(id:String):NoteStyleData
{
var result = NoteStyleRegistry.instance.parseEntryDataWithMigration(id, NoteStyleRegistry.instance.fetchEntryVersion(id));
Expand Down
21 changes: 1 addition & 20 deletions source/funkin/play/song/Song.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import funkin.util.SortUtil;
* can be used to perform custom gameplay behaviors only on specific songs.
*/
@:nullSafety
@:build(funkin.util.macro.EntryMacro.build(funkin.data.song.SongRegistry))
class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMetadata>
{
/**
Expand Down Expand Up @@ -65,19 +66,6 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
*/
public static final DEFAULT_SCROLLSPEED:Float = 1.0;

/**
* The internal ID of the song.
*/
public final id:String;

/**
* Song metadata as parsed from the JSON file.
* This is the data for the `default` variation specifically,
* and is needed for the IRegistryEntry interface.
* Will only be null if the song data could not be loaded.
*/
public final _data:Null<SongMetadata>;

// key = variation id, value = metadata
final _metadata:Map<String, SongMetadata>;

Expand Down Expand Up @@ -624,13 +612,6 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
}
}

public function toString():String
{
return 'Song($id)';
}

public function destroy():Void {}

public function onPause(event:PauseScriptEvent):Void {};

public function onResume(event:ScriptEvent):Void {};
Expand Down

0 comments on commit 273bdcf

Please sign in to comment.