Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

How did you get HTML5 support working? #11

Closed
jbmagination opened this issue Apr 8, 2022 · 5 comments
Closed

How did you get HTML5 support working? #11

jbmagination opened this issue Apr 8, 2022 · 5 comments
Labels
question Further information is requested

Comments

@jbmagination
Copy link

jbmagination commented Apr 8, 2022

Update: see #11 (comment)!


What is your question?

Hey! Me and a few others are working on a mod, and we've already made pretty significant changes to the regular engine codebase. I would switch to this, but it's already WIP and I also don't want to revert/break any of our existing changes. I get stuck at the song freezing; are you able to show how you changed the code to get songs loading in HTML5 (and why it works so that I'm not just ripping it off from you lol)

@jbmagination jbmagination added the question Further information is requested label Apr 8, 2022
@jbmagination
Copy link
Author

update: I have ended up just using Psych Extra. Made a PR; sorting out all the issues and missing changes we made. Will keep this open though since I'm sure others would be interested (as am I still!)

@Starmapo
Copy link
Owner

Starmapo commented Apr 8, 2022

This will be a lot, but it's what's needed to compile to HTML.

On CoolUtil.hx:
Replace precacheSound and precacheMusic, and remove precacheSoundFile:

public static function precacheSound(sound:String, ?library:String = null):Void {
	Paths.returnSound('sounds', sound, library);
}

public static function precacheMusic(sound:String, ?library:String = null):Void {
	Paths.returnSound('music', sound, library);
}

precacheSoundFile uses Assets.exists on the sound path, but due to the new caching system, Paths.sound and Paths.music return the actual sound file instead of the path, which isn't compatible with Assets.exists as it needs a string.

On LoadingState.hx:
Replace getSongPath and getVocalPath

static function getSongPath()
{
    return 'songs:assets/songs/${Paths.formatToSongPath(PlayState.SONG.song)}/Inst.${Paths.SOUND_EXT}';
}

static function getVocalPath()
{
    return 'songs:assets/songs/${Paths.formatToSongPath(PlayState.SONG.song)}/Voices.${Paths.SOUND_EXT}';
}

Due to the new asset cache method, Paths.inst and Paths.voices now return the audio file itself instead of the path to it (which it would fail getting since the sound isn't loaded yet), so we replace them with the file paths.

On Paths.hx:
In clearStoredMemory at the end, replace line 111, only clear the songs cache if it's all preloaded (aka not HTML)

#if PRELOAD_ALL
openfl.Assets.cache.clear("songs");
#end

This function is called right when the game state is created, so it would immediately remove the song audio that LoadingState cached.

Replace voices and inst:

inline static public function voices(song:String):Any
{
	#if PRELOAD_ALL
	var songKey:String = '${song.toLowerCase().replace(' ', '-')}/Voices';
	var voices = returnSound('songs', songKey);
	return voices;
	#else
	var songKey:String = '${song.toLowerCase().replace(' ', '-')}';
	var voices = returnSound(songKey, 'Voices', 'songs');
	return voices;
	#end
}

inline static public function inst(song:String):Any
{
	#if PRELOAD_ALL
	var songKey:String = '${song.toLowerCase().replace(' ', '-')}/Inst';
	var inst = returnSound('songs', songKey);
	return inst;
	#else
	var songKey:String = '${song.toLowerCase().replace(' ', '-')}';
	var inst = returnSound(songKey, 'Inst', 'songs');
	return inst;
	#end
}

On HTML these don't check for the audio in the 'songs' library, so they fail to get it.

On TitleState.hx:
Add after line 283:
if (easterEgg == null) easterEgg = '';
On first play this variable will be null since it hasn't been saved yet, so toUpperCase() won't be a valid function and it'll crash. I'm pretty sure this works fine on desktop so I'm not sure why not on HTML, but this fixes it.

On WeekData.hx:
Remove line 11 (import sys.io.File;)
This class is only available on desktop so it prevents HTML from compiling. It is already imported before in the MODS_ALLOWED condition anyways, so we remove it.

@jbmagination
Copy link
Author

swaaag thank you!

@jbmagination
Copy link
Author

(a heads up that you may want to turn off notifications for this issue; I imagine you'll get many just of issue mentions)

@QuestioningAccount
Copy link

i have an error with one of these, its the paths function
"source/Paths.hx:247: characters 2-8 : static modifier is not supported for module-level fields"
any fix for this?
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants