36 typedef std::vector<IconSetPageDto> TIconSetPageDtos;
37 typedef std::vector<IconDefinitionDto> TIconSetIconDefinitionDtos;
39 TIconSetPageDtos iconSetPages;
40 TIconSetIconDefinitionDtos iconDefinitions;
49 rapidjson::Document document;
50 document.Parse<0>(json.c_str());
51 if (document.HasParseError())
53 std::string errorMsg(GetParseError_En(document.GetParseError()));
54 Eegeo_TTY(
"Error parsing icon sheet - invalid json. %s", errorMsg.c_str());
58 Eegeo_ASSERT(document.HasMember(
"pages"));
59 const rapidjson::Value& pageMappings = document[
"pages"];
60 result.iconSetPages = ParsePages(pageMappings);
62 Eegeo_ASSERT(document.HasMember(
"icons"));
63 const rapidjson::Value& iconMappings = document[
"icons"];
64 result.iconDefinitions = ParseIcons(iconMappings);
71 std::vector<IconSetPageDto> ParsePages(
const rapidjson::Value& json)
73 size_t mappingsCount = json.Size();
75 std::vector<IconSetPageDto> pages;
76 pages.reserve(mappingsCount);
78 for (
int i = 0; i < mappingsCount; ++i)
80 const rapidjson::Value& mappingJson = json[i];
81 Eegeo_ASSERT(mappingJson.HasMember(
"file"),
"Icon page definition has no file defined");
82 Eegeo_ASSERT(mappingJson.HasMember(
"width"),
"Icon page definition has no width defined");
83 Eegeo_ASSERT(mappingJson.HasMember(
"height"),
"Icon page definition has no height defined");
86 page.filename = mappingJson[
"file"].GetString();
87 page.width = mappingJson[
"width"].GetInt();
88 page.height = mappingJson[
"height"].GetInt();
90 pages.push_back(page);
96 std::vector<IconDefinitionDto> ParseIcons(
const rapidjson::Value& json)
98 Eegeo_ASSERT(json.IsArray());
100 size_t mappingsCount = json.Size();
102 std::vector<IconDefinitionDto> mappingEntries;
103 mappingEntries.reserve(mappingsCount);
105 for (
int i = 0; i < mappingsCount; ++i)
107 const rapidjson::Value& mappingJson = json[i];
109 Eegeo_ASSERT(mappingJson.HasMember(
"id"),
"Icon definition has no id");
110 Eegeo_ASSERT(mappingJson.HasMember(
"index"),
"Icon definition has no index");
111 Eegeo_ASSERT(mappingJson.HasMember(
"x"),
"Icon definition has no x coordinate");
112 Eegeo_ASSERT(mappingJson.HasMember(
"y"),
"Icon definition has no y coordinate");
113 Eegeo_ASSERT(mappingJson.HasMember(
"w"),
"Icon definition has no width");
114 Eegeo_ASSERT(mappingJson.HasMember(
"h"),
"Icon definition has no height");
115 Eegeo_ASSERT(mappingJson.HasMember(
"page"),
"Icon definition has no page");
118 icon.iconKey = mappingJson[
"id"].GetString();
119 icon.index = mappingJson[
"index"].GetInt();
120 icon.x = mappingJson[
"x"].GetInt();
121 icon.y = mappingJson[
"y"].GetInt();
122 icon.width = mappingJson[
"w"].GetInt();
123 icon.height = mappingJson[
"h"].GetInt();
124 icon.page = mappingJson[
"page"].GetInt();
127 mappingEntries.push_back(icon);
130 return mappingEntries;