Skip to content

Commit 5063c1c

Browse files
committed
Improve models files to move into correct files
1 parent 0b545d6 commit 5063c1c

File tree

14 files changed

+990
-955
lines changed

14 files changed

+990
-955
lines changed

api/lib/helpers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export 'src/helpers/crypto.dart';
2+
export 'src/helpers/equality.dart';

api/lib/models.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
export 'src/helpers/equality.dart';
2+
13
export 'src/models/background.dart';
4+
export 'src/models/cell.dart';
25
export 'src/models/chat.dart';
36
export 'src/models/config.dart';
47
export 'src/models/data.dart';

api/lib/src/event/state.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:typed_data';
33
import 'package:dart_mappable/dart_mappable.dart';
44
import 'package:networker/networker.dart';
55

6+
import '../models/cell.dart';
67
import '../models/chat.dart';
78
import '../models/data.dart';
89
import '../models/dialog.dart';

api/lib/src/helpers/equality.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:dart_mappable/dart_mappable.dart';
2+
3+
part 'equality.mapper.dart';
4+
5+
@MappableClass(
6+
includeCustomMappers: [IgnoreForEquality()],
7+
generateMethods:
8+
GenerateMethods.all &
9+
~GenerateMethods.equals &
10+
~GenerateMethods.stringify,
11+
)
12+
class IgnoreEqualityBox<T> with IgnoreEqualityBoxMappable<T> {
13+
final T content;
14+
15+
const IgnoreEqualityBox(this.content);
16+
}
17+
18+
class IgnoreForEquality extends SimpleMapper1<IgnoreEqualityBox> {
19+
const IgnoreForEquality();
20+
@override
21+
// use the type parameter [T] in the return type [GenericBox<T>]
22+
IgnoreEqualityBox<T> decode<T>(dynamic value) {
23+
// use the type parameter [T] in your decoding logic
24+
T content = MapperContainer.globals.fromValue<T>(value);
25+
return IgnoreEqualityBox<T>(content);
26+
}
27+
28+
@override
29+
// use the type parameter [T] in the parameter type [GenericBox<T>]
30+
dynamic encode<T>(IgnoreEqualityBox<T> self) {
31+
// use the type parameter [T] in your encoding logic
32+
return MapperContainer.globals.toValue<T>(self.content);
33+
}
34+
35+
// In case of generic types, we also must specify a type factory. This is a special type of
36+
// function used internally to construct generic instances of your type.
37+
// Specify any type arguments in alignment to the decode/encode functions.
38+
@override
39+
Function get typeFactory =>
40+
<T>(f) => f<IgnoreEqualityBox<T>>();
41+
42+
@override
43+
bool equals(value, other, MappingContext context) => value == other;
44+
45+
@override
46+
int hash(value, MappingContext context) => value.hashCode;
47+
48+
@override
49+
String stringify(value, MappingContext context) => value.toString();
50+
}

api/lib/src/helpers/equality.mapper.dart

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/lib/src/models/cell.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'package:dart_mappable/dart_mappable.dart';
2+
3+
import 'vector.dart';
4+
5+
part 'cell.mapper.dart';
6+
7+
@MappableClass()
8+
class TableCell with TableCellMappable {
9+
final List<GameObject> objects;
10+
final List<BoardTile> tiles;
11+
12+
TableCell({this.objects = const [], this.tiles = const []});
13+
14+
bool get isEmpty => objects.isEmpty && tiles.isEmpty;
15+
}
16+
17+
@MappableClass()
18+
class GameObject with GameObjectMappable {
19+
final ItemLocation asset;
20+
final String? variation;
21+
final bool hidden;
22+
23+
GameObject(this.asset, {this.variation, this.hidden = false});
24+
}
25+
26+
@MappableClass()
27+
class BoardTile with BoardTileMappable {
28+
final ItemLocation asset;
29+
final VectorDefinition tile;
30+
31+
BoardTile(this.asset, this.tile);
32+
}

0 commit comments

Comments
 (0)