Skip to content

Commit 42672ef

Browse files
committed
e
1 parent 6a9ac51 commit 42672ef

File tree

3 files changed

+153
-37
lines changed

3 files changed

+153
-37
lines changed

source/objects/NoteSplash.hx

Lines changed: 124 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package objects;
22

33
import backend.animation.PsychAnimationController;
4-
import shaders.RGBPalette;
5-
import flixel.system.FlxAssets.FlxShader;
6-
import objects.charting.ChartingStrumNote;
74
import flixel.FlxSprite;
85
import flixel.animation.FlxBaseAnimation;
96
import flixel.graphics.frames.FlxAtlasFrames;
7+
import flixel.system.FlxAssets.FlxShader;
108
import flixel.util.FlxColor;
11-
import shaders.ColorSwap.ColorSwap;
129
import objects.NoteObject;
10+
import objects.charting.ChartingStrumNote;
11+
import shaders.ColorSwap.ColorSwap;
12+
import shaders.RGBPalette;
1313

1414
typedef RGB = {
1515
r:Null<Int>,
@@ -61,6 +61,8 @@ class NoteSplash extends NoteObject
6161
rgbShader = new PixelSplashShaderRef();
6262
shader = rgbShader.shader;
6363

64+
this.objtype = SPLASH;
65+
6466
loadSplash(splash);
6567
}
6668

@@ -117,8 +119,23 @@ class NoteSplash extends NoteObject
117119
{
118120
var anim:NoteSplashAnim = Reflect.field(config.animations, i);
119121
tempConfig.animations.set(i, anim);
120-
if (anim.noteData % 4 == 0)
121-
maxAnims++;
122+
}
123+
124+
// Calculate maxAnims properly for JSON configs
125+
// Count how many different animation variants we have per key
126+
var animsPerKey:Map<Int, Int> = new Map();
127+
for (anim in tempConfig.animations) {
128+
var baseKey = anim.noteData % 4; // Get base key (0-3)
129+
var variant = Math.floor(anim.noteData / 4) + 1; // Get variant number (1, 2, 3...)
130+
if (!animsPerKey.exists(baseKey) || animsPerKey.get(baseKey) < variant) {
131+
animsPerKey.set(baseKey, variant);
132+
}
133+
}
134+
135+
// maxAnims should be the highest variant number
136+
maxAnims = 0;
137+
for (key => variants in animsPerKey) {
138+
if (variants > maxAnims) maxAnims = variants;
122139
}
123140

