Skip to content

Commit

Permalink
simple getText thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
Joalor64GH authored Nov 22, 2024
1 parent 6b73877 commit ad2fde6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/Creating-a-Mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Each folder in your mod should be used as follows:
* `songs` - Songs used for gameplay.
* `songs/[song-name]/chart.json` - Your song's chart.
* `songs/[song-name]/music.ogg` - Your song's music. Can also be a `.wav`.
* `songs/[song-name]/[script-name].hxs` - Song-specific script (optional).
* `songs/[song-name]/[script-name].hxs` - Song-specific script(s).
* `sounds` - All sound effects.

Also, when it's neccessary, delete any folders you don't need.
Expand Down
18 changes: 5 additions & 13 deletions source/backend/Localization.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Localization {
data = new Map<String, Dynamic>();

var path:String = Paths.txt("languages/languagesList");
if (FileSystem.exists(path)) {
var listContent:String = File.getContent(path);
if (Paths.exists(path)) {
var listContent:String = Paths.getText(path);
var languages:Array<String> = listContent.split('\n');

for (language in languages) {
Expand All @@ -47,18 +47,10 @@ class Localization {
var jsonContent:String;

try {
#if sys
jsonContent = File.getContent(path(language));
#else
jsonContent = Assets.getText(path(language));
#end
} catch (e) {
jsonContent = Paths.getText(path(language));
} catch (e:Dynamic) {
trace('file not found: $e');
#if sys
jsonContent = File.getContent(path(DEFAULT_LANGUAGE));
#else
jsonContent = Assets.getText(path(DEFAULT_LANGUAGE));
#end
jsonContent = Paths.getText(path(DEFAULT_LANGUAGE));
}

return Json.parse(jsonContent);
Expand Down
15 changes: 6 additions & 9 deletions source/backend/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Paths {
inline public static final DEFAULT_FOLDER:String = 'assets';
public static final SOUND_EXT:Array<String> = ['ogg', 'wav'];

public static final getText:String->String = #if sys File.getContent #else Assets.getText #end;

public static var currentTrackedAssets:Map<String, FlxGraphic> = [];
public static var currentTrackedSounds:Map<String, Sound> = [];
public static var localTrackedAssets:Array<String> = [];
Expand Down Expand Up @@ -130,16 +132,11 @@ class Paths {
return getPath(null, file);
}

inline public static function getText(path:String):Array<String>
inline public static function getTextArray(path:String):Array<String>
return Assets.exists(path) ? [for (i in Assets.getText(path).trim().split('\n')) i.trim()] : [];

static public function getTextFromFile(key:String):String {
#if sys
return (FileSystem.exists(file(key))) ? File.getContent(file(key)) : null;
#else
return (Assets.exists(file(key))) ? Assets.getText(file(key)) : null;
#end
}
static public function getTextFromFile(key:String):String
return (exists(file(key))) ? getText(file(key)) : null;

inline static public function txt(key:String)
return file('$key.txt');
Expand Down Expand Up @@ -238,4 +235,4 @@ class Paths {
}
}

typedef FileAssets = #if sys FileSystem; #else openfl.utils.Assets; #end
typedef FileAssets = #if sys FileSystem; #else Assets; #end
9 changes: 2 additions & 7 deletions source/backend/Song.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ typedef NoteData = {
}

class Song {
public static function loadSongfromJson(song:String):Dynamic {
#if sys
return Json.parse(File.getContent(Paths.chart(song)));
#else
return Json.parse(Assets.getText(Paths.chart(song)));
#end
}
public static function loadSongfromJson(song:String):Dynamic
return Json.parse(Paths.getText(Paths.chart(song)));
}
6 changes: 3 additions & 3 deletions source/options/LanguageState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class LanguageState extends ExtendableState {
override function create() {
super.create();

var initLangString = Paths.getText(Paths.txt('languages/languagesData'));
var initLangString = Paths.getTextArray(Paths.txt('languages/languagesData'));

if (Assets.exists(Paths.txt('languages/languagesData'))) {
initLangString = Assets.getText(Paths.txt('languages/languagesData')).trim().split('\n');
if (Paths.exists(Paths.txt('languages/languagesData'))) {
initLangString = Paths.getText(Paths.txt('languages/languagesData')).trim().split('\n');

for (i in 0...initLangString.length)
initLangString[i] = initLangString[i].trim();
Expand Down
2 changes: 1 addition & 1 deletion source/states/MenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MenuState extends ExtendableState {
var path:String = Paths.txt('menuList');
if (FileSystem.exists(path)) {
try {
var menuArray:Array<String> = Paths.getText(path);
var menuArray:Array<String> = Paths.getTextArray(path);
for (i in 0...menuArray.length)
selections = menuArray;

Expand Down
2 changes: 1 addition & 1 deletion source/substates/PauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PauseSubState extends ExtendableSubState {

function changeText() {
var selectedText:String = '';
var textArray:Array<String> = Paths.getText(Paths.txt('tipText'));
var textArray:Array<String> = Paths.getTextArray(Paths.txt('tipText'));

tipTxt.alpha = 1;
isTweening = true;
Expand Down

0 comments on commit ad2fde6

Please sign in to comment.