Skip to content

Commit

Permalink
Fix voices becoming desynced in multimenu
Browse files Browse the repository at this point in the history
Fix some issues with loading settings
Proper exit game option when you press back on the title screen
  • Loading branch information
superpowers04 committed Aug 21, 2024
1 parent 5740600 commit bded101
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 72 deletions.
45 changes: 19 additions & 26 deletions source/Alphabet.hx
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,14 @@ class Alphabet extends FlxSpriteGroup
if(sprite == null) sprite = new FlxSprite();
trace('Loading alphabet sprites');
if(SESave.data.useFontEverywhere){
Frames = new flixel.graphics.frames.FlxFramesCollection(FlxGraphic.fromRectangle(1,1,0x01000000,false,"blank.mp4"));
Frames = new flixel.graphics.frames.FlxFramesCollection(FlxGraphic.fromRectangle(1,1,0x01000000,false,"blank.mp4"));
}else{

if(SELoader.exists("mods/alphabet.png") && SELoader.exists("mods/alphabet.xml")){
try{
Frames = SELoader.loadSparrowFrames('mods/alphabet');
}catch(e){
Frames = Paths.getSparrowAtlas('alphabet');
}
}else{
Frames = Paths.getSparrowAtlas('alphabet');
try{
if(!SELoader.exists("mods/alphabet.png") || !SELoader.exists("mods/alphabet.xml")) throw('');
Frames = SELoader.loadSparrowFrames('mods/alphabet');
}catch(e){
Frames = SELoader.loadSparrowFrames('assets/images/alphabet');
// Paths.getSparrowAtlas('alphabet');
}
}
}
Expand Down Expand Up @@ -230,7 +227,7 @@ class Alphabet extends FlxSpriteGroup
currentLetter++;
},length);
}
function addLetter(character:String,bounce:Bool = false){
public function addLetter(character:String,bounce:Bool = false){
if (character == " " || removeDashes && ( character == "-" || character == "_")){
lastWasSpace = true;
return;
Expand Down Expand Up @@ -406,7 +403,7 @@ class AlphaCharacter extends FlxSprite {

@:keep inline public function createLetter(letter:String):Void
{
var letterCase:String = (if (letter.toLowerCase() == letter) "lowercase" else 'capital');
var letterCase:String = (letter.toLowerCase() == letter ? "lowercase" : 'capital');
if(forceFlxText){
useFLXTEXT(letter);
}else{
Expand All @@ -433,31 +430,27 @@ class AlphaCharacter extends FlxSprite {
@:keep inline public function useFLXTEXT(letter:String,bold:Bool = false) {

var cacheID = letter + '${if(bold) '-bold' else ''}';
var txt = textCache[cacheID];
if(txt == null){
cacheText(letter,bold);
}
txt = textCache[cacheID];
var txt = textCache[cacheID] ?? cacheText(letter,bold);
// txt = textCache[cacheID];
if(txt != null){
graphic = txt.graphic;
frames = txt.frames;
}
}

public function createSymbol(letter:String) {
if(alphabetMap[letter] != null){
if(addAnim(letter, alphabetMap[letter])){
animation.play(letter);
updateHitbox();
return;
}
if(alphabetMap[letter] != null && addAnim(letter, alphabetMap[letter])){
animation.play(letter);
updateHitbox();
return;

}

if(addAnim(letter)){
animation.play(letter);
updateHitbox();
}else{
useFLXTEXT(letter);
};
return;
}
useFLXTEXT(letter);
}
}
20 changes: 20 additions & 0 deletions source/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,24 @@ class CoolUtil {
@:keep inline public static function cleanJSON(input:String):String{ // Haxe doesn't filter out comments?
return (~/\/\*[\s\S]*?\*\/|\/\/.*/g).replace(input.trim(),'');
}
public static function applyAnonToObject(obj:Dynamic,anon:Dynamic,?logErrors:Bool = false):Bool{
if(anon == null) return false;
var type = Type.typeof(obj);
var copied:Bool = false;
for(field in Reflect.fields(anon)){
// if(field.startsWith('set_')){
// field = field.substring(4);
// }
try{
if(Reflect.field(obj,field) == null) throw('$field is not present on $type');
var stuff:Dynamic = Reflect.field(anon,field);
if(stuff == null) throw('$field is not on the obj??');
Reflect.setProperty(obj,field,stuff);
if(!copied) copied = true;
}catch(e){
if(logErrors) trace('Unable to load field "$field": $e');
}
}
return copied;
}
}
12 changes: 6 additions & 6 deletions source/LoadingScreen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ import se.SEProfiler;
var loadingText = new Alphabet(0,0,txt,true);
loadingText.isMenuItem = false;
loadingText.visible = true;
if(SESave.data.doCoolLoading){
// if(SESave.data.doCoolLoading){
loadingIcon = new Sprite();
loadingIcon.x = 640;
loadingIcon.y = 300;
Expand All @@ -127,8 +127,8 @@ import se.SEProfiler;
loadingIcon.graphics.drawRect(0,0, note.width, note.height);
loadingIcon.graphics.endFill();
loadingIcon.scaleX = loadingIcon.scaleY= 0.5;

}
//
// }

var funniBitmap = new BitmapData(1290,730,false,0x100010);
var x = 1200;
Expand Down Expand Up @@ -210,9 +210,9 @@ import se.SEProfiler;
var elapsed = 0;
override function __enterFrame(e:Int){
try{
// if(textField.htmlText != loadingText){
// updateText();
// }
if(textField.htmlText != loadingText){
updateText();
}
if(SESave.data.doCoolLoading){
if(loadingIcon != null){
loadingIcon.rotation += e * vel;
Expand Down
20 changes: 16 additions & 4 deletions source/MainMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class MainMenuState extends SickMenuState {
#if !mobile
if (otherMenu) {mmSwitch(true);FlxG.sound.play(Paths.sound('cancelMenu'));return;} else
#end
selected = false;
escapePress();
// FlxG.switchState(new TitleState());
// do nothing
}
Expand Down Expand Up @@ -297,15 +297,25 @@ class MainMenuState extends SickMenuState {
function otherSwitch(){}
#else
public var otherMenu:Bool = false;
function escapePress(){
callInterp('openExitPrompt',[]);
options = ["Main Menu","Exit Game"];
descriptions = ['Return to the main menu','Close out of the game'];
generateList();
curSelected=0;
selected = false;
changeSelection();
}
function otherSwitch(){
options = ["import clipboard","deprecated freeplay","download assets","download characters","import charts from mods","changelog", 'credits'];
descriptions = ['Treats the contents of your clipboard like you\'ve dragged and dropped it onto the game','Play any song from the main game or your assets folder',"Download content made for or ported to Super Engine","Download characters made for or ported to Super Engine",'Convert charts from other mods to work here. Will put them in Modded Songs',"Read the latest changes for the engine","Check out the awesome people who helped with this engine in some way"];

// if (TitleState.osuBeatmapLoc != '') {options.push("osu beatmaps"); descriptions.push("Play osu beatmaps converted over to FNF");}
options.push("back"); descriptions.push("Go back to the main menu");
curSelected = 0;

#if !mobile
otherMenu = true;
#end
selected = false;
callInterp('otherSwitch',[]);
if(cancelCurrentFunction) return;
Expand Down Expand Up @@ -365,7 +375,7 @@ class MainMenuState extends SickMenuState {
}
}

switch (daChoice){
switch (daChoice.toLowerCase()){

case 'open closed chart':
loading = true;
Expand Down Expand Up @@ -408,6 +418,8 @@ class MainMenuState extends SickMenuState {
// FlxG.switchState(new onlinemod.OfflineMenuState());
case "import clipboard":
AnimationDebug.fileDrop(lime.system.Clipboard.text);
case 'exit game' :
Sys.exit(0);
case 'changelog' | 'update':
FlxG.switchState(new OutdatedSubState());
// case "Setup characters":
Expand Down Expand Up @@ -446,7 +458,7 @@ class MainMenuState extends SickMenuState {
FlxG.switchState(new ImportMod());
case 'download characters':
FlxG.switchState(new RepoState());
case "back":
case "back", "main menu":
mmSwitch(true);
#end
default:
Expand Down
6 changes: 4 additions & 2 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,9 @@ class PlayState extends ScriptMusicBeatState
function resyncVocals():Void {
Conductor.songPosition = FlxG.sound.music.time;
FlxG.sound.music.play();
vocals.syncToSound(FlxG.sound.music);
vocals.syncedSound = FlxG.sound.music;
vocals.sync();
// FlxG.sound.music
resyncCount++;
}

Expand Down Expand Up @@ -3412,7 +3414,7 @@ class PlayState extends ScriptMusicBeatState
SEProfiler.qStart('StepHit');
super.stepHit();
// lastStep = curStep;
if (SESave.data.resyncVoices && handleTimes && (FlxG.sound.music.time > Conductor.songPosition + 5 || FlxG.sound.music.time < Conductor.songPosition - 5) && generatedMusic)
if (SESave.data.resyncVoices && handleTimes && (FlxG.sound.music.time > Conductor.songPosition + 10 || FlxG.sound.music.time < Conductor.songPosition - 10) && generatedMusic)
resyncVocals();


Expand Down
18 changes: 10 additions & 8 deletions source/SEFlxSaveWrapper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import flixel.FlxG;

import sys.io.File;
// import flixel.util.FlxSave;
import tjson.Json;
// import tjson.Json.JSONANONTYPE;
using StringTools;

Expand All @@ -19,17 +20,18 @@ class SEFlxSaveWrapper{
if(!SELoader.exists('SESETTINGS.json')) return;
try{

var json = CoolUtil.cleanJSON(SELoader.loadText('SESETTINGS.json')).replace('"" :','" :').replace('"":','":');
var fieldList = haxe.Json.parse(json); //
var save = Json.parse(json,SESave);
var json = SELoader.loadText('SESETTINGS.json').replace('"_hxcls": "se.SESave",','').replace('"" :','" :').replace('"":','":');
// var fieldList = se.formats.JsonParser.parse(json); /
var save = Json.parse(json);
var newSave = SESave.data = new SESave();
for(field in Reflect.fields(fieldList)){
if(field.startsWith('set_')){
field = field.substring(4);
}
for(field in Reflect.fields(save)){
// if(field.startsWith('set_')){
// field = field.substring(4);
// }
try{
if(Reflect.field(newSave,field) == null) throw('$field is FAKE and only present on the JSON but not the Save');
var stuff:Dynamic = Reflect.field(save,field);
if(stuff == null) throw('$field is FAKE and only present on the JSON but not the Save');
if(stuff == null) throw('$field isn\'t on the JSON even though it\'s part of the json??');
Reflect.setProperty(newSave,field,stuff);
}catch(e){
trace('Unable to load field "$field": $e');
Expand Down
45 changes: 34 additions & 11 deletions source/multi/MultiMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class MultiMenuState extends onlinemod.OfflineMenuState {
favButton.resize(250, 30);
searchField.text = lastSearch;
if(lastSearch != "") reloadList(true,lastSearch);

lastSearch = "";
curSelected = 0;
changeSelection(lastSel);
Expand Down Expand Up @@ -284,11 +283,24 @@ class MultiMenuState extends onlinemod.OfflineMenuState {

if(SESave.data.favourites != null && SESave.data.favourites.length > 0){
var containsSong = false;
var missingSongs:Array<SongInfo> = [];
var missingSongs:Array<Dynamic> = [];
_packCount++;
for (song in SESave.data.favourites){
if(!SELoader.exists(song.path)){
missingSongs.push(song);
for (osong in SESave.data.favourites){
var song:SongInfo = null;
var worked:Bool = false;
try{
song = new SongInfo(osong.name, osong.charts,osong.path,osong.namespace,osong.isCategory,osong.categoryID);
worked = CoolUtil.applyAnonToObject(song,osong);
}catch(e){
trace('$osong is an invalid song!');
missingSongs.push(osong);
continue;
}

if(!worked || song == null || song.path == "" || song.path == null || !SELoader.exists(song.path)){
trace('$osong is an invalid song!
${!worked} ${song == null} ${song.path == ""} ${song.path == null} ${!SELoader.exists(song.path)}');
missingSongs.push(osong);
continue;
}
if(search != "" && !query.match(song.name.toLowerCase())) continue;
Expand Down Expand Up @@ -765,26 +777,29 @@ class MultiMenuState extends onlinemod.OfflineMenuState {
voices = new FlxSound();
voices.loadEmbedded(SELoader.loadSound(songInfo.voices),true);
voices.volume = SESave.data.voicesVol;
voices.looped = true;
voices.looped = false;
voices.play(FlxG.sound.music.time);
FlxG.sound.list.add(voices);
songProgressText.text = "Playing Inst and Voices";
}else{
songProgressText.text = "Playing Inst. No Voices available";
}
shouldVoicesPlay = false;
}else{
if(!voices.playing){
shouldVoicesPlay = !(voices.volume == 0);
if(!voices.playing){voices.play();}
if(shouldVoicesPlay){

songProgressText.text = "Playing Inst and Voices";
voices.time = FlxG.sound.music.time = Conductor.songPosition;
voices.play();
voices.volume = SESave.data.voicesVol * FlxG.sound.volume;
voices.looped = true;
voices.looped = false;
}else{
songProgressText.text = "Playing Inst";
voices.stop();
voices.volume = 0;
// voices.stop();
}
}
shouldVoicesPlay = (voices != null && voices.playing);
}catch(e){
showTempmessage('Unable to play voices! ${e.message}',FlxColor.RED);
}
Expand All @@ -793,6 +808,14 @@ class MultiMenuState extends onlinemod.OfflineMenuState {
FlxG.sound.music.volume = SESave.data.instVol * FlxG.sound.volume;

FlxG.sound.music.play();
FlxG.sound.music.onComplete = function(){
Conductor.songPosition=0;
if(this != null && voices != null){

voices.time = 0;
voices.play();
}
}
}


Expand Down
8 changes: 4 additions & 4 deletions source/se/SESave.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ typedef YourMother = Dynamic;
var songPosition:Bool = true;
var fps:Bool = false;
var flashing:Bool = true;
@:isVar var playStateObjectLocations(get,set):Dynamic = null;
function get_playStateObjectLocations() return null;
function set_playStateObjectLocations(v) return playStateObjectLocations = null;
// @:isVar var playStateObjectLocations(get,set):Dynamic = null;
// function get_playStateObjectLocations() return null;
// function set_playStateObjectLocations(v) return playStateObjectLocations = null;
var flashingLights(get,set):Bool;
@:keep inline function get_flashingLights() return flashing;
@:keep inline function set_flashingLights(v) return flashing = v;
Expand Down Expand Up @@ -102,7 +102,7 @@ typedef YourMother = Dynamic;
var debounce:Bool = false;
var legacyCharter:Bool = false;
var savedServers:Array<Array<Dynamic>> = [];
var favourites(get,default):Array<se.formats.SongInfo> = [];
var favourites(get,default):Array<Dynamic> = [];
function get_favourites() {
if(favourites == null){favourites = [];}
return favourites;
Expand Down
Loading

0 comments on commit bded101

Please sign in to comment.