Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aarushbothra committed Aug 31, 2020
1 parent 7ddedc2 commit b676cb5
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 232 deletions.
4 changes: 2 additions & 2 deletions laser tag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
CODE_SIGN_ENTITLEMENTS = "laser tag/laser tag.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = KG885U9N7S;
INFOPLIST_FILE = "laser tag/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.5;
Expand All @@ -511,7 +511,7 @@
CODE_SIGN_ENTITLEMENTS = "laser tag/laser tag.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = KG885U9N7S;
INFOPLIST_FILE = "laser tag/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
filePath = "laser tag/View Controllers/LobbyVC.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "160"
endingLineNumber = "160"
startingLineNumber = "159"
endingLineNumber = "159"
landmarkName = "collectionView(_:cellForItemAt:)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -202,8 +202,8 @@
filePath = "laser tag/View Controllers/LobbyVC.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "162"
endingLineNumber = "162"
startingLineNumber = "161"
endingLineNumber = "161"
landmarkName = "collectionView(_:cellForItemAt:)"
landmarkType = "7">
</BreakpointContent>
Expand Down
23 changes: 21 additions & 2 deletions laser tag/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@
</constraints>
<viewLayoutGuide key="safeArea" id="F1P-Ls-BBq"/>
</view>
<navigationItem key="navigationItem" id="r71-o9-28G"/>
<connections>
<outlet property="alertLabel" destination="zsK-n7-JGJ" id="1C1-Wm-8WK"/>
<outlet property="ammoInGunLabel" destination="iOj-hl-sOW" id="KLH-TX-RUc"/>
Expand All @@ -1014,7 +1015,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Kn0-UI-idT" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="4441.875" y="124.64788732394366"/>
<point key="canvasLocation" x="5380" y="124.58770614692655"/>
</scene>
<!--Game OverVC-->
<scene sceneID="zd3-Dt-sYF">
Expand Down Expand Up @@ -1077,7 +1078,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="I16-SX-FVI" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="5418.75" y="128.87323943661971"/>
<point key="canvasLocation" x="6357.6000000000004" y="128.18590704647679"/>
</scene>
<!--Starting CountdownVC-->
<scene sceneID="oEX-O0-1lM">
Expand Down Expand Up @@ -1301,6 +1302,24 @@
</objects>
<point key="canvasLocation" x="4437.6000000000004" y="1563.8680659670167"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="CM9-4m-x3t">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="2NU-sP-Yjw" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="wiv-O1-QYZ">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="Lbb-TB-4aH" kind="relationship" relationship="rootViewController" id="qYd-ft-sZh"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="JTL-Nx-gG8" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="4440.8000000000002" y="124.58770614692655"/>
</scene>
</scenes>
<color key="tintColor" systemColor="systemBlueColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</document>
70 changes: 61 additions & 9 deletions laser tag/Handlers/BluetoothHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class BluetoothHandler: NSObject {

var execute = true

var possibleGuns = [Gun]()

public func initializeCentraManager(){
print("initializing")
centralManager = CBCentralManager(delegate: self, queue: nil)
Expand Down Expand Up @@ -146,21 +148,63 @@ extension BluetoothHandler: CBCentralManagerDelegate {

public func connectToGun() {

self.centralManager.scanForPeripherals(withServices: [gunServiceUUID])
self.centralManager.scanForPeripherals(withServices: [self.gunServiceUUID])

let progress = Progress(totalUnitCount: 10)

Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true){ (timer) in

guard progress.isFinished == false else {
timer.invalidate()
print("attempting connection")
if self.possibleGuns.count > 0 {
var peripheralToConnect = self.possibleGuns[0]
for gun in self.possibleGuns {
print(Int(gun.RSSI))
print(gun.peripheral.identifier)
if Int(gun.RSSI) > Int(peripheralToConnect.RSSI) {
peripheralToConnect = gun
}
}
print("Peripheral To Connect: \(peripheralToConnect.peripheral.identifier)")
//self.possibleGuns.sorted(by: {Int($0.RSSI) < Int($1.RSSI)})
print("connecting")
self.laserTagGun = peripheralToConnect.peripheral
//points the peripheral to its delegate function
self.laserTagGun.delegate = self
self.centralManager.connect(self.laserTagGun)

}
return
}

progress.completedUnitCount += 1


}
}


//function called after manager has found gun

public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
centralManager.stopScan()
//peripheral is gun
print(peripheral)
laserTagGun = peripheral
//centralManager.stopScan()
print("scanning")
if possibleGuns.count == 0 {
possibleGuns.append(Gun(peripheral: peripheral, RSSI: RSSI))
//print(peripheral)
} else {
for gun in possibleGuns {
if gun.peripheral.identifier != peripheral.identifier {
possibleGuns.append(Gun(peripheral: peripheral, RSSI: RSSI))
//print(peripheral)
}
}
}

//points the peripheral to its delegate function
laserTagGun.delegate = self
//peripheral is gun


centralManager.connect(laserTagGun)

}

Expand Down Expand Up @@ -375,7 +419,11 @@ extension BluetoothHandler: CBPeripheralDelegate{
//handleGame.resetHealth()
execute = false
}

case 4:
if networking.gameStarted && !handleGame.isDead {
NFCRead.readNFCTag()
execute = false
}
default:
break
}
Expand Down Expand Up @@ -418,4 +466,8 @@ extension BluetoothHandler: CBPeripheralDelegate{

}

struct Gun {
let peripheral: CBPeripheral
let RSSI: NSNumber
}

Loading

0 comments on commit b676cb5

Please sign in to comment.