To keep transitions between scenes instant, I map the story's JSON into a dictionary when the app starts. This swaps out slow linear searches for O(1) lookups, so the game stays snappy even as the script gets longer.
private func loadStory() {
guard let url = Bundle.main.url(forResource: "story", withExtension: "json"),
let data = try? Data(contentsOf: url) else { return }
do {
let decoded = try JSONDecoder().decode(StoryData.self, from: data)
for page in decoded.screens {
pages[page.id] = page
}
orderedPages = decoded.screens
currentPageID = decoded.screens.first?.id
} catch {
print("Failed to decode story.json: \(error)")
}
}



