Skip to content

Commit

Permalink
Fixed iOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-bovet committed Dec 15, 2022
1 parent 7a9953d commit 8c6dabf
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 32 deletions.
32 changes: 25 additions & 7 deletions BChess.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
A72E2B57200496CD006CBB1C /* BoardHashTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A72E2B56200496CC006CBB1C /* BoardHashTests.cpp */; };
A731BD3720009856004C13EF /* Tournament.swift in Sources */ = {isa = PBXBuildFile; fileRef = A731BD3620009856004C13EF /* Tournament.swift */; };
A731BD392000A513004C13EF /* TournamentEngines.swift in Sources */ = {isa = PBXBuildFile; fileRef = A731BD382000A513004C13EF /* TournamentEngines.swift */; };
A746997C2637CCF7007E0058 /* NavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A746997B2637CCF7007E0058 /* NavigationView.swift */; };
A746997D2637CCF7007E0058 /* NavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A746997B2637CCF7007E0058 /* NavigationView.swift */; };
A746997C2637CCF7007E0058 /* NavigationActionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A746997B2637CCF7007E0058 /* NavigationActionView.swift */; };
A746997D2637CCF7007E0058 /* NavigationActionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A746997B2637CCF7007E0058 /* NavigationActionView.swift */; };
A746C244200148E9001F4437 /* ChessBoardHash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A746C242200148E9001F4437 /* ChessBoardHash.cpp */; };
A746C245200148ED001F4437 /* ChessBoardHash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A746C242200148E9001F4437 /* ChessBoardHash.cpp */; };
A746C2492001707F001F4437 /* GameHistory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A746C2472001707F001F4437 /* GameHistory.cpp */; };
Expand Down Expand Up @@ -229,7 +229,7 @@
A72E2B56200496CC006CBB1C /* BoardHashTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoardHashTests.cpp; sourceTree = "<group>"; };
A731BD3620009856004C13EF /* Tournament.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tournament.swift; sourceTree = "<group>"; };
A731BD382000A513004C13EF /* TournamentEngines.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentEngines.swift; sourceTree = "<group>"; };
A746997B2637CCF7007E0058 /* NavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationView.swift; sourceTree = "<group>"; };
A746997B2637CCF7007E0058 /* NavigationActionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationActionView.swift; sourceTree = "<group>"; };
A746C242200148E9001F4437 /* ChessBoardHash.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ChessBoardHash.cpp; sourceTree = "<group>"; };
A746C243200148E9001F4437 /* ChessBoardHash.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ChessBoardHash.hpp; sourceTree = "<group>"; };
A746C2472001707F001F4437 /* GameHistory.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GameHistory.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -590,7 +590,7 @@
A72C3E012650D78100CB9DB7 /* VariationSelectionView.swift */,
A77F66AE25A832240030E61D /* ContentView.swift */,
A7A30F2E25B2BAFC00729432 /* PromotionView.swift */,
A746997B2637CCF7007E0058 /* NavigationView.swift */,
A746997B2637CCF7007E0058 /* NavigationActionView.swift */,
A712C255265377C000E05408 /* Arrow.swift */,
);
path = Views;
Expand Down Expand Up @@ -760,7 +760,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1230;
LastUpgradeCheck = 1230;
LastUpgradeCheck = 1410;
ORGANIZATIONNAME = "Jean Bovet";
TargetAttributes = {
A7712D131FB916E900E7E802 = {
Expand Down Expand Up @@ -920,7 +920,7 @@
A712C25326522F6000E05408 /* FullMove.swift in Sources */,
A791117F264B92E500F97FA7 /* FEngineGame+Private.h in Sources */,
A795162225ABE59900AEA95F /* PlayAgainst.swift in Sources */,
A746997C2637CCF7007E0058 /* NavigationView.swift in Sources */,
A746997C2637CCF7007E0058 /* NavigationActionView.swift in Sources */,
A7FE324E25AAD61200A75936 /* FEngineUtility.mm in Sources */,
A79515F625ABE44000AEA95F /* PiecesView.swift in Sources */,
A7BC72E42636003F008FBBB4 /* NewGameView.swift in Sources */,
Expand Down Expand Up @@ -978,7 +978,7 @@
A712C25426522F6000E05408 /* FullMove.swift in Sources */,
A7911180264B92E500F97FA7 /* FEngineGame+Private.h in Sources */,
A7FE31CB25AA96A800A75936 /* FEngineUtility.mm in Sources */,
A746997D2637CCF7007E0058 /* NavigationView.swift in Sources */,
A746997D2637CCF7007E0058 /* NavigationActionView.swift in Sources */,
A79515F725ABE44000AEA95F /* PiecesView.swift in Sources */,
A758BB0725AC119C0092714E /* Actions.swift in Sources */,
A716976D262BFF8C00156BD6 /* SettingsView.swift in Sources */,
Expand Down Expand Up @@ -1086,6 +1086,7 @@
CLANG_WARN_ASSIGN_ENUM = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1097,6 +1098,7 @@
);
INFOPLIST_FILE = BChessTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
PRODUCT_BUNDLE_IDENTIFIER = "ch.arizona-software.BChessTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BChess/BChess-Bridging-Header.h";
Expand All @@ -1109,6 +1111,7 @@
CLANG_WARN_ASSIGN_ENUM = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1120,6 +1123,7 @@
);
INFOPLIST_FILE = BChessTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
PRODUCT_BUNDLE_IDENTIFIER = "ch.arizona-software.BChessTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BChess/BChess-Bridging-Header.h";
Expand All @@ -1139,6 +1143,7 @@
INFOPLIST_FILE = iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MARKETING_VERSION = 0.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand All @@ -1164,6 +1169,7 @@
INFOPLIST_FILE = iOS/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MARKETING_VERSION = 0.2;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "ch.arizona-software.BChess";
Expand All @@ -1187,6 +1193,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 110;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -1215,6 +1222,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 110;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand All @@ -1241,6 +1249,7 @@
INFOPLIST_FILE = "Tests iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 14.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "ch.arizona-software.Tests-iOS";
Expand All @@ -1262,6 +1271,7 @@
INFOPLIST_FILE = "Tests iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 14.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "ch.arizona-software.Tests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1280,6 +1290,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
INFOPLIST_FILE = "Tests macOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
Expand All @@ -1300,6 +1311,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
INFOPLIST_FILE = "Tests macOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
Expand Down Expand Up @@ -1346,6 +1358,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -1407,6 +1420,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -1432,8 +1446,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BChess/BChess-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -1446,8 +1462,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 28XRU7S6GA;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "BChess/BChess-Bridging-Header.h";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
33 changes: 32 additions & 1 deletion Shared/Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ struct Actions {
document.lastMove = nil
}

