Skip to content

Commit

Permalink
fix song scripts on html5
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 17, 2024
1 parent 9cc2fe0 commit c44302c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 48 deletions.
16 changes: 10 additions & 6 deletions project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
<define name="MODS_ALLOWED" if="desktop"/>

<!--Enables tools for modding (like the console, editors, etc)-->
<define name="DEV_TOOLS" if="MODS_ALLOWED"/>
<define name="DEV_TOOLS" if="desktop"/>

<!--If you want hxvlc videos to be used-->
<define name="VIDEOS_ALLOWED" if="cpp"/>
<define name="VIDEOS_ALLOWED"/>

<!--If you want the discord rcp to be used-->
<define name="DISCORD_ALLOWED" if="cpp" unless="mobile"/>
<define name="DISCORD_ALLOWED" if="desktop"/>

<!--If you want to have ffmpeg used for osu and quaver pack zip support-->
<define name="ZIPS_ALLOWED" if="desktop"/>
Expand Down Expand Up @@ -76,17 +76,21 @@

<!-- _______________________________ Libraries ______________________________ -->

<haxedev set='webgl' if="web" />

<haxelib name="flixel" />
<haxedev set='webgl' />
<haxelib name="flixel-ui" />
<haxelib name="flixel-addons" />
<haxelib name="haxeui-core" unless="mac"/>
<haxelib name="haxeui-openfl" unless="mac"/>
<haxelib name="discord_rpc" if="DISCORD_ALLOWED"/>
<haxelib name="maru-hscript" />
<haxelib name="hxvlc" if="VIDEOS_ALLOWED"/>
<haxedef name="hscriptPos"/>

<section if="cpp">
<haxelib name="hxvlc" if="VIDEOS_ALLOWED"/>
<haxelib name="discord_rpc" if="DISCORD_ALLOWED"/>
</section>

<!-- ______________________________ Haxedefines _____________________________ -->

