feat: 移植 B50 成绩图,并把项目名从 purarine 改回 ichino
海报从 Empurple 的 Best50ImageRenderer/ImageBuilder 移植:按原始像素坐标 (1762x1850 画布、300x100 卡片、5 列、行距 120) 叠加在 base.png 上,底图里 已画好的面板/药丸标签/页脚不重复绘制;页面外壳走 Ichino 的 Material 3。 RatingCalculator 的达成率分档改成单张有序表,避免偏移与评级错位; RA 与评级由 test/rating_calculator_test.dart 的边界用例锁定。 GetUserRatingApi 只需要 userId(Cookie 可选),所以 Preview API 模式、未登录 游戏服务器时也能出图,只是没有 FC/AP/FS 标记。导出用 RepaintBoundary 抓 全尺寸 PNG:原生走 share_plus(不支持文件分享的平台回退为落盘并提示路径), web 走下载。 BEST35 与 BEST15 改为各自独立排版。原先沿用 Empurple 的跨列表全局序号, BEST35 没打满时 BEST15 会整体上移混进上半区。 path_provider 会经 path_provider_android 2.3.x 拖入 jni 插件,而 jni 把 windows/linux 也声明成 ffiPlugin,桌面构建因此去链接 jvm.lib 并失败, 故用 dependency_overrides 钉住 path_provider_android <2.3.0。
This commit is contained in:
1 parent
24ccd628d1
commit
79fa0d7a20
67 files changed
+1563
-62
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'music_data_cache.dart';
|
||||
|
||||
class MusicInfo {
|
||||
final String title;
|
||||
final Map<int, double> dsByLevel;
|
||||
|
||||
const MusicInfo({required this.title, required this.dsByLevel});
|
||||
}
|
||||
|
||||
/// 乐曲元数据来源,移植自 Empurple 的 `MusicDataProvider`。
|
||||
///
|
||||
/// 游戏接口的 ratingList 只有 musicId,曲名与各难度定数需要另行获取。
|
||||
class MusicDataService {
|
||||
static const String _musicDataUrl =
|
||||
'https://www.diving-fish.com/api/maimaidxprober/music_data';
|
||||
static const String _cacheFileName = 'music_data.json';
|
||||
|
||||
MusicDataService._();
|
||||
|
||||
static final MusicDataService instance = MusicDataService._();
|
||||
|
||||
final Map<int, MusicInfo> _byId = {};
|
||||
Future<void>? _inFlight;
|
||||
|
||||
String getTitle(int musicId) => _byId[musicId]?.title ?? 'Unknown';
|
||||
|
||||
/// 缺失定数时返回 0,RA 也随之为 0,与 Empurple 行为一致。
|
||||
double getDs(int musicId, int level) =>
|
||||
_byId[musicId]?.dsByLevel[level] ?? 0.0;
|
||||
|
||||
/// 并发调用共享同一次下载。
|
||||
Future<void> load() {
|
||||
if (_byId.isNotEmpty) return Future.value();
|
||||
return _inFlight ??= _load().whenComplete(() => _inFlight = null);
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final cached = await readTextCache(_cacheFileName);
|
||||
final content = cached ?? await _download();
|
||||
_parse(content);
|
||||
if (cached == null) {
|
||||
await writeTextCache(_cacheFileName, content);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _download() async {
|
||||
final response = await http
|
||||
.get(Uri.parse(_musicDataUrl), headers: const {'User-Agent': 'Ichino/1.0'})
|
||||
.timeout(const Duration(seconds: 20));
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('music_data HTTP ${response.statusCode}');
|
||||
}
|
||||
return response.body;
|
||||
}
|
||||
|
||||
void _parse(String content) {
|
||||
final decoded = jsonDecode(content);
|
||||
if (decoded is! List) return;
|
||||
_byId.clear();
|
||||
for (final item in decoded.whereType<Map<String, dynamic>>()) {
|
||||
final id = _toInt(item['id']);
|
||||
if (id == 0) continue;
|
||||
final ds = item['ds'];
|
||||
_byId[id] = MusicInfo(
|
||||
title: item['title']?.toString() ?? 'Unknown',
|
||||
dsByLevel: ds is List
|
||||
? {
|
||||
for (var level = 0; level < ds.length; level++)
|
||||
level: _toDouble(ds[level]),
|
||||
}
|
||||
: const {},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static int _toInt(dynamic v) {
|
||||
if (v is int) return v;
|
||||
if (v is num) return v.toInt();
|
||||
if (v is String) return int.tryParse(v) ?? 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double _toDouble(dynamic v) {
|
||||
if (v is double) return v;
|
||||
if (v is int) return v.toDouble();
|
||||
if (v is String) return double.tryParse(v) ?? 0.0;
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user