diff --git a/Shared/Bridge/FEngine.h b/Shared/Bridge/FEngine.h index ad5bb9f..d362bde 100644 --- a/Shared/Bridge/FEngine.h +++ b/Shared/Bridge/FEngine.h @@ -43,6 +43,7 @@ typedef void(^FEngineDidUpdateCallback)(); - (NSString* _Nonnull)PGNFormattedForDisplay; - (NSArray* _Nonnull)moveNodesTree; +- (NSUInteger)currentMoveNodeUUID; - (NSArray* _Nonnull)allMoves; - (NSArray* _Nonnull)movesAt:(NSUInteger)rank file:(NSUInteger)file; diff --git a/Shared/Bridge/FEngine.mm b/Shared/Bridge/FEngine.mm index 0ce063d..aee7ee5 100644 --- a/Shared/Bridge/FEngine.mm +++ b/Shared/Bridge/FEngine.mm @@ -125,6 +125,10 @@ - (void)moveNodesFromNode:(ChessGame::MoveNode)node return rootNode.variations; } +- (NSUInteger)currentMoveNodeUUID { + return engine.game.getCurrentMoveUUID(); +} + #pragma mark - - (NSString*)state { diff --git a/Shared/Bridge/FEngineMoveNode+Private.h b/Shared/Bridge/FEngineMoveNode+Private.h index 25d5a5d..d85fb3a 100644 --- a/Shared/Bridge/FEngineMoveNode+Private.h +++ b/Shared/Bridge/FEngineMoveNode+Private.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readwrite) NSUInteger moveNumber; @property (nonatomic, readwrite) BOOL whiteMove; +@property (nonatomic, readwrite) NSUInteger uuid; @property (nonatomic, strong, readwrite) NSString * _Nonnull name; @property (nonatomic, strong, readwrite) NSString * _Nonnull comment; @property (nonatomic, strong, readwrite) NSMutableArray * _Nonnull variations; diff --git a/Shared/Bridge/FEngineMoveNode.h b/Shared/Bridge/FEngineMoveNode.h index aa95eb3..1623e10 100644 --- a/Shared/Bridge/FEngineMoveNode.h +++ b/Shared/Bridge/FEngineMoveNode.h @@ -13,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface FEngineMoveNode: NSObject @property (nonatomic, readonly) NSUInteger moveNumber; @property (nonatomic, readonly) BOOL whiteMove; +@property (nonatomic, readonly) NSUInteger uuid; @property (nonatomic, strong, readonly) NSString * _Nonnull name; @property (nonatomic, strong, readonly) NSString * _Nonnull comment; @property (nonatomic, strong, readonly) NSArray * _Nonnull variations; diff --git a/Shared/Bridge/FEngineMoveNode.mm b/Shared/Bridge/FEngineMoveNode.mm index 27992d1..ca58e66 100644 --- a/Shared/Bridge/FEngineMoveNode.mm +++ b/Shared/Bridge/FEngineMoveNode.mm @@ -19,6 +19,7 @@ - (instancetype)initWithNode:(ChessGame::MoveNode)node { if (self = [super init]) { self.moveNumber = node.moveNumber; self.whiteMove = MOVE_COLOR(node.move) == WHITE; + self.uuid = node.uuid; self.name = NSStringFromString(FPGN::to_string(node.move, FPGN::SANType::tight)); self.comment = NSStringFromString(node.comment); self.variations = [NSMutableArray array]; diff --git a/Shared/Engine/Engine/ChessGame.cpp b/Shared/Engine/Engine/ChessGame.cpp index d32b722..e177548 100644 --- a/Shared/Engine/Engine/ChessGame.cpp +++ b/Shared/Engine/Engine/ChessGame.cpp @@ -91,6 +91,7 @@ void ChessGame::move(Move move, std::string comment, bool replace) { // this is a new variation (either main variation if no variation exists yet). if (!found || replace) { MoveNode newNode = MoveNode(); + newNode.uuid = nextMoveUUID(); newNode.moveNumber = ceil(moveIndexes.moveCursor / 2) + 1; newNode.comment = comment; newNode.move = move; diff --git a/Shared/Engine/Engine/ChessGame.hpp b/Shared/Engine/Engine/ChessGame.hpp index e64733d..3cac448 100644 --- a/Shared/Engine/Engine/ChessGame.hpp +++ b/Shared/Engine/Engine/ChessGame.hpp @@ -51,7 +51,12 @@ class ChessGame { // that a game represents. A node has a move associated with it, including // the next move node (or move nodes if there is more than one variation). struct MoveNode { - // The move number + // Unique ID for this move node, used to identify uniquely this node + // across any variations. For example, this is used to indicate + // which move node is the current one in the game. + unsigned int uuid; + + // The full move number unsigned moveNumber; // The move itself @@ -149,6 +154,14 @@ class ChessGame { return move; } + unsigned int getCurrentMoveUUID() { + unsigned int uuid = 0; + root.lookupNode(0, moveIndexes.moveCursor, moveIndexes, [&uuid](auto & node) { + uuid = node.uuid; + }); + return uuid; + } + MoveNode getRoot() { return root; } @@ -182,6 +195,20 @@ class ChessGame { MoveNode root; MoveIndexes moveIndexes; + // Unique ID for each generated move. + // Simply incrementing this variable + // is sufficient. + unsigned int moveUUID; + + unsigned int nextMoveUUID() { + if (moveUUID < UINT_MAX) { + moveUUID++; + } else { + moveUUID = 0; + } + return moveUUID; + } + void replayMoves(); }; diff --git a/Shared/Views/ContentView.swift b/Shared/Views/ContentView.swift index 7b5d70f..9929ede 100644 --- a/Shared/Views/ContentView.swift +++ b/Shared/Views/ContentView.swift @@ -38,9 +38,7 @@ struct ContentView: View { if (showInfo) { VStack(alignment: .leading) { - if (document.mode.value != .play) { - AnalyzeActionsView(document: $document) - } + AnalyzeActionsView(document: $document) InformationView(document: document) } diff --git a/Shared/Views/FullMoveItemView.swift b/Shared/Views/FullMoveItemView.swift index 99ebb25..61d69ce 100644 --- a/Shared/Views/FullMoveItemView.swift +++ b/Shared/Views/FullMoveItemView.swift @@ -11,21 +11,35 @@ import SwiftUI struct FullMoveItemView: View { var item: FullMoveItem + var currentMoveUUID: UInt + + func moveNameText(node: FEngineMoveNode) -> Text { + if node.uuid == currentMoveUUID { + return Text("\(node.name)") + .bold() + .underline() + } else { + return Text("\(node.name)") + } + } var body: some View { if let wm = item.whiteMove, let bm = item.blackMove { - Text("\(wm.moveNumber). \(wm.name)") + + Text("\(wm.moveNumber). ") + + moveNameText(node: wm) + Text(item.whiteComment) .italic() + - Text("\(bm.name)") + + moveNameText(node: bm) + Text(item.blackComment) .italic() } else if let wm = item.whiteMove { - Text("\(wm.moveNumber). \(wm.name)") + + Text("\(wm.moveNumber). ") + + moveNameText(node: wm) + Text(item.whiteComment) .italic() } else if let bm = item.blackMove { - Text("\(bm.moveNumber)... \(bm.name)") + + Text("\(bm.moveNumber)... ") + + moveNameText(node: bm) + Text(item.whiteComment) .italic() } else { @@ -36,6 +50,6 @@ struct FullMoveItemView: View { struct FullMoveItemView_Previews: PreviewProvider { static var previews: some View { - FullMoveItemView(item: FullMoveItem()) + FullMoveItemView(item: FullMoveItem(), currentMoveUUID: 0) } } diff --git a/Shared/Views/InformationView.swift b/Shared/Views/InformationView.swift index 8df7833..b863e0b 100644 --- a/Shared/Views/InformationView.swift +++ b/Shared/Views/InformationView.swift @@ -67,7 +67,7 @@ struct InformationView: View { .padding(.bottom) } List(document.moveNodes.moveNodes, children: \FullMoveItem.children) { item in - FullMoveItemView(item: item) + FullMoveItemView(item: item, currentMoveUUID: document.engine.currentMoveNodeUUID()) .font(.system(.body, design: .monospaced)) } Spacer()