Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Softcoded Backing Cards #3685

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/funkin/data/freeplay/player/PlayerData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class PlayerFreeplayDJData
@:default("PROTECT YO NUTS")
var text3:String;

@:optional
@:default('BackingCard')
public var backcardClassName:String = 'BackingCard';

@:jignored
var animationMap:Map<String, AnimationData>;

Expand Down
45 changes: 35 additions & 10 deletions source/funkin/ui/freeplay/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import funkin.util.SortUtil;
import openfl.display.BlendMode;
import funkin.data.freeplay.style.FreeplayStyleRegistry;
import funkin.data.song.SongData.SongMusicData;
import funkin.util.macro.ClassMacro;
#if FEATURE_DISCORD_RPC
import funkin.api.discord.DiscordClient;
#end
Expand Down Expand Up @@ -221,16 +222,40 @@ class FreeplayState extends MusicBeatSubState

if (stickers?.members != null) stickerSubState = stickers;

switch (currentCharacterId)
if (PlayerRegistry.instance.hasNewCharacter())
{
case(PlayerRegistry.instance.hasNewCharacter()) => true:
backingCard = new NewCharacterCard(currentCharacter);
case 'bf':
backingCard = new BoyfriendCard(currentCharacter);
case 'pico':
backingCard = new PicoCard(currentCharacter);
default:
backingCard = new BackingCard(currentCharacter);
backingCard = new NewCharacterCard(currentCharacter);
}
else
{
for (className in ScriptedBackingCard.listScriptClasses())
{
if (className == currentCharacter.getBackcardClassName())
{
backingCard = ScriptedBackingCard.init(className, currentCharacter, null);
break;
}
}

if (backingCard == null)
{
for (cls in ClassMacro.listClassesInPackage('funkin.ui.freeplay.backcards'))
{
if (cls == null) continue;
var className:String = Type.getClassName(cls).split('.')?.pop() ?? '';

if (className == currentCharacter.getBackcardClassName())
{
backingCard = Type.createInstance(cls, [currentCharacter, null]);
break;
}
}
}
}

if (backingCard == null)
{
backingCard = new BackingCard(currentCharacter, null);
}

// We build a bunch of sprites BEFORE create() so we can guarantee they aren't null later on.
Expand Down Expand Up @@ -327,7 +352,7 @@ class FreeplayState extends MusicBeatSubState
if (backingCard != null)
{
add(backingCard);
backingCard.init();
backingCard.initCard();
backingCard.applyExitMovers(exitMovers, exitMoversCharSel);
backingCard.instance = this;
}
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/freeplay/backcards/BackingCard.hx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class BackingCard extends FlxSpriteGroup
/**
* Called in create. Adds sprites and tweens.
*/
public function init():Void
public function initCard():Void
{
FlxTween.tween(pinkBack, {x: 0}, 0.6, {ease: FlxEase.quartOut});
add(pinkBack);
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/freeplay/backcards/BoyfriendCard.hx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class BoyfriendCard extends BackingCard
funnyScroll3 = new BGScrollingText(0, orangeBackShit.y + 10, currentCharacter.getFreeplayDJText(1), FlxG.width / 2, 60);
}

public override function init():Void
public override function initCard():Void
{
FlxTween.tween(pinkBack, {x: 0}, 0.6, {ease: FlxEase.quartOut});
add(pinkBack);
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/freeplay/backcards/NewCharacterCard.hx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class NewCharacterCard extends BackingCard
FlxTween.tween(newUnlock3, {speed: 0}, 0.8, {ease: FlxEase.sineIn});
}

public override function init():Void
public override function initCard():Void
{
FlxTween.tween(pinkBack, {x: 0}, 0.6, {ease: FlxEase.quartOut});
add(pinkBack);
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/freeplay/backcards/PicoCard.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class PicoCard extends BackingCard
});
}

public override function init():Void
public override function initCard():Void
{
FlxTween.tween(pinkBack, {x: 0}, 0.6, {ease: FlxEase.quartOut});
add(pinkBack);
Expand Down
8 changes: 8 additions & 0 deletions source/funkin/ui/freeplay/backcards/ScriptedBackingCard.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package funkin.ui.freeplay.backcards;

/**
* A script that can be tied to a BackingCard.
* Create a scripted class that extends BackingCard to use this.
*/
@:hscriptClass
class ScriptedBackingCard extends funkin.ui.freeplay.backcards.BackingCard implements polymod.hscript.HScriptedClass {}
8 changes: 8 additions & 0 deletions source/funkin/ui/freeplay/charselect/PlayableCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ class PlayableCharacter implements IRegistryEntry<PlayerData>
return _data?.unlocked ?? true;
}

/**
* Returns the Class that Freeplay should use for the backing card.
*/
public function getBackcardClassName():String
{
return _data?.freeplayDJ?.backcardClassName ?? 'BackingCard';
}

/**
* Called when the character is destroyed.
* TODO: Document when this gets called
Expand Down
Loading