<haxedef name="FLX_NO_FOCUS_LOST_SCREEN" />
Expand Down
2 changes: 1 addition & 1 deletion source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InitState extends FlxState
Conductor.init();
CoolUtil.init();
Highscore.load();
#if DISCORD_ALLOWED
#if discord_rpc
DiscordClient.initialize();
lime.app.Application.current.onExit.add((code:Int) -> DiscordClient.shutdown());
#end
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ScriptConsole.hx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class ScriptConsole extends ResizableSprite {
var tmr:Float = 0;
public function update(elapsed:Float) {
if (tmr <= 0) { // Show / hide console
if (FlxG.keys.justPressed.F1) {
if (#if web FlxG.keys.justPressed.F2 #else FlxG.keys.justPressed.F1 #end) {
tmr = 0.1; // Fix spam issue
show = !show;
visible = true;
Expand Down
32 changes: 16 additions & 16 deletions source/funkin/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import funkin.objects.*;
import funkin.objects.note.*;
import funkin.objects.funkui.FunkBar;
import funkin.objects.FunkCamera.AngledCamera;
#if VIDEOS_ALLOWED
#if hxvlc
import hxvlc.flixel.FlxVideo;
#end

Expand Down Expand Up @@ -89,7 +89,7 @@ class PlayState extends MusicBeatState
public var dialogueBox:DialogueBoxBase = null;

// Discord RPC variables
#if DISCORD_ALLOWED
#if discord_rpc
var iconRPC:String = "";
var detailsText:String = "";
var detailsPausedText:String = "";
Expand Down Expand Up @@ -144,7 +144,7 @@ class PlayState extends MusicBeatState

SONG = Song.checkSong(SONG, null, false);

#if DISCORD_ALLOWED
#if discord_rpc
detailsText = isStoryMode ? 'Story Mode: ${storyWeek.toUpperCase()}' : 'Freeplay';
detailsPausedText = 'Paused - $detailsText';
if (Character.getCharData(SONG.players[1]) != null)
Expand Down Expand Up @@ -211,7 +211,7 @@ class PlayState extends MusicBeatState

//Character Scripts
boyfriend.type = "bf"; dad.type = "dad"; gf.type = "gf";
for (char in [boyfriend, dad, gf]) addCharScript(char);
addCharScript(boyfriend); addCharScript(dad); addCharScript(gf);

//Song Scripts
ModdingUtil.addScriptFolder('songs/${Song.formatSongFolder(SONG.song)}');
Expand Down Expand Up @@ -319,13 +319,13 @@ class PlayState extends MusicBeatState
CoolUtil.gc(true);
}

#if VIDEOS_ALLOWED public var video:FlxVideo; #end
#if hxvlc public var video:FlxVideo; #end

public function startVideo(file:String, ?completeFunc:()->Void):Void
{
completeFunc ??= () -> startCountdown();

#if VIDEOS_ALLOWED
#if hxvlc
video = new FlxVideo();
video.load(Paths.video(file));
video.onEndReached.add(() -> {
Expand All @@ -341,7 +341,7 @@ class PlayState extends MusicBeatState
}

public function endVideo() {
#if VIDEOS_ALLOWED
#if hxvlc
if (video != null)
video.onEndReached.dispatch();
#end
Expand Down Expand Up @@ -464,7 +464,7 @@ class PlayState extends MusicBeatState
// Song duration in a float, useful for the time left feature
songLength = Conductor.inst.length;

#if DISCORD_ALLOWED DiscordClient.changePresence(detailsText, '${SONG.song} (${formatDiff()})', iconRPC, true, songLength); #end
#if discord_rpc DiscordClient.changePresence(detailsText, '${SONG.song} (${formatDiff()})', iconRPC, true, songLength); #end
}

private function openPauseSubState(easterEgg:Bool = false):Void {
Expand Down Expand Up @@ -506,7 +506,7 @@ class PlayState extends MusicBeatState
Conductor.play();
}

#if DISCORD_ALLOWED
#if discord_rpc
var presenceDetails = '${SONG.song} (${formatDiff()})';
var presenceTime = songLength - Conductor.songPosition;
DiscordClient.changePresence(detailsText, presenceDetails, iconRPC, Conductor.songPosition >= 0, presenceTime);
Expand Down Expand Up @@ -557,7 +557,7 @@ class PlayState extends MusicBeatState
if (canPause) {
if (startedCountdown) if (getKey('PAUSE', JUST_PRESSED)) {
openPauseSubState(true);
#if DISCORD_ALLOWED DiscordClient.changePresence(detailsPausedText, '${SONG.song} (${formatDiff()})', iconRPC); #end
#if discord_rpc DiscordClient.changePresence(detailsPausedText, '${SONG.song} (${formatDiff()})', iconRPC); #end
}
}

Expand All @@ -570,19 +570,19 @@ class PlayState extends MusicBeatState
#if DEV_TOOLS
if (justPressed.SIX) {
clearCacheData = {tempCache: false};
#if DISCORD_ALLOWED DiscordClient.changePresence("Stage Editor", null, null, true); #end
#if discord_rpc DiscordClient.changePresence("Stage Editor", null, null, true); #end
switchState(new StageDebug(stageData));
}

if (justPressed.SEVEN) {
clearCacheData = {tempCache: false};
switchState(new ChartingState());
#if DISCORD_ALLOWED DiscordClient.changePresence("Chart Editor", null, null, true); #end
#if discord_rpc DiscordClient.changePresence("Chart Editor", null, null, true); #end
}

if (justPressed.EIGHT) {
clearCacheData = {tempCache: false};
#if DISCORD_ALLOWED DiscordClient.changePresence("Character Editor", null, null, true); #end
#if discord_rpc DiscordClient.changePresence("Character Editor", null, null, true); #end

if (FlxG.keys.pressed.SHIFT) {
if (FlxG.keys.pressed.CONTROL) switchState(new AnimationDebug(SONG.players[2]));
Expand Down Expand Up @@ -623,7 +623,7 @@ class PlayState extends MusicBeatState
openSubState(new GameOverSubstate(boyfriend.OG_X, boyfriend.OG_Y));

// Game Over doesn't get his own variable because it's only used here
#if DISCORD_ALLOWED DiscordClient.changePresence('Game Over - $detailsText', SONG.song + ' (${formatDiff()})', iconRPC); #end
#if discord_rpc DiscordClient.changePresence('Game Over - $detailsText', SONG.song + ' (${formatDiff()})', iconRPC); #end
}

inline public function snapCamera():Void
Expand Down Expand Up @@ -655,7 +655,7 @@ class PlayState extends MusicBeatState
#if DEV_TOOLS
if (inChartEditor) {
switchState(new ChartingState());
#if DISCORD_ALLOWED DiscordClient.changePresence("Chart Editor", null, null, true); #end
#if discord_rpc DiscordClient.changePresence("Chart Editor", null, null, true); #end
}
else #end inCutscene ? ModdingUtil.addCall('startCutscene', [true]) : exitSong();
}
Expand Down Expand Up @@ -789,7 +789,7 @@ class PlayState extends MusicBeatState
CoolUtil.destroyMusic();
SkinUtil.setCurSkin('default');

#if VIDEOS_ALLOWED
#if hxvlc
if (video != null) {
video.dispose();
video = null;
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/states/menus/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FreeplayState extends MusicBeatState
FlxG.mouse.visible = #if mobile false; #else true; #end
#if mobile MobileTouch.setMode(MENU); #end

#if DISCORD_ALLOWED // Updating Discord Rich Presence
#if discord_rpc // Updating Discord Rich Presence
DiscordClient.changePresence("In the Menus", null);
#end

Expand Down
4 changes: 2 additions & 2 deletions source/funkin/states/menus/MainMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MainMenuState extends MusicBeatState {
override function create():Void
{
// Updating Discord Rich Presence
#if DISCORD_ALLOWED DiscordClient.changePresence("In the Menus", null); #end
#if discord_rpc DiscordClient.changePresence("In the Menus", null); #end
#if mobile MobileTouch.setMode(NONE); #end

if (FlxG.sound.music == null || !FlxG.sound.music.playing)
Expand Down Expand Up @@ -108,7 +108,7 @@ class MainMenuState extends MusicBeatState {
}
#end

#if DEV_TOOLS
#if (DEV_TOOLS && sys)
if (FlxG.keys.justPressed.SEVEN) {
selectedSomethin = true;
switchState(new funkin.states.editors.ModSetupState());
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/states/menus/StoryMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class StoryMenuState extends MusicBeatState {
grpWeekCharacters = new TypedGroup<MenuCharacter>();

// Updating Discord Rich Presence
#if DISCORD_ALLOWED DiscordClient.changePresence("In the Menus", null); #end
#if discord_rpc DiscordClient.changePresence("In the Menus", null); #end
#if mobile MobileTouch.setMode(MENU); #end

WeekSetup.getWeekList().fastForEach((week, i) -> {
Expand Down
12 changes: 6 additions & 6 deletions source/funkin/util/backend/DiscordClient.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package funkin.util.backend;

#if DISCORD_ALLOWED
#if discord_rpc
import Sys.sleep;
import discord_rpc.DiscordRpc;
#end
Expand All @@ -12,7 +12,7 @@ class DiscordClient

public function new()
{
#if DISCORD_ALLOWED
#if discord_rpc
trace("Discord Client starting...");
DiscordRpc.start({
clientID: "1168666530788163705", // 814588678700924999
Expand All @@ -35,14 +35,14 @@ class DiscordClient

public static function shutdown()
{
#if DISCORD_ALLOWED
#if discord_rpc
DiscordRpc.shutdown();
#end
}

static function onReady()
{
#if DISCORD_ALLOWED
#if discord_rpc
DiscordRpc.presence({
details: "In the Menus",
state: null,
Expand All @@ -64,7 +64,7 @@ class DiscordClient

public static function initialize()
{
#if DISCORD_ALLOWED
#if discord_rpc
var DiscordDaemon = sys.thread.Thread.create(() ->
{
new DiscordClient();
Expand All @@ -75,7 +75,7 @@ class DiscordClient

public static function changePresence(details:String, state:Null<String>, ?smallImageKey : String, ?hasStartTimestamp : Bool, ?endTimestamp: Float)
{
#if DISCORD_ALLOWED
#if discord_rpc
var startTimestamp:Float = hasStartTimestamp ? Date.now().getTime() : 0;

if (endTimestamp > 0)
Expand Down
8 changes: 4 additions & 4 deletions source/funkin/util/modding/FunkScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class FunkScript extends hscript.Script implements IFlxDestroyable
set('FlxEase', flixel.tweens.FlxEase);
set('FlxTrail', flixel.addons.effects.FlxTrail);

#if VIDEOS_ALLOWED
#if hxvlc
set('FlxVideo', hxvlc.flixel.FlxVideo);
set('FlxVideoSprite', hxvlc.flixel.FlxVideoSprite);
#end

#if DISCORD_ALLOWED
#if discord_rpc
set("changeDiscordPresence", DiscordClient.changePresence);
#end

Expand All @@ -150,8 +150,8 @@ class FunkScript extends hscript.Script implements IFlxDestroyable
#end
);

set("VIDEOS_ALLOWED", #if VIDEOS_ALLOWED true #else false #end);
set("DISCORD_ALLOWED", #if DISCORD_ALLOWED true #else false #end);
set("VIDEOS_ALLOWED", #if hxvlc true #else false #end);
set("DISCORD_ALLOWED", #if discord_rpc true #else false #end);
set("ZIPS_ALLOWED", #if ZIPS_ALLOWED true #else false #end);

//HScript Functions
Expand Down
13 changes: 3 additions & 10 deletions source/funkin/util/modding/ModdingUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ typedef ModFolder = {
* 0 => Beta 2
*/

class ModdingUtil {
class ModdingUtil
{
public static var folderExceptions(default, never):Array<String> = ['data', 'fonts', 'images', 'music', 'songs', 'videos', 'sounds'];
public static inline var API_VERSION:Int = 0;
public static final DEFAULT_MOD:ModFolder = {
Expand Down Expand Up @@ -252,15 +253,7 @@ class ModdingUtil {

public static function getScriptList(folder:String = 'data/scripts/global', assets:Bool = true, globalMod:Bool = true, curMod:Bool = true, allMods:Bool = false):Array<String>
{
final scripts = assets ? Paths.getFileList(TEXT, true, 'hx', 'assets/$folder') : [];

#if !desktop
var library = folder.split("/")[0];
switch (library) {
case "images" | "data" | "sounds" | "fonts":
case _: scripts.fastForEach((script, i) -> scripts.unsafeSet(i, library + ":" + script));
}
#end
var scripts = assets ? Paths.getFileList(TEXT, true, 'hx', 'assets/$folder') : [];

#if MODS_ALLOWED
var modScripts = Paths.getModFileList(folder, 'hx', true, globalMod, curMod, allMods);
Expand Down

0 comments on commit c44302c

Please sign in to comment.