Exemple #1
0
void BTPc::serialize(ObjectSerializer* s)
{
 int i;
 s->add("name", &name);
 s->add("race", &race, NULL, &BTGame::getGame()->getRaceList());
 s->add("job", &job, NULL, &BTGame::getGame()->getJobList());
 s->add("jobAbbrev", &job, NULL, &BTGame::getGame()->getJobAbbrevList());
 s->add("gender", &gender, NULL, &genderLookup);
 s->add("picture", &picture);
 s->add("monster", &monster);
 for (i = 0; i < BT_STATS; ++i)
 {
  std::vector<XMLAttribute> *attrib = new std::vector<XMLAttribute>;
  char tmp[10];
  snprintf(tmp, 10, "%d", i + 1);
  attrib->push_back(XMLAttribute("number", tmp));
  s->add("stat", &stat[i], attrib);
 }
 for (i = 0; i < BT_STATS; ++i)
 {
  std::vector<XMLAttribute> *attrib = new std::vector<XMLAttribute>;
  char tmp[10];
  snprintf(tmp, 10, "%d", i + 1);
  attrib->push_back(XMLAttribute("number", tmp));
  s->add("statMax", &statMax[i], attrib);
 }
 s->add("ac", &ac);
 s->add("toHit", &toHit);
 s->add("rateAttacks", &rateAttacks);
 s->add("save", &save);
 s->add("status", &status, &BTStatusLookup::lookup);
 s->add("dmgBonus", &dmgBonus, &BTDamageBonus::create);
 s->add("maxhp", &maxHp);
 s->add("hp", &hp);
 s->add("maxsp", &maxSp);
 s->add("sp", &sp);
 s->add("maxLevel", &maxLevel);
 s->add("level", &level);
 s->add("xp", &xp);
 s->add("gold", &gold);
 s->add("skill", &skill, &BTSkillValue::create);
 for (i = 0; i < BT_ITEMS; ++i)
 {
  std::vector<XMLAttribute> *attrib = new std::vector<XMLAttribute>;
  char tmp[10];
  snprintf(tmp, 10, "%d", i + 1);
  attrib->push_back(XMLAttribute("number", tmp));
  s->add("item", &item[i], attrib);
 }
 s->add("tag", &tag);
}
Exemple #2
0
void BTDisplayConfig::serialize(ObjectSerializer* s)
{
    s->add("width", &width);
    s->add("height", &height);
    s->add("expanded", &expanded, &BTDisplayExpanded::create);
    s->add("background", &background);
    s->add("font", &font);
    s->add("fontsize", &fontsize);
    s->add("x3d", &x3d);
    s->add("y3d", &y3d);
    s->add("color", &color, &BTDisplayColor::create);
    s->add("layout", &layout, &BTLayoutConfig::create);
    for (int i = 0; i < BT_PARTYSIZE; ++i)
    {
        std::vector<XMLAttribute> *attrib = new std::vector<XMLAttribute>;
        char tmp[10];
        snprintf(tmp, 10, "%d", i + 1);
        attrib->push_back(XMLAttribute("number", tmp));
        s->add("status", &status[i], attrib);
    }
    s->add("statBlock", &statusInfo, &BTStatBlock::create);
    s->add("conditional", &statusInfo, &BTConditional::create);
    s->add("print", &statusInfo, &BTPrint::create);
    s->add("icon", &icon, &BTIcon::create);
    s->add("facingIcon", &icon, &BTFacingIcon::create);
    s->add("xMap", &xMap);
    s->add("yMap", &yMap);
    s->add("widthMap", &widthMap);
    s->add("heightMap", &heightMap);
    s->add("mapDisplayMode", &mapDisplayMode, NULL, &mapDisplayModeLookup);
    s->add("centerMap", &centerMap);
    s->add("coordinatesMap", &coordinatesMap);
}
Exemple #3
0
	void XMLNode::SetAttribute(const std::string &name, std::string value)
	{
		if(mAttributes.count(name)) {
			return mAttributes[name].SetValue(value);
		} else {
			mAttributes.insert(
				std::pair<std::string, XMLAttribute>(name, XMLAttribute(name, value))
			);
		}
	}
