Skip to content

Commit

Permalink
Updating SUtil and renaming it into StorageUtil
Browse files Browse the repository at this point in the history
- SUtill ==> StorageUtil
  • Loading branch information
Stefan2008Git committed Aug 26, 2024
1 parent 157beb1 commit eeec887
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 63 deletions.
8 changes: 4 additions & 4 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import states.TitleState;
#if android
import android.Hardware;
import android.backend.AndroidDialogsExtend;
import android.backend.SUtil;
import android.backend.StorageUtil;
#end

#if linux
Expand Down Expand Up @@ -51,7 +51,7 @@ class Main extends Sprite
{
super();

#if android SUtil.doTheCheck(); #end
#if android StorageUtil.doTheCheck(); #end

#if windows
@:functionCode("
Expand Down Expand Up @@ -171,7 +171,7 @@ class Main extends Sprite
dateNow = dateNow.replace(" ", "_");
dateNow = dateNow.replace(":", "'");

path = SUtil.getPath() + "./crash/" + "SB Engine_" + dateNow + ".log";
path = StorageUtil.getPath() + "./crash/" + "SB Engine_" + dateNow + ".log";

for (stackItem in callStack)
{
Expand All @@ -187,7 +187,7 @@ class Main extends Sprite
errorMessage += e.error + "\nPlease report this error to the GitHub page: https://github.com/Stefan2008Git/FNF-SB-Engine\n\n> Crash Handler written by: sqirra-rng";
extraErrorMessage += e.error + "\n\n=====================\nSBinator Crash Report\n=====================\n\nGenerated by: Friday Night Funkin' SB Engine - " + MainMenuState.sbEngineVersion + " (" + MainMenuState.psychEngineVersion + ")" + "\nSystem timestamp: " + Date.now().toString() + "\nDriver info: " + Main.fpsVar.getGLInfo(RENDERER) + "\n" + Main.fpsVar.os + "\nRender method: " + FlxG.renderMethod + "\n\n=====================\n";

if (!FileSystem.exists(SUtil.getPath() + "crash/")) FileSystem.createDirectory(SUtil.getPath() + "crash/");
if (!FileSystem.exists(StorageUtil.getPath() + "crash/")) FileSystem.createDirectory(StorageUtil.getPath() + "crash/");
File.saveContent(path, extraErrorMessage + "\n");

Sys.println("Crash dump saved in " + Path.normalize(path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import openfl.utils.Assets as OpenFlAssets;

using StringTools;

class SUtil
class StorageUtil
{
#if android
private static var aDir:String = null; // android dir
Expand Down Expand Up @@ -50,10 +50,10 @@ class SUtil

if (Permissions.getGrantedPermissions().contains(PermissionsList.READ_EXTERNAL_STORAGE) || Permissions.getGrantedPermissions().contains(PermissionsList.WRITE_EXTERNAL_STORAGE))
{
if (!FileSystem.exists(Tools.getExternalStorageDirectory() + '/' + '.SB Engine')) FileSystem.createDirectory(Tools.getExternalStorageDirecotry() + '/' + '.SB Engine');
if (!FileSystem.exists(Tools.getExternalStorageDirectory() + '/' + '.SB Engine')) FileSystem.createDirectory(Tools.getExternalStorageDirectory() + '/' + '.SB Engine');
if (ClientPrefs.data.toastText) AndroidDialogsExtend.openToastBox("Creating the root directory...", 1);

if (!FileSystem.exists(SUtil.getPath() + 'assets') && !FileSystem.exists(SUtil.getPath() + 'mods'))
if (!FileSystem.exists(StorageUtil.getPath() + 'assets') && !FileSystem.exists(StorageUtil.getPath() + 'mods'))
{
applicationAlert('Uncaught Error!', "Whoops, seems you didn't extract the 2 folders from the .APK!\nPlease watch the tutorial by pressing OK.");
if (ClientPrefs.data.toastText) AndroidDialogsExtend.openToastBox("Missing the assets and mods folder in root directory!", 1);
Expand All @@ -62,15 +62,15 @@ class SUtil
}
else
{
if (!FileSystem.exists(SUtil.getPath() + 'assets'))
if (!FileSystem.exists(StorageUtil.getPath() + 'assets'))
{
applicationAlert('Uncaught Error!', "Whoops, seems you are missing the assets folder from the .APK to the root directory!\nPlease watch the tutorial by pressing OK.");
if (ClientPrefs.data.toastText) AndroidDialogsExtend.openToastBox("Missing the assets folder in root directory!", 1);
CoolUtil.browserLoad('https://www.youtube.com/watch?v=Cm1JE_uBbYk');
openfl.system.System.exit(1);
}

if (!FileSystem.exists(SUtil.getPath() + 'mods'))
if (!FileSystem.exists(StorageUtil.getPath() + 'mods'))
{
applicationAlert('Uncaught Error!', "Whoops, seems you are missing the mods folder from the .APK to the root directory!\nPlease watch the tutorial by pressing OK.");
if (ClientPrefs.data.toastText) AndroidDialogsExtend.openToastBox("Missing the mods folder in root directory!", 1);
Expand All @@ -83,8 +83,8 @@ class SUtil

public static function saveContent(fileName:String = 'file', fileExtension:String = '.json', fileData:String = 'You forgot something to add in your code')
{
if (!FileSystem.exists(SUtil.getPath() + 'saves')) FileSystem.createDirectory(SUtil.getPath() + 'saves');
File.saveContent(SUtil.getPath() + 'saves/' + fileName + fileExtension, fileData);
if (!FileSystem.exists(StorageUtil.getPath() + 'saves')) FileSystem.createDirectory(StorageUtil.getPath() + 'saves');
File.saveContent(StorageUtil.getPath() + 'saves/' + fileName + fileExtension, fileData);
if (ClientPrefs.data.toastText) AndroidDialogsExtend.openToastBox("Done! File Saved Successfully!", 1);
}

Expand Down
2 changes: 1 addition & 1 deletion source/backend/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CoolUtil
#if (sys && MODS_ALLOWED)
var formatted:Array<String> = path.split(':'); //prevent "shared:", "preload:" and other library names on file path
if (android)
path = SUtil.getPath() + formatted[formatted.length-1];
path = StorageUtil.getPath() + formatted[formatted.length-1];
else
path = formatted[formatted.length-1];

Expand Down
6 changes: 3 additions & 3 deletions source/backend/Mods.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import lime.utils.Assets;
#end

import tjson.TJSON as Json;
import android.backend.SUtil;
import android.backend.StorageUtil;

typedef ModsList = {
enabled:Array<String>,
Expand Down Expand Up @@ -88,7 +88,7 @@ class Mods

for (file in paths)
{
var list:Array<String> = CoolUtil.coolTextFile(SUtil.getPath() + file);
var list:Array<String> = CoolUtil.coolTextFile(StorageUtil.getPath() + file);
for (value in list)
if((allowDuplicates || !mergedList.contains(value)) && value.length > 0)
mergedList.push(value);
Expand Down Expand Up @@ -218,7 +218,7 @@ class Mods
fileStr += values[0] + '|' + (values[1] ? '1' : '0');
}

File.saveContent(SUtil.getPath() + 'modsList.txt', fileStr);
File.saveContent(StorageUtil.getPath() + 'modsList.txt', fileStr);
updatedOnState = true;
//TraceText.makeTheTraceText('Saved modsList.txt');
#end
Expand Down
26 changes: 13 additions & 13 deletions source/backend/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Paths

inline public static function getSharedPath(file:String = '')
{
return SUtil.getPath() + 'assets/shared/$file';
return StorageUtil.getPath() + 'assets/shared/$file';
}

inline static function getLibraryPathForce(file:String, library:String, ?level:String)
Expand Down Expand Up @@ -154,7 +154,7 @@ class Paths
var file:String = modsVideo(key);
if(FileSystem.exists(file)) return file;
#end
return SUtil.getPath() + 'assets/videos/$key.$VIDEO_EXT';
return StorageUtil.getPath() + 'assets/videos/$key.$VIDEO_EXT';
}

static public function sound(key:String, ?library:String):Sound
Expand Down Expand Up @@ -245,19 +245,19 @@ class Paths
if (!ignoreMods && FileSystem.exists(modFolders(key)))
return File.getContent(modFolders(key));

if (FileSystem.exists(SUtil.getPath() + getPreloadPath(key)))
return File.getContent(SUtil.getPath() + getPreloadPath(key));
if (FileSystem.exists(StorageUtil.getPath() + getPreloadPath(key)))
return File.getContent(StorageUtil.getPath() + getPreloadPath(key));

if (currentLevel != null)
{
var levelPath:String = '';
if(currentLevel != 'shared') {
levelPath = SUtil.getPath() + getLibraryPathForce(key, 'week_assets', currentLevel);
levelPath = StorageUtil.getPath() + getLibraryPathForce(key, 'week_assets', currentLevel);
if (FileSystem.exists(levelPath))
return File.getContent(levelPath);
}

levelPath = SUtil.getPath() + getLibraryPathForce(key, 'shared');
levelPath = StorageUtil.getPath() + getLibraryPathForce(key, 'shared');
if (FileSystem.exists(levelPath))
return File.getContent(levelPath);
}
Expand All @@ -275,7 +275,7 @@ class Paths
return file;
}
#end
return SUtil.getPath() + 'assets/fonts/$key';
return StorageUtil.getPath() + 'assets/fonts/$key';
}

public static function fileExists(key:String, type:AssetType, ?ignoreMods:Bool = false, ?library:String = null)
Expand All @@ -290,7 +290,7 @@ class Paths
if (FileSystem.exists(mods(Mods.currentModDirectory + '/' + key)) || FileSystem.exists(mods(key)))
return true;

if (FileSystem.exists(SUtil.getPath() + 'assets/shared/' + key) || FileSystem.exists(SUtil.getPath() + 'assets/' + key))
if (FileSystem.exists(StorageUtil.getPath() + 'assets/shared/' + key) || FileSystem.exists(StorageUtil.getPath() + 'assets/' + key))
return true;
}
#end
Expand Down Expand Up @@ -406,7 +406,7 @@ class Paths

#if MODS_ALLOWED
inline static public function mods(key:String = '')
return SUtil.getPath() + 'mods/' + key;
return StorageUtil.getPath() + 'mods/' + key;

inline static public function modsFont(key:String)
return modFolders('fonts/' + key);
Expand Down Expand Up @@ -444,18 +444,18 @@ class Paths
return fileToCheck;

}
var fileToCheck:String = SUtil.getPath() + 'mods/' + key;
var fileToCheck:String = StorageUtil.getPath() + 'mods/' + key;
if(FileSystem.exists(fileToCheck))
return fileToCheck;

var fileToCheck:String = SUtil.getPath() + 'assets/' + key;
var fileToCheck:String = StorageUtil.getPath() + 'assets/' + key;
if(FileSystem.exists(fileToCheck))
return fileToCheck;

var fileToCheck:String = SUtil.getPath() + 'assets/shared/' + key;
var fileToCheck:String = StorageUtil.getPath() + 'assets/shared/' + key;
if(FileSystem.exists(fileToCheck))
return fileToCheck;
return SUtil.getPath() + 'mods/' + key;
return StorageUtil.getPath() + 'mods/' + key;
}
#end

Expand Down
2 changes: 1 addition & 1 deletion source/backend/StageData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class StageData {

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

#if MODS_ALLOWED
var modPath:String = Paths.modFolders('stages/' + stage + '.json');
Expand Down
6 changes: 3 additions & 3 deletions source/backend/WeekData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sys.io.File;
import sys.FileSystem;
#end

import android.backend.SUtil;
import android.backend.StorageUtil;
import tjson.TJSON as Json;

typedef WeekFile =
Expand Down Expand Up @@ -87,13 +87,13 @@ class WeekData {
weeksList = [];
weeksLoaded.clear();
#if MODS_ALLOWED
var directories:Array<String> = [Paths.mods(), SUtil.getPath() + Paths.getPreloadPath()];
var directories:Array<String> = [Paths.mods(), StorageUtil.getPath() + Paths.getPreloadPath()];
var originalLength:Int = directories.length;

for (mod in Mods.parseList().enabled)
directories.push(Paths.mods(mod + '/'));
#else
var directories:Array<String> = [SUtil.getPath() + Paths.getPreloadPath()];
var directories:Array<String> = [StorageUtil.getPath() + Paths.getPreloadPath()];
var originalLength:Int = directories.length;
#end

Expand Down
6 changes: 3 additions & 3 deletions source/cutscenes/DialogueCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sys.FileSystem;
import sys.io.File;
#end

import android.backend.SUtil;
import android.backend.StorageUtil;

typedef DialogueCharacterFile = {
var image:String;
Expand Down Expand Up @@ -64,10 +64,10 @@ class DialogueCharacter extends FlxSprite
#if MODS_ALLOWED
var path:String = Paths.modFolders(characterPath);
if (!FileSystem.exists(path))
path = SUtil.getPath() + Paths.getPreloadPath(characterPath);
path = StorageUtil.getPath() + Paths.getPreloadPath(characterPath);

if(!FileSystem.exists(path))
path = SUtil.getPath() + Paths.getPreloadPath('images/dialogue/' + DEFAULT_CHARACTER + '.json');
path = StorageUtil.getPath() + Paths.getPreloadPath('images/dialogue/' + DEFAULT_CHARACTER + '.json');

rawJson = File.getContent(path);

Expand Down
2 changes: 1 addition & 1 deletion source/import.hx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ import sys.io.Process;
#end

// Friday Night Funkin': SB Engine stuff (Im talking about states, substates, backend, etc.)
import android.backend.SUtil;
import android.backend.StorageUtil;
import backend.animation.PsychAnimationController;
import backend.BaseStage;
import backend.ClientPrefs;
Expand Down
6 changes: 3 additions & 3 deletions source/objects/MenuCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sys.FileSystem;
#end
import openfl.utils.Assets;
import tjson.TJSON as Json;
import android.backend.SUtil;
import android.backend.StorageUtil;

typedef MenuCharacterFile = {
var image:String;
Expand Down Expand Up @@ -54,11 +54,11 @@ class MenuCharacter extends FlxSprite
#if MODS_ALLOWED
var path:String = Paths.modFolders(characterPath);
if (!FileSystem.exists(path)) {
path = SUtil.getPath() + Paths.getPreloadPath(characterPath);
path = StorageUtil.getPath() + Paths.getPreloadPath(characterPath);
}

if(!FileSystem.exists(path)) {
path = SUtil.getPath() + Paths.getPreloadPath('images/menucharacters/' + DEFAULT_CHARACTER + '.json');
path = StorageUtil.getPath() + Paths.getPreloadPath('images/menucharacters/' + DEFAULT_CHARACTER + '.json');
}
rawJson = File.getContent(path);

Expand Down
2 changes: 1 addition & 1 deletion source/objects/NoteSplash.hx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class NoteSplash extends FlxSprite
if(configs.exists(skin)) return configs.get(skin);

var path:String = Paths.getPath('images/$skin.txt', TEXT, true);
if (!FileSystem.exists(path)) path = SUtil.getPath() + 'assets/shared/images/noteSplashes/noteSplashes.txt'; // use default text
if (!FileSystem.exists(path)) path = StorageUtil.getPath() + 'assets/shared/images/noteSplashes/noteSplashes.txt'; // use default text
var configFile:Array<String> = CoolUtil.coolTextFile(path, false);
if(configFile.length < 1) return null;

Expand Down
4 changes: 2 additions & 2 deletions source/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ class FunkinLua {
path = Paths.modsJson(Paths.formatToSongPath(PlayState.SONG.song) + '/' + dialogueFile);
if(!FileSystem.exists(path))
#end
path = SUtil.getPath() + Paths.json(Paths.formatToSongPath(PlayState.SONG.song) + '/' + dialogueFile);
path = StorageUtil.getPath() + Paths.json(Paths.formatToSongPath(PlayState.SONG.song) + '/' + dialogueFile);

luaTrace('startDialogue: Trying to load dialogue: ' + path);

Expand Down Expand Up @@ -1553,7 +1553,7 @@ class FunkinLua {
function findScript(scriptFile:String, ext:String = '.lua')
{
if(!scriptFile.endsWith(ext)) scriptFile += ext;
var preloadPath:String = SUtil.getPath() + Paths.getPreloadPath(scriptFile);
var preloadPath:String = StorageUtil.getPath() + Paths.getPreloadPath(scriptFile);
#if MODS_ALLOWED
var path:String = Paths.modFolders(scriptFile);
if(FileSystem.exists(scriptFile))
Expand Down
2 changes: 1 addition & 1 deletion source/states/ModsMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class ModsMenuState extends MusicBeatState
fileStr += values[0] + '|' + (values[1] ? '1' : '0');
}

var path:String = SUtil.getPath() + 'modsList.txt';
var path:String = StorageUtil.getPath() + 'modsList.txt';
File.saveContent(path, fileStr);
Mods.pushGlobalMods();
}
Expand Down
4 changes: 2 additions & 2 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4441,11 +4441,11 @@ class PlayState extends MusicBeatState
#if MODS_ALLOWED
var scriptToLoad:String = Paths.modFolders(scriptFile);
if(!FileSystem.exists(scriptToLoad))
scriptToLoad = Paths.getPreloadPath(SUtil.getPath() + scriptFile);
scriptToLoad = Paths.getPreloadPath(StorageUtil.getPath() + scriptFile);

if(FileSystem.exists(scriptToLoad))
#elseif sys
var scriptToLoad:String = Paths.getPreloadPath(SUtil.getPath() + scriptFile);
var scriptToLoad:String = Paths.getPreloadPath(StorageUtil.getPath() + scriptFile);
if(OpenFlAssets.exists(scriptToLoad))
#end
{
Expand Down
2 changes: 1 addition & 1 deletion source/states/SBinatorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SBinatorState extends MusicBeatState

function changeText() {
var selectedText:String = '';
var textArray:Array<String> = CoolUtil.coolTextFile(SUtil.getPath() + Paths.txt('loadingTips'));
var textArray:Array<String> = CoolUtil.coolTextFile(StorageUtil.getPath() + Paths.txt('loadingTips'));

randomText.alpha = 1;
tweening = true;
Expand Down
4 changes: 2 additions & 2 deletions source/states/editors/CharacterEditorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ class CharacterEditorState extends MusicBeatState

#if MODS_ALLOWED
characterList = [];
var directories:Array<String> = [Paths.mods('characters/'), Paths.mods(Mods.currentModDirectory + '/characters/'), SUtil.getPath() + Paths.getPreloadPath('characters/')];
var directories:Array<String> = [Paths.mods('characters/'), Paths.mods(Mods.currentModDirectory + '/characters/'), StorageUtil.getPath() + Paths.getPreloadPath('characters/')];
for(mod in Mods.getGlobalMods())
directories.push(Paths.mods(mod + '/characters/'));
for (i in 0...directories.length) {
Expand Down Expand Up @@ -1316,7 +1316,7 @@ class CharacterEditorState extends MusicBeatState
if (data.length > 0)
{
#if android
SUtil.saveContent('$_char', '.json', data);
StorageUtil.saveContent('$_char', '.json', data);
#else
_file = new FileReference();
_file.addEventListener(Event.COMPLETE, onSaveComplete);
Expand Down
Loading

0 comments on commit eeec887

Please sign in to comment.