Merge pull request #79 from halx99/master

Refactor CCValue.
This commit is contained in:
HALX99 2020-03-03 22:55:40 +08:00 committed by GitHub
commit 8ea95eebd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 261 additions and 259 deletions

View File

@ -91,7 +91,7 @@ void AnimationCache::parseVersion1(const ValueMap& animations)
{ {
const ValueMap& animationDict = anim.second.asValueMap(); const ValueMap& animationDict = anim.second.asValueMap();
const ValueVector& frameNames = animationDict.at("frames").asValueVector(); const ValueVector& frameNames = animationDict.at("frames").asValueVector();
float delay = animationDict.at("delay").asFloat(); float delay = animationDict.at("delay").toFloat();
Animation* animation = nullptr; Animation* animation = nullptr;
if ( frameNames.empty() ) if ( frameNames.empty() )
@ -143,7 +143,7 @@ void AnimationCache::parseVersion2(const ValueMap& animations)
ValueMap& animationDict = const_cast<ValueMap&>(anim.second.asValueMap()); ValueMap& animationDict = const_cast<ValueMap&>(anim.second.asValueMap());
const Value& loops = animationDict["loops"]; const Value& loops = animationDict["loops"];
bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].asBool(); bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].toBool();
ValueVector& frameArray = animationDict["frames"].asValueVector(); ValueVector& frameArray = animationDict["frames"].asValueVector();
@ -168,7 +168,7 @@ void AnimationCache::parseVersion2(const ValueMap& animations)
continue; continue;
} }
float delayUnits = entry["delayUnits"].asFloat(); float delayUnits = entry["delayUnits"].toFloat();
Value& userInfo = entry["notification"]; Value& userInfo = entry["notification"];
AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, delayUnits, userInfo.getType() == Value::Type::MAP ? userInfo.asValueMap() : ValueMapNull); AnimationFrame *animFrame = AnimationFrame::create(spriteFrame, delayUnits, userInfo.getType() == Value::Type::MAP ? userInfo.asValueMap() : ValueMapNull);
@ -176,8 +176,8 @@ void AnimationCache::parseVersion2(const ValueMap& animations)
array.pushBack(animFrame); array.pushBack(animFrame);
} }
float delayPerUnit = animationDict["delayPerUnit"].asFloat(); float delayPerUnit = animationDict["delayPerUnit"].toFloat();
Animation *animation = Animation::create(array, delayPerUnit, loops.getType() != Value::Type::NONE ? loops.asInt() : 1); Animation *animation = Animation::create(array, delayPerUnit, loops.getType() != Value::Type::NONE ? loops.toInt() : 1);
animation->setRestoreOriginalFrame(restoreOriginalFrame); animation->setRestoreOriginalFrame(restoreOriginalFrame);
@ -201,7 +201,7 @@ void AnimationCache::addAnimationsWithDictionary(const ValueMap& dictionary,cons
if(propsItr != dictionary.end() ) if(propsItr != dictionary.end() )
{ {
const ValueMap& properties = propsItr->second.asValueMap(); const ValueMap& properties = propsItr->second.asValueMap();
version = properties.at("format").asInt(); version = properties.at("format").toInt();
const ValueVector& spritesheets = properties.at("spritesheets").asValueVector(); const ValueVector& spritesheets = properties.at("spritesheets").asValueVector();
for(const auto &value : spritesheets) { for(const auto &value : spritesheets) {

View File

@ -763,11 +763,11 @@ void FastTMXLayer::parseInternalProperties()
{ {
_useAutomaticVertexZ = true; _useAutomaticVertexZ = true;
auto alphaFuncVal = getProperty("cc_alpha_func"); auto alphaFuncVal = getProperty("cc_alpha_func");
_alphaFuncValue = alphaFuncVal.asFloat(); _alphaFuncValue = alphaFuncVal.toFloat();
} }
else else
{ {
_vertexZvalue = vertexz.asInt(); _vertexZvalue = vertexz.toInt();
} }
} }

View File

@ -39,13 +39,13 @@ FontCharMap * FontCharMap::create(const std::string& plistFile)
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr); ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr);
CCASSERT(dict["version"].asInt() == 1, "Unsupported version. Upgrade cocos2d version"); CCASSERT(dict["version"].toInt() == 1, "Unsupported version. Upgrade cocos2d version");
std::string textureFilename = relPathStr + dict["textureFilename"].asString(); std::string textureFilename = relPathStr + dict["textureFilename"].asString();
unsigned int width = dict["itemWidth"].asInt(); unsigned int width = dict["itemWidth"].toInt();
unsigned int height = dict["itemHeight"].asInt(); unsigned int height = dict["itemHeight"].toInt();
unsigned int startChar = dict["firstChar"].asInt(); unsigned int startChar = dict["firstChar"].toInt();
Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(textureFilename); Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(textureFilename);
if (!tempTexture) if (!tempTexture)

View File

@ -109,13 +109,13 @@ bool LabelAtlas::initWithString(const std::string& theString, const std::string&
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr); ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr);
CCASSERT(dict["version"].asInt() == 1, "Unsupported version. Upgrade cocos2d version"); CCASSERT(dict["version"].toInt() == 1, "Unsupported version. Upgrade cocos2d version");
std::string textureFilename = relPathStr + dict["textureFilename"].asString(); std::string textureFilename = relPathStr + dict["textureFilename"].asString();
unsigned int width = dict["itemWidth"].asInt() / CC_CONTENT_SCALE_FACTOR(); unsigned int width = dict["itemWidth"].toInt() / CC_CONTENT_SCALE_FACTOR();
unsigned int height = dict["itemHeight"].asInt() / CC_CONTENT_SCALE_FACTOR(); unsigned int height = dict["itemHeight"].toInt() / CC_CONTENT_SCALE_FACTOR();
unsigned int startChar = dict["firstChar"].asInt(); unsigned int startChar = dict["firstChar"].toInt();
this->initWithString(theString, textureFilename, width, height, startChar); this->initWithString(theString, textureFilename, width, height, startChar);

View File

