Skip to content

Commit

Permalink
Merge branch 'rewrite/master' into input-offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteMasterEric committed Mar 29, 2024
2 parents 680ed3c + 86c91d1 commit 35f99b4
Show file tree
Hide file tree
Showing 57 changed files with 1,865 additions and 308 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build-shit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ jobs:
apt update
apt install -y sudo git curl unzip
- name: Fix git config on posix runner
# this can't be {{ github.workspace }} because that's not docker-aware
run: |
git config --global --add safe.directory ${{ github.workspace }}
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Get checkout token
uses: actions/create-github-app-token@v1
id: app_token
Expand Down Expand Up @@ -90,8 +91,9 @@ jobs:
runs-on: [self-hosted, macos]
steps:
- name: Fix git config on posix runner
# this can't be {{ github.workspace }} because that's not docker-aware
run: |
git config --global --add safe.directory ${{ github.workspace }}
git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Get checkout token
uses: actions/create-github-app-token@v1
id: app_token
Expand Down
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@
"label": "HTML5 / Debug (Watch)",
"target": "html5",
"args": ["-debug", "-watch", "-DFORCE_DEBUG_VERSION"]
},
{
"label": "macOS / Debug",
"target": "mac",
"args": ["-debug", "-DFORCE_DEBUG_VERSION"]
},
{
"label": "macOS / Release",
"target": "mac",
"args": ["-release"]
},
{
"label": "macOS / Release (GitHub Actions)",
"target": "mac",
"args": ["-release", "-DGITHUB_BUILD"]
}
],
"cmake.configureOnOpen": false,
Expand Down
12 changes: 10 additions & 2 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
<app title="Friday Night Funkin'" file="Funkin" packageName="com.funkin.fnf" package="com.funkin.fnf" main="Main" version="0.3.0" company="ninjamuffin99" />
<!--Switch Export with Unique ApplicationID and Icon-->
<set name="APP_ID" value="0x0100f6c013bbc000" />
<app preloader="funkin.Preloader" />

<!--
Define the OpenFL sprite which displays the preloader.
You can't replace the preloader's logic here, sadly, but you can extend it.
Basic preloading logic is done by `openfl.display.Preloader`.
-->
<app preloader="funkin.ui.transition.preload.FunkinPreloader" />

<!--Minimum without FLX_NO_GAMEPAD: 11.8, without FLX_NO_NATIVE_CURSOR: 11.2-->
<set name="SWF_VERSION" value="11.8" />
<!-- ____________________________ Window Settings ___________________________ -->
<!--These window settings apply to all targets-->
<window width="1280" height="720" fps="" background="#000000" hardware="true" vsync="false" />
<window width="1280" height="720" fps="60" background="#000000" hardware="true" vsync="false" />
<!--HTML5-specific-->
<window if="html5" resizable="true" />
<!--Desktop-specific-->
Expand Down Expand Up @@ -95,6 +102,7 @@
<!-- If compiled via github actions, show debug version number. -->
<define name="FORCE_DEBUG_VERSION" if="GITHUB_BUILD" />
<define name="NO_REDIRECT_ASSETS_FOLDER" if="GITHUB_BUILD" />
<define name="TOUCH_HERE_TO_PLAY" if="web" />

<!-- _______________________________ Libraries ______________________________ -->
<haxelib name="lime" /> <!-- Game engine backend -->
Expand Down
2 changes: 1 addition & 1 deletion art
Submodule art updated from 03e7c2 to 004636
2 changes: 1 addition & 1 deletion assets
12 changes: 10 additions & 2 deletions source/funkin/Conductor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ class Conductor
* You can also do stuff like store a reference to the Conductor and pass it around or temporarily replace it,
* or have a second Conductor running at the same time, or other weird stuff like that if you need to.
*/
public static var instance:Conductor = new Conductor();
public static var instance(get, never):Conductor;

