Skip to content

Commit

Permalink
Fixed TM/HM numbers in Personal Data Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
AdAstra-LD committed Dec 13, 2023
1 parent d27545e commit c18aca0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions DS_Map/PersonalDataEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private void addAllMachinesButton_Click(object sender, EventArgs e) {
}

currentLoadedFile.machines = new SortedSet<byte>();
for (byte i = 1; i < tot + 1; i++) {
for (byte i = 0; i < tot; i++) {
currentLoadedFile.machines.Add(i);
}
RebuildMachinesListBoxes();
Expand Down Expand Up @@ -506,8 +506,8 @@ private void RebuildMachinesListBoxes(bool keepAddableSelection = true, bool kee

int dataIndex = 0;
byte tot = (byte)(PokemonPersonalData.tmsCount + PokemonPersonalData.hmsCount);
for (byte i = 1; i < tot + 1; i++) {
string currentItem = MachineNameFromIndex(i);
for (byte i = 0; i < tot; i++) {
string currentItem = MachineNameFromZeroBasedIndex(i);
if (dataIndex < currentLoadedFile.machines.Count && currentLoadedFile.machines.Contains(i)) {
addedMachinesListBox.Items.Add(currentItem);
dataIndex++;
Expand All @@ -532,7 +532,10 @@ private void RebuildMachinesListBoxes(bool keepAddableSelection = true, bool kee
}
}

private static string MachineNameFromIndex(int n) {
private static string MachineNameFromZeroBasedIndex(int n) {
//0-91 --> TMs
//>=92 --> HM
n += 1;
int diff = n - PokemonPersonalData.tmsCount;
string item = diff > 0 ? "HM " + diff : "TM " + n;
return item;
Expand All @@ -547,6 +550,7 @@ private static int IndexFromMachineName(string machineName) {

if (isTM || parts[0].Equals("HM", StringComparison.OrdinalIgnoreCase)) {
if (int.TryParse(parts[1], out int number)) {
number--;
// Calculate the index based on the prefix (TM or HM)
int index = isTM ? number : number + PokemonPersonalData.tmsCount;
return index;
Expand Down

0 comments on commit c18aca0

Please sign in to comment.