Skip to content

Commit

Permalink
Clean-up StageData
Browse files Browse the repository at this point in the history
  • Loading branch information
Raltyro authored and CharlesCatYT committed Feb 3, 2024
1 parent 38cae78 commit 53374f9
Showing 1 changed file with 14 additions and 47 deletions.
61 changes: 14 additions & 47 deletions source/backend/StageData.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package backend;

import openfl.utils.Assets;
import haxe.Json;
import backend.Song;

typedef StageFile = {
Expand All @@ -22,8 +21,7 @@ typedef StageFile = {
}

class StageData {
public static function dummy():StageFile
{
public static function dummy():StageFile {
return {
directory: "",
defaultZoom: 0.9,
Expand All @@ -45,62 +43,31 @@ class StageData {
public static var forceNextDirectory:String = null;
public static function loadDirectory(SONG:SwagSong) {
var stage:String = '';
if(SONG.stage != null) {
stage = SONG.stage;
} else if(SONG.song != null) {
switch (SONG.song.toLowerCase().replace(' ', '-'))
{
case 'spookeez' | 'south' | 'monster':
stage = 'spooky';
case 'pico' | 'blammed' | 'philly' | 'philly-nice':
stage = 'philly';
case 'milf' | 'satin-panties' | 'high':
stage = 'limo';
case 'cocoa' | 'eggnog':
stage = 'mall';
case 'winter-horrorland':
stage = 'mallEvil';
case 'senpai' | 'roses':
stage = 'school';
case 'thorns':
stage = 'schoolEvil';
case 'ugh' | 'guns' | 'stress':
stage = 'tank';
default:
stage = 'stage';
}
} else {
stage = 'stage';
}
if (SONG.stage != null) stage = SONG.stage;
else if (SONG.song != null) stage = vanillaSongStage(SONG.song.toLowerCase().replace(' ', '-'));
else stage = 'stage';

var stageFile:StageFile = getStageFile(stage);
if(stageFile == null) { //preventing crashes
forceNextDirectory = '';
} else {
forceNextDirectory = stageFile.directory;
}
if (stageFile == null) forceNextDirectory = ''; // preventing crashes
else forceNextDirectory = stageFile.directory;
}

public static function getStageFile(stage:String):StageFile {
var rawJson:String = null;
var path:String = Paths.getSharedPath('stages/' + stage + '.json');

#if sys
#if MODS_ALLOWED
var modPath:String = Paths.modFolders('stages/' + stage + '.json');
if(FileSystem.exists(modPath)) {
rawJson = File.getContent(modPath);
} else if(FileSystem.exists(path)) {
rawJson = File.getContent(path);
}
#else
if(Assets.exists(path)) {
rawJson = Assets.getText(path);
}
if (FileSystem.exists(modPath)) rawJson = File.getContent(modPath);
else
#end
if (FileSystem.exists(path)) rawJson = File.getContent(path);
else
{
return null;
}
#end
if (Assets.exists(path)) rawJson = Assets.getText(path);
else return null;

return cast tjson.TJSON.parse(rawJson);
}

Expand Down

0 comments on commit 53374f9

Please sign in to comment.