示例#1
0
    /*
     *
     *  Execute a PlayFab Cloud Script function to update the group entity object data to the
     *  updated CSV. Title-level data should not be changed directly from the client.
     *
     *  @param dataobj: the updated CSV; the Cloud Script function sets the entity group object data to
     *      this value.
     *  @param item_id: ItemID of the item that was either added or removed
     *
     */

    private void UpdateGroupObject(string dataobj, bool adding_item, string item_id)
    {
        /* Call a Cloud Script function to update the group entity object data */
        PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new PlayFab.CloudScriptModels.ExecuteEntityCloudScriptRequest()
        {
            // Group entity on which we call Cloud Script function
            Entity = new PlayFab.CloudScriptModels.EntityKey {
                Id = WishList.group_entityKeyId, Type = WishList.group_entityKeyType
            },
            // Cloud Script function name
            FunctionName = "addItemtoWishlist",
            // Function parameters for Cloud Script function; prop1 is the updated CSV
            FunctionParameter = new { prop1 = dataobj },
            // Create a Playstream event, which can be found in Game Manager; helpful for debugging and logging
            GeneratePlayStreamEvent = true
        }, result => {
            /* The Cloud Script function returned successfully, so we must update the store in our Unity game. */
            if (adding_item)
            {
                /* The item with ItemID item_id was added, so update store accordingly. */
                StoreSetup.SetUpStore(item_id, false);
            }
            else
            {
                /* The item with ItemID item_id was removed, so update store accordingly. */
                StoreSetup.SetUpStore(item_id, true);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#2
0
    /*
     *  Find the entity group for the player's wish list, or create one if does not exist
     *
     *  @param player_entityKeyId: the entity ID of the player; for a title entity the ID should be;
     *      in most cases, this can be found in LoginResult.EntityToken.Entity.Id
     *  @param player_entityKeyType: the entity type of the player whose wish list we are searching
     *      for; should be title_player_account entity in most cases
     *
     */

    public static void FindOrCreateWishList(string player_entityKeyId, string player_entityKeyType)
    {
        PlayFab.DataModels.EntityKey ent = new PlayFab.DataModels.EntityKey {
            Id = player_entityKeyId, Type = player_entityKeyType
        };

        var req = new PlayFab.DataModels.GetObjectsRequest {
            Entity = ent
        };

        PlayFabDataAPI.GetObjects(req, result => {
            if (!result.Objects.ContainsKey("wishlist"))
            {
                // Empty so need to create
                CreateEntityWishList();
            }
            else
            {
                string wl = (string)result.Objects["wishlist"].DataObject;

                // Exists so can set up store
                StoreSetup.SetUpStore(wl, false);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#3
0
 private IObservableStore <State> CreateStore(LoggingMiddlewareOptions options)
 {
     return(StoreSetup.CreateStore <State>()
            .FromReducer(Reducers.PassThrough)
            .UsingLoggingMiddleware(_loggerFactory, options)
            .Build());
 }
示例#4
0
    /*
     *
     *  Execute a PlayFab Cloud Script function to update the group entity object data to the
     *  updated CSV. Title-level data should not be changed directly from the client.
     *
     *  @param dataobj: the updated CSV; the Cloud Script function sets the entity group object data to
     *      this value.
     *  @param item_id: ItemID of the item that was either added or removed
     *
     */

    private void UpdateObject(string dataobj, bool adding_item, string item_id)
    {
        PlayFab.DataModels.EntityKey entity = new PlayFab.DataModels.EntityKey {
            Id = LoginClass.getPlayerEntityKeyId(), Type = LoginClass.getPlayerEntityKeyType()
        };

        List <PlayFab.DataModels.SetObject> ObjList = new List <PlayFab.DataModels.SetObject>();

        ObjList.Add(

            new PlayFab.DataModels.SetObject {
            ObjectName = "wishlist",
            DataObject = dataobj
        }

            );

        var request = new PlayFab.DataModels.SetObjectsRequest {
            Entity  = entity,
            Objects = ObjList
        };

        PlayFabDataAPI.SetObjects(request, result => {
            if (adding_item)
            {
                StoreSetup.SetUpStore(item_id, false);
            }
            else
            {
                StoreSetup.SetUpStore(item_id, true);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#5
0
 internal void Store_Construction_Should_Throw_If_Any_Middleware_Is_Null()
 {
     Should.Throw <ArgumentException>(
         () => StoreSetup.CreateStore <State>()
         .FromReducer(Reducers.PassThrough)
         .UsingMiddleware(Mock.Middleware.IncrementInt, null)
         .Build());
 }
示例#6
0
 internal void Store_Construction_Should_Throw_For_Null_Middleware_Collection()
 {
     Should.Throw <ArgumentNullException>(
         () => StoreSetup.CreateStore <State>()
         .FromReducer(Reducers.PassThrough)
         .UsingMiddleware(null)
         .Build());
 }
示例#7
0
        internal void Store_Should_Have_Provided_Initial_State_After_Construction(State initialState)
        {
            var store = StoreSetup.CreateStore <State>()
                        .FromReducer(Reducers.Replace)
                        .WithInitialState(initialState)
                        .Build();

            store.State.ShouldBe(initialState);
        }
示例#8
0
        internal void Subscribers_Implementing_IStoreSubscriber_Should_Receive_Store_On_Subscription()
        {
            var store = StoreSetup.CreateStore <State>()
                        .FromReducer(Reducers.Replace)
                        .WithInitialState(new State(1, true))
                        .Build();

            var subscriber = new Subscriber();

            store.Subscribe(subscriber);
            subscriber.Store.ShouldBe(store);
        }
示例#9
0
        internal void Store_Should_Pass_Dispatched_Actions_Through_Middleware_Before_Reducing()
        {
            var initialState = new State(0, false);
            var middleware   = new Middleware <State>[] { Mock.Middleware.IncrementInt, Mock.Middleware.NegateBool };
            var store        = StoreSetup.CreateStore <State>()
                               .FromReducer(Reducers.Replace)
                               .WithInitialState(initialState)
                               .UsingMiddleware(middleware)
                               .Build();

            store.Dispatch(new ChangeInt(1));
            store.State.IntProperty.ShouldBe(2);

            store.Dispatch(new ChangeBool(false));
            store.State.BoolProperty.ShouldBe(true);
        }
示例#10
0
        internal void Store_Should_Concatenate_Middleware_If_Multiple_Sets_Provided_During_Construction()
        {
            var initialState = new State(0, false);
            var store        = StoreSetup.CreateStore <State>()
                               .FromReducer(Reducers.Replace)
                               .WithInitialState(initialState)
                               .UsingMiddleware(Mock.Middleware.IncrementInt)
                               .UsingMiddleware(Mock.Middleware.NegateBool)
                               .Build();

            store.Dispatch(new ChangeInt(1));
            store.State.IntProperty.ShouldBe(2);

            store.Dispatch(new ChangeBool(false));
            store.State.BoolProperty.ShouldBe(true);
        }
示例#11
0
        internal async Task Store_Should_Apply_Actions_In_Order_Of_Dispatch(
            State initialState,
            object[] actions,
            State expectedFinalState)
        {
            var store = StoreSetup.CreateStore <State>()
                        .FromReducer(Reducers.Replace)
                        .WithInitialState(initialState)
                        .Build();

            foreach (var action in actions)
            {
                await store.Dispatch(action);
            }

            store.State.ShouldBe(expectedFinalState);
        }
示例#12
0
    /*
     *  Upon successful login, set up the store for our game and find the user's wish list.
     *
     *  @param result: the PlayFab LoginResult object which occurs upon a successful call to LoginWithPlayFab
     *
     *  When the player clicks the button to log in, the Client calls LoginWithPlayFabRequest to return
     *  the login token. Authenticate the client in order to call other PlayFab Client APIs.
     *
     */

    private void OnLoginSuccess(LoginResult result)
    {
        LoginClass.player_entityKeyId   = result.EntityToken.Entity.Id;
        LoginClass.player_entityKeyType = result.EntityToken.Entity.Type;

        PlayFab.GroupsModels.EntityKey entity = new PlayFab.GroupsModels.EntityKey {
            Id = LoginClass.player_entityKeyId, Type = LoginClass.player_entityKeyType
        };

        var request = new ListMembershipRequest {
            Entity = entity
        };

        /* Set up the store buttons for the Unity game. This will change depending on the nature of your game. */

        StoreSetup.StoreStart();

        /* Now that the player has logged in, find their wish list. If not found, create it. */

        WishList.FindOrCreateWishList(LoginClass.player_entityKeyId, LoginClass.player_entityKeyType);
    }
示例#13
0
        internal async Task Middleware_Should_Be_Configurable_To_Log_Next_State_After_Dispatch()
        {
            // Given: a store which is configured to use logging middleware.
            var options = LoggingMiddlewareOptions.Default;

            options.LogAtStart     = false;
            options.LogElapsedTime = false;
            options.LogNextState   = true;

            var store = StoreSetup.CreateStore <State>()
                        .FromReducer(Reducers.Replace)
                        .WithInitialState(new State(0, false))
                        .UsingLoggingMiddleware(_loggerFactory, options)
                        .Build();

            // When: we dispatch an action to change the state.
            await store.Dispatch(new ChangeInt(5));

            // Then: the new state resulting from the action should have been logged.
            var expectedNextState = new State(5, false);

            _logs.ShouldHaveSingleItem().ShouldContain(expectedNextState.ToString());
        }
示例#14
0
    /*
     *  Find the entity group for the player's wish list, or create one if does not exist
     *
     *  @param player_entityKeyId: the entity ID of the player; for a title entity the ID should be;
     *      in most cases, this can be found in LoginResult.EntityToken.Entity.Id
     *  @param player_entityKeyType: the entity type of the player whose wish list we are searching
     *      for; should be title_player_account entity in most cases
     *
     *  Upon login, this function examines all entity groups that the player belongs to. For each group,
     *  the group name is compared to the nomenclature for wish list groups. If the group is not found,
     *  then one is created
     */

    public static void FindOrCreateWishList(string player_entityKeyId, string player_entityKeyType)
    {
        /* Create entity key for the ListMembership request */

        PlayFab.GroupsModels.EntityKey entity = new PlayFab.GroupsModels.EntityKey {
            Id = player_entityKeyId, Type = player_entityKeyType
        };

        var request = new ListMembershipRequest {
            Entity = entity
        };

        PlayFabGroupsAPI.ListMembership(request, membershipResult => {
            bool found = false; // Will tell us whether the wish list entity group exists

            /*
             *  Iterate through all groups the player belongs to. If the wish list entity group exists,
             *  it should be one of these groups
             */

            for (int i = 0; i < membershipResult.Groups.Count; i++)
            {
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";

                /* Compare the name of the group to the nomenclature the wish list entity group name will follow */

                if (membershipResult.Groups[i].GroupName.Equals(group_name))
                {
                    found = true; // If the name matches, we found the wish list entity group

                    /* Set the wish list group's entity ID and entity type so we can access the group in other functions */
                    WishList.group_entityKeyId   = membershipResult.Groups[i].Group.Id;
                    WishList.group_entityKeyType = membershipResult.Groups[i].Group.Type;

                    PlayFab.DataModels.EntityKey group_ek = new PlayFab.DataModels.EntityKey {
                        Id = membershipResult.Groups[i].Group.Id, Type = membershipResult.Groups[i].Group.Type
                    };
                    GetObjectsRequest getObjectsRequest = new GetObjectsRequest {
                        Entity = group_ek
                    };

                    /*  This is the wish list entity group. To get the wish list CSV, we need to get the object in that entity
                     *  group with the "wishlist" key
                     */

                    PlayFabDataAPI.GetObjects(getObjectsRequest, objectResult => {
                        if (!string.IsNullOrEmpty((string)objectResult.Objects["wishlist"].DataObject))
                        {
                            string wl = (string)objectResult.Objects["wishlist"].DataObject;
                            /* Set up the Unity game store. Specifically, change colors and button text if an item is on the wishlist */
                            StoreSetup.SetUpStore(wl, false);
                        }
                    }, error => { Debug.LogError(error.GenerateErrorReport()); });
                }
            }

            // AddPlayFabIdToGroup(); // Where should this go?


            /* Wish list entity group does not exist, so create one */
            if (!found)
            {
                /*
                 *  Wish list entity groups should follow the following nomenclature:
                 *  [PlayFab title ID] + "wishlist.
                 *
                 *  This nomenclature allows us to find the group by name in the future.
                 */
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";
                CreateWishlist(group_name);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#15
0
 internal void Store_Construction_Should_Throw_If_Reducer_Is_Not_Specified()
 {
     Should.Throw <InvalidOperationException>(() => StoreSetup.CreateStore <State>().Build());
 }
示例#16
0
 /// <inheritdoc />
 public ObservableStoreSpec()
 {
     _store = StoreSetup.CreateStore <State>()
              .FromReducer(Reducers.PassThrough)
              .Build();
 }
示例#17
0
 protected void OpenSetupModal()
 {
     StoreSetup.OpenModal();
 }