This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ShimmerView: View { | |
private struct Constants { | |
static let duration: Double = 0.9 | |
static let minOpacity: Double = 0.25 | |
static let maxOpacity: Double = 1.0 | |
static let cornerRadius: CGFloat = 2.0 | |
} | |
@State private var opacity: Double = Constants.minOpacity | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class LastRidleIdStore { | |
private let key = "com.wordle.last.ridle.id.key" | |
private let userDefaults = UserDefaults.standard | |
func saveLastRidle(id: String) { | |
userDefaults.set(id, forKey: key) | |
} | |
func getLastRidleId() -> String? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class RidleProvider { | |
private static var riddle = Ridle.defaultRiddle() | |
func fetch(completion: @escaping (_ ridle: Ridle?) -> Void) { | |
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { | |
completion(RidleProvider.riddle) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Ridle { | |
var words: [Word] | |
var currentWordIndex: Int | |
var currentCharIndex: Int | |
let id: String | |
let answer: String | |
let availableUntil: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct GameView: View { | |
@StateObject var viewModel = GameViewModel(riddle: Ridle.defaultRiddle(), keys: Keys.defaultKeys()) | |
var body: some View { | |
Group { | |
ZStack { | |
GeometryReader { geo in | |
if viewModel.gameState == .loading { | |
EmptyView() | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import Combine | |
final class GameViewModel: ObservableObject { | |
enum GameState { | |
case play, win, lose, waitingForNewRidle, loading | |
} | |
private let ridleProvider = RidleProvider() | |
private let lastRidleIdStore = LastRidleIdStore() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Keys { | |
var rows: [KeysRow] | |
} | |
extension Keys { | |
static func initFrom(keysStrs: [String]) -> Keys { | |
let rows = keysStrs.compactMap { | |
KeysRow(chars: $0.compactMap { Char(title: String($0), highlight: .none) }) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct KeysRow { | |
var chars: [Char] = [] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct KeyboardView: View { | |
let keys: Keys | |
let width: CGFloat | |
let onTap: (_ char: String) -> Void | |
let onEnter: () -> Void | |
let onRemove: () -> Void | |
var body: some View { | |
let width = charSize(width: width, keys: keys) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct BoardView: View { | |
let words: [Word] | |
var body: some View { | |
VStack(spacing: 6) { | |
ForEach((0...5), id: \.self) { index in | |
WordView(word: words[index]) | |
} | |
} | |
} |