Unit(const nlohmann::json &obj) : Point(obj) { if (obj.count("M")) mass = obj["M"].get<double>(); if (obj.count("SX")) speed.x = obj["SX"].get<double>(); if (obj.count("SY")) speed.y = obj["SY"].get<double>(); }
inline void from_json (const nlohmann::json& j, tileset& ts) { ts.firstgid = j["firstgid"].get<uint32>(); if (j.count("source")) { ts.type = tileset::tiled_tileset_type_external; ts.source = j["source"].get<std::string>(); } else { ts.type = tileset::tiled_tileset_type_embedded; ts.name = j["name"].get<std::string>(); ts.tilewidth = j["tilewidth"].get<uint32>(); ts.tileheight = j["tileheight"].get<uint32>(); ts.spacing = j["spacing"].get<uint32>(); ts.margin = j["margin"].get<uint32>(); ts.tilecount = j["tilecount"].get<uint32>(); ts.columns = j["columns"].get<uint32>(); ts.image = j["image"].get<std::string>(); ts.imagewidth = j["imagewidth"].get<uint32>(); ts.imageheight = j["imageheight"].get<uint32>(); } }
PlayerFragment(const nlohmann::json &obj) : CircularUnit(obj) { if (obj.count("TTF")) ttf = obj["TTF"].get<int>(); auto id_str = obj["Id"].get<string>(); auto dot_pos = id_str.find('.'); if (dot_pos == string::npos) { playerId = stoi(id_str); } else { playerId = stoi(id_str.substr(0, dot_pos)); fragmentId = stoi(id_str.substr(dot_pos + 1)); } }
//-------------------------------------------------------------- void Particles::deserialize(const nlohmann::json & json) { ofxPreset::Serializer::Deserialize(json, nm::Particle::parameters); // Restore Renderer settings. if (json.count("Renderers")) { auto & jsonRenderers = json["Renderers"]; for (auto & it : this->renderers) { ofxPreset::Serializer::Deserialize(jsonRenderers, it.second.parameters); } } if (!this->parameters.stateFile->empty()) { this->loadState(this->parameters.stateFile); } }
inline void from_json (const nlohmann::json& j, object& o) { JSON_VALIDATE_REQUIRED(j, id, is_number); JSON_VALIDATE_REQUIRED(j, name, is_string); JSON_VALIDATE_REQUIRED(j, type, is_string); JSON_VALIDATE_REQUIRED(j, x, is_number); JSON_VALIDATE_REQUIRED(j, y, is_number); JSON_VALIDATE_REQUIRED(j, width, is_number); JSON_VALIDATE_REQUIRED(j, height, is_number); JSON_VALIDATE_REQUIRED(j, visible, is_boolean); JSON_VALIDATE_REQUIRED(j, rotation, is_number_float); JSON_VALIDATE_OPTIONAL(j, properties, is_object); JSON_VALIDATE_OPTIONAL(j, propertytypes, is_object); JSON_VALIDATE_OPTIONAL(j, gid, is_number); JSON_VALIDATE_OPTIONAL(j, point, is_boolean); JSON_VALIDATE_OPTIONAL(j, ellipse, is_boolean); JSON_VALIDATE_OPTIONAL(j, polygon, is_array); JSON_VALIDATE_OPTIONAL(j, polyline, is_array); JSON_VALIDATE_OPTIONAL(j, text, is_string); o.id = j["id"].get<int32>(); o.name = j["name"].get<std::string>(); o.type = j["type"].get<std::string>(); o.x = j["x"].get<int32>(); o.y = j["y"].get<int32>(); o.width = j["width"].get<int32>(); o.height = j["height"].get<int32>(); o.visible = j["visible"].get<bool>(); o.rotation = j["rotation"].get<float>(); deserialize(j, o.properties); if (j.count("gid")) { o.gid = j["gid"].get<int32>(); if (o.gid <= 0) { throw std::invalid_argument("object has invalid gid"); } o.otype = object_type::sprite; return; } o.otype = object_type::rect; if (j.count("point") && j["point"].get<bool>()) { o.otype = object_type::point; } if (j.count("ellipse") && j["ellipse"].get<bool>()) { o.otype = object_type::ellipse; } if (j.count("polygon")) { o.otype = object_type::polygon; o.coords = j["polygon"].get<std::vector<coordinate>>(); } if (j.count("polyline")) { o.otype = object_type::polyline; o.coords = j["polyline"].get<std::vector<coordinate>>(); } if (j.count("text")) { o.otype = object_type::text; o.text = j["text"].get<object_text>(); } }
inline void _initNetwork(nlohmann::json &network) { if (!network.count("private")) network["private"] = true; if (!network.count("creationTime")) network["creationTime"] = OSUtils::now(); if (!network.count("name")) network["name"] = ""; if (!network.count("multicastLimit")) network["multicastLimit"] = (uint64_t)32; if (!network.count("enableBroadcast")) network["enableBroadcast"] = true; if (!network.count("v4AssignMode")) network["v4AssignMode"] = {{"zt",false}}; if (!network.count("v6AssignMode")) network["v6AssignMode"] = {{"rfc4193",false},{"zt",false},{"6plane",false}}; if (!network.count("authTokens")) network["authTokens"] = nlohmann::json::array(); if (!network.count("capabilities")) network["capabilities"] = nlohmann::json::array(); if (!network.count("tags")) network["tags"] = nlohmann::json::array(); if (!network.count("routes")) network["routes"] = nlohmann::json::array(); if (!network.count("ipAssignmentPools")) network["ipAssignmentPools"] = nlohmann::json::array(); if (!network.count("rules")) { // If unspecified, rules are set to allow anything and behave like a flat L2 segment network["rules"] = {{ { "not",false }, { "or", false }, { "type","ACTION_ACCEPT" } }}; } network["objtype"] = "network"; }
// These init objects with default and static/informational fields inline void _initMember(nlohmann::json &member) { if (!member.count("authorized")) member["authorized"] = false; if (!member.count("authHistory")) member["authHistory"] = nlohmann::json::array(); if (!member.count("ipAssignments")) member["ipAssignments"] = nlohmann::json::array(); if (!member.count("recentLog")) member["recentLog"] = nlohmann::json::array(); if (!member.count("activeBridge")) member["activeBridge"] = false; if (!member.count("tags")) member["tags"] = nlohmann::json::array(); if (!member.count("capabilities")) member["capabilities"] = nlohmann::json::array(); if (!member.count("creationTime")) member["creationTime"] = OSUtils::now(); if (!member.count("noAutoAssignIps")) member["noAutoAssignIps"] = false; if (!member.count("revision")) member["revision"] = 0ULL; if (!member.count("lastDeauthorizedTime")) member["lastDeauthorizedTime"] = 0ULL; if (!member.count("lastAuthorizedTime")) member["lastAuthorizedTime"] = 0ULL; member["objtype"] = "member"; }
//-------------------------------------------------------------- void Interlude::deserialize(const nlohmann::json & json) { // Restore Stripes. if (json.count("Stripes Back")) { auto layout = render::Layout::Back; auto jsonStripes = json["Stripes Back"]; for (int i = 0; i < jsonStripes.size(); ++i) { auto instance = this->addStripes(layout); if (instance) { ofxPreset::Serializer::Deserialize(jsonStripes, instance->parameters); } } } if (json.count("Stripes Front")) { auto layout = render::Layout::Front; auto jsonStripes = json["Stripes Front"]; for (int i = 0; i < jsonStripes.size(); ++i) { auto instance = this->addStripes(layout); if (instance) { ofxPreset::Serializer::Deserialize(jsonStripes, instance->parameters); } } } }