Skip to content

Commit 625f245

Browse files
committed
GOD HELP-
1 parent 449279c commit 625f245

File tree

7 files changed

+211
-123
lines changed

7 files changed

+211
-123
lines changed
-518 Bytes
Binary file not shown.

source/archipelago/APGameState.hx

Lines changed: 83 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -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> {

source/archipelago/APNote.hx

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import archipelago.PacketTypes.NetworkItem;
55
class APNote extends objects.Note {
66
var APItem:NetworkItem;
77
public var APItemLocation:Null<Int> = null;
8+
public var index:Int = 0;
89

910
public function new(note:objects.Note, location:Int, ?item:NetworkItem = null) {
1011
super(note.strumTime, note.noteData, note.prevNote, note.isSustainNote);
@@ -32,6 +33,8 @@ class APNote extends objects.Note {
3233
this.rgbShader.r = 0x3380CC;
3334
this.rgbShader.g = 0x3380CC;
3435
this.rgbShader.b = 0x3380CC;
36+
37+
this.checkInfo = {note: this, loc: location}; // Set the checkInfo for the new note
3538
}
3639

3740
// Replace notes with a certain amount of locations.
@@ -45,42 +48,87 @@ class APNote extends objects.Note {
4548
var note = notes[randomIndex];
4649

4750
var shouldIgnore:Bool = (note.ignoreNote || note.hitCausesMiss || note.isSustainNote || (ignoreNonEmptyNoteType && !note.noteType.isEmpty()) || !note.mustPress);
48-
if (shouldIgnore) continue; // Skip if the note should be ignored
51+
if (shouldIgnore || randomIndices.contains(randomIndex)) continue; // Skip if the note should be ignored or already selected
4952

50-
// Check if the note should be ignored
51-
if (!randomIndices.contains(randomIndex) &&
52-
!note.ignoreNote &&
53-
(!ignoreNonEmptyNoteType || note.noteType.isEmpty())) {
54-
randomIndices.push(randomIndex);
55-
}
53+
randomIndices.push(randomIndex);
5654
}
5755

5856
for (i in 0...randomIndices.length) {
5957
var note:objects.Note = notes[randomIndices[i]];
6058
var location:Int = locations[i % locations.length];
6159
var apNote = new APNote(note, location, null); // Create a new APNote with the location
60+
// apNote.noteIndex = note.noteIndex;
6261
newNotes.push(apNote);
63-
notes[randomIndices[i]].isCheck = true; // Replace the original note with the APNote
64-
note = apNote; // Also replace the original note with the APNote
65-
for (queue in apNote.field.noteQueue) {
66-
for (i in 0...queue.length) {
67-
if (queue[i] == note) {
68-
queue[i] = apNote; // Replace the note with apNote in the double-array
69-
queue[i].rgbShader.r = 0x3380CC; // Set the color of the new note
70-
queue[i].rgbShader.g = 0x3380CC; // Set the color of the new note
71-
queue[i].rgbShader.b = 0x3380CC; // Set the color of the new note
72-
note.rgbShader.r = 0x3380CC; // Set the color of the original note to red
73-
note.rgbShader.g = 0x3380CC; // Set the color of the original note to red
74-
note.rgbShader.b = 0x3380CC; // Set the color of the original note to red
75-
break; // Break out of the loop once the note is found and replaced
76-
}
77-
}
62+
63+
// Replace the original note with the APNote
64+
notes[randomIndices[i]] = apNote;
65+
66+
apNote.index = i; // Set the index for the new note
67+
68+
69+
// Set the checkInfo for the new note
70+
apNote.checkInfo = {note: apNote, loc: location};
71+
}
72+
return newNotes; // Return the new notes
73+
}
74+
75+
public static function replaceInQueue(notes:Array<Array<objects.Note>>, locations:Array<Int>, ?ignoreNonEmptyNoteType:Bool = true) {
76+
var newNotes:Array<APNote> = [];
77+
var flatNotes:Array<{lane:Int, index:Int, note:objects.Note}> = [];
78+
79+
// Flatten the notes array into a single array with lane and index information
80+
for (lane in 0...notes.length) {
81+
for (index in 0...notes[lane].length) {
82+
var note = notes[lane][index];
83+
flatNotes.push({lane: lane, index: index, note: note});
7884
}
79-
apNote.isCheck = true; // Set the isCheck property to true
8085
}
86+
87+
var randomIndices:Array<Int> = [];
88+
89+
// Generate a list of random unique indices across all notes
90+
while (randomIndices.length < Math.min(locations.length, flatNotes.length)) {
91+
var randomIndex = Std.random(flatNotes.length);
92+
var noteData = flatNotes[randomIndex];
93+
var note = noteData.note;
94+
95+
var shouldIgnore:Bool = (note.ignoreNote || note.hitCausesMiss || note.isSustainNote || (ignoreNonEmptyNoteType && !note.noteType.isEmpty()) || !note.mustPress);
96+
if (shouldIgnore || randomIndices.contains(randomIndex)) continue; // Skip if the note should be ignored or already selected
97+
98+
randomIndices.push(randomIndex);
99+
}
100+
101+
for (i in 0...randomIndices.length) {
102+
var randomIndex = randomIndices[i];
103+
var noteData = flatNotes[randomIndex];
104+
var lane = noteData.lane;
105+
var index = noteData.index;
106+
var note = noteData.note;
107+
var location:Int = locations[i % locations.length];
108+
var apNote = new APNote(note, location, null); // Create a new APNote with the location
109+
// black coloring
110+
apNote.rgbShader.r = 0xFF313131;
111+
apNote.rgbShader.g = 0xFFFFFFFF;
112+
apNote.rgbShader.b = 0xFFB4B4B4;
113+
newNotes.push(apNote);
114+
115+
// Replace the original note with the APNote
116+
notes[lane][index] = apNote;
117+
// Just in case, recolor.
118+
notes[lane][index].rgbShader.r = 0xFF313131;
119+
notes[lane][index].rgbShader.g = 0xFFFFFFFF;
120+
notes[lane][index].rgbShader.b = 0xFFB4B4B4;
121+
122+
apNote.index = i; // Set the index for the new note
123+
124+
// Set the checkInfo for the new note
125+
apNote.checkInfo = {note: apNote, loc: location};
126+
}
127+
return newNotes; // Return the new notes
81128
}
82129

83130
public function sendCheck():Void {
131+
84132
trace('Location ID: $APItemLocation');
85133
if (APItemLocation != null) {
86134
APEntryState.apGame.info().LocationChecks([APItemLocation]);

0 commit comments

Comments
 (0)