mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-14 19:25:16 -05:00
Merge branch 'rewrite/master' into feature/chart-editor-freeplay-difficulty
This commit is contained in:
commit
66188fbd52
45 changed files with 1952 additions and 1124 deletions
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -110,6 +110,11 @@
|
||||||
"target": "windows",
|
"target": "windows",
|
||||||
"args": ["-debug", "-DSONG=bopeebo -DDIFFICULTY=normal"]
|
"args": ["-debug", "-DSONG=bopeebo -DDIFFICULTY=normal"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Windows / Debug (Conversation Test)",
|
||||||
|
"target": "windows",
|
||||||
|
"args": ["-debug", "-DDIALOGUE"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Windows / Debug (Straight to Chart Editor)",
|
"label": "Windows / Debug (Straight to Chart Editor)",
|
||||||
"target": "windows",
|
"target": "windows",
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
<library name="week7" preload="false" />
|
<library name="week7" preload="false" />
|
||||||
<library name="weekend1" preload="false" />
|
<library name="weekend1" preload="false" />
|
||||||
</section>
|
</section>
|
||||||
|
<library name="art" preload="false" />
|
||||||
<assets path="assets/songs" library="songs" exclude="*.fla|*.ogg" if="web" />
|
<assets path="assets/songs" library="songs" exclude="*.fla|*.ogg" if="web" />
|
||||||
<assets path="assets/songs" library="songs" exclude="*.fla|*.mp3" unless="web" />
|
<assets path="assets/songs" library="songs" exclude="*.fla|*.mp3" unless="web" />
|
||||||
<assets path="assets/shared" library="shared" exclude="*.fla|*.ogg" if="web" />
|
<assets path="assets/shared" library="shared" exclude="*.fla|*.ogg" if="web" />
|
||||||
|
@ -82,14 +83,15 @@
|
||||||
If we can exclude the `mods` folder from the manifest, we can re-enable this line.
|
If we can exclude the `mods` folder from the manifest, we can re-enable this line.
|
||||||
<assets path='example_mods' rename='mods' embed='false' exclude="*.md" />
|
<assets path='example_mods' rename='mods' embed='false' exclude="*.md" />
|
||||||
-->
|
-->
|
||||||
<assets path="art/readme.txt" rename="do NOT readme.txt" />
|
<assets path="art/readme.txt" rename="do NOT readme.txt" library="art"/>
|
||||||
<assets path="CHANGELOG.md" rename="changelog.txt" />
|
<assets path="CHANGELOG.md" rename="changelog.txt" library="art"/>
|
||||||
<!-- NOTE FOR FUTURE SELF SINCE FONTS ARE ALWAYS FUCKY
|
<!-- NOTE FOR FUTURE SELF SINCE FONTS ARE ALWAYS FUCKY
|
||||||
TO FIX ONE OF THEM, I CONVERTED IT TO OTF. DUNNO IF YOU NEED TO
|
TO FIX ONE OF THEM, I CONVERTED IT TO OTF. DUNNO IF YOU NEED TO
|
||||||
THEN UHHH I USED THE NAME OF THE FONT WITH SETFORMAT() ON THE TEXT!!!
|
THEN UHHH I USED THE NAME OF THE FONT WITH SETFORMAT() ON THE TEXT!!!
|
||||||
NOT USING A DIRECT THING TO THE ASSET!!!
|
NOT USING A DIRECT THING TO THE ASSET!!!
|
||||||
-->
|
-->
|
||||||
<assets path="assets/fonts" embed="true" />
|
<assets path="assets/fonts" embed="true" />
|
||||||
|
|
||||||
<!-- _______________________________ Libraries ______________________________ -->
|
<!-- _______________________________ Libraries ______________________________ -->
|
||||||
<haxelib name="lime" /> <!-- Game engine backend -->
|
<haxelib name="lime" /> <!-- Game engine backend -->
|
||||||
<haxelib name="openfl" /> <!-- Game engine backend -->
|
<haxelib name="openfl" /> <!-- Game engine backend -->
|
||||||
|
@ -108,7 +110,6 @@
|
||||||
<haxelib name="hxCodec" /> <!-- Video playback -->
|
<haxelib name="hxCodec" /> <!-- Video playback -->
|
||||||
|
|
||||||
<haxelib name="json2object" /> <!-- JSON parsing -->
|
<haxelib name="json2object" /> <!-- JSON parsing -->
|
||||||
<haxelib name="tink_json" /> <!-- JSON parsing (DEPRECATED) -->
|
|
||||||
<haxelib name="thx.semver" /> <!-- Version string handling -->
|
<haxelib name="thx.semver" /> <!-- Version string handling -->
|
||||||
|
|
||||||
<haxelib name="hmm" /> <!-- Read library version data at compile time so it can be baked into logs -->
|
<haxelib name="hmm" /> <!-- Read library version data at compile time so it can be baked into logs -->
|
||||||
|
|
7
hmm.json
7
hmm.json
|
@ -149,18 +149,13 @@
|
||||||
"name": "polymod",
|
"name": "polymod",
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"dir": null,
|
"dir": null,
|
||||||
"ref": "cb11a95d0159271eb3587428cf4b9602e46dc469",
|
"ref": "6cec79e4f322fbb262170594ed67ab72b4714810",
|
||||||
"url": "https://github.com/larsiusprime/polymod"
|
"url": "https://github.com/larsiusprime/polymod"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "thx.semver",
|
"name": "thx.semver",
|
||||||
"type": "haxelib",
|
"type": "haxelib",
|
||||||
"version": "0.2.2"
|
"version": "0.2.2"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tink_json",
|
|
||||||
"type": "haxelib",
|
|
||||||
"version": "0.11.0"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ import funkin.data.level.LevelRegistry;
|
||||||
import funkin.data.notestyle.NoteStyleRegistry;
|
import funkin.data.notestyle.NoteStyleRegistry;
|
||||||
import funkin.data.event.SongEventRegistry;
|
import funkin.data.event.SongEventRegistry;
|
||||||
import funkin.data.stage.StageRegistry;
|
import funkin.data.stage.StageRegistry;
|
||||||
import funkin.play.cutscene.dialogue.ConversationDataParser;
|
import funkin.data.dialogue.ConversationRegistry;
|
||||||
import funkin.play.cutscene.dialogue.DialogueBoxDataParser;
|
import funkin.data.dialogue.DialogueBoxRegistry;
|
||||||
import funkin.play.cutscene.dialogue.SpeakerDataParser;
|
import funkin.data.dialogue.SpeakerRegistry;
|
||||||
import funkin.data.song.SongRegistry;
|
import funkin.data.song.SongRegistry;
|
||||||
import funkin.play.character.CharacterData.CharacterDataParser;
|
import funkin.play.character.CharacterData.CharacterDataParser;
|
||||||
import funkin.modding.module.ModuleHandler;
|
import funkin.modding.module.ModuleHandler;
|
||||||
|
@ -208,22 +208,29 @@ class InitState extends FlxState
|
||||||
// GAME DATA PARSING
|
// GAME DATA PARSING
|
||||||
//
|
//
|
||||||
|
|
||||||
// NOTE: Registries and data parsers must be imported and not referenced with fully qualified names,
|
// NOTE: Registries must be imported and not referenced with fully qualified names,
|
||||||
// to ensure build macros work properly.
|
// to ensure build macros work properly.
|
||||||
|
trace('Parsing game data...');
|
||||||
|
var perfStart = haxe.Timer.stamp();
|
||||||
|
SongEventRegistry.loadEventCache(); // SongEventRegistry is structured differently so it's not a BaseRegistry.
|
||||||
SongRegistry.instance.loadEntries();
|
SongRegistry.instance.loadEntries();
|
||||||
LevelRegistry.instance.loadEntries();
|
LevelRegistry.instance.loadEntries();
|
||||||
NoteStyleRegistry.instance.loadEntries();
|
NoteStyleRegistry.instance.loadEntries();
|
||||||
SongEventRegistry.loadEventCache();
|
ConversationRegistry.instance.loadEntries();
|
||||||
ConversationDataParser.loadConversationCache();
|
DialogueBoxRegistry.instance.loadEntries();
|
||||||
DialogueBoxDataParser.loadDialogueBoxCache();
|
SpeakerRegistry.instance.loadEntries();
|
||||||
SpeakerDataParser.loadSpeakerCache();
|
|
||||||
StageRegistry.instance.loadEntries();
|
StageRegistry.instance.loadEntries();
|
||||||
CharacterDataParser.loadCharacterCache();
|
|
||||||
|
// TODO: CharacterDataParser doesn't use json2object, so it's way slower than the other parsers.
|
||||||
|
CharacterDataParser.loadCharacterCache(); // TODO: Migrate characters to BaseRegistry.
|
||||||
|
|
||||||
ModuleHandler.buildModuleCallbacks();
|
ModuleHandler.buildModuleCallbacks();
|
||||||
ModuleHandler.loadModuleCache();
|
ModuleHandler.loadModuleCache();
|
||||||
|
|
||||||
ModuleHandler.callOnCreate();
|
ModuleHandler.callOnCreate();
|
||||||
|
|
||||||
|
var perfEnd = haxe.Timer.stamp();
|
||||||
|
|
||||||
|
trace('Parsing game data took ${Math.floor((perfEnd - perfStart) * 1000)}ms.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,6 +248,8 @@ class InitState extends FlxState
|
||||||
startLevel(defineLevel(), defineDifficulty());
|
startLevel(defineLevel(), defineDifficulty());
|
||||||
#elseif FREEPLAY // -DFREEPLAY
|
#elseif FREEPLAY // -DFREEPLAY
|
||||||
FlxG.switchState(new FreeplayState());
|
FlxG.switchState(new FreeplayState());
|
||||||
|
#elseif DIALOGUE // -DDIALOGUE
|
||||||
|
FlxG.switchState(new funkin.ui.debug.dialogue.ConversationDebugState());
|
||||||
#elseif ANIMATE // -DANIMATE
|
#elseif ANIMATE // -DANIMATE
|
||||||
FlxG.switchState(new funkin.ui.debug.anim.FlxAnimateTest());
|
FlxG.switchState(new funkin.ui.debug.anim.FlxAnimateTest());
|
||||||
#elseif WAVEFORM // -DWAVEFORM
|
#elseif WAVEFORM // -DWAVEFORM
|
||||||
|
|
|
@ -8,6 +8,8 @@ import flixel.sound.FlxSound;
|
||||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||||
import flixel.system.FlxAssets.FlxSoundAsset;
|
import flixel.system.FlxAssets.FlxSoundAsset;
|
||||||
import funkin.util.tools.ICloneable;
|
import funkin.util.tools.ICloneable;
|
||||||
|
import funkin.audio.waveform.WaveformData;
|
||||||
|
import funkin.audio.waveform.WaveformDataParser;
|
||||||
import flixel.math.FlxMath;
|
import flixel.math.FlxMath;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
#if (openfl >= "8.0.0")
|
#if (openfl >= "8.0.0")
|
||||||
|
@ -58,6 +60,24 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
|
||||||
return this.playing || this._shouldPlay;
|
return this.playing || this._shouldPlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waveform data for this sound.
|
||||||
|
* This is lazily loaded, so it will be built the first time it is accessed.
|
||||||
|
*/
|
||||||
|
public var waveformData(get, never):WaveformData;
|
||||||
|
|
||||||
|
var _waveformData:Null<WaveformData> = null;
|
||||||
|
|
||||||
|
function get_waveformData():WaveformData
|
||||||
|
{
|
||||||
|
if (_waveformData == null)
|
||||||
|
{
|
||||||
|
_waveformData = WaveformDataParser.interpretFlxSound(this);
|
||||||
|
if (_waveformData == null) throw 'Could not interpret waveform data!';
|
||||||
|
}
|
||||||
|
return _waveformData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Are we in a state where the song should play but time is negative?
|
* Are we in a state where the song should play but time is negative?
|
||||||
*/
|
*/
|
||||||
|
@ -218,6 +238,10 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
|
||||||
// Call init to ensure the FlxSound is properly initialized.
|
// Call init to ensure the FlxSound is properly initialized.
|
||||||
sound.init(this.looped, this.autoDestroy, this.onComplete);
|
sound.init(this.looped, this.autoDestroy, this.onComplete);
|
||||||
|
|
||||||
|
// Oh yeah, the waveform data is the same too!
|
||||||
|
@:privateAccess
|
||||||
|
sound._waveformData = this._waveformData;
|
||||||
|
|
||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package funkin.audio;
|
||||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||||
import flixel.sound.FlxSound;
|
import flixel.sound.FlxSound;
|
||||||
import funkin.audio.FunkinSound;
|
import funkin.audio.FunkinSound;
|
||||||
|
import flixel.tweens.FlxTween;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A group of FunkinSounds that are all synced together.
|
* A group of FunkinSounds that are all synced together.
|
||||||
|
@ -14,6 +15,8 @@ class SoundGroup extends FlxTypedGroup<FunkinSound>
|
||||||
|
|
||||||
public var volume(get, set):Float;
|
public var volume(get, set):Float;
|
||||||
|
|
||||||
|
public var muted(get, set):Bool;
|
||||||
|
|
||||||
public var pitch(get, set):Float;
|
public var pitch(get, set):Float;
|
||||||
|
|
||||||
public var playing(get, never):Bool;
|
public var playing(get, never):Bool;
|
||||||
|
@ -124,6 +127,26 @@ class SoundGroup extends FlxTypedGroup<FunkinSound>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fade in all the sounds in the group.
|
||||||
|
*/
|
||||||
|
public function fadeIn(duration:Float, ?from:Float = 0.0, ?to:Float = 1.0, ?onComplete:FlxTween->Void):Void
|
||||||
|
{
|
||||||
|
forEachAlive(function(sound:FunkinSound) {
|
||||||
|
sound.fadeIn(duration, from, to, onComplete);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fade out all the sounds in the group.
|
||||||
|
*/
|
||||||
|
public function fadeOut(duration:Float, ?to:Float = 0.0, ?onComplete:FlxTween->Void):Void
|
||||||
|
{
|
||||||
|
forEachAlive(function(sound:FunkinSound) {
|
||||||
|
sound.fadeOut(duration, to, onComplete);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop all the sounds in the group.
|
* Stop all the sounds in the group.
|
||||||
*/
|
*/
|
||||||
|
@ -191,6 +214,22 @@ class SoundGroup extends FlxTypedGroup<FunkinSound>
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_muted():Bool
|
||||||
|
{
|
||||||
|
if (getFirstAlive() != null) return getFirstAlive().muted;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_muted(muted:Bool):Bool
|
||||||
|
{
|
||||||
|
forEachAlive(function(snd:FunkinSound) {
|
||||||
|
snd.muted = muted;
|
||||||
|
});
|
||||||
|
|
||||||
|
return muted;
|
||||||
|
}
|
||||||
|
|
||||||
function get_pitch():Float
|
function get_pitch():Float
|
||||||
{
|
{
|
||||||
#if FLX_PITCH
|
#if FLX_PITCH
|
||||||
|
|
|
@ -116,18 +116,18 @@ class VoicesGroup extends SoundGroup
|
||||||
return opponentVoices.members[index];
|
return opponentVoices.members[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildPlayerVoiceWaveform():Null<WaveformData>
|
public function getPlayerVoiceWaveform():Null<WaveformData>
|
||||||
{
|
{
|
||||||
if (playerVoices.members.length == 0) return null;
|
if (playerVoices.members.length == 0) return null;
|
||||||
|
|
||||||
return WaveformDataParser.interpretFlxSound(playerVoices.members[0]);
|
return playerVoices.members[0].waveformData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildOpponentVoiceWaveform():Null<WaveformData>
|
public function getOpponentVoiceWaveform():Null<WaveformData>
|
||||||
{
|
{
|
||||||
if (opponentVoices.members.length == 0) return null;
|
if (opponentVoices.members.length == 0) return null;
|
||||||
|
|
||||||
return WaveformDataParser.interpretFlxSound(opponentVoices.members[0]);
|
return opponentVoices.members[0].waveformData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -182,6 +182,38 @@ class WaveformData
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new WaveformData whose data represents the two waveforms overlayed.
|
||||||
|
*/
|
||||||
|
public function merge(that:WaveformData):WaveformData
|
||||||
|
{
|
||||||
|
var result = this.clone([]);
|
||||||
|
|
||||||
|
for (channelIndex in 0...this.channels)
|
||||||
|
{
|
||||||
|
var thisChannel = this.channel(channelIndex);
|
||||||
|
var thatChannel = that.channel(channelIndex);
|
||||||
|
var resultChannel = result.channel(channelIndex);
|
||||||
|
|
||||||
|
for (index in 0...this.length)
|
||||||
|
{
|
||||||
|
var thisMinSample = thisChannel.minSample(index);
|
||||||
|
var thatMinSample = thatChannel.minSample(index);
|
||||||
|
|
||||||
|
var thisMaxSample = thisChannel.maxSample(index);
|
||||||
|
var thatMaxSample = thatChannel.maxSample(index);
|
||||||
|
|
||||||
|
resultChannel.setMinSample(index, Std.int(Math.min(thisMinSample, thatMinSample)));
|
||||||
|
resultChannel.setMaxSample(index, Std.int(Math.max(thisMaxSample, thatMaxSample)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:privateAccess
|
||||||
|
result.length = this.length;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new WaveformData whose parameters match the current object.
|
* Create a new WaveformData whose parameters match the current object.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,12 +29,12 @@ class WaveformDataParser
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trace('[WAVEFORM] Method 2 worked.');
|
// trace('[WAVEFORM] Method 2 worked.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trace('[WAVEFORM] Method 1 worked.');
|
// trace('[WAVEFORM] Method 1 worked.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return interpretAudioBuffer(soundBuffer);
|
return interpretAudioBuffer(soundBuffer);
|
||||||
|
@ -55,22 +55,24 @@ class WaveformDataParser
|
||||||
var soundDataSampleCount:Int = Std.int(Math.ceil(soundDataRawLength / channels / (bitsPerSample == 16 ? 2 : 1)));
|
var soundDataSampleCount:Int = Std.int(Math.ceil(soundDataRawLength / channels / (bitsPerSample == 16 ? 2 : 1)));
|
||||||
var outputPointCount:Int = Std.int(Math.ceil(soundDataSampleCount / samplesPerPoint));
|
var outputPointCount:Int = Std.int(Math.ceil(soundDataSampleCount / samplesPerPoint));
|
||||||
|
|
||||||
trace('Interpreting audio buffer:');
|
// trace('Interpreting audio buffer:');
|
||||||
trace(' sampleRate: ${sampleRate}');
|
// trace(' sampleRate: ${sampleRate}');
|
||||||
trace(' channels: ${channels}');
|
// trace(' channels: ${channels}');
|
||||||
trace(' bitsPerSample: ${bitsPerSample}');
|
// trace(' bitsPerSample: ${bitsPerSample}');
|
||||||
trace(' samplesPerPoint: ${samplesPerPoint}');
|
// trace(' samplesPerPoint: ${samplesPerPoint}');
|
||||||
trace(' pointsPerSecond: ${pointsPerSecond}');
|
// trace(' pointsPerSecond: ${pointsPerSecond}');
|
||||||
trace(' soundDataRawLength: ${soundDataRawLength}');
|
// trace(' soundDataRawLength: ${soundDataRawLength}');
|
||||||
trace(' soundDataSampleCount: ${soundDataSampleCount}');
|
// trace(' soundDataSampleCount: ${soundDataSampleCount}');
|
||||||
trace(' soundDataRawLength/4: ${soundDataRawLength / 4}');
|
// trace(' soundDataRawLength/4: ${soundDataRawLength / 4}');
|
||||||
trace(' outputPointCount: ${outputPointCount}');
|
// trace(' outputPointCount: ${outputPointCount}');
|
||||||
|
|
||||||
var minSampleValue:Int = bitsPerSample == 16 ? INT16_MIN : INT8_MIN;
|
var minSampleValue:Int = bitsPerSample == 16 ? INT16_MIN : INT8_MIN;
|
||||||
var maxSampleValue:Int = bitsPerSample == 16 ? INT16_MAX : INT8_MAX;
|
var maxSampleValue:Int = bitsPerSample == 16 ? INT16_MAX : INT8_MAX;
|
||||||
|
|
||||||
var outputData:Array<Int> = [];
|
var outputData:Array<Int> = [];
|
||||||
|
|
||||||
|
var perfStart = haxe.Timer.stamp();
|
||||||
|
|
||||||
for (pointIndex in 0...outputPointCount)
|
for (pointIndex in 0...outputPointCount)
|
||||||
{
|
{
|
||||||
// minChannel1, maxChannel1, minChannel2, maxChannel2, ...
|
// minChannel1, maxChannel1, minChannel2, maxChannel2, ...
|
||||||
|
@ -106,6 +108,9 @@ class WaveformDataParser
|
||||||
var outputDataLength:Int = Std.int(outputData.length / channels / 2);
|
var outputDataLength:Int = Std.int(outputData.length / channels / 2);
|
||||||
var result = new WaveformData(null, channels, sampleRate, samplesPerPoint, bitsPerSample, outputPointCount, outputData);
|
var result = new WaveformData(null, channels, sampleRate, samplesPerPoint, bitsPerSample, outputPointCount, outputData);
|
||||||
|
|
||||||
|
var perfEnd = haxe.Timer.stamp();
|
||||||
|
trace('[WAVEFORM] Interpreted audio buffer in ${perfEnd - perfStart} seconds.');
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,9 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
|
||||||
this.entries = new Map<String, T>();
|
this.entries = new Map<String, T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Create a `loadEntriesAsync()` function.
|
||||||
|
*/
|
||||||
public function loadEntries():Void
|
public function loadEntries():Void
|
||||||
{
|
{
|
||||||
clearEntries();
|
clearEntries();
|
||||||
|
@ -54,7 +57,7 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
|
||||||
// SCRIPTED ENTRIES
|
// SCRIPTED ENTRIES
|
||||||
//
|
//
|
||||||
var scriptedEntryClassNames:Array<String> = getScriptedClassNames();
|
var scriptedEntryClassNames:Array<String> = getScriptedClassNames();
|
||||||
log('Registering ${scriptedEntryClassNames.length} scripted entries...');
|
log('Parsing ${scriptedEntryClassNames.length} scripted entries...');
|
||||||
|
|
||||||
for (entryCls in scriptedEntryClassNames)
|
for (entryCls in scriptedEntryClassNames)
|
||||||
{
|
{
|
||||||
|
@ -78,7 +81,7 @@ abstract class BaseRegistry<T:(IRegistryEntry<J> & Constructible<EntryConstructo
|
||||||
var unscriptedEntryIds:Array<String> = entryIdList.filter(function(entryId:String):Bool {
|
var unscriptedEntryIds:Array<String> = entryIdList.filter(function(entryId:String):Bool {
|
||||||
return !entries.exists(entryId);
|
return !entries.exists(entryId);
|
||||||
});
|
});
|
||||||
log('Fetching data for ${unscriptedEntryIds.length} unscripted entries...');
|
log('Parsing ${unscriptedEntryIds.length} unscripted entries...');
|
||||||
for (entryId in unscriptedEntryIds)
|
for (entryId in unscriptedEntryIds)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -120,6 +120,71 @@ class DataParse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function backdropData(json:Json, name:String):funkin.data.dialogue.ConversationData.BackdropData
|
||||||
|
{
|
||||||
|
switch (json.value)
|
||||||
|
{
|
||||||
|
case JObject(fields):
|
||||||
|
var result:Dynamic = {};
|
||||||
|
var backdropType:String = '';
|
||||||
|
|
||||||
|
for (field in fields)
|
||||||
|
{
|
||||||
|
switch (field.name)
|
||||||
|
{
|
||||||
|
case 'type':
|
||||||
|
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):Null<funkin.data.dialogue.ConversationData.OutroData>
|
||||||
|
{
|
||||||
|
switch (json.value)
|
||||||
|
{
|
||||||
|
case JObject(fields):
|
||||||
|
var result:Dynamic = {};
|
||||||
|
var outroType:String = '';
|
||||||
|
|
||||||
|
for (field in fields)
|
||||||
|
{
|
||||||
|
switch (field.name)
|
||||||
|
{
|
||||||
|
case 'type':
|
||||||
|
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}".';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
default:
|
||||||
|
throw 'Expected property $name to be an object, but it was ${json.value}.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parser which outputs a `Either<Float, LegacyScrollSpeeds>`.
|
* Parser which outputs a `Either<Float, LegacyScrollSpeeds>`.
|
||||||
* Used by the FNF legacy JSON importer.
|
* Used by the FNF legacy JSON importer.
|
||||||
|
|
168
source/funkin/data/dialogue/ConversationData.hx
Normal file
168
source/funkin/data/dialogue/ConversationData.hx
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
package funkin.data.dialogue;
|
||||||
|
|
||||||
|
import funkin.data.animation.AnimationData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type definition for the data for a specific conversation.
|
||||||
|
* It includes things like what dialogue boxes to use, what text to display, and what animations to play.
|
||||||
|
* @see https://lib.haxe.org/p/json2object/
|
||||||
|
*/
|
||||||
|
typedef ConversationData =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Semantic version for conversation data.
|
||||||
|
*/
|
||||||
|
public var version:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data on the backdrop for the conversation.
|
||||||
|
*/
|
||||||
|
@:jcustomparse(funkin.data.DataParse.backdropData)
|
||||||
|
public var backdrop:BackdropData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data on the outro for the conversation.
|
||||||
|
*/
|
||||||
|
@:jcustomparse(funkin.data.DataParse.outroData)
|
||||||
|
@:optional
|
||||||
|
public var outro:Null<OutroData>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data on the music for the conversation.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
public var music:Null<MusicData>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data for each line of dialogue in the conversation.
|
||||||
|
*/
|
||||||
|
public var dialogue:Array<DialogueEntryData>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data on the backdrop for the conversation, behind the dialogue box.
|
||||||
|
* A custom parser distinguishes between backdrop types based on the `type` field.
|
||||||
|
*/
|
||||||
|
enum BackdropData
|
||||||
|
{
|
||||||
|
SOLID(data:BackdropData_Solid); // 'solid'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data for a Solid color backdrop.
|
||||||
|
*/
|
||||||
|
typedef BackdropData_Solid =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Used to distinguish between backdrop types. Should always be `solid` for this type.
|
||||||
|
*/
|
||||||
|
var type:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color of the backdrop.
|
||||||
|
*/
|
||||||
|
var color:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fade-in time for the backdrop.
|
||||||
|
* @default No fade-in
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(0.0)
|
||||||
|
var fadeTime:Float;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum OutroData
|
||||||
|
{
|
||||||
|
NONE(data:OutroData_None); // 'none'
|
||||||
|
FADE(data:OutroData_Fade); // 'fade'
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef OutroData_None =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Used to distinguish between outro types. Should always be `none` for this type.
|
||||||
|
*/
|
||||||
|
var type:String;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef OutroData_Fade =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Used to distinguish between outro types. Should always be `fade` for this type.
|
||||||
|
*/
|
||||||
|
var type:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time to fade out the conversation.
|
||||||
|
* @default 1 second
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(1.0)
|
||||||
|
var fadeTime:Float;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef MusicData =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The asset to play for the music.
|
||||||
|
*/
|
||||||
|
var asset:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time to fade in the music.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(0.0)
|
||||||
|
var fadeTime:Float;
|
||||||
|
|
||||||
|
@:optional
|
||||||
|
@:default(false)
|
||||||
|
var looped:Bool;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data on a single line of dialogue in a conversation.
|
||||||
|
*/
|
||||||
|
typedef DialogueEntryData =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Which speaker is speaking.
|
||||||
|
* @see `SpeakerData.hx`
|
||||||
|
*/
|
||||||
|
public var speaker:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The animation the speaker should play for this line of dialogue.
|
||||||
|
*/
|
||||||
|
public var speakerAnimation:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which dialogue box to use for this line of dialogue.
|
||||||
|
* @see `DialogueBoxData.hx`
|
||||||
|
*/
|
||||||
|
public var box:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which animation to play for the dialogue box.
|
||||||
|
*/
|
||||||
|
public var boxAnimation:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The text that will display for this line of dialogue.
|
||||||
|
* Text will automatically wrap.
|
||||||
|
* When the user advances the dialogue, the next entry in the array will concatenate on.
|
||||||
|
* Advancing when the last entry is displayed will move to the next `DialogueEntryData`,
|
||||||
|
* or end the conversation if there are no more.
|
||||||
|
*/
|
||||||
|
public var text:Array<String>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The relative speed at which text gets "typed out".
|
||||||
|
* Setting `speed` to `1.5` would make it look like the character is speaking quickly,
|
||||||
|
* and setting `speed` to `0.5` would make it look like the character is emphasizing each word.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(1.0)
|
||||||
|
public var speed:Float;
|
||||||
|
};
|
81
source/funkin/data/dialogue/ConversationRegistry.hx
Normal file
81
source/funkin/data/dialogue/ConversationRegistry.hx
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package funkin.data.dialogue;
|
||||||
|
|
||||||
|
import funkin.play.cutscene.dialogue.Conversation;
|
||||||
|
import funkin.data.dialogue.ConversationData;
|
||||||
|
import funkin.play.cutscene.dialogue.ScriptedConversation;
|
||||||
|
|
||||||
|
class ConversationRegistry extends BaseRegistry<Conversation, ConversationData>
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The current version string for the dialogue box data format.
|
||||||
|
* Handle breaking changes by incrementing this value
|
||||||
|
* and adding migration to the `migrateConversationData()` function.
|
||||||
|
*/
|
||||||
|
public static final CONVERSATION_DATA_VERSION:thx.semver.Version = "1.0.0";
|
||||||
|
|
||||||
|
public static final CONVERSATION_DATA_VERSION_RULE:thx.semver.VersionRule = "1.0.x";
|
||||||
|
|
||||||
|
public static final instance:ConversationRegistry = new ConversationRegistry();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
128
source/funkin/data/dialogue/DialogueBoxData.hx
Normal file
128
source/funkin/data/dialogue/DialogueBoxData.hx
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
package funkin.data.dialogue;
|
||||||
|
|
||||||
|
import funkin.data.animation.AnimationData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type definition for the data for a conversation text box.
|
||||||
|
* It includes things like the sprite to use, and the font and color for the text.
|
||||||
|
* The actual text is included in the ConversationData.
|
||||||
|
* @see https://lib.haxe.org/p/json2object/
|
||||||
|
*/
|
||||||
|
typedef DialogueBoxData =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Semantic version for dialogue box data.
|
||||||
|
*/
|
||||||
|
public var version:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A human readable name for the dialogue box type.
|
||||||
|
*/
|
||||||
|
public var name:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The asset path for the sprite to use for the dialogue box.
|
||||||
|
* Takes a static sprite or a sprite sheet.
|
||||||
|
*/
|
||||||
|
public var assetPath:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to horizontally flip the dialogue box sprite.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(false)
|
||||||
|
public var flipX:Bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to vertically flip the dialogue box sprite.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(false)
|
||||||
|
public var flipY:Bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to disable anti-aliasing for the dialogue box sprite.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(false)
|
||||||
|
public var isPixel:Bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The relative horizontal and vertical offsets for the dialogue box sprite.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default([0, 0])
|
||||||
|
public var offsets:Array<Float>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Info about how to display text in the dialogue box.
|
||||||
|
*/
|
||||||
|
public var text:DialogueBoxTextData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiply the size of the dialogue box sprite.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(1)
|
||||||
|
public var scale:Float;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If using a spritesheet for the dialogue box, the animations to use.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default([])
|
||||||
|
public var animations:Array<AnimationData>;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef DialogueBoxTextData =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The position of the text in teh box.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default([0, 0])
|
||||||
|
var offsets:Array<Float>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The width of the
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(300)
|
||||||
|
var width:Int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The font size to use for the text.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(32)
|
||||||
|
var size:Int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color to use for the text.
|
||||||
|
* Use a string that can be translated to a color, like `#FF0000` for red.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default("#000000")
|
||||||
|
var color:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The font to use for the text.
|
||||||
|
* @since v1.1.0
|
||||||
|
* @default `Arial`, make sure to switch this!
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default("Arial")
|
||||||
|
var fontFamily:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color to use for the shadow of the text. Use transparent to disable.
|
||||||
|
*/
|
||||||
|
var shadowColor:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The width of the shadow of the text.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(0)
|
||||||
|
var shadowWidth:Int;
|
||||||
|
};
|
81
source/funkin/data/dialogue/DialogueBoxRegistry.hx
Normal file
81
source/funkin/data/dialogue/DialogueBoxRegistry.hx
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package funkin.data.dialogue;
|
||||||
|
|
||||||
|
import funkin.play.cutscene.dialogue.DialogueBox;
|
||||||
|
import funkin.data.dialogue.DialogueBoxData;
|
||||||
|
import funkin.play.cutscene.dialogue.ScriptedDialogueBox;
|
||||||
|
|
||||||
|
class DialogueBoxRegistry extends BaseRegistry<DialogueBox, DialogueBoxData>
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The current version string for the dialogue box data format.
|
||||||
|
* Handle breaking changes by incrementing this value
|
||||||
|
* and adding migration to the `migrateDialogueBoxData()` function.
|
||||||
|
*/
|
||||||
|
public static final DIALOGUEBOX_DATA_VERSION:thx.semver.Version = "1.1.0";
|
||||||
|
|
||||||
|
public static final DIALOGUEBOX_DATA_VERSION_RULE:thx.semver.VersionRule = "1.1.x";
|
||||||
|
|
||||||
|
public static final instance:DialogueBoxRegistry = new DialogueBoxRegistry();
|
||||||
|
|
||||||
|
public function new()
|
||||||
|
{
|
||||||
|
super('DIALOGUEBOX', 'dialogue/boxes', DIALOGUEBOX_DATA_VERSION_RULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read, parse, and validate the JSON data and produce the corresponding data object.
|
||||||
|
*/
|
||||||
|
public function parseEntryData(id:String):Null<DialogueBoxData>
|
||||||
|
{
|
||||||
|
// JsonParser does not take type parameters,
|
||||||
|
// otherwise this function would be in BaseRegistry.
|
||||||
|
var parser = new json2object.JsonParser<DialogueBoxData>();
|
||||||
|
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<DialogueBoxData>
|
||||||
|
{
|
||||||
|
var parser = new json2object.JsonParser<DialogueBoxData>();
|
||||||
|
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):DialogueBox
|
||||||
|
{
|
||||||
|
return ScriptedDialogueBox.init(clsName, "unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getScriptedClassNames():Array<String>
|
||||||
|
{
|
||||||
|
return ScriptedDialogueBox.listScriptClasses();
|
||||||
|
}
|
||||||
|
}
|
68
source/funkin/data/dialogue/SpeakerData.hx
Normal file
68
source/funkin/data/dialogue/SpeakerData.hx
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
package funkin.data.dialogue;
|
||||||
|
|
||||||
|
import funkin.data.animation.AnimationData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type definition for a specific speaker in a conversation.
|
||||||
|
* It includes things like what sprite to use and its available animations.
|
||||||
|
* @see https://lib.haxe.org/p/json2object/
|
||||||
|
*/
|
||||||
|
typedef SpeakerData =
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Semantic version of the speaker data.
|
||||||
|
*/
|
||||||
|
public var version:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A human-readable name for the speaker.
|
||||||
|
*/
|
||||||
|
public var name:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path to the asset to use for the speaker's sprite.
|
||||||
|
*/
|
||||||
|
public var assetPath:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the sprite should be flipped horizontally.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(false)
|
||||||
|
public var flipX:Bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the sprite should be flipped vertically.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(false)
|
||||||
|
public var flipY:Bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to disable anti-aliasing for the dialogue box sprite.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(false)
|
||||||
|
public var isPixel:Bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The offsets to apply to the sprite's position.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default([0, 0])
|
||||||
|
public var offsets:Array<Float>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scale to apply to the sprite.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(1.0)
|
||||||
|
public var scale:Float;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The available animations for the speaker.
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default([])
|
||||||
|
public var animations:Array<AnimationData>;
|
||||||
|
}
|
81
source/funkin/data/dialogue/SpeakerRegistry.hx
Normal file
81
source/funkin/data/dialogue/SpeakerRegistry.hx
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package funkin.data.dialogue;
|
||||||
|
|
||||||
|
import funkin.play.cutscene.dialogue.Speaker;
|
||||||
|
import funkin.data.dialogue.SpeakerData;
|
||||||
|
import funkin.play.cutscene.dialogue.ScriptedSpeaker;
|
||||||
|
|
||||||
|
class SpeakerRegistry extends BaseRegistry<Speaker, SpeakerData>
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The current version string for the speaker data format.
|
||||||
|
* Handle breaking changes by incrementing this value
|
||||||
|
* and adding migration to the `migrateSpeakerData()` function.
|
||||||
|
*/
|
||||||
|
public static final SPEAKER_DATA_VERSION:thx.semver.Version = "1.0.0";
|
||||||
|
|
||||||
|
public static final SPEAKER_DATA_VERSION_RULE:thx.semver.VersionRule = "1.0.x";
|
||||||
|
|
||||||
|
public static final instance:SpeakerRegistry = new SpeakerRegistry();
|
||||||
|
|
||||||
|
public function new()
|
||||||
|
{
|
||||||
|
super('SPEAKER', 'dialogue/speakers', SPEAKER_DATA_VERSION_RULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read, parse, and validate the JSON data and produce the corresponding data object.
|
||||||
|
*/
|
||||||
|
public function parseEntryData(id:String):Null<SpeakerData>
|
||||||
|
{
|
||||||
|
// JsonParser does not take type parameters,
|
||||||
|
// otherwise this function would be in BaseRegistry.
|
||||||
|
var parser = new json2object.JsonParser<SpeakerData>();
|
||||||
|
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<SpeakerData>
|
||||||
|
{
|
||||||
|
var parser = new json2object.JsonParser<SpeakerData>();
|
||||||
|
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):Speaker
|
||||||
|
{
|
||||||
|
return ScriptedSpeaker.init(clsName, "unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getScriptedClassNames():Array<String>
|
||||||
|
{
|
||||||
|
return ScriptedSpeaker.listScriptClasses();
|
||||||
|
}
|
||||||
|
}
|
|
@ -431,6 +431,24 @@ class SongPlayData implements ICloneable<SongPlayData>
|
||||||
@:optional
|
@:optional
|
||||||
public var album:Null<String>;
|
public var album:Null<String>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The start time for the audio preview in Freeplay.
|
||||||
|
* Defaults to 0 seconds in.
|
||||||
|
* @since `2.2.2`
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(0)
|
||||||
|
public var previewStart:Int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The end time for the audio preview in Freeplay.
|
||||||
|
* Defaults to 15 seconds in.
|
||||||
|
* @since `2.2.2`
|
||||||
|
*/
|
||||||
|
@:optional
|
||||||
|
@:default(15000)
|
||||||
|
public var previewEnd:Int;
|
||||||
|
|
||||||
public function new()
|
public function new()
|
||||||
{
|
{
|
||||||
ratings = new Map<String, Int>();
|
ratings = new Map<String, Int>();
|
||||||
|
@ -438,6 +456,7 @@ class SongPlayData implements ICloneable<SongPlayData>
|
||||||
|
|
||||||
public function clone():SongPlayData
|
public function clone():SongPlayData
|
||||||
{
|
{
|
||||||
|
// TODO: This sucks! If you forget to update this you get weird behavior.
|
||||||
var result:SongPlayData = new SongPlayData();
|
var result:SongPlayData = new SongPlayData();
|
||||||
result.songVariations = this.songVariations.clone();
|
result.songVariations = this.songVariations.clone();
|
||||||
result.difficulties = this.difficulties.clone();
|
result.difficulties = this.difficulties.clone();
|
||||||
|
@ -446,6 +465,8 @@ class SongPlayData implements ICloneable<SongPlayData>
|
||||||
result.noteStyle = this.noteStyle;
|
result.noteStyle = this.noteStyle;
|
||||||
result.ratings = this.ratings.clone();
|
result.ratings = this.ratings.clone();
|
||||||
result.album = this.album;
|
result.album = this.album;
|
||||||
|
result.previewStart = this.previewStart;
|
||||||
|
result.previewEnd = this.previewEnd;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -777,7 +798,7 @@ abstract SongEventData(SongEventDataRaw) from SongEventDataRaw to SongEventDataR
|
||||||
|
|
||||||
var title = eventSchema.getByName(key)?.title ?? 'UnknownField';
|
var title = eventSchema.getByName(key)?.title ?? 'UnknownField';
|
||||||
|
|
||||||
if (eventSchema.stringifyFieldValue(key, value) != null) trace(eventSchema.stringifyFieldValue(key, value));
|
// if (eventSchema.stringifyFieldValue(key, value) != null) trace(eventSchema.stringifyFieldValue(key, value));
|
||||||
var valueStr = eventSchema.stringifyFieldValue(key, value) ?? 'UnknownValue';
|
var valueStr = eventSchema.stringifyFieldValue(key, value) ?? 'UnknownValue';
|
||||||
|
|
||||||
result += '\n- ${title}: ${valueStr}';
|
result += '\n- ${title}: ${valueStr}';
|
||||||
|
|
|
@ -20,7 +20,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
||||||
* Handle breaking changes by incrementing this value
|
* Handle breaking changes by incrementing this value
|
||||||
* and adding migration to the `migrateStageData()` function.
|
* and adding migration to the `migrateStageData()` function.
|
||||||
*/
|
*/
|
||||||
public static final SONG_METADATA_VERSION:thx.semver.Version = "2.2.1";
|
public static final SONG_METADATA_VERSION:thx.semver.Version = "2.2.2";
|
||||||
|
|
||||||
public static final SONG_METADATA_VERSION_RULE:thx.semver.VersionRule = "2.2.x";
|
public static final SONG_METADATA_VERSION_RULE:thx.semver.VersionRule = "2.2.x";
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
||||||
// SCRIPTED ENTRIES
|
// SCRIPTED ENTRIES
|
||||||
//
|
//
|
||||||
var scriptedEntryClassNames:Array<String> = getScriptedClassNames();
|
var scriptedEntryClassNames:Array<String> = getScriptedClassNames();
|
||||||
log('Registering ${scriptedEntryClassNames.length} scripted entries...');
|
log('Parsing ${scriptedEntryClassNames.length} scripted entries...');
|
||||||
|
|
||||||
for (entryCls in scriptedEntryClassNames)
|
for (entryCls in scriptedEntryClassNames)
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
|
||||||
var unscriptedEntryIds:Array<String> = entryIdList.filter(function(entryId:String):Bool {
|
var unscriptedEntryIds:Array<String> = entryIdList.filter(function(entryId:String):Bool {
|
||||||
return !entries.exists(entryId);
|
return !entries.exists(entryId);
|
||||||
});
|
});
|
||||||
log('Fetching data for ${unscriptedEntryIds.length} unscripted entries...');
|
log('Parsing ${unscriptedEntryIds.length} unscripted entries...');
|
||||||
for (entryId in unscriptedEntryIds)
|
for (entryId in unscriptedEntryIds)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -2,7 +2,6 @@ package funkin.modding;
|
||||||
|
|
||||||
import funkin.util.macro.ClassMacro;
|
import funkin.util.macro.ClassMacro;
|
||||||
import funkin.modding.module.ModuleHandler;
|
import funkin.modding.module.ModuleHandler;
|
||||||
import funkin.play.character.CharacterData.CharacterDataParser;
|
|
||||||
import funkin.data.song.SongData;
|
import funkin.data.song.SongData;
|
||||||
import funkin.data.stage.StageData;
|
import funkin.data.stage.StageData;
|
||||||
import polymod.Polymod;
|
import polymod.Polymod;
|
||||||
|
@ -13,10 +12,11 @@ import funkin.data.stage.StageRegistry;
|
||||||
import funkin.util.FileUtil;
|
import funkin.util.FileUtil;
|
||||||
import funkin.data.level.LevelRegistry;
|
import funkin.data.level.LevelRegistry;
|
||||||
import funkin.data.notestyle.NoteStyleRegistry;
|
import funkin.data.notestyle.NoteStyleRegistry;
|
||||||
import funkin.play.cutscene.dialogue.ConversationDataParser;
|
import funkin.data.dialogue.ConversationRegistry;
|
||||||
import funkin.play.cutscene.dialogue.DialogueBoxDataParser;
|
import funkin.data.dialogue.DialogueBoxRegistry;
|
||||||
|
import funkin.data.dialogue.SpeakerRegistry;
|
||||||
|
import funkin.play.character.CharacterData.CharacterDataParser;
|
||||||
import funkin.save.Save;
|
import funkin.save.Save;
|
||||||
import funkin.play.cutscene.dialogue.SpeakerDataParser;
|
|
||||||
import funkin.data.song.SongRegistry;
|
import funkin.data.song.SongRegistry;
|
||||||
|
|
||||||
class PolymodHandler
|
class PolymodHandler
|
||||||
|
@ -208,8 +208,8 @@ class PolymodHandler
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
assetLibraryPaths: [
|
assetLibraryPaths: [
|
||||||
"default" => "preload", "shared" => "", "songs" => "songs", "tutorial" => "tutorial", "week1" => "week1", "week2" => "week2", "week3" => "week3",
|
"default" => "preload", "shared" => "shared", "songs" => "songs", "tutorial" => "tutorial", "week1" => "week1", "week2" => "week2",
|
||||||
"week4" => "week4", "week5" => "week5", "week6" => "week6", "week7" => "week7", "weekend1" => "weekend1",
|
"week3" => "week3", "week4" => "week4", "week5" => "week5", "week6" => "week6", "week7" => "week7", "weekend1" => "weekend1",
|
||||||
],
|
],
|
||||||
coreAssetRedirect: CORE_FOLDER,
|
coreAssetRedirect: CORE_FOLDER,
|
||||||
}
|
}
|
||||||
|
@ -273,11 +273,11 @@ class PolymodHandler
|
||||||
LevelRegistry.instance.loadEntries();
|
LevelRegistry.instance.loadEntries();
|
||||||
NoteStyleRegistry.instance.loadEntries();
|
NoteStyleRegistry.instance.loadEntries();
|
||||||
SongEventRegistry.loadEventCache();
|
SongEventRegistry.loadEventCache();
|
||||||
ConversationDataParser.loadConversationCache();
|
ConversationRegistry.instance.loadEntries();
|
||||||
DialogueBoxDataParser.loadDialogueBoxCache();
|
DialogueBoxRegistry.instance.loadEntries();
|
||||||
SpeakerDataParser.loadSpeakerCache();
|
SpeakerRegistry.instance.loadEntries();
|
||||||
StageRegistry.instance.loadEntries();
|
StageRegistry.instance.loadEntries();
|
||||||
CharacterDataParser.loadCharacterCache();
|
CharacterDataParser.loadCharacterCache(); // TODO: Migrate characters to BaseRegistry.
|
||||||
ModuleHandler.loadModuleCache();
|
ModuleHandler.loadModuleCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ import funkin.modding.events.ScriptEventDispatcher;
|
||||||
import funkin.play.character.BaseCharacter;
|
import funkin.play.character.BaseCharacter;
|
||||||
import funkin.play.character.CharacterData.CharacterDataParser;
|
import funkin.play.character.CharacterData.CharacterDataParser;
|
||||||
import funkin.play.cutscene.dialogue.Conversation;
|
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.VanillaCutscenes;
|
||||||
import funkin.play.cutscene.VideoCutscene;
|
import funkin.play.cutscene.VideoCutscene;
|
||||||
import funkin.data.event.SongEventRegistry;
|
import funkin.data.event.SongEventRegistry;
|
||||||
|
@ -1662,7 +1662,7 @@ class PlayState extends MusicBeatSubState
|
||||||
{
|
{
|
||||||
isInCutscene = true;
|
isInCutscene = true;
|
||||||
|
|
||||||
currentConversation = ConversationDataParser.fetchConversation(conversationId);
|
currentConversation = ConversationRegistry.instance.fetchEntry(conversationId);
|
||||||
if (currentConversation == null) return;
|
if (currentConversation == null) return;
|
||||||
|
|
||||||
currentConversation.completeCallback = onConversationComplete;
|
currentConversation.completeCallback = onConversationComplete;
|
||||||
|
|
|
@ -43,7 +43,7 @@ class CharacterDataParser
|
||||||
{
|
{
|
||||||
// Clear any stages that are cached if there were any.
|
// Clear any stages that are cached if there were any.
|
||||||
clearCharacterCache();
|
clearCharacterCache();
|
||||||
trace('Loading character cache...');
|
trace('[CHARACTER] Parsing all entries...');
|
||||||
|
|
||||||
//
|
//
|
||||||
// UNSCRIPTED CHARACTERS
|
// UNSCRIPTED CHARACTERS
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
package funkin.play.cutscene.dialogue;
|
||||||
|
|
||||||
|
import funkin.data.IRegistryEntry;
|
||||||
import flixel.FlxSprite;
|
import flixel.FlxSprite;
|
||||||
import flixel.group.FlxSpriteGroup;
|
import flixel.group.FlxSpriteGroup;
|
||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
|
import funkin.graphics.FunkinSprite;
|
||||||
import flixel.tweens.FlxTween;
|
import flixel.tweens.FlxTween;
|
||||||
import flixel.tweens.FlxEase;
|
import flixel.tweens.FlxEase;
|
||||||
import flixel.sound.FlxSound;
|
import flixel.sound.FlxSound;
|
||||||
|
@ -13,27 +15,30 @@ import funkin.modding.IScriptedClass.IEventHandler;
|
||||||
import funkin.play.cutscene.dialogue.DialogueBox;
|
import funkin.play.cutscene.dialogue.DialogueBox;
|
||||||
import funkin.modding.IScriptedClass.IDialogueScriptedClass;
|
import funkin.modding.IScriptedClass.IDialogueScriptedClass;
|
||||||
import funkin.modding.events.ScriptEventDispatcher;
|
import funkin.modding.events.ScriptEventDispatcher;
|
||||||
import funkin.play.cutscene.dialogue.ConversationData.DialogueEntryData;
|
|
||||||
import flixel.addons.display.FlxPieDial;
|
import flixel.addons.display.FlxPieDial;
|
||||||
|
import funkin.data.dialogue.ConversationData;
|
||||||
|
import funkin.data.dialogue.ConversationData.DialogueEntryData;
|
||||||
|
import funkin.data.dialogue.ConversationRegistry;
|
||||||
|
import funkin.data.dialogue.SpeakerData;
|
||||||
|
import funkin.data.dialogue.SpeakerRegistry;
|
||||||
|
import funkin.data.dialogue.DialogueBoxData;
|
||||||
|
import funkin.data.dialogue.DialogueBoxRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A high-level handler for dialogue.
|
* A high-level handler for dialogue.
|
||||||
*
|
*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass implements IRegistryEntry<ConversationData>
|
||||||
{
|
{
|
||||||
static final CONVERSATION_SKIP_TIMER:Float = 1.5;
|
static final CONVERSATION_SKIP_TIMER:Float = 1.5;
|
||||||
|
|
||||||
var skipHeldTimer:Float = 0.0;
|
var skipHeldTimer:Float = 0.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DATA
|
* The ID of the conversation.
|
||||||
*/
|
*/
|
||||||
/**
|
public final id:String;
|
||||||
* The ID of the associated dialogue.
|
|
||||||
*/
|
|
||||||
public final conversationId:String;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current state of the conversation.
|
* The current state of the conversation.
|
||||||
|
@ -41,9 +46,9 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
var state:ConversationState = ConversationState.Start;
|
var state:ConversationState = ConversationState.Start;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data for the associated dialogue.
|
* Conversation data as parsed from the JSON file.
|
||||||
*/
|
*/
|
||||||
var conversationData:ConversationData;
|
public final _data:ConversationData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current entry in the dialogue.
|
* The current entry in the dialogue.
|
||||||
|
@ -54,7 +59,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
function get_currentDialogueEntryCount():Int
|
function get_currentDialogueEntryCount():Int
|
||||||
{
|
{
|
||||||
return conversationData.dialogue.length;
|
return _data.dialogue.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,10 +78,10 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
function get_currentDialogueEntryData():DialogueEntryData
|
function get_currentDialogueEntryData():DialogueEntryData
|
||||||
{
|
{
|
||||||
if (conversationData == null || conversationData.dialogue == null) return null;
|
if (_data == null || _data.dialogue == null) return null;
|
||||||
if (currentDialogueEntry < 0 || currentDialogueEntry >= conversationData.dialogue.length) return null;
|
if (currentDialogueEntry < 0 || currentDialogueEntry >= _data.dialogue.length) return null;
|
||||||
|
|
||||||
return conversationData.dialogue[currentDialogueEntry];
|
return _data.dialogue[currentDialogueEntry];
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentDialogueLineString(get, never):String;
|
var currentDialogueLineString(get, never):String;
|
||||||
|
@ -94,7 +99,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
/**
|
/**
|
||||||
* GRAPHICS
|
* GRAPHICS
|
||||||
*/
|
*/
|
||||||
var backdrop:FlxSprite;
|
var backdrop:FunkinSprite;
|
||||||
|
|
||||||
var currentSpeaker:Speaker;
|
var currentSpeaker:Speaker;
|
||||||
|
|
||||||
|
@ -102,14 +107,17 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
var skipTimer:FlxPieDial;
|
var skipTimer:FlxPieDial;
|
||||||
|
|
||||||
public function new(conversationId:String)
|
public function new(id:String)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.conversationId = conversationId;
|
this.id = id;
|
||||||
this.conversationData = ConversationDataParser.parseConversationData(this.conversationId);
|
this._data = _fetchData(id);
|
||||||
|
|
||||||
if (conversationData == null) throw 'Could not load conversation data for conversation ID "$conversationId"';
|
if (_data == null)
|
||||||
|
{
|
||||||
|
throw 'Could not parse conversation data for id: $id';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCreate(event:ScriptEvent):Void
|
public function onCreate(event:ScriptEvent):Void
|
||||||
|
@ -125,14 +133,14 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
function setupMusic():Void
|
function setupMusic():Void
|
||||||
{
|
{
|
||||||
if (conversationData.music == null) return;
|
if (_data.music == null) return;
|
||||||
|
|
||||||
music = new FlxSound().loadEmbedded(Paths.music(conversationData.music.asset), true, true);
|
music = new FlxSound().loadEmbedded(Paths.music(_data.music.asset), true, true);
|
||||||
music.volume = 0;
|
music.volume = 0;
|
||||||
|
|
||||||
if (conversationData.music.fadeTime > 0.0)
|
if (_data.music.fadeTime > 0.0)
|
||||||
{
|
{
|
||||||
FlxTween.tween(music, {volume: 1.0}, conversationData.music.fadeTime, {ease: FlxEase.linear});
|
FlxTween.tween(music, {volume: 1.0}, _data.music.fadeTime, {ease: FlxEase.linear});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -145,19 +153,20 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
function setupBackdrop():Void
|
function setupBackdrop():Void
|
||||||
{
|
{
|
||||||
backdrop = new FlxSprite(0, 0);
|
backdrop = new FunkinSprite(0, 0);
|
||||||
|
|
||||||
if (conversationData.backdrop == null) return;
|
if (_data.backdrop == null) return;
|
||||||
|
|
||||||
// Play intro
|
// Play intro
|
||||||
switch (conversationData?.backdrop.type)
|
switch (_data.backdrop)
|
||||||
{
|
{
|
||||||
case SOLID:
|
case SOLID(backdropData):
|
||||||
backdrop.makeGraphic(Std.int(FlxG.width), Std.int(FlxG.height), FlxColor.fromString(conversationData.backdrop.data.color));
|
var targetColor:FlxColor = FlxColor.fromString(backdropData.color);
|
||||||
if (conversationData.backdrop.data.fadeTime > 0.0)
|
backdrop.makeSolidColor(Std.int(FlxG.width), Std.int(FlxG.height), targetColor);
|
||||||
|
if (backdropData.fadeTime > 0.0)
|
||||||
{
|
{
|
||||||
backdrop.alpha = 0.0;
|
backdrop.alpha = 0.0;
|
||||||
FlxTween.tween(backdrop, {alpha: 1.0}, conversationData.backdrop.data.fadeTime, {ease: FlxEase.linear});
|
FlxTween.tween(backdrop, {alpha: 1.0}, backdropData.fadeTime, {ease: FlxEase.linear});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -190,9 +199,9 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
var nextSpeakerId:String = currentDialogueEntryData.speaker;
|
var nextSpeakerId:String = currentDialogueEntryData.speaker;
|
||||||
|
|
||||||
// Skip the next steps if the current speaker is already displayed.
|
// Skip the next steps if the current speaker is already displayed.
|
||||||
if (currentSpeaker != null && nextSpeakerId == currentSpeaker.speakerId) return;
|
if (currentSpeaker != null && nextSpeakerId == currentSpeaker.id) return;
|
||||||
|
|
||||||
var nextSpeaker:Speaker = SpeakerDataParser.fetchSpeaker(nextSpeakerId);
|
var nextSpeaker:Speaker = SpeakerRegistry.instance.fetchEntry(nextSpeakerId);
|
||||||
|
|
||||||
if (currentSpeaker != null)
|
if (currentSpeaker != null)
|
||||||
{
|
{
|
||||||
|
@ -241,7 +250,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
var nextDialogueBoxId:String = currentDialogueEntryData?.box;
|
var nextDialogueBoxId:String = currentDialogueEntryData?.box;
|
||||||
|
|
||||||
// Skip the next steps if the current speaker is already displayed.
|
// Skip the next steps if the current speaker is already displayed.
|
||||||
if (currentDialogueBox != null && nextDialogueBoxId == currentDialogueBox.dialogueBoxId) return;
|
if (currentDialogueBox != null && nextDialogueBoxId == currentDialogueBox.id) return;
|
||||||
|
|
||||||
if (currentDialogueBox != null)
|
if (currentDialogueBox != null)
|
||||||
{
|
{
|
||||||
|
@ -250,7 +259,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
currentDialogueBox = null;
|
currentDialogueBox = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextDialogueBox:DialogueBox = DialogueBoxDataParser.fetchDialogueBox(nextDialogueBoxId);
|
var nextDialogueBox:DialogueBox = DialogueBoxRegistry.instance.fetchEntry(nextDialogueBoxId);
|
||||||
|
|
||||||
if (nextDialogueBox == null)
|
if (nextDialogueBox == null)
|
||||||
{
|
{
|
||||||
|
@ -378,20 +387,18 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
public function startOutro():Void
|
public function startOutro():Void
|
||||||
{
|
{
|
||||||
switch (conversationData?.outro?.type)
|
switch (_data?.outro)
|
||||||
{
|
{
|
||||||
case FADE:
|
case FADE(outroData):
|
||||||
var fadeTime:Float = conversationData?.outro.data.fadeTime ?? 1.0;
|
outroTween = FlxTween.tween(this, {alpha: 0.0}, outroData.fadeTime,
|
||||||
|
|
||||||
outroTween = FlxTween.tween(this, {alpha: 0.0}, fadeTime,
|
|
||||||
{
|
{
|
||||||
type: ONESHOT, // holy shit like the game no way
|
type: ONESHOT, // holy shit like the game no way
|
||||||
startDelay: 0,
|
startDelay: 0,
|
||||||
onComplete: (_) -> endOutro(),
|
onComplete: (_) -> endOutro(),
|
||||||
});
|
});
|
||||||
|
|
||||||
FlxTween.tween(this.music, {volume: 0.0}, fadeTime);
|
FlxTween.tween(this.music, {volume: 0.0}, outroData.fadeTime);
|
||||||
case NONE:
|
case NONE(_):
|
||||||
// Immediately clean up.
|
// Immediately clean up.
|
||||||
endOutro();
|
endOutro();
|
||||||
default:
|
default:
|
||||||
|
@ -400,7 +407,7 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var completeCallback:Void->Void;
|
public var completeCallback:() -> Void;
|
||||||
|
|
||||||
public function endOutro():Void
|
public function endOutro():Void
|
||||||
{
|
{
|
||||||
|
@ -596,7 +603,12 @@ class Conversation extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
public override function toString():String
|
public override function toString():String
|
||||||
{
|
{
|
||||||
return 'Conversation($conversationId)';
|
return 'Conversation($id)';
|
||||||
|
}
|
||||||
|
|
||||||
|
static function _fetchData(id:String):Null<ConversationData>
|
||||||
|
{
|
||||||
|
return ConversationRegistry.instance.parseEntryDataWithMigration(id, ConversationRegistry.instance.fetchEntryVersion(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,240 +0,0 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
|
||||||
|
|
||||||
import funkin.util.SerializerUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about a conversation.
|
|
||||||
* Includes what speakers are in the conversation, and what phrases they say.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.ConversationData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class ConversationData
|
|
||||||
{
|
|
||||||
public var version:String;
|
|
||||||
public var backdrop:BackdropData;
|
|
||||||
public var outro:OutroData;
|
|
||||||
public var music:MusicData;
|
|
||||||
public var dialogue:Array<DialogueEntryData>;
|
|
||||||
|
|
||||||
public function new(version:String, backdrop:BackdropData, outro:OutroData, music:MusicData, dialogue:Array<DialogueEntryData>)
|
|
||||||
{
|
|
||||||
this.version = version;
|
|
||||||
this.backdrop = backdrop;
|
|
||||||
this.outro = outro;
|
|
||||||
this.music = music;
|
|
||||||
this.dialogue = dialogue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromString(i:String):ConversationData
|
|
||||||
{
|
|
||||||
if (i == null || i == '') return null;
|
|
||||||
var data:
|
|
||||||
{
|
|
||||||
version:String,
|
|
||||||
backdrop:Dynamic, // TODO: tink.Json doesn't like when these are typed
|
|
||||||
?outro:Dynamic, // TODO: tink.Json doesn't like when these are typed
|
|
||||||
?music:Dynamic, // TODO: tink.Json doesn't like when these are typed
|
|
||||||
dialogue:Array<Dynamic> // TODO: tink.Json doesn't like when these are typed
|
|
||||||
} = tink.Json.parse(i);
|
|
||||||
return fromJson(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):ConversationData
|
|
||||||
{
|
|
||||||
// TODO: Check version and perform migrations if necessary.
|
|
||||||
if (j == null) return null;
|
|
||||||
return new ConversationData(j.version, BackdropData.fromJson(j.backdrop), OutroData.fromJson(j.outro), MusicData.fromJson(j.music),
|
|
||||||
j.dialogue.map(d -> DialogueEntryData.fromJson(d)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
version: this.version,
|
|
||||||
backdrop: this.backdrop.toJson(),
|
|
||||||
dialogue: this.dialogue.map(d -> d.toJson())
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about a single dialogue entry.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.ConversationData.DialogueEntryData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class DialogueEntryData
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The speaker who says this phrase.
|
|
||||||
*/
|
|
||||||
public var speaker:String;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The animation the speaker will play.
|
|
||||||
*/
|
|
||||||
public var speakerAnimation:String;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The text box that will appear.
|
|
||||||
*/
|
|
||||||
public var box:String;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The animation the dialogue box will play.
|
|
||||||
*/
|
|
||||||
public var boxAnimation:String;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The lines of text that will appear in the text box.
|
|
||||||
*/
|
|
||||||
public var text:Array<String>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The relative speed at which the text will scroll.
|
|
||||||
* @default 1.0
|
|
||||||
*/
|
|
||||||
public var speed:Float = 1.0;
|
|
||||||
|
|
||||||
public function new(speaker:String, speakerAnimation:String, box:String, boxAnimation:String, text:Array<String>, speed:Float = null)
|
|
||||||
{
|
|
||||||
this.speaker = speaker;
|
|
||||||
this.speakerAnimation = speakerAnimation;
|
|
||||||
this.box = box;
|
|
||||||
this.boxAnimation = boxAnimation;
|
|
||||||
this.text = text;
|
|
||||||
if (speed != null) this.speed = speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):DialogueEntryData
|
|
||||||
{
|
|
||||||
if (j == null) return null;
|
|
||||||
return new DialogueEntryData(j.speaker, j.speakerAnimation, j.box, j.boxAnimation, j.text, j.speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
var result:Dynamic =
|
|
||||||
{
|
|
||||||
speaker: this.speaker,
|
|
||||||
speakerAnimation: this.speakerAnimation,
|
|
||||||
box: this.box,
|
|
||||||
boxAnimation: this.boxAnimation,
|
|
||||||
text: this.text,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.speed != 1.0) result.speed = this.speed;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about a backdrop.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.ConversationData.BackdropData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class BackdropData
|
|
||||||
{
|
|
||||||
public var type:BackdropType;
|
|
||||||
public var data:Dynamic;
|
|
||||||
|
|
||||||
public function new(typeStr:String, data:Dynamic)
|
|
||||||
{
|
|
||||||
this.type = typeStr;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):BackdropData
|
|
||||||
{
|
|
||||||
if (j == null) return null;
|
|
||||||
return new BackdropData(j.type, j.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
type: this.type,
|
|
||||||
data: this.data
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum abstract BackdropType(String) from String to String
|
|
||||||
{
|
|
||||||
public var SOLID:BackdropType = 'solid';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about a music track.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.ConversationData.MusicData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class MusicData
|
|
||||||
{
|
|
||||||
public var asset:String;
|
|
||||||
|
|
||||||
public var fadeTime:Float;
|
|
||||||
|
|
||||||
@:optional
|
|
||||||
@:default(false)
|
|
||||||
public var looped:Bool;
|
|
||||||
|
|
||||||
public function new(asset:String, looped:Bool, fadeTime:Float = 0.0)
|
|
||||||
{
|
|
||||||
this.asset = asset;
|
|
||||||
this.looped = looped;
|
|
||||||
this.fadeTime = fadeTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):MusicData
|
|
||||||
{
|
|
||||||
if (j == null) return null;
|
|
||||||
return new MusicData(j.asset, j.looped, j.fadeTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
asset: this.asset,
|
|
||||||
looped: this.looped,
|
|
||||||
fadeTime: this.fadeTime
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about an outro.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.ConversationData.OutroData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class OutroData
|
|
||||||
{
|
|
||||||
public var type:OutroType;
|
|
||||||
public var data:Dynamic;
|
|
||||||
|
|
||||||
public function new(?typeStr:String, data:Dynamic)
|
|
||||||
{
|
|
||||||
this.type = typeStr ?? OutroType.NONE;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):OutroData
|
|
||||||
{
|
|
||||||
if (j == null) return null;
|
|
||||||
return new OutroData(j.type, j.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
type: this.type,
|
|
||||||
data: this.data
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum abstract OutroType(String) from String to String
|
|
||||||
{
|
|
||||||
public var NONE:OutroType = 'none';
|
|
||||||
public var FADE:OutroType = 'fade';
|
|
||||||
}
|
|
|
@ -1,163 +0,0 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
|
||||||
|
|
||||||
import openfl.Assets;
|
|
||||||
import funkin.util.assets.DataAssets;
|
|
||||||
import funkin.play.cutscene.dialogue.ScriptedConversation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains utilities for loading and parsing conversation data.
|
|
||||||
* TODO: Refactor to use the json2object + BaseRegistry system that actually validates things for you.
|
|
||||||
*/
|
|
||||||
class ConversationDataParser
|
|
||||||
{
|
|
||||||
public static final CONVERSATION_DATA_VERSION:String = '1.0.0';
|
|
||||||
public static final CONVERSATION_DATA_VERSION_RULE:String = '1.0.x';
|
|
||||||
|
|
||||||
static final conversationCache:Map<String, Conversation> = new Map<String, Conversation>();
|
|
||||||
static final conversationScriptedClass:Map<String, String> = new Map<String, String>();
|
|
||||||
|
|
||||||
static final DEFAULT_CONVERSATION_ID:String = 'UNKNOWN';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses and preloads the game's conversation data and scripts when the game starts.
|
|
||||||
*
|
|
||||||
* If you want to force conversations to be reloaded, you can just call this function again.
|
|
||||||
*/
|
|
||||||
public static function loadConversationCache():Void
|
|
||||||
{
|
|
||||||
clearConversationCache();
|
|
||||||
trace('Loading dialogue conversation cache...');
|
|
||||||
|
|
||||||
//
|
|
||||||
// SCRIPTED CONVERSATIONS
|
|
||||||
//
|
|
||||||
var scriptedConversationClassNames:Array<String> = ScriptedConversation.listScriptClasses();
|
|
||||||
trace(' Instantiating ${scriptedConversationClassNames.length} scripted conversations...');
|
|
||||||
for (conversationCls in scriptedConversationClassNames)
|
|
||||||
{
|
|
||||||
var conversation:Conversation = ScriptedConversation.init(conversationCls, DEFAULT_CONVERSATION_ID);
|
|
||||||
if (conversation != null)
|
|
||||||
{
|
|
||||||
trace(' Loaded scripted conversation: ${conversationCls}');
|
|
||||||
// Disable the rendering logic for conversation until it's loaded.
|
|
||||||
// Note that kill() =/= destroy()
|
|
||||||
conversation.kill();
|
|
||||||
|
|
||||||
// Then store it.
|
|
||||||
conversationCache.set(conversation.conversationId, conversation);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trace(' Failed to instantiate scripted conversation class: ${conversationCls}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// UNSCRIPTED CONVERSATIONS
|
|
||||||
//
|
|
||||||
// Scripts refers to code here, not the actual dialogue.
|
|
||||||
var conversationIdList:Array<String> = DataAssets.listDataFilesInPath('dialogue/conversations/');
|
|
||||||
// Filter out conversations that are scripted.
|
|
||||||
var unscriptedConversationIds:Array<String> = conversationIdList.filter(function(conversationId:String):Bool {
|
|
||||||
return !conversationCache.exists(conversationId);
|
|
||||||
});
|
|
||||||
trace(' Fetching data for ${unscriptedConversationIds.length} conversations...');
|
|
||||||
for (conversationId in unscriptedConversationIds)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var conversation:Conversation = new Conversation(conversationId);
|
|
||||||
// Say something offensive to kill the conversation.
|
|
||||||
// We will revive it later.
|
|
||||||
conversation.kill();
|
|
||||||
if (conversation != null)
|
|
||||||
{
|
|
||||||
trace(' Loaded conversation data: ${conversation.conversationId}');
|
|
||||||
conversationCache.set(conversation.conversationId, conversation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
trace(e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches data for a conversation and returns a Conversation instance,
|
|
||||||
* ready to be displayed.
|
|
||||||
* @param conversationId The ID of the conversation to fetch.
|
|
||||||
* @return The conversation instance, or null if the conversation was not found.
|
|
||||||
*/
|
|
||||||
public static function fetchConversation(conversationId:String):Null<Conversation>
|
|
||||||
{
|
|
||||||
if (conversationId != null && conversationId != '' && conversationCache.exists(conversationId))
|
|
||||||
{
|
|
||||||
trace('Successfully fetched conversation: ${conversationId}');
|
|
||||||
var conversation:Conversation = conversationCache.get(conversationId);
|
|
||||||
// ...ANYway...
|
|
||||||
conversation.revive();
|
|
||||||
return conversation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trace('Failed to fetch conversation, not found in cache: ${conversationId}');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function clearConversationCache():Void
|
|
||||||
{
|
|
||||||
if (conversationCache != null)
|
|
||||||
{
|
|
||||||
for (conversation in conversationCache)
|
|
||||||
{
|
|
||||||
conversation.destroy();
|
|
||||||
}
|
|
||||||
conversationCache.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function listConversationIds():Array<String>
|
|
||||||
{
|
|
||||||
return conversationCache.keys().array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a conversation's JSON file, parse its data, and return it.
|
|
||||||
*
|
|
||||||
* @param conversationId The conversation to load.
|
|
||||||
* @return The conversation data, or null if validation failed.
|
|
||||||
*/
|
|
||||||
public static function parseConversationData(conversationId:String):Null<ConversationData>
|
|
||||||
{
|
|
||||||
trace('Parsing conversation data: ${conversationId}');
|
|
||||||
var rawJson:String = loadConversationFile(conversationId);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var conversationData:ConversationData = ConversationData.fromString(rawJson);
|
|
||||||
return conversationData;
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
trace('Failed to parse conversation ($conversationId).');
|
|
||||||
trace(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function loadConversationFile(conversationPath:String):String
|
|
||||||
{
|
|
||||||
var conversationFilePath:String = Paths.json('dialogue/conversations/${conversationPath}');
|
|
||||||
var rawJson:String = Assets.getText(conversationFilePath).trim();
|
|
||||||
|
|
||||||
while (!rawJson.endsWith('}') && rawJson.length > 0)
|
|
||||||
{
|
|
||||||
rawJson = rawJson.substr(0, rawJson.length - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rawJson;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
package funkin.play.cutscene.dialogue;
|
||||||
|
|
||||||
import flixel.FlxSprite;
|
import flixel.FlxSprite;
|
||||||
|
import funkin.data.IRegistryEntry;
|
||||||
import flixel.group.FlxSpriteGroup;
|
import flixel.group.FlxSpriteGroup;
|
||||||
import flixel.graphics.frames.FlxFramesCollection;
|
import flixel.graphics.frames.FlxFramesCollection;
|
||||||
import flixel.text.FlxText;
|
import flixel.text.FlxText;
|
||||||
|
@ -9,18 +10,21 @@ import funkin.util.assets.FlxAnimationUtil;
|
||||||
import funkin.modding.events.ScriptEvent;
|
import funkin.modding.events.ScriptEvent;
|
||||||
import funkin.modding.IScriptedClass.IDialogueScriptedClass;
|
import funkin.modding.IScriptedClass.IDialogueScriptedClass;
|
||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
|
import funkin.data.dialogue.DialogueBoxData;
|
||||||
|
import funkin.data.dialogue.DialogueBoxRegistry;
|
||||||
|
|
||||||
class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass implements IRegistryEntry<DialogueBoxData>
|
||||||
{
|
{
|
||||||
public final dialogueBoxId:String;
|
public final id:String;
|
||||||
|
|
||||||
public var dialogueBoxName(get, never):String;
|
public var dialogueBoxName(get, never):String;
|
||||||
|
|
||||||
function get_dialogueBoxName():String
|
function get_dialogueBoxName():String
|
||||||
{
|
{
|
||||||
return boxData?.name ?? 'UNKNOWN';
|
return _data.name ?? 'UNKNOWN';
|
||||||
}
|
}
|
||||||
|
|
||||||
var boxData:DialogueBoxData;
|
public final _data:DialogueBoxData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Offset the speaker's sprite by this much when playing each animation.
|
* Offset the speaker's sprite by this much when playing each animation.
|
||||||
|
@ -88,13 +92,16 @@ class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
return this.speed;
|
return this.speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function new(dialogueBoxId:String)
|
public function new(id:String)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.dialogueBoxId = dialogueBoxId;
|
this.id = id;
|
||||||
this.boxData = DialogueBoxDataParser.parseDialogueBoxData(this.dialogueBoxId);
|
this._data = _fetchData(id);
|
||||||
|
|
||||||
if (boxData == null) throw 'Could not load dialogue box data for box ID "$dialogueBoxId"';
|
if (_data == null)
|
||||||
|
{
|
||||||
|
throw 'Could not parse dialogue box data for id: $id';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCreate(event:ScriptEvent):Void
|
public function onCreate(event:ScriptEvent):Void
|
||||||
|
@ -115,18 +122,18 @@ class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
function loadSpritesheet():Void
|
function loadSpritesheet():Void
|
||||||
{
|
{
|
||||||
trace('[DIALOGUE BOX] Loading spritesheet ${boxData.assetPath} for ${dialogueBoxId}');
|
trace('[DIALOGUE BOX] Loading spritesheet ${_data.assetPath} for ${id}');
|
||||||
|
|
||||||
var tex:FlxFramesCollection = Paths.getSparrowAtlas(boxData.assetPath);
|
var tex:FlxFramesCollection = Paths.getSparrowAtlas(_data.assetPath);
|
||||||
if (tex == null)
|
if (tex == null)
|
||||||
{
|
{
|
||||||
trace('Could not load Sparrow sprite: ${boxData.assetPath}');
|
trace('Could not load Sparrow sprite: ${_data.assetPath}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.boxSprite.frames = tex;
|
this.boxSprite.frames = tex;
|
||||||
|
|
||||||
if (boxData.isPixel)
|
if (_data.isPixel)
|
||||||
{
|
{
|
||||||
this.boxSprite.antialiasing = false;
|
this.boxSprite.antialiasing = false;
|
||||||
}
|
}
|
||||||
|
@ -135,9 +142,10 @@ class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
this.boxSprite.antialiasing = true;
|
this.boxSprite.antialiasing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.flipX = boxData.flipX;
|
this.flipX = _data.flipX;
|
||||||
this.globalOffsets = boxData.offsets;
|
this.flipY = _data.flipY;
|
||||||
this.setScale(boxData.scale);
|
this.globalOffsets = _data.offsets;
|
||||||
|
this.setScale(_data.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setText(newText:String):Void
|
public function setText(newText:String):Void
|
||||||
|
@ -184,11 +192,11 @@ class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
|
|
||||||
function loadAnimations():Void
|
function loadAnimations():Void
|
||||||
{
|
{
|
||||||
trace('[DIALOGUE BOX] Loading ${boxData.animations.length} animations for ${dialogueBoxId}');
|
trace('[DIALOGUE BOX] Loading ${_data.animations.length} animations for ${id}');
|
||||||
|
|
||||||
FlxAnimationUtil.addAtlasAnimations(this.boxSprite, boxData.animations);
|
FlxAnimationUtil.addAtlasAnimations(this.boxSprite, _data.animations);
|
||||||
|
|
||||||
for (anim in boxData.animations)
|
for (anim in _data.animations)
|
||||||
{
|
{
|
||||||
if (anim.offsets == null)
|
if (anim.offsets == null)
|
||||||
{
|
{
|
||||||
|
@ -201,7 +209,7 @@ class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
}
|
}
|
||||||
|
|
||||||
var animNames:Array<String> = this.boxSprite?.animation?.getNameList() ?? [];
|
var animNames:Array<String> = this.boxSprite?.animation?.getNameList() ?? [];
|
||||||
trace('[DIALOGUE BOX] Successfully loaded ${animNames.length} animations for ${dialogueBoxId}');
|
trace('[DIALOGUE BOX] Successfully loaded ${animNames.length} animations for ${id}');
|
||||||
|
|
||||||
boxSprite.animation.callback = this.onAnimationFrame;
|
boxSprite.animation.callback = this.onAnimationFrame;
|
||||||
boxSprite.animation.finishCallback = this.onAnimationFinished;
|
boxSprite.animation.finishCallback = this.onAnimationFinished;
|
||||||
|
@ -234,16 +242,16 @@ class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
function loadText():Void
|
function loadText():Void
|
||||||
{
|
{
|
||||||
textDisplay = new FlxTypeText(0, 0, 300, '', 32);
|
textDisplay = new FlxTypeText(0, 0, 300, '', 32);
|
||||||
textDisplay.fieldWidth = boxData.text.width;
|
textDisplay.fieldWidth = _data.text.width;
|
||||||
textDisplay.setFormat('Pixel Arial 11 Bold', boxData.text.size, FlxColor.fromString(boxData.text.color), LEFT, SHADOW,
|
textDisplay.setFormat(_data.text.fontFamily, _data.text.size, FlxColor.fromString(_data.text.color), LEFT, SHADOW,
|
||||||
FlxColor.fromString(boxData.text.shadowColor ?? '#00000000'), false);
|
FlxColor.fromString(_data.text.shadowColor ?? '#00000000'), false);
|
||||||
textDisplay.borderSize = boxData.text.shadowWidth ?? 2;
|
textDisplay.borderSize = _data.text.shadowWidth ?? 2;
|
||||||
textDisplay.sounds = [FlxG.sound.load(Paths.sound('pixelText'), 0.6)];
|
textDisplay.sounds = [FlxG.sound.load(Paths.sound('pixelText'), 0.6)];
|
||||||
|
|
||||||
textDisplay.completeCallback = onTypingComplete;
|
textDisplay.completeCallback = onTypingComplete;
|
||||||
|
|
||||||
textDisplay.x += boxData.text.offsets[0];
|
textDisplay.x += _data.text.offsets[0];
|
||||||
textDisplay.y += boxData.text.offsets[1];
|
textDisplay.y += _data.text.offsets[1];
|
||||||
|
|
||||||
add(textDisplay);
|
add(textDisplay);
|
||||||
}
|
}
|
||||||
|
@ -374,4 +382,14 @@ class DialogueBox extends FlxSpriteGroup implements IDialogueScriptedClass
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onScriptEvent(event:ScriptEvent):Void {}
|
public function onScriptEvent(event:ScriptEvent):Void {}
|
||||||
|
|
||||||
|
public override function toString():String
|
||||||
|
{
|
||||||
|
return 'DialogueBox($id)';
|
||||||
|
}
|
||||||
|
|
||||||
|
static function _fetchData(id:String):Null<DialogueBoxData>
|
||||||
|
{
|
||||||
|
return DialogueBoxRegistry.instance.parseEntryDataWithMigration(id, DialogueBoxRegistry.instance.fetchEntryVersion(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,124 +0,0 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
|
||||||
|
|
||||||
import funkin.data.animation.AnimationData;
|
|
||||||
import funkin.util.SerializerUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about a text box.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.DialogueBoxData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class DialogueBoxData
|
|
||||||
{
|
|
||||||
public var version:String;
|
|
||||||
public var name:String;
|
|
||||||
public var assetPath:String;
|
|
||||||
public var flipX:Bool;
|
|
||||||
public var flipY:Bool;
|
|
||||||
public var isPixel:Bool;
|
|
||||||
public var offsets:Array<Float>;
|
|
||||||
public var text:DialogueBoxTextData;
|
|
||||||
public var scale:Float;
|
|
||||||
public var animations:Array<AnimationData>;
|
|
||||||
|
|
||||||
public function new(version:String, name:String, assetPath:String, flipX:Bool = false, flipY:Bool = false, isPixel:Bool = false, offsets:Null<Array<Float>>,
|
|
||||||
text:DialogueBoxTextData, scale:Float = 1.0, animations:Array<AnimationData>)
|
|
||||||
{
|
|
||||||
this.version = version;
|
|
||||||
this.name = name;
|
|
||||||
this.assetPath = assetPath;
|
|
||||||
this.flipX = flipX;
|
|
||||||
this.flipY = flipY;
|
|
||||||
this.isPixel = isPixel;
|
|
||||||
this.offsets = offsets ?? [0, 0];
|
|
||||||
this.text = text;
|
|
||||||
this.scale = scale;
|
|
||||||
this.animations = animations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromString(i:String):DialogueBoxData
|
|
||||||
{
|
|
||||||
if (i == null || i == '') return null;
|
|
||||||
var data:
|
|
||||||
{
|
|
||||||
version:String,
|
|
||||||
name:String,
|
|
||||||
assetPath:String,
|
|
||||||
flipX:Bool,
|
|
||||||
flipY:Bool,
|
|
||||||
isPixel:Bool,
|
|
||||||
?offsets:Array<Float>,
|
|
||||||
text:Dynamic,
|
|
||||||
scale:Float,
|
|
||||||
animations:Array<AnimationData>
|
|
||||||
} = tink.Json.parse(i);
|
|
||||||
return fromJson(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):DialogueBoxData
|
|
||||||
{
|
|
||||||
// TODO: Check version and perform migrations if necessary.
|
|
||||||
if (j == null) return null;
|
|
||||||
return new DialogueBoxData(j.version, j.name, j.assetPath, j.flipX, j.flipY, j.isPixel, j.offsets, DialogueBoxTextData.fromJson(j.text), j.scale,
|
|
||||||
j.animations);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
version: this.version,
|
|
||||||
name: this.name,
|
|
||||||
assetPath: this.assetPath,
|
|
||||||
flipX: this.flipX,
|
|
||||||
flipY: this.flipY,
|
|
||||||
isPixel: this.isPixel,
|
|
||||||
offsets: this.offsets,
|
|
||||||
scale: this.scale,
|
|
||||||
animations: this.animations
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about text in a text box.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.DialogueBoxTextData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class DialogueBoxTextData
|
|
||||||
{
|
|
||||||
public var offsets:Array<Float>;
|
|
||||||
public var width:Int;
|
|
||||||
public var size:Int;
|
|
||||||
public var color:String;
|
|
||||||
public var shadowColor:Null<String>;
|
|
||||||
public var shadowWidth:Null<Int>;
|
|
||||||
|
|
||||||
public function new(offsets:Null<Array<Float>>, ?width:Int, ?size:Int, color:String, ?shadowColor:String, shadowWidth:Null<Int>)
|
|
||||||
{
|
|
||||||
this.offsets = offsets ?? [0, 0];
|
|
||||||
this.width = width ?? 300;
|
|
||||||
this.size = size ?? 32;
|
|
||||||
this.color = color;
|
|
||||||
this.shadowColor = shadowColor;
|
|
||||||
this.shadowWidth = shadowWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):DialogueBoxTextData
|
|
||||||
{
|
|
||||||
// TODO: Check version and perform migrations if necessary.
|
|
||||||
if (j == null) return null;
|
|
||||||
return new DialogueBoxTextData(j.offsets, j.width, j.size, j.color, j.shadowColor, j.shadowWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
offsets: this.offsets,
|
|
||||||
width: this.width,
|
|
||||||
size: this.size,
|
|
||||||
color: this.color,
|
|
||||||
shadowColor: this.shadowColor,
|
|
||||||
shadowWidth: this.shadowWidth,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,159 +0,0 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
|
||||||
|
|
||||||
import openfl.Assets;
|
|
||||||
import funkin.util.assets.DataAssets;
|
|
||||||
import funkin.play.cutscene.dialogue.DialogueBox;
|
|
||||||
import funkin.play.cutscene.dialogue.ScriptedDialogueBox;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains utilities for loading and parsing dialogueBox data.
|
|
||||||
*/
|
|
||||||
class DialogueBoxDataParser
|
|
||||||
{
|
|
||||||
public static final DIALOGUE_BOX_DATA_VERSION:String = '1.0.0';
|
|
||||||
public static final DIALOGUE_BOX_DATA_VERSION_RULE:String = '1.0.x';
|
|
||||||
|
|
||||||
static final dialogueBoxCache:Map<String, DialogueBox> = new Map<String, DialogueBox>();
|
|
||||||
|
|
||||||
static final dialogueBoxScriptedClass:Map<String, String> = new Map<String, String>();
|
|
||||||
|
|
||||||
static final DEFAULT_DIALOGUE_BOX_ID:String = 'UNKNOWN';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses and preloads the game's dialogueBox data and scripts when the game starts.
|
|
||||||
*
|
|
||||||
* If you want to force dialogue boxes to be reloaded, you can just call this function again.
|
|
||||||
*/
|
|
||||||
public static function loadDialogueBoxCache():Void
|
|
||||||
{
|
|
||||||
clearDialogueBoxCache();
|
|
||||||
trace('Loading dialogue box cache...');
|
|
||||||
|
|
||||||
//
|
|
||||||
// SCRIPTED CONVERSATIONS
|
|
||||||
//
|
|
||||||
var scriptedDialogueBoxClassNames:Array<String> = ScriptedDialogueBox.listScriptClasses();
|
|
||||||
trace(' Instantiating ${scriptedDialogueBoxClassNames.length} scripted dialogue boxes...');
|
|
||||||
for (dialogueBoxCls in scriptedDialogueBoxClassNames)
|
|
||||||
{
|
|
||||||
var dialogueBox:DialogueBox = ScriptedDialogueBox.init(dialogueBoxCls, DEFAULT_DIALOGUE_BOX_ID);
|
|
||||||
if (dialogueBox != null)
|
|
||||||
{
|
|
||||||
trace(' Loaded scripted dialogue box: ${dialogueBox.dialogueBoxName}');
|
|
||||||
// Disable the rendering logic for dialogueBox until it's loaded.
|
|
||||||
// Note that kill() =/= destroy()
|
|
||||||
dialogueBox.kill();
|
|
||||||
|
|
||||||
// Then store it.
|
|
||||||
dialogueBoxCache.set(dialogueBox.dialogueBoxId, dialogueBox);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trace(' Failed to instantiate scripted dialogueBox class: ${dialogueBoxCls}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// UNSCRIPTED CONVERSATIONS
|
|
||||||
//
|
|
||||||
// Scripts refers to code here, not the actual dialogue.
|
|
||||||
var dialogueBoxIdList:Array<String> = DataAssets.listDataFilesInPath('dialogue/boxes/');
|
|
||||||
// Filter out dialogue boxes that are scripted.
|
|
||||||
var unscriptedDialogueBoxIds:Array<String> = dialogueBoxIdList.filter(function(dialogueBoxId:String):Bool {
|
|
||||||
return !dialogueBoxCache.exists(dialogueBoxId);
|
|
||||||
});
|
|
||||||
trace(' Fetching data for ${unscriptedDialogueBoxIds.length} dialogue boxes...');
|
|
||||||
for (dialogueBoxId in unscriptedDialogueBoxIds)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var dialogueBox:DialogueBox = new DialogueBox(dialogueBoxId);
|
|
||||||
if (dialogueBox != null)
|
|
||||||
{
|
|
||||||
trace(' Loaded dialogueBox data: ${dialogueBox.dialogueBoxName}');
|
|
||||||
dialogueBoxCache.set(dialogueBox.dialogueBoxId, dialogueBox);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
trace(e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches data for a dialogueBox and returns a DialogueBox instance,
|
|
||||||
* ready to be displayed.
|
|
||||||
* @param dialogueBoxId The ID of the dialogueBox to fetch.
|
|
||||||
* @return The dialogueBox instance, or null if the dialogueBox was not found.
|
|
||||||
*/
|
|
||||||
public static function fetchDialogueBox(dialogueBoxId:String):Null<DialogueBox>
|
|
||||||
{
|
|
||||||
if (dialogueBoxId != null && dialogueBoxId != '' && dialogueBoxCache.exists(dialogueBoxId))
|
|
||||||
{
|
|
||||||
trace('Successfully fetched dialogueBox: ${dialogueBoxId}');
|
|
||||||
var dialogueBox:DialogueBox = dialogueBoxCache.get(dialogueBoxId);
|
|
||||||
dialogueBox.revive();
|
|
||||||
return dialogueBox;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trace('Failed to fetch dialogueBox, not found in cache: ${dialogueBoxId}');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function clearDialogueBoxCache():Void
|
|
||||||
{
|
|
||||||
if (dialogueBoxCache != null)
|
|
||||||
{
|
|
||||||
for (dialogueBox in dialogueBoxCache)
|
|
||||||
{
|
|
||||||
dialogueBox.destroy();
|
|
||||||
}
|
|
||||||
dialogueBoxCache.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function listDialogueBoxIds():Array<String>
|
|
||||||
{
|
|
||||||
return dialogueBoxCache.keys().array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a dialogueBox's JSON file, parse its data, and return it.
|
|
||||||
*
|
|
||||||
* @param dialogueBoxId The dialogueBox to load.
|
|
||||||
* @return The dialogueBox data, or null if validation failed.
|
|
||||||
*/
|
|
||||||
public static function parseDialogueBoxData(dialogueBoxId:String):Null<DialogueBoxData>
|
|
||||||
{
|
|
||||||
var rawJson:String = loadDialogueBoxFile(dialogueBoxId);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var dialogueBoxData:DialogueBoxData = DialogueBoxData.fromString(rawJson);
|
|
||||||
return dialogueBoxData;
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
trace('Failed to parse dialogueBox ($dialogueBoxId).');
|
|
||||||
trace(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function loadDialogueBoxFile(dialogueBoxPath:String):String
|
|
||||||
{
|
|
||||||
var dialogueBoxFilePath:String = Paths.json('dialogue/boxes/${dialogueBoxPath}');
|
|
||||||
var rawJson:String = Assets.getText(dialogueBoxFilePath).trim();
|
|
||||||
|
|
||||||
while (!rawJson.endsWith('}') && rawJson.length > 0)
|
|
||||||
{
|
|
||||||
rawJson = rawJson.substr(0, rawJson.length - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rawJson;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,10 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
package funkin.play.cutscene.dialogue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A script that can be tied to a Conversation.
|
||||||
|
* Create a scripted class that extends Conversation to use this.
|
||||||
|
* This allows you to customize how a specific conversation appears and behaves.
|
||||||
|
* Someone clever could use this to add branching dialogue I think.
|
||||||
|
*/
|
||||||
@:hscriptClass
|
@:hscriptClass
|
||||||
class ScriptedConversation extends Conversation implements polymod.hscript.HScriptedClass {}
|
class ScriptedConversation extends Conversation implements polymod.hscript.HScriptedClass {}
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
package funkin.play.cutscene.dialogue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A script that can be tied to a DialogueBox.
|
||||||
|
* Create a scripted class that extends DialogueBox to use this.
|
||||||
|
* This allows you to customize how a specific dialogue box appears.
|
||||||
|
*/
|
||||||
@:hscriptClass
|
@:hscriptClass
|
||||||
class ScriptedDialogueBox extends DialogueBox implements polymod.hscript.HScriptedClass {}
|
class ScriptedDialogueBox extends DialogueBox implements polymod.hscript.HScriptedClass {}
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
package funkin.play.cutscene.dialogue;
|
||||||
|
|
||||||
import flixel.FlxSprite;
|
import flixel.FlxSprite;
|
||||||
|
import funkin.data.IRegistryEntry;
|
||||||
import funkin.modding.events.ScriptEvent;
|
import funkin.modding.events.ScriptEvent;
|
||||||
import flixel.graphics.frames.FlxFramesCollection;
|
import flixel.graphics.frames.FlxFramesCollection;
|
||||||
import funkin.util.assets.FlxAnimationUtil;
|
import funkin.util.assets.FlxAnimationUtil;
|
||||||
import funkin.modding.IScriptedClass.IDialogueScriptedClass;
|
import funkin.modding.IScriptedClass.IDialogueScriptedClass;
|
||||||
|
import funkin.data.dialogue.SpeakerData;
|
||||||
|
import funkin.data.dialogue.SpeakerRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The character sprite which displays during dialogue.
|
* The character sprite which displays during dialogue.
|
||||||
*
|
*
|
||||||
* Most conversations have two speakers, with one being flipped.
|
* Most conversations have two speakers, with one being flipped.
|
||||||
*/
|
*/
|
||||||
class Speaker extends FlxSprite implements IDialogueScriptedClass
|
class Speaker extends FlxSprite implements IDialogueScriptedClass implements IRegistryEntry<SpeakerData>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The internal ID for this speaker.
|
* The internal ID for this speaker.
|
||||||
*/
|
*/
|
||||||
public final speakerId:String;
|
public final id:String;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The full data for a speaker.
|
* The full data for a speaker.
|
||||||
*/
|
*/
|
||||||
var speakerData:SpeakerData;
|
public final _data:SpeakerData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A readable name for this speaker.
|
* A readable name for this speaker.
|
||||||
|
@ -30,7 +33,7 @@ class Speaker extends FlxSprite implements IDialogueScriptedClass
|
||||||
|
|
||||||
function get_speakerName():String
|
function get_speakerName():String
|
||||||
{
|
{
|
||||||
return speakerData.name;
|
return _data.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,14 +78,17 @@ class Speaker extends FlxSprite implements IDialogueScriptedClass
|
||||||
return globalOffsets = value;
|
return globalOffsets = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function new(speakerId:String)
|
public function new(id:String)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.speakerId = speakerId;
|
this.id = id;
|
||||||
this.speakerData = SpeakerDataParser.parseSpeakerData(this.speakerId);
|
this._data = _fetchData(id);
|
||||||
|
|
||||||
if (speakerData == null) throw 'Could not load speaker data for speaker ID "$speakerId"';
|
if (_data == null)
|
||||||
|
{
|
||||||
|
throw 'Could not parse speaker data for id: $id';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,18 +108,18 @@ class Speaker extends FlxSprite implements IDialogueScriptedClass
|
||||||
|
|
||||||
function loadSpritesheet():Void
|
function loadSpritesheet():Void
|
||||||
{
|
{
|
||||||
trace('[SPEAKER] Loading spritesheet ${speakerData.assetPath} for ${speakerId}');
|
trace('[SPEAKER] Loading spritesheet ${_data.assetPath} for ${id}');
|
||||||
|
|
||||||
var tex:FlxFramesCollection = Paths.getSparrowAtlas(speakerData.assetPath);
|
var tex:FlxFramesCollection = Paths.getSparrowAtlas(_data.assetPath);
|
||||||
if (tex == null)
|
if (tex == null)
|
||||||
{
|
{
|
||||||
trace('Could not load Sparrow sprite: ${speakerData.assetPath}');
|
trace('Could not load Sparrow sprite: ${_data.assetPath}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frames = tex;
|
this.frames = tex;
|
||||||
|
|
||||||
if (speakerData.isPixel)
|
if (_data.isPixel)
|
||||||
{
|
{
|
||||||
this.antialiasing = false;
|
this.antialiasing = false;
|
||||||
}
|
}
|
||||||
|
@ -122,9 +128,10 @@ class Speaker extends FlxSprite implements IDialogueScriptedClass
|
||||||
this.antialiasing = true;
|
this.antialiasing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.flipX = speakerData.flipX;
|
this.flipX = _data.flipX;
|
||||||
this.globalOffsets = speakerData.offsets;
|
this.flipY = _data.flipY;
|
||||||
this.setScale(speakerData.scale);
|
this.globalOffsets = _data.offsets;
|
||||||
|
this.setScale(_data.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,11 +148,11 @@ class Speaker extends FlxSprite implements IDialogueScriptedClass
|
||||||
|
|
||||||
function loadAnimations():Void
|
function loadAnimations():Void
|
||||||
{
|
{
|
||||||
trace('[SPEAKER] Loading ${speakerData.animations.length} animations for ${speakerId}');
|
trace('[SPEAKER] Loading ${_data.animations.length} animations for ${id}');
|
||||||
|
|
||||||
FlxAnimationUtil.addAtlasAnimations(this, speakerData.animations);
|
FlxAnimationUtil.addAtlasAnimations(this, _data.animations);
|
||||||
|
|
||||||
for (anim in speakerData.animations)
|
for (anim in _data.animations)
|
||||||
{
|
{
|
||||||
if (anim.offsets == null)
|
if (anim.offsets == null)
|
||||||
{
|
{
|
||||||
|
@ -158,7 +165,7 @@ class Speaker extends FlxSprite implements IDialogueScriptedClass
|
||||||
}
|
}
|
||||||
|
|
||||||
var animNames:Array<String> = this.animation.getNameList();
|
var animNames:Array<String> = this.animation.getNameList();
|
||||||
trace('[SPEAKER] Successfully loaded ${animNames.length} animations for ${speakerId}');
|
trace('[SPEAKER] Successfully loaded ${animNames.length} animations for ${id}');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -271,4 +278,14 @@ class Speaker extends FlxSprite implements IDialogueScriptedClass
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onScriptEvent(event:ScriptEvent):Void {}
|
public function onScriptEvent(event:ScriptEvent):Void {}
|
||||||
|
|
||||||
|
public override function toString():String
|
||||||
|
{
|
||||||
|
return 'Speaker($id)';
|
||||||
|
}
|
||||||
|
|
||||||
|
static function _fetchData(id:String):Null<SpeakerData>
|
||||||
|
{
|
||||||
|
return SpeakerRegistry.instance.parseEntryDataWithMigration(id, SpeakerRegistry.instance.fetchEntryVersion(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
|
||||||
|
|
||||||
import funkin.data.animation.AnimationData;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data about a conversation.
|
|
||||||
* Includes what speakers are in the conversation, and what phrases they say.
|
|
||||||
*/
|
|
||||||
@:jsonParse(j -> funkin.play.cutscene.dialogue.SpeakerData.fromJson(j))
|
|
||||||
@:jsonStringify(v -> v.toJson())
|
|
||||||
class SpeakerData
|
|
||||||
{
|
|
||||||
public var version:String;
|
|
||||||
public var name:String;
|
|
||||||
public var assetPath:String;
|
|
||||||
public var flipX:Bool;
|
|
||||||
public var isPixel:Bool;
|
|
||||||
public var offsets:Array<Float>;
|
|
||||||
public var scale:Float;
|
|
||||||
public var animations:Array<AnimationData>;
|
|
||||||
|
|
||||||
public function new(version:String, name:String, assetPath:String, animations:Array<AnimationData>, ?offsets:Array<Float>, flipX:Bool = false,
|
|
||||||
isPixel:Bool = false, ?scale:Float = 1.0)
|
|
||||||
{
|
|
||||||
this.version = version;
|
|
||||||
this.name = name;
|
|
||||||
this.assetPath = assetPath;
|
|
||||||
this.animations = animations;
|
|
||||||
|
|
||||||
this.offsets = offsets;
|
|
||||||
if (this.offsets == null || this.offsets == []) this.offsets = [0, 0];
|
|
||||||
|
|
||||||
this.flipX = flipX;
|
|
||||||
this.isPixel = isPixel;
|
|
||||||
this.scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromString(i:String):SpeakerData
|
|
||||||
{
|
|
||||||
if (i == null || i == '') return null;
|
|
||||||
var data:
|
|
||||||
{
|
|
||||||
version:String,
|
|
||||||
name:String,
|
|
||||||
assetPath:String,
|
|
||||||
animations:Array<AnimationData>,
|
|
||||||
?offsets:Array<Float>,
|
|
||||||
?flipX:Bool,
|
|
||||||
?isPixel:Bool,
|
|
||||||
?scale:Float
|
|
||||||
} = tink.Json.parse(i);
|
|
||||||
return fromJson(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function fromJson(j:Dynamic):SpeakerData
|
|
||||||
{
|
|
||||||
// TODO: Check version and perform migrations if necessary.
|
|
||||||
if (j == null) return null;
|
|
||||||
return new SpeakerData(j.version, j.name, j.assetPath, j.animations, j.offsets, j.flipX, j.isPixel, j.scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toJson():Dynamic
|
|
||||||
{
|
|
||||||
var result:Dynamic =
|
|
||||||
{
|
|
||||||
version: this.version,
|
|
||||||
name: this.name,
|
|
||||||
assetPath: this.assetPath,
|
|
||||||
animations: this.animations,
|
|
||||||
flipX: this.flipX,
|
|
||||||
isPixel: this.isPixel
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.scale != 1.0) result.scale = this.scale;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,159 +0,0 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
|
||||||
|
|
||||||
import openfl.Assets;
|
|
||||||
import funkin.util.assets.DataAssets;
|
|
||||||
import funkin.play.cutscene.dialogue.Speaker;
|
|
||||||
import funkin.play.cutscene.dialogue.ScriptedSpeaker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains utilities for loading and parsing speaker data.
|
|
||||||
*/
|
|
||||||
class SpeakerDataParser
|
|
||||||
{
|
|
||||||
public static final SPEAKER_DATA_VERSION:String = '1.0.0';
|
|
||||||
public static final SPEAKER_DATA_VERSION_RULE:String = '1.0.x';
|
|
||||||
|
|
||||||
static final speakerCache:Map<String, Speaker> = new Map<String, Speaker>();
|
|
||||||
|
|
||||||
static final speakerScriptedClass:Map<String, String> = new Map<String, String>();
|
|
||||||
|
|
||||||
static final DEFAULT_SPEAKER_ID:String = 'UNKNOWN';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses and preloads the game's speaker data and scripts when the game starts.
|
|
||||||
*
|
|
||||||
* If you want to force speakers to be reloaded, you can just call this function again.
|
|
||||||
*/
|
|
||||||
public static function loadSpeakerCache():Void
|
|
||||||
{
|
|
||||||
clearSpeakerCache();
|
|
||||||
trace('Loading dialogue speaker cache...');
|
|
||||||
|
|
||||||
//
|
|
||||||
// SCRIPTED CONVERSATIONS
|
|
||||||
//
|
|
||||||
var scriptedSpeakerClassNames:Array<String> = ScriptedSpeaker.listScriptClasses();
|
|
||||||
trace(' Instantiating ${scriptedSpeakerClassNames.length} scripted speakers...');
|
|
||||||
for (speakerCls in scriptedSpeakerClassNames)
|
|
||||||
{
|
|
||||||
var speaker:Speaker = ScriptedSpeaker.init(speakerCls, DEFAULT_SPEAKER_ID);
|
|
||||||
if (speaker != null)
|
|
||||||
{
|
|
||||||
trace(' Loaded scripted speaker: ${speaker.speakerName}');
|
|
||||||
// Disable the rendering logic for speaker until it's loaded.
|
|
||||||
// Note that kill() =/= destroy()
|
|
||||||
speaker.kill();
|
|
||||||
|
|
||||||
// Then store it.
|
|
||||||
speakerCache.set(speaker.speakerId, speaker);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trace(' Failed to instantiate scripted speaker class: ${speakerCls}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// UNSCRIPTED CONVERSATIONS
|
|
||||||
//
|
|
||||||
// Scripts refers to code here, not the actual dialogue.
|
|
||||||
var speakerIdList:Array<String> = DataAssets.listDataFilesInPath('dialogue/speakers/');
|
|
||||||
// Filter out speakers that are scripted.
|
|
||||||
var unscriptedSpeakerIds:Array<String> = speakerIdList.filter(function(speakerId:String):Bool {
|
|
||||||
return !speakerCache.exists(speakerId);
|
|
||||||
});
|
|
||||||
trace(' Fetching data for ${unscriptedSpeakerIds.length} speakers...');
|
|
||||||
for (speakerId in unscriptedSpeakerIds)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var speaker:Speaker = new Speaker(speakerId);
|
|
||||||
if (speaker != null)
|
|
||||||
{
|
|
||||||
trace(' Loaded speaker data: ${speaker.speakerName}');
|
|
||||||
speakerCache.set(speaker.speakerId, speaker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
trace(e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches data for a speaker and returns a Speaker instance,
|
|
||||||
* ready to be displayed.
|
|
||||||
* @param speakerId The ID of the speaker to fetch.
|
|
||||||
* @return The speaker instance, or null if the speaker was not found.
|
|
||||||
*/
|
|
||||||
public static function fetchSpeaker(speakerId:String):Null<Speaker>
|
|
||||||
{
|
|
||||||
if (speakerId != null && speakerId != '' && speakerCache.exists(speakerId))
|
|
||||||
{
|
|
||||||
trace('Successfully fetched speaker: ${speakerId}');
|
|
||||||
var speaker:Speaker = speakerCache.get(speakerId);
|
|
||||||
speaker.revive();
|
|
||||||
return speaker;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trace('Failed to fetch speaker, not found in cache: ${speakerId}');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function clearSpeakerCache():Void
|
|
||||||
{
|
|
||||||
if (speakerCache != null)
|
|
||||||
{
|
|
||||||
for (speaker in speakerCache)
|
|
||||||
{
|
|
||||||
speaker.destroy();
|
|
||||||
}
|
|
||||||
speakerCache.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function listSpeakerIds():Array<String>
|
|
||||||
{
|
|
||||||
return speakerCache.keys().array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a speaker's JSON file, parse its data, and return it.
|
|
||||||
*
|
|
||||||
* @param speakerId The speaker to load.
|
|
||||||
* @return The speaker data, or null if validation failed.
|
|
||||||
*/
|
|
||||||
public static function parseSpeakerData(speakerId:String):Null<SpeakerData>
|
|
||||||
{
|
|
||||||
var rawJson:String = loadSpeakerFile(speakerId);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var speakerData:SpeakerData = SpeakerData.fromString(rawJson);
|
|
||||||
return speakerData;
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
trace('Failed to parse speaker ($speakerId).');
|
|
||||||
trace(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function loadSpeakerFile(speakerPath:String):String
|
|
||||||
{
|
|
||||||
var speakerFilePath:String = Paths.json('dialogue/speakers/${speakerPath}');
|
|
||||||
var rawJson:String = Assets.getText(speakerFilePath).trim();
|
|
||||||
|
|
||||||
while (!rawJson.endsWith('}') && rawJson.length > 0)
|
|
||||||
{
|
|
||||||
rawJson = rawJson.substr(0, rawJson.length - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rawJson;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +1,52 @@
|
||||||
package funkin.ui.debug.charting;
|
package funkin.ui.debug.charting;
|
||||||
|
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorOffsetsToolbox;
|
|
||||||
import funkin.util.logging.CrashHandler;
|
|
||||||
import haxe.ui.containers.HBox;
|
|
||||||
import haxe.ui.containers.Grid;
|
|
||||||
import haxe.ui.containers.ScrollView;
|
|
||||||
import haxe.ui.containers.menus.MenuBar;
|
|
||||||
import flixel.addons.display.FlxSliceSprite;
|
import flixel.addons.display.FlxSliceSprite;
|
||||||
import flixel.addons.display.FlxTiledSprite;
|
import flixel.addons.display.FlxTiledSprite;
|
||||||
import flixel.addons.transition.FlxTransitionableState;
|
import flixel.addons.transition.FlxTransitionableState;
|
||||||
import flixel.FlxCamera;
|
import flixel.FlxCamera;
|
||||||
import flixel.FlxSprite;
|
import flixel.FlxSprite;
|
||||||
import flixel.FlxSubState;
|
import flixel.FlxSubState;
|
||||||
|
import flixel.graphics.FlxGraphic;
|
||||||
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||||
import flixel.group.FlxSpriteGroup;
|
import flixel.group.FlxSpriteGroup;
|
||||||
import funkin.graphics.FunkinSprite;
|
|
||||||
import flixel.input.keyboard.FlxKey;
|
import flixel.input.keyboard.FlxKey;
|
||||||
|
import flixel.input.mouse.FlxMouseEvent;
|
||||||
import flixel.math.FlxMath;
|
import flixel.math.FlxMath;
|
||||||
import flixel.math.FlxPoint;
|
import flixel.math.FlxPoint;
|
||||||
import flixel.graphics.FlxGraphic;
|
|
||||||
import flixel.math.FlxRect;
|
import flixel.math.FlxRect;
|
||||||
import flixel.sound.FlxSound;
|
import flixel.sound.FlxSound;
|
||||||
|
import flixel.system.debug.log.LogStyle;
|
||||||
import flixel.system.FlxAssets.FlxSoundAsset;
|
import flixel.system.FlxAssets.FlxSoundAsset;
|
||||||
|
import flixel.text.FlxText;
|
||||||
import flixel.tweens.FlxEase;
|
import flixel.tweens.FlxEase;
|
||||||
import flixel.tweens.FlxTween;
|
import flixel.tweens.FlxTween;
|
||||||
import flixel.tweens.misc.VarTween;
|
import flixel.tweens.misc.VarTween;
|
||||||
import funkin.audio.waveform.WaveformSprite;
|
|
||||||
import haxe.ui.Toolkit;
|
|
||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
import flixel.util.FlxSort;
|
import flixel.util.FlxSort;
|
||||||
import flixel.util.FlxTimer;
|
import flixel.util.FlxTimer;
|
||||||
|
import funkin.audio.FunkinSound;
|
||||||
|
import funkin.audio.visualize.PolygonSpectogram;
|
||||||
import funkin.audio.visualize.PolygonSpectogram;
|
import funkin.audio.visualize.PolygonSpectogram;
|
||||||
import funkin.audio.VoicesGroup;
|
import funkin.audio.VoicesGroup;
|
||||||
import funkin.audio.FunkinSound;
|
import funkin.audio.waveform.WaveformSprite;
|
||||||
import funkin.data.notestyle.NoteStyleRegistry;
|
import funkin.data.notestyle.NoteStyleRegistry;
|
||||||
import funkin.data.song.SongData.SongCharacterData;
|
import funkin.data.song.SongData.SongCharacterData;
|
||||||
|
import funkin.data.song.SongData.SongCharacterData;
|
||||||
|
import funkin.data.song.SongData.SongChartData;
|
||||||
import funkin.data.song.SongData.SongChartData;
|
import funkin.data.song.SongData.SongChartData;
|
||||||
import funkin.data.song.SongData.SongEventData;
|
import funkin.data.song.SongData.SongEventData;
|
||||||
|
import funkin.data.song.SongData.SongEventData;
|
||||||
import funkin.data.song.SongData.SongMetadata;
|
import funkin.data.song.SongData.SongMetadata;
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorDifficultyToolbox;
|
import funkin.data.song.SongData.SongMetadata;
|
||||||
|
import funkin.data.song.SongData.SongNoteData;
|
||||||
import funkin.data.song.SongData.SongNoteData;
|
import funkin.data.song.SongData.SongNoteData;
|
||||||
import funkin.data.song.SongData.SongOffsets;
|
import funkin.data.song.SongData.SongOffsets;
|
||||||
import funkin.data.song.SongDataUtils;
|
import funkin.data.song.SongDataUtils;
|
||||||
|
import funkin.data.song.SongDataUtils;
|
||||||
import funkin.data.song.SongRegistry;
|
import funkin.data.song.SongRegistry;
|
||||||
|
import funkin.data.song.SongRegistry;
|
||||||
|
import funkin.data.stage.StageData;
|
||||||
|
import funkin.graphics.FunkinSprite;
|
||||||
import funkin.input.Cursor;
|
import funkin.input.Cursor;
|
||||||
import funkin.input.TurboKeyHandler;
|
import funkin.input.TurboKeyHandler;
|
||||||
import funkin.modding.events.ScriptEvent;
|
import funkin.modding.events.ScriptEvent;
|
||||||
|
@ -52,22 +57,14 @@ import funkin.play.components.HealthIcon;
|
||||||
import funkin.play.notes.NoteSprite;
|
import funkin.play.notes.NoteSprite;
|
||||||
import funkin.play.PlayState;
|
import funkin.play.PlayState;
|
||||||
import funkin.play.song.Song;
|
import funkin.play.song.Song;
|
||||||
import funkin.data.song.SongData.SongChartData;
|
|
||||||
import funkin.data.song.SongRegistry;
|
|
||||||
import funkin.data.song.SongData.SongEventData;
|
|
||||||
import funkin.data.song.SongData.SongMetadata;
|
|
||||||
import funkin.data.song.SongData.SongNoteData;
|
|
||||||
import funkin.data.song.SongData.SongCharacterData;
|
|
||||||
import funkin.data.song.SongDataUtils;
|
|
||||||
import funkin.ui.debug.charting.commands.ChartEditorCommand;
|
|
||||||
import funkin.data.stage.StageData;
|
|
||||||
import funkin.save.Save;
|
import funkin.save.Save;
|
||||||
import funkin.ui.debug.charting.commands.AddEventsCommand;
|
import funkin.ui.debug.charting.commands.AddEventsCommand;
|
||||||
import funkin.ui.debug.charting.commands.AddNotesCommand;
|
import funkin.ui.debug.charting.commands.AddNotesCommand;
|
||||||
import funkin.ui.debug.charting.commands.ChartEditorCommand;
|
import funkin.ui.debug.charting.commands.ChartEditorCommand;
|
||||||
import funkin.ui.debug.charting.commands.ChartEditorCommand;
|
import funkin.ui.debug.charting.commands.ChartEditorCommand;
|
||||||
import funkin.ui.debug.charting.commands.CutItemsCommand;
|
import funkin.ui.debug.charting.commands.ChartEditorCommand;
|
||||||
import funkin.ui.debug.charting.commands.CopyItemsCommand;
|
import funkin.ui.debug.charting.commands.CopyItemsCommand;
|
||||||
|
import funkin.ui.debug.charting.commands.CutItemsCommand;
|
||||||
import funkin.ui.debug.charting.commands.DeselectAllItemsCommand;
|
import funkin.ui.debug.charting.commands.DeselectAllItemsCommand;
|
||||||
import funkin.ui.debug.charting.commands.DeselectItemsCommand;
|
import funkin.ui.debug.charting.commands.DeselectItemsCommand;
|
||||||
import funkin.ui.debug.charting.commands.ExtendNoteLengthCommand;
|
import funkin.ui.debug.charting.commands.ExtendNoteLengthCommand;
|
||||||
|
@ -85,17 +82,22 @@ import funkin.ui.debug.charting.commands.SelectItemsCommand;
|
||||||
import funkin.ui.debug.charting.commands.SetItemSelectionCommand;
|
import funkin.ui.debug.charting.commands.SetItemSelectionCommand;
|
||||||
import funkin.ui.debug.charting.components.ChartEditorEventSprite;
|
import funkin.ui.debug.charting.components.ChartEditorEventSprite;
|
||||||
import funkin.ui.debug.charting.components.ChartEditorHoldNoteSprite;
|
import funkin.ui.debug.charting.components.ChartEditorHoldNoteSprite;
|
||||||
|
import funkin.ui.debug.charting.components.ChartEditorMeasureTicks;
|
||||||
import funkin.ui.debug.charting.components.ChartEditorNotePreview;
|
import funkin.ui.debug.charting.components.ChartEditorNotePreview;
|
||||||
import funkin.ui.debug.charting.components.ChartEditorNoteSprite;
|
import funkin.ui.debug.charting.components.ChartEditorNoteSprite;
|
||||||
import funkin.ui.debug.charting.components.ChartEditorMeasureTicks;
|
|
||||||
import funkin.ui.debug.charting.components.ChartEditorPlaybarHead;
|
import funkin.ui.debug.charting.components.ChartEditorPlaybarHead;
|
||||||
import funkin.ui.debug.charting.components.ChartEditorSelectionSquareSprite;
|
import funkin.ui.debug.charting.components.ChartEditorSelectionSquareSprite;
|
||||||
import funkin.ui.debug.charting.handlers.ChartEditorShortcutHandler;
|
import funkin.ui.debug.charting.handlers.ChartEditorShortcutHandler;
|
||||||
|
import funkin.ui.debug.charting.toolboxes.ChartEditorBaseToolbox;
|
||||||
|
import funkin.ui.debug.charting.toolboxes.ChartEditorDifficultyToolbox;
|
||||||
|
import funkin.ui.debug.charting.toolboxes.ChartEditorFreeplayToolbox;
|
||||||
|
import funkin.ui.debug.charting.toolboxes.ChartEditorOffsetsToolbox;
|
||||||
import funkin.ui.haxeui.components.CharacterPlayer;
|
import funkin.ui.haxeui.components.CharacterPlayer;
|
||||||
import funkin.ui.haxeui.HaxeUIState;
|
import funkin.ui.haxeui.HaxeUIState;
|
||||||
import funkin.ui.mainmenu.MainMenuState;
|
import funkin.ui.mainmenu.MainMenuState;
|
||||||
import funkin.util.Constants;
|
import funkin.util.Constants;
|
||||||
import funkin.util.FileUtil;
|
import funkin.util.FileUtil;
|
||||||
|
import funkin.util.logging.CrashHandler;
|
||||||
import funkin.util.SortUtil;
|
import funkin.util.SortUtil;
|
||||||
import funkin.util.WindowUtil;
|
import funkin.util.WindowUtil;
|
||||||
import haxe.DynamicAccess;
|
import haxe.DynamicAccess;
|
||||||
|
@ -103,23 +105,26 @@ import haxe.io.Bytes;
|
||||||
import haxe.io.Path;
|
import haxe.io.Path;
|
||||||
import haxe.ui.backend.flixel.UIRuntimeState;
|
import haxe.ui.backend.flixel.UIRuntimeState;
|
||||||
import haxe.ui.backend.flixel.UIState;
|
import haxe.ui.backend.flixel.UIState;
|
||||||
import haxe.ui.components.DropDown;
|
|
||||||
import haxe.ui.components.Label;
|
|
||||||
import haxe.ui.components.Button;
|
import haxe.ui.components.Button;
|
||||||
|
import haxe.ui.components.DropDown;
|
||||||
|
import haxe.ui.components.Image;
|
||||||
|
import haxe.ui.components.Label;
|
||||||
import haxe.ui.components.NumberStepper;
|
import haxe.ui.components.NumberStepper;
|
||||||
import haxe.ui.components.Slider;
|
import haxe.ui.components.Slider;
|
||||||
import haxe.ui.components.TextField;
|
import haxe.ui.components.TextField;
|
||||||
|
import haxe.ui.containers.Box;
|
||||||
import haxe.ui.containers.dialogs.CollapsibleDialog;
|
import haxe.ui.containers.dialogs.CollapsibleDialog;
|
||||||
import haxe.ui.containers.Frame;
|
import haxe.ui.containers.Frame;
|
||||||
import haxe.ui.containers.Box;
|
import haxe.ui.containers.Grid;
|
||||||
|
import haxe.ui.containers.HBox;
|
||||||
import haxe.ui.containers.menus.Menu;
|
import haxe.ui.containers.menus.Menu;
|
||||||
import haxe.ui.containers.menus.MenuBar;
|
import haxe.ui.containers.menus.MenuBar;
|
||||||
import haxe.ui.containers.menus.MenuItem;
|
import haxe.ui.containers.menus.MenuBar;
|
||||||
import haxe.ui.containers.menus.MenuCheckBox;
|
import haxe.ui.containers.menus.MenuCheckBox;
|
||||||
|
import haxe.ui.containers.menus.MenuItem;
|
||||||
|
import haxe.ui.containers.ScrollView;
|
||||||
import haxe.ui.containers.TreeView;
|
import haxe.ui.containers.TreeView;
|
||||||
import haxe.ui.containers.TreeViewNode;
|
import haxe.ui.containers.TreeViewNode;
|
||||||
import haxe.ui.components.Image;
|
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorBaseToolbox;
|
|
||||||
import haxe.ui.core.Component;
|
import haxe.ui.core.Component;
|
||||||
import haxe.ui.core.Screen;
|
import haxe.ui.core.Screen;
|
||||||
import haxe.ui.events.DragEvent;
|
import haxe.ui.events.DragEvent;
|
||||||
|
@ -127,12 +132,8 @@ import haxe.ui.events.MouseEvent;
|
||||||
import haxe.ui.events.UIEvent;
|
import haxe.ui.events.UIEvent;
|
||||||
import haxe.ui.events.UIEvent;
|
import haxe.ui.events.UIEvent;
|
||||||
import haxe.ui.focus.FocusManager;
|
import haxe.ui.focus.FocusManager;
|
||||||
|
import haxe.ui.Toolkit;
|
||||||
import openfl.display.BitmapData;
|
import openfl.display.BitmapData;
|
||||||
import funkin.audio.visualize.PolygonSpectogram;
|
|
||||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
|
||||||
import flixel.input.mouse.FlxMouseEvent;
|
|
||||||
import flixel.text.FlxText;
|
|
||||||
import flixel.system.debug.log.LogStyle;
|
|
||||||
|
|
||||||
using Lambda;
|
using Lambda;
|
||||||
|
|
||||||
|
@ -154,18 +155,19 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
|
||||||
*/
|
*/
|
||||||
// ==============================
|
// ==============================
|
||||||
// Layouts
|
// Layouts
|
||||||
public static final CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/notedata');
|
|
||||||
|
|
||||||
public static final CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/eventdata');
|
|
||||||
public static final CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT:String = Paths.ui('chart-editor/toolbox/playtest-properties');
|
|
||||||
public static final CHART_EDITOR_TOOLBOX_METADATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/metadata');
|
|
||||||
public static final CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:String = Paths.ui('chart-editor/toolbox/offsets');
|
|
||||||
public static final CHART_EDITOR_TOOLBOX_DIFFICULTY_LAYOUT:String = Paths.ui('chart-editor/toolbox/difficulty');
|
public static final CHART_EDITOR_TOOLBOX_DIFFICULTY_LAYOUT:String = Paths.ui('chart-editor/toolbox/difficulty');
|
||||||
|
|
||||||
public static final CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:String = Paths.ui('chart-editor/toolbox/player-preview');
|
public static final CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:String = Paths.ui('chart-editor/toolbox/player-preview');
|
||||||
public static final CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:String = Paths.ui('chart-editor/toolbox/opponent-preview');
|
public static final CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:String = Paths.ui('chart-editor/toolbox/opponent-preview');
|
||||||
|
public static final CHART_EDITOR_TOOLBOX_METADATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/metadata');
|
||||||
|
public static final CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:String = Paths.ui('chart-editor/toolbox/offsets');
|
||||||
|
public static final CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/notedata');
|
||||||
|
public static final CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/eventdata');
|
||||||
|
public static final CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT:String = Paths.ui('chart-editor/toolbox/freeplay');
|
||||||
|
public static final CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT:String = Paths.ui('chart-editor/toolbox/playtest-properties');
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
public static final SUPPORTED_MUSIC_FORMATS:Array<String> = ['ogg'];
|
public static final SUPPORTED_MUSIC_FORMATS:Array<String> = #if sys ['ogg'] #else ['mp3'] #end;
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
|
|
||||||
|
@ -1334,6 +1336,30 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
|
||||||
return currentSongMetadata.playData.noteStyle = value;
|
return currentSongMetadata.playData.noteStyle = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentSongFreeplayPreviewStart(get, set):Int;
|
||||||
|
|
||||||
|
function get_currentSongFreeplayPreviewStart():Int
|
||||||
|
{
|
||||||
|
return currentSongMetadata.playData.previewStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_currentSongFreeplayPreviewStart(value:Int):Int
|
||||||
|
{
|
||||||
|
return currentSongMetadata.playData.previewStart = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentSongFreeplayPreviewEnd(get, set):Int;
|
||||||
|
|
||||||
|
function get_currentSongFreeplayPreviewEnd():Int
|
||||||
|
{
|
||||||
|
return currentSongMetadata.playData.previewEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_currentSongFreeplayPreviewEnd(value:Int):Int
|
||||||
|
{
|
||||||
|
return currentSongMetadata.playData.previewEnd = value;
|
||||||
|
}
|
||||||
|
|
||||||
var currentSongStage(get, set):String;
|
var currentSongStage(get, set):String;
|
||||||
|
|
||||||
function get_currentSongStage():String
|
function get_currentSongStage():String
|
||||||
|
@ -2943,6 +2969,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
|
||||||
menubarItemToggleToolboxOffsets.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT, event.value);
|
menubarItemToggleToolboxOffsets.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT, event.value);
|
||||||
menubarItemToggleToolboxNotes.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT, event.value);
|
menubarItemToggleToolboxNotes.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT, event.value);
|
||||||
menubarItemToggleToolboxEventData.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT, event.value);
|
menubarItemToggleToolboxEventData.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT, event.value);
|
||||||
|
menubarItemToggleToolboxFreeplay.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT, event.value);
|
||||||
menubarItemToggleToolboxPlaytestProperties.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT, event.value);
|
menubarItemToggleToolboxPlaytestProperties.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT, event.value);
|
||||||
menubarItemToggleToolboxPlayerPreview.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT, event.value);
|
menubarItemToggleToolboxPlayerPreview.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT, event.value);
|
||||||
menubarItemToggleToolboxOpponentPreview.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT, event.value);
|
menubarItemToggleToolboxOpponentPreview.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT, event.value);
|
||||||
|
@ -5983,6 +6010,16 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hardRefreshFreeplayToolbox():Void
|
||||||
|
{
|
||||||
|
var freeplayToolbox:ChartEditorFreeplayToolbox = cast this.getToolbox(CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT);
|
||||||
|
if (freeplayToolbox != null)
|
||||||
|
{
|
||||||
|
freeplayToolbox.refreshAudioPreview();
|
||||||
|
freeplayToolbox.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the voices group.
|
* Clear the voices group.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -52,7 +52,11 @@ class SetAudioOffsetCommand implements ChartEditorCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the offsets toolbox.
|
// Update the offsets toolbox.
|
||||||
if (refreshOffsetsToolbox) state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT);
|
if (refreshOffsetsToolbox)
|
||||||
|
{
|
||||||
|
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT);
|
||||||
|
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function undo(state:ChartEditorState):Void
|
public function undo(state:ChartEditorState):Void
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package funkin.ui.debug.charting.commands;
|
||||||
|
|
||||||
|
import funkin.data.song.SongData.SongNoteData;
|
||||||
|
import funkin.data.song.SongDataUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command that sets the start time or end time of the Freeplay preview.
|
||||||
|
*/
|
||||||
|
@:nullSafety
|
||||||
|
@:access(funkin.ui.debug.charting.ChartEditorState)
|
||||||
|
class SetFreeplayPreviewCommand implements ChartEditorCommand
|
||||||
|
{
|
||||||
|
var previousStartTime:Int = 0;
|
||||||
|
var previousEndTime:Int = 0;
|
||||||
|
var newStartTime:Null<Int> = null;
|
||||||
|
var newEndTime:Null<Int> = null;
|
||||||
|
|
||||||
|
public function new(newStartTime:Null<Int>, newEndTime:Null<Int>)
|
||||||
|
{
|
||||||
|
this.newStartTime = newStartTime;
|
||||||
|
this.newEndTime = newEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(state:ChartEditorState):Void
|
||||||
|
{
|
||||||
|
this.previousStartTime = state.currentSongFreeplayPreviewStart;
|
||||||
|
this.previousEndTime = state.currentSongFreeplayPreviewEnd;
|
||||||
|
|
||||||
|
if (newStartTime != null) state.currentSongFreeplayPreviewStart = newStartTime;
|
||||||
|
if (newEndTime != null) state.currentSongFreeplayPreviewEnd = newEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function undo(state:ChartEditorState):Void
|
||||||
|
{
|
||||||
|
state.currentSongFreeplayPreviewStart = previousStartTime;
|
||||||
|
state.currentSongFreeplayPreviewEnd = previousEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldAddToHistory(state:ChartEditorState):Bool
|
||||||
|
{
|
||||||
|
return (newStartTime != null && newStartTime != previousStartTime) || (newEndTime != null && newEndTime != previousEndTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toString():String
|
||||||
|
{
|
||||||
|
var setStart = newStartTime != null && newStartTime != previousStartTime;
|
||||||
|
var setEnd = newEndTime != null && newEndTime != previousEndTime;
|
||||||
|
|
||||||
|
if (setStart && !setEnd)
|
||||||
|
{
|
||||||
|
return "Set Freeplay Preview Start Time";
|
||||||
|
}
|
||||||
|
else if (setEnd && !setStart)
|
||||||
|
{
|
||||||
|
return "Set Freeplay Preview End Time";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "Set Freeplay Preview Start and End Times";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -128,17 +128,42 @@ class ChartEditorAudioHandler
|
||||||
|
|
||||||
public static function switchToInstrumental(state:ChartEditorState, instId:String = '', playerId:String, opponentId:String):Bool
|
public static function switchToInstrumental(state:ChartEditorState, instId:String = '', playerId:String, opponentId:String):Bool
|
||||||
{
|
{
|
||||||
|
var perfA = haxe.Timer.stamp();
|
||||||
|
|
||||||
var result:Bool = playInstrumental(state, instId);
|
var result:Bool = playInstrumental(state, instId);
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
|
|
||||||
|
var perfB = haxe.Timer.stamp();
|
||||||
|
|
||||||
stopExistingVocals(state);
|
stopExistingVocals(state);
|
||||||
|
|
||||||
|
var perfC = haxe.Timer.stamp();
|
||||||
|
|
||||||
result = playVocals(state, BF, playerId, instId);
|
result = playVocals(state, BF, playerId, instId);
|
||||||
|
|
||||||
|
var perfD = haxe.Timer.stamp();
|
||||||
|
|
||||||
// if (!result) return false;
|
// if (!result) return false;
|
||||||
result = playVocals(state, DAD, opponentId, instId);
|
result = playVocals(state, DAD, opponentId, instId);
|
||||||
// if (!result) return false;
|
// if (!result) return false;
|
||||||
|
|
||||||
|
var perfE = haxe.Timer.stamp();
|
||||||
|
|
||||||
state.hardRefreshOffsetsToolbox();
|
state.hardRefreshOffsetsToolbox();
|
||||||
|
|
||||||
|
var perfF = haxe.Timer.stamp();
|
||||||
|
|
||||||
|
state.hardRefreshFreeplayToolbox();
|
||||||
|
|
||||||
|
var perfG = haxe.Timer.stamp();
|
||||||
|
|
||||||
|
trace('Switched to instrumental in ${perfB - perfA} seconds.');
|
||||||
|
trace('Stopped existing vocals in ${perfC - perfB} seconds.');
|
||||||
|
trace('Played BF vocals in ${perfD - perfC} seconds.');
|
||||||
|
trace('Played DAD vocals in ${perfE - perfD} seconds.');
|
||||||
|
trace('Hard refreshed offsets toolbox in ${perfF - perfE} seconds.');
|
||||||
|
trace('Hard refreshed freeplay toolbox in ${perfG - perfF} seconds.');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +174,10 @@ class ChartEditorAudioHandler
|
||||||
{
|
{
|
||||||
if (instId == '') instId = 'default';
|
if (instId == '') instId = 'default';
|
||||||
var instTrackData:Null<Bytes> = state.audioInstTrackData.get(instId);
|
var instTrackData:Null<Bytes> = state.audioInstTrackData.get(instId);
|
||||||
|
var perfA = haxe.Timer.stamp();
|
||||||
var instTrack:Null<FunkinSound> = SoundUtil.buildSoundFromBytes(instTrackData);
|
var instTrack:Null<FunkinSound> = SoundUtil.buildSoundFromBytes(instTrackData);
|
||||||
|
var perfB = haxe.Timer.stamp();
|
||||||
|
trace('Built instrumental track in ${perfB - perfA} seconds.');
|
||||||
if (instTrack == null) return false;
|
if (instTrack == null) return false;
|
||||||
|
|
||||||
stopExistingInstrumental(state);
|
stopExistingInstrumental(state);
|
||||||
|
@ -177,7 +205,10 @@ class ChartEditorAudioHandler
|
||||||
{
|
{
|
||||||
var trackId:String = '${charId}${instId == '' ? '' : '-${instId}'}';
|
var trackId:String = '${charId}${instId == '' ? '' : '-${instId}'}';
|
||||||
var vocalTrackData:Null<Bytes> = state.audioVocalTrackData.get(trackId);
|
var vocalTrackData:Null<Bytes> = state.audioVocalTrackData.get(trackId);
|
||||||
|
var perfStart = haxe.Timer.stamp();
|
||||||
var vocalTrack:Null<FunkinSound> = SoundUtil.buildSoundFromBytes(vocalTrackData);
|
var vocalTrack:Null<FunkinSound> = SoundUtil.buildSoundFromBytes(vocalTrackData);
|
||||||
|
var perfEnd = haxe.Timer.stamp();
|
||||||
|
trace('Built vocal track in ${perfEnd - perfStart} seconds.');
|
||||||
|
|
||||||
if (state.audioVocalTrackGroup == null) state.audioVocalTrackGroup = new VoicesGroup();
|
if (state.audioVocalTrackGroup == null) state.audioVocalTrackGroup = new VoicesGroup();
|
||||||
|
|
||||||
|
@ -188,7 +219,11 @@ class ChartEditorAudioHandler
|
||||||
case BF:
|
case BF:
|
||||||
state.audioVocalTrackGroup.addPlayerVoice(vocalTrack);
|
state.audioVocalTrackGroup.addPlayerVoice(vocalTrack);
|
||||||
|
|
||||||
var waveformData:Null<WaveformData> = WaveformDataParser.interpretFlxSound(vocalTrack);
|
var perfStart = haxe.Timer.stamp();
|
||||||
|
var waveformData:Null<WaveformData> = vocalTrack.waveformData;
|
||||||
|
var perfEnd = haxe.Timer.stamp();
|
||||||
|
trace('Interpreted waveform data in ${perfEnd - perfStart} seconds.');
|
||||||
|
|
||||||
if (waveformData != null)
|
if (waveformData != null)
|
||||||
{
|
{
|
||||||
var duration:Float = Conductor.instance.getStepTimeInMs(16) * 0.001;
|
var duration:Float = Conductor.instance.getStepTimeInMs(16) * 0.001;
|
||||||
|
@ -211,7 +246,11 @@ class ChartEditorAudioHandler
|
||||||
case DAD:
|
case DAD:
|
||||||
state.audioVocalTrackGroup.addOpponentVoice(vocalTrack);
|
state.audioVocalTrackGroup.addOpponentVoice(vocalTrack);
|
||||||
|
|
||||||
var waveformData:Null<WaveformData> = WaveformDataParser.interpretFlxSound(vocalTrack);
|
var perfStart = haxe.Timer.stamp();
|
||||||
|
var waveformData:Null<WaveformData> = vocalTrack.waveformData;
|
||||||
|
var perfEnd = haxe.Timer.stamp();
|
||||||
|
trace('Interpreted waveform data in ${perfEnd - perfStart} seconds.');
|
||||||
|
|
||||||
if (waveformData != null)
|
if (waveformData != null)
|
||||||
{
|
{
|
||||||
var duration:Float = Conductor.instance.getStepTimeInMs(16) * 0.001;
|
var duration:Float = Conductor.instance.getStepTimeInMs(16) * 0.001;
|
||||||
|
|
|
@ -28,6 +28,8 @@ class ChartEditorImportExportHandler
|
||||||
*/
|
*/
|
||||||
public static function loadSongAsTemplate(state:ChartEditorState, songId:String):Void
|
public static function loadSongAsTemplate(state:ChartEditorState, songId:String):Void
|
||||||
{
|
{
|
||||||
|
trace('===============START');
|
||||||
|
|
||||||
var song:Null<Song> = SongRegistry.instance.fetchEntry(songId);
|
var song:Null<Song> = SongRegistry.instance.fetchEntry(songId);
|
||||||
|
|
||||||
if (song == null) return;
|
if (song == null) return;
|
||||||
|
@ -98,11 +100,14 @@ class ChartEditorImportExportHandler
|
||||||
state.isHaxeUIDialogOpen = false;
|
state.isHaxeUIDialogOpen = false;
|
||||||
state.currentWorkingFilePath = null; // New file, so no path.
|
state.currentWorkingFilePath = null; // New file, so no path.
|
||||||
state.switchToCurrentInstrumental();
|
state.switchToCurrentInstrumental();
|
||||||
|
|
||||||
state.postLoadInstrumental();
|
state.postLoadInstrumental();
|
||||||
|
|
||||||
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_METADATA_LAYOUT);
|
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_METADATA_LAYOUT);
|
||||||
|
|
||||||
state.success('Success', 'Loaded song (${rawSongMetadata[0].songName})');
|
state.success('Success', 'Loaded song (${rawSongMetadata[0].songName})');
|
||||||
|
|
||||||
|
trace('===============END');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,6 +36,7 @@ import haxe.ui.containers.dialogs.Dialog.DialogEvent;
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorBaseToolbox;
|
import funkin.ui.debug.charting.toolboxes.ChartEditorBaseToolbox;
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorMetadataToolbox;
|
import funkin.ui.debug.charting.toolboxes.ChartEditorMetadataToolbox;
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorOffsetsToolbox;
|
import funkin.ui.debug.charting.toolboxes.ChartEditorOffsetsToolbox;
|
||||||
|
import funkin.ui.debug.charting.toolboxes.ChartEditorFreeplayToolbox;
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorEventDataToolbox;
|
import funkin.ui.debug.charting.toolboxes.ChartEditorEventDataToolbox;
|
||||||
import funkin.ui.debug.charting.toolboxes.ChartEditorDifficultyToolbox;
|
import funkin.ui.debug.charting.toolboxes.ChartEditorDifficultyToolbox;
|
||||||
import haxe.ui.containers.Frame;
|
import haxe.ui.containers.Frame;
|
||||||
|
@ -92,6 +93,8 @@ class ChartEditorToolboxHandler
|
||||||
cast(toolbox, ChartEditorBaseToolbox).refresh();
|
cast(toolbox, ChartEditorBaseToolbox).refresh();
|
||||||
case ChartEditorState.CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:
|
||||||
cast(toolbox, ChartEditorBaseToolbox).refresh();
|
cast(toolbox, ChartEditorBaseToolbox).refresh();
|
||||||
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT:
|
||||||
|
cast(toolbox, ChartEditorBaseToolbox).refresh();
|
||||||
case ChartEditorState.CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:
|
||||||
onShowToolboxPlayerPreview(state, toolbox);
|
onShowToolboxPlayerPreview(state, toolbox);
|
||||||
case ChartEditorState.CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:
|
||||||
|
@ -205,6 +208,8 @@ class ChartEditorToolboxHandler
|
||||||
toolbox = buildToolboxMetadataLayout(state);
|
toolbox = buildToolboxMetadataLayout(state);
|
||||||
case ChartEditorState.CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:
|
||||||
toolbox = buildToolboxOffsetsLayout(state);
|
toolbox = buildToolboxOffsetsLayout(state);
|
||||||
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT:
|
||||||
|
toolbox = buildToolboxFreeplayLayout(state);
|
||||||
case ChartEditorState.CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:
|
||||||
toolbox = buildToolboxPlayerPreviewLayout(state);
|
toolbox = buildToolboxPlayerPreviewLayout(state);
|
||||||
case ChartEditorState.CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:
|
case ChartEditorState.CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:
|
||||||
|
@ -383,6 +388,15 @@ class ChartEditorToolboxHandler
|
||||||
return toolbox;
|
return toolbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function buildToolboxFreeplayLayout(state:ChartEditorState):Null<ChartEditorBaseToolbox>
|
||||||
|
{
|
||||||
|
var toolbox:ChartEditorBaseToolbox = ChartEditorFreeplayToolbox.build(state);
|
||||||
|
|
||||||
|
if (toolbox == null) return null;
|
||||||
|
|
||||||
|
return toolbox;
|
||||||
|
}
|
||||||
|
|
||||||
static function buildToolboxEventDataLayout(state:ChartEditorState):Null<ChartEditorBaseToolbox>
|
static function buildToolboxEventDataLayout(state:ChartEditorState):Null<ChartEditorBaseToolbox>
|
||||||
{
|
{
|
||||||
var toolbox:ChartEditorBaseToolbox = ChartEditorEventDataToolbox.build(state);
|
var toolbox:ChartEditorBaseToolbox = ChartEditorEventDataToolbox.build(state);
|
||||||
|
|
|
@ -0,0 +1,693 @@
|
||||||
|
package funkin.ui.debug.charting.toolboxes;
|
||||||
|
|
||||||
|
import funkin.audio.SoundGroup;
|
||||||
|
import haxe.ui.components.Button;
|
||||||
|
import haxe.ui.components.HorizontalSlider;
|
||||||
|
import haxe.ui.components.Label;
|
||||||
|
import flixel.addons.display.FlxTiledSprite;
|
||||||
|
import flixel.math.FlxMath;
|
||||||
|
import haxe.ui.components.NumberStepper;
|
||||||
|
import haxe.ui.components.Slider;
|
||||||
|
import haxe.ui.backend.flixel.components.SpriteWrapper;
|
||||||
|
import funkin.ui.debug.charting.commands.SetFreeplayPreviewCommand;
|
||||||
|
import funkin.ui.haxeui.components.WaveformPlayer;
|
||||||
|
import funkin.audio.waveform.WaveformDataParser;
|
||||||
|
import haxe.ui.containers.VBox;
|
||||||
|
import haxe.ui.containers.Absolute;
|
||||||
|
import haxe.ui.containers.ScrollView;
|
||||||
|
import funkin.ui.freeplay.FreeplayState;
|
||||||
|
import haxe.ui.containers.Frame;
|
||||||
|
import haxe.ui.core.Screen;
|
||||||
|
import haxe.ui.events.DragEvent;
|
||||||
|
import haxe.ui.events.MouseEvent;
|
||||||
|
import haxe.ui.events.UIEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The toolbox which allows modifying information like Song Title, Scroll Speed, Characters/Stages, and starting BPM.
|
||||||
|
*/
|
||||||
|
// @:nullSafety // TODO: Fix null safety when used with HaxeUI build macros.
|
||||||
|
@:access(funkin.ui.debug.charting.ChartEditorState)
|
||||||
|
@:build(haxe.ui.ComponentBuilder.build("assets/exclude/data/ui/chart-editor/toolboxes/freeplay.xml"))
|
||||||
|
class ChartEditorFreeplayToolbox extends ChartEditorBaseToolbox
|
||||||
|
{
|
||||||
|
var waveformContainer:Absolute;
|
||||||
|
var waveformScrollview:ScrollView;
|
||||||
|
var waveformMusic:WaveformPlayer;
|
||||||
|
var freeplayButtonZoomIn:Button;
|
||||||
|
var freeplayButtonZoomOut:Button;
|
||||||
|
var freeplayButtonPause:Button;
|
||||||
|
var freeplayButtonPlay:Button;
|
||||||
|
var freeplayButtonStop:Button;
|
||||||
|
var freeplayPreviewStart:NumberStepper;
|
||||||
|
var freeplayPreviewEnd:NumberStepper;
|
||||||
|
var freeplayTicksContainer:Absolute;
|
||||||
|
var playheadSprite:SpriteWrapper;
|
||||||
|
var previewSelectionSprite:SpriteWrapper;
|
||||||
|
|
||||||
|
static final TICK_LABEL_X_OFFSET:Float = 4.0;
|
||||||
|
|
||||||
|
static final PLAYHEAD_RIGHT_PAD:Float = 10.0;
|
||||||
|
|
||||||
|
static final BASE_SCALE:Float = 64.0;
|
||||||
|
static final STARTING_SCALE:Float = 1024.0;
|
||||||
|
static final MIN_SCALE:Float = 4.0;
|
||||||
|
static final WAVEFORM_ZOOM_MULT:Float = 1.5;
|
||||||
|
|
||||||
|
static final MAGIC_SCALE_BASE_TIME:Float = 5.0;
|
||||||
|
|
||||||
|
var waveformScale:Float = STARTING_SCALE;
|
||||||
|
|
||||||
|
var playheadAbsolutePos(get, set):Float;
|
||||||
|
|
||||||
|
function get_playheadAbsolutePos():Float
|
||||||
|
{
|
||||||
|
return playheadSprite.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_playheadAbsolutePos(value:Float):Float
|
||||||
|
{
|
||||||
|
return playheadSprite.left = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var playheadRelativePos(get, set):Float;
|
||||||
|
|
||||||
|
function get_playheadRelativePos():Float
|
||||||
|
{
|
||||||
|
return playheadSprite.left - waveformScrollview.hscrollPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_playheadRelativePos(value:Float):Float
|
||||||
|
{
|
||||||
|
return playheadSprite.left = waveformScrollview.hscrollPos + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var previewBoxStartPosAbsolute(get, set):Float;
|
||||||
|
|
||||||
|
function get_previewBoxStartPosAbsolute():Float
|
||||||
|
{
|
||||||
|
return previewSelectionSprite.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_previewBoxStartPosAbsolute(value:Float):Float
|
||||||
|
{
|
||||||
|
return previewSelectionSprite.left = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var previewBoxEndPosAbsolute(get, set):Float;
|
||||||
|
|
||||||
|
function get_previewBoxEndPosAbsolute():Float
|
||||||
|
{
|
||||||
|
return previewSelectionSprite.left + previewSelectionSprite.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_previewBoxEndPosAbsolute(value:Float):Float
|
||||||
|
{
|
||||||
|
if (value < previewBoxStartPosAbsolute) return previewSelectionSprite.left = previewBoxStartPosAbsolute;
|
||||||
|
return previewSelectionSprite.width = value - previewBoxStartPosAbsolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
var previewBoxStartPosRelative(get, set):Float;
|
||||||
|
|
||||||
|
function get_previewBoxStartPosRelative():Float
|
||||||
|
{
|
||||||
|
return previewSelectionSprite.left - waveformScrollview.hscrollPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_previewBoxStartPosRelative(value:Float):Float
|
||||||
|
{
|
||||||
|
return previewSelectionSprite.left = waveformScrollview.hscrollPos + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var previewBoxEndPosRelative(get, set):Float;
|
||||||
|
|
||||||
|
function get_previewBoxEndPosRelative():Float
|
||||||
|
{
|
||||||
|
return previewSelectionSprite.left + previewSelectionSprite.width - waveformScrollview.hscrollPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_previewBoxEndPosRelative(value:Float):Float
|
||||||
|
{
|
||||||
|
if (value < previewBoxStartPosRelative) return previewSelectionSprite.left = previewBoxStartPosRelative;
|
||||||
|
return previewSelectionSprite.width = value - previewBoxStartPosRelative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount you need to multiply the zoom by such that, at the base zoom level, one tick is equal to `MAGIC_SCALE_BASE_TIME` seconds.
|
||||||
|
*/
|
||||||
|
var waveformMagicFactor:Float = 1.0;
|
||||||
|
|
||||||
|
var audioPreviewTracks:SoundGroup;
|
||||||
|
|
||||||
|
var tickTiledSprite:FlxTiledSprite;
|
||||||
|
|
||||||
|
var freeplayPreviewVolume(get, null):Float;
|
||||||
|
|
||||||
|
function get_freeplayPreviewVolume():Float
|
||||||
|
{
|
||||||
|
return freeplayMusicVolume.value * 2 / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tickLabels:Array<Label> = [];
|
||||||
|
|
||||||
|
public function new(chartEditorState2:ChartEditorState)
|
||||||
|
{
|
||||||
|
super(chartEditorState2);
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
this.onDialogClosed = onClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onClose(event:UIEvent)
|
||||||
|
{
|
||||||
|
chartEditorState.menubarItemToggleToolboxFreeplay.selected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize():Void
|
||||||
|
{
|
||||||
|
// Starting position.
|
||||||
|
// TODO: Save and load this.
|
||||||
|
this.x = 150;
|
||||||
|
this.y = 250;
|
||||||
|
|
||||||
|
freeplayMusicVolume.onChange = (_) -> {
|
||||||
|
setTrackVolume(freeplayPreviewVolume);
|
||||||
|
};
|
||||||
|
freeplayMusicMute.onClick = (_) -> {
|
||||||
|
toggleMuteTrack();
|
||||||
|
};
|
||||||
|
freeplayButtonZoomIn.onClick = (_) -> {
|
||||||
|
zoomWaveformIn();
|
||||||
|
};
|
||||||
|
freeplayButtonZoomOut.onClick = (_) -> {
|
||||||
|
zoomWaveformOut();
|
||||||
|
};
|
||||||
|
freeplayButtonPause.onClick = (_) -> {
|
||||||
|
pauseAudioPreview();
|
||||||
|
};
|
||||||
|
freeplayButtonPlay.onClick = (_) -> {
|
||||||
|
playAudioPreview();
|
||||||
|
};
|
||||||
|
freeplayButtonStop.onClick = (_) -> {
|
||||||
|
stopAudioPreview();
|
||||||
|
};
|
||||||
|
testPreview.onClick = (_) -> {
|
||||||
|
performPreview();
|
||||||
|
};
|
||||||
|
freeplayPreviewStart.onChange = (event:UIEvent) -> {
|
||||||
|
if (event.value == chartEditorState.currentSongFreeplayPreviewStart) return;
|
||||||
|
if (waveformDragStartPos != null) return; // The values are changing because we are dragging the preview.
|
||||||
|
|
||||||
|
chartEditorState.performCommand(new SetFreeplayPreviewCommand(event.value, null));
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
freeplayPreviewEnd.onChange = (event:UIEvent) -> {
|
||||||
|
if (event.value == chartEditorState.currentSongFreeplayPreviewEnd) return;
|
||||||
|
if (waveformDragStartPos != null) return; // The values are changing because we are dragging the preview.
|
||||||
|
|
||||||
|
chartEditorState.performCommand(new SetFreeplayPreviewCommand(null, event.value));
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
waveformScrollview.onScroll = (_) -> {
|
||||||
|
if (!audioPreviewTracks.playing)
|
||||||
|
{
|
||||||
|
// Move the playhead if it would go out of view.
|
||||||
|
var prevPlayheadRelativePos = playheadRelativePos;
|
||||||
|
playheadRelativePos = FlxMath.bound(playheadRelativePos, 0, waveformScrollview.width - PLAYHEAD_RIGHT_PAD);
|
||||||
|
trace('newPos: ${playheadRelativePos}');
|
||||||
|
var diff = playheadRelativePos - prevPlayheadRelativePos;
|
||||||
|
|
||||||
|
if (diff != 0)
|
||||||
|
{
|
||||||
|
// We have to change the song time to match the playhead position when we move it.
|
||||||
|
var currentWaveformIndex:Int = Std.int(playheadAbsolutePos * (waveformScale / BASE_SCALE * waveformMagicFactor));
|
||||||
|
var targetSongTimeSeconds:Float = waveformMusic.waveform.waveformData.indexToSeconds(currentWaveformIndex);
|
||||||
|
audioPreviewTracks.time = targetSongTimeSeconds * Constants.MS_PER_SEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
addOffsetsToAudioPreview();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// The scrollview probably changed because the song position changed.
|
||||||
|
// If we try to move the song now it will glitch.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Either way, clipRect has changed, so we need to refresh the waveforms.
|
||||||
|
refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
initializeTicks();
|
||||||
|
|
||||||
|
refreshAudioPreview();
|
||||||
|
refresh();
|
||||||
|
refreshTicks();
|
||||||
|
|
||||||
|
waveformMusic.registerEvent(MouseEvent.MOUSE_DOWN, (_) -> {
|
||||||
|
onStartDragWaveform();
|
||||||
|
});
|
||||||
|
|
||||||
|
freeplayTicksContainer.registerEvent(MouseEvent.MOUSE_DOWN, (_) -> {
|
||||||
|
onStartDragPlayhead();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeTicks():Void
|
||||||
|
{
|
||||||
|
tickTiledSprite = new FlxTiledSprite(chartEditorState.offsetTickBitmap, 100, chartEditorState.offsetTickBitmap.height, true, false);
|
||||||
|
freeplayTicksSprite.sprite = tickTiledSprite;
|
||||||
|
tickTiledSprite.width = 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pull the audio tracks from the chart editor state and create copies of them to play in the Offsets Toolbox.
|
||||||
|
* These must be DEEP CLONES or else the editor will affect the audio preview!
|
||||||
|
*/
|
||||||
|
public function refreshAudioPreview():Void
|
||||||
|
{
|
||||||
|
if (audioPreviewTracks == null)
|
||||||
|
{
|
||||||
|
audioPreviewTracks = new SoundGroup();
|
||||||
|
// Make sure audioPreviewTracks (and all its children) receives update() calls.
|
||||||
|
chartEditorState.add(audioPreviewTracks);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
audioPreviewTracks.stop();
|
||||||
|
audioPreviewTracks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
var instTrack = chartEditorState.audioInstTrack.clone();
|
||||||
|
audioPreviewTracks.add(instTrack);
|
||||||
|
|
||||||
|
var playerVoice = chartEditorState.audioVocalTrackGroup.getPlayerVoice();
|
||||||
|
if (playerVoice != null) audioPreviewTracks.add(playerVoice.clone());
|
||||||
|
|
||||||
|
var opponentVoice = chartEditorState.audioVocalTrackGroup.getOpponentVoice();
|
||||||
|
if (opponentVoice != null) audioPreviewTracks.add(opponentVoice.clone());
|
||||||
|
|
||||||
|
// Build player waveform.
|
||||||
|
// waveformMusic.waveform.forceUpdate = true;
|
||||||
|
var perfStart = haxe.Timer.stamp();
|
||||||
|
var waveformData1 = playerVoice.waveformData;
|
||||||
|
var waveformData2 = opponentVoice.waveformData;
|
||||||
|
var waveformData3 = chartEditorState.audioInstTrack.waveformData;
|
||||||
|
var waveformData = waveformData1.merge(waveformData2).merge(waveformData3);
|
||||||
|
trace('Waveform data merging took: ${haxe.Timer.stamp() - perfStart} seconds');
|
||||||
|
|
||||||
|
waveformMusic.waveform.waveformData = waveformData;
|
||||||
|
// Set the width and duration to render the full waveform, with the clipRect applied we only render a segment of it.
|
||||||
|
waveformMusic.waveform.duration = instTrack.length / Constants.MS_PER_SEC;
|
||||||
|
|
||||||
|
addOffsetsToAudioPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refreshTicks():Void
|
||||||
|
{
|
||||||
|
while (tickLabels.length > 0)
|
||||||
|
{
|
||||||
|
var label = tickLabels.pop();
|
||||||
|
freeplayTicksContainer.removeComponent(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
var labelYPos:Float = chartEditorState.offsetTickBitmap.height / 2;
|
||||||
|
var labelHeight:Float = chartEditorState.offsetTickBitmap.height / 2;
|
||||||
|
|
||||||
|
var numberOfTicks:Int = Math.floor(waveformMusic.waveform.width / chartEditorState.offsetTickBitmap.width * 2) + 1;
|
||||||
|
|
||||||
|
for (index in 0...numberOfTicks)
|
||||||
|
{
|
||||||
|
var tickPos = chartEditorState.offsetTickBitmap.width / 2 * index;
|
||||||
|
var tickTime = tickPos * (waveformScale / BASE_SCALE * waveformMagicFactor) / waveformMusic.waveform.waveformData.pointsPerSecond();
|
||||||
|
|
||||||
|
var tickLabel:Label = new Label();
|
||||||
|
tickLabel.text = formatTime(tickTime);
|
||||||
|
tickLabel.styleNames = "offset-ticks-label";
|
||||||
|
tickLabel.height = labelHeight;
|
||||||
|
// Positioning within offsetTicksContainer is absolute (relative to the container itself).
|
||||||
|
tickLabel.top = labelYPos;
|
||||||
|
tickLabel.left = tickPos + TICK_LABEL_X_OFFSET;
|
||||||
|
|
||||||
|
freeplayTicksContainer.addComponent(tickLabel);
|
||||||
|
tickLabels.push(tickLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(seconds:Float):String
|
||||||
|
{
|
||||||
|
if (seconds <= 0) return "0.0";
|
||||||
|
|
||||||
|
var integerSeconds = Math.floor(seconds);
|
||||||
|
var decimalSeconds = Math.floor((seconds - integerSeconds) * 10);
|
||||||
|
|
||||||
|
if (integerSeconds < 60)
|
||||||
|
{
|
||||||
|
return '${integerSeconds}.${decimalSeconds}';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var integerMinutes = Math.floor(integerSeconds / 60);
|
||||||
|
var remainingSeconds = integerSeconds % 60;
|
||||||
|
var remainingSecondsPad:String = remainingSeconds < 10 ? '0$remainingSeconds' : '$remainingSeconds';
|
||||||
|
|
||||||
|
return '${integerMinutes}:${remainingSecondsPad}${decimalSeconds > 0 ? '.$decimalSeconds' : ''}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTickLabel():Void {}
|
||||||
|
|
||||||
|
public function onStartDragPlayhead():Void
|
||||||
|
{
|
||||||
|
Screen.instance.registerEvent(MouseEvent.MOUSE_MOVE, onDragPlayhead);
|
||||||
|
Screen.instance.registerEvent(MouseEvent.MOUSE_UP, onStopDragPlayhead);
|
||||||
|
|
||||||
|
movePlayheadToMouse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onDragPlayhead(event:MouseEvent):Void
|
||||||
|
{
|
||||||
|
movePlayheadToMouse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onStopDragPlayhead(event:MouseEvent):Void
|
||||||
|
{
|
||||||
|
// Stop dragging.
|
||||||
|
Screen.instance.unregisterEvent(MouseEvent.MOUSE_MOVE, onDragPlayhead);
|
||||||
|
Screen.instance.unregisterEvent(MouseEvent.MOUSE_UP, onStopDragPlayhead);
|
||||||
|
}
|
||||||
|
|
||||||
|
function movePlayheadToMouse():Void
|
||||||
|
{
|
||||||
|
// Determine the position of the mouse relative to the
|
||||||
|
var mouseXPos = FlxG.mouse.x;
|
||||||
|
|
||||||
|
var relativeMouseXPos = mouseXPos - waveformScrollview.screenX;
|
||||||
|
var targetPlayheadPos = relativeMouseXPos + waveformScrollview.hscrollPos;
|
||||||
|
|
||||||
|
// Move the playhead to the mouse position.
|
||||||
|
playheadAbsolutePos = targetPlayheadPos;
|
||||||
|
|
||||||
|
// Move the audio preview to the playhead position.
|
||||||
|
var currentWaveformIndex:Int = Std.int(playheadAbsolutePos * (waveformScale / BASE_SCALE * waveformMagicFactor));
|
||||||
|
var targetSongTimeSeconds:Float = waveformMusic.waveform.waveformData.indexToSeconds(currentWaveformIndex);
|
||||||
|
audioPreviewTracks.time = targetSongTimeSeconds * Constants.MS_PER_SEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
var waveformDragStartPos:Null<Float> = null;
|
||||||
|
|
||||||
|
var waveformDragPreviewStartPos:Float;
|
||||||
|
var waveformDragPreviewEndPos:Float;
|
||||||
|
|
||||||
|
public function onStartDragWaveform():Void
|
||||||
|
{
|
||||||
|
waveformDragStartPos = FlxG.mouse.x;
|
||||||
|
|
||||||
|
Screen.instance.registerEvent(MouseEvent.MOUSE_MOVE, onDragWaveform);
|
||||||
|
Screen.instance.registerEvent(MouseEvent.MOUSE_UP, onStopDragWaveform);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onDragWaveform(event:MouseEvent):Void
|
||||||
|
{
|
||||||
|
// Set waveformDragPreviewStartPos and waveformDragPreviewEndPos to the position the drag started and the current mouse position.
|
||||||
|
// This only affects the visuals.
|
||||||
|
|
||||||
|
var currentAbsMousePos = FlxG.mouse.x;
|
||||||
|
var dragDiff = currentAbsMousePos - waveformDragStartPos;
|
||||||
|
|
||||||
|
var currentRelativeMousePos = currentAbsMousePos - waveformScrollview.screenX;
|
||||||
|
var relativeStartPos = waveformDragStartPos - waveformScrollview.screenX;
|
||||||
|
|
||||||
|
var isDraggingRight = dragDiff > 0;
|
||||||
|
var hasDraggedEnough = Math.abs(dragDiff) > 10;
|
||||||
|
|
||||||
|
if (hasDraggedEnough)
|
||||||
|
{
|
||||||
|
if (isDraggingRight)
|
||||||
|
{
|
||||||
|
waveformDragPreviewStartPos = relativeStartPos;
|
||||||
|
waveformDragPreviewEndPos = currentRelativeMousePos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waveformDragPreviewStartPos = currentRelativeMousePos;
|
||||||
|
waveformDragPreviewEndPos = relativeStartPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onStopDragWaveform(event:MouseEvent):Void
|
||||||
|
{
|
||||||
|
Screen.instance.unregisterEvent(MouseEvent.MOUSE_MOVE, onDragWaveform);
|
||||||
|
Screen.instance.unregisterEvent(MouseEvent.MOUSE_UP, onStopDragWaveform);
|
||||||
|
|
||||||
|
var previewStartPosAbsolute = waveformDragPreviewStartPos + waveformScrollview.hscrollPos;
|
||||||
|
var previewStartPosIndex:Int = Std.int(previewStartPosAbsolute * (waveformScale / BASE_SCALE * waveformMagicFactor));
|
||||||
|
var previewStartPosMs:Int = Std.int(waveformMusic.waveform.waveformData.indexToSeconds(previewStartPosIndex) * Constants.MS_PER_SEC);
|
||||||
|
|
||||||
|
var previewEndPosAbsolute = waveformDragPreviewEndPos + waveformScrollview.hscrollPos;
|
||||||
|
var previewEndPosIndex:Int = Std.int(previewEndPosAbsolute * (waveformScale / BASE_SCALE * waveformMagicFactor));
|
||||||
|
var previewEndPosMs:Int = Std.int(waveformMusic.waveform.waveformData.indexToSeconds(previewEndPosIndex) * Constants.MS_PER_SEC);
|
||||||
|
|
||||||
|
chartEditorState.performCommand(new SetFreeplayPreviewCommand(previewStartPosMs, previewEndPosMs));
|
||||||
|
|
||||||
|
waveformDragStartPos = null;
|
||||||
|
waveformDragPreviewStartPos = 0;
|
||||||
|
waveformDragPreviewEndPos = 0;
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
addOffsetsToAudioPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function playAudioPreview():Void
|
||||||
|
{
|
||||||
|
if (isPerformingPreview) stopPerformingPreview();
|
||||||
|
|
||||||
|
audioPreviewTracks.volume = freeplayPreviewVolume;
|
||||||
|
audioPreviewTracks.play(false, audioPreviewTracks.time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addOffsetsToAudioPreview():Void
|
||||||
|
{
|
||||||
|
var trackInst = audioPreviewTracks.members[0];
|
||||||
|
if (trackInst != null)
|
||||||
|
{
|
||||||
|
trackInst.time -= chartEditorState.currentInstrumentalOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
var trackPlayer = audioPreviewTracks.members[1];
|
||||||
|
if (trackPlayer != null)
|
||||||
|
{
|
||||||
|
trackPlayer.time -= chartEditorState.currentVocalOffsetPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
var trackOpponent = audioPreviewTracks.members[2];
|
||||||
|
if (trackOpponent != null)
|
||||||
|
{
|
||||||
|
trackOpponent.time -= chartEditorState.currentVocalOffsetOpponent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pauseAudioPreview():Void
|
||||||
|
{
|
||||||
|
if (isPerformingPreview) stopPerformingPreview();
|
||||||
|
|
||||||
|
audioPreviewTracks.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stopAudioPreview():Void
|
||||||
|
{
|
||||||
|
if (isPerformingPreview) stopPerformingPreview();
|
||||||
|
|
||||||
|
audioPreviewTracks.stop();
|
||||||
|
|
||||||
|
audioPreviewTracks.time = 0;
|
||||||
|
|
||||||
|
waveformScrollview.hscrollPos = 0;
|
||||||
|
playheadAbsolutePos = 0 + playheadSprite.width;
|
||||||
|
refresh();
|
||||||
|
addOffsetsToAudioPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function zoomWaveformIn():Void
|
||||||
|
{
|
||||||
|
if (isPerformingPreview) stopPerformingPreview();
|
||||||
|
|
||||||
|
if (waveformScale > MIN_SCALE)
|
||||||
|
{
|
||||||
|
waveformScale = waveformScale / WAVEFORM_ZOOM_MULT;
|
||||||
|
if (waveformScale < MIN_SCALE) waveformScale = MIN_SCALE;
|
||||||
|
|
||||||
|
trace('Zooming in, scale: ${waveformScale}');
|
||||||
|
|
||||||
|
// Update the playhead too!
|
||||||
|
playheadAbsolutePos = playheadAbsolutePos * WAVEFORM_ZOOM_MULT;
|
||||||
|
|
||||||
|
// Recenter the scroll view on the playhead.
|
||||||
|
var vaguelyCenterPlayheadOffset = waveformScrollview.width / 8;
|
||||||
|
waveformScrollview.hscrollPos = playheadAbsolutePos - vaguelyCenterPlayheadOffset;
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
refreshTicks();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waveformScale = MIN_SCALE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function zoomWaveformOut():Void
|
||||||
|
{
|
||||||
|
waveformScale = waveformScale * WAVEFORM_ZOOM_MULT;
|
||||||
|
if (waveformScale < MIN_SCALE) waveformScale = MIN_SCALE;
|
||||||
|
|
||||||
|
trace('Zooming out, scale: ${waveformScale}');
|
||||||
|
|
||||||
|
// Update the playhead too!
|
||||||
|
playheadAbsolutePos = playheadAbsolutePos / WAVEFORM_ZOOM_MULT;
|
||||||
|
|
||||||
|
// Recenter the scroll view on the playhead.
|
||||||
|
var vaguelyCenterPlayheadOffset = waveformScrollview.width / 8;
|
||||||
|
waveformScrollview.hscrollPos = playheadAbsolutePos - vaguelyCenterPlayheadOffset;
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
refreshTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTrackVolume(volume:Float):Void
|
||||||
|
{
|
||||||
|
audioPreviewTracks.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function muteTrack():Void
|
||||||
|
{
|
||||||
|
audioPreviewTracks.muted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unmuteTrack():Void
|
||||||
|
{
|
||||||
|
audioPreviewTracks.muted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toggleMuteTrack():Void
|
||||||
|
{
|
||||||
|
audioPreviewTracks.muted = !audioPreviewTracks.muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isPerformingPreview:Bool = false;
|
||||||
|
var isFadingOutPreview:Bool = false;
|
||||||
|
|
||||||
|
public function performPreview():Void
|
||||||
|
{
|
||||||
|
isPerformingPreview = true;
|
||||||
|
isFadingOutPreview = false;
|
||||||
|
audioPreviewTracks.play(true, chartEditorState.currentSongFreeplayPreviewStart);
|
||||||
|
audioPreviewTracks.fadeIn(FreeplayState.FADE_IN_DURATION, FreeplayState.FADE_IN_START_VOLUME * freeplayPreviewVolume,
|
||||||
|
FreeplayState.FADE_IN_END_VOLUME * freeplayPreviewVolume, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stopPerformingPreview():Void
|
||||||
|
{
|
||||||
|
isPerformingPreview = false;
|
||||||
|
isFadingOutPreview = false;
|
||||||
|
audioPreviewTracks.volume = freeplayPreviewVolume;
|
||||||
|
audioPreviewTracks.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override function update(elapsed:Float)
|
||||||
|
{
|
||||||
|
super.update(elapsed);
|
||||||
|
|
||||||
|
if (isPerformingPreview && !audioPreviewTracks.playing)
|
||||||
|
{
|
||||||
|
stopPerformingPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPerformingPreview && audioPreviewTracks.playing)
|
||||||
|
{
|
||||||
|
var startFadeOutTime = chartEditorState.currentSongFreeplayPreviewEnd - (FreeplayState.FADE_OUT_DURATION * Constants.MS_PER_SEC);
|
||||||
|
trace('startFadeOutTime: ${audioPreviewTracks.time} >= ${startFadeOutTime}');
|
||||||
|
if (!isFadingOutPreview && audioPreviewTracks.time >= startFadeOutTime)
|
||||||
|
{
|
||||||
|
isFadingOutPreview = true;
|
||||||
|
audioPreviewTracks.fadeOut(FreeplayState.FADE_OUT_DURATION, FreeplayState.FADE_OUT_END_VOLUME * freeplayPreviewVolume, (_) -> {
|
||||||
|
trace('Stop performing preview! ${audioPreviewTracks.time}');
|
||||||
|
stopPerformingPreview();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (audioPreviewTracks.playing)
|
||||||
|
{
|
||||||
|
var targetScrollPos:Float = waveformMusic.waveform.waveformData.secondsToIndex(audioPreviewTracks.time / Constants.MS_PER_SEC) / (waveformScale / BASE_SCALE * waveformMagicFactor);
|
||||||
|
// waveformScrollview.hscrollPos = targetScrollPos;
|
||||||
|
var prevPlayheadAbsolutePos = playheadAbsolutePos;
|
||||||
|
playheadAbsolutePos = targetScrollPos;
|
||||||
|
var playheadDiff = playheadAbsolutePos - prevPlayheadAbsolutePos;
|
||||||
|
|
||||||
|
// BEHAVIOR C.
|
||||||
|
// Copy Audacity!
|
||||||
|
// If the playhead is out of view, jump forward or backward by one screen width until it's in view.
|
||||||
|
if (playheadAbsolutePos < waveformScrollview.hscrollPos)
|
||||||
|
{
|
||||||
|
waveformScrollview.hscrollPos -= waveformScrollview.width;
|
||||||
|
}
|
||||||
|
if (playheadAbsolutePos > waveformScrollview.hscrollPos + waveformScrollview.width)
|
||||||
|
{
|
||||||
|
waveformScrollview.hscrollPos += waveformScrollview.width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
freeplayLabelTime.text = formatTime(audioPreviewTracks.time / Constants.MS_PER_SEC);
|
||||||
|
if (waveformDragStartPos != null && (waveformDragPreviewStartPos > 0 && waveformDragPreviewEndPos > 0))
|
||||||
|
{
|
||||||
|
var previewStartPosAbsolute = waveformDragPreviewStartPos + waveformScrollview.hscrollPos;
|
||||||
|
var previewStartPosIndex:Int = Std.int(previewStartPosAbsolute * (waveformScale / BASE_SCALE * waveformMagicFactor));
|
||||||
|
var previewStartPosMs:Int = Std.int(waveformMusic.waveform.waveformData.indexToSeconds(previewStartPosIndex) * Constants.MS_PER_SEC);
|
||||||
|
|
||||||
|
var previewEndPosAbsolute = waveformDragPreviewEndPos + waveformScrollview.hscrollPos;
|
||||||
|
var previewEndPosIndex:Int = Std.int(previewEndPosAbsolute * (waveformScale / BASE_SCALE * waveformMagicFactor));
|
||||||
|
var previewEndPosMs:Int = Std.int(waveformMusic.waveform.waveformData.indexToSeconds(previewEndPosIndex) * Constants.MS_PER_SEC);
|
||||||
|
|
||||||
|
// Set the values in milliseconds.
|
||||||
|
freeplayPreviewStart.value = previewStartPosMs;
|
||||||
|
freeplayPreviewEnd.value = previewEndPosMs;
|
||||||
|
|
||||||
|
previewBoxStartPosAbsolute = previewStartPosAbsolute;
|
||||||
|
previewBoxEndPosAbsolute = previewEndPosAbsolute;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
previewBoxStartPosAbsolute = waveformMusic.waveform.waveformData.secondsToIndex(chartEditorState.currentSongFreeplayPreviewStart / Constants.MS_PER_SEC) / (waveformScale / BASE_SCALE * waveformMagicFactor);
|
||||||
|
previewBoxEndPosAbsolute = waveformMusic.waveform.waveformData.secondsToIndex(chartEditorState.currentSongFreeplayPreviewEnd / Constants.MS_PER_SEC) / (waveformScale / BASE_SCALE * waveformMagicFactor);
|
||||||
|
|
||||||
|
freeplayPreviewStart.value = chartEditorState.currentSongFreeplayPreviewStart;
|
||||||
|
freeplayPreviewEnd.value = chartEditorState.currentSongFreeplayPreviewEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override function refresh():Void
|
||||||
|
{
|
||||||
|
super.refresh();
|
||||||
|
|
||||||
|
waveformMagicFactor = MAGIC_SCALE_BASE_TIME / (chartEditorState.offsetTickBitmap.width / waveformMusic.waveform.waveformData.pointsPerSecond());
|
||||||
|
|
||||||
|
var currentZoomFactor = waveformScale / BASE_SCALE * waveformMagicFactor;
|
||||||
|
|
||||||
|
var maxWidth:Int = -1;
|
||||||
|
|
||||||
|
waveformMusic.waveform.time = -chartEditorState.currentInstrumentalOffset / Constants.MS_PER_SEC;
|
||||||
|
waveformMusic.waveform.width = (waveformMusic.waveform.waveformData?.length ?? 1000) / currentZoomFactor;
|
||||||
|
if (waveformMusic.waveform.width > maxWidth) maxWidth = Std.int(waveformMusic.waveform.width);
|
||||||
|
waveformMusic.waveform.height = 65;
|
||||||
|
waveformMusic.waveform.markDirty();
|
||||||
|
|
||||||
|
waveformContainer.width = maxWidth;
|
||||||
|
tickTiledSprite.width = maxWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function build(chartEditorState:ChartEditorState):ChartEditorFreeplayToolbox
|
||||||
|
{
|
||||||
|
return new ChartEditorFreeplayToolbox(chartEditorState);
|
||||||
|
}
|
||||||
|
}
|
|
@ -191,7 +191,6 @@ class ChartEditorOffsetsToolbox extends ChartEditorBaseToolbox
|
||||||
// Move the playhead if it would go out of view.
|
// Move the playhead if it would go out of view.
|
||||||
var prevPlayheadRelativePos = playheadRelativePos;
|
var prevPlayheadRelativePos = playheadRelativePos;
|
||||||
playheadRelativePos = FlxMath.bound(playheadRelativePos, 0, waveformScrollview.width - PLAYHEAD_RIGHT_PAD);
|
playheadRelativePos = FlxMath.bound(playheadRelativePos, 0, waveformScrollview.width - PLAYHEAD_RIGHT_PAD);
|
||||||
trace('newPos: ${playheadRelativePos}');
|
|
||||||
var diff = playheadRelativePos - prevPlayheadRelativePos;
|
var diff = playheadRelativePos - prevPlayheadRelativePos;
|
||||||
|
|
||||||
if (diff != 0)
|
if (diff != 0)
|
||||||
|
@ -271,18 +270,18 @@ class ChartEditorOffsetsToolbox extends ChartEditorBaseToolbox
|
||||||
|
|
||||||
// Build player waveform.
|
// Build player waveform.
|
||||||
// waveformPlayer.waveform.forceUpdate = true;
|
// waveformPlayer.waveform.forceUpdate = true;
|
||||||
waveformPlayer.waveform.waveformData = WaveformDataParser.interpretFlxSound(playerVoice);
|
waveformPlayer.waveform.waveformData = playerVoice.waveformData;
|
||||||
// Set the width and duration to render the full waveform, with the clipRect applied we only render a segment of it.
|
// Set the width and duration to render the full waveform, with the clipRect applied we only render a segment of it.
|
||||||
waveformPlayer.waveform.duration = playerVoice.length / Constants.MS_PER_SEC;
|
waveformPlayer.waveform.duration = playerVoice.length / Constants.MS_PER_SEC;
|
||||||
|
|
||||||
// Build opponent waveform.
|
// Build opponent waveform.
|
||||||
// waveformOpponent.waveform.forceUpdate = true;
|
// waveformOpponent.waveform.forceUpdate = true;
|
||||||
waveformOpponent.waveform.waveformData = WaveformDataParser.interpretFlxSound(opponentVoice);
|
waveformOpponent.waveform.waveformData = opponentVoice.waveformData;
|
||||||
waveformOpponent.waveform.duration = opponentVoice.length / Constants.MS_PER_SEC;
|
waveformOpponent.waveform.duration = opponentVoice.length / Constants.MS_PER_SEC;
|
||||||
|
|
||||||
// Build instrumental waveform.
|
// Build instrumental waveform.
|
||||||
// waveformInstrumental.waveform.forceUpdate = true;
|
// waveformInstrumental.waveform.forceUpdate = true;
|
||||||
waveformInstrumental.waveform.waveformData = WaveformDataParser.interpretFlxSound(instTrack);
|
waveformInstrumental.waveform.waveformData = chartEditorState.audioInstTrack.waveformData;
|
||||||
waveformInstrumental.waveform.duration = instTrack.length / Constants.MS_PER_SEC;
|
waveformInstrumental.waveform.duration = instTrack.length / Constants.MS_PER_SEC;
|
||||||
|
|
||||||
addOffsetsToAudioPreview();
|
addOffsetsToAudioPreview();
|
||||||
|
@ -410,8 +409,6 @@ class ChartEditorOffsetsToolbox extends ChartEditorBaseToolbox
|
||||||
deltaPixels / waveformInstrumental.waveform.waveformData.pointsPerSecond() * Constants.MS_PER_SEC;
|
deltaPixels / waveformInstrumental.waveform.waveformData.pointsPerSecond() * Constants.MS_PER_SEC;
|
||||||
};
|
};
|
||||||
|
|
||||||
trace('Moving waveform by ${deltaMousePosition} -> ${deltaPixels} -> ${deltaMilliseconds} milliseconds.');
|
|
||||||
|
|
||||||
switch (dragWaveform)
|
switch (dragWaveform)
|
||||||
{
|
{
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
|
@ -537,8 +534,6 @@ class ChartEditorOffsetsToolbox extends ChartEditorBaseToolbox
|
||||||
waveformScale = waveformScale / WAVEFORM_ZOOM_MULT;
|
waveformScale = waveformScale / WAVEFORM_ZOOM_MULT;
|
||||||
if (waveformScale < MIN_SCALE) waveformScale = MIN_SCALE;
|
if (waveformScale < MIN_SCALE) waveformScale = MIN_SCALE;
|
||||||
|
|
||||||
trace('Zooming in, scale: ${waveformScale}');
|
|
||||||
|
|
||||||
// Update the playhead too!
|
// Update the playhead too!
|
||||||
playheadAbsolutePos = playheadAbsolutePos * WAVEFORM_ZOOM_MULT;
|
playheadAbsolutePos = playheadAbsolutePos * WAVEFORM_ZOOM_MULT;
|
||||||
|
|
||||||
|
@ -560,8 +555,6 @@ class ChartEditorOffsetsToolbox extends ChartEditorBaseToolbox
|
||||||
waveformScale = waveformScale * WAVEFORM_ZOOM_MULT;
|
waveformScale = waveformScale * WAVEFORM_ZOOM_MULT;
|
||||||
if (waveformScale < MIN_SCALE) waveformScale = MIN_SCALE;
|
if (waveformScale < MIN_SCALE) waveformScale = MIN_SCALE;
|
||||||
|
|
||||||
trace('Zooming out, scale: ${waveformScale}');
|
|
||||||
|
|
||||||
// Update the playhead too!
|
// Update the playhead too!
|
||||||
playheadAbsolutePos = playheadAbsolutePos / WAVEFORM_ZOOM_MULT;
|
playheadAbsolutePos = playheadAbsolutePos / WAVEFORM_ZOOM_MULT;
|
||||||
|
|
||||||
|
@ -776,7 +769,7 @@ class ChartEditorOffsetsToolbox extends ChartEditorBaseToolbox
|
||||||
audioPreviewOpponentOffset = chartEditorState.currentVocalOffsetOpponent;
|
audioPreviewOpponentOffset = chartEditorState.currentVocalOffsetOpponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
offsetLabelTime.text = formatTime(audioPreviewTracks.time / Constants.MS_PER_SEC);
|
||||||
// Keep the playhead in view.
|
// Keep the playhead in view.
|
||||||
// playheadRelativePos = FlxMath.bound(playheadRelativePos, waveformScrollview.hscrollPos + 1,
|
// playheadRelativePos = FlxMath.bound(playheadRelativePos, waveformScrollview.hscrollPos + 1,
|
||||||
// Math.min(waveformScrollview.hscrollPos + waveformScrollview.width, waveformContainer.width));
|
// Math.min(waveformScrollview.hscrollPos + waveformScrollview.width, waveformContainer.width));
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
package funkin.play.cutscene.dialogue;
|
package funkin.ui.debug.dialogue;
|
||||||
|
|
||||||
import flixel.FlxState;
|
import flixel.FlxState;
|
||||||
import funkin.modding.events.ScriptEventDispatcher;
|
import funkin.modding.events.ScriptEventDispatcher;
|
||||||
import funkin.modding.events.ScriptEvent;
|
import funkin.modding.events.ScriptEvent;
|
||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
import funkin.ui.MusicBeatState;
|
import funkin.ui.MusicBeatState;
|
||||||
|
import funkin.data.dialogue.ConversationData;
|
||||||
|
import funkin.data.dialogue.ConversationRegistry;
|
||||||
|
import funkin.data.dialogue.DialogueBoxData;
|
||||||
|
import funkin.data.dialogue.DialogueBoxRegistry;
|
||||||
|
import funkin.data.dialogue.SpeakerData;
|
||||||
|
import funkin.data.dialogue.SpeakerRegistry;
|
||||||
|
import funkin.play.cutscene.dialogue.Conversation;
|
||||||
|
import funkin.play.cutscene.dialogue.DialogueBox;
|
||||||
|
import funkin.play.cutscene.dialogue.Speaker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A state with displays a conversation with no background.
|
* A state with displays a conversation with no background.
|
||||||
|
@ -27,7 +36,7 @@ class ConversationDebugState extends MusicBeatState
|
||||||
|
|
||||||
public override function create():Void
|
public override function create():Void
|
||||||
{
|
{
|
||||||
conversation = ConversationDataParser.fetchConversation(conversationId);
|
conversation = ConversationRegistry.instance.fetchEntry(conversationId);
|
||||||
conversation.completeCallback = onConversationComplete;
|
conversation.completeCallback = onConversationComplete;
|
||||||
add(conversation);
|
add(conversation);
|
||||||
|
|
||||||
|
@ -40,6 +49,12 @@ class ConversationDebugState extends MusicBeatState
|
||||||
conversation = null;
|
conversation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override function dispatchEvent(event:ScriptEvent):Void
|
||||||
|
{
|
||||||
|
// Dispatch event to conversation script.
|
||||||
|
ScriptEventDispatcher.callEvent(conversation, event);
|
||||||
|
}
|
||||||
|
|
||||||
public override function update(elapsed:Float):Void
|
public override function update(elapsed:Float):Void
|
||||||
{
|
{
|
||||||
super.update(elapsed);
|
super.update(elapsed);
|
|
@ -56,6 +56,31 @@ import lime.utils.Assets;
|
||||||
|
|
||||||
class FreeplayState extends MusicBeatSubState
|
class FreeplayState extends MusicBeatSubState
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* For the audio preview, the duration of the fade-in effect.
|
||||||
|
*/
|
||||||
|
public static final FADE_IN_DURATION:Float = 0.5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the audio preview, the duration of the fade-out effect.
|
||||||
|
*/
|
||||||
|
public static final FADE_OUT_DURATION:Float = 0.25;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the audio preview, the volume at which the fade-in starts.
|
||||||
|
*/
|
||||||
|
public static final FADE_IN_START_VOLUME:Float = 0.25;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the audio preview, the volume at which the fade-in ends.
|
||||||
|
*/
|
||||||
|
public static final FADE_IN_END_VOLUME:Float = 1.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the audio preview, the volume at which the fade-out starts.
|
||||||
|
*/
|
||||||
|
public static final FADE_OUT_END_VOLUME:Float = 0.0;
|
||||||
|
|
||||||
var songs:Array<Null<FreeplaySongData>> = [];
|
var songs:Array<Null<FreeplaySongData>> = [];
|
||||||
|
|
||||||
var diffIdsCurrent:Array<String> = [];
|
var diffIdsCurrent:Array<String> = [];
|
||||||
|
@ -139,9 +164,9 @@ class FreeplayState extends MusicBeatSubState
|
||||||
isDebug = true;
|
isDebug = true;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
if (FlxG.sound.music != null)
|
if (FlxG.sound.music == null || (FlxG.sound.music != null && !FlxG.sound.music.playing))
|
||||||
{
|
{
|
||||||
if (!FlxG.sound.music.playing) FlxG.sound.playMusic(Paths.music('freakyMenu/freakyMenu'));
|
FlxG.sound.playMusic(Paths.music('freakyMenu/freakyMenu'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a null entry that represents the RANDOM option
|
// Add a null entry that represents the RANDOM option
|
||||||
|
|
|
@ -9,7 +9,8 @@ class DataAssets
|
||||||
|
|
||||||
public static function listDataFilesInPath(path:String, ?suffix:String = '.json'):Array<String>
|
public static function listDataFilesInPath(path:String, ?suffix:String = '.json'):Array<String>
|
||||||
{
|
{
|
||||||
var textAssets = openfl.utils.Assets.list();
|
var textAssets = openfl.utils.Assets.list(TEXT);
|
||||||
|
|
||||||
var queryPath = buildDataPath(path);
|
var queryPath = buildDataPath(path);
|
||||||
|
|
||||||
var results:Array<String> = [];
|
var results:Array<String> = [];
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
<haxelib name="hxCodec" /> <!-- Video playback -->
|
<haxelib name="hxCodec" /> <!-- Video playback -->
|
||||||
<haxelib name="thx.semver" /> <!-- Semantic version handling -->
|
<haxelib name="thx.semver" /> <!-- Semantic version handling -->
|
||||||
<haxelib name="json2object" /> <!-- JSON parsing -->
|
<haxelib name="json2object" /> <!-- JSON parsing -->
|
||||||
<haxelib name="tink_json" /> <!-- JSON parsing -->
|
|
||||||
|
|
||||||
<!-- Test dependencies -->
|
<!-- Test dependencies -->
|
||||||
<haxelib name="munit" /> <!-- Unit test execution -->
|
<haxelib name="munit" /> <!-- Unit test execution -->
|
||||||
|
|
Loading…
Reference in a new issue