HLayoutObject.cpp
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
//  HLayoutObject.cpp
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
//
//
#include <stdio.h>
#include "HLayoutObject.h"
#include "HScalingUtils.h"
#include "HJSONParseUtils.h"
#include "HLayoutParser.h"
HLayoutObject::~HLayoutObject()
{
    
}
void HLayoutObject::loadCommonPropertiesFromJSON(const rapidjson::Value& jsonValue, HLayoutViewInterface* scene, const std::string resFolder, const std::string altResFolder)
{
    if(jsonValue.HasMember("type")){
        const auto& classNameJSON = jsonValue["type"];
        this->className = classNameJSON.GetString();
    } else {
        this->className = "";
    }
   if(jsonValue.HasMember("name")){
        const auto& objectNameJSON = jsonValue["name"];
        this->objectName = objectNameJSON.GetString();
   } else {
        this->objectName = "";
   }
    
    cocos2d::Node* thisAsNode = dynamic_cast<cocos2d::Node*>(this);
    if(jsonValue.HasMember("scale")){
        const auto& scaleJSON = jsonValue["scale"];
        if(scaleJSON.IsFloat() || scaleJSON.IsInt()){
            thisAsNode->setScale(scaleJSON.GetFloat());
        }
    }
    
    if(jsonValue.HasMember("rotation")){
        const auto& rotationJSON = jsonValue["rotation"];
        if(rotationJSON.IsFloat() || rotationJSON.IsInt()){
            thisAsNode->setRotation(rotationJSON.GetFloat());
        }
    }
    
    if(jsonValue.HasMember("hidden")){
        const auto& hiddenJSON = jsonValue["hidden"];
        if(hiddenJSON.IsBool()){
            thisAsNode->setVisible(!hiddenJSON.GetBool());
        }
    }
    
    if(HJSONParseUtils::checkMemberBool(jsonValue, "visible", false)){
        thisAsNode->setVisible(false);
    }
    if(jsonValue.HasMember("anchorPoint")){
        const auto& anchorPointJSON = jsonValue["anchorPoint"];
        float x = anchorPointJSON["x"].GetFloat();
        float y = anchorPointJSON["y"].GetFloat();
        thisAsNode->setAnchorPoint(cocos2d::Point(x, y));
    }
    if(jsonValue.HasMember("width") && jsonValue.HasMember("height")){
        float width = jsonValue["width"].GetFloat();
        float height = jsonValue["height"].GetFloat();
        width = HScalingUtils::configureNodeDimension(width);
        height = HScalingUtils::configureNodeDimension(height);
        thisAsNode->setContentSize(cocos2d::Size(width, height));
    }
}
void HLayoutObject::prepareSize(const rapidjson::Value& jsonValue, float& width, float& height)
{
    width = 0;
    height = 0;
}