Exemple #4
0
XMLAttributeColl& XMLAttributeColl::AddAttribute(const char* name, const char* val)
{
	int c = m_attrs.size();
	for(int i=0; i<c; i++)
	{
		XMLAttribute& attr = m_attrs[i];
		if(attr.m_name.icompare(name) == 0)
		{
			attr.m_value = val;
			return *this;
		}
	}
	m_attrs.push_back(XMLAttribute(name, val));
	return *this;
}
Exemple #5
0
void XMLAttributes::set(const String &name, const String &value)
{
	OS_ASSERT(name.empty() == false);

	shared_ptr<XMLAttribute> attribute = find(name);
	if(attribute != nullptr)
	{
		attribute->setValue(value);
	}
	else
	{
		attribute.reset(OS_NEW XMLAttribute(getNode(), name, value));
		m_attributes.push_back(attribute);
	}
}
XMLNode*
create_string_node(const StringResource& str, const string& name)
{
    vector<XMLAttribute> attrs;
    attrs.push_back(XMLAttribute(XMLNS_XMLNS, "space", "preserve"));
    XMLNode* node = XMLNode::NewElement(str.pos, XLIFF_XMLNS, name, attrs, XMLNode::EXACT);

    const vector<XMLNode*>& children = str.value->Children();
    size_t I = children.size();
    int err = 0;
    for (size_t i=0; i<I; i++) {
        int phID = 0;
        err |= convert_html_to_xliff(children[i], name, node, &phID);
    }

    if (err != 0) {
        delete node;
    }
    return node;
}
XMLNode*
XLIFFFile::ToXMLNode() const
{
    XMLNode* root;
    size_t N;

    // <xliff>
    {
        vector<XMLAttribute> attrs;
        XLIFF_NAMESPACES.AddToAttributes(&attrs);
        attrs.push_back(XMLAttribute(XLIFF_XMLNS, "version", "1.2"));
        root = XMLNode::NewElement(GENERATED_POS, XLIFF_XMLNS, "xliff", attrs, XMLNode::PRETTY);
    }

    vector<TransUnit> groups;

    // <file>
    vector<File> files = m_files;
    sort(files.begin(), files.end());
    const size_t I = files.size();
    for (size_t i=0; i<I; i++) {
        const File& file = files[i];

        vector<XMLAttribute> fileAttrs;
        fileAttrs.push_back(XMLAttribute(XLIFF_XMLNS, "datatype", "x-android-res"));
        fileAttrs.push_back(XMLAttribute(XLIFF_XMLNS, "original", file.filename));

        struct timeval tv;
        struct timezone tz;
        gettimeofday(&tv, &tz);
        fileAttrs.push_back(XMLAttribute(XLIFF_XMLNS, "date", trim_string(ctime(&tv.tv_sec))));

        fileAttrs.push_back(XMLAttribute(XLIFF_XMLNS, "source-language", m_sourceConfig.locale));
        fileAttrs.push_back(XMLAttribute(XLIFF_XMLNS, "target-language", m_targetConfig.locale));
        fileAttrs.push_back(XMLAttribute(XLIFF_XMLNS, "build-num", m_currentVersion));

        XMLNode* fileNode = XMLNode::NewElement(GENERATED_POS, XLIFF_XMLNS, "file", fileAttrs,
                                                XMLNode::PRETTY);
        root->EditChildren().push_back(fileNode);

        // <body>
        XMLNode* bodyNode = XMLNode::NewElement(GENERATED_POS, XLIFF_XMLNS, "body",
                                                vector<XMLAttribute>(), XMLNode::PRETTY);
        fileNode->EditChildren().push_back(bodyNode);

        // <trans-unit>
        vector<TransUnit> transUnits = file.transUnits;
        sort(transUnits.begin(), transUnits.end(), compare_id);
        const size_t J = transUnits.size();
        for (size_t j=0; j<J; j++) {
            const TransUnit& transUnit = transUnits[j];

            vector<XMLAttribute> tuAttrs;

            // strings start with string:
            tuAttrs.push_back(XMLAttribute(XLIFF_XMLNS, "id", transUnit.id));
            XMLNode* transUnitNode = XMLNode::NewElement(GENERATED_POS, XLIFF_XMLNS, "trans-unit",
                                                         tuAttrs, XMLNode::PRETTY);
            bodyNode->EditChildren().push_back(transUnitNode);

            // <extradata>
            if (transUnit.source.comment != "") {
                vector<XMLAttribute> extradataAttrs;
                XMLNode* extraNode = XMLNode::NewElement(GENERATED_POS, XLIFF_XMLNS, "extradata",
                                                            extradataAttrs, XMLNode::EXACT);
                transUnitNode->EditChildren().push_back(extraNode);
                extraNode->EditChildren().push_back(
                        XMLNode::NewText(GENERATED_POS, transUnit.source.comment,
                                         XMLNode::PRETTY));
            }

            // <source>
            if (transUnit.source.id != "") {
                transUnitNode->EditChildren().push_back(
                                    create_string_node(transUnit.source, "source"));
            }
            
            // <target>
            if (transUnit.target.id != "") {
                transUnitNode->EditChildren().push_back(
                                    create_string_node(transUnit.target, "target"));
            }

            // <alt-trans>
            if (transUnit.altSource.id != "" || transUnit.altTarget.id != ""
                    || transUnit.rejectComment != "") {
                vector<XMLAttribute> altTransAttrs;
                XMLNode* altTransNode = XMLNode::NewElement(GENERATED_POS, XLIFF_XMLNS, "alt-trans",
                                                            altTransAttrs, XMLNode::PRETTY);
                transUnitNode->EditChildren().push_back(altTransNode);

                // <extradata>
                if (transUnit.rejectComment != "") {
                    vector<XMLAttribute> extradataAttrs;
                    XMLNode* extraNode = XMLNode::NewElement(GENERATED_POS, XLIFF_XMLNS,
                                                                "extradata", extradataAttrs,
                                                                XMLNode::EXACT);
                    altTransNode->EditChildren().push_back(extraNode);
                    extraNode->EditChildren().push_back(
                            XMLNode::NewText(GENERATED_POS, transUnit.rejectComment,
                                             XMLNode::PRETTY));
                }
                
                // <source>
                if (transUnit.altSource.id != "") {
                    altTransNode->EditChildren().push_back(
                                        create_string_node(transUnit.altSource, "source"));
                }
                
                // <target>
                if (transUnit.altTarget.id != "") {
                    altTransNode->EditChildren().push_back(
                                        create_string_node(transUnit.altTarget, "target"));
                }
            }
            
        }
    }

    return root;
}
int
convert_html_to_xliff(const XMLNode* original, const string& name, XMLNode* addTo, int* phID)
{
    int err = 0;
    if (original->Type() == XMLNode::TEXT) {
        addTo->EditChildren().push_back(original->Clone());
        return 0;
    } else {
        string ctype;
        if (original->Namespace() == "") {
            if (original->Name() == "b") {
                ctype = "bold";
            }
            else if (original->Name() == "i") {
                ctype = "italic";
            }
            else if (original->Name() == "u") {
                ctype = "underline";
            }
        }
        if (ctype != "") {
            vector<XMLAttribute> attrs;
            attrs.push_back(XMLAttribute(XLIFF_XMLNS, "ctype", ctype));
            XMLNode* copy = XMLNode::NewElement(original->Position(), XLIFF_XMLNS, "g",
                                                attrs, XMLNode::EXACT);

            const vector<XMLNode*>& children = original->Children();
            size_t I = children.size();
            for (size_t i=0; i<I; i++) {
                err |= convert_html_to_xliff(children[i], name, copy, phID);
            }
            return err;
        }
        else {
            if (original->Namespace() == XLIFF_XMLNS) {
                addTo->EditChildren().push_back(original->Clone());
                return 0;
            } else {
                if (original->Namespace() == "") {
                    // flatten out the tag into ph tags -- but only if there is no namespace
                    // that's still unsupported because propagating the xmlns attribute is hard.
                    vector<XMLAttribute> attrs;
                    char idStr[30];
                    (*phID)++;
                    sprintf(idStr, "id-%d", *phID);
                    attrs.push_back(XMLAttribute(XLIFF_XMLNS, "id", idStr));

                    if (original->Children().size() == 0) {
                        XMLNode* ph = XMLNode::NewElement(original->Position(), XLIFF_XMLNS,
                                "ph", attrs, XMLNode::EXACT);
                        ph->EditChildren().push_back(
                                XMLNode::NewText(original->Position(),
                                    original->ToString(XLIFF_NAMESPACES),
                                    XMLNode::EXACT));
                        addTo->EditChildren().push_back(ph);
                    } else {
                        XMLNode* begin = XMLNode::NewElement(original->Position(), XLIFF_XMLNS,
                                "bpt", attrs, XMLNode::EXACT);
                        begin->EditChildren().push_back(
                                XMLNode::NewText(original->Position(),
                                    original->OpenTagToString(XLIFF_NAMESPACES, XMLNode::EXACT),
                                    XMLNode::EXACT));
                        XMLNode* end = XMLNode::NewElement(original->Position(), XLIFF_XMLNS,
                                "ept", attrs, XMLNode::EXACT);
                        string endText = "</";
                            endText += original->Name();
                            endText += ">";
                        end->EditChildren().push_back(XMLNode::NewText(original->Position(),
                                endText, XMLNode::EXACT));

                        addTo->EditChildren().push_back(begin);

                        const vector<XMLNode*>& children = original->Children();
                        size_t I = children.size();
                        for (size_t i=0; i<I; i++) {
                            err |= convert_html_to_xliff(children[i], name, addTo, phID);
                        }

                        addTo->EditChildren().push_back(end);
                    }
                    return err;
                } else {
                    original->Position().Error("invalid <%s> element in <%s> tag\n",
                                                original->Name().c_str(), name.c_str());
                    return 1;
                }
            }
        }
    }
}