Skip to content

Commit

Permalink
feat(Studio): Enforce room indexing with StyleConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Dec 27, 2024
1 parent d369818 commit b5ab201
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Studio/CelesteStudio/Editing/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ public Document Document {
Recalc();
ScrollCaretIntoView();

// Detect user-preference for room indexing
DetectPreference();
if (StyleConfig.Current.RoomLabelStartingIndex == null) {
// Detect user-preference for room indexing
DetectPreference();
}

UpdateRoomLabelIndices([]);

Settings.Changed += () => {
DetectPreference();
if (StyleConfig.Current.RoomLabelStartingIndex == null) {
DetectPreference();
}
UpdateRoomLabelIndices([]);
};

Expand Down Expand Up @@ -140,7 +145,10 @@ void HandleTextChanged(Document _, Dictionary<int, string> insertions, Dictionar
}

void UpdateRoomLabelIndices(int[] rowsToIgnore) {
if (Settings.Instance.AutoIndexRoomLabels == AutoRoomIndexing.Disabled) {
var autoIndexing = StyleConfig.Current.RoomLabelIndexing ?? Settings.Instance.AutoIndexRoomLabels;
int startingIndex = Math.Max(StyleConfig.Current.RoomLabelStartingIndex ?? roomLabelStartIndex, 0);

if (autoIndexing == AutoRoomIndexing.Disabled) {
return;
}

Expand All @@ -149,7 +157,7 @@ void UpdateRoomLabelIndices(int[] rowsToIgnore) {
// Allows the user to edit labels without them being auto-trimmed
string untrimmedLabel = string.Empty;

foreach ((string line, int row, string filePath, _) in IterateDocumentLines(includeReads: Settings.Instance.AutoIndexRoomLabels == AutoRoomIndexing.IncludeReads)) {
foreach ((string line, int row, string filePath, _) in IterateDocumentLines(includeReads: autoIndexing == AutoRoomIndexing.IncludeReads)) {
var match = RoomLabelRegex.Match(line);
if (!match.Success) {
continue;
Expand Down Expand Up @@ -200,10 +208,10 @@ void UpdateRoomLabelIndices(int[] rowsToIgnore) {

if (!rowsToIgnore.Contains(occurrences[i].Row)) {
string oldLabel = Document.Lines[occurrences[i].Row]["#".Length..];
string newLabel = $"lvl_{label} ({i + roomLabelStartIndex})";
string newLabel = $"lvl_{label} ({i + startingIndex})";
Task.Run(async () => await RefactorLabelName(oldLabel, newLabel).ConfigureAwait(false));
}
Document.ReplaceLine(occurrences[i].Row, $"#lvl_{writtenLabel} ({i + roomLabelStartIndex})");
Document.ReplaceLine(occurrences[i].Row, $"#lvl_{writtenLabel} ({i + startingIndex})");
}
}
}
Expand Down

0 comments on commit b5ab201

Please sign in to comment.