Skip to content

Commit

Permalink
Fix data import
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaumeise03 committed Aug 4, 2024
1 parent 7bd8485 commit 6987aa6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/bloc/data_loading_bloc/data_loading_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class DataLoadingBloc extends Bloc<DataLoadingBlocEvent, DataLoadingBlocState> {
Emitter<DataLoadingBlocState> emit,
) async {
emit(LoadingRepositoryState('Importing data'));
print("Importing data from $path");

final json = await File(path).readAsString();
final data = jsonDecode(json);
Expand All @@ -176,24 +177,26 @@ class DataLoadingBloc extends Bloc<DataLoadingBlocEvent, DataLoadingBlocState> {
);
final fittings = List<FittingListElement>.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());
}
Expand Down
1 change: 1 addition & 0 deletions lib/model/ship/ship_fitting_loadout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ShipFittingLoadout extends ChangeNotifier
json['lightDestroyersSlots'] =
json['lightDestroyersSlots'] ?? <String, dynamic>{};
json['hangarRigSlots'] = json['hangarRigSlots'] ?? <String, dynamic>{};
json['type'] = json['type'] ?? 'LOADOUT';
return _$ShipFittingLoadoutFromJson(json);
}

Expand Down

0 comments on commit 6987aa6

Please sign in to comment.