From 6987aa622e1e28dfb09b637abdcd8f4e2cf27f61 Mon Sep 17 00:00:00 2001 From: Blaumeise03 Date: Sun, 4 Aug 2024 16:54:52 +0200 Subject: [PATCH] Fix data import --- lib/bloc/data_loading_bloc/data_loading_bloc.dart | 13 ++++++++----- lib/model/ship/ship_fitting_loadout.dart | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/bloc/data_loading_bloc/data_loading_bloc.dart b/lib/bloc/data_loading_bloc/data_loading_bloc.dart index fa46dd6..f1167d3 100644 --- a/lib/bloc/data_loading_bloc/data_loading_bloc.dart +++ b/lib/bloc/data_loading_bloc/data_loading_bloc.dart @@ -165,6 +165,7 @@ class DataLoadingBloc extends Bloc { Emitter emit, ) async { emit(LoadingRepositoryState('Importing data')); + print("Importing data from $path"); final json = await File(path).readAsString(); final data = jsonDecode(json); @@ -176,24 +177,26 @@ class DataLoadingBloc extends Bloc { ); final fittings = List.from( data['fittings'].map( - (x) => { + (x) { if (x['type'] == null || x['type'] == 'LOADOUT') { - ShipFittingLoadout.fromJson(x) + return ShipFittingLoadout.fromJson(x); } else if (x['type'] == "FOLDER") { - ShipFittingFolder.fromJson(x) + return ShipFittingFolder.fromJson(x); } else { - //Should never happen - null + //Should not happen unless we try to import data from a newer version + throw Exception('Invalid fitting type ${x['type']}'); } } ), ); + print("Converted json data"); await _characterRepository.loadCharacters( data: characters, defaultPilot: data[CharacterRepository.defaultPilotPrefsKey], ); await _fittingRepository.loadLoadouts(data: fittings); + print("Loaded data"); emit(RepositoryLoadedState()); } diff --git a/lib/model/ship/ship_fitting_loadout.dart b/lib/model/ship/ship_fitting_loadout.dart index 55ee6ff..42d95b5 100644 --- a/lib/model/ship/ship_fitting_loadout.dart +++ b/lib/model/ship/ship_fitting_loadout.dart @@ -90,6 +90,7 @@ class ShipFittingLoadout extends ChangeNotifier json['lightDestroyersSlots'] = json['lightDestroyersSlots'] ?? {}; json['hangarRigSlots'] = json['hangarRigSlots'] ?? {}; + json['type'] = json['type'] ?? 'LOADOUT'; return _$ShipFittingLoadoutFromJson(json); }