Skip to content

Commit

Permalink
Add piece shape from mono assets
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Mar 6, 2024
1 parent d6535d0 commit 2142096
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 20 deletions.
Binary file added assets/piece_sets/mono/2.0x/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/2.0x/K.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/2.0x/N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/2.0x/P.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/2.0x/Q.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/2.0x/R.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/3.0x/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/3.0x/K.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/3.0x/N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/3.0x/P.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/3.0x/Q.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/3.0x/R.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/4.0x/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/4.0x/K.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/4.0x/N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/4.0x/P.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/4.0x/Q.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/4.0x/R.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/K.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/P.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/Q.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/piece_sets/mono/R.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 48 additions & 1 deletion lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions lib/src/widgets/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ class _BoardState extends State<Board> {
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,
),
],
Expand Down
55 changes: 38 additions & 17 deletions lib/src/widgets/shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
};
}
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 2142096

Please sign in to comment.