Skip to content

Commit 3b13fa2

Browse files
committed
AP AF
1 parent a941bd6 commit 3b13fa2

File tree

6 files changed

+193
-7
lines changed

6 files changed

+193
-7
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"xstring": "cpp"
4+
}
5+
}

source/archipelago/APItem.hx

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class APItem {
263263
if (this.condition.checkFn(this)) {
264264
//trace("Condition passed, executing onTrigger for item: " + this.name);
265265
onTrigger();
266+
allItems.remove(this);
266267
} else {
267268
//trace("Condition failed, onTrigger not executed for item: " + this.name);
268269
}
@@ -283,13 +284,13 @@ class APItem {
283284
if (this.condition.checkFn(this)) {
284285
//trace("Condition passed, executing onTrigger for item: " + this.name);
285286
onTrigger();
287+
allItems.remove(this);
286288
} else {
287289
//trace("Condition failed, onTrigger not executed for item: " + this.name);
288290
}
289291
}
290292

291293
//trace("Removing item from allItems: " + this.name);
292-
allItems.remove(this);
293294
}
294295

295296
public static function createItems():Void {
@@ -364,4 +365,124 @@ class APChartModifier extends APItem {
364365
public static function restoreFromSave(modifier:String):Void {
365366
new APChartModifier(modifier);
366367
}
367-
}
368+
}
369+
class APAprilFools extends APItem {
370+
private static var options:Map<Int, Void->Void> = new Map();
371+
372+
static function initializeOptions():Void {
373+
options.set(0, function() {
374+
APItem.createCustomItem("April Fools - Nothing", ConditionHelper.Everywhere(), function() {
375+
archipelago.APItem.popup("April Fools! Nothing happened this time.", "April Fools!");
376+
});
377+
});
378+
379+
options.set(1, function() {
380+
APItem.createCustomItem("April Fools - Random Item", ConditionHelper.Everywhere(), function() {
381+
var randomItem = ["Blue Balls Curse", "Fake Transition", "Ticket", "SvC Effect", "Ghost Chat", "Shield", "Max HP Up", "Tutorial Trap"];
382+
var chosenItem = randomItem[Std.random(randomItem.length)];
383+
archipelago.APItem.createItemByName(chosenItem);
384+
});
385+
});
386+
387+
options.set(2, function() {
388+
APItem.createCustomItem("April Fools - No Heal", ConditionHelper.PlayState(), function() {
389+
if (Std.is(FlxG.state, states.PlayState)) {
390+
var playState:states.PlayState = cast FlxG.state;
391+
playState.noHeal = true;
392+
archipelago.APItem.popup("Healing disabled! Good luck!", "April Fools!");
393+
}
394+
});
395+
});
396+
397+
options.set(3, function() {
398+
APItem.createCustomItem("April Fools - Fake Transition", ConditionHelper.Everywhere(), function() {
399+
var transitionType = Std.random(2) == 0 ? "fallSequential" : "fallRandom";
400+
TransitionState.fakeTransition({ transitionType: transitionType });
401+
archipelago.APItem.popup("I hope you don't mind playing again!", "April Fools!");
402+
});
403+
});
404+
405+
options.set(4, function() {
406+
APItem.createCustomItem("April Fools - Random Song", ConditionHelper.Freeplay(), function() {
407+
if (Std.is(FlxG.state, states.FreeplayState)) {
408+
var freeplayState:states.FreeplayState = cast FlxG.state;
409+
var songList = freeplayState.songList;
410+
if (songList.length == 0) {
411+
archipelago.APItem.popup("No songs available to switch!", "April Fools!");
412+
return;
413+
}
414+
}
415+
});
416+
});
417+
418+
options.set(5, function() {
419+
APItem.createCustomItem("April Fools - Health/MaxHP", ConditionHelper.PlayState(), function() {
420+
if (Std.is(FlxG.state, states.PlayState)) {
421+
var playState:states.PlayState = cast FlxG.state;
422+
if (Std.random(2) == 0) {
423+
var tween = flixel.tweens.FlxTween.num(playState.health, 0, 1, function(value:Float) {
424+
playState.health = value;
425+
});
426+
archipelago.APItem.popup("Your health is now 0!", "April Fools!");
427+
} else {
428+
var tween = flixel.tweens.FlxTween.num(playState.MaxHP, 0, 1, function(value:Float) {
429+
playState.MaxHP = value;
430+
});
431+
archipelago.APItem.popup("Your MaxHP is now 0!", "April Fools!");
432+
}
433+
}
434+
});
435+
});
436+
437+
438+
options.set(6, function() {
439+
APItem.createCustomItem("April Fools - Screen Flip", ConditionHelper.PlayState(), function() {
440+
if (Std.is(FlxG.state, states.PlayState)) {
441+
var playState:states.PlayState = cast FlxG.state;
442+
var randomChance = Std.random(100);
443+
var targetAngle = 180;
444+
445+
if (randomChance < 10) { // 10% chance to overflip or underflip
446+
targetAngle = 180 + (Std.random(3) - 1) * 360;
447+
} else if (randomChance < 20) { // 10% chance to invert the screen
448+
targetAngle = 0;
449+
}
450+
451+
flixel.FlxG.camera.angle = 0;
452+
flixel.tweens.FlxTween.num(0, targetAngle, 1, function(value:Float) {
453+
flixel.FlxG.camera.angle = value;
454+
});
455+
archipelago.APItem.popup("The screen is flipped!", "April Fools!");
456+
}
457+
});
458+
});
459+
460+
// Windows Only, as notifications can't be sent this way on other platforms
461+
#if windows
462+
options.set(7, function() {
463+
APItem.createCustomItem("April Fools - Windows Notification", ConditionHelper.Everywhere(), function() {
464+
var notification = new haxe.win32.Notification("April Fools!", "This is a Windows notification!");
465+
notification.show();
466+
});
467+
});
468+
469+
470+
471+
}
472+
473+
public function new() {
474+
super("April Fools", ConditionHelper.Special(), function() {
475+
if (options.lengthTo() == 0) {
476+
initializeOptions();
477+
}
478+
479+
480+
var randomChoice = Std.random(options.lengthTo());
481+
var action = options.get(randomChoice);
482+
if (action != null) {
483+
action();
484+
APItem.popup("Something happened...", "April Fools!");
485+
}
486+
}, false, false);
487+
}
488+
}