func undoMove() {
guard document.engine.canMove(to: .backward) else {
return
}

withAnimation {
document.selection = Selection.empty()
document.lastMove = nil

if engine.isAnalyzing() {
engine.cancel()
}
document.engine.move(to: .backward, variation: 0)
document.pgn = document.engine.pgnAllGames()
}
}

func redoMove() {
guard document.engine.canMove(to: .forward) else {
return
}

withAnimation {
document.selection = Selection.empty()
document.lastMove = nil

document.engine.move(to: .forward, variation: 0)
document.pgn = document.engine.pgnAllGames()
}
}

func canMove(to: Direction) -> Bool {
return engine.canMove(to: to);
}
Expand Down Expand Up @@ -124,7 +155,7 @@ struct Actions {
pb.declareTypes([.string], owner: nil)
pb.setString(engine.getPGNCurrentGame(), forType: .string)
#else
UIPasteboard.general.string = engine.pgn()
UIPasteboard.general.string = engine.getPGNCurrentGame()
#endif
}

Expand Down
18 changes: 18 additions & 0 deletions Shared/ActionsToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ struct RotateBoard: View {
}
}

struct UndoMoveButton: View {
@Binding var document: ChessDocument
var body: some View {
Button(action: { Actions(document: $document).undoMove() }) {
Label("Undo Move", systemImage: "arrow.uturn.backward.square")
}.disabled(!document.engine.canMove(to: .backward))
}
}

