Skip to content

Commit

Permalink
chart backups moment
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Dec 6, 2023
1 parent 95a7422 commit 1d5ba1c
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 23 deletions.
4 changes: 4 additions & 0 deletions assets/preload/data/defaultOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@
"value": "{}",
"save": "autosave"
},
{
"option": "backupDuration",
"value": 10
},
{
"option": "shaders",
"value": true
Expand Down
8 changes: 7 additions & 1 deletion source/game/Character.hx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ class Character extends FlxSprite {

barColor = FlxColor.fromRGB(config.barColor[0], config.barColor[1], config.barColor[2]);

var localKeyCount = isPlayer ? PlayState.SONG.playerKeyCount : PlayState.SONG.keyCount;
var localKeyCount;
if(PlayState.SONG.playerKeyCount != null && PlayState.SONG.keyCount != null ){
localKeyCount = isPlayer ? PlayState.SONG.playerKeyCount : PlayState.SONG.keyCount;
}
else{
localKeyCount = isPlayer ? 4 : 4;
}

if (config.noteColors == null){
config.noteColors = NoteColors.defaultColors;
Expand Down
2 changes: 1 addition & 1 deletion source/game/Note.hx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class Note extends FlxSprite {
alpha = 0.3;
}
}
if (canBeHit && Options.getData("playerStrumsGlowWhenCanBeHit") && !isSustainNote && !inEditor && animation.curAnim.name.contains("default")){
if (canBeHit && Options.getData("playerStrumsGlowWhenCanBeHit") && !isSustainNote && !inEditor && animation.curAnim.name.contains("default") && animation != null){
animation.play("glow");
}
}
Expand Down
10 changes: 6 additions & 4 deletions source/game/NoteSplash.hx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ class NoteSplash extends FlxSprite {
noteColor = charColors.noteColors[localKeyCount - 1][noteData];
else
noteColor = NoteColors.getNoteColor(NoteVariables.Other_Note_Anim_Stuff[PlayState.SONG.keyCount - 1][noteData]);

colorSwap.r = noteColor[0];
colorSwap.g = noteColor[1];
colorSwap.b = noteColor[2];
}
else{
noteColor = [255,0,0];
}
colorSwap.r = noteColor[0];
colorSwap.g = noteColor[1];
colorSwap.b = noteColor[2];
update(0);
}

Expand Down
4 changes: 4 additions & 0 deletions source/modding/ModchartUtilities.hx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ class ModchartUtilities {
version: lime.app.Application.current.meta.get('version'),
});

setVar("version", {
version: lime.app.Application.current.meta.get('version'),
});

// callbacks

