Skip to content

Commit 5c72bea

Browse files
committed
Paths.content.animateAtlas, and attempt for DJ Visualizer
Signed-off-by: TechnikTil <techniktil@tilnotdrip.org>
1 parent 39508f7 commit 5c72bea

9 files changed

Lines changed: 16590 additions & 288380 deletions

File tree

assets/ui/freeplay/freeplay-boyfriend/Animation.json

Lines changed: 16174 additions & 288025 deletions
Large diffs are not rendered by default.

assets/ui/freeplay/freeplay-boyfriend/spritemap1.json

Lines changed: 289 additions & 289 deletions
Large diffs are not rendered by default.
492 KB
Loading
375 Bytes
Binary file not shown.

src/funkin/objects/FunkinSprite.hx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class FunkinSprite extends FlxAnimate
1717
*/
1818
public var doInvisibleDraw:Bool = false;
1919

20+
/**
21+
* Settings to use when initializing texture atlases.
22+
*/
23+
public var atlasSettings:FlxAnimateSettings = {};
24+
2025
public function new(x:Float = 0, y:Float = 0)
2126
{
2227
super(x, y);
@@ -64,7 +69,7 @@ class FunkinSprite extends FlxAnimate
6469
}
6570
else if (Paths.location.exists(path + '/Animation.json'))
6671
{
67-
frames = FlxAnimateFrames.fromAnimate(Paths.location.get(path));
72+
frames = Paths.content.animateAtlas(path, atlasSettings);
6873
}
6974

7075
return this;

src/funkin/objects/ui/freeplay/FreeplayDJ.hx

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package funkin.objects.ui.freeplay;
22

3+
import animate.internal.Timeline;
4+
import animate.internal.elements.Element;
5+
import animate.internal.elements.SymbolInstance;
36
import flixel.util.FlxSignal;
7+
import funkin.util.visualizer.AnalyzerAnimationHelper;
48

59
/*
610
TODO: MAKE THIS LESS HARDCODED!
@@ -17,9 +21,18 @@ class FreeplayDJ extends FunkinSprite
1721
*/
1822
public var introDone:FlxSignal = new FlxSignal();
1923

24+
var analyzerHelper:AnalyzerAnimationHelper;
25+
2026
public function new(x:Float, y:Float, id:String)
2127
{
2228
super(x, y);
29+
analyzerHelper = new AnalyzerAnimationHelper(null, 3, 4);
30+
31+
// TODO: enable this, it currently breaks the visualizer.
32+
atlasSettings = {
33+
swfMode: false,
34+
filterQuality: HIGH
35+
};
2336

2437
// todo: softcode this
2538
switch (id)
@@ -46,8 +59,7 @@ class FreeplayDJ extends FunkinSprite
4659
case Intro:
4760
currentState = Idle;
4861
introDone.dispatch();
49-
// TODO: invalid cast
50-
// cast(this, FreeplayDJAtlas)?.initVisualizer(FlxG.sound.music);
62+
initVisualizer(FlxG.sound.music);
5163

5264
default:
5365
}
@@ -118,6 +130,46 @@ class FreeplayDJ extends FunkinSprite
118130
#end
119131
}
120132

