@@ -3,7 +3,7 @@ package archipelago;
33import haxe .ds .StringMap ;
44
55typedef Condition = {
6- var checkFn : Void -> Bool ;
6+ var checkFn : APItem -> Bool ;
77 var type : ConditionType ;
88}
99
@@ -14,16 +14,23 @@ enum ConditionType {
1414}
1515
1616class ConditionHelper {
17- public static inline function create (check : Void -> Bool , type : ConditionType ): Condition {
17+ private static inline function create (check : APItem -> Bool , type : ConditionType ): Condition {
1818 return { checkFn : check , type : type };
1919 }
2020
21- public static inline function check (condition : Condition , item : APItem ): Bool {
22- return condition .checkFn ();
21+ public static inline function check (item : APItem ): Bool {
22+ return item .condition .checkFn (item );
23+ }
24+
25+ public static inline function Everywhere (): Condition {
26+ return ConditionHelper .create (function (item : APItem ): Bool { return true ; }, ConditionType . Everywhere );
27+ }
28+ public static inline function PlayState (): Condition {
29+ return ConditionHelper .create (function (item : APItem ): Bool { return Std .is (FlxG .state , states. PlayState ) && (! states. PlayState .instance .startingSong || item .isException ); }, ConditionType . PlayState );
30+ }
31+ public static inline function Freeplay (): Condition {
32+ return ConditionHelper .create (function (item : APItem ): Bool { return Std .is (FlxG .state , states. FreeplayState ); }, ConditionType . Freeplay );
2333 }
24- public static var Everywhere = ConditionHelper .create (function (): Bool { return true ; }, ConditionType . Everywhere );
25- public static var PlayState = ConditionHelper .create (function (): Bool { return Std .is (FlxG .state , states. PlayState ) && ! states. PlayState .instance .startingSong ;}, ConditionType . PlayState );
26- public static var Freeplay = ConditionHelper .create (function (): Bool { return Std .is (FlxG .state , states. FreeplayState ); }, ConditionType . Freeplay );
2734}
2835
2936class ActiveArray {
@@ -116,7 +123,7 @@ class APItem {
116123 public static function createItemByName (name : String ): APItem {
117124 switch (name ) {
118125 case " Blue Balls Curse" :
119- return new APItem (name , ConditionHelper . Everywhere , function () {
126+ return new APItem (name , ConditionHelper . Everywhere () , function () {
120127 // Check if shields are available
121128 if (shields > 0 ) {
122129 shields -- ;
@@ -147,29 +154,29 @@ class APItem {
147154 }, 100 );
148155 }, false , false );
149156 case " Fake Transition" :
150- return new APItem (name , ConditionHelper . Everywhere , function () TransitionState .fakeTransition ({transitionType :" transparent close" }), true , false );
157+ return new APItem (name , ConditionHelper . Everywhere () , function () TransitionState .fakeTransition ({transitionType :" transparent close" }), true , false );
151158 case " Ticket" :
152- return new APItem (name , ConditionHelper . Everywhere , function () {popup (" You got a ticket!" );
159+ return new APItem (name , ConditionHelper . Everywhere () , function () {popup (" You got a ticket!" );
153160 archipelago. APInfo .ticketCount ++ ;
154161 }, true , true );
155162 case " SvC Effect" :
156- return new APItem (name , ConditionHelper . PlayState , function () APPlayState .instance .doEffect (APPlayState .instance .effectArray [APPlayState .instance .curEffect ]), true , false );
163+ return new APItem (name , ConditionHelper . PlayState () , function () APPlayState .instance .doEffect (APPlayState .instance .effectArray [APPlayState .instance .curEffect ]), true , false );
157164 case " Ghost Chat" :
158- return new APItem (name , ConditionHelper . PlayState , function () APPlayState .instance .triggerGhostChat (), true , false );
165+ return new APItem (name , ConditionHelper . PlayState () , function () APPlayState .instance .triggerGhostChat (), true , false );
159166 case " Shield" :
160- return new APItem (name , ConditionHelper . Everywhere , function () {
167+ return new APItem (name , ConditionHelper . Everywhere () , function () {
161168 shields ++ ;
162169 trace (" Shield acquired! Current shields: " + shields );
163170 popup (" You got a shield!" );
164171 }, true , true );
165172 case " Max HP Up" :
166- return new APItem (name , ConditionHelper . Everywhere , function () {
173+ return new APItem (name , ConditionHelper . Everywhere () , function () {
167174 maxHPUp ++ ;
168175 trace (" Max HP increased! Current max HP: " + maxHPUp );
169176 popup (" You got a max HP up!" );
170177 }, true , true );
171178 case " Tutorial Trap" :
172- return new APItem (name , ConditionHelper . PlayState , function () {
179+ return new APItem (name , ConditionHelper . PlayState () , function () {
173180 // Wait for PlayState's startedCountdown to become active
174181 haxe. Timer .delay (function checkCountdown () {
175182 var playState : archipelago. APPlayState = cast states. PlayState .instance ;
@@ -193,16 +200,16 @@ class APItem {
193200 trace (" Triggering item: " + this .name );
194201 trace (" Is exception: " + this .isException );
195202 trace (" Condition type: " + this .condition .type );
196- trace (" Condition check result: " + this .condition .checkFn ());
203+ trace (" Condition check result: " + this .condition .checkFn (this ));
197204
198- if (! this .isException && this .condition .type != ConditionType . Everywhere && this .condition .checkFn ()) {
205+ if (! this .isException && this .condition .type != ConditionType . Everywhere && this .condition .checkFn (this )) {
199206 trace (" Setting active item to: " + this .name );
200207 APItem .activeItem = this ;
201208 } else {
202209 trace (" Active item not set due to condition, exception rules, or being an Everywhere item." );
203210 }
204211
205- if (this .condition .checkFn ()) {
212+ if (this .condition .checkFn (this )) {
206213 trace (" Condition passed, executing onTrigger for item: " + this .name );
207214 onTrigger ();
208215 } else {
@@ -213,16 +220,16 @@ class APItem {
213220 trace (" Triggering item: " + this .name );
214221 trace (" Is exception: " + this .isException );
215222 trace (" Condition type: " + this .condition .type );
216- trace (" Condition check result: " + this .condition .checkFn ());
223+ trace (" Condition check result: " + this .condition .checkFn (this ));
217224
218- if (! this .isException && this .condition .type != ConditionType . Everywhere && this .condition .checkFn ()) {
225+ if (! this .isException && this .condition .type != ConditionType . Everywhere && this .condition .checkFn (this )) {
219226 trace (" Setting active item to: " + this .name );
220227 APItem .activeItem = this ;
221228 } else {
222229 trace (" Active item not set due to condition, exception rules, or being an Everywhere item." );
223230 }
224231
225- if (this .condition .checkFn ()) {
232+ if (this .condition .checkFn (this )) {
226233 trace (" Condition passed, executing onTrigger for item: " + this .name );
227234 onTrigger ();
228235 } else {
@@ -273,7 +280,7 @@ class APItem {
273280 if (! allowedToTrigger && ! item .isException ) {
274281 continue ;
275282 }
276- if (item .condition .checkFn ()) {
283+ if (item .condition .checkFn (item )) {
277284 if (! triggered || item .isException ) {
278285 item .trigger ();
279286 if (! item .isException ) {
0 commit comments