feat: move json file data to code

This commit is contained in:
xkeyC 2024-05-05 15:05:47 +08:00
parent f392463a84
commit a8e88983e2
6 changed files with 31 additions and 38 deletions

View File

@ -1,4 +1,4 @@
{
final advancedLocalizationJsonData = {
"class_keys": [
{
"id": "location_opt",
@ -98,9 +98,7 @@
{
"class_name": "物品-常用",
"id": "thing",
"keys": [
"item_Name.*"
]
"keys": ["item_Name.*"]
},
{
"class_name": "载具-其他",
@ -115,9 +113,7 @@
{
"class_name": "载具-常用",
"id": "vehicle",
"keys": [
"vehicle_Name.*"
]
"keys": ["vehicle_Name.*"]
},
{
"id": "mission",
@ -562,4 +558,4 @@
]
}
]
}
};

View File

@ -1,9 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:starcitizen_doctor/common/utils/log.dart';
@ -13,6 +11,7 @@ import 'package:starcitizen_doctor/data/sc_localization_data.dart';
import 'package:starcitizen_doctor/provider/unp4kc.dart';
import '../home_ui_model.dart';
import 'advanced_localization_ui.json.dart';
import 'localization_ui_model.dart';
part 'advanced_localization_ui_model.g.dart';
@ -151,8 +150,7 @@ class AdvancedLocalizationUIModel extends _$AdvancedLocalizationUIModel {
}
Future<AppAdvancedLocalizationData> _readClassJson() async {
final s = await rootBundle.loadString("assets/advanced_localization.json");
return AppAdvancedLocalizationData.fromJson(json.decode(s));
return AppAdvancedLocalizationData.fromJson(advancedLocalizationJsonData);
}
Future<(String, String)> _readIni(LocalizationUIState localizationUIState,

View File

@ -7,7 +7,7 @@ part of 'advanced_localization_ui_model.dart';
// **************************************************************************
String _$advancedLocalizationUIModelHash() =>
r'55c9d02d4c78112b2772f789c2758c3ea88808cb';
r'2db0a21dd98f5fb002469fcefe1bc1c0d514e135';
/// See also [AdvancedLocalizationUIModel].
@ProviderFor(AdvancedLocalizationUIModel)

View File

@ -1,4 +1,4 @@
[
final performanceUIConfJsonData = [
{
"key": "r_ssdo",
"name": "屏幕光线后处理",
@ -319,4 +319,4 @@
"value": 1,
"group": "自定义"
}
]
];

View File

@ -1,9 +1,7 @@
// ignore_for_file: avoid_build_context_in_providers, avoid_public_notifier_properties
import 'dart:convert';
import 'dart:io';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/services.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive/hive.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
@ -14,6 +12,8 @@ import 'package:starcitizen_doctor/data/game_performance_data.dart';
import 'package:starcitizen_doctor/generated/l10n.dart';
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
import 'performance_ui.json.dart';
part 'performance_ui_model.freezed.dart';
part 'performance_ui_model.g.dart';
@ -50,22 +50,16 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
Future<void> _init() async {
customizeCtrl.clear();
_inAppKeys.clear();
final String jsonString =
await rootBundle.loadString('assets/performance.json');
final list = json.decode(jsonString);
if (list is List) {
final performanceMap = <String, List<GamePerformanceData>>{};
for (var element in list) {
final item = GamePerformanceData.fromJson(element);
if (item.key != "customize") {
_inAppKeys.add(item.key ?? "");
}
performanceMap[item.group!] ??= [];
performanceMap[item.group]?.add(item);
final performanceMap = <String, List<GamePerformanceData>>{};
for (var element in performanceUIConfJsonData) {
final item = GamePerformanceData.fromJson(element);
if (item.key != "customize") {
_inAppKeys.add(item.key ?? "");
}
state = state.copyWith(performanceMap: performanceMap);
performanceMap[item.group!] ??= [];
performanceMap[item.group]?.add(item);
}
state = state.copyWith(performanceMap: performanceMap);
if (await confFile.exists()) {
await _readConf();
@ -155,11 +149,13 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
}
clean(BuildContext context) async {
state = state.copyWith(workingString: S.current.performance_info_delete_config_file);
state = state.copyWith(
workingString: S.current.performance_info_delete_config_file);
if (await confFile.exists()) {
await confFile.delete(recursive: true);
}
state = state.copyWith(workingString: S.current.performance_action_clear_shaders);
state = state.copyWith(
workingString: S.current.performance_action_clear_shaders);
if (!context.mounted) return;
await cleanShaderCache(context);
state = state.copyWith(workingString: S.current.performance_info_done);
@ -188,7 +184,8 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
applyProfile(bool cleanShader) async {
if (state.performanceMap == null) return;
AnalyticsApi.touch("performance_apply");
state = state.copyWith(workingString: S.current.performance_info_generate_config_file);
state = state.copyWith(
workingString: S.current.performance_info_generate_config_file);
String conf = "";
for (var v in state.performanceMap!.entries) {
for (var c in v.value) {
@ -207,14 +204,16 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
}
}
}
state = state.copyWith(workingString: S.current.performance_info_write_out_config_file);
state = state.copyWith(
workingString: S.current.performance_info_write_out_config_file);
if (await confFile.exists()) {
await confFile.delete();
}
await confFile.create();
await confFile.writeAsString(conf);
if (cleanShader) {
state = state.copyWith(workingString: S.current.performance_action_clear_shaders);
state = state.copyWith(
workingString: S.current.performance_action_clear_shaders);
await cleanShaderCache(null);
}
state = state.copyWith(workingString: S.current.performance_info_done);
@ -226,4 +225,4 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
updateState() {
state = state.copyWith();
}
}
}

View File

@ -7,7 +7,7 @@ part of 'performance_ui_model.dart';
// **************************************************************************
String _$homePerformanceUIModelHash() =>
r'6ac9c9adc428120cb5ce71949221064c9e5d9385';
r'83fbdbbae287892dd0c67f5fd86d42a73d0ab91f';
/// See also [HomePerformanceUIModel].
@ProviderFor(HomePerformanceUIModel)