FINISHED PORTING 10 gotta still finalize dialogues

98% completed dialogue system!
BUT ALL THE PORTING COMPLEDD
This commit is contained in:
⍚~Nex
2024-02-26 00:34:25 +01:00
parent e18e1a2c7a
commit abb953647e
10 changed files with 108 additions and 38 deletions
@@ -0,0 +1,11 @@
package funkin.backend.scripting.events;
import haxe.xml.Access;
/**
* CANCEL this event to customize from 0 the xml structure part!
*/
final class DialogueStructureEvent extends CancellableEvent
{
public var dialogueData:Access;
}
+17 -12
View File
@@ -726,7 +726,7 @@ class PlayState extends MusicBeatState
scoreTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Score:0", 16);
missesTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Misses:0", 16);
accuracyTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Acc:-% (N/A)", 16);
accuracyTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Accuracy:-% (N/A)", 16);
accuracyTxt.addFormat(accFormat, 0, 1);
for(text in [scoreTxt, missesTxt, accuracyTxt]) {
@@ -736,6 +736,7 @@ class PlayState extends MusicBeatState
scoreTxt.alignment = RIGHT;
missesTxt.alignment = CENTER;
accuracyTxt.alignment = LEFT;
updateRatingStuff();
for(e in [healthBar, healthBarBG, iconP1, iconP2, scoreTxt, missesTxt, accuracyTxt])
e.cameras = [camHUD];
@@ -1191,17 +1192,7 @@ class PlayState extends MusicBeatState
iconP2.health = 1 - (healthBar.percent / 100);
}
@:dox(hide)
override public function update(elapsed:Float)
{
scripts.call("update", [elapsed]);
if (inCutscene) {
super.update(elapsed);
scripts.call("postUpdate", [elapsed]);
return;
}
function updateRatingStuff() {
scoreTxt.text = 'Score:$songScore';
missesTxt.text = '${comboBreaks ? "Combo Breaks" : "Misses"}:$misses';
@@ -1215,6 +1206,20 @@ class PlayState extends MusicBeatState
accuracyTxt._formatRanges[0].range.start = accuracyTxt.text.length - curRating.rating.length;
accuracyTxt._formatRanges[0].range.end = accuracyTxt.text.length;
}
}
@:dox(hide)
override public function update(elapsed:Float)
{
scripts.call("update", [elapsed]);
if (inCutscene) {
super.update(elapsed);
scripts.call("postUpdate", [elapsed]);
return;
}
updateRatingStuff();
if (controls.PAUSE && startedCountdown && canPause)
pauseGame();
@@ -1,10 +1,12 @@
package funkin.game.cutscenes;
import funkin.backend.scripting.events.CancellableEvent;
import funkin.backend.utils.FunkinParentDisabler;
import funkin.backend.scripting.events.*;
import funkin.backend.scripting.Script;
import flixel.sound.FlxSound;
import funkin.game.cutscenes.dialogue.*;
import haxe.xml.Access;
import haxe.io.Path;
/**
* Substate made for dialogue cutscenes. To use it in a scripted cutscene, call `startDialogue`.
@@ -24,7 +26,7 @@ class DialogueCutscene extends Cutscene {
public var curMusic:FlxSound = null;
public static var cutscene:DialogueCutscene;
//public var dialogueScript:Script;
public var dialogueScript:Script;
public function set_curLine(val:DialogueLine) {
lastLine = curLine;
@@ -37,14 +39,23 @@ class DialogueCutscene extends Cutscene {
camera = dialogueCamera = new FlxCamera();
dialogueCamera.bgColor = 0;
FlxG.cameras.add(dialogueCamera, false);
dialogueScript = Script.create(Paths.script(Path.withoutExtension(dialoguePath), null, dialoguePath.startsWith('assets')));
dialogueScript.setParent(cutscene = this);
dialogueScript.load();
}
var parentDisabler:FunkinParentDisabler;
public override function create() {
cutscene = this;
super.create();
add(parentDisabler = new FunkinParentDisabler());
try {
dialogueData = new Access(Xml.parse(Assets.getText(dialoguePath)).firstElement());
var event = EventManager.get(DialogueStructureEvent).recycle(dialogueData);
event.dialogueData = new Access(Xml.parse(Assets.getText(dialoguePath)).firstElement());
dialogueScript.call('structureLoaded', [event]);
if(event.cancelled) return;
dialogueData = event.dialogueData;
// Add characters
for(char in dialogueData.nodes.char) {
@@ -98,10 +109,18 @@ class DialogueCutscene extends Cutscene {
Logs.trace('Error while loading dialogue at ${dialoguePath}: ${e.toString()}', ERROR);
close();
}
dialogueScript.call("postCreate");
}
public override function beatHit(curBeat:Int) {
super.beatHit(curBeat);
dialogueScript.call("beatHit", [curBeat]);
}
public override function update(elapsed:Float) {
super.update(elapsed);
dialogueScript.call("update", [elapsed]);
if(controls.ACCEPT) {
@:privateAccess
if(dialogueBox.dialogueEnded) next();
@@ -109,8 +128,13 @@ class DialogueCutscene extends Cutscene {
}
}
/**
* Use this to cancel `next`!
*/
public var canProceed:Bool = true;
public function next(playFirst:Bool = false) {
dialogueScript.call("next", [playFirst]);
if(!canProceed) return;
if ((curLine = dialogueLines.shift()) == null) {
@@ -145,20 +169,25 @@ class DialogueCutscene extends Cutscene {
curMusic.play();
curMusic.fadeIn(1, 0, curMusic.volume);
} else if(curLine.musicVolume != null && curMusic != null) curMusic.volume = curLine.musicVolume;
dialogueScript.call("postNext", [playFirst]);
}
public override function close() {
var event = new CancellableEvent();
for(c in charMap) c.dialogueCharScript.call("close", [event]);
dialogueBox.dialogueBoxScript.call("close", [event]);
if(event.cancelled)
return;
dialogueScript.call("close", [event]);
if(event.cancelled) return;
super.close();
}
public override function destroy() {
if(curMusic != null && !curMusic.persist) curMusic.destroy();
dialogueScript.call("destroy");
dialogueScript.destroy();
super.destroy();
cutscene = null;
FlxG.cameras.remove(dialogueCamera);
@@ -36,7 +36,7 @@ class DialogueBox extends FunkinSprite {
if(event.cancelled) return; // No idea the pyscho that would do this but hey, it can happen - Nex
try {
event.dialogueBoxData = dialogueBoxData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement());
event.dialogueBoxData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement());
dialogueBoxScript.call('structureLoaded', [event]);
if(event.cancelled) return;
name = event.name;
@@ -32,7 +32,7 @@ class DialogueCharacter extends FunkinSprite {
if(event.cancelled) return;
try {
event.charData = charData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement());
event.charData = new Access(Xml.parse(Assets.getText(Paths.xml(defPath + event.name))).firstElement());
dialogueCharScript.call('structureLoaded', [event]);
if(event.cancelled) return;
name = event.name;