source/backend/MusicBeatState.hx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,56 @@ class MusicBeatState extends FlxState
219219
curStep = lastChange.stepTime + Math.floor(shit);
220220
}
221221

222+
public static function playSong(storyPlaylist:Array<String>, storyMode:Bool = false, difficulty:Int = 0, ?transition:String, ?type:String = null, ?manualDiff:Array<String> = null):Void {
223+
var songs:Array<backend.Song.SwagSong> = [];
224+
225+
if (storyPlaylist.length > 1) {
226+
storyMode = true;
227+
}
228+
Difficulty.resetList();
229+
if (manualDiff != null) Difficulty.list = manualDiff;
230+
231+
if (storyMode) {
232+
for (songPath in storyPlaylist) {
233+
var songLowercase:String = Paths.formatToSongPath(songPath);
234+
var formattedSong:String = Highscore.formatSong(songLowercase, difficulty);
235+
songs.push(Song.loadFromJson(formattedSong, songLowercase));
236+
}
237+
PlayState.storyPlaylist = songs.map(function(song:SwagSong):String {
238+
return song.song;
239+
});
240+
PlayState.SONG = null;
241+
} else {
242+
// songsInput is a String when storyMode is false
243+
var songLowercase:String = Paths.formatToSongPath(storyPlaylist[0]);
244+
var formattedSong:String = Highscore.formatSong(songLowercase, difficulty);
245+
PlayState.SONG = Song.loadFromJson(formattedSong, songLowercase);
246+
}
247+
248+
PlayState.isStoryMode = storyMode;
249+
PlayState.storyDifficulty = difficulty;
250+
251+
// Additional setup for PlayState as needed
252+
253+
// Transition to PlayState
254+
switch (transition) {
255+
case "FlxG", "FlxG.switchState":
256+
FlxG.switchState(new PlayState());
257+
258+
case "MusicBeatState":
259+
switchState(new PlayState());
260+
261+
case "TransitionState":
262+
TransitionState.transitionState(PlayState, {
263+
transitionType: type
264+
});
265+
266+
default:
267+
FlxG.switchState(new PlayState());
268+
269+
}
270+
}
271+
222272
public static function switchState(nextState:FlxState = null)
223273
{
224274
if (nextState == null)

source/backend/TransitionState.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class TransitionState {
424424
// Function to check if all tweens are complete
425425
var checkAllComplete = function() {
426426
if (completedTweens >= totalTweens) {
427-
restoreSprites();
427+
MusicBeatState.resetState();
428428
}
429429
};
430430

@@ -446,7 +446,7 @@ class TransitionState {
446446

447447
// In case there are no sprites, directly restore state
448448
if (totalTweens == 0) {
449-
restoreSprites();
449+
MusicBeatState.resetState();
450450
}
451451

452452
case "fallSequential":
@@ -475,7 +475,7 @@ class TransitionState {
475475
});
476476
} else {
477477
// All objects processed, restore state
478-
restoreSprites();
478+
MusicBeatState.resetState();
479479
}
480480
};
481481

source/states/FreeplayState.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ class FreeplayState extends MusicBeatState
5151
public static var instance:FreeplayState;
5252

5353
var songs:Array<SongMetadata> = [];
54+
public var songList(get, never):Array<SongMetadata>;
55+
56+
public function get_songList():Array<SongMetadata> {
57+
return songs;
58+
}
59+
5460
var selector:FlxText;
5561
private static var curSelected:Int = 0;
5662
var lerpSelected:Float = 0;

source/yutautil/CollectionUtils.hx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,11 @@ class CollectionUtils
12441244

12451245
public static inline function lengthTo<T>(input:Dynamic):Int
12461246
{
1247-
if (Std.is(input, Array))
1247+
if (!exists(input, true))
1248+
{
1249+
return 0;
1250+
}
1251+
else if (Std.is(input, Array))
12481252
{
12491253
return (input : Array<T>).length;
12501254
}
@@ -1267,7 +1271,7 @@ class CollectionUtils
12671271
}
12681272
else
12691273
{
1270-
return 1;
1274+
return 0;
12711275
}
12721276
}
12731277

0 commit comments

Comments
 (0)