diff --git a/Clemens Playground/Clemens_PlaygroundApp.swift b/Clemens Playground/Clemens_PlaygroundApp.swift index 1270293..211e32f 100644 --- a/Clemens Playground/Clemens_PlaygroundApp.swift +++ b/Clemens Playground/Clemens_PlaygroundApp.swift @@ -22,18 +22,9 @@ import WebKit @main struct Clemens_PlaygroundApp: App { - - private var url = "https://fressnapf-dev-gameassets.gamegame-server.de/" - var body: some Scene { WindowGroup { - VStack { - // Use this for >= Xcode 26 and remove commentary in "NewWebView.swift" - // NewWebView(url) - - // Use this for < Xcode 26 - OldWebView(url) - } + GameSelection() } } } diff --git a/Clemens Playground/Data/Game.swift b/Clemens Playground/Data/Game.swift new file mode 100644 index 0000000..27bba69 --- /dev/null +++ b/Clemens Playground/Data/Game.swift @@ -0,0 +1,14 @@ +// +// Game.swift +// Clemens Playground +// +// Created by Maximilian Roider on 14.11.25. +// + +import Foundation + +struct Game: Hashable, Codable, Identifiable { + var id: Int + var name: String + var url: String +} diff --git a/Clemens Playground/Data/Loader.swift b/Clemens Playground/Data/Loader.swift new file mode 100644 index 0000000..ac08715 --- /dev/null +++ b/Clemens Playground/Data/Loader.swift @@ -0,0 +1,33 @@ +// +// Loader.swift +// Clemens Playground +// +// Created by Maximilian Roider on 14.11.25. +// + +import Foundation + +var games: [Game] = load("games.json") + +func load(_ filename: String) -> T { + + let data: Data + + guard let file = Bundle.main.url(forResource: filename, withExtension: nil) + else { + fatalError("Couldn't find \(filename) in main bundle.") + } + + do { + data = try Data(contentsOf: file) + } catch { + fatalError("Couldn't load \(filename) from main bundle:\n\(error)") + } + + do { + let decoder = JSONDecoder() + return try decoder.decode(T.self, from: data) + } catch { + fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)") + } +} diff --git a/Clemens Playground/Screens/GameSelection.swift b/Clemens Playground/Screens/GameSelection.swift new file mode 100644 index 0000000..fc5b003 --- /dev/null +++ b/Clemens Playground/Screens/GameSelection.swift @@ -0,0 +1,25 @@ +// +// GameSelection.swift +// Clemens Playground +// +// Created by Maximilian Roider on 14.11.25. +// + +import SwiftUI + +struct GameSelection: View { + var body: some View { + NavigationSplitView { + List(games) { game in + NavigationLink { + GameView(game) + } label: { + GameRow(game) + } + } + .navigationTitle("Games") + } detail: { + Text("Select a game") + } + } +} diff --git a/Clemens Playground/Screens/GameView.swift b/Clemens Playground/Screens/GameView.swift new file mode 100644 index 0000000..a09c925 --- /dev/null +++ b/Clemens Playground/Screens/GameView.swift @@ -0,0 +1,24 @@ +// +// GameView.swift +// Clemens Playground +// +// Created by Maximilian Roider on 14.11.25. +// + +import SwiftUI + +struct GameView: View { + private let game: Game + + init(_ game: Game) { + self.game = game + } + + var body: some View { + // Use this for >= Xcode 26 and remove commentary in "NewWebView.swift" + // NewWebView(game.url) + + // Use this for < Xcode 26 + OldWebView(game.url) + } +} diff --git a/Clemens Playground/Views/GameSelection/GameRow.swift b/Clemens Playground/Views/GameSelection/GameRow.swift new file mode 100644 index 0000000..86d01d5 --- /dev/null +++ b/Clemens Playground/Views/GameSelection/GameRow.swift @@ -0,0 +1,25 @@ +// +// GameRow.swift +// Clemens Playground +// +// Created by Maximilian Roider on 14.11.25. +// + +import SwiftUI + +struct GameRow: View { + + var game: Game + + init(_ game: Game) { + self.game = game + } + + var body: some View { + HStack { + Text(game.name) + Spacer() + Image(systemName: "chevron.forward") + } + } +} diff --git a/Clemens Playground/NewWebView.swift b/Clemens Playground/Views/WebViews/NewWebView.swift similarity index 100% rename from Clemens Playground/NewWebView.swift rename to Clemens Playground/Views/WebViews/NewWebView.swift diff --git a/Clemens Playground/OldWebView.swift b/Clemens Playground/Views/WebViews/OldWebView.swift similarity index 94% rename from Clemens Playground/OldWebView.swift rename to Clemens Playground/Views/WebViews/OldWebView.swift index 8a70101..79288fb 100644 --- a/Clemens Playground/OldWebView.swift +++ b/Clemens Playground/Views/WebViews/OldWebView.swift @@ -10,7 +10,7 @@ import SwiftUI import WebKit struct OldWebView: UIViewRepresentable { - let url: String + private let url: String init(_ url: String) { self.url = url diff --git a/Clemens Playground/games.json b/Clemens Playground/games.json new file mode 100644 index 0000000..69ba7ab --- /dev/null +++ b/Clemens Playground/games.json @@ -0,0 +1,12 @@ +[ + { + "id": 1001, + "name": "Fressnapf", + "url": "https://fressnapf-dev-gameassets.gamegame-server.de/" + }, + { + "id": 1002, + "name": "Projekt-Git", + "url": "https://git.roider.tech/darksider110/Clemens-Webview-Playground" + }, +]