133+
/**
134+
* Initializes the visualizer with `snd`.
135+
* @param snd The sound to initialize with.
136+
*/
137+
public function initVisualizer(snd:FlxSound):Void
138+
{
139+
analyzerHelper.snd = snd;
140+
analyzerHelper.initAnalyzer(35);
141+
}
142+
143+
override public function draw():Void
144+
{
145+
if (analyzerHelper.ready)
146+
{
147+
analyzerHelper.updateFFT();
148+
149+
var ttLightsTimeline:Null<Timeline> = library.getSymbol("turn table lights")?.timeline;
150+
151+
if (ttLightsTimeline != null)
152+
{
153+
for (i => layer in ttLightsTimeline.layers)
154+
{
155+
var elements:Null<Array<Element>> = layer?.getFrameAtIndex(ttLightsTimeline.currentFrame)?.elements;
156+
157+
for (element in elements ?? [])
158+
{
159+
var symbol:SymbolInstance = element?.toSymbolInstance();
160+
if (symbol == null)
161+
continue;
162+
163+
symbol.loopType = PLAY_ONCE;
164+
symbol.firstFrame = analyzerHelper.frameMap[i];
165+
}
166+
}
167+
}
168+
}
169+
170+
super.draw();
171+
}
172+
121173
override public function playAnimation(name:String, ?restart:Bool = false, ?stunAnimations:Bool = false, ?reversed:Bool = false):Void
122174
{
123175
super.playAnimation(name, restart, stunAnimations, reversed);

src/funkin/objects/ui/freeplay/FreeplayDJAtlas.hx

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/funkin/util/paths/PathsContent.hx

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package funkin.util.paths;
22

3+
import animate.FlxAnimateFrames;
34
import flixel.graphics.FlxGraphic;
45
import flixel.graphics.frames.FlxAtlasFrames;
56
import flixel.graphics.frames.FlxFramesCollection;
7+
import haxe.io.Path;
68
import openfl.display.BitmapData;
79
import openfl.media.Sound;
810

911
/**
1012
* A Paths class that helps returning objects or content based on stuff inside files.
1113
*/
14+
@:access(animate.FlxAnimateFrames)
1215
class PathsContent
1316
{
1417
/**
@@ -80,6 +83,58 @@ class PathsContent
8083
return FlxAtlasFrames.fromSparrow(imageGraphic(key), xml(key));
8184
}
8285

86+
/**
87+
* Returns animate atlas information.
88+
* @param key The folder key to use for the information.
89+
* @return Animate Frames with information about the atlas.
90+
*/
91+
public function animateAtlas(key:String, settings:FlxAnimateSettings):Null<FlxAnimateFrames>
92+
{
93+
var path:String = Path.removeTrailingSlashes(key);
94+
95+
var hasAnimation:Bool = Paths.location.exists('${path}/Animation.json');
96+
if (!hasAnimation)
97+
{
98+
trace('[ERROR] No Animation.json file found for ${key}!');
99+
return null;
100+
}
101+
102+
var animation:String = text('${path}/Animation.json');
103+
var spritemaps:Array<SpritemapInput> = [];
104+
105+
var isInlined:Bool = !Paths.location.exists('${path}/metadata.json');
106+
var metadata:Null<String> = null;
107+
108+
var libraryList:Null<Array<String>> = null;
109+
110+
if (!isInlined)
111+
{
112+
metadata = text('${path}/metadata.json');
113+
libraryList = Paths.location.scan('${path}/LIBRARY', '.json', true, FILE, false);
114+
}
115+
116+
for (spritemap in Paths.location.scan(path, '.json', true, FILE, false))
117+
{
118+
if (!spritemap.startsWith('spritemap'))
119+
continue;
120+
121+
spritemaps.push({
122+
source: imageGraphic('${path}/${spritemap}'),
123+
json: text('${path}/${spritemap}.json')
124+
});
125+
}
126+
127+
if (spritemaps.length < 1)
128+
{
129+
trace('[ERROR] No spritemaps found for ${key}!');
130+
return null;
131+
}
132+
133+
var frames:FlxAnimateFrames = FlxAnimateFrames._fromAnimateInput(animation, spritemaps, metadata, path, isInlined, libraryList, settings);
134+
FlxAnimateFrames._cachedAtlases.remove(path);
135+
return frames;
136+
}
137+
83138
/**
84139
* Returns text from a file.
85140
* @param key The text key to use for returning the text inside.
@@ -98,7 +153,9 @@ class PathsContent
98153
*/
99154
public function rawText(path:String):String
100155
{
101-
return FlxG.assets.getText(path, false);
156+
var text:String = FlxG.assets.getText(path, false);
157+
text = text.replace(String.fromCharCode(0xFEFF), "");
158+
return text;
102159
}
103160

104161
/**

src/funkin/util/visualizer/AnalyzerAnimationHelper.hx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ class AnalyzerAnimationHelper
66
{
77
var analyzer:SpectralAnalyzer;
88

9-
var barCount:Int;
10-
var barHeight:Int;
9+
/**
10+
* The bar count for the analyzer.
11+
*/
12+
public var barCount:Int;
13+
14+
/**
15+
* The bar height for the analyzer.
16+
*/
17+
public var barHeight:Int;
1118

1219
/**
1320
* The sound to use for this analyzer.

0 commit comments

Comments
 (0)