AtmoSphere/lib/services/wallpaper_service.dart
2026-01-16 18:22:32 +08:00

76 lines
1.8 KiB
Dart

import 'dart:math';
class WallpaperService {
final Random _random = Random();
final Map<String, int> _wallpaperCounts = {
'clear_day': 3,
'clear_night': 5,
'cloudy_day': 4,
'cloudy_night': 4,
'rain_day': 4,
'rain_night': 4,
'snow_day': 4,
'snow_night': 1,
'fog_day': 1,
'fog_night': 1,
'default': 1,
};
String _getRandomAssetForCategory(String category) {
final key = _wallpaperCounts.containsKey(category) ? category : 'default';
final count = _wallpaperCounts[key]!;
if (count == 0) {
return 'assets/wallpapers/default/image1.png';
}
final imageNumber = _random.nextInt(count) + 1;
return 'assets/wallpapers/$key/image$imageNumber.png';
}
String getWallpaper(int conditionCode, bool isDay) {
String categoryKey;
switch (conditionCode) {
case 1000:
categoryKey = isDay ? 'clear_day' : 'clear_night';
break;
case 1003:
case 1006:
case 1009:
categoryKey = isDay ? 'cloudy_day' : 'cloudy_night';
break;
case 1030:
case 1135:
case 1147:
categoryKey = isDay ? 'fog_day' : 'fog_night';
break;
case 1063:
case 1180:
case 1183:
case 1186:
case 1189:
case 1192:
case 1195:
categoryKey = isDay ? 'rain_day' : 'rain_night';
break;
case 1066:
case 1210:
case 1213:
case 1216:
case 1219:
case 1222:
case 1225:
categoryKey = isDay ? 'snow_day' : 'snow_night';
break;
case 1087:
case 1273:
case 1276:
categoryKey = isDay ? 'rain_day' : 'rain_night';
break;
default:
categoryKey = 'default';
break;
}
return _getRandomAssetForCategory(categoryKey);
}
}