Skip to content

Commit

Permalink
Revert "Base folder asset scanning (because no mod support breaks fre…
Browse files Browse the repository at this point in the history
…eplay) (…"

This reverts commit b790fb7.
  • Loading branch information
NexIsDumb authored May 31, 2024
1 parent b790fb7 commit 2f9774b
Showing 1 changed file with 53 additions and 142 deletions.
195 changes: 53 additions & 142 deletions source/funkin/backend/assets/AssetsLibraryList.hx
Original file line number Diff line number Diff line change
@@ -1,55 +1,40 @@
package funkin.backend.assets;

import sys.FileSystem;
import funkin.backend.assets.IModsAssetLibrary;
import lime.utils.AssetLibrary;

using StringTools;

class AssetsLibraryList extends AssetLibrary
{
class AssetsLibraryList extends AssetLibrary {
public var libraries:Array<AssetLibrary> = [];

@:allow(funkin.backend.system.Main)
@:allow(funkin.backend.system.MainState)
private var __defaultLibraries:Array<AssetLibrary> = [];

public var base:AssetLibrary;

public function removeLibrary(lib:AssetLibrary)
{
if (lib == null)
return lib;
public function removeLibrary(lib:AssetLibrary) {
if (lib == null) return lib;
libraries.remove(lib);
return lib;
}

public function existsSpecific(id:String, type:String, source:AssetSource = BOTH)
{
public function existsSpecific(id:String, type:String, source:AssetSource = BOTH) {
if (!id.startsWith("assets/") && exists('assets/$id', type))
return true;
for (k => e in libraries)
{
if (shouldSkipLib(k, source))
continue;
for(k=>e in libraries) {
if (shouldSkipLib(k, source)) continue;
if (e.exists(id, type))
return true;
}
return false;
}

public override inline function exists(id:String, type:String):Bool
return existsSpecific(id, type, BOTH);

public function getSpecificPath(id:String, source:AssetSource = BOTH)
{
for (k => e in libraries)
{
if (shouldSkipLib(k, source))
continue;
public function getSpecificPath(id:String, source:AssetSource = BOTH) {
for(k=>e in libraries) {
if (shouldSkipLib(k, source)) continue;

@:privateAccess
if (e.exists(id, e.types.get(id)))
{
if (e.exists(id, e.types.get(id))) {
var path = e.getPath(id);
if (path != null)
return path;
Expand All @@ -61,200 +46,126 @@ class AssetsLibraryList extends AssetLibrary
public override inline function getPath(id:String)
return getSpecificPath(id, BOTH);

public function getFiles(folder:String, source:AssetSource = BOTH):Array<String>
{
public function getFiles(folder:String, source:AssetSource = BOTH):Array<String> {
var content:Array<String> = [];
for (k => e in libraries)
{
if (shouldSkipLib(k, source))
continue;
for(k=>e in libraries) {
if (shouldSkipLib(k, source)) continue;

var l = e;

if (l is openfl.utils.AssetLibrary)
{
if (l is openfl.utils.AssetLibrary) {
@:privateAccess
l = cast(l, openfl.utils.AssetLibrary).__proxy;
}

// TODO: do base folder scanning
#if MOD_SUPPORT
if (source == MODS || source == BOTH)
{
if (l is IModsAssetLibrary)
{
var lib = cast(l, IModsAssetLibrary);
for (e in lib.getFiles(folder))
content.push(e);
}
if (l is IModsAssetLibrary) {
var lib = cast(l, IModsAssetLibrary);
for(e in lib.getFiles(folder))
content.push(e);
}
#else
#if sys
if (source == SOURCE || source == BOTH)
{
var fileStuffs = FileSystem.readDirectory(folder);
if (fileStuffs != null && fileStuffs.length > 0)
{
for (e in fileStuffs)
{
if (!FileSystem.isDirectory(folder + e.toString()))
{
content.push(e);
}
}
}
else
{
Logs.trace('No files/folders found in the requested directory \'${folder}\'', WARNING, YELLOW);
}
}
#end
#end
}
return content;
}

public function getFolders(folder:String, source:AssetSource = BOTH):Array<String>
{
public function getFolders(folder:String, source:AssetSource = BOTH):Array<String> {
var content:Array<String> = [];
for (k => e in libraries)
{
if (shouldSkipLib(k, source))
continue;
for(k=>e in libraries) {
if (shouldSkipLib(k, source)) continue;

var l = e;

if (l is openfl.utils.AssetLibrary)
{
if (l is openfl.utils.AssetLibrary) {
@:privateAccess
l = cast(l, openfl.utils.AssetLibrary).__proxy;
}

// TODO: do base folder scanning
#if MOD_SUPPORT
if (source == MODS || source == BOTH)
{
if (l is IModsAssetLibrary)
{
var lib = cast(l, IModsAssetLibrary);
for (e in lib.getFolders(folder))
content.push(e);
}
}
#else
#if sys
if (source == SOURCE || source == BOTH)
{
var fileStuffs = FileSystem.readDirectory(folder);
if (fileStuffs != null && fileStuffs.length > 0)
{
for (e in fileStuffs)
{
if (FileSystem.isDirectory(folder + e.toString()))
{
content.push(e);
}
}
}
else
{
Logs.trace('No files/folders found in the requested directory \'${folder}\'', WARNING, YELLOW);
}
if (l is IModsAssetLibrary) {
var lib = cast(l, IModsAssetLibrary);
for(e in lib.getFolders(folder))
content.push(e);
}
#end
#end
}
return content;
}

public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH):Dynamic
{
try
{
if (!id.startsWith("assets/"))
{
public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH):Dynamic {
try {
if (!id.startsWith("assets/")) {
var ass = getSpecificAsset('assets/$id', type, source);
if (ass != null)
{
if (ass != null) {
return ass;
}
}
for (k => e in libraries)
{
if (shouldSkipLib(k, source))
continue;
for(k=>e in libraries) {
if (shouldSkipLib(k, source)) continue;

@:privateAccess
if (e.exists(id, e.types.get(id)))
{
if (e.exists(id, e.types.get(id))) {
var asset = e.getAsset(id, type);
if (asset != null)
{
if (asset != null) {
return asset;
}
}
}
return null;
}
catch (e)
{
} catch(e) {
throw e;
}
return null;
}

private function shouldSkipLib(k:Int, source:AssetSource)
{
return switch (source)
{
case BOTH: false;
case SOURCE: k < libraries.length - __defaultLibraries.length;
case MODS: k >= libraries.length - __defaultLibraries.length;
private function shouldSkipLib(k:Int, source:AssetSource) {
return switch(source) {
case BOTH: false;
case SOURCE: k < libraries.length - __defaultLibraries.length;
case MODS: k >= libraries.length - __defaultLibraries.length;
};
}

public override inline function getAsset(id:String, type:String):Dynamic
return getSpecificAsset(id, type, BOTH);

public override function isLocal(id:String, type:String)
{
public override function isLocal(id:String, type:String) {
return true;
}

public function new(?base:AssetLibrary)
{
public function new(?base:AssetLibrary) {
super();
if (base == null)
base = Assets.getLibrary("default");
addLibrary(this.base = base);
__defaultLibraries.push(base);
}

public function unloadLibraries()
{
for (l in libraries)
public function unloadLibraries() {
for(l in libraries)
if (!__defaultLibraries.contains(l))
l.unload();
}

public function reset()
{
public function reset() {
unloadLibraries();

libraries = [];

// adds default libraries in again
for (d in __defaultLibraries)
for(d in __defaultLibraries)
addLibrary(d);
}

public function addLibrary(lib:AssetLibrary)
{
public function addLibrary(lib:AssetLibrary) {
libraries.insert(0, lib);
return lib;
}
}

enum abstract AssetSource(Null<Bool>) from Bool from Null<Bool> to Null<Bool>
{
enum abstract AssetSource(Null<Bool>) from Bool from Null<Bool> to Null<Bool> {
var SOURCE = true;
var MODS = false;
var BOTH = null;
}
}

0 comments on commit 2f9774b

Please sign in to comment.