Rework credits data structure.

This commit is contained in:
EliteMasterEric 2024-03-28 02:57:22 -04:00
parent 1e888658f7
commit 5311b043ac
3 changed files with 47 additions and 22 deletions

View file

@ -5,7 +5,7 @@ package funkin.ui.credits;
*/ */
typedef CreditsData = typedef CreditsData =
{ {
var roles:Array<CreditsDataRole>; var entries:Array<CreditsDataRole>;
} }
/** /**
@ -13,8 +13,16 @@ typedef CreditsData =
*/ */
typedef CreditsDataRole = typedef CreditsDataRole =
{ {
var roleName:String; @:optional
var members:Array<CreditsDataMember>; var header:String;
@:optional
@:default([])
var body:Array<CreditsDataMember>;
@:optional
@:default(false)
var appendBackers:Bool;
} }
/** /**
@ -22,5 +30,5 @@ typedef CreditsDataRole =
*/ */
typedef CreditsDataMember = typedef CreditsDataMember =
{ {
var fullName:String; var line:String;
} }

View file

@ -24,14 +24,14 @@ class CreditsDataHandler
return; return;
} }
var roleCount = data.roles.length; var entryCount = data.entries.length;
var memberCount = 0; var lineCount = 0;
for (role in data.roles) for (entry in data.entries)
{ {
memberCount += role.members.length; lineCount += entry?.body?.length ?? 0;
} }
trace('CreditsData($roleCount roles with $memberCount members)'); trace('CreditsData($entryCount entries containing $lineCount lines)');
} }
/** /**
@ -43,15 +43,19 @@ class CreditsDataHandler
public static inline function getFallback():CreditsData public static inline function getFallback():CreditsData
{ {
return { return {
roles: [ entries: [
{ {
roleName: 'Founders', header: 'Founders',
members: [ body: [
{fullName: 'ninjamuffin99'}, {line: 'ninjamuffin99'},
{fullName: 'PhantomArcade'}, {line: 'PhantomArcade'},
{fullName: 'KawaiSprite'}, {line: 'KawaiSprite'},
{fullName: 'evilsk8r'}, {line: 'evilsk8r'},
] ]
},
{
header: 'Kickstarter Backers',
appendBackers: true
} }
] ]
}; };

View file

@ -116,17 +116,30 @@ class CreditsState extends MusicBeatState
{ {
var y = 0; var y = 0;
for (role in CreditsDataHandler.CREDITS_DATA.roles) for (entry in CreditsDataHandler.CREDITS_DATA.entries)
{ {
creditsGroup.add(buildCreditsLine(role.roleName, y, true, CreditsSide.Center)); if (entry.header != null)
y += CREDITS_HEADER_FONT_SIZE;
for (member in role.members)
{ {
creditsGroup.add(buildCreditsLine(member.fullName, y, false, CreditsSide.Center)); creditsGroup.add(buildCreditsLine(entry.header, y, true, CreditsSide.Center));
y += CREDITS_HEADER_FONT_SIZE;
}
for (line in entry?.body ?? [])
{
creditsGroup.add(buildCreditsLine(line.line, y, false, CreditsSide.Center));
y += CREDITS_FONT_SIZE; y += CREDITS_FONT_SIZE;
} }
if (entry.appendBackers)
{
var backers = CreditsDataHandler.fetchBackerEntries();
for (backer in backers)
{
creditsGroup.add(buildCreditsLine(backer, y, false, CreditsSide.Center));
y += CREDITS_FONT_SIZE;
}
}
// Padding between each role. // Padding between each role.
y += CREDITS_FONT_SIZE * 2; y += CREDITS_FONT_SIZE * 2;
} }