make it compile on html5
Windows Builds / Windows Build (push) Has been cancelled
Windows Builds / Windows Debug Build (push) Has been cancelled
Mac OS Builds / Mac OS Build (push) Has been cancelled
Mac OS Builds / Mac OS Debug Build (push) Has been cancelled
Linux Builds / Linux Build (push) Has been cancelled
Linux Builds / Linux Debug Build (push) Has been cancelled

This commit is contained in:
2026-07-19 15:58:56 +02:00
parent 9207e46105
commit a93a74aede
13 changed files with 102 additions and 8 deletions
@@ -8,7 +8,9 @@ import lime.media.AudioBuffer;
import lime.text.Font;
import lime.utils.Bytes;
import openfl.utils.AssetLibrary;
#if sys
import sys.io.File;
#end
#if MOD_SUPPORT
import funkin.backend.utils.SysZip.SysZipEntry;
+4
View File
@@ -21,8 +21,10 @@ import openfl.Lib;
import openfl.display.Sprite;
import openfl.text.TextFormat;
import openfl.utils.AssetLibrary;
#if sys
import sys.FileSystem;
import sys.io.File;
#end
#if android
import android.content.Context;
import android.os.Build;
@@ -59,7 +61,9 @@ class Main extends Sprite
public static function preInit() {
funkin.backend.utils.NativeAPI.registerAsDPICompatible();
#if sys
funkin.backend.system.CommandLineHandler.parseCommandLine(Sys.args());
#end
funkin.backend.system.Main.fixWorkingDirectory();
}
@@ -157,13 +157,16 @@ class MainState extends FlxState {
CoolUtil.safeAddAttributes('./.temp/', NativeAPI.FileAttribute.HIDDEN);
#end
#if MOD_SUPPORT
for (lib in ModsFolder.getLoadedModsLibs()) {
if (!(lib is ZipFolderLibrary)) continue;
if (cast(lib, ZipFolderLibrary).PRELOAD_VIDEOS) cast(lib, ZipFolderLibrary).precacheVideos();
}
#end
var startState:Class<FlxState> = Flags.DISABLE_WARNING_SCREEN ? TitleState : funkin.menus.WarningState;
#if MOD_SUPPORT
// In this case if the mod we just loaded a compressed modpack, we can't edit or modify files without decompressing it.
if (Options.devMode && Options.allowConfigWarning && !isZipMod) {
var lib:ModsFolderLibrary;
@@ -176,6 +179,7 @@ class MainState extends FlxState {
return;
}
}
#end
FlxG.switchState(cast Type.createInstance(startState, []));
}
+21 -1
View File
@@ -2,7 +2,9 @@ package funkin.backend.utils;
import flixel.sound.FlxSound;
import lime.media.AudioBuffer;
#if !js
import lime.utils.ArrayBufferView.ArrayBufferIO;
#end
import lime.utils.ArrayBuffer;
#if (lime_cffi && lime_vorbis)
@@ -30,6 +32,7 @@ final class AudioAnalyzer {
* @param wordSize How many bytes to get with to one byte (Usually it's bitsPerSample / 8 or bitsPerSample >> 3).
* @return Byte from the audio buffer with specified position.
*/
#if sys
public static function getByte(buffer:ArrayBuffer, position:Int, wordSize:Int):Int {
if (wordSize == 2) return inline ArrayBufferIO.getInt16(buffer, position);
else if (wordSize == 3) {
@@ -40,6 +43,19 @@ final class AudioAnalyzer {
else if (wordSize == 4) return inline ArrayBufferIO.getInt32(buffer, position);
else return inline ArrayBufferIO.getUint8(buffer, position) - 128;
}
#elseif js
public static function getByte(buffer:lime.utils.UInt8Array, position:Int, wordSize:Int):Int {
var view = new lime.utils.DataView(buffer.buffer);
if (wordSize == 2) return inline view.getInt16(position, true);
else if (wordSize == 3) {
var b = inline view.getUint16(position, true) | (view.getUint8(position + 2) << 16);
if (b & 0x800000 != 0) return b - 0x1000000;
else return b;
}
else if (wordSize == 4) return inline view.getInt32(position, true);
else return inline view.getUint8(position) - 128;
}
#end
/**
* Gets levels from the frequencies with specified sample rate.
@@ -450,12 +466,16 @@ final class AudioAnalyzer {
}
inline function __readData(startPos:Float, endPos:Float, callback:AudioAnalyzerCallback) {
var pos = Math.floor(startPos * __toBits), end = Math.min(Math.floor(endPos * __toBits), buffer.data.buffer.length), c = 0;
var pos = Math.floor(startPos * __toBits), end = Math.min(Math.floor(endPos * __toBits), buffer.data.buffer.byteLength), c = 0;
pos -= pos % __sampleSize;
end -= end % __sampleSize;
while (pos < end) {
#if sys
callback(getByte(buffer.data.buffer, pos, __wordSize), c);
#elseif js
callback(getByte(buffer.data, pos, __wordSize), c);
#end
if (++c > buffer.channels) c = 0;
pos += __wordSize;
}
+4 -3
View File
@@ -1,5 +1,6 @@
package funkin.backend.utils;
import lime.utils.AssetType;
#if cpp
import cpp.Float64;
#end
@@ -1240,9 +1241,9 @@ final class CoolUtil
* @return Bool
*/
public static function imageHasFrameData(path:String):String {
if (FileSystem.exists(Path.withExtension(path, "xml"))) return "xml";
if (FileSystem.exists(Path.withExtension(path, "txt"))) return "txt";
if (FileSystem.exists(Path.withExtension(path, "json"))) return "json";
if (Paths.assetsTree.existsSpecific(Path.withExtension(path, "xml"), AssetType.TEXT)) return "xml";
if (Paths.assetsTree.existsSpecific(Path.withExtension(path, "txt"), AssetType.TEXT)) return "txt";
if (Paths.assetsTree.existsSpecific(Path.withExtension(path, "json"), AssetType.TEXT)) return "json";
return null;
}
+3 -3
View File
@@ -1,5 +1,8 @@
package funkin.backend.utils;
#if !macro
import funkin.backend.system.Logs;
#end
#if (target.threaded)
import sys.thread.Deque;
import sys.thread.Thread;
@@ -8,9 +11,6 @@ import sys.thread.Mutex;
private typedef Thread = Dynamic;
#end
#if !macro
import funkin.backend.system.Logs;
#end
final class ThreadUtil {
inline static function error(text:String) {
@@ -254,6 +254,7 @@ final class TranslationUtil
// todo make it load the default languages in a second string map
#if MOD_SUPPORT
for(mod in ModsFolder.getLoadedModsLibs(true)) for(file in mod.getFiles("assets/" + mainPath).sortAlphabetically().map((v)->'$mainPath/$v')) {
if(Path.extension(file).toLowerCase() != "xml") continue;
@@ -277,6 +278,7 @@ final class TranslationUtil
parseXml(langNode, prefix);
}
#end
for(pair in translations) {
var node = pair.node;
@@ -17,8 +17,10 @@ import funkin.game.Character;
import haxe.xml.Access;
import haxe.xml.Printer;
import funkin.editors.ui.UIImageExplorer.ImageSaveData;
#if sys
import sys.FileSystem;
import sys.io.File;
#end
class CharacterEditor extends UIState {
static var __character:String;
@@ -518,6 +520,7 @@ class CharacterEditor extends UIState {
characterPropertiesWindow.editCharacterInfo(oldInfo, false);
case CCharEditSprite(fileID):
var cneisdPath:String = './.temp/__undo__${Type.getClassName(Type.getClass(FlxG.state))}__${fileID}.cneisd';
#if sys
if (FileSystem.exists(cneisdPath)) {
try {
var cneisdData:String = File.getContent(cneisdPath);
@@ -530,6 +533,7 @@ class CharacterEditor extends UIState {
trace('ERROR COMPLETING UNDO: $e');
};
}
#end
case CAnimCreate(animID, animData):
characterAnimsWindow.deleteAnimation(characterAnimsWindow.buttons.members[animID], false);
case CAnimDelete(animID, animData):
@@ -592,6 +596,7 @@ class CharacterEditor extends UIState {
characterPropertiesWindow.editCharacterInfo(newInfo, false);
case CCharEditSprite(fileID):
var cneisdPath:String = './.temp/__redo__${Type.getClassName(Type.getClass(FlxG.state))}__${fileID}.cneisd';
#if sys
if (FileSystem.exists(cneisdPath)) {
try {
var cneisdData:String = File.getContent(cneisdPath);
@@ -604,6 +609,7 @@ class CharacterEditor extends UIState {
trace('ERROR COMPLETING UNDO: $e');
};
}
#end
case CAnimCreate(animID, animData):
characterAnimsWindow.addAnimation(animData, animID, false);
playAnimation(animData.name);
@@ -371,12 +371,14 @@ class SongCreationScreen extends UISubstateWindow {
{
case 2 /*"V-Slice Project (.fnfc)"*/:
var files:Map<String, Any> = [];
#if sys
for (field in new ZipReader(new BytesInput(importChartFile.file)).read()) {
var fileName = field.fileName;
var fileContent = ZipUtil.unzip(field);
files.set(fileName, fileContent);
}
saveFromVSlice(files);
#end
case 1 /*"V-Slice"*/:
var songId = importIdTextBox.label.text;
var files:Map<String, Any> = [];
@@ -62,7 +62,11 @@ class UIFileExplorer extends UISliceSprite {
}
public function loadFile(path:String) {
#if sys
file = cast sys.io.File.getBytes(filePath = path);
#else
file = null;
#end
deleteButton.visible = deleteButton.selectable = deleteIcon.visible = !(uploadButton.visible = uploadButton.selectable = false);
if (this.onFile != null) this.onFile(filePath, file);
+47 -1
View File
@@ -8,8 +8,10 @@ import haxe.Json;
import haxe.io.Bytes;
import haxe.io.Path;
import openfl.display.BitmapData;
#if sys
import sys.FileSystem;
import sys.io.File;
#end
import animate.FlxAnimateJson;
using StringTools;
@@ -60,13 +62,19 @@ class UIImageExplorer extends UIFileExplorer {
directoryBG.members.push(directoryTextBox);
if (image != null) {
#if sys
var fullImagePath:String = '${Path.normalize(Sys.getCwd())}/${Paths.image(image)}'.replace('/', '\\');
#else
var fullImagePath = null;
#end
var noExt = Path.withoutExtension(fullImagePath);
#if sys
if (FileSystem.exists('$noExt\\spritemap1.png'))
fullImagePath = '$noExt\\spritemap1.png';
if (FileSystem.exists(fullImagePath))
loadFile(fullImagePath);
#end
}
allowDirectories = CoolUtil.isMapEmpty(imageFiles); __firstLoad = false;
@@ -100,7 +108,11 @@ class UIImageExplorer extends UIFileExplorer {
// CHECK ATLAS
if(allowAtlases && ANIMATE_ATLAS_REGEX.match(fileName)) {
// check if directory has the other files
#if sys
files = FileSystem.readDirectory(directoryPath);
#else
files = null;
#end
var hasAnimationJson:Bool = false;
var hasSpritemapJson:Bool = false;
for(file in files) {
@@ -116,12 +128,20 @@ class UIImageExplorer extends UIFileExplorer {
}
} else if(allowAtlases && Path.extension(fileName) == "png") {
// check if the spritemap json files point to the image
#if sys
files = FileSystem.readDirectory(directoryPath);
#else
files = null;
#end
var hasAnimationJson:Bool = false;
var foundSpritemapJson:Bool = false;
for(file in files) {
if(SPRITEMAP_JSON_REGEX.match(file)) {
#if sys
var content:String = CoolUtil.removeBOM(File.getContent(Path.join([directoryPath, file])));
#else
var content = null;
#end
var json:SpritemapJson = Json.parse(content);
if(json.meta.image.toLowerCase() == fileName.toLowerCase())
foundSpritemapJson = true;
@@ -146,7 +166,11 @@ class UIImageExplorer extends UIFileExplorer {
spritemaps.sort(Reflect.compare);
for(spritemap in spritemaps) {
#if sys
var content:String = CoolUtil.removeBOM(File.getContent(Path.join([directoryPath, spritemap])));
#else
var content = null;
#end
var json:SpritemapJson = Json.parse(content);
var imageToFind:String = json.meta.image.toLowerCase();
for(file in files) {
@@ -168,17 +192,23 @@ class UIImageExplorer extends UIFileExplorer {
if (isAtlas) {
var dataPath:String = '$directoryPath/Animation.json'.replace('/', '\\');
#if sys
if (FileSystem.exists(dataPath)) {
var dataPathFile:String = File.getContent(dataPath);
animationList = CoolUtil.getAnimsListFromAtlas(cast haxe.Json.parse(dataPathFile));
imageFiles.set(Path.withoutDirectory(dataPath), dataPathFile);
}
#end
} else {
var dataPathExt:String = CoolUtil.imageHasFrameData(imagePath);
var dataPath:String = Path.withExtension(imagePath, dataPathExt);
#if sys
var dataPathFile:String = !isAtlas && dataPathExt != null ? File.getContent(dataPath) : null;
#else
var dataPathFile = null;
#end
if (dataPathExt != null) {
frames = CoolUtil.loadFramesFromData(dataPathFile, dataPathExt);
animationList = CoolUtil.getAnimsListFromFrames(frames, dataPathExt);
@@ -200,14 +230,24 @@ class UIImageExplorer extends UIFileExplorer {
for(spritemap in spritemapImages) {
var spritemapPath:String = Path.join([directoryPath, spritemap]);
#if sys
var info = FileSystem.stat(spritemapPath);
#else
var info = null;
#end
size += info.size;
spritemapPath = spritemapPath.replace('/', '\\');
#if sys
imageFiles.set(Path.withoutDirectory(spritemapPath), sys.io.File.getBytes(spritemapPath));
#end
}
#if sys
file = cast sys.io.File.getBytes(filePath = spritemapPath);
#else
file = null;
#end
image = BitmapData.fromBytes(file).crop();
} else {
@@ -321,12 +361,16 @@ class UIImageExplorer extends UIFileExplorer {
var alreadlyExistingFiles:Array<String> = [];
for (name => file in imageData.imageFiles)
#if sys
if (FileSystem.exists('$directory/$name'))
alreadlyExistingFiles.push('$directory/$name');
#end
function deleteExistingFiles() {
#if sys
for (file in alreadlyExistingFiles)
FileSystem.deleteFile(file);
#end
alreadlyExistingFiles = [];
}
@@ -346,8 +390,10 @@ class UIImageExplorer extends UIFileExplorer {
label: TU.translate("uiImageExplorer.override"),
color: 0xFFFF0000,
onClick: (_) -> {
#if sys
deleteExistingFiles();
acuttalySaveFiles();
#end
}
},
{
+2
View File
@@ -1,6 +1,8 @@
package funkin.game;
#if sys
import sys.FileSystem;
#end
import flixel.util.FlxSpriteUtil;
import openfl.display.Graphics;
import flixel.util.typeLimit.OneOfTwo;
@@ -15,6 +15,7 @@ class HTML5AudioSource
private var parent:AudioSource;
private var playing:Bool;
private var position:Vector4;
private var loopTime:Float;
public function new(parent:AudioSource)
{