Skip to content

Commit 4cecba5

Browse files
committed
[LOOP-4596] Scenario Organization
1 parent 85f5db4 commit 4cecba5

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

Loop/View Controllers/TestingScenariosTableViewController.swift

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
1414

1515
private let scenariosManager: TestingScenariosManager
1616

17-
private var scenarioURLs: [URL] = [] {
17+
private var scenarios: [LoopScenario] = [] {
1818
didSet {
19-
options = scenarioURLs.map {
20-
$0 // /Scenarios/HF-1-Scenario_1.json
21-
.deletingPathExtension() // /Scenarios/HF-1-Scenario_1
22-
.lastPathComponent // HF-1-Scenario_1
23-
.replacingOccurrences(of: "HF-1-", with: "") // Scenario_1
24-
.replacingOccurrences(of: "HF-2-", with: "") // Scenario_1
25-
.replacingOccurrences(of: "_", with: " ") // Scenario 1
26-
}
19+
options = scenarios.map(\.name)
20+
2721
if isViewLoaded {
2822
DispatchQueue.main.async {
2923
self.updateLoadButtonEnabled()
@@ -65,14 +59,14 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
6559
contextHelp = "The scenarios directory location is available in the debug output of the Xcode console."
6660

6761
if let activeScenarioURL = scenariosManager.activeScenarioURL {
68-
selectedIndex = scenarioURLs.firstIndex(of: activeScenarioURL)
62+
selectedIndex = scenarios.firstIndex(where: { $0.url == activeScenarioURL })
6963
}
7064

7165
updateLoadButtonEnabled()
7266
}
7367

7468
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
75-
let url = scenarioURLs[indexPath.row]
69+
let url = scenarios[indexPath.row].url
7670

7771
let rewindScenario = contextualAction(
7872
rowTitle: "⏮ Rewind",
@@ -86,7 +80,7 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
8680
}
8781

8882
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
89-
let url = scenarioURLs[indexPath.row]
83+
let url = scenarios[indexPath.row].url
9084

9185
let advanceScenario = contextualAction(
9286
rowTitle: "Advance ⏭",
@@ -137,7 +131,7 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
137131
}
138132

139133
private func updateLoadButtonEnabled() {
140-
loadButtonItem.isEnabled = !scenarioURLs.isEmpty && selectedIndex != nil
134+
loadButtonItem.isEnabled = !scenarios.isEmpty && selectedIndex != nil
141135
}
142136

143137
@objc private func loadSelectedScenario() {
@@ -146,7 +140,7 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
146140
return
147141
}
148142

149-
let url = scenarioURLs[selectedIndex]
143+
let url = scenarios[selectedIndex].url
150144

151145
loadButtonItem.isEnabled = false
152146
loadButtonItem.title = "Loading..."
@@ -170,13 +164,13 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
170164

171165
extension TestingScenariosTableViewController: TestingScenariosManagerDelegate {
172166
func testingScenariosManager(_ manager: TestingScenariosManager, didUpdateScenarioURLs scenarioURLs: [URL]) {
173-
var filteredURLs = Set<URL>()
167+
var filteredScenarios = Set<LoopScenario>()
174168
manager.pluginManager.availableSupports.forEach { supportUI in
175-
supportUI.filterScenarios(scenarioURLs: scenarioURLs).forEach { scenarioURL in
176-
filteredURLs.insert(scenarioURL)
169+
supportUI.filteredScenarios(scenarioURLs: scenarioURLs).forEach { scenario in
170+
filteredScenarios.insert(scenario)
177171
}
178172
}
179173

180-
self.scenarioURLs = Array(filteredURLs).sorted(by: { $0.lastPathComponent < $1.lastPathComponent })
174+
self.scenarios = Array(filteredScenarios).sorted(by: { $0.name < $1.name })
181175
}
182176
}

0 commit comments

Comments
 (0)