Skip to content

Commit

Permalink
Rewrite conversation JSON parsing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteMasterEric committed Feb 7, 2024
1 parent 401c200 commit fa556dc
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 1,006 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
"target": "windows",
"args": ["-debug", "-DSONG=bopeebo -DDIFFICULTY=normal"]
},
{
"label": "Windows / Debug (Conversation Test)",
"target": "windows",
"args": ["-debug", "-DDIALOGUE"]
},
{
"label": "Windows / Debug (Straight to Chart Editor)",
"target": "windows",
Expand Down
1 change: 0 additions & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
<haxelib name="hxCodec" /> <!-- Video playback -->

<haxelib name="json2object" /> <!-- JSON parsing -->
<haxelib name="tink_json" /> <!-- JSON parsing (DEPRECATED) -->
<haxelib name="thx.semver" /> <!-- Version string handling -->

<haxelib name="hmm" /> <!-- Read library version data at compile time so it can be baked into logs -->
Expand Down
5 changes: 0 additions & 5 deletions hmm.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@
"name": "thx.semver",
"type": "haxelib",
"version": "0.2.2"
},
{
"name": "tink_json",
"type": "haxelib",
"version": "0.11.0"
}
]
}
24 changes: 17 additions & 7 deletions source/funkin/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import funkin.data.level.LevelRegistry;
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.data.event.SongEventRegistry;
import funkin.data.stage.StageRegistry;
import funkin.play.cutscene.dialogue.ConversationDataParser;
import funkin.play.cutscene.dialogue.DialogueBoxDataParser;
import funkin.play.cutscene.dialogue.SpeakerDataParser;
import funkin.data.dialogue.ConversationRegistry;
import funkin.data.dialogue.DialogueBoxRegistry;
import funkin.data.dialogue.SpeakerRegistry;
import funkin.data.song.SongRegistry;
import funkin.play.character.CharacterData.CharacterDataParser;
import funkin.modding.module.ModuleHandler;
Expand Down Expand Up @@ -208,22 +208,30 @@ class InitState extends FlxState
// GAME DATA PARSING
//

trace('Parsing game data...');

var perf_gameDataParse_start = haxe.Timer.stamp();

// NOTE: Registries and data parsers must be imported and not referenced with fully qualified names,
// to ensure build macros work properly.
SongRegistry.instance.loadEntries();
LevelRegistry.instance.loadEntries();
NoteStyleRegistry.instance.loadEntries();
SongEventRegistry.loadEventCache();
ConversationDataParser.loadConversationCache();
DialogueBoxDataParser.loadDialogueBoxCache();
SpeakerDataParser.loadSpeakerCache();
ConversationRegistry.instance.loadEntries();
DialogueBoxRegistry.instance.loadEntries();
SpeakerRegistry.instance.loadEntries();
StageRegistry.instance.loadEntries();
CharacterDataParser.loadCharacterCache();
CharacterDataParser.loadCharacterCache(); // TODO: Migrate characters to BaseRegistry.

ModuleHandler.buildModuleCallbacks();
ModuleHandler.loadModuleCache();

ModuleHandler.callOnCreate();

var perf_gameDataParse_end = haxe.Timer.stamp();

trace('Done parsing game data. Duration: ${perf_gameDataParse_end - perf_gameDataParse_start} seconds');
}

/**
Expand All @@ -241,6 +249,8 @@ class InitState extends FlxState
startLevel(defineLevel(), defineDifficulty());
#elseif FREEPLAY // -DFREEPLAY
FlxG.switchState(new FreeplayState());
#elseif DIALOGUE // -DDIALOGUE
FlxG.switchState(new funkin.ui.debug.dialogue.ConversationDebugState());
#elseif ANIMATE // -DANIMATE
FlxG.switchState(new funkin.ui.debug.anim.FlxAnimateTest());
#elseif WAVEFORM // -DWAVEFORM
Expand Down
62 changes: 62 additions & 0 deletions source/funkin/data/DataParse.hx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,68 @@ class DataParse
}
}

public static function backdropData(json:Json, name:String):BackdropData
{
switch (json.value)
{
case JObject(fields):
var result:BackdropData = {};
var backdropType:String = '';

for (field in fields)
{
switch (field.name)
{
case 'backdropType':
backdropType = Tools.getValue(field.value);
}
Reflect.setField(result, field.name, Tools.getValue(field.value));
}

switch (backdropType)
{
case 'solid':
return SOLID(result);
default:
throw 'Expected Backdrop property $name to be specify a valid "type", but it was "${backdropType}".';
}

return null;
default:
throw 'Expected property $name to be an object, but it was ${json.value}.';
}
}

public static function outroData(json:Json, name:String):OutroData
{
switch (json.value)
{
case JObject(fields):
var result:OutroData = {};
var outroType:String = '';

for (field in fields)
{
switch (field.name)
{
case 'outroType':
outroType = Tools.getValue(field.value);
}
Reflect.setField(result, field.name, Tools.getValue(field.value));
}

switch (outroType)
{
case 'none':
return NONE(result);
case 'fade':
return FADE(result);
default:
throw 'Expected Outro property $name to be specify a valid "type", but it was "${outroType}".';
}
}
}

/**
* Parser which outputs a `Either<Float, LegacyScrollSpeeds>`.
* Used by the FNF legacy JSON importer.
Expand Down
8 changes: 4 additions & 4 deletions source/funkin/modding/PolymodHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ class PolymodHandler
LevelRegistry.instance.loadEntries();
NoteStyleRegistry.instance.loadEntries();
SongEventRegistry.loadEventCache();
ConversationDataParser.loadConversationCache();
DialogueBoxDataParser.loadDialogueBoxCache();
SpeakerDataParser.loadSpeakerCache();
ConversationRegistry.instance.loadEntries();
DialogueBoxRegistry.instance.loadEntries();
SpeakerRegistry.instance.loadEntries();
StageRegistry.instance.loadEntries();
CharacterDataParser.loadCharacterCache();
CharacterDataParser.loadCharacterCache(); // TODO: Migrate characters to BaseRegistry.
ModuleHandler.loadModuleCache();
}
}
4 changes: 2 additions & 2 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import funkin.modding.events.ScriptEventDispatcher;
import funkin.play.character.BaseCharacter;
import funkin.play.character.CharacterData.CharacterDataParser;
import funkin.play.cutscene.dialogue.Conversation;
import funkin.play.cutscene.dialogue.ConversationDataParser;
import funkin.data.dialogue.ConversationRegistry;
import funkin.play.cutscene.VanillaCutscenes;
import funkin.play.cutscene.VideoCutscene;
import funkin.data.event.SongEventRegistry;
Expand Down Expand Up @@ -1662,7 +1662,7 @@ class PlayState extends MusicBeatSubState
{
isInCutscene = true;

currentConversation = ConversationDataParser.fetchConversation(conversationId);
currentConversation = ConversationRegistry.instance.fetchEntry(conversationId);
if (currentConversation == null) return;

currentConversation.completeCallback = onConversationComplete;
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/play/cutscene/dialogue/Conversation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import funkin.modding.IScriptedClass.IEventHandler;
import funkin.play.cutscene.dialogue.DialogueBox;
import funkin.modding.IScriptedClass.IDialogueScriptedClass;
import funkin.modding.events.ScriptEventDispatcher;
import funkin.play.cutscene.dialogue.ConversationData.DialogueEntryData;
import funkin.data.dialogue.ConversationData.DialogueEntryData;
import flixel.addons.display.FlxPieDial;

/**
Expand Down
Loading

0 comments on commit fa556dc

Please sign in to comment.