bool CCCoreEventDispatcher::init() { if (!CCAbstractAggregatedEventHandler::init()) { return false; } CCSoomlaEventDispatcher *eventDispatcher = CCSoomlaEventDispatcher::getInstance(); eventDispatcher->registerEventHandler(CCCoreConsts::EVENT_REWARD_GIVEN, [this](__Dictionary *parameters) { __String *rewardId = dynamic_cast<__String *>(parameters->objectForKey("reward")); CC_ASSERT(rewardId); CCReward *reward = CCReward::getReward(rewardId); CC_ASSERT(reward); this->onRewardGivenEvent(reward); }); eventDispatcher->registerEventHandler(CCCoreConsts::EVENT_REWARD_TAKEN, [this](__Dictionary *parameters) { __String *rewardId = dynamic_cast<__String *>(parameters->objectForKey("reward")); CC_ASSERT(rewardId); CCReward *reward = CCReward::getReward(rewardId); CC_ASSERT(reward); this->onRewardTakenEvent(reward); }); eventDispatcher->registerEventHandler(CCCoreConsts::EVENT_CUSTOM, [this](__Dictionary *parameters) { __String *name = dynamic_cast<__String *>(parameters->objectForKey("name")); CC_ASSERT(name); __Dictionary *extra = dynamic_cast<__Dictionary *>(parameters->objectForKey("extra")); CC_ASSERT(extra); this->onCustomEvent(name, extra); }); return true; }
bool CCCoreEventDispatcher::init() { CCSoomlaEventDispatcher* eventDispatcher = CCSoomlaEventDispatcher::getInstance(); eventDispatcher->registerEventHandler( CCCoreConsts::EVENT_REWARD_GIVEN, [this](const ValueMap& parameters) { auto&& rewardId = parameters.at(CCCoreConsts::DICT_ELEMENT_REWARD).asString(); CCReward* reward = CCReward::getReward(rewardId); this->onRewardGivenEvent(reward); }); eventDispatcher->registerEventHandler( CCCoreConsts::EVENT_REWARD_TAKEN, [this](const ValueMap& parameters) { auto&& rewardId = parameters.at(CCCoreConsts::DICT_ELEMENT_REWARD).asString(); CCReward* reward = CCReward::getReward(rewardId); this->onRewardTakenEvent(reward); }); eventDispatcher->registerEventHandler( CCCoreConsts::EVENT_CUSTOM, [this](const ValueMap& parameters) { auto&& name = parameters.at(CCCoreConsts::DICT_ELEMENT_NAME).asString(); auto& extra = parameters.at(CCCoreConsts::DICT_ELEMENT_EXTRA).asValueMap(); this->onCustomEvent(name, extra); }); return true; }
bool CCProfileEventDispatcher::init() { if (!CCAbstractAggregatedEventHandler::init()) { return false; } CCSoomlaEventDispatcher *eventDispatcher = CCSoomlaEventDispatcher::getInstance(); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_PROFILE_INITIALIZED, [this](__Dictionary *parameters) { this->onProfileInitialized(); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_USER_RATING, [this](__Dictionary *parameters) { this->onUserRatingEvent(); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_LOGIN_CANCELLED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); this->onLoginCancelledEvent(CCProvider(provider->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_LOGIN_FAILED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __String *errorDescription = dynamic_cast<__String *>(parameters->objectForKey("errorDescription")); this->onLoginFailed(CCProvider(provider->getValue()), errorDescription); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_LOGIN_FINISHED, [this](__Dictionary *parameters) { CCUserProfile *userProfile = this->extractUserProfile(parameters->objectForKey("userProfile")); this->onLoginFinished(userProfile); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_LOGIN_STARTED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); this->onLoginStarted(CCProvider(provider->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_LOGOUT_FAILED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __String *errorDescription = dynamic_cast<__String *>(parameters->objectForKey("errorDescription")); this->onLogoutFailed(CCProvider(provider->getValue()), errorDescription); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_LOGOUT_FINISHED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); this->onLogoutFinished(CCProvider(provider->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_LOGOUT_STARTED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); this->onLogoutStarted(CCProvider(provider->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_GET_CONTACTS_FAILED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __String *errorDescription = dynamic_cast<__String *>(parameters->objectForKey("errorDescription")); this->onGetContactsFailed(CCProvider(provider->getValue()), errorDescription); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_GET_CONTACTS_FINISHED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __Array *contacts = this->extractUserProfileArray(parameters->objectForKey("contacts")); this->onGetContactsFinished(CCProvider(provider->getValue()), contacts); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_GET_CONTACTS_STARTED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); this->onGetContactsStarted(CCProvider(provider->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_GET_FEED_FAILED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __String *errorDescription = dynamic_cast<__String *>(parameters->objectForKey("errorDescription")); this->onGetFeedFailed(CCProvider(provider->getValue()), errorDescription); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_GET_FEED_FINISHED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __Array *feed = dynamic_cast<__Array *>(parameters->objectForKey("feed")); this->onGetFeedFinished(CCProvider(provider->getValue()), feed); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_GET_FEED_STARTED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); this->onGetFeedStarted(CCProvider(provider->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_SOCIAL_ACTION_FAILED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __Integer *socialActionType = dynamic_cast<__Integer *>(parameters->objectForKey("socialActionType")); __String *errorDescription = dynamic_cast<__String *>(parameters->objectForKey("errorDescription")); this->onSocialActionFailedEvent(CCProvider(provider->getValue()), CCSocialActionType(socialActionType->getValue()), errorDescription); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_SOCIAL_ACTION_FINISHED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __Integer *socialActionType = dynamic_cast<__Integer *>(parameters->objectForKey("socialActionType")); this->onSocialActionFinishedEvent(CCProvider(provider->getValue()), CCSocialActionType(socialActionType->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_SOCIAL_ACTION_STARTED, [this](__Dictionary *parameters) { __Integer* provider = dynamic_cast<__Integer *>(parameters->objectForKey("provider")); __Integer *socialActionType = dynamic_cast<__Integer *>(parameters->objectForKey("socialActionType")); this->onSocialActionStartedEvent(CCProvider(provider->getValue()), CCSocialActionType(socialActionType->getValue())); }); eventDispatcher->registerEventHandler(CCProfileConsts::EVENT_USER_PROFILE_UPDATED, [this](__Dictionary *parameters) { CCUserProfile *userProfile = this->extractUserProfile(parameters->objectForKey("userProfile")); this->onUserProfileUpdatedEvent(userProfile); }); return true; }
bool CCStoreEventDispatcher::init() { if (!CCAbstractAggregatedEventHandler::init()) { return false; } CCSoomlaEventDispatcher *eventDispatcher = CCSoomlaEventDispatcher::getInstance(); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_BILLING_NOT_SUPPORTED, [this](__Dictionary *parameters) { this->onBillingNotSupported(); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_BILLING_SUPPORTED, [this](__Dictionary *parameters) { this->onBillingSupported(); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_CURRENCY_BALANCE_CHANGED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); __Integer *balance = (__Integer *)(parameters->objectForKey("balance")); __Integer *amountAdded = (__Integer *)(parameters->objectForKey("amountAdded")); CCError *error = NULL; CCVirtualCurrency *virtualCurrency = dynamic_cast<CCVirtualCurrency *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_CURRENCY_BALANCE_CHANGED, error); return; } CC_ASSERT(virtualCurrency); this->onCurrencyBalanceChanged(virtualCurrency, balance->getValue(), amountAdded->getValue()); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_GOOD_BALANCE_CHANGED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); __Integer *balance = (__Integer *)(parameters->objectForKey("balance")); __Integer *amountAdded = (__Integer *)(parameters->objectForKey("amountAdded")); CCError *error = NULL; CCVirtualGood *virtualGood = dynamic_cast<CCVirtualGood *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_GOOD_BALANCE_CHANGED, error); return; } CC_ASSERT(virtualGood); this->onGoodBalanceChanged(virtualGood, balance->getValue(), amountAdded->getValue()); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_GOOD_EQUIPPED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCEquippableVG *equippableVG = dynamic_cast<CCEquippableVG *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_GOOD_EQUIPPED, error); return; } CC_ASSERT(equippableVG); this->onGoodEquipped(equippableVG); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_GOOD_UNEQUIPPED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCEquippableVG *equippableVG = dynamic_cast<CCEquippableVG *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_GOOD_UNEQUIPPED, error); return; } CC_ASSERT(equippableVG); this->onGoodUnEquipped(equippableVG); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_GOOD_UPGRADE, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); __String *vguItemId = (__String *)(parameters->objectForKey("vguItemId")); CCError *error; error = NULL; CCVirtualGood *virtualGood = dynamic_cast<CCVirtualGood *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_GOOD_UPGRADE, error); return; } CC_ASSERT(virtualGood); error = NULL; CCUpgradeVG *upgradeVG = dynamic_cast<CCUpgradeVG *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(vguItemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_GOOD_UPGRADE, error); return; } CC_ASSERT(upgradeVG); this->onGoodUpgrade(virtualGood, upgradeVG); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_ITEM_PURCHASED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_ITEM_PURCHASED, error); return; } CC_ASSERT(purchasableVirtualItem); this->onItemPurchased(purchasableVirtualItem); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_ITEM_PURCHASE_STARTED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>( CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_ITEM_PURCHASE_STARTED, error); return; } CC_ASSERT(purchasableVirtualItem); this->onItemPurchaseStarted(purchasableVirtualItem); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_PURCHASE_CANCELED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_MARKET_PURCHASE_CANCELED, error); return; } CC_ASSERT(purchasableVirtualItem); this->onMarketPurchaseCancelled(purchasableVirtualItem); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_PURCHASE, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_MARKET_PURCHASE, error); return; } CC_ASSERT(purchasableVirtualItem); __String *token = (__String *)(parameters->objectForKey("token")); __String *payload = (__String *)(parameters->objectForKey("payload")); __SetIterator i; this->onMarketPurchase(purchasableVirtualItem, token, payload); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_PURCHASE_STARTED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>( CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_MARKET_PURCHASE_STARTED, error); return; } CC_ASSERT(purchasableVirtualItem); this->onMarketPurchaseStarted(purchasableVirtualItem); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_PURCHASE_STARTED, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_MARKET_PURCHASE_STARTED, error); return; } CC_ASSERT(purchasableVirtualItem); this->onMarketPurchaseStarted(purchasableVirtualItem); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_ITEMS_REFRESHED, [this](__Dictionary *parameters) { __Array *marketItemDicts = (__Array *)(parameters->objectForKey("marketItems")); __Array *marketItems = __Array::create(); CCError *error = NULL; __Dictionary *marketItem = NULL; for (unsigned int i = 0; i < marketItemDicts->count(); i++) { marketItem = dynamic_cast<__Dictionary *>(marketItemDicts->getObjectAtIndex(i)); CC_ASSERT(marketItem); __String *productId = dynamic_cast<__String *>(marketItem->objectForKey("productId")); __String *marketPrice = dynamic_cast<__String *>(marketItem->objectForKey("marketPrice")); __String *marketTitle = dynamic_cast<__String *>(marketItem->objectForKey("marketTitle")); __String *marketDescription = dynamic_cast<__String *>(marketItem->objectForKey("marketDesc")); CCPurchasableVirtualItem *pvi = CCStoreInfo::sharedStoreInfo()->getPurchasableItemWithProductId( productId->getCString(), &error); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_MARKET_ITEMS_REFRESHED, error); return; } CC_ASSERT(pvi); CCPurchaseWithMarket *purchaseWithMarket = dynamic_cast<CCPurchaseWithMarket *>(pvi->getPurchaseType()); CC_ASSERT(purchaseWithMarket); CCMarketItem *mi = purchaseWithMarket->getMarketItem(); mi->setMarketPrice(marketPrice); mi->setMarketTitle(marketTitle); mi->setMarketDescription(marketDescription); pvi->save(); marketItems->addObject(purchaseWithMarket); } this->onMarketItemsRefreshed(marketItems); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_ITEMS_REFRESH_STARTED, [this](__Dictionary *parameters) { this->onMarketItemsRefreshStarted(); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_PURCHASE_VERIFICATION, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_MARKET_PURCHASE_VERIFICATION, error); return; } CC_ASSERT(purchasableVirtualItem); this->onMarketPurchaseVerification(purchasableVirtualItem); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_RESTORE_TRANSACTION_FINISHED, [this](__Dictionary *parameters) { __Bool *success = (__Bool *)(parameters->objectForKey("success")); this->onRestoreTransactionsFinished(success->getValue()); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_RESTORE_TRANSACTION_STARTED, [this](__Dictionary *parameters) { this->onRestoreTransactionsStarted(); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_UNEXPECTED_ERROR_IN_STORE, [this](__Dictionary *parameters) { this->onUnexpectedErrorInStore(); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_STORE_CONTROLLER_INITIALIZED, [this](__Dictionary *parameters) { this->onStoreControllerInitialized(); }); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_MARKET_REFUND, [this](__Dictionary *parameters) { __String *itemId = (__String *)(parameters->objectForKey("itemId")); CCError *error = NULL; CCPurchasableVirtualItem *purchasableVirtualItem = dynamic_cast<CCPurchasableVirtualItem *>(CCStoreInfo::sharedStoreInfo()->getItemByItemId(itemId->getCString(), &error)); if (error) { CCStoreUtils::logException(CCStoreConsts::EVENT_MARKET_REFUND, error); return; } CC_ASSERT(purchasableVirtualItem); this->onMarketRefund(purchasableVirtualItem); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_IAB_SERVICE_STARTED, [this](__Dictionary *parameters) { this->onIabServiceStarted(); }); eventDispatcher->registerEventHandler(CCStoreConsts::EVENT_IAB_SERVICE_STOPPED, [this](__Dictionary *parameters) { this->onIabServiceStopped(); }); #endif return true; }