From b878f460a7d0f534373e70d3a0e453408694b763 Mon Sep 17 00:00:00 2001 From: SlayerOrnstein Date: Sun, 21 Mar 2021 14:35:32 -0400 Subject: [PATCH] fix: update steel path entities --- lib/src/entities/worldstate/steel_path.dart | 16 +++++++-- .../models/worldstate/steel_path_model.dart | 22 ++++++++++-- .../models/worldstate/steel_path_model.g.dart | 36 ++++++++++++++++--- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/lib/src/entities/worldstate/steel_path.dart b/lib/src/entities/worldstate/steel_path.dart index d4d1804..f793d15 100644 --- a/lib/src/entities/worldstate/steel_path.dart +++ b/lib/src/entities/worldstate/steel_path.dart @@ -1,3 +1,5 @@ +import 'package:equatable/equatable.dart'; + import '../../../objects.dart'; class SteelPath extends WorldstateObject { @@ -8,9 +10,19 @@ class SteelPath extends WorldstateObject { required this.rotation, }) : super(activation: activation, expiry: expiry); - final String currentReward; - final List rotation; + final SteelPathReward currentReward; + final List rotation; @override List get props => super.props..addAll([currentReward, rotation]); } + +class SteelPathReward extends Equatable { + const SteelPathReward({required this.name, required this.cost}); + + final String name; + final int cost; + + @override + List get props => [name, cost]; +} diff --git a/lib/src/models/worldstate/steel_path_model.dart b/lib/src/models/worldstate/steel_path_model.dart index ec30b55..8f85cd9 100644 --- a/lib/src/models/worldstate/steel_path_model.dart +++ b/lib/src/models/worldstate/steel_path_model.dart @@ -9,8 +9,8 @@ class SteelPathMdoel extends SteelPath { const SteelPathMdoel({ required DateTime activation, required DateTime expiry, - required String currentReward, - required List rotation, + required this.currentReward, + required this.rotation, }) : super( activation: activation, expiry: expiry, @@ -22,5 +22,23 @@ class SteelPathMdoel extends SteelPath { return _$SteelPathMdoelFromJson(json); } + @override + final SteelPathRewardModel currentReward; + + @override + final List rotation; + Map toJson() => _$SteelPathMdoelToJson(this); } + +@JsonSerializable() +class SteelPathRewardModel extends SteelPathReward { + SteelPathRewardModel({required String name, required int cost}) + : super(name: name, cost: cost); + + factory SteelPathRewardModel.fromJson(Map json) { + return _$SteelPathRewardModelFromJson(json); + } + + Map toJson() => _$SteelPathRewardModelToJson(this); +} diff --git a/lib/src/models/worldstate/steel_path_model.g.dart b/lib/src/models/worldstate/steel_path_model.g.dart index 03e91aa..6026789 100644 --- a/lib/src/models/worldstate/steel_path_model.g.dart +++ b/lib/src/models/worldstate/steel_path_model.g.dart @@ -13,9 +13,18 @@ SteelPathMdoel _$SteelPathMdoelFromJson(Map json) { json, 'activation', (v) => DateTime.parse(v as String)), expiry: $checkedConvert(json, 'expiry', (v) => DateTime.parse(v as String)), - currentReward: $checkedConvert(json, 'currentReward', (v) => v as String), - rotation: $checkedConvert(json, 'rotation', - (v) => (v as List).map((e) => e as String).toList()), + currentReward: $checkedConvert( + json, + 'currentReward', + (v) => SteelPathRewardModel.fromJson( + Map.from(v as Map))), + rotation: $checkedConvert( + json, + 'rotation', + (v) => (v as List) + .map((e) => SteelPathRewardModel.fromJson( + Map.from(e as Map))) + .toList()), ); return val; }); @@ -25,6 +34,23 @@ Map _$SteelPathMdoelToJson(SteelPathMdoel instance) => { 'activation': instance.activation?.toIso8601String(), 'expiry': instance.expiry?.toIso8601String(), - 'currentReward': instance.currentReward, - 'rotation': instance.rotation, + 'currentReward': instance.currentReward.toJson(), + 'rotation': instance.rotation.map((e) => e.toJson()).toList(), + }; + +SteelPathRewardModel _$SteelPathRewardModelFromJson(Map json) { + return $checkedNew('SteelPathRewardModel', json, () { + final val = SteelPathRewardModel( + name: $checkedConvert(json, 'name', (v) => v as String), + cost: $checkedConvert(json, 'cost', (v) => v as int), + ); + return val; + }); +} + +Map _$SteelPathRewardModelToJson( + SteelPathRewardModel instance) => + { + 'name': instance.name, + 'cost': instance.cost, };