diff --git a/assets/preload/data/character data/gf/config.json b/assets/preload/data/character data/gf/config.json index 7339ebd610..aad63c4ecb 100644 --- a/assets/preload/data/character data/gf/config.json +++ b/assets/preload/data/character data/gf/config.json @@ -2,6 +2,7 @@ "cameraOffset": [-40, -250], "barColor": [186, 49, 104], "mainCharacterID": 1, + "followMainCharacter": true, "characters": [ { "name": "speakers", diff --git a/mods/Friday Night Funkin'/data/character data/nene/script.hx b/mods/Friday Night Funkin'/data/character data/nene/script.hx index 761c87de05..59efaef527 100644 --- a/mods/Friday Night Funkin'/data/character data/nene/script.hx +++ b/mods/Friday Night Funkin'/data/character data/nene/script.hx @@ -117,9 +117,9 @@ function updatePost(elapsed:Float) { function turnChange(turn:String) { switch (turn) { case 'dad': - (PlayState.SONG.chartType == 0) ? movePupilsRight() : movePupilsLeft(); // workaround to some really strange issue where its flipped on vslice charts? + (PlayState.SONG.chartType == "LEGACY") ? movePupilsRight() : movePupilsLeft(); // workaround to some really strange issue where its flipped on vslice charts? case 'bf': - (PlayState.SONG.chartType == 0) ? movePupilsLeft() : movePupilsRight(); + (PlayState.SONG.chartType == "LEGACY") ? movePupilsLeft() : movePupilsRight(); default: trace('no match!'); } diff --git a/source/game/Character.hx b/source/game/Character.hx index 6588294e49..38c9c2f6dc 100644 --- a/source/game/Character.hx +++ b/source/game/Character.hx @@ -15,7 +15,6 @@ import modding.CharacterConfig; import modding.scripts.languages.HScript; import states.PlayState; - /** * The base character class. */ @@ -38,6 +37,7 @@ class Character extends FlxSprite { public var otherCharacters:Array; public var mainCharacterID:Int = 0; + public var followMainCharacter:Bool = false; public var offsetsFlipWhenPlayer:Bool = true; public var offsetsFlipWhenEnemy:Bool = false; @@ -64,7 +64,6 @@ class Character extends FlxSprite { public var preventDanceForAnim:Bool = false; public function new(x:Float, y:Float, ?character:String = "bf", ?isPlayer:Bool = false, ?isDeathCharacter:Bool = false) { - super(x, y); animOffsets = new Map>(); @@ -118,8 +117,7 @@ class Character extends FlxSprite { if (isPlayer) { // Doesn't flip for BF, since his are already in the right place??? if (swapLeftAndRightSingPlayer && !isDeathCharacter) { - try{ - + try { var oldOffRight = animOffsets.get("singRIGHT"); var oldOffLeft = animOffsets.get("singLEFT"); var oldRight:Array = animation.getByName('singRIGHT').frames; @@ -141,9 +139,8 @@ class Character extends FlxSprite { animOffsets.set("singRIGHTmiss", oldOffLeftMiss); animOffsets.set("singLEFTmiss", oldOffRightMiss); } - } - catch(e){ - //trace(e, ERROR); + } catch (e) { + // trace(e, ERROR); } } } @@ -161,14 +158,13 @@ class Character extends FlxSprite { characterName = "bf"; curCharacter = characterName; } - if(Assets.exists(Paths.hx("data/character data/" + characterName + "/script"))) - { - script = new HScript(Paths.hx("data/character data/" + characterName + "/script")); - - script.interp.variables.set("character", this); - PlayState.instance.scripts.push(script); - script.call("createCharacter", [curCharacter]); - } + if (Assets.exists(Paths.hx("data/character data/" + characterName + "/script"))) { + script = new HScript(Paths.hx("data/character data/" + characterName + "/script")); + + script.interp.variables.set("character", this); + PlayState.instance.scripts.push(script); + script.call("createCharacter", [curCharacter]); + } if (Options.getData("optimizedChars") && Assets.exists(Paths.json("character data/optimized_" + characterName + "/config"))) characterName = "optimized_" + characterName; @@ -204,14 +200,13 @@ class Character extends FlxSprite { } } - public function loadCharacterConfiguration(config:CharacterConfig) { if (config.characters == null || config.characters.length <= 1) { if (!isPlayer) flipX = config.defaultFlipX; else flipX = !config.defaultFlipX; - if (Options.getData("dinnerbone")){ + if (Options.getData("dinnerbone")) { flipY = !config.defaultFlipY; } @@ -233,18 +228,17 @@ class Character extends FlxSprite { dancesLeftAndRight = config.dancesLeftAndRight; - if (Assets.exists(Paths.file("images/characters/" + config.imagePath + "/Animation.json", TEXT))){ + if (Assets.exists(Paths.file("images/characters/" + config.imagePath + "/Animation.json", TEXT))) { atlasMode = true; atlas = new FlxAnimate(0.0, 0.0, Paths.getTextureAtlas("characters/" + config.imagePath, "shared")); atlas.showPivot = false; - } - else{ + } else { frames = Paths.getAtlas(config.imagePath); } - if(config.extraSheets != null){ - for (sheet in config.extraSheets){ - cast(frames, FlxAtlasFrames).addAtlas(Paths.getAtlas(sheet)); //multiatlas support. + if (config.extraSheets != null) { + for (sheet in config.extraSheets) { + cast(frames, FlxAtlasFrames).addAtlas(Paths.getAtlas(sheet)); // multiatlas support. } } @@ -259,7 +253,8 @@ class Character extends FlxSprite { if (!atlasMode) { for (selected_animation in config.animations) { if (selected_animation.indices != null && selected_animation.indices.length > 0) { - animation.addByIndices(selected_animation.name, selected_animation.animation_name, selected_animation.indices, "", selected_animation.fps, selected_animation.looped); + animation.addByIndices(selected_animation.name, selected_animation.animation_name, selected_animation.indices, "", + selected_animation.fps, selected_animation.looped); } else { animation.addByPrefix(selected_animation.name, selected_animation.animation_name, selected_animation.fps, selected_animation.looped); } @@ -267,7 +262,8 @@ class Character extends FlxSprite { } else { for (selected_animation in config.animations) { if (selected_animation.indices != null && selected_animation.indices.length > 0) { - atlas.anim.addBySymbolIndices(selected_animation.name, selected_animation.animation_name, selected_animation.indices, selected_animation.fps, selected_animation.looped); + atlas.anim.addBySymbolIndices(selected_animation.name, selected_animation.animation_name, selected_animation.indices, + selected_animation.fps, selected_animation.looped); } else { atlas.anim.addBySymbol(selected_animation.name, selected_animation.animation_name, selected_animation.fps, selected_animation.looped); } @@ -279,9 +275,8 @@ class Character extends FlxSprite { else { if (dancesLeftAndRight) playAnim("danceRight"); - else{ + else { playAnim("idle"); - } } @@ -319,6 +314,7 @@ class Character extends FlxSprite { } else { otherCharacters = []; mainCharacterID = config.mainCharacterID; + followMainCharacter = config.followMainCharacter; for (characterData in config.characters) { var character:Character; @@ -344,14 +340,12 @@ class Character extends FlxSprite { barColor = FlxColor.fromRGB(config.barColor[0], config.barColor[1], config.barColor[2]); var localKeyCount; - if(FlxG.state == PlayState.instance){ + if (FlxG.state == PlayState.instance) { localKeyCount = isPlayer ? PlayState.SONG.playerKeyCount : PlayState.SONG.keyCount; - } - else{ + } else { localKeyCount = 4; } - if (config.cameraOffset != null) { if (flipX) config.cameraOffset[0] = 0 - config.cameraOffset[0]; @@ -392,20 +386,15 @@ class Character extends FlxSprite { override function update(elapsed:Float) { if (!debugMode && curCharacter != '' && hasAnims()) { - if(curAnimFinished() && hasAnim(curAnimName() + '-loop')) - { - playAnim(curAnimName() + '-loop'); - } - else if (playFullAnim && curAnimFinished()) - { - playFullAnim = false; - dance(''); - } - else if (preventDanceForAnim && curAnimFinished()) - { - preventDanceForAnim = false; - dance(''); - } + if (curAnimFinished() && hasAnim(curAnimName() + '-loop')) { + playAnim(curAnimName() + '-loop'); + } else if (playFullAnim && curAnimFinished()) { + playFullAnim = false; + dance(''); + } else if (preventDanceForAnim && curAnimFinished()) { + preventDanceForAnim = false; + dance(''); + } if (!isPlayer) { if (curAnimName().startsWith('sing')) holdTimer += elapsed * (FlxG.state == PlayState.instance ? PlayState.songMultiplier : 1); @@ -422,29 +411,28 @@ class Character extends FlxSprite { playAnim('danceRight'); } } - + if (atlasMode && atlas != null) { atlas.update(elapsed); } super.update(elapsed); - } private var danced:Bool = false; public var lastAnim:String = ''; + var mostRecentAlt:String = ""; public inline function curAnimLooped():Bool { @:privateAccess - return (!atlasMode && animation.curAnim != null && animation.curAnim.looped) || - (atlasMode && atlas.anim.loopType == flxanimate.data.AnimationData.Loop.Loop); + return (!atlasMode && animation.curAnim != null && animation.curAnim.looped) + || (atlasMode && atlas.anim.loopType == flxanimate.data.AnimationData.Loop.Loop); } public inline function curAnimFinished():Bool { - return (!atlasMode && animation.curAnim != null && animation.curAnim.finished) || - (atlasMode && atlas.anim.finished); + return (!atlasMode && animation.curAnim != null && animation.curAnim.finished) || (atlasMode && atlas.anim.finished); } public function curAnimName():String { @@ -477,9 +465,7 @@ class Character extends FlxSprite { var alt:String = ''; if ((!dancesLeftAndRight && hasAnim("idle" + altAnim)) - || (dancesLeftAndRight - && hasAnim("danceLeft" + altAnim) - && hasAnim("danceRight" + altAnim))) + || (dancesLeftAndRight && hasAnim("danceLeft" + altAnim) && hasAnim("danceRight" + altAnim))) alt = altAnim; mostRecentAlt = alt; @@ -507,15 +493,15 @@ class Character extends FlxSprite { public function playAnim(AnimName:String, Force:Bool = false, Reversed:Bool = false, Frame:Int = 0):Void { if (playFullAnim || !hasAnim(AnimName)) return; - - if (singAnimPrefix != 'sing' && AnimName.contains('sing')){ + + if (singAnimPrefix != 'sing' && AnimName.contains('sing')) { var anim:String = AnimName; anim = anim.replace('sing', singAnimPrefix); - if (animation.getByName(anim) != null) //check if it exists so no broken anims + if (animation.getByName(anim) != null) // check if it exists so no broken anims AnimName = anim; } - preventDanceForAnim = false; //reset it + preventDanceForAnim = false; // reset it if (atlasMode && atlas != null) { atlas.anim.play(AnimName, Force, Reversed, Frame); @@ -536,14 +522,14 @@ class Character extends FlxSprite { } public inline function addOffset(name:String, x:Float = 0, y:Float = 0) { - animOffsets.set(name, [(isPlayer && offsetsFlipWhenPlayer) || (!isPlayer && offsetsFlipWhenEnemy) ? -x : x, y]); + animOffsets.set(name, [ + (isPlayer && offsetsFlipWhenPlayer) || (!isPlayer && offsetsFlipWhenEnemy) ? -x : x, + y + ]); } - - public function getMainCharacter():Character - { - if (otherCharacters?.length > 0 && mainCharacterID > 0) - { + public function getMainCharacter():Character { + if (otherCharacters != null && otherCharacters.length > 0 && followMainCharacter) { return otherCharacters[mainCharacterID]; } return this; diff --git a/source/game/SongLoader.hx b/source/game/SongLoader.hx index 4702eddcb4..3391784d0c 100644 --- a/source/game/SongLoader.hx +++ b/source/game/SongLoader.hx @@ -239,9 +239,9 @@ typedef Section = { var changeTimeScale:Bool; } -enum abstract ChartType(Int){ - var LEGACY = 0; - var VSLICE = 1; +enum abstract ChartType(String) to String from String{ + var LEGACY = "LEGACY"; + var VSLICE = "VSLICE"; } typedef SongData = { diff --git a/source/modding/CharacterConfig.hx b/source/modding/CharacterConfig.hx index dee1dd5df6..0714e49765 100644 --- a/source/modding/CharacterConfig.hx +++ b/source/modding/CharacterConfig.hx @@ -30,6 +30,7 @@ typedef CharacterConfig = var antialiased:Null; var antialiasing:Null; var mainCharacterID:Null; + var followMainCharacter:Null; /** * Any extra spritesheets to be with the main sheet. */ diff --git a/source/modding/ModchartUtilities.hx b/source/modding/ModchartUtilities.hx index 6d14579310..2c50e852fc 100644 --- a/source/modding/ModchartUtilities.hx +++ b/source/modding/ModchartUtilities.hx @@ -210,13 +210,13 @@ class ModchartUtilities { perlin = new Perlin(); - lua_Sprites.set("boyfriend", PlayState.boyfriend.getMainCharacter()); - lua_Sprites.set("girlfriend", PlayState.gf.getMainCharacter()); - lua_Sprites.set("dad", PlayState.dad.getMainCharacter()); + lua_Sprites.set("boyfriend", PlayState.boyfriend); + lua_Sprites.set("girlfriend", PlayState.gf); + lua_Sprites.set("dad", PlayState.dad); - lua_Characters.set("boyfriend", PlayState.boyfriend.getMainCharacter()); - lua_Characters.set("girlfriend", PlayState.gf.getMainCharacter()); - lua_Characters.set("dad", PlayState.dad.getMainCharacter()); + lua_Characters.set("boyfriend", PlayState.boyfriend); + lua_Characters.set("girlfriend", PlayState.gf); + lua_Characters.set("dad", PlayState.dad); lua_Cameras.set("game", {cam: PlayState.instance.camGame, shaders: [], shaderNames: []}); lua_Cameras.set("hud", {cam: PlayState.instance.camHUD, shaders: [], shaderNames: []}); @@ -3415,9 +3415,9 @@ class ModchartUtilities { lua_Sprites.set("girlfriend", PlayState.gf); lua_Sprites.set("dad", PlayState.dad); - lua_Characters.set("boyfriend", PlayState.boyfriend.getMainCharacter()); - lua_Characters.set("girlfriend", PlayState.gf.getMainCharacter()); - lua_Characters.set("dad", PlayState.dad.getMainCharacter()); + lua_Characters.set("boyfriend", PlayState.boyfriend); + lua_Characters.set("girlfriend", PlayState.gf); + lua_Characters.set("dad", PlayState.dad); lua_Sounds.set("Inst", FlxG.sound.music); lua_Sounds.set("Voices", PlayState.instance.vocals.members[0]); @@ -3431,8 +3431,8 @@ class ModchartUtilities { } if (PlayState.dad.otherCharacters != null) { - lua_Sprites.set('dad', PlayState.dad.getMainCharacter()); - lua_Characters.set('dad', PlayState.dad.getMainCharacter()); + lua_Sprites.set('dad', PlayState.dad.otherCharacters[PlayState.dad.mainCharacterID]); + lua_Characters.set('dad', PlayState.dad.otherCharacters[PlayState.dad.mainCharacterID]); for (char in 0...PlayState.dad.otherCharacters.length) { lua_Sprites.set("dadCharacter" + char, PlayState.dad.otherCharacters[char]); lua_Characters.set("dadCharacter" + char, PlayState.dad.otherCharacters[char]); @@ -3440,8 +3440,8 @@ class ModchartUtilities { } if (PlayState.boyfriend.otherCharacters != null) { - lua_Sprites.set('boyfriend', PlayState.boyfriend.getMainCharacter()); - lua_Characters.set('boyfriend', PlayState.boyfriend.getMainCharacter()); + lua_Sprites.set('boyfriend', PlayState.boyfriend.otherCharacters[PlayState.boyfriend.mainCharacterID]); + lua_Characters.set('boyfriend', PlayState.boyfriend.otherCharacters[PlayState.boyfriend.mainCharacterID]); for (char in 0...PlayState.boyfriend.otherCharacters.length) { lua_Sprites.set("bfCharacter" + char, PlayState.boyfriend.otherCharacters[char]); lua_Characters.set("bfCharacter" + char, PlayState.boyfriend.otherCharacters[char]); @@ -3449,8 +3449,8 @@ class ModchartUtilities { } if (PlayState.gf.otherCharacters != null) { - lua_Sprites.set('girlfriend', PlayState.gf.getMainCharacter()); - lua_Characters.set('girlfriend', PlayState.gf.getMainCharacter()); + lua_Sprites.set('girlfriend', PlayState.gf.otherCharacters[PlayState.gf.mainCharacterID]); + lua_Characters.set('girlfriend', PlayState.gf.otherCharacters[PlayState.gf.mainCharacterID]); for (char in 0...PlayState.gf.otherCharacters.length) { lua_Sprites.set("gfCharacter" + char, PlayState.gf.otherCharacters[char]); lua_Characters.set("gfCharacter" + char, PlayState.gf.otherCharacters[char]); diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index 75a0c918e9..b49e2c80f6 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -2095,7 +2095,7 @@ class PlayState extends MusicBeatState { camFollow.y *= 0.5; if (PlayState.SONG.notes[Std.int(curStep / Conductor.stepsPerSection)].mustHitSection) { if (Options.getData("cameraTracksDirections") && boyfriend.getMainCharacter().hasAnims()) { - switch (boyfriend.curAnimName().toLowerCase()) { + switch (boyfriend.getMainCharacter().curAnimName().toLowerCase()) { case "singleft": camFollow.x -= 50; case "singright": @@ -2108,7 +2108,7 @@ class PlayState extends MusicBeatState { } } else { if (Options.getData("cameraTracksDirections") && dad.getMainCharacter().hasAnims()) { - switch (dad.curAnimName().toLowerCase()) { + switch (dad.getMainCharacter().curAnimName().toLowerCase()) { case "singleft": camFollow.x -= 50; case "singright": @@ -2137,7 +2137,7 @@ class PlayState extends MusicBeatState { vocals.stop(); FlxG.sound.music.stop(); - openSubState(new GameOverSubstate(boyfriend.getMainCharacter().getScreenPosition().x, boyfriend.getMainCharacter().getScreenPosition().y)); + openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); #if DISCORD_ALLOWED // Game Over doesn't get his own variable because it's only used here @@ -3737,8 +3737,6 @@ class PlayState extends MusicBeatState { return PlayState.gf.getMainCharacter(); case "dad" | "opponent" | "player2" | "1": return PlayState.dad.getMainCharacter(); - case "bf" | "boyfriend" | "player" | "player1" | "0": - return PlayState.boyfriend.getMainCharacter(); } return PlayState.boyfriend.getMainCharacter();