refactor(DD2Switcher): simplify sequence index handling and settings loading
This commit is contained in:
@@ -48,25 +48,21 @@ namespace DD2Switcher {
|
|||||||
public static void StartSequenceMode() {
|
public static void StartSequenceMode() {
|
||||||
Console.WriteLine($"StartSequenceMode called. FirstIndex: {FirstIndex}, LastIndex: {LastIndex}");
|
Console.WriteLine($"StartSequenceMode called. FirstIndex: {FirstIndex}, LastIndex: {LastIndex}");
|
||||||
|
|
||||||
// Compute default indices if not set by user
|
// Compute indices only when sequence starts, not stored permanently
|
||||||
if (FirstIndex == -1 || LastIndex == -1) {
|
int sequenceFirstIndex = FirstIndex;
|
||||||
FirstIndex = FindFirstNonNullWindow();
|
int sequenceLastIndex = LastIndex;
|
||||||
LastIndex = FindLastNonNullWindow();
|
|
||||||
Console.WriteLine($"Computed default indices: FirstIndex={FirstIndex}, LastIndex={LastIndex}");
|
|
||||||
|
|
||||||
// Ensure LastIndex is different from FirstIndex if there are multiple windows
|
// If no user indices, use absolute first and last windows
|
||||||
if (FirstIndex != -1 && LastIndex != -1 && FirstIndex == LastIndex) {
|
if (sequenceFirstIndex == -1 || sequenceLastIndex == -1) {
|
||||||
int nextWindow = FindNextNonNullWindow(FirstIndex + 1);
|
sequenceFirstIndex = FindFirstNonNullWindow();
|
||||||
if (nextWindow != -1) {
|
sequenceLastIndex = FindLastNonNullWindow();
|
||||||
LastIndex = nextWindow;
|
Console.WriteLine(
|
||||||
Console.WriteLine($"Adjusted LastIndex to: {LastIndex} (different from FirstIndex)");
|
$"Computed sequence indices: FirstIndex={sequenceFirstIndex}, LastIndex={sequenceLastIndex}");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FirstIndex >= 0 && LastIndex >= 0 && FirstIndex <= LastIndex) {
|
if (sequenceFirstIndex >= 0 && sequenceLastIndex >= 0 && sequenceFirstIndex <= sequenceLastIndex) {
|
||||||
CurrentState = SequenceState.PROCESSING;
|
CurrentState = SequenceState.PROCESSING;
|
||||||
CurrentSequenceIndex = FirstIndex;
|
CurrentSequenceIndex = sequenceFirstIndex;
|
||||||
Console.WriteLine($"Starting sequence mode, tabbing to index {CurrentSequenceIndex + 1}");
|
Console.WriteLine($"Starting sequence mode, tabbing to index {CurrentSequenceIndex + 1}");
|
||||||
TabTo(CurrentSequenceIndex + 1); // Tab to first window
|
TabTo(CurrentSequenceIndex + 1); // Tab to first window
|
||||||
CurrentState = SequenceState.WAITING;
|
CurrentState = SequenceState.WAITING;
|
||||||
@@ -77,18 +73,22 @@ namespace DD2Switcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void NextSequenceStep() {
|
public static void NextSequenceStep() {
|
||||||
Console.WriteLine(
|
Console.WriteLine($"NextSequenceStep called. State: {CurrentState}, CurrentIndex: {CurrentSequenceIndex}");
|
||||||
$"NextSequenceStep called. State: {CurrentState}, CurrentIndex: {CurrentSequenceIndex}, LastIndex: {LastIndex}");
|
|
||||||
if (CurrentState == SequenceState.INACTIVE)
|
if (CurrentState == SequenceState.INACTIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CurrentState = SequenceState.PROCESSING;
|
CurrentState = SequenceState.PROCESSING;
|
||||||
CurrentSequenceIndex++;
|
CurrentSequenceIndex++;
|
||||||
Console.WriteLine($"Advanced to index {CurrentSequenceIndex}");
|
Console.WriteLine($"Advanced to index {CurrentSequenceIndex}");
|
||||||
if (CurrentSequenceIndex > LastIndex) {
|
|
||||||
|
// Get the actual last index for this sequence (computed or user-set)
|
||||||
|
int sequenceLastIndex = (LastIndex != -1) ? LastIndex : FindLastNonNullWindow();
|
||||||
|
|
||||||
|
if (CurrentSequenceIndex > sequenceLastIndex) {
|
||||||
// End of sequence - tab back to first
|
// End of sequence - tab back to first
|
||||||
|
int sequenceFirstIndex = (FirstIndex != -1) ? FirstIndex : FindFirstNonNullWindow();
|
||||||
Console.WriteLine("End of sequence reached, tabbing back to first window");
|
Console.WriteLine("End of sequence reached, tabbing back to first window");
|
||||||
TabTo(FirstIndex + 1);
|
TabTo(sequenceFirstIndex + 1);
|
||||||
ExitSequenceMode();
|
ExitSequenceMode();
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine($"Tabbing to index {CurrentSequenceIndex + 1}");
|
Console.WriteLine($"Tabbing to index {CurrentSequenceIndex + 1}");
|
||||||
@@ -116,11 +116,11 @@ namespace DD2Switcher {
|
|||||||
string json = File.ReadAllText(settingsPath);
|
string json = File.ReadAllText(settingsPath);
|
||||||
Console.WriteLine($"Read JSON: {json}");
|
Console.WriteLine($"Read JSON: {json}");
|
||||||
var settings = JsonSerializer.Deserialize<Settings>(json);
|
var settings = JsonSerializer.Deserialize<Settings>(json);
|
||||||
FirstIndex = settings.FirstIndex;
|
// DO NOT load FirstIndex and LastIndex - they should be set by user only
|
||||||
LastIndex = settings.LastIndex;
|
// FirstIndex = settings.FirstIndex;
|
||||||
|
// LastIndex = settings.LastIndex;
|
||||||
SequenceKeybind = settings.SequenceKeybind;
|
SequenceKeybind = settings.SequenceKeybind;
|
||||||
Console.WriteLine(
|
Console.WriteLine($"Loaded settings: Keybind={SequenceKeybind} (First/Last indices NOT loaded)");
|
||||||
$"Loaded settings: First={FirstIndex}, Last={LastIndex}, Keybind={SequenceKeybind}");
|
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine($"Settings file does not exist at: {settingsPath}");
|
Console.WriteLine($"Settings file does not exist at: {settingsPath}");
|
||||||
Console.WriteLine("Using default settings");
|
Console.WriteLine("Using default settings");
|
||||||
|
@@ -151,10 +151,18 @@ namespace DD2Switcher {
|
|||||||
windowPanelForm.UpdateDisplay();
|
windowPanelForm.UpdateDisplay();
|
||||||
|
|
||||||
windowPanelForm.PickClicked += (sender, index) => {
|
windowPanelForm.PickClicked += (sender, index) => {
|
||||||
if (Program.FirstIndex == -1) {
|
// If clicking on a window that's already first or last, remove that setting
|
||||||
|
if (index == Program.FirstIndex) {
|
||||||
|
Program.FirstIndex = -1;
|
||||||
|
Console.WriteLine($"Removed first index: {index}");
|
||||||
|
} else if (index == Program.LastIndex) {
|
||||||
|
Program.LastIndex = -1;
|
||||||
|
Console.WriteLine($"Removed last index: {index}");
|
||||||
|
} else if (Program.FirstIndex == -1) {
|
||||||
// First pick - set both first and last
|
// First pick - set both first and last
|
||||||
Program.FirstIndex = index;
|
Program.FirstIndex = index;
|
||||||
Program.LastIndex = index;
|
Program.LastIndex = index;
|
||||||
|
Console.WriteLine($"Set first and last index: {index}");
|
||||||
} else if (Program.LastIndex == -1) {
|
} else if (Program.LastIndex == -1) {
|
||||||
// Second pick - set last (must be >= first)
|
// Second pick - set last (must be >= first)
|
||||||
if (index >= Program.FirstIndex) {
|
if (index >= Program.FirstIndex) {
|
||||||
@@ -163,6 +171,7 @@ namespace DD2Switcher {
|
|||||||
Program.LastIndex = Program.FirstIndex;
|
Program.LastIndex = Program.FirstIndex;
|
||||||
Program.FirstIndex = index;
|
Program.FirstIndex = index;
|
||||||
}
|
}
|
||||||
|
Console.WriteLine($"Set last index: {Program.LastIndex}");
|
||||||
} else {
|
} else {
|
||||||
// Subsequent picks - determine which becomes first
|
// Subsequent picks - determine which becomes first
|
||||||
int distanceToFirst = Math.Abs(index - Program.FirstIndex);
|
int distanceToFirst = Math.Abs(index - Program.FirstIndex);
|
||||||
@@ -185,6 +194,7 @@ namespace DD2Switcher {
|
|||||||
Program.LastIndex = index;
|
Program.LastIndex = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Console.WriteLine($"Updated indices: First={Program.FirstIndex}, Last={Program.LastIndex}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure last >= first
|
// Ensure last >= first
|
||||||
|
Reference in New Issue
Block a user