Esempio n. 1
0
    //associates clientCollection to meteor's client document
    IEnumerator CreateClientDoc(string recordGroupName)
    {
        clientCollection = Meteor.Collection <ClientTemplate> .Create(recordGroupName);         //creates meteor collection

        yield return(clientCollection);

        /* Handler for knowing our client's color */

        clientCollection.DidAddRecord += (string id, ClientTemplate document) => {
            Debug.LogError(string.Format("Client document added:\n{0}", document.Serialize()));
        };
    }
Esempio n. 2
0
    //collection of gameObjects
    public IEnumerator CreateGameObjectCollection()
    {
        gameObjectCollection = Meteor.Collection <DatabaseEntry> .Create("gameObjects");

        yield return(gameObjectCollection);
        /* Handler for debugging the addition of gameObjects: */

        /*
         * gameObjectCollection.DidAddRecord += (string id, DatabaseEntry document) => {
         *      Debug.LogError(string.Format("gameObject document added:\n{0}", document.Serialize()));
         * };
         */
    }
Esempio n. 3
0
    //associates playerCollection with meteor's session document
    IEnumerator CreatePlayerDoc(string recordGroupName)         //
    {
        playerCollection = Meteor.Collection <PlayerTemplate> .Create(recordGroupName);

        yield return(playerCollection);         //waits until collection is finished being created
        /* Add handler for debugging session adds: */

        /*
         * playerCollection.DidAddRecord += (string id, PlayerTemplate document) => {
         *      Debug.Log(string.Format("Player document added:\n{0}", document.Serialize()));
         * };
         */
    }
Esempio n. 4
0
    //associates channelCollection with meteor's channel document
    IEnumerator CreateChannelDoc(string recordGroupName)
    {
        channelCollection = Meteor.Collection <ChannelTemplate> .Create(recordGroupName);

        yield return(channelCollection);        //waits until collection is finished being created
        /* Add handler for debugging channel adds: */

        /*
         * channelCollection.DidAddRecord += (string id, ChannelTemplate document) => {
         *      Debug.Log(string.Format("Channel document added:\n{0}", document.Serialize()));
         * };
         */
    }
Esempio n. 5
0
    //associates sessionCollection to meteor's sessions document
    IEnumerator CreateSessionDoc(string recordGroupName)
    {
        sessionCollection = Meteor.Collection <SessionTemplate> .Create(recordGroupName); //creates meteor collection

        yield return(sessionCollection);                                                  //waits until collection is finished being created
        /* Add handler for debugging session adds: */

        /*
         * sessionCollection.DidAddRecord += (string id, SessionTemplate document) => {
         *      Debug.LogError(string.Format("Session document added:\n{0}", document.Serialize()));
         *      };
         * sessionCollection.DidChangeRecord += (string arg1, ChannelTemplate arg2, IDictionary arg3, string[] arg4) => {
         *      Debug.Log ("Session document CHANGED: " + arg2.Serialize());
         *      };
         */
    }
Esempio n. 6
0
    //collection of gameObjects
    public IEnumerator CreateGameObjectCollection()
    {
        gameObjectCollection = Meteor.Collection <DatabaseEntry> .Create("gameObjects");

        yield return(gameObjectCollection);

        /* Handler for debugging the addition of gameObjects: */

        /*
         * gameObjectCollection.DidAddRecord += (string id, DatabaseEntry document) => {
         *      Debug.LogError(string.Format("gameObject document added:\n{0}", document.Serialize()));
         * };
         */
        Debug.LogError("adding record change handler(s)");
        gameObjectCollection.DidChangeRecord += GetComponent <GameManager>().HandleDidChangeRecord;
        gameObjectCollection.DidAddRecord    += GetComponent <GameManager>().HandleDidAddRecord;
        gameObjectCollectionCreated           = true;
    }
    //collection of gameObjects
    public IEnumerator CreateMeteorCollection()
    {
        var methodCall = Meteor.Method <ChannelResponse> .Call("createGameObjectCollection", this.sessionID, collectionKey);

        yield return((Coroutine)methodCall);


        var initMethodCall = Meteor.Method <ChannelResponse> .Call("initGameObjectCollections", collectionKey);

        yield return((Coroutine)initMethodCall);


        var subscription = Meteor.Subscription.Subscribe("gameObjectCollection", collectionKey);

        yield return((Coroutine)subscription);          //wait until subscription successful


        mongoCollection = Meteor.Collection <TMongoDocument> .Create(this.collectionKey);

        yield return(mongoCollection);

        mongoCollection.DidAddRecord += (string arg1, TMongoDocument arg2) => {
            //we only need to bind the record if the object was created by Tabletop and hasn't been bound.
            try {
                bindRecord(arg2);
            }
            catch (KeyNotFoundException e) {
                Debug.Log("didn't find the record guid, assuming dont have to bind (object wasn't in the unbound things)");
            }
        };

        mongoCollection.DidRemoveRecord += (string obj) => {
            PrizmRecord <TMongoDocument> record = this.LookUpPrizmRecordBy_ID(obj);
            if (record != null)
            {
                record.WasRemovedByServer = true;
            }
            else
            {
                Debug.Log("record wasn't associated with us");
            }
//			if (record != null) CoroutineHost.Instance.StartCoroutine (RemoveRecord(record));
        };
    }
Esempio n. 8
0
    //associates playerCollection to meteor's channel document
    IEnumerator CreatePlayerDoc(string recordGroupName)
    {
        playerCollection = Meteor.Collection <PlayerTemplate> .Create(recordGroupName); //creates meteor collection

        yield return(playerCollection);                                                 //waits until collection is finished being created

        /* Add handler for debugging channel adds: */

        /*
         * playerCollection.DidAddRecord += (string id, ChannelTemplate document) => {
         *      Debug.LogError(string.Format("Player document added:\n{0}", document.Serialize()));
         *      };
         */

        //triggered when player receives their color from the tabletop
        //this changes the UI of the chip
        Debug.Log("recordchangehandler added for player");
        playerCollection.DidChangeRecord += (string arg1, PlayerTemplate arg2, IDictionary arg3, string[] arg4) => {
            Debug.Log("record changed in playerCollection, the change is: " + arg2._id + ", but our ID is : " + playerID);
            if (arg2._id == playerID)
            {
                /*
                 * Debug.Log ("showing the player's token now");
                 *
                 * //set color to the same one as on tabletop
                 * color = (PlayerColor.color)System.Enum.Parse(typeof(PlayerColor.color), arg2.color);
                 * string colorName = color.ToString();
                 * Transform foundColor = GameObject.Find("PlayerCircle").transform.FindChild(colorName).transform;
                 * if (foundColor)
                 * {
                 *      foundColor.gameObject.SetActive(true);
                 * }
                 */

                //creates client document and opens channels
                if (arg2.sessionID != null)
                {
                    sessionID = arg2.sessionID;
                    Debug.Log("sessionID set: " + sessionID);
                    StartCoroutine(OpenSession(sessionName));
                }
            }
        };
    }