setLuaFunction("trace", function(str:Dynamic = "") {
Expand Down
33 changes: 16 additions & 17 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,6 @@ class PlayState extends MusicBeatState {
var globalLuaScript:ModchartUtilities;
#end

var fixedUpdateTime:Float = 0.0;

function allScriptCall(func:String, ?args:Array<Dynamic>) {
for (cool_script in scripts) {
cool_script.call(func, args);
Expand Down Expand Up @@ -2224,39 +2222,33 @@ class PlayState extends MusicBeatState {
function fixedUpdate() {

if (script != null)
script.call("fixedUpdate", [fixedUpdateFPS]);
script.call("fixedUpdate", [1 / 120]);

if (gf.script != null)
gf.script.call("fixedUpdate", [fixedUpdateFPS]);
gf.script.call("fixedUpdate", [1 / 120]);
if (dad.script != null)
dad.script.call("fixedUpdate", [fixedUpdateFPS]);
dad.script.call("fixedUpdate", [1 / 120]);
if (boyfriend.script != null)
boyfriend.script.call("fixedUpdate", [fixedUpdateFPS]);
boyfriend.script.call("fixedUpdate", [1 / 120]);

#if linc_luajit
setLuaVar("songPos", Conductor.songPosition);
setLuaVar("bot", Options.getData("botplay"));
setLuaVar("hudZoom", camHUD.zoom);
setLuaVar("curBeat", curBeat);
setLuaVar("cameraZoom", FlxG.camera.zoom);

executeALuaState("fixedUpdate", [fixedUpdateFPS]);
allScriptCall("fixedUpdate", [fixedUpdateFPS]);
executeALuaState("fixedUpdate", [1 / 120]);
#end
allScriptCall("fixedUpdate", [1 / 120]);
}

var fixedUpdateFPS:Int = 60;
var fixedUpdateTime:Float = 0.0;

override public function update(elapsed:Float) {
if (script != null)
script.update(elapsed);

fixedUpdateTime += elapsed;

if (fixedUpdateTime > 1 / fixedUpdateFPS) {
fixedUpdate();
fixedUpdateTime = 0;
}


super.update(elapsed);

tweenManager.update(elapsed);
Expand Down Expand Up @@ -2300,6 +2292,13 @@ class PlayState extends MusicBeatState {

song_info_timer += elapsed;

fixedUpdateTime += elapsed;

if (fixedUpdateTime >= 1 / 120) {
fixedUpdate();
fixedUpdateTime = 0;
}

if (song_info_timer >= 0.25 / songMultiplier) {
updateSongInfoText();
song_info_timer = 0;
Expand Down
70 changes: 70 additions & 0 deletions source/tools/ChartingState.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools;

import flixel.util.FlxTimer;
import flixel.FlxObject;
import game.EventSprite;
import utilities.NoteVariables;
Expand Down Expand Up @@ -315,11 +316,80 @@ class ChartingState extends MusicBeatState {
updateHeads();
updateGrid();

new FlxTimer().start(Options.getData("backupDuration") * 60, backupChart, 0);
new FlxTimer().start(Options.getData("backupDuration") * 60, backupEvents, 0);

super.create();

loadedAutosave = false;
}

private function backupChart(_):Void{
trace("trying to make a backup of the chart...");
var json:Dynamic;
var date:String = Date.now().toString();
var path:String;
date = StringTools.replace(date, " ", "_");
date = StringTools.replace(date, ":", "'");
json = {"song": _song};
json.song.events = [];
var data:String = Json.stringify(json);

if ((data != null) && (data.length > 0)) {
var gamingName = _song.song.toLowerCase();

if (difficulty.toLowerCase() != 'normal')
gamingName = gamingName + '-' + difficulty.toLowerCase();

#if sys
path = "./backups/" + "backup-" + gamingName + '-on-' + date + ".json";
if (!sys.FileSystem.exists("./backups/"))
sys.FileSystem.createDirectory("./backups/");
sys.io.File.saveContent(path, Std.string(data.trim()));
trace("chart backup made!");
#else
trace("failed to make backup!")
#end
}
}
private function backupEvents(_):Void {
trace("trying to make a backup of the events...");
var json:Dynamic;
var date:String = Date.now().toString();
var path:String;
date = StringTools.replace(date, " ", "_");
date = StringTools.replace(date, ":", "'");

json = {
"song": {
"events": []
}
};
json.song.events = events;
var data:String = Json.stringify(json);
if ((data != null) && (data.length > 0)) {

var gamingName = _song.song.toLowerCase();

gamingName = "events-";

gamingName += _song.song.toLowerCase();

if (difficulty.toLowerCase() != 'normal')
gamingName = gamingName + '-' + difficulty.toLowerCase();

#if sys
path = "./backups/" + "backup-" + gamingName + '-on-' + date + ".json";
if (!sys.FileSystem.exists("./backups/"))
sys.FileSystem.createDirectory("./backups/");
sys.io.File.saveContent(path, Std.string(data.trim()));
trace("events backup made!");
#else
trace("failed to make backup!")
#end
}
}

function addSongUI():Void {
// base ui thingy :D
var tab_group_song = new FlxUI(null, UI_box);
Expand Down

0 comments on commit 1d5ba1c

Please sign in to comment.