From 2609add7cf3f2957fd52865d48a04371d2e2212c Mon Sep 17 00:00:00 2001 From: Blantados Date: Wed, 13 Mar 2024 11:13:12 +0800 Subject: [PATCH] More 1.8 --- source/Main.hx | 22 ++- source/luafiles/DeprecatedFunctions.hx | 4 +- source/luafiles/TweenFunctions.hx | 1 + source/states/PlayState.hx | 11 +- source/states/SecretState.hx | 2 +- source/states/editors/CharacterEditorState.hx | 153 +++++++++++------- source/states/editors/ChartingState.hx | 35 +++- 7 files changed, 157 insertions(+), 71 deletions(-) diff --git a/source/Main.hx b/source/Main.hx index 433a679..813c683 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -107,7 +107,7 @@ class Main extends Sprite fpsCounter = new FPS(10, 3, 0xFFFFFF); addChild(fpsCounter); Lib.current.stage.align = "tl"; - Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE; + Lib.current.stage.scaleMode = StageScaleMode.SHOW_ALL; var daBool:Bool = FlxG.save.data.fps || FlxG.save.data.showFPS; toggleFPS(daBool); #end @@ -115,6 +115,26 @@ class Main extends Sprite #if CRASH_HANDLER Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash); #end + + // shader coords fix + FlxG.signals.gameResized.add(function (w, h) { + if (FlxG.cameras != null) { + for (cam in FlxG.cameras.list) { + if (cam != null && cam.filters != null) + resetSpriteCache(cam.flashSprite); + } + } + + if (FlxG.game != null) + resetSpriteCache(FlxG.game); + }); + } + + static function resetSpriteCache(sprite:Sprite):Void { + @:privateAccess { + sprite.__cacheBitmap = null; + sprite.__cacheBitmapData = null; + } } public static function dumpCache() diff --git a/source/luafiles/DeprecatedFunctions.hx b/source/luafiles/DeprecatedFunctions.hx index 909508d..d6d81cf 100644 --- a/source/luafiles/DeprecatedFunctions.hx +++ b/source/luafiles/DeprecatedFunctions.hx @@ -20,8 +20,8 @@ class DeprecatedFunctions Lua_helper.add_callback(lua, "objectPlayAnimation", function(obj:String, name:String, forced:Bool = false, ?startFrame:Int = 0) { //ModchartState.luaTrace("objectPlayAnimation is deprecated! Use playAnim instead", false, true); // i still use this - if(PlayState.instance.getLuaObject(obj,false) != null) { - PlayState.instance.getLuaObject(obj,false).animation.play(name, forced, false, startFrame); + if(LuaUtils.getObjectDirectly(obj) != null) { + LuaUtils.getObjectDirectly(obj).animation.play(name, forced, false, startFrame); return true; } diff --git a/source/luafiles/TweenFunctions.hx b/source/luafiles/TweenFunctions.hx index d508b27..f1c617a 100644 --- a/source/luafiles/TweenFunctions.hx +++ b/source/luafiles/TweenFunctions.hx @@ -24,6 +24,7 @@ class TweenFunctions Lua_helper.add_callback(lua, "doTweenZoom", function(tag:String, vars:String, value:Dynamic, duration:Float, ease:String) { oldTweenFunction(tag, vars, {zoom: value}, duration, ease, 'doTweenZoom'); }); + Lua_helper.add_callback(lua, "cancelTween", function(tag:String) { LuaUtils.cancelTween(tag); }); diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index eaad0d6..e7195d5 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -3169,9 +3169,6 @@ class PlayState extends MusicBeatState public var paused:Bool = false; public var startedCountdown:Bool = false; public var canPause:Bool = true; - public var spookyText:FlxText; - public var spookyRendered:Bool = false; - public var spookySteps:Int = 0; public var nps:Int = 0; public var maxNPS:Int = 0; @@ -3213,14 +3210,14 @@ class PlayState extends MusicBeatState paused = true; pauseCameraEffects = true; - // 1 / 1000 chance for Gitaroo Man easter egg - if (FlxG.random.bool(0.1)) + // I finally got tired with it + /*if (FlxG.random.bool(0.1)) { cancelMusicFadeTween(); MusicBeatState.switchState(new states.GitarooPause()); } else - { + {*/ if(FlxG.sound.music != null) { FlxG.sound.music.pause(); vocals.pause(); @@ -3228,7 +3225,7 @@ class PlayState extends MusicBeatState isPaused = true; openSubState(new substates.PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); - } + //} #if desktop DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + storyDifficultyText + ")", iconP2.getCharacter()); diff --git a/source/states/SecretState.hx b/source/states/SecretState.hx index 939b6a6..bb17cf5 100644 --- a/source/states/SecretState.hx +++ b/source/states/SecretState.hx @@ -44,7 +44,7 @@ class SecretState extends MusicBeatState lolText = new FlxText(0, 0, FlxG.width - 100, 32); lolText.setFormat(Paths.font("vcr.ttf"), 32, FlxColor.WHITE, CENTER); - lolText.text = "The version 1.7 update for BETADCIU Engine! Optimized the code for the engine a LOT and fixed some features that previously didn't work as intended. As always, I've also added some more lua stuff and made some more minor adjustments. \n\nMore BETADCIU Modpacks will be released soon! Hope you enjoy the update!"; + lolText.text = "Here's version 1.8 of BETADCIU Engine! All hx files are now organized in folders like 0.7+ Psych so any code that breaks when porting from 0.6 to 0.7+ Psych will probably also need to be fixed for this version. Not sure what else broke along the way so I will be fixing and reuploading all existing modpacks.\n\nMore BETADCIU Modpacks will be released soon! Hope you enjoy the update!"; lolText.borderColor = FlxColor.BLACK; lolText.borderSize = 3; lolText.borderStyle = FlxTextBorderStyle.OUTLINE; diff --git a/source/states/editors/CharacterEditorState.hx b/source/states/editors/CharacterEditorState.hx index 6c61ef8..caa3042 100644 --- a/source/states/editors/CharacterEditorState.hx +++ b/source/states/editors/CharacterEditorState.hx @@ -48,7 +48,7 @@ class CharacterEditorState extends MusicBeatState var textAnim:FlxText; var bgLayer:FlxTypedGroup; var charLayer:FlxTypedGroup; - var dumbTexts:FlxTypedGroup; + var animsTxtGroup:FlxTypedGroup; //var animList:Array = []; var curAnim:Int = 0; var daAnim:String = 'spooky'; @@ -80,6 +80,8 @@ class CharacterEditorState extends MusicBeatState var cameraFollowPointer:FlxSprite; var healthBarBG:FlxSprite; + var anims = null; + override function create() { FlxG.sound.playMusic(Paths.music('kawaruslow'), 0.7); @@ -130,9 +132,9 @@ class CharacterEditorState extends MusicBeatState add(leHealthIcon); leHealthIcon.cameras = [camHUD]; - dumbTexts = new FlxTypedGroup(); - add(dumbTexts); - dumbTexts.cameras = [camHUD]; + animsTxtGroup = new FlxTypedGroup(); + add(animsTxtGroup); + animsTxtGroup.cameras = [camHUD]; textAnim = new FlxText(300, 16); textAnim.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, RIGHT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); @@ -142,7 +144,7 @@ class CharacterEditorState extends MusicBeatState textAnim.cameras = [camHUD]; add(textAnim); - genBoyOffsets(); + reloadAnimList(); camFollow = new FlxObject(0, 0, 2, 2); camFollow.screenCenter(); @@ -489,6 +491,8 @@ class CharacterEditorState extends MusicBeatState char.flipAnims(); ghostChar.flipX = char.flipX; + updateTextColors(); + if (char.isPlayer) char.setPosition(char.playerPositionArray[0] + OFFSET_X + 100, char.playerPositionArray[1]); else @@ -558,7 +562,7 @@ class CharacterEditorState extends MusicBeatState reloadCharacterOptions(); resetHealthBarColor(); updatePointerPos(); - genBoyOffsets(); + reloadAnimList(); }); templateCharacter.color = FlxColor.RED; @@ -868,7 +872,7 @@ class CharacterEditorState extends MusicBeatState } reloadAnimationDropDown(); - genBoyOffsets(); + reloadAnimList(); trace('Added/Updated animation: ' + animationInputText.text); }); @@ -890,7 +894,7 @@ class CharacterEditorState extends MusicBeatState char.playAnim(char.animationsArray[0].anim, true); } reloadAnimationDropDown(); - genBoyOffsets(); + reloadAnimList(); trace('Removed animation: ' + animationInputText.text); break; } @@ -1071,73 +1075,86 @@ class CharacterEditorState extends MusicBeatState reloadGhost(); } - function genBoyOffsets():Void + function reloadAnimList():Void { var daLoop:Int = 0; - var i:Int = dumbTexts.members.length-1; + var i:Int = animsTxtGroup.members.length-1; while(i >= 0) { - var memb:FlxText = dumbTexts.members[i]; + var memb:FlxText = animsTxtGroup.members[i]; if(memb != null) { memb.kill(); - dumbTexts.remove(memb); + animsTxtGroup.remove(memb); memb.destroy(); } --i; } - dumbTexts.clear(); - - var text:FlxText = new FlxText(10, 20 + (18 * daLoop), 0, 'Offsets:', 15); - text.setFormat(null, 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + animsTxtGroup.clear(); + + var text:FlxText = animsTxtGroup.recycle(FlxText); + text.x = 10; + text.y = 32 + (20 * daLoop); + text.fieldWidth = 400; + text.fieldHeight = 20; + text.text = "Offsets:"; + text.setFormat(null, 16, FlxColor.WHITE, LEFT, OUTLINE_FAST, FlxColor.BLACK); text.scrollFactor.set(); text.borderSize = 1; - dumbTexts.add(text); - text.cameras = [camHUD]; + animsTxtGroup.add(text); daLoop++; - for (anim => offsets in char.animOffsets) + for (anim in anims) { - var text:FlxText = new FlxText(10, 20 + (18 * daLoop), 0, anim + ": " + offsets, 15); - text.setFormat(null, 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + var text:FlxText = animsTxtGroup.recycle(FlxText); + text.x = 10; + text.y = 32 + (20 * daLoop); + text.fieldWidth = 400; + text.fieldHeight = 20; + text.text = anim.anim + ": " + anim.offsets; + text.setFormat(null, 16, FlxColor.WHITE, LEFT, OUTLINE_FAST, FlxColor.BLACK); text.scrollFactor.set(); text.borderSize = 1; - dumbTexts.add(text); - text.cameras = [camHUD]; + animsTxtGroup.add(text); daLoop++; } - if (char.animPlayerOffsets != null) - { - daLoop++; + daLoop++; - var text:FlxText = new FlxText(10, 20 + (18 * daLoop), 0, 'Player Offsets:', 15); - text.setFormat(null, 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + var text:FlxText = animsTxtGroup.recycle(FlxText); + text.x = 10; + text.y = 32 + (20 * daLoop); + text.fieldWidth = 400; + text.fieldHeight = 20; + text.text = "Player Offsets:"; + text.setFormat(null, 16, FlxColor.WHITE, LEFT, OUTLINE_FAST, FlxColor.BLACK); + text.scrollFactor.set(); + text.borderSize = 1; + animsTxtGroup.add(text); + daLoop++; + + for (anim in anims) + { + var text:FlxText = animsTxtGroup.recycle(FlxText); + text.x = 10; + text.y = 32 + (20 * daLoop); + text.fieldWidth = 400; + text.fieldHeight = 20; + text.text = anim.anim + ": " + (anim.playerOffsets != null ? anim.playerOffsets : anim.offsets); + text.setFormat(null, 16, FlxColor.WHITE, LEFT, OUTLINE_FAST, FlxColor.BLACK); text.scrollFactor.set(); text.borderSize = 1; - dumbTexts.add(text); - text.cameras = [camHUD]; - daLoop++; + animsTxtGroup.add(text); - for (anim => playerOffsets in char.animPlayerOffsets) - { - var text:FlxText = new FlxText(10, 20 + (18 * daLoop), 0, anim + ": " + playerOffsets, 15); - text.setFormat(null, 16, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); - text.scrollFactor.set(); - text.borderSize = 1; - dumbTexts.add(text); - text.cameras = [camHUD]; - - daLoop++; - } + daLoop++; } textAnim.visible = true; - if(dumbTexts.length < 1) { + if(animsTxtGroup.length < 1) { var text:FlxText = new FlxText(10, 38, 0, "ERROR! No animations found.", 15); text.scrollFactor.set(); text.borderSize = 1; - dumbTexts.add(text); + animsTxtGroup.add(text); textAnim.visible = false; } } @@ -1186,8 +1203,10 @@ class CharacterEditorState extends MusicBeatState ghostChar.alpha = 0.6; char = new Character(0, 0, daAnim, !isDad); - if(char.animationsArray[0] != null) { - char.playAnim(char.animationsArray[0].anim, true); + anims = char.animationsArray; + + if(anims[0] != null) { + char.playAnim(anims[0].anim, true); } char.debugMode = true; @@ -1221,7 +1240,7 @@ class CharacterEditorState extends MusicBeatState }*/ if(blahBlahBlah) { - genBoyOffsets(); + reloadAnimList(); } reloadCharacterOptions(); reloadBGs(); @@ -1552,26 +1571,25 @@ class CharacterEditorState extends MusicBeatState } if(char.animationsArray.length > 0) { - if (FlxG.keys.justPressed.W) - { + if (FlxG.keys.justPressed.W){ curAnim -= 1; } - if (FlxG.keys.justPressed.S) - { + if (FlxG.keys.justPressed.S){ curAnim += 1; } - if (curAnim < 0) + if (curAnim < 0){ curAnim = char.animationsArray.length - 1; - + } + if (curAnim >= char.animationsArray.length) curAnim = 0; if (FlxG.keys.justPressed.S || FlxG.keys.justPressed.W || FlxG.keys.justPressed.SPACE) { char.playAnim(char.animationsArray[curAnim].anim, true); - genBoyOffsets(); + reloadAnimList(); } if (FlxG.keys.justPressed.R) @@ -1581,7 +1599,7 @@ class CharacterEditorState extends MusicBeatState char.animationsArray[curAnim].playerOffsets = [0, 0]; char.addPlayerOffset(char.animationsArray[curAnim].anim, char.animationsArray[curAnim].playerOffsets[0], char.animationsArray[curAnim].playerOffsets[1]); ghostChar.addPlayerOffset(char.animationsArray[curAnim].anim, char.animationsArray[curAnim].playerOffsets[0], char.animationsArray[curAnim].playerOffsets[1]); - genBoyOffsets(); + reloadAnimList(); } else { @@ -1589,14 +1607,12 @@ class CharacterEditorState extends MusicBeatState char.addOffset(char.animationsArray[curAnim].anim, char.animationsArray[curAnim].offsets[0], char.animationsArray[curAnim].offsets[1]); ghostChar.addOffset(char.animationsArray[curAnim].anim, char.animationsArray[curAnim].offsets[0], char.animationsArray[curAnim].offsets[1]); - genBoyOffsets(); + reloadAnimList(); } } var controlArray:Array = [FlxG.keys.justPressed.LEFT, FlxG.keys.justPressed.RIGHT, FlxG.keys.justPressed.UP, FlxG.keys.justPressed.DOWN]; - - for (i in 0...controlArray.length) { if(controlArray[i]) { var holdShift = FlxG.keys.pressed.SHIFT; @@ -1629,9 +1645,11 @@ class CharacterEditorState extends MusicBeatState if(ghostChar.animation.curAnim != null && char.animation.curAnim != null && char.animation.curAnim.name == ghostChar.animation.curAnim.name) { ghostChar.playAnim(char.animation.curAnim.name, false); } - genBoyOffsets(); + reloadAnimList(); } } + + updateTextColors(); } } camMenu.zoom = FlxG.camera.zoom; @@ -1731,4 +1749,21 @@ class CharacterEditorState extends MusicBeatState var text:String = prefix + Clipboard.text.replace('\n', ''); return text; } + + inline function updateTextColors() + { + var playerSplit = 0; + + for (i in 0...animsTxtGroup.members.length) + { + var text = animsTxtGroup.members[i]; + text.color = FlxColor.WHITE; + + if(text.text.split(':')[0] == char.animation.curAnim.name){ + if ((char.isPlayer && i > 1 + anims.length) || (!char.isPlayer && i < 1 + anims.length)){ + text.color = 0xFF66A9E8; + } + } + } + } } diff --git a/source/states/editors/ChartingState.hx b/source/states/editors/ChartingState.hx index 75f1582..6d9d6f4 100644 --- a/source/states/editors/ChartingState.hx +++ b/source/states/editors/ChartingState.hx @@ -2257,7 +2257,7 @@ class ChartingState extends MusicBeatState #end } - //because fuck runHaxeCode + //these lag when running on lua for some bizarre reason public static function wavDataFuncs(funcName:String, daVar:Dynamic, ?args:Array){ switch(funcName.toLowerCase()){ case "getuint16": @@ -2269,6 +2269,38 @@ class ChartingState extends MusicBeatState return null; } + public static function returnSampleLevelAtTime(buffer:AudioBuffer, curTime:Float = 0){ + var sampleMult:Float = buffer.sampleRate / 44100; + var index:Int = Std.int(curTime * sampleMult); + var drawIndex:Int = 0; + var samplesPerRow = 1; + var waveBytes:Bytes = buffer.data.toBytes(); + + var min:Float = 0; + var max:Float = 0; + + var byte:Int = waveBytes.getUInt16(index * 4); + + if (byte > 65535 / 2) + byte -= 65535; + + var sample:Float = (byte / 65535); + + if (sample > 0) + { + if (sample > max) + max = sample; + } + else if (sample < 0) + { + if (sample < min) + min = sample; + } + + return max + min; + } + + //so we did all the math in chartingstate. public static function returnWavData(buffer:AudioBuffer, curTime:Float = 0){ var newWavData:Array = [null, null, null, null, null]; @@ -2282,6 +2314,7 @@ class ChartingState extends MusicBeatState } + public static function updateWaveformSprite(daSprite:FlxSprite, daSound:FlxSound, songPos:Float) { var newWavData:Array>> = [[[0], [0]], [[0], [0]]];