Skip to content

Commit

Permalink
Merge pull request #11 from contimatteo/feature/pitch
Browse files Browse the repository at this point in the history
Feature/pitch
  • Loading branch information
contimatteo authored Feb 18, 2020
2 parents 31caeec + 72a5a4d commit eecc115
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 40 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/


# Custom
#
# avoid pitch build

Report/pitch/*.pdf
4 changes: 2 additions & 2 deletions Briscola-Multiplayer/Controllers/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MenuController: UIViewController {
var gameOptions: GameOptions?;

//
// MARK: @
// MARK: @IBOutlet

@IBOutlet weak var localPlayerName: UITextField!
@IBOutlet weak var gameMode: UISegmentedControl!
Expand Down Expand Up @@ -71,7 +71,7 @@ class MenuController: UIViewController {
}

//
// MARK:
// MARK: Events

@objc func localPlayerNameChanged(_ input: UITextField) {
guard let playerName: String = input.text else { return; }
Expand Down
2 changes: 1 addition & 1 deletion Briscola-Multiplayer/Controllers/ResultsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ResultsController: UIViewController {

private func render() {
// button
saveResultButton.isEnabled = !matchResultSaved;
saveResultButton.isHidden = matchResultSaved;

// match result label
var localPlayerMatchResultText: String = "HAI PAREGGIATO!";
Expand Down
7 changes: 4 additions & 3 deletions Briscola-Multiplayer/Libraries/AI-PlayerEmulator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import Foundation


class AIPlayerEmulator {

//
// MARK:
// MARK: Variables

private var trumpCard: CardModel;

Expand All @@ -22,14 +23,14 @@ class AIPlayerEmulator {
private var cardsOnTable: Array<CardModel?> = [];

//
// MARK:
// MARK: Initializers

init(trumpCard: CardModel) {
self.trumpCard = trumpCard;
}

//
// MARK:
// MARK: Methods

func playCard(playerIndex: Int, playersHands: Array<Array<CardModel>>, cardsOnTable: Array<CardModel?>) -> Int {
var cardToPlay: Int?;
Expand Down
8 changes: 4 additions & 4 deletions Briscola-Multiplayer/Libraries/FacebookManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import FBSDKShareKit
class FacebookManager {

//
// MARK:
// MARK: Variables

private var permissions: [String];
private var loginManager: LoginManager;
private var currentUserProfile : [String: Any]?;

//
// MARK:
// MARK: Initializers

init(permissions: [String]) {
self.permissions = permissions;
Expand All @@ -37,7 +37,7 @@ class FacebookManager {
}

//
// MARK
// MARK: Public Methods

func login(from: UIViewController, didCompleteHandler: LoginManagerLoginResultBlock!) {
// self.loginManager.logIn(permissions: self.permissions, from: from, handler: handler);
Expand Down Expand Up @@ -100,7 +100,7 @@ class FacebookManager {
}

//
// MARK
// MARK: Private Methods

private func loginDidComplete(_ result: LoginManagerLoginResult?, error: Error?, didComplete: LoginManagerLoginResultBlock!) {
// error
Expand Down
47 changes: 35 additions & 12 deletions Briscola-Multiplayer/Libraries/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ class SessionManager: NSObject {
return session
}()

var serviceAdvertiser: MCNearbyServiceAdvertiser
var serviceBrowser: MCNearbyServiceBrowser
// MCNearbyServiceAdvertiser: publishes an advertisement for a specific service that
// your app provides through the Multipeer Connectivity framework and notifies its
// delegate about invitations from nearby peers.
var serviceAdvertiser: MCNearbyServiceAdvertiser;

// MCNearbyServiceBrowser: searches (by service type) for services offered by nearby
// devices using infrastructure Wi-Fi, peer-to-peer Wi-Fi, and Bluetooth (in iOS) or Ethernet
// (in macOS and tvOS), and provides the ability to easily invite those devices to a Multipeer
// Connectivity session (MCSession).
var serviceBrowser: MCNearbyServiceBrowser;

// Connected peers are stored in the MCSession
// Manually track connecting and disconnected peers
Expand All @@ -54,7 +62,7 @@ class SessionManager: NSObject {
// MARK: Initializer

override init() {
let kMCSessionServiceType = "mcsessionp2p"
let kMCSessionServiceType = "mcsessionp2p";

// Create the service advertiser
serviceAdvertiser = MCNearbyServiceAdvertiser(peer: peerID, discoveryInfo: nil, serviceType: kMCSessionServiceType)
Expand Down Expand Up @@ -124,16 +132,17 @@ class SessionManager: NSObject {

return send(data);
}


}



//
// MARK: MCSessionDelegate
// MCSessionDelegate: this protocol defines methods that a delegate of the MCSession class
// can implement to handle session-related events.

extension SessionManager: MCSessionDelegate {

// Remote peer changed state.
func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
let displayName = peerID.displayName

Expand All @@ -159,18 +168,23 @@ extension SessionManager: MCSessionDelegate {
delegate?.sessionDidChangeState()
}

// Received data from remote peer.
func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
if (_SESSION_DEBUG_) { NSLog("\(#function) from [\(peerID.displayName)]"); }

delegate?.didReceivedDataFromPeer(data);
}

// UNUSED: Start receiving a resource from remote peer.
func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
if (_SESSION_DEBUG_) {
NSLog("\(#function) \(resourceName) from [\(peerID.displayName)] with progress [\(progress)]");
}
}

// UNUSED: Finished receiving a resource from remote peer and saved the content
// in a temporary location - the app is responsible for moving the file
// to a permanent location within its sandbox.
func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) {
// If error is not nil something went wrong
if (error != nil) {
Expand All @@ -180,22 +194,23 @@ extension SessionManager: MCSessionDelegate {
}
}

// Streaming API not utilized in this sample code
// UNUSED: Received a byte stream from remote peer.
func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {
if (_SESSION_DEBUG_) { NSLog("\(#function) \(streamName) from [\(peerID.displayName)]"); }
}
}



//
// MARK: MCNearbyServiceBrowserDelegate
// MCNearbyServiceBrowserDelegate: this protocol defines methods that a MCNearbyServiceBrowser
// object’s delegate can implement to handle browser-related events.

extension SessionManager: MCNearbyServiceBrowserDelegate {

// Found a nearby advertising peer
// Found a nearby advertising peer.
func browser(_ browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String : String]?) {
let remotePeerName = peerID.displayName

let myPeerID = session.myPeerID

let shouldInvite = (myPeerID.displayName.compare(remotePeerName) == .orderedDescending)
Expand All @@ -210,27 +225,35 @@ extension SessionManager: MCNearbyServiceBrowserDelegate {
delegate?.sessionDidChangeState()
}

// A nearby peer has stopped advertising.
func browser(_ browser: MCNearbyServiceBrowser, lostPeer peerID: MCPeerID) {
if (_SESSION_DEBUG_) { NSLog("\(#function) [\(peerID.displayName)]"); }
}

// Browsing did not start due to an error.
func browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) {
if (_SESSION_DEBUG_) { NSLog("\(#function) \(error)"); }
}
}



//
// MARK: MCNearbyServiceAdvertiserDelegate
// MCNearbyServiceAdvertiserDelegate: this protocol describes the methods that the delegate object
// for an MCNearbyServiceAdvertiser instance can implement for handling events from the
// MCNearbyServiceAdvertiser class.

extension SessionManager: MCNearbyServiceAdvertiserDelegate {

// Incoming invitation request. Call the invitationHandler block with YES
// and a valid session to connect the inviting peer to the session.
func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: Data?, invitationHandler: @escaping (Bool, MCSession?) -> Void) {
if (_SESSION_DEBUG_) { NSLog("\(#function) Accepting invitation from [\(peerID.displayName)]"); }

invitationHandler(true, session)
invitationHandler(true, session);
}

// Advertising did not start due to an error.
func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didNotStartAdvertisingPeer error: Error) {
if (_SESSION_DEBUG_) { NSLog("\(#function) \(error)"); }
}
Expand Down
18 changes: 10 additions & 8 deletions Briscola-Multiplayer/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fCZ-LD-pe1">
<rect key="frame" x="69" y="369" width="183" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fCZ-LD-pe1">
<rect key="frame" x="65" y="368" width="190" height="30"/>
<color key="backgroundColor" systemColor="linkColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="190" id="IhT-a6-VBU"/>
<constraint firstAttribute="height" constant="30" id="wEg-Aw-S9Q"/>
</constraints>
<state key="normal" title="SALVA IL RISULTATO">
Expand Down Expand Up @@ -273,8 +274,8 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" text="PUNTEGGIO AVVERSARIO" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jlv-S4-H4Q">
<rect key="frame" x="59" y="167" width="203" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PUNTEGGIO AVVERSARIO" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jlv-S4-H4Q">
<rect key="frame" x="58.5" y="166" width="203" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="P8c-F3-yCd"/>
</constraints>
Expand Down Expand Up @@ -308,6 +309,7 @@
<constraint firstAttribute="centerX" secondItem="fCZ-LD-pe1" secondAttribute="centerX" id="c3q-xP-xXU"/>
<constraint firstItem="YXi-bq-mxz" firstAttribute="top" secondItem="eYY-Px-mD1" secondAttribute="bottom" constant="15" id="mG4-iv-SUt"/>
<constraint firstItem="sbe-zy-Ca8" firstAttribute="bottom" secondItem="czb-0p-3LY" secondAttribute="bottom" constant="42" id="qaT-zL-cNa"/>
<constraint firstItem="Jlv-S4-H4Q" firstAttribute="centerX" secondItem="jN5-3L-72x" secondAttribute="centerX" id="rjw-oy-EZv"/>
</constraints>
<viewLayoutGuide key="safeArea" id="sbe-zy-Ca8"/>
</view>
Expand Down Expand Up @@ -352,7 +354,7 @@
<segue destination="NOz-NJ-38e" kind="show" identifier="showSocialView" id="51h-ve-b8L"/>
</connections>
</button>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Inserisci il tuo nome" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="P2P-g5-l80">
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="il tuo nome" borderStyle="roundedRect" placeholder="Inserisci il tuo nome" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="P2P-g5-l80">
<rect key="frame" x="60" y="86" width="200" height="25"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="3D5-zT-Uef"/>
Expand Down Expand Up @@ -416,7 +418,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="n3i-rn-3Kr">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="n3i-rn-3Kr">
<rect key="frame" x="208" y="325" width="52" height="25"/>
<constraints>
<constraint firstAttribute="width" constant="50" id="O2l-ot-ukr"/>
Expand All @@ -433,7 +435,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OzO-Tt-uAr">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="OzO-Tt-uAr">
<rect key="frame" x="58" y="325" width="52" height="25"/>
<constraints>
<constraint firstAttribute="width" constant="50" id="4TS-oV-JDs"/>
Expand All @@ -460,7 +462,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ya7-82-pLc">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="ya7-82-pLc">
<rect key="frame" x="135" y="395" width="52" height="25"/>
<constraints>
<constraint firstAttribute="width" constant="50" id="Hwt-cb-JQX"/>
Expand Down
2 changes: 1 addition & 1 deletion Briscola-Multiplayer/Utilities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct CONSTANTS {

static let REMOTE_PLAYER_NAME: String = "avversario";
static let EMULATOR_PLAYER_NAME: String = "avversario";
static let LOCAL_PLAYER_NAME: String = "TU";
static let LOCAL_PLAYER_NAME: String = "TU"; // unused

static let APP_GITHUB_REPOSITORY_LINK: String = "https://github.com/contimatteo/Briscola";

Expand Down
15 changes: 7 additions & 8 deletions Briscola-Multiplayer/Utilities/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ import MultipeerConnectivity


//
// MARK: MCSession
// MARK: MCSession (extension)

extension MCSession {

// Gets the string for a peer connection state
//
// - parameter state: Peer connection state, an MCSessionState enum value
// - returns: String for peer connection state
//
class func stringForPeerConnectionState(_ state: MCSessionState) -> String {
switch state {
case .connecting:
return "Connecting"
return "Connecting";

case .connected:
return "Connected"
return "Connected";

case .notConnected:
return "Not Connected"
return "Not Connected";

@unknown default:
return "Uknown state"
return "Uknown state";
}

}

}
9 changes: 8 additions & 1 deletion Briscola-Multiplayer/Utilities/SessionObjects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import Foundation

//
// MARK: Session
// MARK: - SS_InitObj

class SS_InitObj: NSObject, NSCoding {

var cardsDeck: [String]!;
var senderPlayerIndex: Int!;
var senderPlayerName: String!;
Expand Down Expand Up @@ -48,9 +49,14 @@ class SS_InitObj: NSObject, NSCoding {
static func fromData(_ data: Data) -> SS_InitObj? {
return NSKeyedUnarchiver.unarchiveObject(with: data) as? SS_InitObj;
}

}

//
// MARK: - SS_CardPlayed

class SS_CardPlayed: NSObject, NSCoding {

var type: String!;
var number: Int!;
var senderPlayerIndex: Int!;
Expand Down Expand Up @@ -87,4 +93,5 @@ class SS_CardPlayed: NSObject, NSCoding {
static func fromData(_ data: Data) -> SS_CardPlayed? {
return NSKeyedUnarchiver.unarchiveObject(with: data) as? SS_CardPlayed;
}

}
Binary file modified Report/pitch/Conti Matteo - 0000802576.key
Binary file not shown.

0 comments on commit eecc115

Please sign in to comment.