Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions project.hxp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Project extends HXProject
static final DISCORD_ALLOWED:CompileFlag = CompileFlag.get("DISCORD_ALLOWED");
static final MODCHARTS_ALLOWED:CompileFlag = CompileFlag.get("MODCHARTS_ALLOWED");
static final DCEBUILD:CompileFlag = CompileFlag.get("DCEBUILD");
static final USE_OPENFL_FILESYSTEM:CompileFlag = CompileFlag.get("USE_OPENFL_FILESYSTEM");

static final ENABLE_ASCII_ART:Bool = true;

Expand Down Expand Up @@ -213,6 +214,7 @@ class Project extends HXProject
DISCORD_ALLOWED.integrate((isDesktop() && !isHashLink()));
MODCHARTS_ALLOWED.integrate(/*DCEBUILD.isDisabled()*/false);
DCEBUILD.integrate(false);
USE_OPENFL_FILESYSTEM.integrate(MODS_ALLOWED.isDisabled()/*|| isMobile()*/);

setHaxedef("FLX_NO_FOCUS_LOST_SCREEN");
if (!isDebug())
Expand Down
6 changes: 6 additions & 0 deletions source/engine/backend/io/File.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class File
return path;
}

#if USE_OPENFL_FILESYSTEM
static function openflcwd(path:String):String
{
@:privateAccess
Expand All @@ -33,6 +34,7 @@ class File

return path;
}
#end

public static function getContent(path:String):Null<String>
{
Expand All @@ -50,8 +52,10 @@ class File
#end
#end

#if USE_OPENFL_FILESYSTEM
if (Assets.exists(openflcwd(path)))
return Assets.getText(openflcwd(path));
#end

return null;
}
Expand All @@ -72,6 +76,7 @@ class File
#end
#end

#if USE_OPENFL_FILESYSTEM
if (Assets.exists(openflcwd(path)))
switch (haxe.io.Path.extension(path).toLowerCase())
{
Expand All @@ -80,6 +85,7 @@ class File
default:
return Assets.getBytes(openflcwd(path));
}
#end

return null;
}
Expand Down
75 changes: 47 additions & 28 deletions source/engine/backend/io/FileSystem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FileSystem
return path;
}

#if USE_OPENFL_FILESYSTEM
static function openflcwd(path:String):String
{
@:privateAccess
Expand All @@ -32,6 +33,7 @@ class FileSystem

return path;
}
#end

public static function exists(path:String):Bool
{
Expand All @@ -49,10 +51,12 @@ class FileSystem
#end
#end

if (Assets.exists(openflcwd(path)))
#if USE_OPENFL_FILESYSTEM
if (Assets.exists(openflcwd(path)) || Assets.list().filter(asset -> asset.startsWith(path) && asset != path).length > 0)
return true;
#end

return Assets.list().filter(asset -> asset.startsWith(path) && asset != path).length > 0;
return false;
}

public static function rename(path:String, newPath:String):Void
Expand Down Expand Up @@ -139,7 +143,12 @@ class FileSystem
#end
#end

return Assets.list().filter(asset -> asset.startsWith(path) && asset != path).length > 0;
#if USE_OPENFL_FILESYSTEM
if (Assets.list().filter(asset -> asset.startsWith(path) && asset != path).length > 0)
return true;
#end

return false;
}

public static function createDirectory(path:String):Void
Expand Down Expand Up @@ -186,44 +195,54 @@ class FileSystem

public static function readDirectory(path:String):Array<String>
{
var result:Array<String> = null;

#if MODS_ALLOWED
#if linux
var actualPath:String = cwd(path);
actualPath = getCaseInsensitivePath(path);
if (actualPath == null)
actualPath = path;
var actualPath = cwd(path);
actualPath = getCaseInsensitivePath(path) ?? path;
if (SysFileSystem.exists(actualPath) && SysFileSystem.isDirectory(actualPath))
return SysFileSystem.readDirectory(actualPath);
result = SysFileSystem.readDirectory(actualPath);
#else
if (SysFileSystem.exists(cwd(path)) && SysFileSystem.isDirectory(cwd(path)))
return SysFileSystem.readDirectory(cwd(path) );
result = SysFileSystem.readDirectory(cwd(path));
#end
#end

var filteredList:Array<String> = Assets.list().filter(f -> f.startsWith(path));
var results:Array<String> = [];
for (i in filteredList.copy())
#if USE_OPENFL_FILESYSTEM
if (result == null)
{
var slashsCount:Int = path.split('/').length;
if (path.endsWith('/'))
slashsCount -= 1;
var filteredList = Assets.list().filter(f -> f.startsWith(path));
var results:Array<String> = [];

if (i.split('/').length - 1 != slashsCount)
filteredList.remove(i);
}
for (item in filteredList)
{
@:privateAccess
for (library in lime.utils.Assets.libraries.keys())
for (i in filteredList.copy())
{
var slashsCount = path.split('/').length;
if (path.endsWith('/'))
slashsCount--;

if (i.split('/').length - 1 != slashsCount)
filteredList.remove(i);
}

for (item in filteredList)
{
var libPath:String = '$library:$item';
if (library != 'default' && Assets.exists(libPath) && !results.contains(libPath))
results.push(libPath);
else if (Assets.exists(item) && !results.contains(item))
results.push(item);
@:privateAccess
for (library in lime.utils.Assets.libraries.keys())
{
var libPath = '$library:$item';
if (library != 'default' && Assets.exists(libPath) && !results.contains(libPath))
results.push(libPath);
else if (Assets.exists(item) && !results.contains(item))
results.push(item);
}
}

result = results.map(f -> f.substr(f.lastIndexOf("/") + 1));
}
return results.map(f -> f.substr(f.lastIndexOf("/") + 1));
#end

return result ?? [];
}

#if (linux && MODS_ALLOWED)
Expand Down
9 changes: 9 additions & 0 deletions source/engine/mobile/backend/io/Assets.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mobile.backend.io;

#if android
typedef Assets = mobile.backend.io.android.Assets;
// #elseif ios
// typedef Assets = mobile.backend.io.ios.Assets;
#else
typedef Assets = Dynamic;
#end
Loading