From 056ccf9fb0e6e047243effd47cdb5a5a9333e15e Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Tue, 6 Dec 2022 13:35:24 +0100 Subject: [PATCH] titlescreen --- assets/data/titlescreen/titlescreen.xml | 8 ++- buildnumber.txt | 2 +- source/funkin/game/Stage.hx | 66 +------------------------ source/funkin/menus/TitleState.hx | 44 +++++++---------- source/funkin/system/MusicBeatGroup.hx | 14 ++++++ source/funkin/system/XMLUtil.hx | 63 +++++++++++++++++++++++ 6 files changed, 106 insertions(+), 91 deletions(-) create mode 100644 source/funkin/system/MusicBeatGroup.hx diff --git a/assets/data/titlescreen/titlescreen.xml b/assets/data/titlescreen/titlescreen.xml index 7ffecdb1..f6a3fc0b 100644 --- a/assets/data/titlescreen/titlescreen.xml +++ b/assets/data/titlescreen/titlescreen.xml @@ -1,7 +1,13 @@ - + + + + + + + diff --git a/buildnumber.txt b/buildnumber.txt index 669268d4..979b6660 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1395 \ No newline at end of file +1400 \ No newline at end of file diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index 12d74953..8aa3d4aa 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -57,48 +57,9 @@ class Stage extends FlxBasic implements IBeatReceiver { case "sprite" | "spr" | "sparrow": if (!node.has.sprite || !node.has.name || !node.has.x || !node.has.y) continue; - var spr = new StageSprite(node.att.name); - spr.antialiasing = true; - - spr.loadAnimatedGraphic(Paths.image('$spritesParentFolder${node.att.sprite}', null, true)); - - var x:Null = Std.parseFloat(node.att.x); - var y:Null = Std.parseFloat(node.att.y); - if (x != null) spr.x = x; - if (y != null) spr.y = y; - if (node.has.scroll) { - var scroll:Null = Std.parseFloat(node.att.scroll); - if (scroll != null) spr.scrollFactor.set(scroll, scroll); - } else { - if (node.has.scrollx) { - var scroll:Null = Std.parseFloat(node.att.scrollx); - if (scroll != null) spr.scrollFactor.x = scroll; - } - if (node.has.scrolly) { - var scroll:Null = Std.parseFloat(node.att.scrolly); - if (scroll != null) spr.scrollFactor.y = scroll; - } - } - if (node.has.antialiasing) spr.antialiasing = node.att.antialiasing == "true"; - if (node.has.scale) { - var scale:Null = Std.parseFloat(node.att.scale); - if (scale != null) spr.scale.set(scale, scale); - } - if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox(); - - for(anim in node.nodes.anim) { - if (anim.has.name) spr.beatAnims.push(anim.att.name); - XMLUtil.addXMLAnimation(spr, anim); - } - if (node.has.beatAnim && node.att.beatAnim.trim() != "") spr.beatAnims = [for(e in node.att.beatAnim.split(",")) e.trim()]; - - if (node.has.anim) { - spr.animation.play(node.att.anim, true); - } else if (spr.beatAnims.length > 0) { - spr.animation.play(spr.beatAnims[0], true); - } + var spr = XMLUtil.createSpriteFromXML(node, spritesParentFolder); - stageSprites.set(node.att.name, spr); + stageSprites.set(spr.name, spr); state.add(spr); spr; case "boyfriend" | "bf": @@ -164,27 +125,4 @@ class Stage extends FlxBasic implements IBeatReceiver { public function beatHit(curBeat:Int) {} public function stepHit(curStep:Int) {} -} - -class StageSprite extends FlxSprite implements IBeatReceiver { - public var beatAnims:Array = []; - public var name:String; - - public function new(name:String) { - super(); - this.name = name; - } - public override function update(elapsed:Float) { - super.update(elapsed); - } - - public function beatHit(curBeat:Int) { - if (beatAnims.length > 0) { - var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)]; - if (anim != null && anim != "null" && anim != "none") - animation.play(anim); - } - - } - public function stepHit(curBeat:Int) {} } \ No newline at end of file diff --git a/source/funkin/menus/TitleState.hx b/source/funkin/menus/TitleState.hx index fef10af8..822380ec 100644 --- a/source/funkin/menus/TitleState.hx +++ b/source/funkin/menus/TitleState.hx @@ -1,5 +1,7 @@ package funkin.menus; +import funkin.system.MusicBeatGroup; +import funkin.system.XMLUtil; import flixel.util.typeLimit.OneOfThree; import flixel.util.typeLimit.OneOfTwo; import flixel.FlxG; @@ -56,6 +58,7 @@ class TitleState extends MusicBeatState var gfDance:FlxSprite; var danceLeft:Bool = false; var titleText:FlxSprite; + var titleScreenSprites:MusicBeatGroup; function startIntro() { @@ -64,28 +67,15 @@ class TitleState extends MusicBeatState persistentUpdate = true; - loadXML(); - var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK); add(bg); - logoBl = new FlxSprite(-150, -100); - logoBl.frames = Paths.getFrames('logoBumpin'); - logoBl.antialiasing = true; - logoBl.animation.addByPrefix('bump', 'logo bumpin', 24); - logoBl.animation.play('bump'); - logoBl.updateHitbox(); - - gfDance = new FlxSprite(FlxG.width * 0.4, FlxG.height * 0.07); - gfDance.frames = Paths.getFrames('gfDanceTitle'); - gfDance.animation.addByIndices('danceLeft', 'gfDance', [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], "", 24, false); - gfDance.animation.addByIndices('danceRight', 'gfDance', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "", 24, false); - gfDance.antialiasing = true; - add(gfDance); - add(logoBl); + titleScreenSprites = new MusicBeatGroup(); + add(titleScreenSprites); + loadXML(); titleText = new FlxSprite(100, FlxG.height * 0.8); - titleText.frames = Paths.getFrames('titleEnter'); + titleText.frames = Paths.getFrames('menus/titlescreen/titleEnter'); titleText.animation.addByPrefix('idle', "Press Enter to Begin", 24); titleText.animation.addByPrefix('press', "ENTER PRESSED", 24); titleText.antialiasing = true; @@ -211,14 +201,6 @@ class TitleState extends MusicBeatState { super.beatHit(curBeat); - logoBl.animation.play('bump'); - danceLeft = !danceLeft; - - if (danceLeft) - gfDance.animation.play('danceRight'); - else - gfDance.animation.play('danceLeft'); - #if TITLESCREEN_XML if (curBeat >= titleLength || skippedIntro) { if (!skippedIntro) skipIntro(); @@ -275,6 +257,18 @@ class TitleState extends MusicBeatState if (xml.hasNode.intro) { titleLines = []; if (xml.node.intro.has.length) titleLength = CoolUtil.getDefault(Std.parseInt(xml.node.intro.att.length), 16); + for(node in xml.nodes.sprites) { + var parentFolder:String = node.getAtt("folder").getDefault(""); + if (parentFolder != "" && !parentFolder.endsWith("/")) parentFolder += "/"; + for(sprNode in node.elements) { + var spr = XMLUtil.createSpriteFromXML(sprNode, parentFolder); + switch(node.name) { + // TODO: press enter to begin customisation + default: + titleScreenSprites.add(spr); + } + } + } for(text in xml.node.intro.nodes.text) { var beat:Int = CoolUtil.getDefault(text.has.beat ? Std.parseInt(text.att.beat) : null, 0); var texts:Array> = []; diff --git a/source/funkin/system/MusicBeatGroup.hx b/source/funkin/system/MusicBeatGroup.hx new file mode 100644 index 00000000..9e241bb0 --- /dev/null +++ b/source/funkin/system/MusicBeatGroup.hx @@ -0,0 +1,14 @@ +package funkin.system; + +import flixel.FlxSprite; +import funkin.interfaces.IBeatReceiver; +import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; + +class MusicBeatGroup extends FlxTypedSpriteGroup implements IBeatReceiver { + public function beatHit(curBeat:Int) { + for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).beatHit(curBeat); + } + public function stepHit(curStep:Int) { + for(e in members) if (e is IBeatReceiver) cast(e, IBeatReceiver).stepHit(curStep); + } +} \ No newline at end of file diff --git a/source/funkin/system/XMLUtil.hx b/source/funkin/system/XMLUtil.hx index 672fa46b..acc6cf92 100644 --- a/source/funkin/system/XMLUtil.hx +++ b/source/funkin/system/XMLUtil.hx @@ -1,5 +1,7 @@ package funkin.system; +import flixel.math.FlxMath; +import funkin.interfaces.IBeatReceiver; import haxe.xml.Access; import funkin.interfaces.IOffsetCompatible; import flixel.FlxSprite; @@ -39,6 +41,48 @@ class XMLUtil { return OK; } + /** + * Creates a new sprite based on a XML node. + */ + public static function createSpriteFromXML(node:Access, parentFolder:String = "", ?cl:Class):XMLSprite { + if (parentFolder == null) parentFolder = ""; + + var spr = cl != null ? Type.createInstance(cl, []) : new XMLSprite(); + spr.name = node.getAtt("name"); + spr.antialiasing = true; + + spr.loadAnimatedGraphic(Paths.image('$parentFolder${node.getAtt("sprite")}', null, true)); + + var x:Null = node.has.x ? Std.parseFloat(node.att.x) : null; + var y:Null = node.has.y ? Std.parseFloat(node.att.y) : null; + if (x != null) spr.x = x; + if (y != null) spr.y = y; + if (node.has.scroll) { + var scroll:Null = Std.parseFloat(node.att.scroll); + if (scroll != null) spr.scrollFactor.set(scroll, scroll); + } else { + if (node.has.scrollx) { + var scroll:Null = Std.parseFloat(node.att.scrollx); + if (scroll != null) spr.scrollFactor.x = scroll; + } + if (node.has.scrolly) { + var scroll:Null = Std.parseFloat(node.att.scrolly); + if (scroll != null) spr.scrollFactor.y = scroll; + } + } + if (node.has.antialiasing) spr.antialiasing = node.att.antialiasing == "true"; + if (node.has.scale) { + var scale:Null = Std.parseFloat(node.att.scale); + if (scale != null) spr.scale.set(scale, scale); + } + if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox(); + + for(anim in node.nodes.anim) + addXMLAnimation(spr, anim); + + return spr; + } + /** * Adds an XML animation to `sprite`. * @param sprite Destination sprite @@ -95,4 +139,23 @@ typedef AnimData = { var x:Float; var y:Float; var indices:Array; +} + +class XMLSprite extends FlxSprite implements IBeatReceiver { + public var beatAnims:Array = []; + public var name:String; + + public override function update(elapsed:Float) { + super.update(elapsed); + } + + public function beatHit(curBeat:Int) { + if (beatAnims.length > 0) { + var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)]; + if (anim != null && anim != "null" && anim != "none") + animation.play(anim); + } + + } + public function stepHit(curBeat:Int) {} } \ No newline at end of file