Exemplo n.º 1
0
    public void TestStoreItems()
    {
        // Simulate the flow for RequestItemsList.
        bool storeItemsReceived = false;

        KongregateWeb.StoreItemsReceived += items =>
        {
            storeItemsReceived = true;
            Assert.AreEqual(
                new StoreItem[]
            {
                new StoreItem(
                    123,
                    "cool_item",
                    "Cool Item",
                    "An item that is cool",
                    170,
                    new string[] { "tag" },
                    "https://example.com/image.png"),
            },
                items);
        };

        KongregateWeb.RequestItemList();
        _kongWebInstance.SendMessage("OnItemList", StoreItemJson);
        Assert.IsTrue(storeItemsReceived);
    }
Exemplo n.º 2
0
 private void OnDestroy()
 {
     if (_instance == this)
     {
         _instance = null;
     }
 }
Exemplo n.º 3
0
        public void Purchase(ProductDefinition product, string developerPayload)
        {
            Debug.Assert(
                _pendingProducts == null,
                "Attempting to make a purchase while updating store products");

            _pendingPurchase = product;
            KongregateWeb.PurchaseItems(new string[] { product.id });
        }
Exemplo n.º 4
0
        void OnPurchaseSuccess(string[] items)
        {
            if (_pendingPurchase == null)
            {
                Debug.LogErrorFormat(
                    "Received purchase success notification when no purchase was in progress: {0}",
                    string.Join(", ", items));
                return;
            }

            // When the purchase succeeds, request an updated list of user items from
            // Kongregate. The purchase items flow doesn't return the metadata for the
            // purchased item, so we need to request the items ourself to finish the
            // purchase flow.
            KongregateWeb.RequestUserItemList();
        }
Exemplo n.º 5
0
    private void Awake()
    {
        // Only allow one instance of the API bridge.
        if (_instance != null)
        {
            UnityEngine.Debug.LogWarning("Removing duplicate Kongregate API GameObject, only one may be active at a time");
            Destroy(gameObject);
            return;
        }

        // Make this object the current instance and ensure that it isn't destroyed
        // on scene loads.
        _instance = this;
        DontDestroyOnLoad(gameObject);

        initKongregateAPI(name);
    }
Exemplo n.º 6
0
    public void TestUserItems()
    {
        bool userItemsRecieved = false;

        KongregateWeb.UserItemsReceived += items =>
        {
            userItemsRecieved = true;
            Assert.AreEqual(
                new UserItem[]
            {
                new UserItem(123, "cool_item", "some metadata goes here", 1),
            },
                items);
        };

        KongregateWeb.RequestUserItemList();
        _kongWebInstance.SendMessage("OnUserItems", UserItemJson);
        Assert.IsTrue(userItemsRecieved);
    }
Exemplo n.º 7
0
        public void RetrieveProducts(ReadOnlyCollection <ProductDefinition> products)
        {
            Debug.Assert(
                _pendingPurchase == null,
                "Attempting to update store products while purchase is in progress");

            _pendingProducts = products;

            // Wait for the API to become ready, then request the list of store items
            // and the user's items.
            //
            // NOTE: BecameReady is invoked immediately if the API is already ready, so
            // the callback will still be invoked even if the API is already ready.
            KongregateWeb.BecameReady += () =>
            {
                KongregateWeb.RequestItemList();
                KongregateWeb.RequestUserItemList();
            };
        }