124141
this.config = tempConfig;
@@ -172,7 +189,7 @@ class NoteSplash extends NoteObject
172189
} else if (PlayState.mania >= 0 && PlayState.mania < Note.ammo.length) {
173190
keyCount = Note.ammo[PlayState.mania];
174191
}
175-
192+
176193
// Get the appropriate color array for the current key count
177194
var colArray:Array<String> = [];
178195
if (PlayState.mania >= 0 && PlayState.mania < Note.ammo.length && Note.keysShit.exists(PlayState.mania)) {
@@ -182,7 +199,7 @@ class NoteSplash extends NoteObject
182199
colArray = letters.map(letter -> letter.toLowerCase()); // Convert to lowercase for consistency
183200
}
184201
}
185-
202+
186203
// Fallback to default if no proper key data found
187204
if (colArray.length == 0) {
188205
colArray = Note.colArray.copy();
@@ -191,7 +208,7 @@ class NoteSplash extends NoteObject
191208
colArray.push('key${colArray.length}');
192209
}
193210
}
194-
211+
195212
var failedToFind:Bool = false;
196213
while (true)
197214
{
@@ -240,25 +257,38 @@ class NoteSplash extends NoteObject
240257

241258
setPosition(x, y);
242259

243-
if (babyArrow != null)
244-
setPosition(babyArrow.x - Note.swagWidth * 0.95, babyArrow.y - Note.swagWidth); // To prevent it from being misplaced for one game tick
260+
#if debug
261+
trace('NoteSplash: Initial position set to ($x, $y)');
262+
#end
245263

246-
if (babyArrowCharting != null)
247-
setPosition(babyArrowCharting.x - Note.swagWidth * 0.95, babyArrowCharting.y - Note.swagWidth); // Specifically so that the VisualSettingsSubstate stops crying
264+
// Only use babyArrow positioning if we're in editor mode or no position was provided
265+
if (babyArrow != null && (inEditor || (x == 0 && y == 0))) {
266+
setPosition(babyArrow.x - Note.swagWidth * 0.95, babyArrow.y - Note.swagWidth);
267+
#if debug
268+
trace('NoteSplash: Using babyArrow position: (${babyArrow.x - Note.swagWidth * 0.95}, ${babyArrow.y - Note.swagWidth})');
269+
#end
270+
}
271+
272+
if (babyArrowCharting != null && (inEditor || (x == 0 && y == 0))) {
273+
setPosition(babyArrowCharting.x - Note.swagWidth * 0.95, babyArrowCharting.y - Note.swagWidth);
274+
#if debug
275+
trace('NoteSplash: Using babyArrowCharting position');
276+
#end
277+
}
248278

249279
if (note != null)
250280
noteData = note.noteData;
251281

252282
// Get current key count for proper noteData calculation
253283
var keyCount:Int = 4; // Default fallback
254284
var colArray:Array<String> = Note.colArray.copy();
255-
285+
256286
if (PlayState.instance != null && PlayState.instance.playfields != null && PlayState.instance.playfields.members.length > 0) {
257287
keyCount = PlayState.instance.playfields.members[0].keyCount;
258288
} else if (PlayState.mania >= 0 && PlayState.mania < Note.ammo.length) {
259289
keyCount = Note.ammo[PlayState.mania];
260290
}
261-
291+
262292
// Get the appropriate color array for the current key count
263293
if (PlayState.mania >= 0 && PlayState.mania < Note.ammo.length && Note.keysShit.exists(PlayState.mania)) {
264294
var keyData = Note.keysShit.get(PlayState.mania);
@@ -267,7 +297,7 @@ class NoteSplash extends NoteObject
267297
colArray = letters.map(letter -> letter.toLowerCase());
268298
}
269299
}
270-
300+
271301
// Extend color array if needed
272302
while (colArray.length < keyCount) {
273303
colArray.push('key${colArray.length}');
@@ -277,8 +307,37 @@ class NoteSplash extends NoteObject
277307
noteData = noteData % colArray.length + (FlxG.random.int(0, maxAnims - 1) * colArray.length);
278308

279309
this.noteData = noteData;
310+
311+
// Make sure the splash is visible and properly positioned
312+
alpha = 0;
313+
visible = true;
314+
280315
var anim:String = playDefaultAnim();
281316

317+
// Apply config-based offset if animation was found
318+
if (anim != null && config != null && config.animations.exists(anim)) {
319+
var animData = config.animations.get(anim);
320+
if (animData.offsets != null && animData.offsets.length >= 2) {
321+
offset.set(animData.offsets[0], animData.offsets[1]);
322+
#if debug
323+
trace('NoteSplash: Applied animation offset (${animData.offsets[0]}, ${animData.offsets[1]}) for anim: $anim');
324+
#end
325+
} else {
326+
offset.set(0, 0);
327+
#if debug
328+
trace('NoteSplash: No offset data for anim: $anim');
329+
#end
330+
}
331+
} else {
332+
#if debug
333+
trace('NoteSplash: No animation or config found for offset application');
334+
#end
335+
}
336+
337+
#if debug
338+
trace('NoteSplash: Final position after spawn: (${this.x}, ${this.y}) with offset (${offset.x}, ${offset.y})');
339+
#end
340+
282341
var tempShader:RGBPalette = null;
283342
if (config.allowRGB)
284343
{
@@ -301,7 +360,7 @@ class NoteSplash extends NoteObject
301360
// Ensure we don't go out of bounds for RGB arrays
302361
if (rgbIndex < ClientPrefs.data.arrowRGB.length) {
303362
arr = ClientPrefs.data.arrowRGB[rgbIndex];
304-
if (PlayState.isPixelStage && rgbIndex < ClientPrefs.data.arrowRGBPixel.length)
363+
if (PlayState.isPixelStage && rgbIndex < ClientPrefs.data.arrowRGBPixel.length)
305364
arr = ClientPrefs.data.arrowRGBPixel[rgbIndex];
306365
} else {
307366
// Fallback to default RGB values for extended keys
@@ -317,7 +376,7 @@ class NoteSplash extends NoteObject
317376
continue;
318377
}
319378

320-
var r:Null<Int> = rgb.r;
379+
var r:Null<Int> = rgb.r;
321380
var g:Null<Int> = rgb.g;
322381
var b:Null<Int> = rgb.b;
323382

@@ -385,12 +444,29 @@ class NoteSplash extends NoteObject
385444

386445
spawned = true;
387446
}
388-
447+
389448
public function playDefaultAnim()
390449
{
391450
var anim:String = noteDataMap.get(noteData);
392-
if (anim != null && animation.exists(anim))
451+
#if debug
452+
trace('NoteSplash: Trying to play animation for noteData $noteData, found: $anim');
453+
trace('NoteSplash: Available animations in noteDataMap: ${[for (k => v in noteDataMap) '$k=>$v']}');
454+
#end
455+
456+
if (anim != null && animation.exists(anim)) {
393457
animation.play(anim, true);
458+
alpha = ClientPrefs.data.splashAlpha;
459+
spawned = true;
460+
461+
#if debug
462+
trace('NoteSplash: Successfully playing animation: $anim');
463+
#end
464+
} else {
465+
#if debug
466+
trace('NoteSplash: Failed to play animation - anim: $anim, exists: ${anim != null ? animation.exists(anim) : false}');
467+
trace('NoteSplash: Available animations: ${animation.getNameList()}');
468+
#end
469+
}
394470

395471
return anim;
396472
}
@@ -411,14 +487,18 @@ class NoteSplash extends NoteObject
411487
if (spawned)
412488
{
413489
aliveTime += elapsed;
414-
if (animation.curAnim == null && aliveTime >= buggedKillTime)
415-
{
490+
491+
// Check if animation finished or if it's taking too long
492+
if (animation.curAnim != null && animation.curAnim.finished) {
493+
kill();
494+
spawned = false;
495+
} else if (animation.curAnim == null && aliveTime >= buggedKillTime) {
416496
kill();
417497
spawned = false;
418498
}
419499
}
420500

421-
if (babyArrow != null)
501+
if (babyArrow != null && inEditor)
422502
{
423503
if (copyX)
424504
x = babyArrow.x - Note.swagWidth * 0.95;
@@ -427,7 +507,7 @@ class NoteSplash extends NoteObject
427507
y = babyArrow.y - Note.swagWidth;
428508
}
429509

430-
if (babyArrowCharting != null)
510+
if (babyArrowCharting != null && inEditor)
431511
{
432512
if (copyX)
433513
x = babyArrowCharting.x - Note.swagWidth * 0.95;
@@ -466,7 +546,7 @@ class NoteSplash extends NoteObject
466546
return config;
467547
}
468548

469-
function set_config(value:NoteSplashConfig):NoteSplashConfig
549+
function set_config(value:NoteSplashConfig):NoteSplashConfig
470550
{
471551
if (value == null) value = createConfig();
472552

@@ -479,12 +559,27 @@ class NoteSplash extends NoteObject
479559
var key:String = i.name;
480560
if (i.prefix.length > 0 && key != null && key.length > 0)
481561
{
562+
// Use the appropriate FPS - either the single value or the first value from array
563+
var animFPS:Int = 24; // Default FPS
564+
if (i.fps != null && i.fps.length > 0) {
565+
animFPS = i.fps[0]; // Use first FPS value for consistent animation speed
566+
if (i.fps.length > 1) {
567+
// If there are two FPS values, use a random value between them
568+
animFPS = FlxG.random.int(i.fps[0], i.fps[1]);
569+
}
570+
}
571+
482572
if (i.indices != null && i.indices.length > 0)
483-
animation.addByIndices(key, i.prefix, i.indices, "", i.fps[1], false);
573+
animation.addByIndices(key, i.prefix, i.indices, "", animFPS, false);
484574
else
485-
animation.addByPrefix(key, i.prefix, i.fps[1], false);
575+
animation.addByPrefix(key, i.prefix, animFPS, false);
486576

487577
noteDataMap.set(i.noteData, key);
578+
579+
// Debug output to verify animations are being loaded
580+
#if debug
581+
trace('NoteSplash: Added animation "$key" with prefix "${i.prefix}" for noteData ${i.noteData} at ${animFPS}fps');
582+
#end
488583
}
489584
}
490585

@@ -503,7 +598,7 @@ class NoteSplash extends NoteObject
503598
}
504599
}
505600

