Beispiel #1
0
    /** Private functions **/
    /**
     * Transforms given JSONObject to StoreInfo
     *
     * @param JSONObject
     * @throws JSONException
     */
    private static void fromJSONObject(JSONObject JSONObject) {

        mVirtualItems = new Dictionary<String, VirtualItem>();
        mPurchasableItems = new Dictionary<String, PurchasableVirtualItem>();
        mGoodsCategories = new Dictionary<String, VirtualCategory>();
        mGoodsUpgrades = new Dictionary<String, List<UpgradeVG>>();
        mCurrencyPacks = new List<VirtualCurrencyPack>();
        mGoods = new List<VirtualGood>();
        mCategories = new List<VirtualCategory>();
        mCurrencies = new List<VirtualCurrency>();
        //mNonConsumables = new List<NonConsumableItem>();
        if (JSONObject.HasField(StoreJSONConsts.STORE_CURRENCIES)) {
            JSONObject virtualCurrencies = JSONObject[StoreJSONConsts.STORE_CURRENCIES];
            for (int i=0; i<virtualCurrencies.Count; i++){
                JSONObject o = virtualCurrencies[i];
                VirtualCurrency c = new VirtualCurrency(o);
                mCurrencies.Add(c);

                mVirtualItems.Add(c.getItemId(), c);
            }
        }

        if (JSONObject.HasField(StoreJSONConsts.STORE_CURRENCYPACKS)) {
            JSONObject currencyPacks = JSONObject[StoreJSONConsts.STORE_CURRENCYPACKS];
            for (int i=0; i<currencyPacks.Count; i++){
                JSONObject o = currencyPacks[i];
                VirtualCurrencyPack pack = new VirtualCurrencyPack(o);
                mCurrencyPacks.Add(pack);

                mVirtualItems.Add(pack.getItemId(), pack);

                PurchaseType purchaseType = pack.GetPurchaseType();
                if (purchaseType is PurchaseWithMarket) {
                    mPurchasableItems.Add(((PurchaseWithMarket) purchaseType)
                            .getMarketItem().getProductId(), pack);
                }
            }
        }

        // The order in which VirtualGoods are created matters!
        // For example: VGU and VGP depend on other VGs
        if (JSONObject.HasField(StoreJSONConsts.STORE_GOODS)) {
            JSONObject virtualGoods = JSONObject[StoreJSONConsts.STORE_GOODS];
            if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_SU)) {
                JSONObject suGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_SU];
                for (int i=0; i<suGoods.Count; i++){
                    JSONObject o = suGoods[i];
                    SingleUseVG g = new SingleUseVG(o);
                    addVG(g);
                }
            }


            if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_LT)) {
                JSONObject ltGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_LT];
                for (int i=0; i<ltGoods.Count; i++){
                    JSONObject o = ltGoods[i];
                    LifetimeVG g = new LifetimeVG(o);
                    addVG(g);
                }
            }


            if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_EQ)) {
                JSONObject eqGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_EQ];
                for (int i=0; i<eqGoods.Count; i++){
                    JSONObject o = eqGoods[i];
                    EquippableVG g = new EquippableVG(o);
                    addVG(g);
                }
            }

            if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_PA)) {
                JSONObject paGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_PA];
                for (int i=0; i<paGoods.Count; i++){
                    JSONObject o = paGoods[i];
                    SingleUsePackVG g = new SingleUsePackVG(o);
                    addVG(g);
                }
            }


            if (virtualGoods.HasField(StoreJSONConsts.STORE_GOODS_UP)) {
                JSONObject upGoods = virtualGoods[StoreJSONConsts.STORE_GOODS_UP];
                for (int i=0; i<upGoods.Count; i++){
                    JSONObject o = upGoods[i];
                    UpgradeVG g = new UpgradeVG(o);
                    addVG(g);

                    List<UpgradeVG> upgrades = mGoodsUpgrades[g.getGoodItemId()];
                    if (upgrades == null) {
                        upgrades = new List<UpgradeVG>();
                        mGoodsUpgrades.Add(g.getGoodItemId(), upgrades);
                    }
                    upgrades.Add(g);
                }
            }

        }

        // Categories depend on virtual goods. That's why the have to be initialized after!
        if (JSONObject.HasField(StoreJSONConsts.STORE_CATEGORIES)) {
            JSONObject virtualCategories = JSONObject[StoreJSONConsts.STORE_CATEGORIES];
            for(int i=0; i<virtualCategories.Count; i++){
                JSONObject o = virtualCategories[i];
                VirtualCategory category = new VirtualCategory(o);
                mCategories.Add(category);
                foreach(String goodItemId in category.getGoodsItemIds()) {
                    mGoodsCategories.Add(goodItemId, category);
                }
            }
        }
        /*
        if (JSONObject.TryGetValue(StoreJSONConsts.STORE_NONCONSUMABLES, out value)) {
            JSONObject nonConsumables = JSONObject.Value<JSONObject>(StoreJSONConsts.STORE_NONCONSUMABLES);
            for (int i=0; i<nonConsumables.Count; i++){
                JSONObject o = nonConsumables.Value<JSONObject>(i);
                NonConsumableItem non = new NonConsumableItem(o);
                mNonConsumables.Add(non);

                mVirtualItems.Add(non.getItemId(), non);

                PurchaseType purchaseType = non.GetPurchaseType();
                if (purchaseType is PurchaseWithMarket) {
                    mPurchasableItems.Add(((PurchaseWithMarket) purchaseType)
                            .getMarketItem().getProductId(), non);
                }
            }
        }*/
    }