string ValueJsonStringVisitor::visit(const cocos2d::Value &v) { switch (v.getType()) { case cocos2d::Value::Type::NONE: case cocos2d::Value::Type::BYTE: case cocos2d::Value::Type::INTEGER: case cocos2d::Value::Type::FLOAT: case cocos2d::Value::Type::DOUBLE: case cocos2d::Value::Type::BOOLEAN: return v.asString(); break; case cocos2d::Value::Type::STRING: return string("\"") + v.asString() + string("\""); break; case cocos2d::Value::Type::VECTOR: return visit(v.asValueVector()); break; case cocos2d::Value::Type::MAP: return visitMap<ValueMap>(v.asValueMap()); break; case cocos2d::Value::Type::INT_KEY_MAP: return visitMap<ValueMapIntKey>(v.asIntKeyMap()); break; default: CCASSERT(false, "Invalid type!"); break; } }
bool CustomInput::onAssignCCBCustomProperty(CCObject* pTarget, const char* pMemberVariableName, const cocos2d::Value& pCCBValue) { CustomInput* target = dynamic_cast<CustomInput*>(pTarget); if(pCCBValue.getType() == cocos2d::Value::Type::INTEGER && strcmp(pMemberVariableName, "maxChar") == 0) { target->setMaxChar(pCCBValue.asInt()); } else if(pCCBValue.getType() == cocos2d::Value::Type::INTEGER && strcmp(pMemberVariableName, "fontSize") == 0) { target->setFontSize(pCCBValue.asInt()); } else if(pCCBValue.getType() == cocos2d::Value::Type::STRING && strcmp(pMemberVariableName, "placeHolder") == 0) { target->setPlaceHolder(Screate(pCCBValue.asString())); } else if(pCCBValue.getType() == cocos2d::Value::Type::STRING && strcmp(pMemberVariableName, "fontName") == 0) { target->setFontName(Screate(pCCBValue.asString())); } else if(pCCBValue.getType() == cocos2d::Value::Type::BOOLEAN && strcmp(pMemberVariableName, "numbers") == 0) { target->setNumbersOnly(pCCBValue.asBool()); } else { CustomBaseNode::onAssignCCBCustomProperty(pTarget, pMemberVariableName, pCCBValue); } return false; }
void JsonValueConverter::value(const cocos2d::Value &v) { StackItem ¤t = _stack.back(); if (current.value.getType() == cocos2d::Value::Type::MAP) { if (current.index %2 == 0) { CCASSERT(v.getType() == cocos2d::Value::Type::STRING, "Key must be a string"); current.key = v.asString(); } else { current.value.asValueMap()[current.key] = v; } current.index++; } else { current.value.asValueVector().push_back(v); } }