Skip to content

Commit

Permalink
fix some compatability and bugs with character groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Dec 4, 2024
1 parent d87dfd5 commit bca9878
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 89 deletions.
1 change: 1 addition & 0 deletions assets/preload/data/character data/gf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cameraOffset": [-40, -250],
"barColor": [186, 49, 104],
"mainCharacterID": 1,
"followMainCharacter": true,
"characters": [
{
"name": "speakers",
Expand Down
4 changes: 2 additions & 2 deletions mods/Friday Night Funkin'/data/character data/nene/script.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
Expand Down
114 changes: 50 additions & 64 deletions source/game/Character.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import modding.CharacterConfig;
import modding.scripts.languages.HScript;
import states.PlayState;


/**
* The base character class.
*/
Expand All @@ -38,6 +37,7 @@ class Character extends FlxSprite {

public var otherCharacters:Array<Character>;
public var mainCharacterID:Int = 0;
public var followMainCharacter:Bool = false;

public var offsetsFlipWhenPlayer:Bool = true;
public var offsetsFlipWhenEnemy:Bool = false;
Expand All @@ -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<String, Array<Dynamic>>();
Expand Down Expand Up @@ -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<Int> = animation.getByName('singRIGHT').frames;
Expand All @@ -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);
}
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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.
}
}

Expand All @@ -259,15 +253,17 @@ 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);
}
}
} 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);
}
Expand All @@ -279,9 +275,8 @@ class Character extends FlxSprite {
else {
if (dancesLeftAndRight)
playAnim("danceRight");
else{
else {
playAnim("idle");

}
}

Expand Down Expand Up @@ -319,6 +314,7 @@ class Character extends FlxSprite {
} else {
otherCharacters = [];
mainCharacterID = config.mainCharacterID;
followMainCharacter = config.followMainCharacter;

for (characterData in config.characters) {
var character:Character;
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions source/game/SongLoader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions source/modding/CharacterConfig.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef CharacterConfig =
var antialiased:Null<Bool>;
var antialiasing:Null<Bool>;
var mainCharacterID:Null<Int>;
var followMainCharacter:Null<Bool>;
/**
* Any extra spritesheets to be with the main sheet.
*/
Expand Down
30 changes: 15 additions & 15 deletions source/modding/ModchartUtilities.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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: []});
Expand Down Expand Up @@ -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]);
Expand All @@ -3431,26 +3431,26 @@ 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]);
}
}

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]);
}
}

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]);
Expand Down
Loading

0 comments on commit bca9878

Please sign in to comment.