struct RedoMoveButton: View {
@Binding var document: ChessDocument
var body: some View {
Button(action: { Actions(document: $document).redoMove() }) {
Label("Redo Move", systemImage: "arrow.uturn.forward.square")
}.disabled(!document.engine.canMove(to: .forward))
}
}

struct CopyFENButton: View {
@Binding var document: ChessDocument
var body: some View {
Expand Down
2 changes: 1 addition & 1 deletion Shared/Bridge/FEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef NS_ENUM(NSInteger, Direction){
// Perform the next move given the direction and variation index
- (void)moveTo:(Direction)direction variation:(NSUInteger)variation;
// Returns the next move UUID given the direction
- (UInt)moveUUID:(Direction)direction;
- (NSUInteger)moveUUID:(Direction)direction;

- (void)move:(NSString* _Nonnull)from to:(NSString* _Nonnull)to;

Expand Down
2 changes: 1 addition & 1 deletion Shared/Bridge/FEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ - (void)moveTo:(Direction)direction variation:(NSUInteger)variation {
[self fireUpdate:self.stateIndex];
}

- (UInt)moveUUID:(Direction)direction {
- (NSUInteger)moveUUID:(Direction)direction {
auto nextIndexes = engine.game().moveIndexesTo([self gameDirection:direction]);
return engine.game().getMoveUUID(nextIndexes);
}
Expand Down
10 changes: 5 additions & 5 deletions Shared/ChessDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import SwiftUI
import UniformTypeIdentifiers

extension UTType {
static var exampleText: UTType {
UTType(importedAs: "com.example.plain-text")
static var json: UTType {
UTType(importedAs: "ch.arizona-software.chess.json")
}
static var pgn: UTType {
UTType(importedAs: "com.apple.chess.pgn")
Expand Down Expand Up @@ -137,14 +137,14 @@ struct ChessDocument: FileDocument {
assert(result)
}

static var readableContentTypes: [UTType] { [.exampleText, .pgn] }
static var readableContentTypes: [UTType] { [.json, .pgn] }

init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents else {
throw CocoaError(.fileReadCorruptFile)
}

if configuration.contentType == .exampleText {
if configuration.contentType == .json {
let decoder = JSONDecoder()
let state = try decoder.decode(GameState.self, from: data)

Expand All @@ -161,7 +161,7 @@ struct ChessDocument: FileDocument {
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
let pgnToWrite = mode.value != .play ? mode.pgnBeforeAnalyzing : pgn
switch configuration.contentType {
case .exampleText:
case .json:
let state = GameState(pgn: pgnToWrite, rotated: rotated, white: whitePlayer, black: blackPlayer)
let encoder = JSONEncoder()
let data = try encoder.encode(state)
Expand Down
4 changes: 3 additions & 1 deletion Shared/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ struct ContentView: View {
}

if (showInfo) {
#if os(macOS)
VStack(alignment: .leading, spacing: 10) {
NavigationView(document: $document)
NavigationActionView(document: $document)
InformationView(document: $document)
}
.frame(minWidth: 350, idealWidth: 350, maxWidth: 350, alignment: .leading)
#endif
}
}
.padding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import SwiftUI

struct NavigationView: View {
struct NavigationActionView: View {

@Binding var document: ChessDocument

Expand Down Expand Up @@ -49,9 +49,9 @@ struct NavigationView: View {
}
}

struct NavigationView_Previews: PreviewProvider {
struct NavigationActionView_Previews: PreviewProvider {
static var previews: some View {
let doc = try! ChessDocument()
NavigationView(document: .constant(doc))
NavigationActionView(document: .constant(doc))
}
}
4 changes: 2 additions & 2 deletions Shared/Views/NewGameView_iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ struct NewGameView_iOS: View {
struct NewGameView_iOS_Previews: PreviewProvider {
static var previews: some View {
Group {
let doc = ChessDocument()
let doc = try! ChessDocument()
NewGameView_iOS(document: .constant(doc), editMode: false)
}
Group {
let doc = ChessDocument()
let doc = try! ChessDocument()
NewGameView_iOS(document: .constant(doc), editMode: true)
}
}
Expand Down
Loading

0 comments on commit 8c6dabf

Please sign in to comment.