Skip to content

Commit

Permalink
Finally fix saves using weird ass default values
Browse files Browse the repository at this point in the history
  • Loading branch information
superpowers04 committed Jun 12, 2024
1 parent eb2a33b commit 38bbcab
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 27 deletions.
46 changes: 20 additions & 26 deletions source/SEFlxSaveWrapper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,27 @@ class SEFlxSaveWrapper{
try{

var json = CoolUtil.cleanJSON(SELoader.loadText('SESETTINGS.json')).replace('"" :','" :').replace('"":','":');
var anon = Json.parse(json,SESave,new SESave());
if(anon is SESave){
SESave.data = anon;
return;
var fieldList = haxe.Json.parse(json); //
var save = Json.parse(json,SESave);
var newSave = SESave.data = new SESave();
for(field in Reflect.fields(fieldList)){
if(field.startsWith('set_')){
field = field.substring(4);
}
try{
var stuff:Dynamic = Reflect.field(save,field);
if(stuff == null) throw('how the fuck is $field null, THIS WAS LITERALLY SUPPLIED BY THE JSON');
Reflect.setProperty(newSave,field,stuff);
}catch(e){
trace('Unable to load field "$field": $e');
}
}
//
// for(field in Reflect.fields(Type.getInstanceFields(SESave))){
// if(field.startsWith('set_')){
// field = field.substring(4);
// }
// if(!Reflect.hasField(anon,field)){
// trace('Save field "$field" was not found in the save file');
// continue;
// }
// try{
// var stuff = Reflect.field(anon,field);
// if(stuff == null) throw("Invalid field!");
// Reflect.setProperty(SESave.data,field,stuff);
// }catch(e){
// trace('Unable to load field "$field": $e');
// }
// }
SELoader.saveContent("SESETTINGS-OLD.json",json);
trace('Unable to load settings from an invalid format');
try{
MusicBeatState.instance.showTempmessage('Settings file is in an invalid format\n Your settings have been reset!',0xFFFF0000);
}catch(e){}
// SESave.data.keys = save.keys;
// SELoader.saveContent("SESETTINGS-OLD.json",json);
// trace('Unable to load settings from an invalid format');
// try{
// MusicBeatState.instance.showTempmessage('Settings file is in an invalid format\n Your settings have been reset!',0xFFFF0000);
// }catch(e){}
}catch(e){
throw('Error while parsing SESettings.json:\n${e.message}');
}
Expand Down
101 changes: 101 additions & 0 deletions source/se/objects/SEJoinedSound.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package se.objects;

import flixel.sound.FlxSound;

// We literally only extend FlxObject so you can add this as a normal object to a FlxState/FlxGroup for updating
@:publicFields class SEJoinedSound extends FlxBasic {
var sounds:Array<FlxSound> = [];
var sound(get,set):FlxSound;
@:keep inline function get_sound(){
return sounds[0];
}
@:keep inline function set_sound(s:FlxSound){
return sounds[0]=s;
}
var syncVolume:Bool = false;
var syncTime:Bool = true;
var maxTimeDifference:Int=5;
var syncPlaying:Bool = true;
var syncGroup:Bool = false;

function new(?initialSound:FlxSound = null){
super();
if(initialSound != null){
sounds[0]=initialSound;
}
}
function update(?e:Float){
sync();
}
function draw(){}

function sync(){
var sound = sound;
if(!sound.playing) return;
var i = sounds.length;
while(i > 0){
var s = sounds[i];
if(syncVolume) s.volume = sound.volume;
if(syncPlaying && s.playing != sound.playing){
if(sound.playing) s.play();
else s.pause();
}
if(s.playing && syncTime && Math.abs(s.time,sound.time) > maxTimeDifference) s.time = sound.time;

}
}
function add(s:FlxSound):FlxSound{
sounds.push(s);
if(syncGroup) s.group = sound.group;
sync();
return s;
}
function remove(sound:FlxSound):FlxSound{
sounds.remove(sound);
return sound;
}



// Shadowed Variables/Functions. This shit is dumb tbh
function stop() for(sound in sounds) sound.stop();
function start() for(sound in sounds) sound.start();
function pause() for(sound in sounds) sound.pause();
var volume(get,set):Float;
function get_volume() return sound.volume;
function set_volume(v) for(sound in sounds) {sound.volume=v;} return v;
var loopTime(get,set):Float;
function get_loopTime() return sound.loopTime;
function set_loopTime(v) for(sound in sounds) {sound.loopTime=v;} return v;
var endTime(get,set):Float;
function get_endTime() return sound.endTime;
function set_endTime(v) for(sound in sounds) {sound.endTime=v;} return v;
var time(get,set):Float;
function get_time() return sound.time;
function set_time(v) for(sound in sounds) {sound.time=v;} return v;
#if FLX_PITCH
var pitch(get, set):Float;
function get_pitch() return sound.pitch;
function set_pitch(v) for(sound in sounds) {sound.pitch=v;} return v;
#end

var looped(get,set):Bool;
function get_looped() return sound.looped;
function set_looped(v) for(sound in sounds) {sound.looped=v;} return v;
var playing(get,set):Bool;
function get_playing() return sound.playing;
function set_playing(v) for(sound in sounds) {(v?sound.play():sound.pause());} return v;
var autoDestroy(get,set):Bool;
function get_autoDestroy() return sound.autoDestroy;
function set_autoDestroy(v) for(sound in sounds) {sound.autoDestroy=v;} return v;

var onComplete(get,set):Void->Void;
function get_onComplete() return sound.onComplete;
function set_onComplete(v) return sound.onComplete=v;
var group(get, set):FlxSoundGroup;
function get_group() return sound.group;
function set_group(v) for(sound in sounds) {sound.group=v;} return v;



}
2 changes: 1 addition & 1 deletion version.downloadMe
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
24.06.11.0023;
24.06.12.0938;
* Better Psych character support(Still kinda experimental but should be more stable)
* Fix some small errors
* Fix characters not loading due to using ID instead of folderName
Expand Down

0 comments on commit 38bbcab

Please sign in to comment.