From 0ded1f48e82501d696e859a9c8b392b2fed5251e Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Fri, 30 Jul 2021 23:56:19 +0300 Subject: [PATCH] apply nullsafety --- lib/alignment.dart | 11 +++-- lib/dice.dart | 18 +++++---- lib/equipment.dart | 19 +++++---- lib/gear_choice.dart | 27 ++++++------- lib/mappers.dart | 32 ++++++++------- lib/monster.dart | 29 +++++++------- lib/move.dart | 21 +++++----- lib/player_class.dart | 69 ++++++++++++++++---------------- lib/spell.dart | 19 +++++---- lib/src/_base.dart | 11 +++-- lib/src/_data.dart | 8 ---- lib/src/_dungeon_world_data.dart | 25 ++++++------ lib/tag.dart | 22 +++++----- pubspec.lock | 2 +- pubspec.yaml | 3 +- scripts/dump/dart_dump.dart | 4 +- scripts/dump/dart_parsers.dart | 12 +++--- test/dw_entity_test.dart | 5 +-- test/equipment_test.dart | 2 +- test/player_class_test.dart | 2 +- test/spell_test.dart | 4 +- 21 files changed, 166 insertions(+), 179 deletions(-) diff --git a/lib/alignment.dart b/lib/alignment.dart index 83c72f7..999f8e9 100644 --- a/lib/alignment.dart +++ b/lib/alignment.dart @@ -1,17 +1,16 @@ -import 'package:meta/meta.dart'; import 'dw_entity.dart'; class Alignment extends DWEntity { /// Alignment name - String/*!*/ name; + String name; /// Alignment description - String/*!*/ description; + String description; Alignment({ - String key, - @required this.name, - @required this.description, + String? key, + required this.name, + required this.description, }) : super(key: key ?? DWEntity.generateKey(name)); factory Alignment.fromJSON(Map map) => Alignment( diff --git a/lib/dice.dart b/lib/dice.dart index 37b31c5..de92b8f 100644 --- a/lib/dice.dart +++ b/lib/dice.dart @@ -9,10 +9,10 @@ class Dice { num sides; // Modifier value for dice, can be added to `DiceResult` value - num modifier; + num? modifier; // Last result rolled by this die - DiceResult lastResult; + DiceResult? lastResult; /// Simple dice, with sides, die count and modifier. /// You can multiply, add or subtract Dice objects to change the amount of rolls (notice dice must @@ -28,7 +28,7 @@ class Dice { static Dice d12 = Dice(12); static Dice d20 = Dice(20); - Dice copyWith({int sides, int amount, int modifier}) => Dice( + Dice copyWith({int? sides, int? amount, int? modifier}) => Dice( sides ?? this.sides, amount ?? this.amount, modifier ?? this.modifier, @@ -45,6 +45,7 @@ class Dice { @override String toString() => + // ignore: unnecessary_brace_in_string_interps '${amount}d${sides}${modifier != null && modifier != 0 ? modRepr : ''}'; Dice operator *(obj) { @@ -125,7 +126,7 @@ class Dice { DiceResult getRoll() { var results = []; for (num i = 0; i < amount; i++) { - results.add(Random().nextInt(sides) + 1); + results.add(Random().nextInt(sides as int) + 1); } return lastResult = DiceResult(this, results); } @@ -143,7 +144,7 @@ class Dice { return results; } - String get modRepr => (modifier > 0 ? '+' : '') + modifier.toString(); + String get modRepr => ((modifier ?? 0) > 0 ? '+' : '') + modifier.toString(); } class DiceResult { @@ -161,19 +162,20 @@ class DiceResult { // More detailed version of `toString`. String get toDetailedString => - '$dice${didHitNaturalMax ? '*' : ''} => $total\n $mappedResults\n ${didHitNaturalMax ? "Die no. ${indexOfNaturalMax} hit 20" : "Didn\'t hit 20"}'; + '$dice${didHitNaturalMax ? '*' : ''} => $total\n $mappedResults\n ${didHitNaturalMax ? "Die no. $indexOfNaturalMax hit 20" : "Didn\'t hit 20"}'; // All results layed out with their respective die. String get mappedResults { var out = []; for (num i = 0; i < results.length; i++) { - out.add('${i + 1}: ${results[i]}'); + out.add('${i + 1}: ${results[i as int]}'); } return out.toString() + (dice.modifier != 0 ? ' (${dice.modRepr})' : ''); } /// Total (accumulated) value of result, including modifiers. - num get total => results.reduce((tot, cur) => tot + cur) + dice.modifier; + num get total => + results.reduce((tot, cur) => tot + cur) + (dice.modifier ?? 0); // Boolean that represents whether any of the rolled dice hit their natural max value (e.g. 20 for d20) bool get didHitNaturalMax => results.any((r) => r == dice.sides); diff --git a/lib/equipment.dart b/lib/equipment.dart index 8d56554..411998f 100644 --- a/lib/equipment.dart +++ b/lib/equipment.dart @@ -1,27 +1,26 @@ -import 'package:meta/meta.dart'; import 'dw_entity.dart'; import 'tag.dart'; import 'mappers.dart'; class Equipment extends DWEntity { /// Equipment name - String/*!*/ name; + String name; /// Equipment name, in plural String pluralName; /// Item description - String/*!*/ description; + String? description; /// Equipment tags - List tags; + List tags; Equipment({ - String key, - @required this.name, - String pluralName, - @required this.description, - @required this.tags, + String? key, + required this.name, + String? pluralName, + this.description, + required this.tags, }) : pluralName = pluralName ?? _calcPluralName(name), super(key: key ?? DWEntity.generateKey(name)); @@ -33,7 +32,7 @@ class Equipment extends DWEntity { name: map['name'], pluralName: map['plural_name'], description: map['description'], - tags: listMapper(map['tags'], (i) => Tag.fromJSON(i)), + tags: listMapper(map['tags'], (dynamic i) => Tag.fromJSON(i)), ); @override diff --git a/lib/gear_choice.dart b/lib/gear_choice.dart index a4407ce..1ad199d 100644 --- a/lib/gear_choice.dart +++ b/lib/gear_choice.dart @@ -1,19 +1,18 @@ import 'package:dungeon_world_data/tag.dart'; -import 'package:meta/meta.dart'; import 'dw_entity.dart'; import 'mappers.dart'; class GearChoice extends DWEntity { /// Description of choices, possibly with other benefits to the stats. - String/*!*/ label; + String label; /// The list of options to choose from. `label` should specify how many to choose. - List gearOptions; + List gearOptions; GearChoice({ - String key, - @required this.label, - @required this.gearOptions, + String? key, + required this.label, + required this.gearOptions, }) : super(key: key); factory GearChoice.fromJSON(Map map) => GearChoice( @@ -36,19 +35,19 @@ class GearChoice extends DWEntity { class GearOption extends DWEntity { // String key; - String/*!*/ name; - List/*!*/ tags; + String name; + List tags; GearOption({ - String key, - @required this.name, - @required this.tags, + String? key, + required this.name, + required this.tags, }) : super(key: key ?? DWEntity.generateKey(name)); factory GearOption.fromJSON(Map map) => GearOption( key: map['key'], name: map['name'], - tags: listMapper(map['tags'], (t) => Tag.fromJSON(t)), + tags: listMapper(map['tags'], (dynamic t) => Tag.fromJSON(t)), ); factory GearOption.parse(dynamic str) { @@ -56,9 +55,9 @@ class GearOption extends DWEntity { return GearOption.fromJSON(str); } final num openParen = str.indexOf('('); - final num closeParen = str.indexOf(')'); + final num? closeParen = str.indexOf(')'); final name = str.substring(0, openParen > -1 ? openParen : null); - final rawTags = openParen > -1 && closeParen > -1 + final rawTags = openParen > -1 && closeParen! > -1 ? str.substring(openParen + 1, closeParen) : ''; final tags = rawTags.isNotEmpty diff --git a/lib/mappers.dart b/lib/mappers.dart index 7089dde..046cab5 100644 --- a/lib/mappers.dart +++ b/lib/mappers.dart @@ -7,16 +7,18 @@ import 'monster.dart'; import 'player_class.dart'; import 'tag.dart'; -List listMapper(List lst, R Function(A obj) mapper) => +List listMapper(List? lst, R Function(A obj) mapper) => lst != null && lst.isNotEmpty - ? List.from(lst).map((obj) => obj is A ? mapper(obj) : null).toList() + ? (List.from(lst.where((obj) => obj != null && obj is A)) + .map((obj) => mapper(obj)) + .toList()) : []; -Map mapMapper( - Map map, MapEntry Function(dynamic key, dynamic obj) mapper) => +Map mapMapper( + Map? map, MapEntry Function(dynamic key, dynamic obj) mapper) => map != null ? Map.from(map).map(mapper) : {}; -List moveListMapper(List lst) => lst == null || lst.isEmpty +List moveListMapper(List? lst) => lst == null || lst.isEmpty ? [] : listMapper( List.from(lst), (v) => Move.fromJSON(v)); @@ -29,33 +31,33 @@ Map classMapper(Map map) => mapMapper( (k, v) => MapEntry(k.toString(), PlayerClass.fromJSON(v))); -Map/*!*/> nameMapper(Map map) => +Map> nameMapper(Map? map) => mapMapper>( map, (k, v) => MapEntry>(k.toString(), listMapper(v, (j) => j.toString()))); -List> looksMapper(List lst) => - listMapper(lst, (i) => listMapper(i, (j) => j.toString())); +List> looksMapper(List? lst) => + listMapper(lst, (dynamic i) => listMapper(i, (dynamic j) => j.toString())); -Map alignmentsMapper(Map map) => mapMapper(map, +Map alignmentsMapper(Map? map) => mapMapper(map, (k, v) => MapEntry(k.toString(), Alignment.fromJSON(v))); -List gearChoiceMapper(List lst) => - listMapper(lst, (v) => GearChoice.fromJSON(v)); +List gearChoiceMapper(List? lst) => + listMapper(lst, (dynamic v) => GearChoice.fromJSON(v)); -List gearOptionMapper(List lst) => - listMapper(lst, (v) => GearOption.parse(v)); +List gearOptionMapper(List? lst) => + listMapper(lst, (dynamic v) => GearOption.parse(v)); Map equipmentMapper(Map map) => mapMapper(map, (k, v) => MapEntry(k.toString(), Equipment.fromJSON(v))); -List spellsMapper(List lst) { +List spellsMapper(List? lst) { if (lst == null) { return []; } - return listMapper(lst, (v) => Spell.fromJSON(v)); + return listMapper(lst, (dynamic v) => Spell.fromJSON(v)); } Map monsterMapper(Map map) => mapMapper(map, diff --git a/lib/monster.dart b/lib/monster.dart index dc554bf..a3a524f 100644 --- a/lib/monster.dart +++ b/lib/monster.dart @@ -1,44 +1,43 @@ -import 'package:meta/meta.dart'; import 'dw_entity.dart'; import 'tag.dart'; import 'mappers.dart'; class Monster extends DWEntity { /// Monster name - String /*!*/ name; + String name; /// Monster description - String /*!*/ description; + String description; /// Monster instinct - String /*!*/ instinct; + String instinct; /// Monster tags - List tags; + List tags; /// Monster moves - List moves; + List moves; Monster({ - String key, - @required this.name, - @required this.description, - @required this.instinct, - @required this.tags, - @required this.moves, + String? key, + required this.name, + required this.description, + required this.instinct, + required this.tags, + required this.moves, }) : super(key: key ?? DWEntity.generateKey(name)); @override String toString() => - '$name\n tags: $tags,\n moves: ${moves}\n instinct: $instinct'; + '$name\n tags: $tags,\n moves: $moves\n instinct: $instinct'; static Monster fromJSON(Map map) => Monster( key: map['key'], name: map['name'], description: map['description'], instinct: map['instinct'], - tags: listMapper(map['tags'], (i) => Tag.fromJSON(i)), - moves: listMapper(map['moves'], (i) => i.toString())); + tags: listMapper(map['tags'], (dynamic i) => Tag.fromJSON(i)), + moves: listMapper(map['moves'], (dynamic i) => i.toString())); @override Map toJSON() { diff --git a/lib/move.dart b/lib/move.dart index 7fc94ac..1f18b41 100644 --- a/lib/move.dart +++ b/lib/move.dart @@ -1,34 +1,33 @@ -import 'package:meta/meta.dart'; import 'dw_entity.dart'; import 'mappers.dart'; class Move extends DWEntity { /// Move name - String/*!*/ name; + String name; /// Move description - String/*!*/ description; + String description; /// Move explanation - String/*!*/ explanation; + String? explanation; /// Classes that can use this move. /// The keys correspond to the `PlayerClass` key. - List classes; + List classes; Move({ - String key, - @required this.name, - @required this.description, - @required this.explanation, - @required this.classes, + String? key, + required this.name, + required this.description, + this.explanation, + required this.classes, }) : super(key: key ?? DWEntity.generateKey(name)); factory Move.fromJSON(Map map) => Move( key: map['key'], name: map['name'], classes: map['classes'] != null - ? listMapper(map['classes'], (j) => j.toString()) + ? listMapper(map['classes'], (dynamic j) => j.toString()) : [], description: map['description'], explanation: map['explanation'], diff --git a/lib/player_class.dart b/lib/player_class.dart index c5e0aef..cdae1f4 100644 --- a/lib/player_class.dart +++ b/lib/player_class.dart @@ -1,4 +1,3 @@ -import 'package:meta/meta.dart'; import 'alignment.dart'; import 'dice.dart'; import 'dw_entity.dart'; @@ -9,67 +8,67 @@ import 'gear_choice.dart'; class PlayerClass extends DWEntity { /// Class name - String /*!*/ name; + String name; /// Class description - String /*!*/ description; + String description; /// Base max. weight load, without the +STR. - num /*!*/ load; + num load; /// Base HP - num /*!*/ baseHP; + num baseHP; /// Hit die - Dice /*!*/ damage; + Dice damage; /// Character name options, mapped by race - Map /*!*/ > names; + Map> names; /// Class Bonds - List bonds; + List bonds; /// Character look options - List /*!*/ > looks; + List> looks; /// Character alignment options. Map of `Alignment.key` => `Alignment` Map alignments; /// Race moves - List raceMoves; + List raceMoves; /// Starting moves - List startingMoves; + List startingMoves; /// Starting moves - List advancedMoves1; + List advancedMoves1; /// Starting moves - List advancedMoves2; + List advancedMoves2; /// Spells - List spells; + List spells; /// Gear choices - List gearChoices; + List gearChoices; PlayerClass({ - String key, - @required this.name, - @required this.description, - @required this.load, - @required this.baseHP, - @required this.damage, - @required this.names, - @required this.bonds, - @required this.looks, - @required this.alignments, - @required this.raceMoves, - @required this.startingMoves, - @required this.advancedMoves1, - @required this.advancedMoves2, - @required this.spells, - @required this.gearChoices, + String? key, + required this.name, + required this.description, + required this.load, + required this.baseHP, + required this.damage, + required this.names, + required this.bonds, + required this.looks, + required this.alignments, + required this.raceMoves, + required this.startingMoves, + required this.advancedMoves1, + required this.advancedMoves2, + required this.spells, + required this.gearChoices, }) : super(key: key ?? DWEntity.generateKey(name)); /// Combined list of `advancedMoves1` and `advancedMoves2` @@ -92,7 +91,7 @@ class PlayerClass extends DWEntity { baseHP: map['base_hp'], damage: Dice.parse(map['damage']), names: nameMapper(map['names']), - bonds: listMapper(map['bonds'], (j) => j.toString()), + bonds: listMapper(map['bonds'], (dynamic j) => j.toString()), looks: looksMapper(map['looks']), alignments: alignmentsMapper(map['alignments']), raceMoves: moveListMapper(map['race_moves']), @@ -114,8 +113,8 @@ class PlayerClass extends DWEntity { 'names': names, 'bonds': bonds, 'looks': looks, - 'alignments': mapMapper( - alignments, (k, v) => MapEntry(k, v.toJSON())), + 'alignments': + mapMapper(alignments, ((k, v) => MapEntry(k, v.toJSON()))), 'race_moves': listMapper(raceMoves, (move) => move.toJSON()), 'starting_moves': @@ -124,7 +123,7 @@ class PlayerClass extends DWEntity { advancedMoves1, (move) => move.toJSON()), 'advanced_moves_2': listMapper( advancedMoves2, (move) => move.toJSON()), - 'spells': listMapper(spells, (v) => v.toJSON()), + 'spells': listMapper(spells, (dynamic v) => v.toJSON()), 'gear_choices': listMapper( gearChoices, (choice) => choice.toJSON()), }; diff --git a/lib/spell.dart b/lib/spell.dart index 23ad5b8..c3b4d86 100644 --- a/lib/spell.dart +++ b/lib/spell.dart @@ -1,27 +1,26 @@ -import 'package:meta/meta.dart'; import 'dw_entity.dart'; import 'mappers.dart'; import 'tag.dart'; class Spell extends DWEntity { /// Spell name - String/*!*/ name; + String name; /// Spell description - String/*!*/ description; + String description; /// Spell level String level; /// Spell tags - List tags; + List tags; Spell({ - String key, - @required this.name, - @required this.description, - @required this.level, - @required this.tags, + String? key, + required this.name, + required this.description, + required this.level, + required this.tags, }) : super(key: key ?? DWEntity.generateKey(name)); static Spell fromJSON(Map map) => Spell( @@ -29,7 +28,7 @@ class Spell extends DWEntity { name: map['name'], description: map['description'], level: map['level'].toString(), - tags: listMapper(map['tags'], (i) => Tag.fromJSON(i)), + tags: listMapper(map['tags'], (dynamic i) => Tag.fromJSON(i)), ); @override diff --git a/lib/src/_base.dart b/lib/src/_base.dart index c0a0e6c..cae7904 100644 --- a/lib/src/_base.dart +++ b/lib/src/_base.dart @@ -1,9 +1,9 @@ part of '_dungeon_world_data.dart'; abstract class DWEntity { - String key; + String? key; - DWEntity({String key}) { + DWEntity({String? key}) { this.key = key ?? DWEntity.generateKey(null); } @@ -13,7 +13,7 @@ abstract class DWEntity { /// and turned to lowercase. /// /// Otherwise, a `Uuid().v4()` is generated for it. - static String generateKey(String identifier) => + static String generateKey(String? identifier) => identifier != null && identifier.trim().isNotEmpty ? identifier .trim() @@ -36,10 +36,9 @@ abstract class DWEntity { DWEntity copy(); /// Helper method for getting any `DWEntity` by its key. - static T getByKey(String key, Iterable list) => - list.firstWhere( + static T? getByKey(String key, Iterable list) => + list.firstWhereOrNull( (element) => element.key == key, - orElse: () => null, ); } diff --git a/lib/src/_data.dart b/lib/src/_data.dart index 4d31c28..7258c1b 100755 --- a/lib/src/_data.dart +++ b/lib/src/_data.dart @@ -5969,14 +5969,6 @@ void initData() { 'Bring their word into abundance' ], )); - monsterList.add(Monster( - key: '4155de98-1286-46c8-a872-8a2545093d81', - name: null, - description: null, - instinct: null, - tags: [], - moves: [], - )); basicMovesList.add(Move( key: 'hack_slash', name: 'Hack & Slash', diff --git a/lib/src/_dungeon_world_data.dart b/lib/src/_dungeon_world_data.dart index 1197646..da949f3 100644 --- a/lib/src/_dungeon_world_data.dart +++ b/lib/src/_dungeon_world_data.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart' show IterableExtension; import 'package:quiver/core.dart'; import 'package:uuid/uuid.dart'; import '../tag.dart'; @@ -20,40 +21,38 @@ part '_homebrew.dart'; const String VERSION = '2.0.0'; class DungeonWorldData { - /*late*/ Map _raw; + late Map _raw; /// Raw data - Map get raw { - _raw ??= toJSON(); - return _raw; - } + Map get raw => _raw; /// Basic moves - /*late*/ List basicMoves; + late List basicMoves; /// Special moves - /*late*/ List specialMoves; + late List specialMoves; /// Classes - /*late*/ List classes; + late List classes; /// Equipment - /*late*/ List equipment; + late List equipment; /// Spells - /*late*/ List spells; + late List spells; /// Monsters - /*late*/ List monsters; + late List monsters; /// Tags - /*late*/ List tags; + late List tags; /// Current version of data, corresponds to same version of https://www.npmjs.com/package/dungeonworld-data final String version = VERSION; DungeonWorldData() { _initFromData(); + _raw = toJSON(); } void _initFromData() { @@ -92,5 +91,5 @@ class DungeonWorldData { list.map((v) => MapEntry(key(v), v)), ); - static String entryKey(DWEntity item) => item.key /*!*/; + static String entryKey(DWEntity item) => item.key!; } diff --git a/lib/tag.dart b/lib/tag.dart index 2c3fb22..20dc5e3 100644 --- a/lib/tag.dart +++ b/lib/tag.dart @@ -1,23 +1,23 @@ import 'dw_entity.dart'; class Tag extends DWEntity { - static Map tagInfoCache = {}; + static Map tagInfoCache = {}; /// Tag or feature name - String /*!*/ name; + String name; /// Value, if applicable - T value; + T? value; - String description; + String? description; Tag(this.name, [this.value, this.description]) : super(key: name) { if (description != null && - description.isNotEmpty && + description!.isNotEmpty && !tagInfoCache.containsKey(key)) { - tagInfoCache[key] = description; + tagInfoCache[key] = description!; } else if (description == null || - description.isEmpty && tagInfoCache.containsKey(key)) { + description!.isEmpty && tagInfoCache.containsKey(key)) { description = tagInfoCache[key]; } } @@ -39,16 +39,16 @@ class Tag extends DWEntity { var amountThenName = RegExp('([0-9]+)\\s(.*)'); if (amountThenName.hasMatch(obj)) { var match = amountThenName.allMatches(obj).toList().first; - var name = match.group(2); - var value = int.tryParse(match.group(1)); + var name = match.group(2)!; + var value = int.tryParse(match.group(1)!); return Tag(name, value as dynamic); } var mapLike = RegExp('\\{(.*):\\s?([+-]?[0-9]+)\\}'); if (mapLike.hasMatch(obj)) { var match = mapLike.allMatches(obj).toList().first; - var name = match.group(1); - var value = int.tryParse(match.group(2)); + var name = match.group(1)!; + var value = int.tryParse(match.group(2)!); return Tag(name, value as dynamic); } } diff --git a/pubspec.lock b/pubspec.lock index 3b840d2..0a6d1c1 100755 --- a/pubspec.lock +++ b/pubspec.lock @@ -51,7 +51,7 @@ packages: source: hosted version: "0.3.3" collection: - dependency: transitive + dependency: "direct main" description: name: collection url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 2a316d2..6235976 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,12 +5,13 @@ description: Data dump of Dungeon World classes, moves, equipment, and more. version: 2.0.5+10 environment: - sdk: ">=2.11.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: meta: ^1.1.0 quiver: ^3.0.1 uuid: ^3.0.4 + collection: ^1.15.0-nullsafety.4 dev_dependencies: flutter_lints: ^1.0.4 diff --git a/scripts/dump/dart_dump.dart b/scripts/dump/dart_dump.dart index 44463ff..a2d8a54 100644 --- a/scripts/dump/dart_dump.dart +++ b/scripts/dump/dart_dump.dart @@ -33,9 +33,9 @@ void main() async { .join('\n'); print('Writing string'); var str = ''' - ${arraysImports} + $arraysImports void initData() { - ${arrayFills} + $arrayFills } '''; var file = File(join(Directory.current.path, 'output.dart')); diff --git a/scripts/dump/dart_parsers.dart b/scripts/dump/dart_parsers.dart index 81976c4..d1ba91a 100644 --- a/scripts/dump/dart_parsers.dart +++ b/scripts/dump/dart_parsers.dart @@ -4,7 +4,7 @@ String dumpClass( String className, T obj, String Function(T) parser, {bool includeKey = true}) { return """ - ${className}(${includeKey && obj.key != null ? "key: ${parseValue(obj.key)}, " : ""}${parser(obj).trim()}) + $className(${includeKey && obj.key != null ? "key: ${parseValue(obj.key)}, " : ""}${parser(obj).trim()}) """; } @@ -29,7 +29,7 @@ String parseTag(Tag tag) { } String parseTagsArray(List list) { - return parseArray('Tag', list.where((t) => t != null), parseTag); + return parseArray('Tag', list, parseTag); } String parseDice(Dice dice) { @@ -65,7 +65,7 @@ String Function(Tag) parseInfoTags = createClassParser( includeKey: false, ); -String Function(Alignment/*!*/) parseAlignment = createClassParser( +String Function(Alignment) parseAlignment = createClassParser( 'Alignment', (i) => ''' name: ${parseValue(i.name)}, @@ -91,7 +91,7 @@ String Function(PlayerClass) parsePlayerClass = createClassParser( damage: ${parseDice(i.damage)}, names: ${i.names.map((r, s) => MapEntry(parseValue(r), parseArray('String', s, parseValue)))}, bonds: ${parseArray('String', i.bonds, parseValue)}, - looks: ${parseArray('List', i.looks, (s) => parseArray('String', s, parseValue))}, + looks: ${parseArray('List', i.looks, (dynamic s) => parseArray('String', s, parseValue))}, alignments: ${i.alignments.map((k, v) => MapEntry(parseValue(v.name), parseAlignment(v)))}, raceMoves: ${parseArray('Move', i.raceMoves, parseMove)}, startingMoves: ${parseArray('Move', i.startingMoves, parseMove)}, @@ -152,7 +152,7 @@ class ParseDef { String get file => _file; String get arrayName => _arrayName; - ParseDef(this.name, this.list, this.parser, {String file, String arrayName}) + ParseDef(this.name, this.list, this.parser, {String? file, String? arrayName}) : _file = file ?? _fileFromName(name), _arrayName = arrayName ?? _arrayNameFromName(name); @@ -166,7 +166,7 @@ class ParseDef { static String _fileFromName(String name) => name .splitMapJoin(RegExp('([A-Z])'), - onMatch: (match) => '_' + match.group(1).toLowerCase(), + onMatch: (match) => '_' + match.group(1)!.toLowerCase(), onNonMatch: (i) => i) .substring(1) + '.dart'; diff --git a/test/dw_entity_test.dart b/test/dw_entity_test.dart index 6877333..70bd460 100644 --- a/test/dw_entity_test.dart +++ b/test/dw_entity_test.dart @@ -1,12 +1,11 @@ -import 'package:meta/meta.dart'; import 'package:test/test.dart'; import 'package:dungeon_world_data/dw_data.dart'; class Test1 extends DWEntity { final int value; Test1({ - String key, - @required this.value, + String? key, + required this.value, }) : super(key: key); @override diff --git a/test/equipment_test.dart b/test/equipment_test.dart index c239b78..3af3804 100644 --- a/test/equipment_test.dart +++ b/test/equipment_test.dart @@ -4,7 +4,7 @@ import 'package:dungeon_world_data/dw_data.dart'; void main() { group('Equipment', () { test('Key', () { - var equipment = DWEntity.getByKey('tricksy_rope', dungeonWorld.equipment); + var equipment = DWEntity.getByKey('tricksy_rope', dungeonWorld.equipment)!; expect(equipment.key, equals('tricksy_rope')); }); }); diff --git a/test/player_class_test.dart b/test/player_class_test.dart index 245eca7..ecb6e4f 100644 --- a/test/player_class_test.dart +++ b/test/player_class_test.dart @@ -4,7 +4,7 @@ import 'package:dungeon_world_data/dw_data.dart'; void main() { group('PlayerClass', () { test('Key', () { - var paladin = DWEntity.getByKey('paladin', dungeonWorld.classes); + var paladin = DWEntity.getByKey('paladin', dungeonWorld.classes)!; expect(paladin.key, equals('paladin')); }); }); diff --git a/test/spell_test.dart b/test/spell_test.dart index a37314a..7b087e0 100644 --- a/test/spell_test.dart +++ b/test/spell_test.dart @@ -4,12 +4,12 @@ import 'package:dungeon_world_data/dw_data.dart'; void main() { group('Spells', () { test('Key', () { - var equipment = DWEntity.getByKey('plague', dungeonWorld.spells); + var equipment = DWEntity.getByKey('plague', dungeonWorld.spells)!; expect(equipment.key, equals('plague')); }); test('toJSON', () { - var equipment = DWEntity.getByKey('plague', dungeonWorld.spells); + var equipment = DWEntity.getByKey('plague', dungeonWorld.spells)!; expect(equipment.toJSON()['tags'], contains('ongoing')); var json = equipment.toJSON(); expect(json['key'], equals('plague'));