Skip to content

Commit cfac4a5

Browse files
committed
EEEEEEP.
1 parent a5c09f4 commit cfac4a5

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

source/archipelago/APItem.hx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,73 @@ class APrilFools extends APItem {
477477
});
478478
});
479479

480+
options.set(8, function() {
481+
APItem.createCustomItem("April Fools - BF Disappearing Act", ConditionHelper.PlayState(), function() {
482+
if (Std.is(FlxG.state, archipelago.APPlayState)) {
483+
var playState:archipelago.APPlayState = cast FlxG.state;
484+
485+
// // Check if an equivalent function already exists
486+
// if (playState.updateFunctions.exists(function(obj) return Reflect.compareMethods(obj.fn, function() {}))) {
487+
// return;
488+
// }
489+
490+
var bfDisappearFn = {
491+
func: function() {
492+
if (playState.boyfriend != null) {
493+
if (FlxG.keys.justPressed.ENTER) {
494+
playState.boyfriend.alpha = 1;
495+
return;
496+
}
497+
playState.boyfriend.alpha -= 0.01;
498+
if (playState.boyfriend.alpha <= 0) {
499+
try {
500+
FlxG.sound.pause();
501+
} catch (e:Dynamic) {
502+
trace("Error pausing sound: " + e);
503+
}
504+
try {
505+
FlxG.sound.music.pause();
506+
} catch (e:Dynamic) {
507+
trace("Error pausing music: " + e);
508+
}
509+
playState.paused = true;
510+
// throw "Null Object Reference";
511+
backend.COD.COD.COD = "BF ceased to exist";
512+
playState.die();
513+
for (camera in FlxG.cameras.list) {
514+
flixel.tweens.FlxTween.num(camera.alpha, 0, 0.001, function(value:Float) {
515+
camera.alpha = value;
516+
// Cut the sound again.
517+
try {
518+
FlxG.sound.pause();
519+
} catch (e:Dynamic) {
520+
trace("Error pausing sound: " + e);
521+
}
522+
try {
523+
FlxG.sound.music.pause();
524+
} catch (e:Dynamic) {
525+
trace("Error pausing music: " + e);
526+
}
527+
});
528+
}
529+
}
530+
}
531+
},
532+
keepOnRestart: true
533+
};
534+
535+
if (!APPlayState.updateFunctions.map(function(obj) return Reflect.compareMethods(obj.func, bfDisappearFn.func)).contains(true)) {
536+
APPlayState.updateFunctions.push(bfDisappearFn);
537+
} else {
538+
// If the function already exists, remove it first
539+
APPlayState.updateFunctions.remove(bfDisappearFn);
540+
// Then add it again to ensure it's the last one in the list
541+
APPlayState.updateFunctions.push(bfDisappearFn);
542+
}
543+
}
544+
});
545+
});
546+
480547
// Windows Only, as notifications can't be sent this way on other platforms
481548
// We can do this because thanks to the conditional block it will only trigger on windows anyway
482549
#if windows

source/archipelago/APPlayState.hx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class APPlayState extends PlayState {
110110
public var curEffect:Int = 0;
111111

112112
public var effectMap:Map<String, Void->Void>;
113+
public static var updateFunctions:Array<{func: Void->Void, keepOnRestart:Bool, ?activated:Main.Boolean}> = [];
114+
113115
var effectendsin:FlxText;
114116

115117
function generateGibberish(length:Int, exclude:String):String
@@ -169,6 +171,11 @@ class APPlayState extends PlayState {
169171

170172
MaxHP += archipelago.APItem.maxHPUp / 2;
171173

174+
for (func in updateFunctions)
175+
{
176+
if (!func.keepOnRestart && (func.activated != null && func.activated)) updateFunctions.remove(func);
177+
}
178+
172179
effectMap = [
173180
'colorblind' => function() {
174181
var ttl:Float = 16;
@@ -1991,6 +1998,11 @@ class APPlayState extends PlayState {
19911998
}
19921999
}
19932000
}
2001+
for (func in updateFunctions) {
2002+
if (func != null)
2003+
func.func();
2004+
func.activated = true;
2005+
}
19942006
super.update(elapsed);
19952007
}
19962008

@@ -2031,6 +2043,14 @@ class APPlayState extends PlayState {
20312043
if (effectTimer != null && effectTimer.active)
20322044
effectTimer.cancel();
20332045

2046+
for (func in updateFunctions)
2047+
{
2048+
updateFunctions.remove(func);
2049+
}
2050+
2051+
updateFunctions.resize(0);
2052+
updateFunctions = [];
2053+
20342054
if (ghostChat)
20352055
{
20362056
ghostChat = false;

source/yutautil/FreeMap.hx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package yutautil;
2+
3+
import haxe.ds.StringMap;
4+
5+
import haxe.crypto.Sha1;
6+
7+
enum IterationType {
8+
Keys;
9+
Values;
10+
KeyValuePairs;
11+
}
12+
13+
class FreeMap<K, V> {
14+
private var internalMap: StringMap<V>;
15+
16+
public function new() {
17+
internalMap = new StringMap<V>();
18+
}
19+
20+
public function set(key: K, value: V): Void {
21+
var stringKey = keyToString(key);
22+
internalMap.set(stringKey, value);
23+
}
24+
25+
public function get(key: K): Null<V> {
26+
var stringKey = keyToString(key);
27+
return internalMap.get(stringKey);
28+
}
29+
30+
public function exists(key: K): Bool {
31+
var stringKey = keyToString(key);
32+
return internalMap.exists(stringKey);
33+
}
34+
35+
public function remove(key: K): Bool {
36+
var stringKey = keyToString(key);
37+
return internalMap.remove(stringKey);
38+
}
39+
40+
public function iterate(): Array<V> {
41+
var result = [];
42+
var it = internalMap.iterator();
43+
while (it.hasNext()) {
44+
result.push(it.next());
45+
}
46+
return result;
47+
}
48+
49+
public function iterateFor(type: IterationType): Iterable<Dynamic> {
50+
return switch (type) {
51+
case IterationType.Keys:
52+
internalMap.keys();
53+
case IterationType.Values:
54+
internalMap.iterator();
55+
case IterationType.KeyValuePairs:
56+
var mapping = {};
57+
for (key in internalMap.keys()) {
58+
mapping[key] = internalMap.get(key);
59+
}
60+
mapping;
61+
};
62+
}
63+
64+
private function keyToString(key: K): String {
65+
switch (key) {
66+
case true:
67+
return "true-" + Std.string(Lambda.array(internalMap.keys().toArray()).filter(k -> k.startsWith("true-")).length);
68+
case false:
69+
return "false-" + Std.string(Lambda.array(internalMap.keys().toArray()).filter(k -> k.startsWith("false-")).length);
70+
case _:
71+
if (Std.is(key, String) || Std.is(key, Int) || Std.is(key, Float) || Std.is(key, Bool)) {
72+
return Std.string(key);
73+
} else {
74+
return Sha1.encode(haxe.Json.stringify(key));
75+
}
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)