Skip to content

Commit

Permalink
wip html5 support.... whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 15, 2024
1 parent d45069d commit 3904d8e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 33 deletions.
23 changes: 11 additions & 12 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@

<classpath name="source" />

<assets path="assets/preload" rename="assets" exclude="*.ogg" if="web"/>
<assets path="assets/preload" rename="assets" exclude="*.mp3" unless="web"/>
<assets path="assets/preload" rename="assets"/>

<section if="PRELOAD_ALL">
<library name="songs" preload="true" />
Expand All @@ -81,20 +80,20 @@
<library name="shared" preload="false" />
<library name="weeks" preload="false" />
</section>

<assets path="assets/songs" library="songs" exclude="*.ogg" if="web"/>
<assets path="assets/songs" library="songs" exclude="*.mp3" unless="web"/>
<assets path="assets/shared" library="shared" exclude="*.ogg" if="web"/>
<assets path="assets/shared" library="shared" exclude="*.mp3" unless="web"/>
<assets path="assets/weeks" library="weeks" exclude="*.ogg" if="web"/>
<assets path="assets/weeks" library="weeks" exclude="*.mp3" unless="web"/>

<assets path="assets/songs"/>
<assets path="assets/shared"/>
<assets path="assets/weeks"/>
<assets path="assets/fonts"/>
<assets path="assets/videos"/>

<!--<assets path="assets/songs" library="songs"/>
<assets path="assets/shared" library="shared"/>
<assets path="assets/weeks" library="weeks"/>-->

<assets path='example_mods' rename='mods' embed='false' unless="web"/>
<assets path='art/readme.txt' rename='do NOT readme.txt' />
<assets path='art/preloaderArt.png' rename='assets/images/preloaderArt.png' unless="web"/>
<assets path='example_mods' rename='mods' embed='false' if="MODS_ALLOWED"/>
<assets path='art/readme.txt' rename='do NOT readme.txt' if="desktop" />
<assets path='art/preloaderArt.png' rename='assets/images/preloaderArt.png' if="desktop"/>
<assets path='art/ffmpeg.exe' rename='assets/data/ffmpeg.exe' if="ZIPS_ALLOWED"/>

<!-- _______________________________ Libraries ______________________________ -->
Expand Down
5 changes: 4 additions & 1 deletion source/FPS_Mem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class FPS_Mem extends TextField

static inline var memDiv:Float = 1 / 1024 / 1024 * 100;
static inline function formatBytes(bytes:Float):Float {
return Math.round(bytes * memDiv) * 0.01;
return
#if web FlxMath.roundDecimal( #end
Math.round(bytes * memDiv) * 0.01
#if web , 2 ) #end ;
}

var memPeak:Float = 0;
Expand Down
1 change: 0 additions & 1 deletion source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class Main extends Sprite

