Merge pull request #279 from FunkinCrew/feature/hashlink-hot-reload

Allow builds without hxCodec if using hashlink
This commit is contained in:
Cameron Taylor 2024-02-13 03:32:46 -05:00 committed by GitHub
commit cf01f8c0f3
13 changed files with 74 additions and 43 deletions

View file

@ -108,7 +108,7 @@
<haxelib name="flixel-text-input" /> <!-- Improved text field rendering for HaxeUI -->
<haxelib name="polymod" /> <!-- Modding framework -->
<haxelib name="flxanimate" /> <!-- Texture atlas rendering -->
<haxelib name="hxCodec" /> <!-- Video playback -->
<haxelib name="hxCodec" if="desktop release" /> <!-- Video playback -->
<haxelib name="json2object" /> <!-- JSON parsing -->
<haxelib name="thx.semver" /> <!-- Version string handling -->

View file

@ -109,7 +109,7 @@
"name": "lime",
"type": "git",
"dir": null,
"ref": "fff39ba6fc64969cd51987ef7491d9345043dc5d",
"ref": "1359fe6ad52e91175dc636a516d460bd54ea22ed",
"url": "https://github.com/FunkinCrew/lime"
},
{
@ -163,8 +163,10 @@
},
{
"name": "thx.semver",
"type": "haxelib",
"version": "0.2.2"
"type": "git",
"dir": null,
"ref": "cf8d213589a2c7ce4a59b0fdba9e8ff36bc029fa",
"url": "https://github.com/FunkinCrew/thx.semver"
}
]
}

View file

@ -192,7 +192,7 @@ class SoundGroup extends FlxTypedGroup<FunkinSound>
function get_playing():Bool
{
if (getFirstAlive != null) return getFirstAlive().playing;
if (getFirstAlive() != null) return getFirstAlive().playing;
else
return false;
}

View file

@ -192,8 +192,8 @@ class FunkinCamera extends FlxCamera
// get the isolated bitmap
final isolated = grabScreen(false, true);
// apply fullscreen blend
customBlendShader.blend = blend;
customBlendShader.source = isolated;
customBlendShader.blendSwag = blend;
customBlendShader.sourceSwag = isolated;
customBlendShader.updateViewInfo(FlxG.width, FlxG.height, this);
applyFilter(customBlendFilter);
}

View file

@ -4,20 +4,22 @@ import flixel.addons.display.FlxRuntimeShader;
import funkin.Paths;
import openfl.utils.Assets;
import openfl.display.BitmapData;
import openfl.display.ShaderInput;
class BlendModesShader extends FlxRuntimeShader
{
public var camera:BitmapData;
public var camera:ShaderInput<BitmapData>;
public var cameraData:BitmapData;
public function new()
{
super(Assets.getText(Paths.frag('blendModes')));
}
public function setCamera(camera:BitmapData):Void
public function setCamera(cameraData:BitmapData):Void
{
this.camera = camera;
this.cameraData = cameraData;
this.setBitmapData('camera', camera);
this.setBitmapData('camera', this.cameraData);
}
}

View file

@ -6,20 +6,22 @@ import openfl.utils.Assets;
class RuntimeCustomBlendShader extends RuntimePostEffectShader
{
public var source(default, set):BitmapData;
// only different name purely for hashlink fix
public var sourceSwag(default, set):BitmapData;
function set_source(value:BitmapData):BitmapData
function set_sourceSwag(value:BitmapData):BitmapData
{
this.setBitmapData("source", value);
return source = value;
this.setBitmapData("sourceSwag", value);
return sourceSwag = value;
}
public var blend(default, set):BlendMode;
// name change make sure it's not the same variable name as whatever is in the shader file
public var blendSwag(default, set):BlendMode;
function set_blend(value:BlendMode):BlendMode
function set_blendSwag(value:BlendMode):BlendMode
{
this.setInt("blendMode", cast value);
return blend = value;
return blendSwag = value;
}
public function new()

View file

@ -94,12 +94,12 @@ class RuntimeRainShader extends RuntimePostEffectShader
return lightMap = value;
}
public var numLights(default, set):Int = 0;
public var numLightsSwag(default, set):Int = 0; // swag heads, we have never been more back (needs different name purely for hashlink casting fix)
function set_numLights(value:Int):Int
function set_numLightsSwag(value:Int):Int
{
this.setInt('numLights', value);
return numLights = value;
return numLightsSwag = value;
}
public function new()

View file

