예제 #1
0
QJsonObject SceneSerializer::serializeNode(Node* node)
{
    QJsonObject out;

    out["inspector"] = QJsonArray({
            inspectors[node].x(),
            inspectors[node].y()});

    QJsonArray datum_array;

    Datum* deferred = NULL;
    auto datums = node->findChildren<Datum*>(
            QString(), Qt::FindDirectChildrenOnly);

    for (auto d : datums)
        if (dynamic_cast<ScriptDatum*>(d))
            deferred = d;
        else
            datum_array.append(serializeDatum(d));

    if (deferred)
        datum_array.append(serializeDatum(deferred));

    out["datums"] = datum_array;

    return out;
}
예제 #2
0
void SceneSerializer::serializeNode(QDataStream* out, Node* node)
{
    *out << quint32(node->getNodeType());
    *out << node->objectName();

    // Serialize child nodes first.
    serializeNodes(out, node);

    Datum* deferred = NULL;
    auto datums = node->findChildren<Datum*>(QString(),
                                             Qt::FindDirectChildrenOnly);
    *out << quint32(datums.length());
    for (auto d : datums)
    {
        if (dynamic_cast<ScriptDatum*>(d))
        {
            Q_ASSERT(deferred == NULL);
            Q_ASSERT(node->getNodeType() == NodeType::SCRIPT);;
            deferred = d;
        }
        else
        {
            serializeDatum(out, d);
        }
    }

    if (deferred)
    {
        serializeDatum(out, deferred);
    }
}