506-
class PixelSplashShaderRef
601+
class PixelSplashShaderRef
507602
{
508603
public var shader:PixelSplashShader = new PixelSplashShader();
509604
public var enabled(default, set):Bool = true;
@@ -601,4 +696,4 @@ class PixelSplashShader extends FlxShader
601696
{
602697
super();
603698
}
604-
}
699+
}

source/objects/playfields/PlayField.hx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class PlayField extends FlxTypedGroup<FlxBasic>
5959
strumLine.cameras = to;
6060

6161
noteField.cameras = to;
62+
grpNoteSplashes.cameras = to;
63+
64+
#if debug
65+
trace('PlayField: Set cameras for grpNoteSplashes to: $to');
66+
#end
6267

6368
return super.set_cameras(to);
6469
}
@@ -921,30 +926,46 @@ class PlayField extends FlxTypedGroup<FlxBasic>
921926

922927
public function spawnSplash(note:Note, ?splashSkin:String):NoteSplash {
923928
if (note == null) return null;
924-
929+
925930
var splash:NoteSplash = grpNoteSplashes.recycle(NoteSplash);
926931
if (splash == null) {
927932
splash = new NoteSplash();
928933
grpNoteSplashes.add(splash);
929934
}
930-
931-
// Set position based on the strum/note position
935+
936+
// Ensure splash uses the same cameras as the playfield
937+
splash.cameras = this.cameras;
938+
939+
#if debug
940+
trace('NoteSplash: Set splash cameras to: ${splash.cameras}');
941+
#end
942+
943+
// Set position to match the exact strum note position
932944
var strumX:Float = 0;
933945
var strumY:Float = 0;
934946
if (note.column < strumNotes.length) {
935947
var strum = strumNotes[note.column];
936948
if (strum != null) {
949+
// Use the exact strum position - the splash will handle its own centering via offsets
937950
strumX = strum.x;
938951
strumY = strum.y;
952+
953+
#if debug
954+
trace('NoteSplash: Spawning splash for note column ${note.column} at strum position ($strumX, $strumY)');
955+
#end
939956
}
957+
} else {
958+
#if debug
959+
trace('NoteSplash: Warning - note.column ${note.column} >= strumNotes.length ${strumNotes.length}');
960+
#end
940961
}
941-
962+
942963
splash.spawnSplashNote(strumX, strumY, note.noteData, note);
943964
splash.handleRendering = false;
944-
965+
945966
return splash;
946967
}
947-
968+
948969
public function spawnNoteSplashOnNote(note:Note):NoteSplash {
949970
return spawnSplash(note);
950971
}

source/options/SNS.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package options;
22

3-
package objects;
4-
53
import backend.animation.PsychAnimationController;
64
import flixel.system.FlxAssets.FlxShader;
5+
import objects.Note;
6+
import objects.StrumNote;
77
import objects.charting.ChartingStrumNote;
88
import shaders.RGBPalette;
99

0 commit comments

Comments
 (0)