stagexl_interactive_chessboard 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

StageXL Interactive Chessboard #

An interactive chessboard written for StageXL which allows players to move pieces.

alt text

Example #

Chessboard board = Chessboard();
stage.addChild(board);

It is fully compatible with chess.dart #

Chess.Chess chess = Chess.Chess()
  ..move("e3")
  ..move("e5")
  ..move("Qe2")
  ..move("d5");
board.loadFromChessObject(chess);

Any square can have its background color set #

board.resetAllSquareColors();
board.setSquareBackgroundColor("e1", 0xaa27b243);

Capture when squares are clicked #

board.onSquareClicked.listen((ChessEvent event) {
  print(event.squareName);
});

Show and hide the labels around the board #

board.showLabels = true;

Change which way round the board is #

board.blackAtTop = false;

1.1.0 - 25/02/2018. #

  • decoupled square from chessboard so it can be used independantly.

1.0.0 - 20/02/2018. #

  • Initial version

example/main.dart

import 'dart:async';
import 'dart:html' as html;
import 'package:stagexl/stagexl.dart';
import 'package:stagexl_interactive_chessboard/stagexl_interactive_chessboard.dart';
import 'dart:math';
import 'package:chess/chess.dart' as Chess;

Stage stage;

Future<Null> main() async {
  StageOptions options = StageOptions()
    ..backgroundColor = Color.White
    ..stageScaleMode =StageScaleMode.NO_SCALE
    ..stageAlign =StageAlign.TOP_LEFT
    ..renderEngine = RenderEngine.WebGL;

  var canvas = html.querySelector('#stage');
  stage = Stage(canvas, width: 1280, height: 800, options: options);

  var renderLoop = RenderLoop();
  renderLoop.addStage(stage);

  Chessboard board = Chessboard();
  stage.addChild(board);
  board.blackAtTop = false;
  num size = min(stage.stageWidth, stage.stageHeight);
  size -= 20;
  board.setSize(size, size);

  board.x = (stage.stageWidth - board.width) / 2;
  board.y = (stage.stageHeight - board.height) / 2;
  
  Chess.Chess chess = Chess.Chess()
    ..move("e3")
    ..move("e5")
    ..move("Qe2")
    ..move("d5");
  board.loadFromChessObject(chess);

  board.onSquareClicked.listen((ChessEvent event) {
    board.resetAllSquareColors();
    board.setSquareBackgroundColor(event.squareName, 0xaa27b243);

    List<Chess.Move> moves = chess.generate_moves({"square": event.squareName});
    for (Chess.Move move in moves) {
      board.setSquareBackgroundColor(move.to, 0xaaffffb2);
    }
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  stagexl_interactive_chessboard: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:stagexl_interactive_chessboard/stagexl_interactive_chessboard.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/src/Chessboard.dart. (-2.48 points)

Analysis of lib/src/Chessboard.dart reported 5 hints:

line 31 col 7: Avoid const keyword.

line 41 col 25: Unnecessary new keyword.

line 45 col 3: Avoid return types on setters.

line 54 col 3: Avoid return types on setters.

line 129 col 19: Unnecessary new keyword.

Fix lib/src/BottomLabels.dart. (-1 points)

Analysis of lib/src/BottomLabels.dart reported 2 hints:

line 8 col 3: Avoid return types on setters.

line 28 col 29: Unnecessary new keyword.

Fix lib/src/LeftLabels.dart. (-1 points)

Analysis of lib/src/LeftLabels.dart reported 2 hints:

line 8 col 3: Avoid return types on setters.

line 28 col 29: Unnecessary new keyword.

Fix additional 3 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/src/PieceFactory.dart (1 hint)
  • lib/src/ChessEvent.dart (Run dartfmt to format lib/src/ChessEvent.dart.)
  • lib/stagexl_interactive_chessboard.dart (Run dartfmt to format lib/stagexl_interactive_chessboard.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
chess ^0.6.5 0.6.5
stagexl ^1.1.0 1.4.2
stagexl_chess_pieces ^1.0.1 1.0.1
Transitive dependencies
charcode 1.1.2
collection 1.14.12
convert 2.1.1
meta 1.1.8
petitparser 3.0.0
typed_data 1.1.6
xml 3.7.0