void UserDataManager::setEntityParameterLevel(EntityType entityType, EntityParameterLevel EntityParameterLevel) { ValueMap entityListParameterMap; if (this->userData.find(USER_DATA_ENTITY_PARAMETER) == this->userData.end()) { entityListParameterMap = ValueMap(); } else { entityListParameterMap = this->userData[USER_DATA_ENTITY_PARAMETER].asValueMap(); } std::string entityTypeString = this->getEntityTypeStringByEntityType(entityType); ValueMap entityParameterMap; if (entityListParameterMap.find(entityTypeString) == entityListParameterMap.end()) { entityParameterMap = ValueMap(); } else { entityParameterMap = entityListParameterMap[entityTypeString].asValueMap(); } entityParameterMap["rank"] = EntityParameterLevel.rank; entityParameterMap["levelHp"] = EntityParameterLevel.hp; entityParameterMap["levelAttack"] = EntityParameterLevel.attack; entityListParameterMap[entityTypeString] = entityParameterMap; this->userData[USER_DATA_ENTITY_PARAMETER] = entityListParameterMap; this->save(); }
void InputLabel::editBoxEditingDidBegin(ui::EditBox* editBox) { if(locks.size() > 0) { Value infos = Value(ValueMap({{"Sender", Value(this->getID())}})); closeKeyboard(EventCustom::create("CloseKeyboard", &infos)); return; } if(!isOpened && delegate->isEnabled()) { isOpened = true; Value infos = Value(ValueMap({{"Sender", Value(identifier)}})); Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("InputLabelBeginEdit", &infos); } }
void TestUnicodePath::onExit() { FileUtils *sharedFileUtils = FileUtils::getInstance(); sharedFileUtils->purgeCachedEntries(); sharedFileUtils->setFilenameLookupDictionary(ValueMap()); FileUtilsDemo::onExit(); }
void Animation::addSpriteFrame(SpriteFrame* spriteFrame) { AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, 1.0f, ValueMap()); _frames.pushBack(animFrame); // update duration _totalDelayUnits++; }
WebDialog::WebDialog(): _dialog(""), _params(ValueMap()), _callback(nullptr) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) _impl = new screw::ios::WebDialogApple(); #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) _impl = new screw::jni::WebDialogAndroid(); #endif }
void TestIsFileExist::onExit() { FileUtils *sharedFileUtils = FileUtils::getInstance(); // reset filename lookup sharedFileUtils->setFilenameLookupDictionary(ValueMap()); FileUtilsDemo::onExit(); }
void UserDataManager::load() { std::string path = this->getFilePath(); if (! FileUtils::getInstance()->isFileExist(path)) { this->userData = ValueMap(); } else { this->userData = FileUtils::getInstance()->getValueMapFromFile(path); } }
int YesqlClient::scan(const TableId& table, const Key& start_key, int count, const FieldList& fields, std::vector<ValueMap>& result){ sqlite3_stmt* stmt = construct_sql_scan(table, start_key, count, fields); int rc = -1; if (stmt){ do { result.push_back(ValueMap()); rc = read_result_row(stmt, fields, result.back()); count--; } while (count > 0 && rc == SQLITE_ROW); sqlite3_reset(stmt); } return (rc == SQLITE_DONE || rc == SQLITE_ROW) ? 0 : -1; }
bool Animation::initWithSpriteFrames(const Vector<SpriteFrame*>& frames, float delay/* = 0.0f*/, unsigned int loops/* = 1*/) { _delayPerUnit = delay; _loops = loops; for (auto& spriteFrame : frames) { auto animFrame = AnimationFrame::create(spriteFrame, 1, ValueMap()); _frames.pushBack(animFrame); _totalDelayUnits++; } return true; }
void UserDataManager::setIsShownTutorial(TutorialType tutorialType, bool isShown) { ValueMap isShownMap; if (this->userData.find(USER_DATA_IS_SHOWN_TUTORIAL) == this->userData.end()) { isShownMap = ValueMap(); } else { isShownMap = this->userData[USER_DATA_IS_SHOWN_TUTORIAL].asValueMap(); } std::string tutorialTypeString = this->getTutorialTypeStringByTutorialType(tutorialType); isShownMap[tutorialTypeString] = isShown; this->userData[USER_DATA_IS_SHOWN_TUTORIAL] = isShownMap; this->save(); }
ValueMap TMXObjectGroup::getObject(const std::string& objectName) const { if (!_objects.empty()) { for (const auto& v : _objects) { const ValueMap& dict = v.asValueMap(); if (dict.find("name") != dict.end()) { if (dict.at("name").asString() == objectName) return dict; } } } // object not found return ValueMap(); }
ValueArray::ValueArray(const Value& src) { if(!UPP::IsNull(src)) { if(IsType<ValueMap>(src)) { ValueArray v = ValueMap(src); data = v.data; data->Retain(); return; } else { if(src.GetType() != VALUEARRAY_V) throw ValueTypeError(String().Cat() << "Invalid value conversion: " << src.GetTypeName() << " -> ValueArray", src, VALUEARRAY_V); data = (ValueArray::Data *)src.GetVoidPtr(); } } else data = &Single<NullData>(); data->Retain(); }
void UserDataManager::setHighScoreByEntityType(int highScore, EntityType entityType) { int currentHighScore = this->getHighScoreByEntityType(entityType); if (highScore < currentHighScore) { return; } ValueMap highScoreMap; if (this->userData.find(USER_DATA_HIGHSCORE) == this->userData.end()) { highScoreMap = ValueMap(); } else { highScoreMap = this->userData[USER_DATA_HIGHSCORE].asValueMap(); } std::string entityTypeString = this->getEntityTypeStringByEntityType(entityType); highScoreMap[entityTypeString] = highScore; this->userData[USER_DATA_HIGHSCORE] = highScoreMap; this->save(); }
void InputLabel::editBoxReturn(ui::EditBox* editBox) { log("ui::EditBoxReturn : Close InputLabel keyboard"); DelayedDispatcher::eventAfterDelay("InputLabelReturn", Value(ValueMap({{"Sender", Value(getID())}})), 0.01); }
void InputLabel::openKeyboard(EventCustom* event) { ValueMap infos = (event != NULL && event->getUserData() != NULL) ? ((Value*)event->getUserData())->asValueMap() : ValueMap(); if(locks.size() == 0 && ((isValueOfType(infos["Sender"], INTEGER) && infos["Sender"].asInt() == identifier) || (isValueOfType(infos["Target"], INTEGER) && infos["Target"].asInt() == identifier))) { log("Open InputLabel keyboard"); delegate->touchDownAction(this, cocos2d::ui::Widget::TouchEventType::ENDED);//open keyboard by simulating a touch inside isOpened = true; } }
NS_CC_BEGIN /* The subclass FileUtilsApple should override these two method. */ ValueMap FileUtils::getValueMapFromFile(const std::string& filename) { return ValueMap(); }
ValueMap FileUtils::getValueMapFromData(const char* filedata, int filesize) { return ValueMap(); }
/* The subclass FileUtilsApple should override these two method. */ ValueMap FileUtils::getValueMapFromFile(const std::string& filename) {return ValueMap();}
void startElement(void *ctx, const char *name, const char **atts) { CC_UNUSED_PARAM(ctx); CC_UNUSED_PARAM(atts); const std::string sName(name); if( sName == "dict" ) { if(_resultType == SAX_RESULT_DICT && _rootDict.empty()) { _curDict = &_rootDict; } _state = SAX_DICT; SAXState preState = SAX_NONE; if (! _stateStack.empty()) { preState = _stateStack.top(); } if (SAX_ARRAY == preState) { // add a new dictionary into the array _curArray->push_back(Value(ValueMap())); _curDict = &(_curArray->rbegin())->asValueMap(); } else if (SAX_DICT == preState) { // add a new dictionary into the pre dictionary CCASSERT(! _dictStack.empty(), "The state is wrong!"); ValueMap* preDict = _dictStack.top(); (*preDict)[_curKey] = Value(ValueMap()); _curDict = &(*preDict)[_curKey].asValueMap(); } // record the dict state _stateStack.push(_state); _dictStack.push(_curDict); } else if(sName == "key") { _state = SAX_KEY; } else if(sName == "integer") { _state = SAX_INT; } else if(sName == "real") { _state = SAX_REAL; } else if(sName == "string") { _state = SAX_STRING; } else if (sName == "array") { _state = SAX_ARRAY; if (_resultType == SAX_RESULT_ARRAY && _rootArray.empty()) { _curArray = &_rootArray; } SAXState preState = SAX_NONE; if (! _stateStack.empty()) { preState = _stateStack.top(); } if (preState == SAX_DICT) { (*_curDict)[_curKey] = Value(ValueVector()); _curArray = &(*_curDict)[_curKey].asValueVector(); } else if (preState == SAX_ARRAY) { CCASSERT(! _arrayStack.empty(), "The state is wrong!"); ValueVector* preArray = _arrayStack.top(); preArray->push_back(Value(ValueVector())); _curArray = &(_curArray->rbegin())->asValueVector(); } // record the array state _stateStack.push(_state); _arrayStack.push(_curArray); } else { _state = SAX_NONE; } }
AppRequests::AppRequests() { _data = new data::Data(ValueMap(), utils::FileUtils::getDocumentPath("apprequests.plist")); }
void DiamondBuyData::init() { bool isSave = false; if (m_DiamondDataVm == nullptr) { m_DiamondDataVm = new (std::nothrow) ValueMap(); } auto diamondTableList = CfgData::getInstance()->GetCfgTableId("DiamondItem"); int cfgId = 0; for (auto iter = diamondTableList->begin(); iter != diamondTableList->end(); ++iter) { /* 进度通用性与类型: 1 - int(进度通用则存储是否购买, 1为已购买,0为未购买) 0 - map(进度不可通用则存储map,[进度, 购买次数],进度:1或2或3) */ cfgId = *iter; if (GetDiamondData(cfgId) == nullptr) { CfgDataRow itemRow(cfgId); if (itemRow.GetValue(CfgField::GenericID)->asInt() == 1) { m_DiamondDataVm->insert(pair<string, Value>(StringUtils::format("%d", *iter), Value(0))); } else { m_DiamondDataVm->insert(pair<string, Value>(StringUtils::format("%d", *iter), Value(ValueMap()))); } isSave = true; } } if (isSave) SaveDiamondData(); }
void EventResponder::back(EventCustom* event) { ValueMap infos = event != NULL && event->getUserData() != NULL && ((Value*)event->getUserData())->getType() == Value::Type::MAP ? ((Value*)event->getUserData())->asValueMap() : ValueMap(); infos["Scene"] = Value(getPreviousSceneName(currentScene->getSceneName())); Value toSend = Value(infos); Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("PlanSceneSwitch", &toSend); }
ValueMap HudPanel::saveModel() { return ValueMap(); }
void Face::initFaceForKey(std::string key, __Array* faceStates) { // load file plist auto frameCache = SpriteFrameCache::getInstance(); char plistFile[200]; sprintf(plistFile, "%s.plist", key.data()); frameCache->addSpriteFramesWithFile(plistFile); // load animation auto animationCache = AnimationCache::getInstance(); char animationFile[200]; std::string firstSpriteFrameName = ""; sprintf(animationFile, "ani-%s.plist", key.data()); std::string path = FileUtils::getInstance()->fullPathForFilename(animationFile); ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(path); ValueVector animations = dict.at("Animations").asValueVector(); __Array* animationNames = __Array::create(); for (int i = 0; i < animations.size(); i++) { ValueMap animationDict = animations.at(i).asValueMap(); ValueVector frames = animationDict.at("Frames").asValueVector(); ValueMap properties = animationDict.at("Properties").asValueMap(); std::string name = properties.at("Animation").asString(); animationNames->addObject(__String::create(name.data())); float delayPerUnit = 1 / properties.at("FPS").asFloat(); Animation* animation = NULL; if (frames.empty()) { continue; } ssize_t frameSize = frames.size(); Vector<AnimationFrame*> animationFrames(frameSize); for (auto& frame : frames) { ValueMap frameValueMap = frame.asValueMap(); std::string frameString = frameValueMap.at("FrameName").asString(); if (firstSpriteFrameName == "") { firstSpriteFrameName = frameString; } float duration = frameValueMap.at("Duration").asFloat(); SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameString); if (!spriteFrame) { continue; } AnimationFrame* animFrame = AnimationFrame::create(spriteFrame, duration, ValueMap()); animationFrames.pushBack(animFrame); } if (frames.empty()) { assert(NULL); continue; } else if (frames.size() != frameSize) { assert(NULL); } animation = Animation::create(animationFrames, delayPerUnit); animationCache->addAnimation(animation, name); } this->initWithSpriteFrameName(firstSpriteFrameName); this->getTexture()->setAliasTexParameters(); for (int i = 0; i < animationNames->count(); i++) { __String* animationName = (__String*) animationNames->getObjectAtIndex(i); std::string animationNameStr = animationName->getCString(); for (int j = 0; j < faceStates->count(); j++) { FaceState* state = (FaceState*) faceStates->getObjectAtIndex(j); std::string stateString = state->getStateName(); if (animationNameStr.find(stateString) != std::string::npos) { auto animation = animationCache->getAnimation(animationNameStr); auto animate = Animate::create(animation); if (state->isLoop()) { Action* action = RepeatForever::create(animate); this->registerState(stateString, action); } else { Action* action = (Action*) animate; this->registerState(stateString, action); } break; } } } }
bool GameScene::init() { if (!Layer::init()) { return false; } _deviceOrientation = DeviceOrientation::Portrait; auto visibleSize = Director::getInstance()->getVisibleSize(); //setContentSize(Size(visibleSize.width * 2, visibleSize.height)); // 背景レイヤーの上にメインシーン、レポートシーンを含めるコンテナシーンを重ねて、コンテナシーンを移動させ、背景は固定されるようにする // 背景レイヤー auto bkgLayer = Layer::create(); bkgLayer->setName(name::scene::game::BACKGROUND_LAYER); addChild(bkgLayer); auto cache = Director::getInstance()->getTextureCache(); auto tex = cache->getTextureForKey(name::resource::GAME_BACKGROUND); auto spr = Sprite::createWithTexture(tex); cache->removeTexture(tex); //spr->setName(name::GAME_BACKGROUND); spr->setAnchorPoint(Vec2::ZERO); spr->setPosition(Vec2::ZERO); bkgLayer->addChild(spr); // コンテナレイヤー(メインシーンとレポートシーンを含める) auto containerLayer = Layer::create(); containerLayer->setName(name::scene::game::CONTAINER_LAYER); addChild(containerLayer); auto mainScene = MainScene::create(); mainScene->setName(name::scene::MAIN); mainScene->setAnchorPoint(Vec2::ZERO); mainScene->setPosition(Vec2::ZERO); containerLayer->addChild(mainScene); auto reportScene = ReportScene::create(); reportScene->setName(name::scene::REPORT); reportScene->setAnchorPoint(Vec2::ZERO); reportScene->setPosition(Vec2(720, 0)); containerLayer->addChild(reportScene); // 左スクロールイベント Director::getInstance()->getEventDispatcher()->addCustomEventListener(config::event::ScrollToLeftNotification, [this](EventCustom* evt) { auto vec = Vec2::ZERO; if (DeviceOrientation::Portrait == _deviceOrientation) { vec = Vec2(-720, 0); } else if (DeviceOrientation::Landscape == _deviceOrientation) { vec = Vec2(-1280, 0); } getChildByName(name::scene::game::CONTAINER_LAYER)->runAction(MoveBy::create(0.3f, vec)); }); // 右スクロールイベント Director::getInstance()->getEventDispatcher()->addCustomEventListener(config::event::ScrollToRightNotification, [this](EventCustom* evt) { auto vec = Vec2::ZERO; if (DeviceOrientation::Portrait == _deviceOrientation) { vec = Vec2(720, 0); } else if (DeviceOrientation::Landscape == _deviceOrientation) { vec = Vec2(1280, 0); } // スクロールしてスクロール完了を通知 auto action = Sequence::createWithTwoActions(MoveBy::create(0.3f, vec), CallFunc::create([this]() { Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(config::event::ScrollToRightCompletionNotification); })); getChildByName(name::scene::game::CONTAINER_LAYER)->runAction(action); }); // 端末の向き変更イベント Director::getInstance()->getEventDispatcher()->addCustomEventListener(config::event::OrientationChangedNotification, [this](EventCustom* evt) { auto data = static_cast<ValueMap*>(evt->getUserData()); auto w = data->at("w").asInt(); auto h = data->at("h").asInt(); auto glview = Director::getInstance()->getOpenGLView(); // フレームサイズをセットしてから、デザイン解像度をセット glview->setFrameSize(w, h); if (w > h) { //CCLOG("(landscape) w: %d, h: %d", w, h); glview->setDesignResolutionSize(config::resolution::DESIGN_RESOLUTION_LONG_SPAN, config::resolution::DESIGN_RESOLUTION_SHORT_SPAN, config::resolution::DESIGN_POLICY); _deviceOrientation = DeviceOrientation::Landscape; } else { //CCLOG("(portrait) w: %d, h: %d", w, h); glview->setDesignResolutionSize(config::resolution::DESIGN_RESOLUTION_SHORT_SPAN, config::resolution::DESIGN_RESOLUTION_LONG_SPAN, config::resolution::DESIGN_POLICY); _deviceOrientation = DeviceOrientation::Portrait; } reArrangeChildrens(); }); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) auto keyboardListener = EventListenerKeyboard::create(); keyboardListener->onKeyPressed = [this](EventKeyboard::KeyCode keyCode, Event* event) {}; keyboardListener->onKeyReleased = [this](EventKeyboard::KeyCode keyCode, Event* event) { if (EventKeyboard::KeyCode::KEY_V != keyCode && EventKeyboard::KeyCode::KEY_H != keyCode) return; auto data = ValueMap(); if (EventKeyboard::KeyCode::KEY_V == keyCode) { data["w"] = 540; data["h"] = 960; } else if (EventKeyboard::KeyCode::KEY_H == keyCode) { data["w"] = 960; data["h"] = 540; } auto evtDispatcher = Director::getInstance()->getEventDispatcher(); evtDispatcher->dispatchCustomEvent(config::event::OrientationChangedNotification, &data); }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(keyboardListener, this); #endif return true; }
void InputLabel::closeKeyboard(EventCustom* event) { ValueMap infos = (event != NULL && event->getUserData() != NULL) ? ((Value*)event->getUserData())->asValueMap() : ValueMap(); if((isValueOfType(infos["Sender"], INTEGER) && infos["Sender"].asInt() == identifier) || (isValueOfType(infos["Target"], INTEGER) && infos["Target"].asInt() == identifier)) { log("Close InputLabel keyboard"); delegate->detachWithIME(); delegate->closeKeyboard(); //Force close the keyboard } }