Skip to content

Commit

Permalink
import: Add PGN Parser (WIP)
Browse files Browse the repository at this point in the history
Change-Id: Id30d5f2af097d7216eda906dc52d9d3aa68a9a9b
  • Loading branch information
calcitem committed Jan 31, 2025
1 parent 1c99b34 commit 4a07471
Show file tree
Hide file tree
Showing 13 changed files with 1,014 additions and 664 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class GameController {
ValueNotifier<String?>(null);

String? get initialSharingMoveList => _initialSharingMoveList;

set initialSharingMoveList(String? list) {
_initialSharingMoveList = list;
initialSharingMoveListNotifier.value = list;
Expand All @@ -79,9 +80,11 @@ class GameController {
late AnimationManager animationManager;

bool _isInitialized = false;

bool get initialized => _isInitialized;

bool get isPositionSetup => gameRecorder.setupPosition != null;

void clearPositionSetupFlag() => gameRecorder.setupPosition = null;

@visibleForTesting
Expand Down Expand Up @@ -427,5 +430,5 @@ class GameController {

/// Starts a game export.
static Future<void> export(BuildContext context) async =>
ImportService.exportGame(context);
ExportService.exportGame(context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,3 @@ class HistoryRange implements HistoryResponse {
return "${HistoryResponse.tag} Current is equal to moveIndex.";
}
}

/// Custom response to throw when importing the game history.
abstract class ImportResponse {}

class ImportFormatException extends FormatException {
const ImportFormatException([String? source, int? offset])
: super("Cannot import ", source, offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,17 @@ class Position {
ExtMove? _record;

static List<List<List<int>>> get _millTable => _Mills.millTableInit;

static List<List<int>> get _adjacentSquares => _Mills.adjacentSquaresInit;

static List<List<int>> get _millLinesHV => _Mills._horizontalAndVerticalLines;

static List<List<int>> get _millLinesD => _Mills._diagonalLines;

PieceColor pieceOnGrid(int index) => _grid[index];

PieceColor get sideToMove => _sideToMove;

set sideToMove(PieceColor color) {
_sideToMove = color;
_them = _sideToMove.opponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2019-2025 The Sanmill developers (see AUTHORS file)

// export_service.dart

part of '../mill.dart';

class ExportService {
const ExportService._();

/// Exports the game to the device's clipboard.
static Future<void> exportGame(BuildContext context) async {
await Clipboard.setData(
ClipboardData(text: GameController().gameRecorder.moveHistoryText),
);

if (!context.mounted) {
return;
}

rootScaffoldMessengerKey.currentState!
.showSnackBarClear(S.of(context).moveHistoryCopied);

Navigator.pop(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2019-2025 The Sanmill developers (see AUTHORS file)

// import_exceptions.dart

part of '../mill.dart';

/// Custom response to throw when importing the game history.
abstract class ImportResponse {}

class ImportFormatException extends FormatException {
const ImportFormatException([String? source, int? offset])
: super("Cannot import ", source, offset);
}
Loading

0 comments on commit 4a07471

Please sign in to comment.