private function init(?E:Event):Void
{
#if web throw("no."); #end
if (hasEventListener(Event.ADDED_TO_STAGE))
removeEventListener(Event.ADDED_TO_STAGE, init);

Expand Down
2 changes: 1 addition & 1 deletion source/funkin/objects/HealthIcon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HealthIcon extends FlxSpriteExt {
else antialiasing = Preferences.getPref('antialiasing');

var icon = "face";
if (Paths.exists(Paths.png('icons/$char', null), IMAGE)) // Check if icon exists
if (Paths.exists(Paths.png('icons/$char'), IMAGE)) // Check if icon exists
icon = char;

loadImage('icons/$icon'); // Load first to get the resolution
Expand Down
5 changes: 2 additions & 3 deletions source/funkin/sound/FlxFunkSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import openfl.media.Sound;
@:access(lime.media.AudioSource)
@:access(openfl.media.SoundMixer)
@:access(openfl.media.Sound)
@:access(flixel.FlxGame)
class FlxFunkSound extends FlxBasic
{
@:noCompletion
Expand Down Expand Up @@ -245,10 +244,10 @@ class FlxFunkSound extends FlxBasic

if (time != __lastTime) {
__lastTime = time;
__lastTick = Main.game._total;
__lastTick = FlxG.game.ticks;
return time;
}

return time + Main.game._total - __lastTick;
return time + FlxG.game.ticks - __lastTick;
}
}
4 changes: 2 additions & 2 deletions source/funkin/states/LoadingState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LoadingState extends MusicBeatState

public function init(stage:StageJson, characters:Array<String>, song:String)
{
#if !mobile
#if desktop
var addedAssets:Array<String> = []; // Prevent repeating assets

stageAssets = Stage.getStageAssets(stage);
Expand Down Expand Up @@ -47,7 +47,7 @@ class LoadingState extends MusicBeatState

public function start()
{
#if !mobile
#if desktop
var start = openfl.Lib.getTimer();

if (onStart != null)
Expand Down
6 changes: 4 additions & 2 deletions source/funkin/states/menus/StoryMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ class StoryMenuState extends MusicBeatState {
rightArrow.playAnim(getKey('UI_RIGHT', PRESSED) ? 'press' : 'idle');
leftArrow.playAnim(getKey('UI_LEFT', PRESSED) ? 'press' : 'idle');

if (getKey('UI_RIGHT', JUST_PRESSED)) changeDifficulty(1);
if (getKey('UI_LEFT', JUST_PRESSED)) changeDifficulty(-1);
if (difficultySelectors.visible) {
if (getKey('UI_RIGHT', JUST_PRESSED)) changeDifficulty(1);
if (getKey('UI_LEFT', JUST_PRESSED)) changeDifficulty(-1);
}
}

if (getKey('ACCEPT', JUST_PRESSED)) {
Expand Down
17 changes: 12 additions & 5 deletions source/funkin/util/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import sys.FileSystem;

class Paths
{
inline public static var SOUND_EXT = #if web "mp3" #else "ogg" #end;
inline public static var SOUND_EXT = "ogg";
public static var currentLevel(default, set):String = "";

public static function set_currentLevel(value:String)
Expand Down Expand Up @@ -60,12 +60,16 @@ class Paths
}
#end

if (library != null) {
if (level != null) {
if (library != null)
{
if (level != null)
{
final levelPath = getLibraryPathForce(file, library, level);
if (exists(levelPath, type))
return levelPath;
} else {
}
else
{
final libraryPath = getLibraryPath(file, library);
if (exists(libraryPath, type))
return libraryPath;
Expand All @@ -92,7 +96,10 @@ class Paths

inline static function getLibraryPathForce(file:String, library:String, ?level:String, root:String = "assets"):String
{
return (level != null) ? '$library:$root/$library/$level/$file' : '$library:$root/$library/$file';
if (level != null)
return '$root/$library/$level/$file';

return '$root/$library/$file';
}

inline static public function getModPath(file:String):String
Expand Down
8 changes: 6 additions & 2 deletions source/funkin/util/backend/AssetManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ class Asset
return null;
}

function __disposeSound(sound:Sound):Sound @:privateAccess {
function __disposeSound(sound:Sound):Sound @:privateAccess
{
#if !web
var buffer = sound.__buffer;

if (buffer != null) {
buffer.data.buffer = null;
buffer.data = null;
}
#end

sound.close();

Expand Down Expand Up @@ -288,9 +290,11 @@ class AssetManager
}
}

#if sys
while ((stageImages.length + charImages.length + songSounds.length) > 0) {
Sys.sleep(0.01);
}
#end

for (key => bitmap in bitmaps) {
__cacheFromBitmap(key, bitmap.bitmap, false, bitmap.lod);
Expand Down
8 changes: 4 additions & 4 deletions source/funkin/util/modding/ModdingUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ModdingUtil {
public static function clearScripts():Void
{
FunkScript.globalVariables.clear();
#if !mobile
#if DEV_TOOLS
if (Main.console != null)
Main.console.clear();
#end
Expand Down Expand Up @@ -207,10 +207,10 @@ class ModdingUtil {
inline public static function errorPrint(txt:String) print(txt, ERROR);
inline public static function warningPrint(txt:String) print(txt, WARNING);
inline public static function print(text:String, type:PrintType):Void {
#if mobile
trace("[" + type + "] " + text);
#else
#if DEV_TOOLS
Main.console.print(text, type);
#else
trace("[" + type + "] " + text);
#end
}

Expand Down

0 comments on commit 3904d8e

Please sign in to comment.