@ -364,7 +364,7 @@ void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
for(const auto &child : _children) { for(const auto &child : _children) {
CCASSERT(row < rows.size(), "row should less than rows.size()!"); CCASSERT(row < rows.size(), "row should less than rows.size()!");
rowColumns = rows[row].asInt(); rowColumns = rows[row].toInt();
// can not have zero columns on a row // can not have zero columns on a row
CCASSERT(rowColumns, "rowColumns can't be 0."); CCASSERT(rowColumns, "rowColumns can't be 0.");
@ -397,7 +397,7 @@ void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
for(const auto &child : _children) { for(const auto &child : _children) {
if (rowColumns == 0) if (rowColumns == 0)
{ {
rowColumns = rows[row].asInt(); rowColumns = rows[row].toInt();
w = winSize.width / (1 + rowColumns); w = winSize.width / (1 + rowColumns);
x = w; x = w;
} }
@ -460,7 +460,7 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
// check if too many menu items for the amount of rows/columns // check if too many menu items for the amount of rows/columns
CCASSERT(column < columns.size(), "column should be less than columns.size()."); CCASSERT(column < columns.size(), "column should be less than columns.size().");
columnRows = columns[column].asInt(); columnRows = columns[column].toInt();
// can't have zero rows on a column // can't have zero rows on a column
CCASSERT(columnRows, "columnRows can't be 0."); CCASSERT(columnRows, "columnRows can't be 0.");
@ -498,7 +498,7 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
for(const auto &child : _children) { for(const auto &child : _children) {
if (columnRows == 0) if (columnRows == 0)
{ {
columnRows = columns[column].asInt(); columnRows = columns[column].toInt();
y = (float) columnHeights[column]; y = (float) columnHeights[column];
} }

View File

@ -320,7 +320,7 @@ bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string&
Image *image = nullptr; Image *image = nullptr;
do do
{ {
int maxParticles = dictionary["maxParticles"].asInt(); int maxParticles = dictionary["maxParticles"].toInt();
// self, not super // self, not super
if(this->initWithTotalParticles(maxParticles)) if(this->initWithTotalParticles(maxParticles))
{ {
@ -328,91 +328,91 @@ bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string&
_configName = dictionary["configName"].toString(); _configName = dictionary["configName"].toString();
// angle // angle
_angle = dictionary["angle"].asFloat(); _angle = dictionary["angle"].toFloat();
_angleVar = dictionary["angleVariance"].asFloat(); _angleVar = dictionary["angleVariance"].toFloat();
// duration // duration
_duration = dictionary["duration"].asFloat(); _duration = dictionary["duration"].toFloat();
// blend function // blend function
if (!_configName.empty()) if (!_configName.empty())
{ {
_blendFunc.src = utils::toBackendBlendFactor((int)dictionary["blendFuncSource"].asFloat()); _blendFunc.src = utils::toBackendBlendFactor((int)dictionary["blendFuncSource"].toFloat());
} }
else else
{ {
_blendFunc.src = utils::toBackendBlendFactor(dictionary["blendFuncSource"].asInt()); _blendFunc.src = utils::toBackendBlendFactor(dictionary["blendFuncSource"].toInt());
} }
_blendFunc.dst = utils::toBackendBlendFactor(dictionary["blendFuncDestination"].asInt()); _blendFunc.dst = utils::toBackendBlendFactor(dictionary["blendFuncDestination"].toInt());
// color // color
_startColor.r = dictionary["startColorRed"].asFloat(); _startColor.r = dictionary["startColorRed"].toFloat();
_startColor.g = dictionary["startColorGreen"].asFloat(); _startColor.g = dictionary["startColorGreen"].toFloat();
_startColor.b = dictionary["startColorBlue"].asFloat(); _startColor.b = dictionary["startColorBlue"].toFloat();
_startColor.a = dictionary["startColorAlpha"].asFloat(); _startColor.a = dictionary["startColorAlpha"].toFloat();
_startColorVar.r = dictionary["startColorVarianceRed"].asFloat(); _startColorVar.r = dictionary["startColorVarianceRed"].toFloat();
_startColorVar.g = dictionary["startColorVarianceGreen"].asFloat(); _startColorVar.g = dictionary["startColorVarianceGreen"].toFloat();
_startColorVar.b = dictionary["startColorVarianceBlue"].asFloat(); _startColorVar.b = dictionary["startColorVarianceBlue"].toFloat();
_startColorVar.a = dictionary["startColorVarianceAlpha"].asFloat(); _startColorVar.a = dictionary["startColorVarianceAlpha"].toFloat();
_endColor.r = dictionary["finishColorRed"].asFloat(); _endColor.r = dictionary["finishColorRed"].toFloat();
_endColor.g = dictionary["finishColorGreen"].asFloat(); _endColor.g = dictionary["finishColorGreen"].toFloat();
_endColor.b = dictionary["finishColorBlue"].asFloat(); _endColor.b = dictionary["finishColorBlue"].toFloat();
_endColor.a = dictionary["finishColorAlpha"].asFloat(); _endColor.a = dictionary["finishColorAlpha"].toFloat();
_endColorVar.r = dictionary["finishColorVarianceRed"].asFloat(); _endColorVar.r = dictionary["finishColorVarianceRed"].toFloat();
_endColorVar.g = dictionary["finishColorVarianceGreen"].asFloat(); _endColorVar.g = dictionary["finishColorVarianceGreen"].toFloat();
_endColorVar.b = dictionary["finishColorVarianceBlue"].asFloat(); _endColorVar.b = dictionary["finishColorVarianceBlue"].toFloat();
_endColorVar.a = dictionary["finishColorVarianceAlpha"].asFloat(); _endColorVar.a = dictionary["finishColorVarianceAlpha"].toFloat();
// particle size // particle size
_startSize = dictionary["startParticleSize"].asFloat(); _startSize = dictionary["startParticleSize"].toFloat();
_startSizeVar = dictionary["startParticleSizeVariance"].asFloat(); _startSizeVar = dictionary["startParticleSizeVariance"].toFloat();
_endSize = dictionary["finishParticleSize"].asFloat(); _endSize = dictionary["finishParticleSize"].toFloat();
_endSizeVar = dictionary["finishParticleSizeVariance"].asFloat(); _endSizeVar = dictionary["finishParticleSizeVariance"].toFloat();
// position // position
float x = dictionary["sourcePositionx"].asFloat(); float x = dictionary["sourcePositionx"].toFloat();
float y = dictionary["sourcePositiony"].asFloat(); float y = dictionary["sourcePositiony"].toFloat();
if(!_sourcePositionCompatible) { if(!_sourcePositionCompatible) {
this->setSourcePosition(Vec2(x, y)); this->setSourcePosition(Vec2(x, y));
} }
else { else {
this->setPosition(Vec2(x, y)); this->setPosition(Vec2(x, y));
} }
_posVar.x = dictionary["sourcePositionVariancex"].asFloat(); _posVar.x = dictionary["sourcePositionVariancex"].toFloat();
_posVar.y = dictionary["sourcePositionVariancey"].asFloat(); _posVar.y = dictionary["sourcePositionVariancey"].toFloat();
// Spinning // Spinning
_startSpin = dictionary["rotationStart"].asFloat(); _startSpin = dictionary["rotationStart"].toFloat();
_startSpinVar = dictionary["rotationStartVariance"].asFloat(); _startSpinVar = dictionary["rotationStartVariance"].toFloat();
_endSpin= dictionary["rotationEnd"].asFloat(); _endSpin= dictionary["rotationEnd"].toFloat();
_endSpinVar= dictionary["rotationEndVariance"].asFloat(); _endSpinVar= dictionary["rotationEndVariance"].toFloat();
_emitterMode = (Mode) dictionary["emitterType"].asInt(); _emitterMode = (Mode) dictionary["emitterType"].toInt();
// Mode A: Gravity + tangential accel + radial accel // Mode A: Gravity + tangential accel + radial accel
if (_emitterMode == Mode::GRAVITY) if (_emitterMode == Mode::GRAVITY)
{ {
// gravity // gravity
modeA.gravity.x = dictionary["gravityx"].asFloat(); modeA.gravity.x = dictionary["gravityx"].toFloat();
modeA.gravity.y = dictionary["gravityy"].asFloat(); modeA.gravity.y = dictionary["gravityy"].toFloat();
// speed // speed
modeA.speed = dictionary["speed"].asFloat(); modeA.speed = dictionary["speed"].toFloat();
modeA.speedVar = dictionary["speedVariance"].asFloat(); modeA.speedVar = dictionary["speedVariance"].toFloat();
// radial acceleration // radial acceleration
modeA.radialAccel = dictionary["radialAcceleration"].asFloat(); modeA.radialAccel = dictionary["radialAcceleration"].toFloat();
modeA.radialAccelVar = dictionary["radialAccelVariance"].asFloat(); modeA.radialAccelVar = dictionary["radialAccelVariance"].toFloat();
// tangential acceleration // tangential acceleration
modeA.tangentialAccel = dictionary["tangentialAcceleration"].asFloat(); modeA.tangentialAccel = dictionary["tangentialAcceleration"].toFloat();
modeA.tangentialAccelVar = dictionary["tangentialAccelVariance"].asFloat(); modeA.tangentialAccelVar = dictionary["tangentialAccelVariance"].toFloat();
// rotation is dir // rotation is dir
modeA.rotationIsDir = dictionary["rotationIsDir"].asBool(); modeA.rotationIsDir = dictionary["rotationIsDir"].toBool();
} }
// or Mode B: radius movement // or Mode B: radius movement
@ -420,25 +420,25 @@ bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string&
{ {
if (!_configName.empty()) if (!_configName.empty())
{ {
modeB.startRadius = dictionary["maxRadius"].asInt(); modeB.startRadius = dictionary["maxRadius"].toInt();
} }
else else
{ {
modeB.startRadius = dictionary["maxRadius"].asFloat(); modeB.startRadius = dictionary["maxRadius"].toFloat();
} }
modeB.startRadiusVar = dictionary["maxRadiusVariance"].asFloat(); modeB.startRadiusVar = dictionary["maxRadiusVariance"].toFloat();
if (!_configName.empty()) if (!_configName.empty())
{ {
modeB.endRadius = dictionary["minRadius"].asInt(); modeB.endRadius = dictionary["minRadius"].toInt();
} }
else else
{ {
modeB.endRadius = dictionary["minRadius"].asFloat(); modeB.endRadius = dictionary["minRadius"].toFloat();
} }
if (dictionary.find("minRadiusVariance") != dictionary.end()) if (dictionary.find("minRadiusVariance") != dictionary.end())
{ {
modeB.endRadiusVar = dictionary["minRadiusVariance"].asFloat(); modeB.endRadiusVar = dictionary["minRadiusVariance"].toFloat();
} }
else else
{ {
@ -447,13 +447,13 @@ bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string&
if (!_configName.empty()) if (!_configName.empty())
{ {
modeB.rotatePerSecond = dictionary["rotatePerSecond"].asInt(); modeB.rotatePerSecond = dictionary["rotatePerSecond"].toInt();
} }
else else
{ {
modeB.rotatePerSecond = dictionary["rotatePerSecond"].asFloat(); modeB.rotatePerSecond = dictionary["rotatePerSecond"].toFloat();
} }
modeB.rotatePerSecondVar = dictionary["rotatePerSecondVariance"].asFloat(); modeB.rotatePerSecondVar = dictionary["rotatePerSecondVariance"].toFloat();
} else { } else {
CCASSERT( false, "Invalid emitterType in config file"); CCASSERT( false, "Invalid emitterType in config file");
@ -461,8 +461,8 @@ bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string&
} }
// life span // life span
_life = dictionary["particleLifespan"].asFloat(); _life = dictionary["particleLifespan"].toFloat();
_lifeVar = dictionary["particleLifespanVariance"].asFloat(); _lifeVar = dictionary["particleLifespanVariance"].toFloat();
// emission Rate // emission Rate
_emissionRate = _totalParticles / _life; _emissionRate = _totalParticles / _life;
@ -539,7 +539,7 @@ bool ParticleSystem::initWithDictionary(ValueMap& dictionary, const std::string&
} }
} }
_yCoordFlipped = dictionary.find("yCoordFlipped") == dictionary.end() ? 1 : dictionary.at("yCoordFlipped").asInt(); _yCoordFlipped = dictionary.find("yCoordFlipped") == dictionary.end() ? 1 : dictionary.at("yCoordFlipped").toInt();
if( !this->_texture) if( !this->_texture)
CCLOGWARN("cocos2d: Warning: ParticleSystemQuad system without a texture"); CCLOGWARN("cocos2d: Warning: ParticleSystemQuad system without a texture");

View File

@ -140,7 +140,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
if (metaItr != dictionary.end()) if (metaItr != dictionary.end())
{ {
ValueMap& metadataDict = metaItr->second.asValueMap(); ValueMap& metadataDict = metaItr->second.asValueMap();
format = metadataDict["format"].asInt(); format = metadataDict["format"].toInt();
if(metadataDict.find("size") != metadataDict.end()) if(metadataDict.find("size") != metadataDict.end())
{ {
@ -166,14 +166,14 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
if(format == 0) if(format == 0)
{ {
float x = frameDict["x"].asFloat(); float x = frameDict["x"].toFloat();
float y = frameDict["y"].asFloat(); float y = frameDict["y"].toFloat();
float w = frameDict["width"].asFloat(); float w = frameDict["width"].toFloat();
float h = frameDict["height"].asFloat(); float h = frameDict["height"].toFloat();
float ox = frameDict["offsetX"].asFloat(); float ox = frameDict["offsetX"].toFloat();
float oy = frameDict["offsetY"].asFloat(); float oy = frameDict["offsetY"].toFloat();
int ow = frameDict["originalWidth"].asInt(); int ow = frameDict["originalWidth"].toInt();
int oh = frameDict["originalHeight"].asInt(); int oh = frameDict["originalHeight"].toInt();
// check ow/oh // check ow/oh
if(!ow || !oh) if(!ow || !oh)
{ {
@ -198,7 +198,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
// rotation // rotation
if (format == 2) if (format == 2)
{ {
rotated = frameDict["rotated"].asBool(); rotated = frameDict["rotated"].toBool();
} }
Vec2 offset = PointFromString(frameDict["offset"].asString()); Vec2 offset = PointFromString(frameDict["offset"].asString());
@ -219,7 +219,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu
Vec2 spriteOffset = PointFromString(frameDict["spriteOffset"].asString()); Vec2 spriteOffset = PointFromString(frameDict["spriteOffset"].asString());
Size spriteSourceSize = SizeFromString(frameDict["spriteSourceSize"].asString()); Size spriteSourceSize = SizeFromString(frameDict["spriteSourceSize"].asString());
Rect textureRect = RectFromString(frameDict["textureRect"].asString()); Rect textureRect = RectFromString(frameDict["textureRect"].asString());
bool textureRotated = frameDict["textureRotated"].asBool(); bool textureRotated = frameDict["textureRotated"].toBool();
// get aliases // get aliases
ValueVector& aliases = frameDict["aliases"].asValueVector(); ValueVector& aliases = frameDict["aliases"].asValueVector();
@ -554,7 +554,7 @@ void SpriteFrameCache::reloadSpriteFramesWithDictionary(ValueMap& dictionary, Te
if (dictionary.find("metadata") != dictionary.end()) if (dictionary.find("metadata") != dictionary.end())
{ {
ValueMap& metadataDict = dictionary["metadata"].asValueMap(); ValueMap& metadataDict = dictionary["metadata"].asValueMap();
format = metadataDict["format"].asInt(); format = metadataDict["format"].toInt();
} }
// check the format // check the format
@ -571,14 +571,14 @@ void SpriteFrameCache::reloadSpriteFramesWithDictionary(ValueMap& dictionary, Te
if (format == 0) if (format == 0)
{ {
float x = frameDict["x"].asFloat(); float x = frameDict["x"].toFloat();
float y = frameDict["y"].asFloat(); float y = frameDict["y"].toFloat();
float w = frameDict["width"].asFloat(); float w = frameDict["width"].toFloat();
float h = frameDict["height"].asFloat(); float h = frameDict["height"].toFloat();
float ox = frameDict["offsetX"].asFloat(); float ox = frameDict["offsetX"].toFloat();
float oy = frameDict["offsetY"].asFloat(); float oy = frameDict["offsetY"].toFloat();
int ow = frameDict["originalWidth"].asInt(); int ow = frameDict["originalWidth"].toInt();
int oh = frameDict["originalHeight"].asInt(); int oh = frameDict["originalHeight"].toInt();
// check ow/oh // check ow/oh
if (!ow || !oh) if (!ow || !oh)
{ {
@ -603,7 +603,7 @@ void SpriteFrameCache::reloadSpriteFramesWithDictionary(ValueMap& dictionary, Te
// rotation // rotation
if (format == 2) if (format == 2)
{ {
rotated = frameDict["rotated"].asBool(); rotated = frameDict["rotated"].toBool();
} }
Vec2 offset = PointFromString(frameDict["offset"].asString()); Vec2 offset = PointFromString(frameDict["offset"].asString());
@ -624,7 +624,7 @@ void SpriteFrameCache::reloadSpriteFramesWithDictionary(ValueMap& dictionary, Te
Vec2 spriteOffset = PointFromString(frameDict["spriteOffset"].asString()); Vec2 spriteOffset = PointFromString(frameDict["spriteOffset"].asString());
Size spriteSourceSize = SizeFromString(frameDict["spriteSourceSize"].asString()); Size spriteSourceSize = SizeFromString(frameDict["spriteSourceSize"].asString());
Rect textureRect = RectFromString(frameDict["textureRect"].asString()); Rect textureRect = RectFromString(frameDict["textureRect"].asString());
bool textureRotated = frameDict["textureRotated"].asBool(); bool textureRotated = frameDict["textureRotated"].toBool();
// get aliases // get aliases
ValueVector& aliases = frameDict["aliases"].asValueVector(); ValueVector& aliases = frameDict["aliases"].asValueVector();

View File

@ -247,7 +247,7 @@ void TMXLayer::parseInternalProperties()
{ {
_useAutomaticVertexZ = true; _useAutomaticVertexZ = true;
auto alphaFuncVal = getProperty("cc_alpha_func"); auto alphaFuncVal = getProperty("cc_alpha_func");
float alphaFuncValue = alphaFuncVal.asFloat(); float alphaFuncValue = alphaFuncVal.toFloat();
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR_ALPHA_TEST, nullptr); setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR_ALPHA_TEST, nullptr);
@ -259,7 +259,7 @@ void TMXLayer::parseInternalProperties()
} }
else else
{ {
_vertexZvalue = vertexz.asInt(); _vertexZvalue = vertexz.toInt();
} }
} }
} }

View File

@ -271,16 +271,16 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
} }
float hexSideLength = attributeDict["hexsidelength"].asFloat(); float hexSideLength = attributeDict["hexsidelength"].toFloat();
tmxMapInfo->setHexSideLength(hexSideLength); tmxMapInfo->setHexSideLength(hexSideLength);
Size s; Size s;
s.width = attributeDict["width"].asFloat(); s.width = attributeDict["width"].toFloat();
s.height = attributeDict["height"].asFloat(); s.height = attributeDict["height"].toFloat();
tmxMapInfo->setMapSize(s); tmxMapInfo->setMapSize(s);
s.width = attributeDict["tilewidth"].asFloat(); s.width = attributeDict["tilewidth"].toFloat();
s.height = attributeDict["tileheight"].asFloat(); s.height = attributeDict["tileheight"].toFloat();
tmxMapInfo->setTileSize(s); tmxMapInfo->setTileSize(s);
@ -308,7 +308,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
} }
externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename); externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename);
_currentFirstGID = attributeDict["firstgid"].asInt(); _currentFirstGID = attributeDict["firstgid"].toInt();
if (_currentFirstGID < 0) if (_currentFirstGID < 0)
{ {
_currentFirstGID = 0; _currentFirstGID = 0;
@ -325,7 +325,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
if (_recordFirstGID) if (_recordFirstGID)
{ {
// unset before, so this is tmx file. // unset before, so this is tmx file.
tileset->_firstGid = attributeDict["firstgid"].asInt(); tileset->_firstGid = attributeDict["firstgid"].toInt();
if (tileset->_firstGid < 0) if (tileset->_firstGid < 0)
{ {
@ -338,11 +338,11 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
_currentFirstGID = 0; _currentFirstGID = 0;
} }
tileset->_spacing = attributeDict["spacing"].asInt(); tileset->_spacing = attributeDict["spacing"].toInt();
tileset->_margin = attributeDict["margin"].asInt(); tileset->_margin = attributeDict["margin"].toInt();
Size s; Size s;
s.width = attributeDict["tilewidth"].asFloat(); s.width = attributeDict["tilewidth"].toFloat();
s.height = attributeDict["tileheight"].asFloat(); s.height = attributeDict["tileheight"].toFloat();
tileset->_tileSize = s; tileset->_tileSize = s;
tmxMapInfo->getTilesets().pushBack(tileset); tmxMapInfo->getTilesets().pushBack(tileset);
@ -355,7 +355,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
{ {
TMXLayerInfo* layer = tmxMapInfo->getLayers().back(); TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
Size layerSize = layer->_layerSize; Size layerSize = layer->_layerSize;
uint32_t gid = static_cast<uint32_t>(attributeDict["gid"].asUnsignedInt()); uint32_t gid = static_cast<uint32_t>(attributeDict["gid"].toUnsignedInt());
int tilesAmount = layerSize.width*layerSize.height; int tilesAmount = layerSize.width*layerSize.height;
if (_xmlTileIndex < tilesAmount) if (_xmlTileIndex < tilesAmount)
@ -366,7 +366,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
else else
{ {
TMXTilesetInfo* info = tmxMapInfo->getTilesets().back(); TMXTilesetInfo* info = tmxMapInfo->getTilesets().back();
tmxMapInfo->setParentGID(info->_firstGid + attributeDict["id"].asInt()); tmxMapInfo->setParentGID(info->_firstGid + attributeDict["id"].toInt());
tmxMapInfo->getTileProperties()[tmxMapInfo->getParentGID()] = Value(ValueMap()); tmxMapInfo->getTileProperties()[tmxMapInfo->getParentGID()] = Value(ValueMap());
tmxMapInfo->setParentElement(TMXPropertyTile); tmxMapInfo->setParentElement(TMXPropertyTile);
} }
@ -377,18 +377,18 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
layer->_name = attributeDict["name"].toString(); layer->_name = attributeDict["name"].toString();
Size s; Size s;
s.width = attributeDict["width"].asFloat(); s.width = attributeDict["width"].toFloat();
s.height = attributeDict["height"].asFloat(); s.height = attributeDict["height"].toFloat();
layer->_layerSize = s; layer->_layerSize = s;
Value& visibleValue = attributeDict["visible"]; Value& visibleValue = attributeDict["visible"];
layer->_visible = visibleValue.isNull() ? true : visibleValue.asBool(); layer->_visible = visibleValue.isNull() ? true : visibleValue.toBool();
Value& opacityValue = attributeDict["opacity"]; Value& opacityValue = attributeDict["opacity"];
layer->_opacity = opacityValue.isNull() ? 255 : (unsigned char)(255.0f * opacityValue.asFloat()); layer->_opacity = opacityValue.isNull() ? 255 : (unsigned char)(255.0f * opacityValue.toFloat());
float x = attributeDict["x"].asFloat(); float x = attributeDict["x"].toFloat();
float y = attributeDict["y"].asFloat(); float y = attributeDict["y"].toFloat();
layer->_offset.set(x, y); layer->_offset.set(x, y);
tmxMapInfo->getLayers().pushBack(layer); tmxMapInfo->getLayers().pushBack(layer);
@ -402,8 +402,8 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
TMXObjectGroup *objectGroup = new (std::nothrow) TMXObjectGroup(); TMXObjectGroup *objectGroup = new (std::nothrow) TMXObjectGroup();
objectGroup->setGroupName(attributeDict["name"].toString()); objectGroup->setGroupName(attributeDict["name"].toString());
Vec2 positionOffset; Vec2 positionOffset;
positionOffset.x = attributeDict["x"].asFloat() * tmxMapInfo->getTileSize().width; positionOffset.x = attributeDict["x"].toFloat() * tmxMapInfo->getTileSize().width;
positionOffset.y = attributeDict["y"].asFloat() * tmxMapInfo->getTileSize().height; positionOffset.y = attributeDict["y"].toFloat() * tmxMapInfo->getTileSize().height;
objectGroup->setPositionOffset(positionOffset); objectGroup->setPositionOffset(positionOffset);
tmxMapInfo->getObjectGroups().pushBack(objectGroup); tmxMapInfo->getObjectGroups().pushBack(objectGroup);
@ -416,9 +416,9 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
{ {
TMXTilesetInfo* tileset = tmxMapInfo->getTilesets().back(); TMXTilesetInfo* tileset = tmxMapInfo->getTilesets().back();
float tileOffsetX = attributeDict["x"].asFloat(); float tileOffsetX = attributeDict["x"].toFloat();
float tileOffsetY = attributeDict["y"].asFloat(); float tileOffsetY = attributeDict["y"].toFloat();
tileset->_tileOffset = Vec2(tileOffsetX, tileOffsetY); tileset->_tileOffset = Vec2(tileOffsetX, tileOffsetY);
@ -503,23 +503,23 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
// But X and Y since they need special treatment // But X and Y since they need special treatment
// X // X
int x = attributeDict["x"].asInt(); int x = attributeDict["x"].toInt();
// Y // Y
int y = attributeDict["y"].asInt(); int y = attributeDict["y"].toInt();
Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().y - attributeDict["height"].asInt()); Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().y - attributeDict["height"].toInt());
p = CC_POINT_PIXELS_TO_POINTS(p); p = CC_POINT_PIXELS_TO_POINTS(p);
dict["x"] = Value(p.x); dict["x"] = Value(p.x);
dict["y"] = Value(p.y); dict["y"] = Value(p.y);
int width = attributeDict["width"].asInt(); int width = attributeDict["width"].toInt();
int height = attributeDict["height"].asInt(); int height = attributeDict["height"].toInt();
Size s(width, height); Size s(width, height);
s = CC_SIZE_PIXELS_TO_POINTS(s); s = CC_SIZE_PIXELS_TO_POINTS(s);
dict["width"] = Value(s.width); dict["width"] = Value(s.width);
dict["height"] = Value(s.height); dict["height"] = Value(s.height);
dict["rotation"] = attributeDict["rotation"].asDouble(); dict["rotation"] = attributeDict["rotation"].toDouble();
// Add the object to the objectGroup // Add the object to the objectGroup
objectGroup->getObjects().push_back(Value(dict)); objectGroup->getObjects().push_back(Value(dict));

View File

@ -144,7 +144,7 @@ void TileMapAtlas::setTile(const Color3B& tile, const Vec2& position)
// FIXME:: this method consumes a lot of memory // FIXME:: this method consumes a lot of memory
// FIXME:: a tree of something like that shall be implemented // FIXME:: a tree of something like that shall be implemented
std::string key = StringUtils::toString(position.x) + "," + StringUtils::toString(position.y); std::string key = StringUtils::toString(position.x) + "," + StringUtils::toString(position.y);
int num = _posToAtlasIndex[key].asInt(); int num = _posToAtlasIndex[key].toInt();
this->updateAtlasValueAt(position, tile, num); this->updateAtlasValueAt(position, tile, num);
} }

View File

@ -339,7 +339,7 @@ void Configuration::loadConfigFile(const std::string& filename)
if (formatIter != metadata.cend()) if (formatIter != metadata.cend())
{ {
int format = formatIter->second.asInt(); int format = formatIter->second.toInt();
// Support format: 1 // Support format: 1
if (format == 1) if (format == 1)
@ -376,25 +376,25 @@ void Configuration::loadConfigFile(const std::string& filename)
//light info //light info
std::string name = "cocos2d.x.3d.max_dir_light_in_shader"; std::string name = "cocos2d.x.3d.max_dir_light_in_shader";
if (_valueDict.find(name) != _valueDict.end()) if (_valueDict.find(name) != _valueDict.end())
_maxDirLightInShader = _valueDict[name].asInt(); _maxDirLightInShader = _valueDict[name].toInt();
else else
_valueDict[name] = Value(_maxDirLightInShader); _valueDict[name] = Value(_maxDirLightInShader);
name = "cocos2d.x.3d.max_point_light_in_shader"; name = "cocos2d.x.3d.max_point_light_in_shader";
if (_valueDict.find(name) != _valueDict.end()) if (_valueDict.find(name) != _valueDict.end())
_maxPointLightInShader = _valueDict[name].asInt(); _maxPointLightInShader = _valueDict[name].toInt();
else else
_valueDict[name] = Value(_maxPointLightInShader); _valueDict[name] = Value(_maxPointLightInShader);
name = "cocos2d.x.3d.max_spot_light_in_shader"; name = "cocos2d.x.3d.max_spot_light_in_shader";
if (_valueDict.find(name) != _valueDict.end()) if (_valueDict.find(name) != _valueDict.end())
_maxSpotLightInShader = _valueDict[name].asInt(); _maxSpotLightInShader = _valueDict[name].toInt();
else else
_valueDict[name] = Value(_maxSpotLightInShader); _valueDict[name] = Value(_maxSpotLightInShader);
name = "cocos2d.x.3d.animate_quality"; name = "cocos2d.x.3d.animate_quality";
if (_valueDict.find(name) != _valueDict.end()) if (_valueDict.find(name) != _valueDict.end())
_animate3DQuality = (Animate3DQuality)_valueDict[name].asInt(); _animate3DQuality = (Animate3DQuality)_valueDict[name].toInt();
else else
_valueDict[name] = Value((int)_animate3DQuality); _valueDict[name] = Value((int)_animate3DQuality);

View File

@ -203,11 +203,11 @@ void Director::setDefaultValues()
Configuration *conf = Configuration::getInstance(); Configuration *conf = Configuration::getInstance();
// default FPS // default FPS
float fps = conf->getValue("cocos2d.x.fps", Value(kDefaultFPS)).asFloat(); float fps = conf->getValue("cocos2d.x.fps", Value(kDefaultFPS)).toFloat();
_oldAnimationInterval = _animationInterval = 1.0f / fps; _oldAnimationInterval = _animationInterval = 1.0f / fps;
// Display FPS // Display FPS
_displayStats = conf->getValue("cocos2d.x.display_fps", Value(false)).asBool(); _displayStats = conf->getValue("cocos2d.x.display_fps", Value(false)).toBool();
// GL projection // GL projection
std::string projection = conf->getValue("cocos2d.x.gl.projection", Value("3d")).asString(); std::string projection = conf->getValue("cocos2d.x.gl.projection", Value("3d")).asString();
@ -221,7 +221,7 @@ void Director::setDefaultValues()
CCASSERT(false, "Invalid projection value"); CCASSERT(false, "Invalid projection value");
// Default pixel format for PNG images with alpha // Default pixel format for PNG images with alpha
std::string pixel_format = conf->getValue("cocos2d.x.texture.pixel_format_for_png", Value("rgba8888")).asString(); std::string pixel_format = conf->getValue("cocos2d.x.texture.pixel_format_for_png", Value("rgba8888")).toString();
if (pixel_format == "rgba8888") if (pixel_format == "rgba8888")
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8888); Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8888);
else if(pixel_format == "rgba4444") else if(pixel_format == "rgba4444")
@ -230,7 +230,7 @@ void Director::setDefaultValues()
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB5A1); Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB5A1);
// PVR v2 has alpha premultiplied ? // PVR v2 has alpha premultiplied ?
bool pvr_alpha_premultiplied = conf->getValue("cocos2d.x.texture.pvrv2_has_alpha_premultiplied", Value(false)).asBool(); bool pvr_alpha_premultiplied = conf->getValue("cocos2d.x.texture.pvrv2_has_alpha_premultiplied", Value(false)).toBool();
Image::setPVRImagesHavePremultipliedAlpha(pvr_alpha_premultiplied); Image::setPVRImagesHavePremultipliedAlpha(pvr_alpha_premultiplied);
} }

View File

@ -37,6 +37,8 @@ const ValueMapIntKey ValueMapIntKeyNull;
const Value Value::Null; const Value Value::Null;
const std::string Value::NullString;
Value::Value() Value::Value()
: _type(Type::NONE) : _type(Type::NONE)
{ {
@ -440,7 +442,7 @@ bool Value::operator== (const Value& v) const
} }
/// Convert value to a specified type /// Convert value to a specified type
unsigned char Value::asByte() const unsigned char Value::toByte() const
{ {
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted"); CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
@ -482,7 +484,7 @@ unsigned char Value::asByte() const
return 0; return 0;
} }
int Value::asInt() const int Value::toInt() const
{ {
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted"); CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
if (_type == Type::INTEGER) if (_type == Type::INTEGER)
@ -525,7 +527,7 @@ int Value::asInt() const
} }
unsigned int Value::asUnsignedInt() const unsigned int Value::toUnsignedInt() const
{ {
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted"); CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
if (_type == Type::UNSIGNED) if (_type == Type::UNSIGNED)
@ -568,7 +570,7 @@ unsigned int Value::asUnsignedInt() const
return 0u; return 0u;
} }
float Value::asFloat() const float Value::toFloat() const
{ {
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted"); CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
if (_type == Type::FLOAT) if (_type == Type::FLOAT)
@ -609,7 +611,7 @@ float Value::asFloat() const
return 0.0f; return 0.0f;
} }
double Value::asDouble() const double Value::toDouble() const
{ {
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted"); CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
if (_type == Type::DOUBLE) if (_type == Type::DOUBLE)
@ -650,7 +652,7 @@ double Value::asDouble() const
return 0.0; return 0.0;
} }
bool Value::asBool() const bool Value::toBool() const
{ {
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted"); CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
if (_type == Type::BOOLEAN) if (_type == Type::BOOLEAN)
@ -691,18 +693,6 @@ bool Value::asBool() const
return false; return false;
} }
std::string& Value::asString()
{
CCASSERT(_type == Type::STRING, "The value type isn't Type::STRING");
return *_field.strVal;
}
const std::string& Value::asString() const
{
CCASSERT(_type == Type::STRING, "The value type isn't Type::STRING");
return *_field.strVal;
}
std::string Value::toString() const std::string Value::toString() const
{ {
CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted"); CCASSERT(_type != Type::VECTOR && _type != Type::MAP && _type != Type::INT_KEY_MAP, "Only base type (bool, string, float, double, int) could be converted");
@ -740,6 +730,18 @@ std::string Value::toString() const
return ret.str(); return ret.str();
} }
const std::string& Value::asString() const
{
if (_type == Type::STRING)
return *_field.strVal;
return Value::NullString;
}
const std::string& Value::asStringUnsafe() const
{
CCASSERT(_type == Type::STRING, "The value type isn't Type::STRING");
return *_field.strVal;
}
ValueVector& Value::asValueVector() ValueVector& Value::asValueVector()
{ {

View File

@ -57,6 +57,7 @@ class CC_DLL Value
public: public:
/** A predefined Value that has not value. */ /** A predefined Value that has not value. */
static const Value Null; static const Value Null;
static const std::string NullString;
/** Default constructor. */ /** Default constructor. */
Value(); Value();
@ -155,25 +156,24 @@ public:
bool operator== (const Value& v) const; bool operator== (const Value& v) const;
/** Gets as a byte value. Will convert to unsigned char if possible, or will trigger assert error. */ /** Gets as a byte value. Will convert to unsigned char if possible, or will trigger assert error. */
unsigned char asByte() const; unsigned char toByte() const;
/** Gets as an integer value. Will convert to integer if possible, or will trigger assert error. */ /** Gets as an integer value. Will convert to integer if possible, or will trigger assert error. */
int asInt() const; int toInt() const;
/** Gets as an unsigned value. Will convert to unsigned if possible, or will trigger assert error. */ /** Gets as an unsigned value. Will convert to unsigned if possible, or will trigger assert error. */
unsigned int asUnsignedInt() const; unsigned int toUnsignedInt() const;
/** Gets as a float value. Will convert to float if possible, or will trigger assert error. */ /** Gets as a float value. Will convert to float if possible, or will trigger assert error. */
float asFloat() const; float toFloat() const;
/** Gets as a double value. Will convert to double if possible, or will trigger assert error. */ /** Gets as a double value. Will convert to double if possible, or will trigger assert error. */
double asDouble() const; double toDouble() const;
/** Gets as a bool value. Will convert to bool if possible, or will trigger assert error. */ /** Gets as a bool value. Will convert to bool if possible, or will trigger assert error. */
bool asBool() const; bool toBool() const;
/** Gets as a string value. Will convert to string if possible, or will trigger assert error. */
std::string& asString();
/** Gets as a string value. Will convert to string if possible, or will trigger assert error. */
const std::string& asString() const;
/** to as a string value. Will convert to string if possible, or will trigger assert error. */ /** to as a string value. Will convert to string if possible, or will trigger assert error. */
std::string toString() const; std::string toString() const;
/** Gets as a string value. Will convert to string if possible, or will trigger assert error. */
const std::string& asString() const;
const std::string& asStringUnsafe() const;
/** Gets as a ValueVector reference. Will convert to ValueVector if possible, or will trigger assert error. */ /** Gets as a ValueVector reference. Will convert to ValueVector if possible, or will trigger assert error. */
ValueVector& asValueVector(); ValueVector& asValueVector();
/** Gets as a const ValueVector reference. Will convert to ValueVector if possible, or will trigger assert error. */ /** Gets as a const ValueVector reference. Will convert to ValueVector if possible, or will trigger assert error. */

View File

@ -73,7 +73,7 @@ int ComAttribute::getInt(const std::string& key, int def) const
if (_dict.find(key) != _dict.end()) if (_dict.find(key) != _dict.end())
{ {
const cocos2d::Value& v = _dict.at(key); const cocos2d::Value& v = _dict.at(key);
return v.asInt(); return v.toInt();
} }
if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) if (!DICTOOL->checkObjectExist_json(_doc, key.c_str()))
@ -89,7 +89,7 @@ float ComAttribute::getFloat(const std::string& key, float def) const
if (_dict.find(key) != _dict.end()) if (_dict.find(key) != _dict.end())
{ {
const cocos2d::Value& v = _dict.at(key); const cocos2d::Value& v = _dict.at(key);
return v.asFloat(); return v.toFloat();
} }
if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) if (!DICTOOL->checkObjectExist_json(_doc, key.c_str()))
@ -104,7 +104,7 @@ bool ComAttribute::getBool(const std::string& key, bool def) const
if (_dict.find(key) != _dict.end()) if (_dict.find(key) != _dict.end())
{ {
const cocos2d::Value& v = _dict.at(key); const cocos2d::Value& v = _dict.at(key);
return v.asBool(); return v.toBool();
} }
if (!DICTOOL->checkObjectExist_json(_doc, key.c_str())) if (!DICTOOL->checkObjectExist_json(_doc, key.c_str()))

View File

@ -158,8 +158,8 @@ cocos2d::Size GUIReader::getFileDesignSize(const char* fileName) const
keyWidth.append("width"); keyWidth.append("width");
std::string keyHeight = fileName; std::string keyHeight = fileName;
keyHeight.append("height"); keyHeight.append("height");
float w = _fileDesignSizes.at(keyWidth).asFloat(); float w = _fileDesignSizes.at(keyWidth).toFloat();
float h = _fileDesignSizes.at(keyHeight).asFloat(); float h = _fileDesignSizes.at(keyHeight).toFloat();
return Size(w, h); return Size(w, h);
} }

View File

@ -1002,7 +1002,7 @@ void FileUtils::loadFilenameLookupDictionaryFromFile(const std::string &filename
if (!dict.empty()) if (!dict.empty())
{ {
ValueMap& metadata = dict["metadata"].asValueMap(); ValueMap& metadata = dict["metadata"].asValueMap();
int version = metadata["version"].asInt(); int version = metadata["version"].toInt();
if (version != 1) if (version != 1)
{ {
CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %d. Filename: %s", version, filename.c_str()); CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %d. Filename: %s", version, filename.c_str());

View File

@ -73,22 +73,22 @@ static id convertCCValueToNSObject(const cocos2d::Value &value)
return [NSString stringWithCString:value.asString().c_str() encoding:NSUTF8StringEncoding]; return [NSString stringWithCString:value.asString().c_str() encoding:NSUTF8StringEncoding];
case Value::Type::BYTE: case Value::Type::BYTE:
return [NSNumber numberWithInt:value.asByte()]; return [NSNumber numberWithInt:value.toByte()];
case Value::Type::INTEGER: case Value::Type::INTEGER:
return [NSNumber numberWithInt:value.asInt()]; return [NSNumber numberWithInt:value.toInt()];
case Value::Type::UNSIGNED: case Value::Type::UNSIGNED:
return [NSNumber numberWithUnsignedInt:value.asUnsignedInt()]; return [NSNumber numberWithUnsignedInt:value.toUnsignedInt()];
case Value::Type::FLOAT: case Value::Type::FLOAT:
return [NSNumber numberWithFloat:value.asFloat()]; return [NSNumber numberWithFloat:value.toFloat()];
case Value::Type::DOUBLE: case Value::Type::DOUBLE:
return [NSNumber numberWithDouble:value.asDouble()]; return [NSNumber numberWithDouble:value.toDouble()];
case Value::Type::BOOLEAN: case Value::Type::BOOLEAN:
return [NSNumber numberWithBool:value.asBool()]; return [NSNumber numberWithBool:value.toBool()];
case Value::Type::VECTOR: { case Value::Type::VECTOR: {
NSMutableArray *array = [NSMutableArray array]; NSMutableArray *array = [NSMutableArray array];

View File

@ -2758,14 +2758,14 @@ void ccvalue_to_luaval(lua_State* L,const cocos2d::Value& inValue)
switch (obj.getType()) switch (obj.getType())
{ {
case Value::Type::BOOLEAN: case Value::Type::BOOLEAN:
lua_pushboolean(L, obj.asBool()); lua_pushboolean(L, obj.toBool());
break; break;
case Value::Type::FLOAT: case Value::Type::FLOAT:
case Value::Type::DOUBLE: case Value::Type::DOUBLE:
lua_pushnumber(L, obj.asDouble()); lua_pushnumber(L, obj.toDouble());
break; break;
case Value::Type::INTEGER: case Value::Type::INTEGER:
lua_pushinteger(L, obj.asInt()); lua_pushinteger(L, obj.toInt());
break; break;
case Value::Type::STRING: case Value::Type::STRING:
lua_pushstring(L, obj.asString().c_str()); lua_pushstring(L, obj.asString().c_str());
@ -2799,7 +2799,7 @@ void ccvaluemap_to_luaval(lua_State* L,const cocos2d::ValueMap& inValue)
case Value::Type::BOOLEAN: case Value::Type::BOOLEAN:
{ {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
lua_pushboolean(L, obj.asBool()); lua_pushboolean(L, obj.toBool());
lua_rawset(L, -3); lua_rawset(L, -3);
} }
break; break;
@ -2807,14 +2807,14 @@ void ccvaluemap_to_luaval(lua_State* L,const cocos2d::ValueMap& inValue)
case Value::Type::DOUBLE: case Value::Type::DOUBLE:
{ {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
lua_pushnumber(L, obj.asDouble()); lua_pushnumber(L, obj.toDouble());
lua_rawset(L, -3); lua_rawset(L, -3);
} }
break; break;
case Value::Type::INTEGER: case Value::Type::INTEGER:
{ {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
lua_pushinteger(L, obj.asInt()); lua_pushinteger(L, obj.toInt());
lua_rawset(L, -3); lua_rawset(L, -3);
} }
break; break;
@ -2871,7 +2871,7 @@ void ccvaluemapintkey_to_luaval(lua_State* L, const cocos2d::ValueMapIntKey& inV
case Value::Type::BOOLEAN: case Value::Type::BOOLEAN:
{ {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
lua_pushboolean(L, obj.asBool()); lua_pushboolean(L, obj.toBool());
lua_rawset(L, -3); lua_rawset(L, -3);
} }
break; break;
@ -2879,14 +2879,14 @@ void ccvaluemapintkey_to_luaval(lua_State* L, const cocos2d::ValueMapIntKey& inV
case Value::Type::DOUBLE: case Value::Type::DOUBLE:
{ {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
lua_pushnumber(L, obj.asDouble()); lua_pushnumber(L, obj.toDouble());
lua_rawset(L, -3); lua_rawset(L, -3);
} }
break; break;
case Value::Type::INTEGER: case Value::Type::INTEGER:
{ {
lua_pushstring(L, key.c_str()); lua_pushstring(L, key.c_str());
lua_pushinteger(L, obj.asInt()); lua_pushinteger(L, obj.toInt());
lua_rawset(L, -3); lua_rawset(L, -3);
} }
break; break;
@ -2938,7 +2938,7 @@ void ccvaluevector_to_luaval(lua_State* L, const cocos2d::ValueVector& inValue)
case Value::Type::BOOLEAN: case Value::Type::BOOLEAN:
{ {
lua_pushnumber(L, (lua_Number)index); lua_pushnumber(L, (lua_Number)index);
lua_pushboolean(L, obj.asBool()); lua_pushboolean(L, obj.toBool());
lua_rawset(L, -3); lua_rawset(L, -3);
++index; ++index;
} }
@ -2947,7 +2947,7 @@ void ccvaluevector_to_luaval(lua_State* L, const cocos2d::ValueVector& inValue)
case Value::Type::DOUBLE: case Value::Type::DOUBLE:
{ {
lua_pushnumber(L, (lua_Number)index); lua_pushnumber(L, (lua_Number)index);
lua_pushnumber(L, obj.asDouble()); lua_pushnumber(L, obj.toDouble());
lua_rawset(L, -3); lua_rawset(L, -3);
++index; ++index;
} }
@ -2955,7 +2955,7 @@ void ccvaluevector_to_luaval(lua_State* L, const cocos2d::ValueVector& inValue)
case Value::Type::INTEGER: case Value::Type::INTEGER:
{ {
lua_pushnumber(L, (lua_Number)index); lua_pushnumber(L, (lua_Number)index);
lua_pushnumber(L, obj.asInt()); lua_pushnumber(L, obj.toInt());
lua_rawset(L, -3); lua_rawset(L, -3);
++index; ++index;
} }

View File

@ -429,16 +429,16 @@ MyXMLVisitor::MyXMLVisitor(RichText* richText)
src = tagAttrValueMap.at("src").asString(); src = tagAttrValueMap.at("src").asString();
} }
if (tagAttrValueMap.find("height") != tagAttrValueMap.end()) { if (tagAttrValueMap.find("height") != tagAttrValueMap.end()) {
height = tagAttrValueMap.at("height").asInt(); height = tagAttrValueMap.at("height").toInt();
} }
if (tagAttrValueMap.find("width") != tagAttrValueMap.end()) { if (tagAttrValueMap.find("width") != tagAttrValueMap.end()) {
width = tagAttrValueMap.at("width").asInt(); width = tagAttrValueMap.at("width").toInt();
} }
if (tagAttrValueMap.find("type") != tagAttrValueMap.end()) { if (tagAttrValueMap.find("type") != tagAttrValueMap.end()) {
// texture type // texture type
// 0: normal file path // 0: normal file path
// 1: sprite frame name // 1: sprite frame name
int type = tagAttrValueMap.at("type").asInt(); int type = tagAttrValueMap.at("type").toInt();
resType = type == 0 ? Widget::TextureResType::LOCAL : Widget::TextureResType::PLIST; resType = type == 0 ? Widget::TextureResType::LOCAL : Widget::TextureResType::PLIST;
} }
@ -643,7 +643,7 @@ void MyXMLVisitor::startElement(void* /*ctx*/, const char *elementName, const ch
Attributes attributes; Attributes attributes;
if (attrValueMap.find(RichText::KEY_FONT_SIZE) != attrValueMap.end()) { if (attrValueMap.find(RichText::KEY_FONT_SIZE) != attrValueMap.end()) {
attributes.fontSize = attrValueMap.at(RichText::KEY_FONT_SIZE).asFloat(); attributes.fontSize = attrValueMap.at(RichText::KEY_FONT_SIZE).toFloat();
} }
if (attrValueMap.find(RichText::KEY_FONT_SMALL) != attrValueMap.end()) { if (attrValueMap.find(RichText::KEY_FONT_SMALL) != attrValueMap.end()) {
attributes.fontSize = getFontSize() * 0.8f; attributes.fontSize = getFontSize() * 0.8f;
@ -711,7 +711,7 @@ void MyXMLVisitor::startElement(void* /*ctx*/, const char *elementName, const ch
attributes.outlineColor = _richText->color3BWithString(attrValueMap.at(RichText::KEY_TEXT_OUTLINE_COLOR).asString()); attributes.outlineColor = _richText->color3BWithString(attrValueMap.at(RichText::KEY_TEXT_OUTLINE_COLOR).asString());
} }
if (attrValueMap.find(RichText::KEY_TEXT_OUTLINE_SIZE) != attrValueMap.end()) { if (attrValueMap.find(RichText::KEY_TEXT_OUTLINE_SIZE) != attrValueMap.end()) {
attributes.outlineSize = attrValueMap.at(RichText::KEY_TEXT_OUTLINE_SIZE).asInt(); attributes.outlineSize = attrValueMap.at(RichText::KEY_TEXT_OUTLINE_SIZE).toInt();
} }
} }
else if (keyTextStyle == RichText::VALUE_TEXT_STYLE_SHADOW) { else if (keyTextStyle == RichText::VALUE_TEXT_STYLE_SHADOW) {
@ -721,11 +721,11 @@ void MyXMLVisitor::startElement(void* /*ctx*/, const char *elementName, const ch
} }
if ((attrValueMap.find(RichText::KEY_TEXT_SHADOW_OFFSET_WIDTH) != attrValueMap.end()) if ((attrValueMap.find(RichText::KEY_TEXT_SHADOW_OFFSET_WIDTH) != attrValueMap.end())
&& (attrValueMap.find(RichText::KEY_TEXT_SHADOW_OFFSET_HEIGHT) != attrValueMap.end())) { && (attrValueMap.find(RichText::KEY_TEXT_SHADOW_OFFSET_HEIGHT) != attrValueMap.end())) {
attributes.shadowOffset = Size(attrValueMap.at(RichText::KEY_TEXT_SHADOW_OFFSET_WIDTH).asFloat(), attributes.shadowOffset = Size(attrValueMap.at(RichText::KEY_TEXT_SHADOW_OFFSET_WIDTH).toFloat(),
attrValueMap.at(RichText::KEY_TEXT_SHADOW_OFFSET_HEIGHT).asFloat()); attrValueMap.at(RichText::KEY_TEXT_SHADOW_OFFSET_HEIGHT).toFloat());
} }
if (attrValueMap.find(RichText::KEY_TEXT_SHADOW_BLUR_RADIUS) != attrValueMap.end()) { if (attrValueMap.find(RichText::KEY_TEXT_SHADOW_BLUR_RADIUS) != attrValueMap.end()) {
attributes.shadowBlurRadius = attrValueMap.at(RichText::KEY_TEXT_SHADOW_BLUR_RADIUS).asInt(); attributes.shadowBlurRadius = attrValueMap.at(RichText::KEY_TEXT_SHADOW_BLUR_RADIUS).toInt();
} }
} }
else if (keyTextStyle == RichText::VALUE_TEXT_STYLE_GLOW) { else if (keyTextStyle == RichText::VALUE_TEXT_STYLE_GLOW) {
@ -995,12 +995,12 @@ void RichText::removeElement(RichElement *element)
RichText::WrapMode RichText::getWrapMode() const RichText::WrapMode RichText::getWrapMode() const
{ {
return static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).asInt()); return static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).toInt());
} }
void RichText::setWrapMode(RichText::WrapMode wrapMode) void RichText::setWrapMode(RichText::WrapMode wrapMode)
{ {
if (static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).asInt()) != wrapMode) if (static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).toInt()) != wrapMode)
{ {
_defaults[KEY_WRAP_MODE] = static_cast<int>(wrapMode); _defaults[KEY_WRAP_MODE] = static_cast<int>(wrapMode);
_formatTextDirty = true; _formatTextDirty = true;
@ -1009,12 +1009,12 @@ void RichText::setWrapMode(RichText::WrapMode wrapMode)
RichText::HorizontalAlignment RichText::getHorizontalAlignment() const RichText::HorizontalAlignment RichText::getHorizontalAlignment() const
{ {
return static_cast<RichText::HorizontalAlignment>(_defaults.at(KEY_HORIZONTAL_ALIGNMENT).asInt()); return static_cast<RichText::HorizontalAlignment>(_defaults.at(KEY_HORIZONTAL_ALIGNMENT).toInt());
} }
void RichText::setHorizontalAlignment(cocos2d::ui::RichText::HorizontalAlignment a) void RichText::setHorizontalAlignment(cocos2d::ui::RichText::HorizontalAlignment a)
{ {
if (static_cast<RichText::HorizontalAlignment>(_defaults.at(KEY_HORIZONTAL_ALIGNMENT).asInt()) != a) if (static_cast<RichText::HorizontalAlignment>(_defaults.at(KEY_HORIZONTAL_ALIGNMENT).toInt()) != a)
{ {
_defaults[KEY_HORIZONTAL_ALIGNMENT] = static_cast<int>(a); _defaults[KEY_HORIZONTAL_ALIGNMENT] = static_cast<int>(a);
_formatTextDirty = true; _formatTextDirty = true;
@ -1043,7 +1043,7 @@ void RichText::setFontSize(float size)
float RichText::getFontSize() float RichText::getFontSize()
{ {
return _defaults.at(KEY_FONT_SIZE).asFloat(); return _defaults.at(KEY_FONT_SIZE).toFloat();
} }
void RichText::setFontFace(const std::string& face) void RichText::setFontFace(const std::string& face)
@ -1078,7 +1078,7 @@ void RichText::setAnchorTextBold(bool enable)
bool RichText::isAnchorTextBoldEnabled() bool RichText::isAnchorTextBoldEnabled()
{ {
return _defaults[KEY_ANCHOR_TEXT_BOLD].asBool(); return _defaults[KEY_ANCHOR_TEXT_BOLD].toBool();
} }
void RichText::setAnchorTextItalic(bool enable) void RichText::setAnchorTextItalic(bool enable)
@ -1088,7 +1088,7 @@ void RichText::setAnchorTextItalic(bool enable)
bool RichText::isAnchorTextItalicEnabled() bool RichText::isAnchorTextItalicEnabled()
{ {
return _defaults[KEY_ANCHOR_TEXT_ITALIC].asBool(); return _defaults[KEY_ANCHOR_TEXT_ITALIC].toBool();
} }
void RichText::setAnchorTextDel(bool enable) void RichText::setAnchorTextDel(bool enable)
@ -1143,7 +1143,7 @@ Color3B RichText::getAnchorTextOutlineColor3B()
int RichText::getAnchorTextOutlineSize() int RichText::getAnchorTextOutlineSize()
{ {
if (_defaults.find(KEY_ANCHOR_TEXT_OUTLINE_SIZE) != _defaults.end()) { if (_defaults.find(KEY_ANCHOR_TEXT_OUTLINE_SIZE) != _defaults.end()) {
return _defaults.at(KEY_ANCHOR_TEXT_OUTLINE_SIZE).asInt(); return _defaults.at(KEY_ANCHOR_TEXT_OUTLINE_SIZE).toInt();
} }
return -1; return -1;
} }
@ -1178,10 +1178,10 @@ Size RichText::getAnchorTextShadowOffset()
float width = 2.0f; float width = 2.0f;
float height = -2.0f; float height = -2.0f;
if (_defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH) != _defaults.end()) { if (_defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH) != _defaults.end()) {
width = _defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH).asFloat(); width = _defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH).toFloat();
} }
if (_defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT) != _defaults.end()) { if (_defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT) != _defaults.end()) {
height = _defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT).asFloat(); height = _defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT).toFloat();
} }
return Size(width, height); return Size(width, height);
} }
@ -1189,7 +1189,7 @@ Size RichText::getAnchorTextShadowOffset()
int RichText::getAnchorTextShadowBlurRadius() int RichText::getAnchorTextShadowBlurRadius()
{ {
if (_defaults.find(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS) != _defaults.end()) { if (_defaults.find(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS) != _defaults.end()) {
return _defaults.at(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS).asInt(); return _defaults.at(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS).toInt();
} }
return 0; return 0;
} }
@ -1219,19 +1219,19 @@ Color3B RichText::getAnchorTextGlowColor3B()
void RichText::setDefaults(const ValueMap& defaults) void RichText::setDefaults(const ValueMap& defaults)
{ {
if (defaults.find(KEY_VERTICAL_SPACE) != defaults.end()) { if (defaults.find(KEY_VERTICAL_SPACE) != defaults.end()) {
_defaults[KEY_VERTICAL_SPACE] = defaults.at(KEY_VERTICAL_SPACE).asFloat(); _defaults[KEY_VERTICAL_SPACE] = defaults.at(KEY_VERTICAL_SPACE).toFloat();
} }
if (defaults.find(KEY_WRAP_MODE) != defaults.end()) { if (defaults.find(KEY_WRAP_MODE) != defaults.end()) {
_defaults[KEY_WRAP_MODE] = defaults.at(KEY_WRAP_MODE).asInt(); _defaults[KEY_WRAP_MODE] = defaults.at(KEY_WRAP_MODE).toInt();
} }
if (defaults.find(KEY_HORIZONTAL_ALIGNMENT) != defaults.end()) { if (defaults.find(KEY_HORIZONTAL_ALIGNMENT) != defaults.end()) {
_defaults[KEY_HORIZONTAL_ALIGNMENT] = defaults.at(KEY_HORIZONTAL_ALIGNMENT).asInt(); _defaults[KEY_HORIZONTAL_ALIGNMENT] = defaults.at(KEY_HORIZONTAL_ALIGNMENT).toInt();
} }
if (defaults.find(KEY_FONT_COLOR_STRING) != defaults.end()) { if (defaults.find(KEY_FONT_COLOR_STRING) != defaults.end()) {
_defaults[KEY_FONT_COLOR_STRING] = defaults.at(KEY_FONT_COLOR_STRING).asString(); _defaults[KEY_FONT_COLOR_STRING] = defaults.at(KEY_FONT_COLOR_STRING).asString();
} }
if (defaults.find(KEY_FONT_SIZE) != defaults.end()) { if (defaults.find(KEY_FONT_SIZE) != defaults.end()) {
_defaults[KEY_FONT_SIZE] = defaults.at(KEY_FONT_SIZE).asFloat(); _defaults[KEY_FONT_SIZE] = defaults.at(KEY_FONT_SIZE).toFloat();
} }
if (defaults.find(KEY_FONT_FACE) != defaults.end()) { if (defaults.find(KEY_FONT_FACE) != defaults.end()) {
_defaults[KEY_FONT_FACE] = defaults.at(KEY_FONT_FACE).asString(); _defaults[KEY_FONT_FACE] = defaults.at(KEY_FONT_FACE).asString();
@ -1240,10 +1240,10 @@ void RichText::setDefaults(const ValueMap& defaults)
_defaults[KEY_ANCHOR_FONT_COLOR_STRING] = defaults.at(KEY_ANCHOR_FONT_COLOR_STRING).asString(); _defaults[KEY_ANCHOR_FONT_COLOR_STRING] = defaults.at(KEY_ANCHOR_FONT_COLOR_STRING).asString();
} }
if (defaults.find(KEY_ANCHOR_TEXT_BOLD) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_BOLD) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_BOLD] = defaults.at(KEY_ANCHOR_TEXT_BOLD).asBool(); _defaults[KEY_ANCHOR_TEXT_BOLD] = defaults.at(KEY_ANCHOR_TEXT_BOLD).toBool();
} }
if (defaults.find(KEY_ANCHOR_TEXT_ITALIC) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_ITALIC) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_ITALIC] = defaults.at(KEY_ANCHOR_TEXT_ITALIC).asBool(); _defaults[KEY_ANCHOR_TEXT_ITALIC] = defaults.at(KEY_ANCHOR_TEXT_ITALIC).toBool();
} }
if (defaults.find(KEY_ANCHOR_TEXT_LINE) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_LINE) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_LINE] = defaults.at(KEY_ANCHOR_TEXT_LINE).asString(); _defaults[KEY_ANCHOR_TEXT_LINE] = defaults.at(KEY_ANCHOR_TEXT_LINE).asString();
@ -1255,19 +1255,19 @@ void RichText::setDefaults(const ValueMap& defaults)
_defaults[KEY_ANCHOR_TEXT_OUTLINE_COLOR] = defaults.at(KEY_ANCHOR_TEXT_OUTLINE_COLOR).asString(); _defaults[KEY_ANCHOR_TEXT_OUTLINE_COLOR] = defaults.at(KEY_ANCHOR_TEXT_OUTLINE_COLOR).asString();
} }
if (defaults.find(KEY_ANCHOR_TEXT_OUTLINE_SIZE) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_OUTLINE_SIZE) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_OUTLINE_SIZE] = defaults.at(KEY_ANCHOR_TEXT_OUTLINE_SIZE).asInt(); _defaults[KEY_ANCHOR_TEXT_OUTLINE_SIZE] = defaults.at(KEY_ANCHOR_TEXT_OUTLINE_SIZE).toInt();
} }
if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_COLOR) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_COLOR) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_SHADOW_COLOR] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_COLOR).asString(); _defaults[KEY_ANCHOR_TEXT_SHADOW_COLOR] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_COLOR).asString();
} }
if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH).asFloat(); _defaults[KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH).toFloat();
} }
if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT).asFloat(); _defaults[KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT).toFloat();
} }
if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS).asInt(); _defaults[KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS] = defaults.at(KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS).toInt();
} }
if (defaults.find(KEY_ANCHOR_TEXT_GLOW_COLOR) != defaults.end()) { if (defaults.find(KEY_ANCHOR_TEXT_GLOW_COLOR) != defaults.end()) {
_defaults[KEY_ANCHOR_TEXT_GLOW_COLOR] = defaults.at(KEY_ANCHOR_TEXT_GLOW_COLOR).asString(); _defaults[KEY_ANCHOR_TEXT_GLOW_COLOR] = defaults.at(KEY_ANCHOR_TEXT_GLOW_COLOR).asString();
@ -1645,7 +1645,7 @@ void RichText::handleTextRenderer(const std::string& text, const std::string& fo
const Color3B& glowColor) const Color3B& glowColor)
{ {
bool fileExist = FileUtils::getInstance()->isFileExist(fontName); bool fileExist = FileUtils::getInstance()->isFileExist(fontName);
RichText::WrapMode wrapMode = static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).asInt()); RichText::WrapMode wrapMode = static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).toInt());
// split text by \n // split text by \n
std::stringstream ss(text); std::stringstream ss(text);
@ -1784,8 +1784,8 @@ void RichText::addNewLine()
void RichText::formatRenderers() void RichText::formatRenderers()
{ {
float verticalSpace = _defaults[KEY_VERTICAL_SPACE].asFloat(); float verticalSpace = _defaults[KEY_VERTICAL_SPACE].toFloat();
float fontSize = _defaults[KEY_FONT_SIZE].asFloat(); float fontSize = _defaults[KEY_FONT_SIZE].toFloat();
if (_ignoreSize) if (_ignoreSize)
{ {
@ -1890,7 +1890,7 @@ namespace {
} }
void RichText::doHorizontalAlignment(const Vector<cocos2d::Node*> &row, float rowWidth) { void RichText::doHorizontalAlignment(const Vector<cocos2d::Node*> &row, float rowWidth) {
const auto alignment = static_cast<HorizontalAlignment>(_defaults.at(KEY_HORIZONTAL_ALIGNMENT).asInt()); const auto alignment = static_cast<HorizontalAlignment>(_defaults.at(KEY_HORIZONTAL_ALIGNMENT).toInt());
if ( alignment != HorizontalAlignment::LEFT ) { if ( alignment != HorizontalAlignment::LEFT ) {
const auto diff = stripTrailingWhitespace(row); const auto diff = stripTrailingWhitespace(row);
const auto leftOver = getContentSize().width - (rowWidth + diff); const auto leftOver = getContentSize().width - (rowWidth + diff);

View File

@ -112,13 +112,13 @@ void ConfigurationDefault::onEnter()
else else
log("1. Test OK!"); log("1. Test OK!");
bool b_value = Configuration::getInstance()->getValue("invalid.key", Value(true)).asBool(); bool b_value = Configuration::getInstance()->getValue("invalid.key", Value(true)).toBool();
if( ! b_value ) if( ! b_value )
log("2. Test failed!"); log("2. Test failed!");
else else
log("2. Test OK!"); log("2. Test OK!");
double d_value = Configuration::getInstance()->getValue("invalid.key", Value(42.42)).asDouble(); double d_value = Configuration::getInstance()->getValue("invalid.key", Value(42.42)).toDouble();
if( d_value != 42.42 ) if( d_value != 42.42 )
log("3. Test failed!"); log("3. Test failed!");
else else

View File

@ -817,16 +817,16 @@ void TestWriteValueMap::onEnter()
readDataStr += " vectorValue:[2]" + readVectorInMap.at(1).asString() + "\n"; readDataStr += " vectorValue:[2]" + readVectorInMap.at(1).asString() + "\n";
// read bool data // read bool data
readDataStr += " boolValue:" + StringUtils::format("%d", readValueMap["data3"].asBool()) + "\n"; readDataStr += " boolValue:" + StringUtils::format("%d", readValueMap["data3"].toBool()) + "\n";
// read int data // read int data
readDataStr += " intValue:" + StringUtils::format("%d", readValueMap["data4"].asInt()) + "\n"; readDataStr += " intValue:" + StringUtils::format("%d", readValueMap["data4"].toInt()) + "\n";
// read float data // read float data
readDataStr += " floatValue:" + StringUtils::format("%f", readValueMap["data5"].asFloat()) + "\n"; readDataStr += " floatValue:" + StringUtils::format("%f", readValueMap["data5"].toFloat()) + "\n";
// read double data // read double data
readDataStr += " doubleValue:" + StringUtils::format("%f", readValueMap["data6"].asDouble()) + "\n"; readDataStr += " doubleValue:" + StringUtils::format("%f", readValueMap["data6"].toDouble()) + "\n";
readResult->setString(readDataStr); readResult->setString(readDataStr);
} }
@ -920,16 +920,16 @@ void TestWriteValueVector::onEnter()
readDataStr += " vectorValue:[2]" + readVectorInArray.at(1).asString() + "\n"; readDataStr += " vectorValue:[2]" + readVectorInArray.at(1).asString() + "\n";
// read bool data // read bool data
readDataStr += " boolValue:" + StringUtils::format("%d", readArray.at(3).asBool()) + "\n"; readDataStr += " boolValue:" + StringUtils::format("%d", readArray.at(3).toBool()) + "\n";
// read int data // read int data
readDataStr += " intValue:" + StringUtils::format("%d", readArray.at(4).asInt()) + "\n"; readDataStr += " intValue:" + StringUtils::format("%d", readArray.at(4).toInt()) + "\n";
// read float data // read float data
readDataStr += " floatValue:" + StringUtils::format("%f", readArray.at(5).asFloat()) + "\n"; readDataStr += " floatValue:" + StringUtils::format("%f", readArray.at(5).toFloat()) + "\n";
// read double data // read double data
readDataStr += " doubleValue:" + StringUtils::format("%f", readArray.at(6).asDouble()) + "\n"; readDataStr += " doubleValue:" + StringUtils::format("%f", readArray.at(6).toDouble()) + "\n";
readResult->setString(readDataStr); readResult->setString(readDataStr);
} }

View File

@ -781,10 +781,10 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest()
{ {
ValueMap& dict = obj.asValueMap(); ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat(); float x = dict["x"].toFloat();
float y = dict["y"].asFloat(); float y = dict["y"].toFloat();
float width = dict["width"].asFloat(); float width = dict["width"].toFloat();
float height = dict["height"].asFloat(); float height = dict["height"].toFloat();
Color4F color(1.0, 1.0, 1.0, 1.0); Color4F color(1.0, 1.0, 1.0, 1.0);
@ -834,10 +834,10 @@ TMXIsoObjectsTest::TMXIsoObjectsTest()
{ {
ValueMap& dict = obj.asValueMap(); ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat(); float x = dict["x"].toFloat();
float y = dict["y"].asFloat(); float y = dict["y"].toFloat();
float width = dict["width"].asFloat(); float width = dict["width"].toFloat();
float height = dict["height"].asFloat(); float height = dict["height"].toFloat();
Color4F color(1.0, 1.0, 1.0, 1.0); Color4F color(1.0, 1.0, 1.0, 1.0);
@ -1512,10 +1512,10 @@ TMXGIDObjectsTest::TMXGIDObjectsTest()
{ {
ValueMap& dict = obj.asValueMap(); ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat(); float x = dict["x"].toFloat();
float y = dict["y"].asFloat(); float y = dict["y"].toFloat();
float width = dict["width"].asFloat(); float width = dict["width"].toFloat();
float height = dict["height"].asFloat(); float height = dict["height"].toFloat();
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color); drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color); drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);

View File

@ -671,10 +671,10 @@ TMXOrthoObjectsTestNew::TMXOrthoObjectsTestNew()
{ {
ValueMap& dict = obj.asValueMap(); ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat(); float x = dict["x"].toFloat();
float y = dict["y"].asFloat(); float y = dict["y"].toFloat();
float width = dict["width"].asFloat(); float width = dict["width"].toFloat();
float height = dict["height"].asFloat(); float height = dict["height"].toFloat();
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color); drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color); drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
@ -722,10 +722,10 @@ TMXIsoObjectsTestNew::TMXIsoObjectsTestNew()
{ {
ValueMap& dict = obj.asValueMap(); ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat(); float x = dict["x"].toFloat();
float y = dict["y"].asFloat(); float y = dict["y"].toFloat();
float width = dict["width"].asFloat(); float width = dict["width"].toFloat();
float height = dict["height"].asFloat(); float height = dict["height"].toFloat();
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color); drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color); drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
@ -1364,10 +1364,10 @@ TMXGIDObjectsTestNew::TMXGIDObjectsTestNew()
{ {
ValueMap& dict = obj.asValueMap(); ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat(); float x = dict["x"].toFloat();
float y = dict["y"].asFloat(); float y = dict["y"].toFloat();
float width = dict["width"].asFloat(); float width = dict["width"].toFloat();
float height = dict["height"].asFloat(); float height = dict["height"].toFloat();
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color); drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color); drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);