Skip to content

Commit

Permalink
Use same file for all board settings
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Jul 23, 2024
1 parent 3c76af0 commit 7370cfd
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 98 deletions.
1 change: 0 additions & 1 deletion lib/chessground.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ library chessground;

export 'src/board_color_scheme.dart';
export 'src/draw_shape_options.dart';
export 'src/board_editor_settings.dart';
export 'src/board_settings.dart';
export 'src/board_state.dart';
export 'src/fen.dart';
Expand Down
96 changes: 0 additions & 96 deletions lib/src/board_editor_settings.dart

This file was deleted.

91 changes: 91 additions & 0 deletions lib/src/board_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,94 @@ class ChessboardSettings {
);
}
}

/// Board editor settings that control the theme, behavior and purpose of the board editor.
///
/// This is meant for fixed settings that don't change while editing the board.
/// Sensible defaults are provided.
@immutable
class BoardEditorSettings {
/// Creates a new [BoardEditorSettings] with the provided values.
const BoardEditorSettings({
// theme
this.colorScheme = ChessboardColorScheme.brown,
this.pieceAssets = PieceSet.cburnettAssets,
// visual settings
this.borderRadius = BorderRadius.zero,
this.boxShadow = const <BoxShadow>[],
this.enableCoordinates = true,
this.dragFeedbackScale = 2.0,
this.dragFeedbackOffset = const Offset(0.0, -1.0),
});

/// Theme of the board.
final ChessboardColorScheme colorScheme;

/// Piece set.
final PieceAssets pieceAssets;

/// Border radius of the board.
final BorderRadiusGeometry borderRadius;

/// Box shadow of the board.
final List<BoxShadow> boxShadow;

/// Whether to show board coordinates.
final bool enableCoordinates;

// Scale up factor for the piece currently under drag.
final double dragFeedbackScale;

// Offset for the piece currently under drag.
final Offset dragFeedbackOffset;

@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is BoardEditorSettings &&
other.colorScheme == colorScheme &&
other.pieceAssets == pieceAssets &&
other.borderRadius == borderRadius &&
other.boxShadow == boxShadow &&
other.enableCoordinates == enableCoordinates &&
other.dragFeedbackScale == dragFeedbackScale &&
other.dragFeedbackOffset == dragFeedbackOffset;
}

@override
int get hashCode => Object.hash(
colorScheme,
pieceAssets,
borderRadius,
boxShadow,
enableCoordinates,
dragFeedbackScale,
dragFeedbackOffset,
);

/// Creates a copy of this [BoardEditorSettings] but with the given fields replaced with the new values.
BoardEditorSettings copyWith({
ChessboardColorScheme? colorScheme,
PieceAssets? pieceAssets,
BorderRadiusGeometry? borderRadius,
List<BoxShadow>? boxShadow,
bool? enableCoordinates,
double? dragFeedbackScale,
Offset? dragFeedbackOffset,
}) {
return BoardEditorSettings(
colorScheme: colorScheme ?? this.colorScheme,
pieceAssets: pieceAssets ?? this.pieceAssets,
borderRadius: borderRadius ?? this.borderRadius,
boxShadow: boxShadow ?? this.boxShadow,
enableCoordinates: enableCoordinates ?? this.enableCoordinates,
dragFeedbackScale: dragFeedbackScale ?? this.dragFeedbackScale,
dragFeedbackOffset: dragFeedbackOffset ?? this.dragFeedbackOffset,
);
}
}
2 changes: 1 addition & 1 deletion lib/src/widgets/board_editor.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dartchess/dartchess.dart' show Piece, Side;
import 'package:flutter/widgets.dart';

import '../board_editor_settings.dart';
import '../board_settings.dart';
import '../models.dart';
import '../fen.dart';
import 'board.dart';
Expand Down

0 comments on commit 7370cfd

Please sign in to comment.