diff --git a/assets b/assets index 37c65b743..05f17d2ea 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 37c65b743d9eb7ea32f501cafa084268fec7c12c +Subproject commit 05f17d2eadd6de98240ea9ed97755173cffd202a diff --git a/source/funkin/play/cutscene/dialogue/Conversation.hx b/source/funkin/play/cutscene/dialogue/Conversation.hx index 784dd8e29..0910a399b 100644 --- a/source/funkin/play/cutscene/dialogue/Conversation.hx +++ b/source/funkin/play/cutscene/dialogue/Conversation.hx @@ -30,6 +30,7 @@ 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 */ +@:nullSafety class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass implements IRegistryEntry { /** @@ -44,8 +45,9 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl /** * Conversation data as parsed from the JSON file. + * `null` if the data could not be parsed or loaded. */ - public final _data:ConversationData; + public final _data:Null; /** * The current entry in the dialogue. @@ -56,7 +58,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function get_currentDialogueEntryCount():Int { - return _data.dialogue.length; + return _data?.dialogue?.length ?? 0; } /** @@ -68,12 +70,12 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function get_currentDialogueLineCount():Int { - return currentDialogueEntryData.text.length; + return currentDialogueEntryData?.text?.length ?? 0; } - var currentDialogueEntryData(get, never):DialogueEntryData; + var currentDialogueEntryData(get, never):Null; - function get_currentDialogueEntryData():DialogueEntryData + function get_currentDialogueEntryData():Null { if (_data == null || _data.dialogue == null) return null; if (currentDialogueEntry < 0 || currentDialogueEntry >= _data.dialogue.length) return null; @@ -85,22 +87,23 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function get_currentDialogueLineString():String { - return currentDialogueEntryData?.text[currentDialogueLine]; + // TODO: Replace "" with some placeholder text? + return currentDialogueEntryData?.text[currentDialogueLine] ?? ""; } /** * AUDIO */ - var music:FunkinSound; + var music:Null; /** * GRAPHICS */ - var backdrop:FunkinSprite; + var backdrop:Null; - var currentSpeaker:Speaker; + var currentSpeaker:Null; - var currentDialogueBox:DialogueBox; + var currentDialogueBox:Null; public function new(id:String) { @@ -128,17 +131,23 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function setupMusic():Void { + if (_data == null) return; + if (_data.music == null || (_data.music.asset ?? "") == "") return; music = FunkinSound.load(Paths.music(_data.music.asset), 0.0, true, true, true); + var fadeTime:Float = _data.music.fadeTime ?? 0.0; - if (_data.music.fadeTime > 0.0) + if (fadeTime > 0.0) { - FlxTween.tween(music, {volume: 1.0}, _data.music.fadeTime, {ease: FlxEase.linear}); + FlxTween.tween(music, {volume: 1.0}, fadeTime, {ease: FlxEase.linear}); } else { - music.volume = 1.0; + if (music != null) + { + music.volume = 1.0; + } } } @@ -160,6 +169,8 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function setupBackdrop():Void { + if (_data == null) return; + if (backdrop != null) { backdrop.destroy(); @@ -175,12 +186,13 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl switch (_data.backdrop) { case SOLID(backdropData): - var targetColor:FlxColor = FlxColor.fromString(backdropData.color); + var targetColor:Null = FlxColor.fromString(backdropData.color); backdrop.makeSolidColor(Std.int(FlxG.width), Std.int(FlxG.height), targetColor); - if (backdropData.fadeTime > 0.0) + var fadeTime = backdropData.fadeTime ?? 0.0; + if (fadeTime > 0.0) { backdrop.alpha = 0.0; - FlxTween.tween(backdrop, {alpha: 1.0}, backdropData.fadeTime, {ease: EaseUtil.stepped(10)}); + FlxTween.tween(backdrop, {alpha: 1.0}, fadeTime, {ease: EaseUtil.stepped(10)}); } else { @@ -204,7 +216,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function showCurrentSpeaker():Void { - var nextSpeakerId:String = currentDialogueEntryData.speaker; + var nextSpeakerId:String = currentDialogueEntryData?.speaker ?? ""; // Skip the next steps if the current speaker is already displayed. if ((currentSpeaker != null && currentSpeaker.alive) && nextSpeakerId == currentSpeaker.id) return; @@ -216,7 +228,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl currentSpeaker = null; } - var nextSpeaker:Speaker = SpeakerRegistry.instance.fetchEntry(nextSpeakerId); + var nextSpeaker:Null = SpeakerRegistry.instance.fetchEntry(nextSpeakerId); if (nextSpeaker == null) { @@ -242,11 +254,11 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function playSpeakerAnimation():Void { - var nextSpeakerAnimation:String = currentDialogueEntryData.speakerAnimation; + var nextSpeakerAnimation:Null = currentDialogueEntryData?.speakerAnimation; if (nextSpeakerAnimation == null) return; - currentSpeaker.playAnimation(nextSpeakerAnimation); + if (currentSpeaker != null) currentSpeaker.playAnimation(nextSpeakerAnimation); } public function refresh():Void @@ -256,7 +268,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function showCurrentDialogueBox():Void { - var nextDialogueBoxId:String = currentDialogueEntryData?.box; + var nextDialogueBoxId:String = currentDialogueEntryData?.box ?? ""; // Skip the next steps if the current dialogue box is already displayed. if ((currentDialogueBox != null && currentDialogueBox.alive) && nextDialogueBoxId == currentDialogueBox.id) return; @@ -268,7 +280,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl currentDialogueBox = null; } - var nextDialogueBox:DialogueBox = DialogueBoxRegistry.instance.fetchEntry(nextDialogueBoxId); + var nextDialogueBox:Null = DialogueBoxRegistry.instance.fetchEntry(nextDialogueBoxId); if (nextDialogueBox == null) { @@ -290,11 +302,11 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl function playDialogueBoxAnimation():Void { - var nextDialogueBoxAnimation:String = currentDialogueEntryData?.boxAnimation; + var nextDialogueBoxAnimation:Null = currentDialogueEntryData?.boxAnimation; if (nextDialogueBoxAnimation == null) return; - currentDialogueBox.playAnimation(nextDialogueBoxAnimation); + if (currentDialogueBox != null) currentDialogueBox.playAnimation(nextDialogueBoxAnimation); } function onTypingComplete():Void @@ -363,20 +375,32 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl } outroTween = null; - if (this.music != null) this.music.stop(); - this.music = null; + if (this.music != null) + { + this.music.stop(); + this.music = null; + } - if (currentSpeaker != null) currentSpeaker.kill(); - remove(currentSpeaker); - currentSpeaker = null; + if (currentSpeaker != null) + { + currentSpeaker.kill(); + remove(currentSpeaker); + currentSpeaker = null; + } - if (currentDialogueBox != null) currentDialogueBox.kill(); - remove(currentDialogueBox); - currentDialogueBox = null; + if (currentDialogueBox != null) + { + currentDialogueBox.kill(); + remove(currentDialogueBox); + currentDialogueBox = null; + } - if (backdrop != null) backdrop.destroy(); - remove(backdrop); - backdrop = null; + if (backdrop != null) + { + backdrop.destroy(); + remove(backdrop); + backdrop = null; + } startConversation(); } @@ -392,7 +416,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl dispatchEvent(new DialogueScriptEvent(DIALOGUE_SKIP, this, true)); } - var outroTween:FlxTween; + var outroTween:Null = null; public function startOutro():Void { @@ -407,7 +431,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl ease: EaseUtil.stepped(8) }); - FlxTween.tween(this.music, {volume: 0.0}, outroData.fadeTime); + if (this.music != null) FlxTween.tween(this.music, {volume: 0.0}, outroData.fadeTime); case NONE(_): // Immediately clean up. endOutro(); @@ -417,7 +441,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl } } - public var completeCallback:() -> Void; + public var completeCallback:NullVoid> = null; public function endOutro():Void { @@ -477,7 +501,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl { // Continue the dialog with more lines. state = Speaking; - currentDialogueBox.appendText(currentDialogueLineString); + if (currentDialogueBox != null) currentDialogueBox.appendText(currentDialogueLineString); } } @@ -489,7 +513,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl propagateEvent(event); if (event.eventCanceled) return; - currentDialogueBox.skip(); + if (currentDialogueBox != null) currentDialogueBox.skip(); } /** @@ -564,17 +588,26 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass impl if (this.music != null) this.music.stop(); this.music = null; - if (currentSpeaker != null) currentSpeaker.kill(); - remove(currentSpeaker); - currentSpeaker = null; + if (currentSpeaker != null) + { + currentSpeaker.kill(); + remove(currentSpeaker); + currentSpeaker = null; + } - if (currentDialogueBox != null) currentDialogueBox.kill(); - remove(currentDialogueBox); - currentDialogueBox = null; + if (currentDialogueBox != null) + { + currentDialogueBox.kill(); + remove(currentDialogueBox); + currentDialogueBox = null; + } - if (backdrop != null) backdrop.destroy(); - remove(backdrop); - backdrop = null; + if (backdrop != null) + { + backdrop.destroy(); + remove(backdrop); + backdrop = null; + } this.clear();