Files
CodenameEngine/source/funkin/backend/assets/ModsFolderLibrary.hx
4d84e65cb5 flixel-animate implementation (#893)
* added flixel-animate to libs

* I BROKE THE OFFSETS FUCK

.

* yes it does blehtty wdym??

* Removed flxanimate entirely + Fixed transition + Fixed offsets

* Deleted caches (relaunching actions)

* frameOffset for atlases (need testing)

* useRenderTexture added to xml

* Fixed atlases for mods

* a simple redirect so old mods wont break that badly (#879)

* Update FunkinSprite.hx

* remove trace

* Fixed ghosts for atlases

* usable character editor (not entirely fixed)

* fixed zoomFactor + temp fix for atlas popping

* early structure for character editor atlas anim display

* zoomFactor for atlases

* Animate Atlas character editor previews

* FlxAnimateSettings specification

* fixed animation swapping on atlas characters

* OH YEA BABY NEW FLXANIMATE UPDATE THAT MADE CODE 50X SIMPLER **AGAIN** 💖 /pos

* Added label checkbox in Character Editor

* Fixed culling issues with FlxAnimate (fr this time)

* fixed some atlases

* HOW THE FUCK

* gf sad fix + AliasMacro (for backwards comp, manual impl for now)

* Fixed pop-ins

* Update Character.hx

* applyStageMatrix

* FlxAnimate pull request merge (empty commit)

* flixel-animate** i'm clumsy asf i meant the lib not the class name fuck

* Update libs.xml

* Merge changes from main (#892)

* repair ScriptableShader.shader = null (#877)

* optimize updateInput (#878)

* optimize updateInput

* resize optimize

* __notePerStrum optimize

* Update StrumLine.hx

* NoteGroup optimize (#881)

* NoteGroup optimize

* CoolUtil.bound faster

* makes commit with github desktop W FRAKITS

* Use fastSinCos for notes (#889)

* Update Strum.hx

* Update Strum.hx

---------

Co-authored-by: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com>
Co-authored-by: Frakits <90983918+Frakits@users.noreply.github.com>

---------

Co-authored-by: Kolze <53307233+KolzeYT@users.noreply.github.com>
Co-authored-by: HEIHUAa <112499486+HEIHUAa@users.noreply.github.com>
Co-authored-by: Frakits <90983918+Frakits@users.noreply.github.com>
2026-01-28 20:29:32 +01:00

179 lines
4.7 KiB
Haxe

package funkin.backend.assets;
import openfl.utils.AssetLibrary;
import lime.media.AudioBuffer;
import lime.graphics.Image;
import lime.text.Font;
import lime.utils.Bytes;
#if MOD_SUPPORT
import sys.FileStat;
import sys.FileSystem;
#end
using StringTools;
class ModsFolderLibrary extends AssetLibrary implements IModsAssetLibrary {
public var basePath:String;
public var modName:String;
public var libName:String;
//public var useImageCache:Bool = true;
public var prefix = 'assets/';
public function new(basePath:String, libName:String, ?modName:String) {
this.basePath = basePath;
this.libName = libName;
this.prefix = 'assets/$libName/';
this.modName = modName == null ? libName : modName;
super();
}
function toString():String {
return '(ModsFolderLibrary: $modName)';
}
#if MOD_SUPPORT
private var editedTimes:Map<String, Float> = [];
public var _parsedAsset:String = null;
public function getEditedTime(asset:String):Null<Float> {
return editedTimes[asset];
}
public override function getAudioBuffer(id:String):AudioBuffer {
if (!exists(id, "SOUND"))
return null;
var path = getAssetPath();
editedTimes[id] = FileSystem.stat(path).mtime.getTime();
var e = AudioBuffer.fromFile(path);
// LimeAssets.cache.audio.set('$libName:$id', e);
return e;
}
public override function getBytes(id:String):Bytes {
if (!exists(id, "BINARY"))
return null;
var path = getAssetPath();
editedTimes[id] = FileSystem.stat(path).mtime.getTime();
var e = Bytes.fromFile(path);
return e;
}
public override function getFont(id:String):Font {
if (!exists(id, "FONT"))
return null;
var path = getAssetPath();
editedTimes[id] = FileSystem.stat(path).mtime.getTime();
return ModsFolder.registerFont(Font.fromFile(path));
}
public override function getImage(id:String):Image {
if (!exists(id, "IMAGE"))
return null;
var path = getAssetPath();
editedTimes[id] = FileSystem.stat(path).mtime.getTime();
var e = Image.fromFile(path);
return e;
}
public override function getPath(id:String):String {
if (!__parseAsset(id)) return null;
return getAssetPath();
}
public inline function getFolders(folder:String):Array<String>
return __getFiles(folder, true);
public inline function getFiles(folder:String):Array<String>
return __getFiles(folder, false);
public function __getFiles(folder:String, folders:Bool = false) {
if (!folder.endsWith("/")) folder += "/";
if (!__parseAsset(folder)) return [];
var path = getAssetPath();
try {
var result:Array<String> = [];
for(e in FileSystem.readDirectory(path))
if (FileSystem.isDirectory('$path$e') == folders)
result.push(e);
return result;
} catch(e) {
// woops!!
}
return [];
}
public override function exists(asset:String, type:String):Bool {
if(!__parseAsset(asset)) return false;
return FileSystem.exists(getAssetPath());
}
private function getAssetPath() {
return '$basePath/$_parsedAsset';
}
private function __isCacheValid(cache:Map<String, Dynamic>, asset:String, isLocalCache:Bool = false) {
if (!editedTimes.exists(asset))
return false;
var editedTime = editedTimes[asset];
if (editedTime == null || editedTime < FileSystem.stat(getPath(asset)).mtime.getTime()) {
// destroy already existing to prevent memory leak!!!
/*var asset = cache[asset];
if (asset != null) {
switch(Type.getClass(asset)) {
case lime.graphics.Image:
trace("getting rid of image cause replaced");
cast(asset, lime.graphics.Image);
}
}*/
return false;
}
if (!isLocalCache) asset = '$libName:$asset';
return cache.exists(asset) && cache[asset] != null;
}
private function __parseAsset(asset:String):Bool {
if (!asset.startsWith(prefix)) return false;
_parsedAsset = asset.substr(prefix.length);
if(ModsFolder.useLibFile) {
var file = new haxe.io.Path(_parsedAsset);
if(file.file.startsWith("LIB_")) {
var library = file.file.substr(4);
if(library != modName) return false;
_parsedAsset = file.dir + "." + file.ext;
}
}
return true;
}
public override function list(type:String):Array<String> {
var result = [];
__listAppend(result, '');
return result;
}
function __listAppend(arr:Array<String>, folder:String) {
for(file in FileSystem.readDirectory('$basePath/$folder')) {
var fullPath = '$basePath/$folder/$file';
if (FileSystem.isDirectory(fullPath))
__listAppend(arr, '$folder$file/');
else
arr.push('$prefix$folder$file');
}
}
#end
// Backwards compat
@:noCompletion public var folderPath(get, set):String;
@:noCompletion private inline function get_folderPath():String {
return basePath;
}
@:noCompletion private inline function set_folderPath(value:String):String {
return basePath = value;
}
}