示例#1
0
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;
}
示例#2
0
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;
    }
}
示例#3
0
void JsonValueConverter::value(const cocos2d::Value &v) {
    StackItem &current = _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);
    }
}
void U8SDKNativeCallback::OnU8InitSuc(cocos2d::Node *sender, cocos2d::Value data)
{

	if (data.isNull() || data.getType() != cocos2d::Value::Type::MAP)
	{
		CCLOG("OnU8InitSuc Data Type Error:: curr data type is not map.");
		return;
	}

	cocos2d::ValueMap json = data.asValueMap();
	bool exit = json["isSupportExit"].asBool();
	bool accountCenter = json["isSupportAccountCenter"].asBool();
	bool logout = json["isSupportLogout"].asBool();

	U8SDKInterface::getInstance()->setSupports(exit, accountCenter, logout);

	if (this->gameCallback != nullptr)
	{
		this->gameCallback->OnInitSuc();
	}
}
void U8SDKNativeCallback::OnU8LoginSuc(cocos2d::Node *sender, cocos2d::Value data)
{
	if (data.isNull() || data.getType() != cocos2d::Value::Type::MAP)
	{
		CCLOG("OnU8LoginSuc Data Type Error:: curr data type is not map.");
		return;
	}

	U8LoginResult* result = U8LoginResult::create();
	cocos2d::ValueMap json = data.asValueMap();
	result->isSuc = json["isSuc"].asBool();
	result->isSwitchAccount = json["isSwitchAccount"].asBool();
	result->userId = json["userID"].asString();
	result->sdkUserId = json["sdkUserID"].asString();
	result->username = json["username"].asString();
	result->sdkUsername = json["sdkUsername"].asString();
	result->token = json["token"].asString();

	if (this->gameCallback != nullptr)
	{
		this->gameCallback->OnLoginSuc(result);
	}
}
示例#6
0
string JsonUtils::toJsonString(cocos2d::Value &v) {
    CCASSERT(v.getType() == cocos2d::Value::Type::INT_KEY_MAP || v.getType() == cocos2d::Value::Type::MAP ||
             v.getType() == cocos2d::Value::Type::VECTOR, "Only map and vector are valid");
    return ValueJsonStringVisitor::visit(v);
}