diff --git a/ArkitDoushiQi/ArkitDoushiQi.xcodeproj/project.pbxproj b/ArkitDoushiQi/ArkitDoushiQi.xcodeproj/project.pbxproj index 3544142..54a3ecc 100644 --- a/ArkitDoushiQi/ArkitDoushiQi.xcodeproj/project.pbxproj +++ b/ArkitDoushiQi/ArkitDoushiQi.xcodeproj/project.pbxproj @@ -7,6 +7,22 @@ objects = { /* Begin PBXBuildFile section */ + 8268B4A42C1C640000D195CC /* VMArkit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8268B4A32C1C640000D195CC /* VMArkit.swift */; }; + 82740EBE2C19762C009711A5 /* ArKitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82740EBD2C19762C009711A5 /* ArKitView.swift */; }; + 82740EC02C197A48009711A5 /* ArKitViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82740EBF2C197A48009711A5 /* ArKitViewRepresentable.swift */; }; + 82740EC22C197C1A009711A5 /* ContentArkit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82740EC12C197C1A009711A5 /* ContentArkit.swift */; }; + 827AC57F2C206374001701CC /* cat.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC57E2C206374001701CC /* cat.usdz */; }; + 827AC5812C206385001701CC /* dog.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC5802C206385001701CC /* dog.usdz */; }; + 827AC5832C206395001701CC /* elephant.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC5822C206395001701CC /* elephant.usdz */; }; + 827AC5852C2063AB001701CC /* leopard.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC5842C2063AB001701CC /* leopard.usdz */; }; + 827AC5872C2063B6001701CC /* lion.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC5862C2063B6001701CC /* lion.usdz */; }; + 827AC5892C2063C7001701CC /* rat.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC5882C2063C7001701CC /* rat.usdz */; }; + 827AC58B2C2063D6001701CC /* tiger.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC58A2C2063D6001701CC /* tiger.usdz */; }; + 827AC58D2C2063E2001701CC /* wolf.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 827AC58C2C2063E2001701CC /* wolf.usdz */; }; + 827AC58E2C206625001701CC /* DSQ.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2A535D82C0F56A700503472 /* DSQ.xcframework */; }; + 827AC58F2C206625001701CC /* DSQ.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C2A535D82C0F56A700503472 /* DSQ.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 82CCA5442C1C2B6400AFF485 /* board.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 82CCA5432C1C2B6400AFF485 /* board.usdz */; }; + 82CCA5462C1C2B8E00AFF485 /* CatPiece.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 82CCA5452C1C2B8E00AFF485 /* CatPiece.usdz */; }; 16038A272C197B800074346E /* FlagManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16038A262C197B800074346E /* FlagManager.swift */; }; 161A8E932C2055EA00D1ADFE /* Placeholder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 161A8E922C2055EA00D1ADFE /* Placeholder.swift */; }; 165725EA2C1984CC0052D7EF /* FontManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165725E92C1984CC0052D7EF /* FontManager.swift */; }; @@ -25,7 +41,6 @@ C205A2D42BF373380097BD93 /* WtaTennisUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C205A2D32BF373380097BD93 /* WtaTennisUITestsLaunchTests.swift */; }; C24659E52BF5FE09004E80D5 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C24659E42BF5FE09004E80D5 /* MainMenu.swift */; }; C25220EE2C00AC7E0026B71F /* GameParametersMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C25220ED2C00AC7E0026B71F /* GameParametersMenuView.swift */; }; - C2A535D92C0F56A800503472 /* DSQ.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2A535D82C0F56A700503472 /* DSQ.xcframework */; }; C2DF075B2C206EEF00BEE0E1 /* Stub.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2DF075A2C206EEF00BEE0E1 /* Stub.swift */; }; C2DF07622C20719800BEE0E1 /* Magic.sks in Resources */ = {isa = PBXBuildFile; fileRef = C2DF075D2C20719800BEE0E1 /* Magic.sks */; }; C2DF07632C20719800BEE0E1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C2DF075E2C20719800BEE0E1 /* Assets.xcassets */; }; @@ -67,7 +82,36 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + 827AC5902C206625001701CC /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 827AC58F2C206625001701CC /* DSQ.xcframework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ + 8268B4A32C1C640000D195CC /* VMArkit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VMArkit.swift; sourceTree = ""; }; + 82740EBD2C19762C009711A5 /* ArKitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArKitView.swift; sourceTree = ""; }; + 82740EBF2C197A48009711A5 /* ArKitViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArKitViewRepresentable.swift; sourceTree = ""; }; + 82740EC12C197C1A009711A5 /* ContentArkit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentArkit.swift; sourceTree = ""; }; + 827AC57E2C206374001701CC /* cat.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = cat.usdz; sourceTree = ""; }; + 827AC5802C206385001701CC /* dog.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = dog.usdz; sourceTree = ""; }; + 827AC5822C206395001701CC /* elephant.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = elephant.usdz; sourceTree = ""; }; + 827AC5842C2063AB001701CC /* leopard.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = leopard.usdz; sourceTree = ""; }; + 827AC5862C2063B6001701CC /* lion.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = lion.usdz; sourceTree = ""; }; + 827AC5882C2063C7001701CC /* rat.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = rat.usdz; sourceTree = ""; }; + 827AC58A2C2063D6001701CC /* tiger.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = tiger.usdz; sourceTree = ""; }; + 827AC58C2C2063E2001701CC /* wolf.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = wolf.usdz; sourceTree = ""; }; + 82CCA53C2C1C255E00AFF485 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 82CCA5432C1C2B6400AFF485 /* board.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; path = board.usdz; sourceTree = ""; }; + 82CCA5452C1C2B8E00AFF485 /* CatPiece.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; name = CatPiece.usdz; path = ArkitDoushiQi/Resources/Object/CatPiece.usdz; sourceTree = SOURCE_ROOT; }; 16038A262C197B800074346E /* FlagManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlagManager.swift; sourceTree = ""; }; 16038A2A2C197DEC0074346E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 161A8E922C2055EA00D1ADFE /* Placeholder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Placeholder.swift; sourceTree = ""; }; @@ -122,7 +166,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - C2A535D92C0F56A800503472 /* DSQ.xcframework in Frameworks */, + 827AC58E2C206625001701CC /* DSQ.xcframework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -193,6 +237,34 @@ name = Frameworks; sourceTree = ""; }; + 82740EBA2C19739A009711A5 /* ArKit */ = { + isa = PBXGroup; + children = ( + 82740EBD2C19762C009711A5 /* ArKitView.swift */, + 82740EBF2C197A48009711A5 /* ArKitViewRepresentable.swift */, + 82740EC12C197C1A009711A5 /* ContentArkit.swift */, + 8268B4A32C1C640000D195CC /* VMArkit.swift */, + ); + path = ArKit; + sourceTree = ""; + }; + 827AC57D2C2062E5001701CC /* Object */ = { + isa = PBXGroup; + children = ( + 827AC58C2C2063E2001701CC /* wolf.usdz */, + 827AC58A2C2063D6001701CC /* tiger.usdz */, + 827AC5882C2063C7001701CC /* rat.usdz */, + 827AC5862C2063B6001701CC /* lion.usdz */, + 827AC5842C2063AB001701CC /* leopard.usdz */, + 827AC5822C206395001701CC /* elephant.usdz */, + 827AC5802C206385001701CC /* dog.usdz */, + 827AC57E2C206374001701CC /* cat.usdz */, + 82CCA5432C1C2B6400AFF485 /* board.usdz */, + 82CCA5452C1C2B8E00AFF485 /* CatPiece.usdz */, + ); + path = Object; + sourceTree = ""; + }; 82CE59E52C045C7500ADEE24 /* Game */ = { isa = PBXGroup; children = ( @@ -238,6 +310,8 @@ C205A2B52BF373360097BD93 /* ArkitDoushiQi */ = { isa = PBXGroup; children = ( + 82CCA53C2C1C255E00AFF485 /* Info.plist */, + 82740EBA2C19739A009711A5 /* ArKit */, C2DF07592C206EEF00BEE0E1 /* Data */, 16038A2A2C197DEC0074346E /* Info.plist */, C2F015072C09D366000F7221 /* Utils */, @@ -381,6 +455,41 @@ path = Visuals; sourceTree = ""; }; + C2F015272C09D420000F7221 /* PartyEnregistery */ = { + isa = PBXGroup; + children = ( + C2F015282C09D420000F7221 /* Stub.swift */, + C2F015292C09D420000F7221 /* PartyEnregistery.swift */, + ); + path = PartyEnregistery; + sourceTree = ""; + }; + C2F015352C09D592000F7221 /* Resources */ = { + isa = PBXGroup; + children = ( + 827AC57D2C2062E5001701CC /* Object */, + C2F0153A2C09D5C0000F7221 /* fr.lproj */, + C2F015362C09D5A5000F7221 /* en.lproj */, + ); + path = Resources; + sourceTree = ""; + }; + C2F015362C09D5A5000F7221 /* en.lproj */ = { + isa = PBXGroup; + children = ( + C2F015372C09D5A5000F7221 /* Localizable.strings */, + ); + path = en.lproj; + sourceTree = SOURCE_ROOT; + }; + C2F0153A2C09D5C0000F7221 /* fr.lproj */ = { + isa = PBXGroup; + children = ( + C2F0153B2C09D5C0000F7221 /* Localizable.strings */, + ); + path = fr.lproj; + sourceTree = SOURCE_ROOT; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -391,6 +500,7 @@ C205A2AF2BF373360097BD93 /* Sources */, C205A2B02BF373360097BD93 /* Frameworks */, C205A2B12BF373360097BD93 /* Resources */, + 827AC5902C206625001701CC /* Embed Frameworks */, ); buildRules = ( ); @@ -486,14 +596,24 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 82CCA5442C1C2B6400AFF485 /* board.usdz in Resources */, C205A2BE2BF373380097BD93 /* Preview Assets.xcassets in Resources */, 16DB00A42C257BA900BA190C /* nuku1.ttf in Resources */, C2DF07652C20719800BEE0E1 /* FireworkLaunch.sks in Resources */, C2DF07642C20719800BEE0E1 /* Spark.sks in Resources */, C2DF07662C20719800BEE0E1 /* Fireworks.sks in Resources */, + 827AC58D2C2063E2001701CC /* wolf.usdz in Resources */, + 827AC57F2C206374001701CC /* cat.usdz in Resources */, + 82CCA5462C1C2B8E00AFF485 /* CatPiece.usdz in Resources */, + 827AC5852C2063AB001701CC /* leopard.usdz in Resources */, + 827AC5832C206395001701CC /* elephant.usdz in Resources */, C2DF07622C20719800BEE0E1 /* Magic.sks in Resources */, C2DF07632C20719800BEE0E1 /* Assets.xcassets in Resources */, + 827AC5812C206385001701CC /* dog.usdz in Resources */, + 827AC5872C2063B6001701CC /* lion.usdz in Resources */, + 827AC58B2C2063D6001701CC /* tiger.usdz in Resources */, C205A2BB2BF373380097BD93 /* Assets.xcassets in Resources */, + 827AC5892C2063C7001701CC /* rat.usdz in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -518,6 +638,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 82740EC22C197C1A009711A5 /* ContentArkit.swift in Sources */, C2F015112C09D3C3000F7221 /* AI.swift in Sources */, C2DF075B2C206EEF00BEE0E1 /* Stub.swift in Sources */, C2DF076B2C2071B300BEE0E1 /* ActionRemove.swift in Sources */, @@ -533,9 +654,12 @@ 16FA05962C1C1A5F0042D688 /* GameType.swift in Sources */, C2F0151F2C09D3E7000F7221 /* ToggleComponent.swift in Sources */, C2F015202C09D3E7000F7221 /* ButtonComponent.swift in Sources */, + 82740EC02C197A48009711A5 /* ArKitViewRepresentable.swift in Sources */, C2F015262C09D3E7000F7221 /* ProfileEdit.swift in Sources */, 16FA05942C1C1A380042D688 /* Rules.swift in Sources */, C205A2B72BF373360097BD93 /* ArkitDoushiQiApp.swift in Sources */, + 82740EBE2C19762C009711A5 /* ArKitView.swift in Sources */, + 8268B4A42C1C640000D195CC /* VMArkit.swift in Sources */, C2F015232C09D3E7000F7221 /* EditTextComponent.swift in Sources */, C2F015222C09D3E7000F7221 /* PhotoButtonComponent.swift in Sources */, C2F015092C09D366000F7221 /* LanguageSettings.swift in Sources */, @@ -721,12 +845,18 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_IDENTITY = "Apple Development"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"ArkitDoushiQi/Views\""; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = DRCMU7YM68; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = ArkitDoushiQi/Info.plist; + INFOPLIST_KEY_NSCameraUsageDescription = "Donne la cam "; + INFOPLIST_FILE = ArkitDoushiQi/Info.plist; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -737,8 +867,10 @@ "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = UCA.WtaTennis; + PRODUCT_BUNDLE_IDENTIFIER = fr.uca.iut.ArkitDoushiQi; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = tpiOS_2023; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -750,12 +882,18 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_IDENTITY = "Apple Development"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"ArkitDoushiQi/Views\""; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = DRCMU7YM68; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = ArkitDoushiQi/Info.plist; + INFOPLIST_KEY_NSCameraUsageDescription = "Donne la cam "; + INFOPLIST_FILE = ArkitDoushiQi/Info.plist; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -766,8 +904,10 @@ "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = UCA.WtaTennis; + PRODUCT_BUNDLE_IDENTIFIER = fr.uca.iut.ArkitDoushiQi; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = tpiOS_2023; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift new file mode 100644 index 0000000..56d0d25 --- /dev/null +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift @@ -0,0 +1,66 @@ +// +// ArKitView.swift +// ArkitDoushiQi +// +// Created by Enzo JOLYS on 12/06/2024. +// + +import DouShouQiModel +import Foundation +import ARKit +import RealityKit +import UIKit + +class ArKitView : ARView { + + + required init(frame frameRect: CGRect) { + super.init(frame: frameRect) + } + + required init?(coder decoder: NSCoder) { + fatalError("init(coder:) not implemented") + } + + convenience init() { + self.init(frame: UIScreen.main.bounds) + } + + func applyConfiguration() { + let configuration = ARWorldTrackingConfiguration() + session.run(configuration) + } + + func defineAnchors() -> AnchorEntity { + let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2(0.2, 0.2))) + scene.addAnchor(anchor) + return anchor + } + + func addGesture(_ pieces:[Owner : [ Animal : Entity?]]){ + for piece in pieces.flatMap({ animal,values in return values }) + { + if piece.self.value != nil { + self.installGestures([.all], for: piece.self.value as! Entity & HasCollision).forEach { gestureRecognizer in + gestureRecognizer.addTarget(self, action: #selector(handleGesture(_:))) + } + } + } + + } + + var initialTransform: Transform = Transform() + + @objc private func handleGesture(_ recognizer: UIGestureRecognizer) { + guard let translationGesture = recognizer as? EntityTranslationGestureRecognizer, let entity = translationGesture.entity else { return } + + switch translationGesture.state { + case .began: + self.initialTransform = entity.transform + case .ended: + entity.move(to: initialTransform, relativeTo: entity.parent, duration: 1) + default: + break + } + } +} diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitViewRepresentable.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitViewRepresentable.swift new file mode 100644 index 0000000..b11817f --- /dev/null +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitViewRepresentable.swift @@ -0,0 +1,29 @@ +// +// ArKitViewRepresentable.swift +// ArkitDoushiQi +// +// Created by Enzo JOLYS on 12/06/2024. +// + +import Foundation +import SwiftUI +import DouShouQiModel + +struct ArKitViewRepresentable : UIViewRepresentable { + + var vm:VMArkit + + init(_ game:Game){ + vm = VMArkit(game) + } + + func makeUIView(context: Context) -> ArKitView { + let arView = ArKitView() + let anchor = arView.defineAnchors() + vm.setup(anchor) + arView.addGesture(vm.pieces) + return arView + } + + func updateUIView(_ uiView: UIViewType, context: Context) { } +} diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift new file mode 100644 index 0000000..d0e9f97 --- /dev/null +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift @@ -0,0 +1,28 @@ +// +// UIViewArKit.swift +// ArkitDoushiQi +// +// Created by Enzo JOLYS on 12/06/2024. +// + +import SwiftUI +import DouShouQiModel + +struct ContentArkit: View { + + //var vm:VMArkit = VMArkit(try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Bot2", andId: .player2)!)) + + var body: some View { + VStack { + Text("toto") + ArKitViewRepresentable(try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Bot2", andId: .player2)!)) + } + } +} + + +struct UIViewArKit_Previews: PreviewProvider { + static var previews: some View { + ContentArkit() + } +} diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/VMArkit.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/VMArkit.swift new file mode 100644 index 0000000..c5cc548 --- /dev/null +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/VMArkit.swift @@ -0,0 +1,192 @@ +// +// VMArkit.swift +// ArkitDoushiQi +// +// Created by Enzo JOLYS on 14/06/2024. +// + +import Foundation +import DouShouQiModel +import ARKit +import RealityKit +import UIKit + +struct VMArkit { + + static let offset = CGPoint(x: -0.458 * 0.3 , y: -0.3435 * 0.3 ) + static let direction = CGVector(dx: 0.1145 * 0.3, dy: 0.1145 * 0.3) + + var game:Game + + var pieces: [Owner : [ Animal : Entity?]] = [.player1: [.cat:nil, + .elephant:nil, + .dog:nil, + .leopard:nil, + .lion:nil, + .rat:nil, + .tiger:nil, + .wolf:nil], + .player2: [.cat:nil, + .elephant:nil, + .dog:nil, + .leopard:nil, + .lion:nil, + .rat:nil, + .tiger:nil, + .wolf:nil]] + + init(_ game:Game){ + self.game = game + } + + func setup(_ anchor:AnchorEntity){ + addBoard(anchor) + generatePieces(anchor) + displayBoard(game.board) + } + + func addBoard(_ anchor:AnchorEntity){ + let board = try? Entity.load(named: "board") + board?.scale = [0.3,0.3,0.3] + if let board { + print("Ajout du board") + anchor.addChild(board) + } + } + + // -- Crée les pieces + func generatePieces(_ anchor:AnchorEntity) { + + // Position - X,Y,Z + for var piece in pieces.flatMap({ animal,values in return values }) + { + var entity:Entity? + switch piece.self.key { + case .cat : + entity = try? Entity.loadModel(named: "cat") + case .elephant : + entity = try? Entity.loadModel(named: "elephant") + case .dog : + entity = try? Entity.loadModel(named: "dog") + case .leopard : + entity = try? Entity.loadModel(named: "leopard") + case .lion : + entity = try? Entity.loadModel(named: "lion") + case .rat : + entity = try? Entity.loadModel(named: "rat") + case .tiger : + entity = try? Entity.loadModel(named: "tiger") + case .wolf : + entity = try? Entity.loadModel(named: "wolf") + + default: + fatalError("Animal non compris") + } + + + if let entityNotNull = entity { + entityNotNull.scale = [0.3,0.3,0.3] + anchor.addChild(entityNotNull) + entityNotNull.position = SIMD3(0,0.02,0) + + entityNotNull.generateCollisionShapes(recursive:true) + + piece.self.value = entityNotNull + print("Piece \(piece.self.key) a été crée !") + } + else { + print("La pièce \(piece.self.key) n'a pas été crée !") + } + } + + } + + + // -- Affiche les pieces à la bonne positions + func displayBoard(_ board:Board) { + for ligne in 0.. Element vide ") + } + } + } + } + } + } + + func convertPosModeleIntoWorldPos(pos:CGPoint) -> SIMD3 { + return SIMD3(Float(VMArkit.offset.x + VMArkit.direction.dx * pos.x),Float(VMArkit.offset.y + VMArkit.direction.dy * pos.y),10) + } + func converWorldPosIntoPosModele(pos:SIMD3) -> CGPoint { + let posX = Int(round((CGFloat(pos.x) - (VMArkit.offset.x)) / VMArkit.direction.dx)) + let posY = Int(round((CGFloat(pos.y) - (VMArkit.offset.y)) / VMArkit.direction.dy)) + return CGPoint(x: posX, y: posY) + } + + + // ------ Listener -------- // + func defineListeners(){ + self.game.addGameStartedListener { board in startGame()} + self.game.addGameOverListener { board, result, player in gameOver()} + self.game.addGameChangedListener { game in gameChange() } + self.game.addBoardChangedListener { board in boardChange() } + self.game.addMoveChosenCallbacksListener { board, move, player in moveChose(board: board, move: move, player: player) } + self.game.addInvalidMoveCallbacksListener { board,move,player,bool in invalidMove(board: board, move: move, player:player, bool:bool)} + self.game.addPieceRemovedListener { _,_,piece in removePiece(piece: piece) } + + self.game.addPlayerNotifiedListener { board, player in + print("Player notif : \(player.id) à toi de jouer ") + //msg = "Player notif : \(player.id) à toi de jouer !" + if (player is IAPlayer ){ + try! await player.chooseMove(in: board, with: game.rules) + }} + } + + func startGame() { print("Start game !") + //self.msg = "Start !!" + } + func gameOver() { print("Game over !") + //msg = "Game over !!" + } + func gameChange() { print("Game change !") } + func boardChange() { + print("Board change !") + self.displayBoard(self.game.board) + } + + func moveChose(board:Board,move:Move,player:Player) { + } + + func invalidMove(board:Board,move:Move,player:Player,bool:Bool) { + if (bool){ // Valid + print("Move valid de \(player.id)") + print("Move : \(move.description)") + } + else { // Invalid + print("Move invalid de \(player.id)") + print("Move : \(move.description)") + self.displayBoard(self.game.board) + } + print("------------") + } + + func removePiece(piece:Piece){ + print("Remove piece") + if let entity = pieces[piece.owner]![piece.animal] { + if let x = entity { + x.removeFromParent() + } + } + } + + // ------------------------- // + +} diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArkitDoushiQiApp.swift b/ArkitDoushiQi/ArkitDoushiQi/ArkitDoushiQiApp.swift index 69ad0b1..95273db 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/ArkitDoushiQiApp.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/ArkitDoushiQiApp.swift @@ -25,7 +25,8 @@ struct ArkitDoushiQiApp: App { .environmentObject(LanguageSettings(selectedLanguage: .French) ) .environmentObject(languageSettings) - .preferredColorScheme(isDarkMode ? .dark : .light) + .preferredColorScheme(isDarkMode ? .dark : .light)*/ + ContentArkit() } } } diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/CatPiece.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/CatPiece.usdz new file mode 100644 index 0000000..021f023 Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/CatPiece.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/board.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/board.usdz new file mode 100644 index 0000000..ddba6fe Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/board.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/cat.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/cat.usdz new file mode 100644 index 0000000..83112d6 Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/cat.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/dog.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/dog.usdz new file mode 100644 index 0000000..88ab0f4 Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/dog.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/elephant.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/elephant.usdz new file mode 100644 index 0000000..9565263 Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/elephant.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/leopard.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/leopard.usdz new file mode 100644 index 0000000..f018773 Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/leopard.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/lion.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/lion.usdz new file mode 100644 index 0000000..aa901d0 Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/lion.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/rat.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/rat.usdz new file mode 100644 index 0000000..d8cc30d Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/rat.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/tiger.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/tiger.usdz new file mode 100644 index 0000000..dc6792d Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/tiger.usdz differ diff --git a/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/wolf.usdz b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/wolf.usdz new file mode 100644 index 0000000..0b45669 Binary files /dev/null and b/ArkitDoushiQi/ArkitDoushiQi/Resources/Object/wolf.usdz differ diff --git a/ArkitDoushiQi/Object/board.usdz b/ArkitDoushiQi/Object/board.usdz new file mode 100644 index 0000000..ddba6fe Binary files /dev/null and b/ArkitDoushiQi/Object/board.usdz differ