static var _instance:Null<Conductor> = null;

static function get_instance():Conductor
{
if (_instance == null) _instance = new Conductor();
return _instance;
}

/**
* Signal fired when the current Conductor instance advances to a new measure.
Expand Down Expand Up @@ -597,6 +605,6 @@ class Conductor
*/
public static function reset():Void
{
Conductor.instance = new Conductor();
_instance = new Conductor();
}
}
65 changes: 0 additions & 65 deletions source/funkin/Preloader.hx

This file was deleted.

151 changes: 133 additions & 18 deletions source/funkin/audio/FunkinSound.hx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package funkin.audio;

import flixel.sound.FlxSound;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.util.FlxSignal.FlxTypedSignal;
import flixel.math.FlxMath;
import flixel.sound.FlxSound;
import flixel.system.FlxAssets.FlxSoundAsset;
import funkin.util.tools.ICloneable;
import funkin.data.song.SongData.SongMusicData;
import funkin.data.song.SongRegistry;
import flixel.tweens.FlxTween;
import flixel.util.FlxSignal.FlxTypedSignal;
import funkin.audio.waveform.WaveformData;
import funkin.audio.waveform.WaveformDataParser;
import flixel.math.FlxMath;
import funkin.data.song.SongData.SongMusicData;
import funkin.data.song.SongRegistry;
import funkin.util.tools.ICloneable;
import openfl.Assets;
import openfl.media.SoundMixer;
#if (openfl >= "8.0.0")
import openfl.utils.AssetType;
#end

/**
* A FlxSound which adds additional functionality:
* - Delayed playback via negative song position.
* - Easy functions for immediate playback and recycling.
*/
@:nullSafety
class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
Expand Down Expand Up @@ -48,6 +51,11 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
*/
static var pool(default, null):FlxTypedGroup<FunkinSound> = new FlxTypedGroup<FunkinSound>();

/**
* Calculate the current time of the sound.
* NOTE: You need to `add()` the sound to the scene for `update()` to increment the time.
*/
//
public var muted(default, set):Bool = false;

function set_muted(value:Bool):Bool
Expand Down Expand Up @@ -286,15 +294,28 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
* Creates a new `FunkinSound` object and loads it as the current music track.
*
* @param key The key of the music you want to play. Music should be at `music/<key>/<key>.ogg`.
* @param overrideExisting Whether to override music if it is already playing.
* @param mapTimeChanges Whether to check for `SongMusicData` to update the Conductor with.
* @param params A set of additional optional parameters.
* Data should be at `music/<key>/<key>-metadata.json`.
* @return Whether the music was started. `false` if music was already playing or could not be started
*/
public static function playMusic(key:String, overrideExisting:Bool = false, mapTimeChanges:Bool = true):Void
public static function playMusic(key:String, params:FunkinSoundPlayMusicParams):Bool
{
if (!overrideExisting && FlxG.sound.music?.playing) return;
if (!(params.overrideExisting ?? false) && (FlxG.sound.music?.exists ?? false) && FlxG.sound.music.playing) return false;

if (mapTimeChanges)
if (!(params.restartTrack ?? false) && FlxG.sound.music?.playing)
{
if (FlxG.sound.music != null && Std.isOfType(FlxG.sound.music, FunkinSound))
{
var existingSound:FunkinSound = cast FlxG.sound.music;
// Stop here if we would play a matching music track.
if (existingSound._label == Paths.music('$key/$key'))
{
return false;
}
}
}

if (params?.mapTimeChanges ?? true)
{
var songMusicData:Null<SongMusicData> = SongRegistry.instance.parseMusicData(key);
// Will fall back and return null if the metadata doesn't exist or can't be parsed.
Expand All @@ -308,10 +329,27 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
}
}

FlxG.sound.music = FunkinSound.load(Paths.music('$key/$key'));
if (FlxG.sound.music != null)
{
FlxG.sound.music.fadeTween?.cancel();
FlxG.sound.music.stop();
FlxG.sound.music.kill();
}

