diff --git a/assets/piece_sets/mono/2.0x/B.png b/assets/piece_sets/mono/2.0x/B.png new file mode 100644 index 0000000..5744cf0 Binary files /dev/null and b/assets/piece_sets/mono/2.0x/B.png differ diff --git a/assets/piece_sets/mono/2.0x/K.png b/assets/piece_sets/mono/2.0x/K.png new file mode 100644 index 0000000..eb65553 Binary files /dev/null and b/assets/piece_sets/mono/2.0x/K.png differ diff --git a/assets/piece_sets/mono/2.0x/N.png b/assets/piece_sets/mono/2.0x/N.png new file mode 100644 index 0000000..e6225eb Binary files /dev/null and b/assets/piece_sets/mono/2.0x/N.png differ diff --git a/assets/piece_sets/mono/2.0x/P.png b/assets/piece_sets/mono/2.0x/P.png new file mode 100644 index 0000000..dcc05dc Binary files /dev/null and b/assets/piece_sets/mono/2.0x/P.png differ diff --git a/assets/piece_sets/mono/2.0x/Q.png b/assets/piece_sets/mono/2.0x/Q.png new file mode 100644 index 0000000..6820893 Binary files /dev/null and b/assets/piece_sets/mono/2.0x/Q.png differ diff --git a/assets/piece_sets/mono/2.0x/R.png b/assets/piece_sets/mono/2.0x/R.png new file mode 100644 index 0000000..78b4d0e Binary files /dev/null and b/assets/piece_sets/mono/2.0x/R.png differ diff --git a/assets/piece_sets/mono/3.0x/B.png b/assets/piece_sets/mono/3.0x/B.png new file mode 100644 index 0000000..ff1fb46 Binary files /dev/null and b/assets/piece_sets/mono/3.0x/B.png differ diff --git a/assets/piece_sets/mono/3.0x/K.png b/assets/piece_sets/mono/3.0x/K.png new file mode 100644 index 0000000..b1dff84 Binary files /dev/null and b/assets/piece_sets/mono/3.0x/K.png differ diff --git a/assets/piece_sets/mono/3.0x/N.png b/assets/piece_sets/mono/3.0x/N.png new file mode 100644 index 0000000..7bebee2 Binary files /dev/null and b/assets/piece_sets/mono/3.0x/N.png differ diff --git a/assets/piece_sets/mono/3.0x/P.png b/assets/piece_sets/mono/3.0x/P.png new file mode 100644 index 0000000..e2ea4f6 Binary files /dev/null and b/assets/piece_sets/mono/3.0x/P.png differ diff --git a/assets/piece_sets/mono/3.0x/Q.png b/assets/piece_sets/mono/3.0x/Q.png new file mode 100644 index 0000000..86ce819 Binary files /dev/null and b/assets/piece_sets/mono/3.0x/Q.png differ diff --git a/assets/piece_sets/mono/3.0x/R.png b/assets/piece_sets/mono/3.0x/R.png new file mode 100644 index 0000000..8d1cc5d Binary files /dev/null and b/assets/piece_sets/mono/3.0x/R.png differ diff --git a/assets/piece_sets/mono/4.0x/B.png b/assets/piece_sets/mono/4.0x/B.png new file mode 100644 index 0000000..2ece40b Binary files /dev/null and b/assets/piece_sets/mono/4.0x/B.png differ diff --git a/assets/piece_sets/mono/4.0x/K.png b/assets/piece_sets/mono/4.0x/K.png new file mode 100644 index 0000000..ae20439 Binary files /dev/null and b/assets/piece_sets/mono/4.0x/K.png differ diff --git a/assets/piece_sets/mono/4.0x/N.png b/assets/piece_sets/mono/4.0x/N.png new file mode 100644 index 0000000..193aebb Binary files /dev/null and b/assets/piece_sets/mono/4.0x/N.png differ diff --git a/assets/piece_sets/mono/4.0x/P.png b/assets/piece_sets/mono/4.0x/P.png new file mode 100644 index 0000000..e721681 Binary files /dev/null and b/assets/piece_sets/mono/4.0x/P.png differ diff --git a/assets/piece_sets/mono/4.0x/Q.png b/assets/piece_sets/mono/4.0x/Q.png new file mode 100644 index 0000000..1c04471 Binary files /dev/null and b/assets/piece_sets/mono/4.0x/Q.png differ diff --git a/assets/piece_sets/mono/4.0x/R.png b/assets/piece_sets/mono/4.0x/R.png new file mode 100644 index 0000000..2b9085a Binary files /dev/null and b/assets/piece_sets/mono/4.0x/R.png differ diff --git a/assets/piece_sets/mono/B.png b/assets/piece_sets/mono/B.png new file mode 100644 index 0000000..cbf3069 Binary files /dev/null and b/assets/piece_sets/mono/B.png differ diff --git a/assets/piece_sets/mono/K.png b/assets/piece_sets/mono/K.png new file mode 100644 index 0000000..7168097 Binary files /dev/null and b/assets/piece_sets/mono/K.png differ diff --git a/assets/piece_sets/mono/N.png b/assets/piece_sets/mono/N.png new file mode 100644 index 0000000..bc8627b Binary files /dev/null and b/assets/piece_sets/mono/N.png differ diff --git a/assets/piece_sets/mono/P.png b/assets/piece_sets/mono/P.png new file mode 100644 index 0000000..93ba174 Binary files /dev/null and b/assets/piece_sets/mono/P.png differ diff --git a/assets/piece_sets/mono/Q.png b/assets/piece_sets/mono/Q.png new file mode 100644 index 0000000..8d6820c Binary files /dev/null and b/assets/piece_sets/mono/Q.png differ diff --git a/assets/piece_sets/mono/R.png b/assets/piece_sets/mono/R.png new file mode 100644 index 0000000..94af1ea Binary files /dev/null and b/assets/piece_sets/mono/R.png differ diff --git a/lib/src/models.dart b/lib/src/models.dart index fb86e3e..b738e32 100644 --- a/lib/src/models.dart +++ b/lib/src/models.dart @@ -13,7 +13,23 @@ enum Side { enum InteractableSide { both, none, white, black } /// Piece role, such as pawn, knight, etc. -enum Role { king, queen, knight, bishop, rook, pawn } +enum Role { + king, + queen, + knight, + bishop, + rook, + pawn; + + String get letter => switch (this) { + Role.king => 'K', + Role.queen => 'Q', + Role.knight => 'N', + Role.bishop => 'B', + Role.rook => 'R', + Role.pawn => 'P', + }; +} /// Piece kind, such as white pawn, black knight, etc. enum PieceKind { @@ -413,3 +429,34 @@ class Arrow implements Shape { @override int get hashCode => Object.hash(color, orig, dest); } + +@immutable +class PieceShape implements Shape { + final Color color; + final Role role; + final SquareId orig; + + const PieceShape({ + required this.color, + required this.role, + required this.orig, + }); + + @override + Shape newDest(SquareId newDest) { + return this; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is PieceShape && + other.runtimeType == runtimeType && + other.color == color && + other.role == role && + other.orig == orig; + } + + @override + int get hashCode => Object.hash(color, role, orig); +} diff --git a/lib/src/widgets/board.dart b/lib/src/widgets/board.dart index 16aac14..bc5cdca 100644 --- a/lib/src/widgets/board.dart +++ b/lib/src/widgets/board.dart @@ -244,13 +244,13 @@ class _BoardState extends State { for (final shape in shapes) ShapeWidget( shape: shape, - size: widget.size, + boardSize: widget.size, orientation: widget.data.orientation, ), if (_shapeAvatar != null) ShapeWidget( shape: _shapeAvatar!, - size: widget.size, + boardSize: widget.size, orientation: widget.data.orientation, ), ], diff --git a/lib/src/widgets/shape.dart b/lib/src/widgets/shape.dart index 0b11727..944a1b0 100644 --- a/lib/src/widgets/shape.dart +++ b/lib/src/widgets/shape.dart @@ -2,41 +2,62 @@ import 'dart:math' as math; import 'package:flutter/widgets.dart'; import '../models.dart'; +import 'positioned_square.dart'; class ShapeWidget extends StatelessWidget { const ShapeWidget({ super.key, required this.shape, - required this.size, + required this.boardSize, required this.orientation, }); final Shape shape; - final double size; + final double boardSize; final Side orientation; + double get squareSize => boardSize / 8; + @override Widget build(BuildContext context) { - return SizedBox.square( - dimension: size, - child: CustomPaint( - painter: switch (shape) { - Arrow( - color: final color, - orig: final orig, - dest: final dest, - ) => - _ArrowPainter( + return switch (shape) { + Arrow( + color: final color, + orig: final orig, + dest: final dest, + ) => + SizedBox.square( + dimension: boardSize, + child: CustomPaint( + painter: _ArrowPainter( color, orientation, Coord.fromSquareId(orig), Coord.fromSquareId(dest), ), - Circle(color: final color, orig: final orig) => - _CirclePainter(color, orientation, Coord.fromSquareId(orig)), - }, - ), - ); + ), + ), + Circle(color: final color, orig: final orig) => SizedBox.square( + dimension: boardSize, + child: CustomPaint( + painter: + _CirclePainter(color, orientation, Coord.fromSquareId(orig)), + ), + ), + PieceShape(orig: final orig, role: final role, color: final color) => + PositionedSquare( + size: squareSize, + orientation: orientation, + squareId: orig, + child: Image.asset( + 'assets/piece_sets/mono/${role.letter}.png', + package: 'chessground', + color: color, + width: squareSize, + height: squareSize, + ), + ), + }; } } diff --git a/pubspec.yaml b/pubspec.yaml index 2ce5180..4749be4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ flutter: - assets/piece_sets/libra/ - assets/piece_sets/maestro/ - assets/piece_sets/merida/ + - assets/piece_sets/mono/ - assets/piece_sets/mpchess/ - assets/piece_sets/pirouetti/ - assets/piece_sets/pixel/