QJsonObject AnimationToJson::toJsonObject(const QRectF &rect) { QJsonObject object; object.insert("topLeft", toJsonObject(rect.topLeft())); object.insert("bottomRight", toJsonObject(rect.bottomRight())); return object; }
void Visitor<Reader<JSONObject>>::readFrom_impl( const Explorer::DeviceDocumentPlugin& plug) { // Childrens of the root node are the devices // We don't save their children if they don't have canSerialize(). m_obj["RootNode"] = QJsonObject{}; QJsonArray children; for(auto& node : plug.rootNode().children()) { QJsonObject this_node; ISCORE_ASSERT(node.is<Device::DeviceSettings>()); const Device::DeviceSettings& dev = node.get<Device::DeviceSettings>(); auto actual = plug.list().find(dev.name); ISCORE_ASSERT(actual != plug.list().devices().cend()); if((*actual)->capabilities().canSerialize) { this_node = toJsonObject(node); } else { this_node = toJsonObject(node.impl()); } children.push_back(std::move(this_node)); } m_obj["Children"] = children; }
void Visitor<Reader<JSONObject>>::readFrom(const AutomationModel& autom) { m_obj["PluginsMetadata"] = toJsonValue(*autom.pluginModelList); m_obj["Curve"] = toJsonObject(autom.curve()); m_obj["Address"] = toJsonObject(autom.address()); m_obj["Min"] = autom.min(); m_obj["Max"] = autom.max(); }
QJsonObject AnimationToJson::toJsonObject(const HitBox &hitBox) { QJsonObject object; object.insert("group", hitBox.group()); object.insert("rect", toJsonObject(hitBox.rect())); return object; }
ISCORE_PLUGIN_SCENARIO_EXPORT void Visitor<Reader<JSONObject>>::readFrom(const Scenario::StateModel& s) { readFrom(static_cast<const IdentifiedObject<Scenario::StateModel>&>(s)); // Common metadata m_obj["Metadata"] = toJsonObject(s.metadata); m_obj["Event"] = toJsonValue(s.m_eventId); m_obj["PreviousConstraint"] = toJsonValue(s.m_previousConstraint); m_obj["NextConstraint"] = toJsonValue(s.m_nextConstraint); m_obj["HeightPercentage"] = s.m_heightPercentage; // Message tree m_obj["Messages"] = toJsonObject(s.m_messageItemModel->rootNode()); // Processes plugins m_obj["StateProcesses"] = toJsonArray(s.stateProcesses); }
QJsonObject AnimationToJson::toJsonObject(const KeyFrame &keyFrame) { QJsonObject object; object.insert("fileName", QFileInfo(keyFrame.fileName()).fileName()); object.insert("rect", toJsonObject(keyFrame.rect())); // qDebug() << keyFrame.rect() << toJsonObject(keyFrame.rect()); object.insert("offset", toJsonObject(keyFrame.offset())); QJsonObject customPropertiesObject; const auto customProperties = keyFrame.customProperties(); for(auto it = customProperties.begin(); it != customProperties.end(); ++it) { customPropertiesObject.insert(it.key(), it.value()); } object.insert("customProperties", customPropertiesObject); QJsonArray hitBoxes; for (HitBox *hitBox : keyFrame.hitBoxes()) { hitBoxes.append(toJsonObject(*hitBox)); } object.insert("hitBoxes", hitBoxes); return object; }
QJsonValue QV8JsonWrapper::toJsonValue(v8::Handle<v8::Value> value, V8ObjectSet &visitedObjects) { if (value->IsString()) return QJsonValue(QJSConverter::toString(value.As<v8::String>())); else if (value->IsNumber()) return QJsonValue(value->NumberValue()); else if (value->IsBoolean()) return QJsonValue(value->BooleanValue()); else if (value->IsArray()) return toJsonArray(value.As<v8::Array>(), visitedObjects); else if (value->IsObject()) return toJsonObject(value.As<v8::Object>(), visitedObjects); else if (value->IsNull()) return QJsonValue(QJsonValue::Null); else return QJsonValue(QJsonValue::Undefined); }
QJsonObject AnimationToJson::toJsonObject(const Animation &animation) { QJsonObject animationObject; animationObject.insert("frameCount", animation.frameCount()); animationObject.insert("fps", animation.fps()); // animationObject.insert("origin", toJsonObject(animation.origin())); QJsonArray keyFramesArray; const auto keyFrames = animation.keyFrames(); for(auto it = keyFrames.begin(); it != keyFrames.end(); ++it) { QJsonObject keyFrameObject; keyFrameObject.insert("frame", it.key()); keyFrameObject.insert("data", toJsonObject(*it.value())); keyFramesArray.append(keyFrameObject); } animationObject.insert("keyFrames", keyFramesArray); return animationObject; }
QJsonDocument AnimationToJson::toJson(const Animation &animation) { return QJsonDocument(toJsonObject(animation)); }