var music = FunkinSound.load(Paths.music('$key/$key'), params?.startingVolume ?? 1.0, params.loop ?? true, false, true);
if (music != null)
{
FlxG.sound.music = music;

// Prevent repeat update() and onFocus() calls.
FlxG.sound.list.remove(FlxG.sound.music);
// Prevent repeat update() and onFocus() calls.
FlxG.sound.list.remove(FlxG.sound.music);

return true;
}
else
{
return false;
}
}

/**
Expand All @@ -326,11 +364,18 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
* @param autoPlay Whether to play the sound immediately or wait for a `play()` call.
* @param onComplete Called when the sound finished playing.
* @param onLoad Called when the sound finished loading. Called immediately for succesfully loaded embedded sounds.
* @return A `FunkinSound` object.
* @return A `FunkinSound` object, or `null` if the sound could not be loaded.
*/
public static function load(embeddedSound:FlxSoundAsset, volume:Float = 1.0, looped:Bool = false, autoDestroy:Bool = false, autoPlay:Bool = false,
?onComplete:Void->Void, ?onLoad:Void->Void):FunkinSound
?onComplete:Void->Void, ?onLoad:Void->Void):Null<FunkinSound>
{
@:privateAccess
if (SoundMixer.__soundChannels.length >= SoundMixer.MAX_ACTIVE_CHANNELS)
{
FlxG.log.error('FunkinSound could not play sound, channels exhausted! Found ${SoundMixer.__soundChannels.length} active sound channels.');
return null;
}

var sound:FunkinSound = pool.recycle(construct);

// Load the sound.
Expand All @@ -341,6 +386,10 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
{
sound._label = embeddedSound;
}
else
{
sound._label = 'unknown';
}

sound.volume = volume;
sound.group = FlxG.sound.defaultSoundGroup;
Expand All @@ -350,11 +399,41 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
// Call onLoad() because the sound already loaded
if (onLoad != null && sound._sound != null) onLoad();

FlxG.sound.list.remove(FlxG.sound.music);

return sound;
}

public override function destroy():Void
{
// trace('[FunkinSound] Destroying sound "${this._label}"');
super.destroy();
FlxTween.cancelTweensOf(this);
this._label = 'unknown';
}

/**
* Play a sound effect once, then destroy it.
* @param key
* @param volume
* @return static function construct():FunkinSound
*/
public static function playOnce(key:String, volume:Float = 1.0, ?onComplete:Void->Void, ?onLoad:Void->Void):Void
{
var result = FunkinSound.load(key, volume, false, true, true, onComplete, onLoad);
}

/**
* Stop all sounds in the pool and allow them to be recycled.
*/
public static function stopAllAudio(musicToo:Bool = false):Void
{
for (sound in pool)
{
if (sound == null) continue;
if (!musicToo && sound == FlxG.sound.music) continue;
sound.destroy();
}
}

static function construct():FunkinSound
{
var sound:FunkinSound = new FunkinSound();
Expand All @@ -365,3 +444,39 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
return sound;
}
}

/**
* Additional parameters for `FunkinSound.playMusic()`
*/
typedef FunkinSoundPlayMusicParams =
{
/**
* The volume you want the music to start at.
* @default `1.0`
*/
var ?startingVolume:Float;

/**
* Whether to override music if a different track is already playing.
* @default `false`
*/
var ?overrideExisting:Bool;

/**
* Whether to override music if the same track is already playing.
* @default `false`
*/
var ?restartTrack:Bool;

/**
* Whether the music should loop or play once.
* @default `true`
*/
var ?loop:Bool;

/**
* Whether to check for `SongMusicData` to update the Conductor with.
* @default `true`
*/
var ?mapTimeChanges:Bool;
}
Loading

0 comments on commit 35f99b4

Please sign in to comment.