From 6952de51ff8ca8b625670b5cbece3a43de413ac4 Mon Sep 17 00:00:00 2001 From: CharlesCatYT Date: Fri, 29 Mar 2024 20:37:02 -0400 Subject: [PATCH] untested but yeah psych 1.0a is coming so --- source/Main.hx | 7 +++ source/backend/ClientPrefs.hx | 1 + source/backend/ColorBlindness.hx | 51 +++++++++++++++++ source/backend/Song.hx | 21 +++++++ source/debug/FPSCounter.hx | 25 +++------ source/objects/Character.hx | 76 ++++++++++++++------------ source/psychlua/FunkinLua.hx | 27 +++++---- source/psychlua/ReflectionFunctions.hx | 9 +-- source/states/PlayState.hx | 31 ++++++----- source/substates/ResetScoreSubState.hx | 2 + 10 files changed, 164 insertions(+), 86 deletions(-) create mode 100644 source/backend/ColorBlindness.hx diff --git a/source/Main.hx b/source/Main.hx index aeee3f5..230876a 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -19,6 +19,8 @@ import flixel.util.FlxColor; import lime.app.Application; import haxe.EnumFlags; import haxe.Exception; + +import backend.ColorBlindness; import debug.FPSCounter; #if linux @@ -53,6 +55,7 @@ class Main extends Sprite public static var fpsVar:FPSCounter; public static var watermark:Sprite; + public static var colorFilter:ColorBlindness; public static var instance:Main; @@ -87,6 +90,10 @@ class Main extends Sprite if (stage != null) init(); else addEventListener(Event.ADDED_TO_STAGE, init); + + #if VIDEOS_ALLOWED + hxvlc.util.Handle.init(); + #end } private function init(?E:Event):Void { diff --git a/source/backend/ClientPrefs.hx b/source/backend/ClientPrefs.hx index b1628bf..bbb0adb 100644 --- a/source/backend/ClientPrefs.hx +++ b/source/backend/ClientPrefs.hx @@ -101,6 +101,7 @@ import states.StartingState; public var safeFrames:Float = 10; public var guitarHeroSustains:Bool = true; public var discordRPC:Bool = true; + public var colorFilter:String = "NONE"; } class ClientPrefs { diff --git a/source/backend/ColorBlindness.hx b/source/backend/ColorBlindness.hx new file mode 100644 index 0000000..6d2721c --- /dev/null +++ b/source/backend/ColorBlindness.hx @@ -0,0 +1,51 @@ +package backend; + +import backend.ClientPrefs; +import openfl.filters.ColorMatrixFilter; + +@:access(flixel.FlxGame) +class ColorBlindness extends ColorMatrixFilter { + public var enabledFilter:Bool = true; + + public function new(filterType:String) { + enabledFilter = filterType.toUpperCase() != "NONE"; + + if (!enabledFilter) return; + + var filter:Array = []; + switch (filterType.toUpperCase()) { + case "DEUTERANOPIA": + filter = [ + 0.43, 0.72, -.15, 0, 0, + 0.34, 0.57, 0.09, 0, 0, + -.02, 0.03, 1, 0, 0, + 0, 0, 0, 1, 0, + ]; + case "PROTANOPIA": + filter = [ + 0.20, 0.99, -.19, 0, 0, + 0.16, 0.79, 0.04, 0, 0, + 0.01, -.01, 1, 0, 0, + 0, 0, 0, 1, 0, + ]; + case "TRITANOPIA": + filter = [ + 0.97, 0.11, -.08, 0, 0, + 0.02, 0.82, 0.16, 0, 0, + 0.06, 0.88, 0.18, 0, 0, + 0, 0, 0, 1, 0, + ]; + default: + } + super(filter); + } + + public static function setColorFilter() { + if (FlxG.game._filters == null) FlxG.game._filters = []; + if (FlxG.game._filters.contains(Main.colorFilter)) FlxG.game._filters.remove(Main.colorFilter); + + Main.colorFilter = new ColorBlindness(ClientPrefs.data.colorFilter); + if (ClientPrefs.data.colorFilter != "NONE") FlxG.game._filters.push(Main.colorFilter); + /*else FlxG.game.setFilters([]);*/ + } +} \ No newline at end of file diff --git a/source/backend/Song.hx b/source/backend/Song.hx index 8f771c0..6e6625a 100644 --- a/source/backend/Song.hx +++ b/source/backend/Song.hx @@ -33,6 +33,27 @@ typedef SwagSong = @:optional var splashSkin:String; } +//// "what"? +//// a typedef with default values, basically. @crowplexus +@:structInit class ChartNoteData { + public var time: Null = null; + public var id: Null = null; + public var type: Null = null; + public var strumLine: Null = null; + public var isGfNote: Null = null; + public var sLen: Null = null; + + public function dispose() { + // will be cleared by the GC later + time = null; + id = null; + type = null; + strumLine = null; + isGfNote = null; + sLen = null; + } +} + class Song { public var song:String; diff --git a/source/debug/FPSCounter.hx b/source/debug/FPSCounter.hx index 1280664..e1464d1 100644 --- a/source/debug/FPSCounter.hx +++ b/source/debug/FPSCounter.hx @@ -113,7 +113,7 @@ class FPSCounter extends TextField { if (ClientPrefs.data.engineVersion) { text += "\n[ALLEYWAY VER] 1.0b / [PE VER]" + MainMenuState.psychEngineVersion; - text += "\n[VS.FOXA VER] 3.0 SE"; + text += "\n[VS.FOXA VER] 3.0+"; } // #if debug @@ -143,20 +143,14 @@ class FPSCounter extends TextField { cacheCount = currentCount; set_rainbowEnabled(ClientPrefs.data.rainbowFPS); - #if desktop - #if !debug - if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (75); - else y = 3; + #if desktop #if !debug + if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (75); else y = 3; #else - if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (150); - else y = 3; - #end - #end + if (differentPosition) y = (Lib.current.stage.stageHeight - 3) - (150); else y = 3; + #end #end } - function obtainMemory():Dynamic { - return System.totalMemory; - } + function obtainMemory():Dynamic {return System.totalMemory;} private function getGLInfo(info:GLInfo):String { @:privateAccess @@ -164,16 +158,13 @@ class FPSCounter extends TextField { switch (info) { case RENDERER: return Std.string(gl.getParameter(gl.RENDERER)); - case SHADING_LANGUAGE_VERSION: - return Std.string(gl.getParameter(gl.SHADING_LANGUAGE_VERSION)); + case SHADING_LANGUAGE_VERSION: return Std.string(gl.getParameter(gl.SHADING_LANGUAGE_VERSION)); } return ''; } private var hue:Float = 0; - private function doRainbowThing():Void { - textColor = fromHSL({hue = (hue + (FlxG.elapsed * 100)) % 360; hue;}, 1, 0.8); - } + private function doRainbowThing():Void {textColor = fromHSL({hue = (hue + (FlxG.elapsed * 100)) % 360; hue;}, 1, 0.8);} // function named fromHSL which takes a hue, saturation, and lightness value and returns a color (0xffRRGGBB) private static inline function fromHSL(h:Float, s:Float, l:Float) { diff --git a/source/objects/Character.hx b/source/objects/Character.hx index 8f6fc15..142eacc 100644 --- a/source/objects/Character.hx +++ b/source/objects/Character.hx @@ -66,6 +66,8 @@ class Character extends FlxSprite { public var cameraPosition:Array = [0, 0]; public var healthColorArray:Array = [255, 0, 0]; // i wonder if i can turn this to hex optionally hmmmmm + public var missingCharacter:Bool = false; + public var missingText:FlxText; public var hasMissAnimations:Bool = false; public var vocalsFile:String = ''; @@ -98,8 +100,11 @@ class Character extends FlxSprite { #end { path = Paths.getSharedPath('characters/' + DEFAULT_CHARACTER + '.json'); //If a character couldn't be found, change him to BF just to prevent a crash - color = FlxColor.BLACK; - alpha = 0.6; + /*color = FlxColor.BLACK; + alpha = 0.6;*/ + missingCharacter = true; + missingText = new FlxText(0, 0, 300, 'ERROR:\n$curCharacter.json', 16); + missingText.alignment = CENTER; } try { @@ -390,50 +395,57 @@ class Character extends FlxSprite { var lastDanceIdle:Bool = danceIdle; danceIdle = (animOffsets.exists('danceLeft' + idleSuffix) && animOffsets.exists('danceRight' + idleSuffix)); - if(settingCharacterUp) - { - danceEveryNumBeats = (danceIdle ? 1 : 2); - } - else if(lastDanceIdle != danceIdle) - { + if(settingCharacterUp) danceEveryNumBeats = (danceIdle ? 1 : 2); + else if(lastDanceIdle != danceIdle) { var calc:Float = danceEveryNumBeats; - if(danceIdle) - calc /= 2; - else - calc *= 2; + if(danceIdle) calc /= 2; + else calc *= 2; danceEveryNumBeats = Math.round(Math.max(calc, 1)); } settingCharacterUp = false; } - public function addOffset(name:String, x:Float = 0, y:Float = 0) - { - animOffsets[name] = [x, y]; - } - public function quickAnimAdd(name:String, anim:String) - { - animation.addByPrefix(name, anim, 24, false); - } + public function addOffset(name:String, x:Float = 0, y:Float = 0) animOffsets[name] = [x, y]; + public function quickAnimAdd(name:String, anim:String) animation.addByPrefix(name, anim, 24, false); // Atlas support // special thanks ne_eo for the references, you're the goat!! public var isAnimateAtlas:Bool = false; #if flxanimate public var atlas:FlxAnimate; - public override function draw() - { - if(isAnimateAtlas) - { + public override function draw() { + var lastAlpha:Float = alpha; + var lastColor:FlxColor = color; + if (missingCharacter) { + alpha *= 0.6; + color = FlxColor.BLACK; + } + + if (isAnimateAtlas) { copyAtlasValues(); atlas.draw(); + if (missingCharacter) { + alpha = lastAlpha; + color = lastColor; + + missingText.x = getMidpoint().x - 150; + missingText.y = getMidpoint().y - 10; + missingText.draw(); + } return; } super.draw(); + if (missingCharacter) { + alpha = lastAlpha; + color = lastColor; + missingText.x = getMidpoint().x - 150; + missingText.y = getMidpoint().y - 10; + missingText.draw(); + } } public function copyAtlasValues() { - @:privateAccess - { + @:privateAccess { atlas.cameras = cameras; atlas.scrollFactor = scrollFactor; atlas.scale = scale; @@ -453,16 +465,8 @@ class Character extends FlxSprite { } } - public override function destroy() - { - super.destroy(); - destroyAtlas(); - } + public override function destroy() {super.destroy(); destroyAtlas();} - public function destroyAtlas() - { - if (atlas != null) - atlas = FlxDestroyUtil.destroy(atlas); - } + public function destroyAtlas() if (atlas != null) atlas = FlxDestroyUtil.destroy(atlas); #end } \ No newline at end of file diff --git a/source/psychlua/FunkinLua.hx b/source/psychlua/FunkinLua.hx index e73340a..a3fc300 100644 --- a/source/psychlua/FunkinLua.hx +++ b/source/psychlua/FunkinLua.hx @@ -210,12 +210,6 @@ class FunkinLua { // build target (windows, mac, linux, android, etc.) set('buildTarget', getBuildTarget()); - for (name => func in customFunctions) - { - if(func != null) - Lua_helper.add_callback(lua, name, func); - } - // Lua_helper.add_callback(lua, "getRunningScripts", function(){ var runningScripts:Array = []; @@ -1130,14 +1124,15 @@ class FunkinLua { if(spr != null) spr.makeGraphic(width, height, CoolUtil.colorFromString(color)); }); Lua_helper.add_callback(lua, "addAnimationByPrefix", function(obj:String, name:String, prefix:String, framerate:Int = 24, loop:Bool = true) { - var obj:Dynamic = LuaUtils.getObjectDirectly(obj, false); + var obj:FlxSprite = cast LuaUtils.getObjectDirectly(obj, false); if(obj != null && obj.animation != null) { obj.animation.addByPrefix(name, prefix, framerate, loop); if(obj.animation.curAnim == null) { - if(obj.playAnim != null) obj.playAnim(name, true); - else obj.animation.play(name, true); + var dyn:Dynamic = cast obj; + if(dyn.playAnim != null) dyn.playAnim(name, true); + else dyn.animation.play(name, true); } return true; } @@ -1145,17 +1140,19 @@ class FunkinLua { }); Lua_helper.add_callback(lua, "addAnimation", function(obj:String, name:String, frames:Array, framerate:Int = 24, loop:Bool = true) { - var obj:Dynamic = LuaUtils.getObjectDirectly(obj, false); + var obj:FlxSprite = LuaUtils.getObjectDirectly(obj, false); if(obj != null && obj.animation != null) { obj.animation.add(name, frames, framerate, loop); - if(obj.animation.curAnim == null) { - obj.animation.play(name, true); + if(obj.animation.curAnim == null) + { + var dyn:Dynamic = cast obj; + if(dyn.playAnim != null) dyn.playAnim(name, true); + else dyn.animation.play(name, true); } return true; } - return false; - }); + } Lua_helper.add_callback(lua, "addAnimationByIndices", function(obj:String, name:String, prefix:String, indices:Any, framerate:Int = 24, loop:Bool = false) { return LuaUtils.addAnimByIndices(obj, name, prefix, indices, framerate, loop); @@ -1635,6 +1632,8 @@ class FunkinLua { ShaderFunctions.implement(this); DeprecatedFunctions.implement(this); + for (name => func in customFunctions) if (func != null) Lua_helper.add_callback(lua, name, func); + try{ var isString:Bool = !FileSystem.exists(scriptName); var result:Dynamic = null; diff --git a/source/psychlua/ReflectionFunctions.hx b/source/psychlua/ReflectionFunctions.hx index 7ddf988..2d66a61 100644 --- a/source/psychlua/ReflectionFunctions.hx +++ b/source/psychlua/ReflectionFunctions.hx @@ -18,15 +18,12 @@ class ReflectionFunctions Lua_helper.add_callback(lua, "getProperty", function(variable:String, ?allowMaps:Bool = false) { var split:Array = variable.split('.'); - if (split.length > 1) - return LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split, true, true, allowMaps), split[split.length - 1], allowMaps); + if (split.length > 1) return LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split, true, true, allowMaps), split[split.length - 1], allowMaps); return LuaUtils.getVarInArray(LuaUtils.getTargetInstance(), variable, allowMaps); }); - Lua_helper.add_callback(lua, "setProperty", function(variable:String, value:Dynamic, allowMaps:Bool = false) - { + Lua_helper.add_callback(lua, "setProperty", function(variable:String, value:Dynamic, ?allowMaps:Bool = false) { var split:Array = variable.split('.'); - if (split.length > 1) - { + if (split.length > 1) { LuaUtils.setVarInArray(LuaUtils.getPropertyLoop(split, true, true, allowMaps), split[split.length - 1], value, allowMaps); return true; } diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index d0054ed..ba02342 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -3053,6 +3053,11 @@ class PlayState extends MusicBeatState if(char != null) { + if(note.isSustainNote) + { + var holdAnim:String = animToPlay + '-hold'; + if(char.animation.exists(holdAnim)) animToPlay = holdAnim; + } char.playAnim(animToPlay, true); char.holdTimer = 0; } @@ -3099,16 +3104,20 @@ class PlayState extends MusicBeatState return; } if(!note.noAnimation) { - var animToPlay:String = singAnimations[Std.int(Math.abs(Math.min(singAnimations.length-1, note.noteData)))]; + var animToPlay:String = singAnimations[Std.int(Math.abs(Math.min(singAnimations.length-1, note.noteData)))] + note.animSuffix; var char:Character = boyfriend; var animCheck:String = 'hey'; - if(note.gfNote){ + if (note.gfNote) { char = gf; animCheck = 'cheer'; } - if(char != null) - { - char.playAnim(animToPlay + note.animSuffix, true); + if (char != null) { + if(note.isSustainNote) + { + var holdAnim:String = animToPlay + '-hold'; + if(char.animation.exists(holdAnim)) animToPlay = holdAnim; + } + char.playAnim(animToPlay, true); char.holdTimer = 0; if(note.noteType == 'Hey!') { if(char.animOffsets.exists(animCheck)) { @@ -3119,8 +3128,7 @@ class PlayState extends MusicBeatState } } } - if(!cpuControlled) - { + if(!cpuControlled){ var spr = playerStrums.members[note.noteData]; if(spr != null) spr.playAnim('confirm', true); } @@ -3152,8 +3160,7 @@ class PlayState extends MusicBeatState public function spawnNoteSplashOnNote(note:Note) { if(note != null) { var strum:StrumNote = playerStrums.members[note.noteData]; - if(strum != null) - spawnNoteSplash(strum.x, strum.y, note.noteData, note); + if(strum != null) spawnNoteSplash(strum.x, strum.y, note.noteData, note); } } @@ -3176,14 +3183,12 @@ class PlayState extends MusicBeatState #if HSCRIPT_ALLOWED for (script in hscriptArray) - if(script != null) - { + if(script != null) { script.call('onDestroy'); script.destroy(); } - while (hscriptArray.length > 0) - hscriptArray.pop(); + while (hscriptArray.length > 0) hscriptArray.pop(); #end FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyPress); diff --git a/source/substates/ResetScoreSubState.hx b/source/substates/ResetScoreSubState.hx index 91d048f..6f99926 100644 --- a/source/substates/ResetScoreSubState.hx +++ b/source/substates/ResetScoreSubState.hx @@ -69,6 +69,8 @@ class ResetScoreSubState extends MusicBeatSubstate noText.screenCenter(X); noText.x += 200; add(noText); + + for(letter in yesText.letters) letter.color = FlxColor.RED; updateOptions(); }