Repository navigation
Expand file tree
/
Copy pathWeatherExperience.swift
More file actions
348 lines (303 loc) · 10.2 KB
/
Copy pathWeatherExperience.swift
File metadata and controls
348 lines (303 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
import SwiftUI
import UIKit
enum WeatherCondition: String, CaseIterable {
case sunny
case rainy
case snowy
static func actionPool(for condition: WeatherCondition) -> [String] {
switch condition {
case .sunny: return ["lookright", "lookleft", "nodsleepy", "tilt"]
case .rainy: return ["shakewater", "tilt"]
case .snowy: return ["shiver", "nodsleepy"]
}
}
}
enum WeatherType: String, CaseIterable {
case sunny = "晴天"
case lightRain = "小雨"
case moderateRain = "中雨"
case heavyRain = "大雨"
case storm = "暴雨"
case snowy = "雪天"
var weatherCondition: WeatherCondition {
switch self {
case .sunny: return .sunny
case .lightRain, .moderateRain, .heavyRain, .storm: return .rainy
case .snowy: return .snowy
}
}
var intensity: Float {
switch self {
case .sunny: return 0.0
case .lightRain: return 0.2
case .moderateRain: return 0.5
case .heavyRain: return 0.8
case .storm: return 1.0
case .snowy: return 0.4
}
}
var icon: String {
switch self {
case .sunny: return "sun.max.fill"
case .lightRain: return "cloud.drizzle.fill"
case .moderateRain: return "cloud.rain.fill"
case .heavyRain: return "cloud.heavyrain.fill"
case .storm: return "cloud.bolt.rain.fill"
case .snowy: return "cloud.snow.fill"
}
}
mutating func next() {
let all = Self.allCases
if let idx = all.firstIndex(of: self) {
self = all[(idx + 1) % all.count]
}
}
}
enum TimeOfDay: String, CaseIterable {
case morning = "清晨"
case noon = "正午"
case evening = "傍晚"
case night = "深夜"
var icon: String {
switch self {
case .morning: return "sunrise.fill"
case .noon: return "sun.max.fill"
case .evening: return "sunset.fill"
case .night: return "moon.stars.fill"
}
}
var lightColor: UIColor {
switch self {
case .morning: return UIColor(red: 1.0, green: 0.85, blue: 0.7, alpha: 1.0)
case .noon: return .white
case .evening: return UIColor(red: 1.0, green: 0.55, blue: 0.3, alpha: 1.0)
case .night: return UIColor(red: 0.4, green: 0.5, blue: 0.8, alpha: 1.0)
}
}
var lightPosition: SIMD3<Float> {
switch self {
case .morning: return SIMD3<Float>(1.8, 2.5, -8.0)
case .noon: return SIMD3<Float>(0.0, 3.5, -8.0)
case .evening: return SIMD3<Float>(-1.8, 2.5, -8.0)
case .night: return SIMD3<Float>(-1.5, 3.0, -8.0)
}
}
var intensityMultiplier: Float {
switch self {
case .morning: return 0.8
case .noon: return 1.0
case .evening: return 0.7
case .night: return 0.2
}
}
var skyGradient: LinearGradient {
switch self {
case .morning:
return LinearGradient(colors: [Color(red: 0.4, green: 0.6, blue: 0.8), Color(red: 0.9, green: 0.7, blue: 0.5)], startPoint: .top, endPoint: .bottom)
case .noon:
return LinearGradient(colors: [Color(red: 0.35, green: 0.65, blue: 0.95), Color(red: 0.65, green: 0.85, blue: 1.0)], startPoint: .top, endPoint: .bottom)
case .evening:
return LinearGradient(colors: [Color(red: 0.2, green: 0.3, blue: 0.5), Color(red: 0.8, green: 0.4, blue: 0.2)], startPoint: .top, endPoint: .bottom)
case .night:
return LinearGradient(colors: [Color(red: 0.05, green: 0.05, blue: 0.1), Color(red: 0.1, green: 0.15, blue: 0.25)], startPoint: .top, endPoint: .bottom)
}
}
var celestialSymbol: String {
switch self {
case .morning, .noon, .evening: return "sun.max.fill"
case .night: return "moon.fill"
}
}
var celestialColor: Color {
switch self {
case .morning: return Color(red: 1.0, green: 0.6, blue: 0.2)
case .noon: return Color(red: 1.0, green: 0.9, blue: 0.6)
case .evening: return Color(red: 0.9, green: 0.3, blue: 0.1)
case .night: return Color(red: 0.8, green: 0.9, blue: 1.0)
}
}
var celestialAlignment: Alignment {
switch self {
case .morning: return .topTrailing
case .noon: return .top
case .evening, .night: return .topLeading
}
}
mutating func next() {
let all = Self.allCases
if let idx = all.firstIndex(of: self) {
self = all[(idx + 1) % all.count]
}
}
}
struct WeatherPresentation {
let cityName: String
let temperatureText: String
let currentWeather: WeatherType
let timeOfDay: TimeOfDay
var snapshot: WeatherSnapshot {
WeatherSnapshot(weather: currentWeather, timeOfDay: timeOfDay)
}
var statusLine: String {
snapshot.homeLine
}
var keyAdvice: String {
snapshot.keyAdvice
}
var widgetContent: WidgetDisplayContent {
WidgetDisplayContent(
cityName: cityName,
temperatureText: temperatureText,
weatherLabel: currentWeather.rawValue,
poseLabel: snapshot.pose.rawValue,
widgetLine: snapshot.widgetLine,
keyAdvice: snapshot.keyAdvice
)
}
var homeContent: HomeDisplayContent {
HomeDisplayContent(
cityName: cityName,
temperatureText: temperatureText,
contextLine: "\(timeLabel) · \(currentWeather.rawValue)",
poseLabel: snapshot.pose.rawValue,
statusLine: snapshot.homeLine,
keyAdvice: snapshot.keyAdvice,
detailLine: snapshot.detailLine,
trendHint: snapshot.trendHint
)
}
var timeLabel: String {
switch timeOfDay {
case .morning: return "清晨"
case .noon: return "白天"
case .evening: return "傍晚"
case .night: return "夜里"
}
}
}
struct HomeDisplayContent {
let cityName: String
let temperatureText: String
let contextLine: String
let poseLabel: String
let statusLine: String
let keyAdvice: String
let detailLine: String
let trendHint: String
}
struct WidgetDisplayContent {
let cityName: String
let temperatureText: String
let weatherLabel: String
let poseLabel: String
let widgetLine: String
let keyAdvice: String
}
struct WeatherSnapshot {
enum ManulPose: String {
case squintingRest = "眯眼趴着"
case flatWatch = "无聊观察"
case curledRain = "缩着避雨"
case calmSnow = "安静蓬起"
case nightWatch = "夜里警觉"
}
let weather: WeatherType
let timeOfDay: TimeOfDay
var pose: ManulPose {
if timeOfDay == .night {
return .nightWatch
}
switch weather {
case .sunny:
return .squintingRest
case .lightRain, .moderateRain, .heavyRain, .storm:
return .curledRain
case .snowy:
return .calmSnow
}
}
var homeLine: String {
if timeOfDay == .night {
return "天黑了,安静点挺好。"
}
switch weather {
case .sunny: return "亮成这样,谁爱出门谁出门。"
case .lightRain, .moderateRain: return "下得不算狠,烦是一点没少。"
case .heavyRain, .storm: return "这种天还想体面出门?"
case .snowy: return "终于像点样子了。"
}
}
var widgetLine: String {
if timeOfDay == .night {
return "夜里别闹。"
}
switch weather {
case .sunny: return "太亮了。"
case .lightRain, .moderateRain: return "潮,真烦。"
case .heavyRain, .storm: return "别硬出门。"
case .snowy: return "这天还行。"
}
}
var keyAdvice: String {
if timeOfDay == .night {
return "夜里降温"
}
switch weather {
case .sunny: return "紫外线偏强"
case .lightRain, .moderateRain: return "出门带伞"
case .heavyRain, .storm: return "尽量减少外出"
case .snowy: return "注意保暖和路滑"
}
}
var detailLine: String {
if timeOfDay == .night {
return "当前偏凉,夜里更适合安静待着。"
}
switch weather {
case .sunny: return "当前晴朗偏晒,体感会更热一点。"
case .lightRain: return "当前小雨偏潮,晚些时候还会断续落雨。"
case .moderateRain: return "当前中雨,体感偏湿冷,出门最好备伞。"
case .heavyRain, .storm: return "当前雨势偏强,今天更适合减少外出。"
case .snowy: return "当前有雪,空气冷而安静,注意保暖和路滑。"
}
}
var trendHint: String {
if timeOfDay == .night {
return "明早再看"
}
switch weather {
case .sunny: return "晚点会柔和些"
case .lightRain, .moderateRain: return "稍后还会下"
case .heavyRain, .storm: return "今晚仍有雨"
case .snowy: return "夜里会更冷"
}
}
var interactionLines: [String] {
if timeOfDay == .night {
return ["夜里安静点。", "都这时候了,还不休息?"]
}
switch weather {
case .sunny:
return ["亮成这样,谁爱出门谁出门。", "晒得眼都懒得睁。"]
case .lightRain, .moderateRain:
return ["下得不算狠,烦是一点没少。", "潮成这样,还想出门?"]
case .heavyRain, .storm:
return ["这种天还想体面出门?", "别硬撑了,今天就在屋里待着。"]
case .snowy:
return ["终于像点样子了。", "冷是冷,至少比闷雨强。"]
}
}
var transitionLine: String {
interactionLines.first ?? homeLine
}
var widgetAccent: Color {
if timeOfDay == .night {
return .cyan
}
switch weather {
case .sunny: return .yellow
case .lightRain, .moderateRain, .heavyRain, .storm: return .white
case .snowy: return Color(red: 0.82, green: 0.9, blue: 1.0)
}
}
}