Ok it works

This commit is contained in:
lunarcleint
2023-08-19 11:53:57 -07:00
parent a49b60c077
commit 4bcba9e188
6 changed files with 65 additions and 6 deletions
@@ -1,5 +1,8 @@
package funkin.editors.charter;
import haxe.Json;
import funkin.backend.assets.ModsFolder;
import funkin.editors.charter.SongCreationScreen.SongCreationData;
import funkin.options.type.NewOption;
import funkin.backend.system.framerate.Framerate;
import flixel.util.FlxColor;
@@ -8,6 +11,8 @@ import funkin.editors.EditorTreeMenu;
import funkin.options.*;
import funkin.options.type.*;
using StringTools;
class CharterSelection extends EditorTreeMenu {
public var freeplayList:FreeplaySonglist;
public override function create() {
@@ -26,15 +31,13 @@ class CharterSelection extends EditorTreeMenu {
FlxG.switchState(new Charter(s.name, d));
})
];
list.push(new NewOption("New Difficulty", "New Difficulty", function() {
}));
list.push(new NewOption("New Difficulty", "New Difficulty", function() {}));
optionsTree.add(new OptionsScreen(s.name, "Select a difficulty to continue.", list));
})
];
list.insert(0, new NewOption("New Chart", "New Chart", function() {
FlxG.state.openSubState(new SongCreationScreen());
FlxG.state.openSubState(new SongCreationScreen(saveSong));
}));
main = new OptionsScreen("Chart Editor", "Select a song to modify the charts from.", list);
@@ -73,4 +76,34 @@ class CharterSelection extends EditorTreeMenu {
bg.colorTransform.blueMultiplier = FlxMath.lerp(1, color.blueFloat, 0.25);
}
}
public function saveSong(creation:SongCreationData) {
// Paths
var songsDir:String = ModsFolder.currentModFolder != null ? '${ModsFolder.modsPath}${ModsFolder.currentModFolder}/songs/' : './assets/songs/';
var songFolder:String = '$songsDir${creation.meta.name.replace("-", " ")}';
#if sys
// Make Directories
sys.FileSystem.createDirectory(songFolder);
sys.FileSystem.createDirectory('$songFolder/song');
sys.FileSystem.createDirectory('$songFolder/charts');
// Save Files
sys.io.File.saveContent('$songFolder/meta.json', Json.stringify(creation.meta, "\t"));
if (creation.instBytes != null) sys.io.File.saveBytes('$songFolder/song/Inst.${Paths.SOUND_EXT}', creation.instBytes);
if (creation.voicesBytes != null) sys.io.File.saveBytes('$songFolder/song/Voices.${Paths.SOUND_EXT}', creation.voicesBytes);
#end
// Add to List
main.members.insert(1, new IconOption(creation.meta.name, "Press ACCEPT to choose a difficulty to edit.", creation.meta.icon, function() {
var list:Array<OptionType> = [
for(d in creation.meta.difficulties)
if (d != "") new TextOption(d, "Press ACCEPT to edit the chart for the selected difficulty", function() {
FlxG.switchState(new Charter(creation.meta.name, d));
})
];
list.push(new NewOption("New Difficulty", "New Difficulty", function() {}));
optionsTree.add(new OptionsScreen(creation.meta.name, "Select a difficulty to continue.", list));
}));
}
}
@@ -13,7 +13,7 @@ typedef SongCreationData = {
}
class SongCreationScreen extends UISubstateWindow {
private var onSave:SongCreationData -> Void = null;
private var onSave:Null<SongCreationData> -> Void = null;
public var songNameTextBox:UITextBox;
public var bpmStepper:UINumericStepper;
@@ -158,7 +158,7 @@ class SongCreationScreen extends UISubstateWindow {
saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Save & Close", function() {
if (curPage == pages.length-1) {
if (onSave != null) onSave(null);
saveSongInfo();
close();
} else {
curPage++;
@@ -249,4 +249,30 @@ class SongCreationScreen extends UISubstateWindow {
iconSprite.setPosition(iconTextBox.x + 150 + 8, (iconTextBox.y + 16) - (iconSprite.height/2));
}
function saveSongInfo() {
for (stepper in [bpmStepper, beatsPerMesureStepper, stepsPerBeatStepper])
@:privateAccess stepper.__onChange(stepper.label.text);
var meta:ChartMetaData = {
name: songNameTextBox.label.text,
bpm: bpmStepper.value,
beatsPerMesure: Std.int(beatsPerMesureStepper.value),
stepsPerBeat: Std.int(stepsPerBeatStepper.value),
needsVoices: needsVoicesCheckbox.checked,
displayName: displayNameTextBox.label.text,
icon: iconTextBox.label.text,
color: colorWheel.curColorString,
parsedColor: colorWheel.curColor,
opponentModeAllowed: opponentModeCheckbox.checked,
coopAllowed: coopAllowedCheckbox.checked,
difficulties: [for (diff in difficulitesTextBox.label.text.split(",")) diff.trim()],
};
if (onSave != null) onSave({
meta: meta,
instBytes: instExplorer.file,
voicesBytes: voicesExplorer.file
});
}
}