Skip to content

Commit 86550d9

Browse files
committed
feat: debug mode
1 parent c00da57 commit 86550d9

2 files changed

Lines changed: 52 additions & 13 deletions

File tree

lib/utils/shader_selector.dart

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class ShaderConfig {
6161
}
6262

6363
class ShaderSelector {
64+
static bool debugForceThunderstormFog = false;
65+
6466
static bool _isThunderstormCode(int code) {
6567
return code == 103 ||
6668
code == 104 ||
@@ -93,11 +95,34 @@ class ShaderSelector {
9395
}
9496

9597
static ShaderConfig selectShaderConfig(RealtimeWeather? weather) {
96-
return const ShaderConfig(
97-
showFog: true,
98-
showRain: false,
99-
showThunderstorm: true,
100-
fogIntensity: 0.2,
98+
if (debugForceThunderstormFog) {
99+
return const ShaderConfig(
100+
showFog: true,
101+
showRain: false,
102+
showThunderstorm: true,
103+
fogIntensity: 0.2,
104+
);
105+
}
106+
107+
if (weather == null) {
108+
return const ShaderConfig();
109+
}
110+
111+
final weatherCode = weather.data.weatherCode;
112+
final rain = weather.data.rain;
113+
final visibility = parseVisibility(weather.data.visibility);
114+
115+
final showThunderstorm = _isThunderstormCode(weatherCode);
116+
final showRain =
117+
(_isRainCode(weatherCode) || rain > 0) && !showThunderstorm;
118+
final showFog = visibility < 5.0 || _isFogCode(weatherCode);
119+
final fogIntensity = showFog ? calculateFogIntensity(visibility) : 0.0;
120+
121+
return ShaderConfig(
122+
showFog: showFog,
123+
showRain: showRain,
124+
showThunderstorm: showThunderstorm,
125+
fogIntensity: fogIntensity,
101126
);
102127
}
103128

lib/utils/wallpaper_selector.dart

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import 'dart:math' as math;
2-
31
class WallpaperSelector {
2+
static String? debugWallpaperPath = null;
3+
44
static const List<String> dayWallpapers = [
55
'assets/wallpaper/day/autumn_park.jpg',
66
'assets/wallpaper/day/city_foggy.jpg',
@@ -28,17 +28,32 @@ class WallpaperSelector {
2828
'assets/wallpaper/night/town_hillside.jpg',
2929
];
3030

31+
static int _hashDate(DateTime date) {
32+
final dayOfYear = date.difference(DateTime(date.year, 1, 1)).inDays + 1;
33+
return (date.year * 1000 + dayOfYear) % 2147483647;
34+
}
35+
3136
static String selectWallpaper(DateTime utc8Time) {
37+
if (debugWallpaperPath != null) {
38+
return debugWallpaperPath!;
39+
}
40+
3241
final hour = utc8Time.hour;
33-
final dayOfYear = utc8Time.difference(DateTime(utc8Time.year, 1, 1)).inDays + 1;
34-
final random = math.Random(utc8Time.year * 365 + dayOfYear);
42+
final dateHash = _hashDate(utc8Time);
43+
final periodHash = hour >= 6 && hour < 18
44+
? 0
45+
: (hour >= 18 && hour < 20 ? 1 : 2);
46+
final combinedHash = (dateHash * 3 + periodHash) % 2147483647;
3547

3648
if (hour >= 6 && hour < 18) {
37-
return dayWallpapers[random.nextInt(dayWallpapers.length)];
49+
final index = combinedHash % dayWallpapers.length;
50+
return dayWallpapers[index];
3851
} else if (hour >= 18 && hour < 20) {
39-
return duskWallpapers[random.nextInt(duskWallpapers.length)];
52+
final index = combinedHash % duskWallpapers.length;
53+
return duskWallpapers[index];
4054
} else {
41-
return nightWallpapers[random.nextInt(nightWallpapers.length)];
55+
final index = combinedHash % nightWallpapers.length;
56+
return nightWallpapers[index];
4257
}
4358
}
4459

@@ -47,4 +62,3 @@ class WallpaperSelector {
4762
return now.add(const Duration(hours: 8));
4863
}
4964
}
50-

0 commit comments

Comments
 (0)