@@ -112,121 +112,109 @@ class APGameState {
112112 public var ItemIndex : Int = - 1 ;
113113
114114 public function locationData (songName : String ): Array <Int > {
115- // trace("Starting locationData function with songName: " + songName);
116- var matchingLocations : Array <Int > = [];
117- var exactMatch : Int = - 1 ;
118- var hasDashNumber : Bool = false ;
119- var reg = new EReg (" ^" + EReg .escape (songName ) + " (?:-\\ d+)?$" , " " );
120- var apInfo = info ();
121-
122- // trace("Iterating through APLocations...");
123- for (location in APLocations ) {
124- var locationName = apInfo .get_location_name (location );
125- // trace("Checking location: " + location + " with name: " + locationName);
126-
127- if (locationName == songName ) {
128- // trace("Exact match found for location: " + location);
129- exactMatch = location ;
130- break ;
131- } else if (reg .match (locationName )) { // trace("Matching location with dash-number found: " + location);
132- matchingLocations .push (location );
133- hasDashNumber = true ;
115+ try {
116+ // trace("Starting locationData function with songName: " + songName);
117+ var matchingLocations : Array <Int > = [];
118+ var exactMatch : Int = - 1 ;
119+ var hasDashNumber : Bool = false ;
120+ var reg = new EReg (" ^" + EReg .escape (songName ) + " (?:-\\ d+)?$" , " " );
121+ var apInfo = info ();
122+
123+ for (location in APLocations ) {
124+ var locationName = apInfo .get_location_name (location );
125+
126+ if (locationName == songName ) {
127+ exactMatch = location ;
128+ break ;
129+ } else if (reg .match (locationName )) {
130+ matchingLocations .push (location );
131+ hasDashNumber = true ;
132+ }
134133 }
135- }
136134
137- // trace("Finished iterating through APLocations.");
138- // trace("Exact match: " + exactMatch + ", hasDashNumber: " + hasDashNumber);
135+ if (! hasDashNumber && exactMatch != - 1 ) {
136+ return [exactMatch ];
137+ }
139138
140- if (! hasDashNumber && exactMatch != - 1 ) {
141- // trace("Returning exact match as the result: [" + exactMatch + "]");
142- return [exactMatch ];
139+ return matchingLocations ;
140+ } catch (e : Dynamic ) {
141+ var errorMessage = " Error in locationData function for song: " + songName + " . Reason: " + Std .string (e );
142+ trace (errorMessage );
143+ archipelago. APItem .popup (errorMessage , " Error: Locations" , true );
144+ return [];
143145 }
144-
145- // trace("Returning matching locations: " + matchingLocations);
146- return matchingLocations ;
147146 }
148147
149148 public function noteData (songName : String , modName : String , ? week : String ): Array <Int > {
150- // trace("Starting noteData function with songName: " + songName + " and modName: " + modName);
151- var matchingNotes : Array <Int > = [];
152- var reg = new EReg (" ^Note \\ d+: " + EReg .escape (songName + (modName != " " ? " (" + modName + " )" : " " )) + " $" , " " );
153- var apInfo = info ();
154-
155- // trace("Looking for locations matching pattern: " + "Note #: " + songName + (modName != "" ? " (" + modName + ")" : ""));
156-
157- // Initial matching using the regular expression
158- // trace("Iterating through APLocations...");
159- for (location in APLocations ) {
160- var locationName = apInfo .get_location_name (location );
161- if (reg .match (locationName )) {
162- matchingNotes .push (location );
149+ try {
150+ // trace("Starting noteData function with songName: " + songName + " and modName: " + modName);
151+ var matchingNotes : Array <Int > = [];
152+ var reg = new EReg (" ^Note \\ d+: " + EReg .escape (songName + (modName != " " ? " (" + modName + " )" : " " )) + " $" , " " );
153+ var apInfo = info ();
154+
155+ for (location in APLocations ) {
156+ var locationName = apInfo .get_location_name (location );
157+ if (reg .match (locationName )) {
158+ matchingNotes .push (location );
159+ }
163160 }
164- }
165-
166- // Fallback logic if no matches are found
167- if (matchingNotes .length == 0 ) {
168- // trace("No matches found. Attempting fallback logic...");
169- for (song in WeekData .getCurrentWeek ().songs ) {
170- // trace("Checking song in current week: " + song[0]);
171- if ((cast song [0 ] : String ).toLowerCase ().trim () == songName .toLowerCase ().trim () ||
172- (cast song [0 ] : String ).toLowerCase ().trim ().replace (" " , " -" ) == songName .toLowerCase ().trim ().replace (" " , " -" )) {
173- var fallbackReg = new EReg (" ^Note \\ d+: " + EReg .escape (song [0 ] + (modName != " " ? " (" + modName + " )" : " " )) + " $" , " " );
174- for (location in APLocations ) {
175- var locationName = apInfo .get_location_name (location );
176- if (fallbackReg .match (locationName )) {
177- trace (" Fallback match found: " + locationName );
178- matchingNotes .push (location );
161+
162+ if (matchingNotes .length == 0 ) {
163+ for (song in WeekData .getCurrentWeek ().songs ) {
164+ if ((cast song [0 ] : String ).toLowerCase ().trim () == songName .toLowerCase ().trim () ||
165+ (cast song [0 ] : String ).toLowerCase ().trim ().replace (" " , " -" ) == songName .toLowerCase ().trim ().replace (" " , " -" )) {
166+ var fallbackReg = new EReg (" ^Note \\ d+: " + EReg .escape (song [0 ] + (modName != " " ? " (" + modName + " )" : " " )) + " $" , " " );
167+ for (location in APLocations ) {
168+ var locationName = apInfo .get_location_name (location );
169+ if (fallbackReg .match (locationName )) {
170+ trace (" Fallback match found: " + locationName );
171+ matchingNotes .push (location );
172+ }
179173 }
174+ break ;
180175 }
181- break ;
182176 }
183177 }
184- }
185-
186- // Secondary fallback logic using JSON data
187- if (matchingNotes .length == 0 ) {
188- // trace("No matches found in fallback logic. Attempting secondary fallback...");
189- for (song in WeekData .getCurrentWeek ().songs ) {
190- // trace("Checking song in secondary fallback logic: " + song[0]);
191- var songPath = modName .trim () != " "
192- ? " mods/" + modName + " /data/" + song [0 ] + " /" + song [0 ] + " -" + Difficulty .getString (PlayState .storyDifficulty ) + " .json"
193- : " assets/shared/data/" + (song [0 ] + Difficulty .getFilePath ());
194- // trace("Constructed songPath: " + songPath);
195-
196- var songJson : backend. Song . SwagSong = null ;
197- var jsonStuff : Array <String > = modName .trim () != " "
198- ? Paths .crawlDirectory (" mods/" + modName + " /data" , " .json" )
199- : Paths .crawlDirectory (" assets/shared/data" , " .json" );
200- // trace("Retrieved JSON files: " + jsonStuff);
201-
202- for (json in jsonStuff ) {
203- // trace("Checking JSON file: " + json);
204- if (json .trim ().toLowerCase ().replace (" " , " -" ) == songPath .trim ().toLowerCase ().replace (" " , " -" )) {
205- trace (" Match found for JSON file: " + json );
206- songJson = backend. Song .parseJSON (File .getContent (json ));
207- if (songJson != null ) {
208- trace (" Parsed song JSON successfully. Checking song name..." );
209- if (songJson .song .trim ().toLowerCase ().replace (" " , " -" ) == songName .toLowerCase ().trim ().replace (" " , " -" )) {
210- trace (" Match found for song in JSON: " + songJson .song );
211- var fallbackReg = new EReg (" ^Note \\ d+: " + EReg .escape (song [0 ] + (modName != " " ? " (" + modName + " )" : " " )) + " $" , " " );
212- for (location in APLocations ) {
213- var locationName = apInfo .get_location_name (location );
214- if (fallbackReg .match (locationName )) {
215- trace (" Secondary fallback match found: " + locationName );
216- matchingNotes .push (location );
178+
179+ if (matchingNotes .length == 0 ) {
180+ for (song in WeekData .getCurrentWeek ().songs ) {
181+ var songPath = modName .trim () != " "
182+ ? " mods/" + modName + " /data/" + song [0 ] + " /" + song [0 ] + " -" + Difficulty .getString (PlayState .storyDifficulty ) + " .json"
183+ : " assets/shared/data/" + (song [0 ] + Difficulty .getFilePath ());
184+
185+ var songJson : backend. Song . SwagSong = null ;
186+ var jsonStuff : Array <String > = modName .trim () != " "
187+ ? Paths .crawlDirectory (" mods/" + modName + " /data" , " .json" )
188+ : Paths .crawlDirectory (" assets/shared/data" , " .json" );
189+
190+ for (json in jsonStuff ) {
191+ if (json .trim ().toLowerCase ().replace (" " , " -" ) == songPath .trim ().toLowerCase ().replace (" " , " -" )) {
192+ songJson = backend. Song .parseJSON (File .getContent (json ));
193+ if (songJson != null ) {
194+ if (songJson .song .trim ().toLowerCase ().replace (" " , " -" ) == songName .toLowerCase ().trim ().replace (" " , " -" )) {
195+ var fallbackReg = new EReg (" ^Note \\ d+: " + EReg .escape (song [0 ] + (modName != " " ? " (" + modName + " )" : " " )) + " $" , " " );
196+ for (location in APLocations ) {
197+ var locationName = apInfo .get_location_name (location );
198+ if (fallbackReg .match (locationName )) {
199+ trace (" Secondary fallback match found: " + locationName );
200+ matchingNotes .push (location );
201+ }
217202 }
203+ break ;
218204 }
219- break ;
220205 }
221206 }
222207 }
223208 }
224209 }
210+
211+ return matchingNotes ;
212+ } catch (e : Dynamic ) {
213+ var errorMessage = " Error in noteData function for song: " + songName + " and mod: " + modName + " . Reason: " + Std .string (e );
214+ trace (errorMessage );
215+ archipelago. APItem .popup (errorMessage , " Error: Note Checks" , true );
216+ return [];
225217 }
226-
227- // trace("Finished iterating through APLocations.");
228- // trace("Returning matching notes: " + matchingNotes);
229- return matchingNotes ;
230218 }
231219
232220 public function getSongLocations (songName : String , modName : String ): Array <Int > {
0 commit comments