@ -333,8 +333,12 @@ class Controls extends FlxActionSet
throw 'Invalid name: $name';
#end
return byName[name].inputs.map(function(input) return (input.device == KEYBOARD) ? input.inputID : null)
.filter(function(key) return key != null);
// TODO: Revert to `.map().filter()` once HashLink doesn't complain anymore.
var result:Array<FlxKey> = [];
for (input in byName[name].inputs) {
if (input.device == KEYBOARD) result.push(input.inputID);
}
return result;
}
public function getButtonsForAction(name:Action):Array<FlxGamepadInputID> {
@ -343,8 +347,11 @@ class Controls extends FlxActionSet
throw 'Invalid name: $name';
#end
return byName[name].inputs.map(function(input) return (input.device == GAMEPAD) ? input.inputID : null)
.filter(function(key) return key != null);
var result:Array<FlxGamepadInputID> = [];
for (input in byName[name].inputs) {
if (input.device == GAMEPAD) result.push(input.inputID);
}
return result;
}
public function getDialogueName(action:FlxActionDigital):String

View file

@ -8,7 +8,8 @@ import flixel.util.FlxColor;
import flixel.util.FlxTimer;
#if html5
import funkin.graphics.video.FlxVideo;
#else
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
#end
@ -48,14 +49,20 @@ class VideoCutscene
#if html5
playVideoHTML5(filePath);
#else
#end
#if hxCodec
playVideoNative(filePath);
#end
}
public static function isPlaying():Bool
{
#if (html5 || hxCodec)
return vid != null;
#else
return false;
#end
}
#if html5
@ -82,7 +89,9 @@ class VideoCutscene
trace('ALERT: Video is null! Could not play cutscene!');
}
}
#else
#end
#if hxCodec
static var vid:FlxVideoSprite;
static function playVideoNative(filePath:String):Void
@ -118,15 +127,20 @@ class VideoCutscene
{
PlayState.instance.remove(vid);
}
#else
#end
#if hxCodec
if (vid != null)
{
vid.stop();
PlayState.instance.remove(vid);
}
#end
#if (html5 || hxCodec)
vid.destroy();
vid = null;
#end
PlayState.instance.camCutscene.visible = true;
PlayState.instance.camHUD.visible = true;
@ -148,9 +162,3 @@ class VideoCutscene
});
}
}
/*
trace('Video playback failed (${e})');
vid = null;
finishCutscene(0.5);
*/

View file

@ -6050,7 +6050,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
// Stop the music.
if (welcomeMusic != null) welcomeMusic.destroy();
if (audioInstTrack != null) audioInstTrack.destroy();
audioVocalTrackGroup.destroy();
if (audioVocalTrackGroup != null) audioVocalTrackGroup.destroy();
}
function applyCanQuickSave():Void

View file

@ -309,8 +309,8 @@ class ChartEditorAudioHandler
snd.loadEmbedded(asset);
snd.autoDestroy = true;
FlxG.sound.list.add(snd);
snd.play(true);
snd.volume = volume;
snd.play();
}
public static function wipeInstrumentalData(state:ChartEditorState):Void

View file

@ -509,10 +509,10 @@ class StoryMenuState extends MusicBeatState
// super.dispatchEvent(event) dispatches event to module scripts.
super.dispatchEvent(event);
if (levelProps != null && levelProps.length > 0)
if (levelProps?.members != null && levelProps.members.length > 0)
{
// Dispatch event to props.
for (prop in levelProps)
for (prop in levelProps.members)
{
ScriptEventDispatcher.callEvent(prop, event);
}

View file

@ -2,7 +2,8 @@ package funkin.ui.title;
#if html5
import funkin.graphics.video.FlxVideo;
#else
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
#end
import funkin.ui.MusicBeatState;
@ -25,7 +26,9 @@ class AttractState extends MusicBeatState
#if html5
playVideoHTML5(ATTRACT_VIDEO_PATH);
#else
#end
#if hxCodec
playVideoNative(ATTRACT_VIDEO_PATH);
#end
}
@ -50,7 +53,9 @@ class AttractState extends MusicBeatState
trace('ALERT: Video is null! Could not play cutscene!');
}
}
#else
#end
#if hxCodec
var vid:FlxVideoSprite;
function playVideoNative(filePath:String):Void
@ -95,15 +100,20 @@ class AttractState extends MusicBeatState
{
remove(vid);
}
#else
#end
#if hxCodec
if (vid != null)
{
vid.stop();
remove(vid);
}
#end
#if (html5 || hxCodec)
vid.destroy();
vid = null;
#end
FlxG.switchState(() -> new TitleState());
}