Exemplo n.º 1
0
void XMPMetadataSource::loadField(const MetaString& fieldPath, const shared_ptr<Metadata>& md, const shared_ptr<MetadataDesc>& thisPropertyDesc)
{
    MetaString rawValue;
    if (!xmp->GetProperty(VMF_NS, fieldPath.c_str(), &rawValue, NULL))
    {
        VMF_EXCEPTION(DataStorageException, "Corrupted field by path " + fieldPath);
    }


    MetaString fieldName;
    if (!xmp->GetQualifier(VMF_NS, fieldPath.c_str(), VMF_NS, FIELD_NAME, &fieldName, NULL))
    {
        fieldName = "";
    }

    FieldDesc thisFieldDesc;
    if (!thisPropertyDesc->getFieldDesc(thisFieldDesc, fieldName))
    {
        VMF_EXCEPTION(DataStorageException, "Extra field by path " + fieldPath);
    }


    Variant fieldValue;
    fieldValue.fromString(thisFieldDesc.type, rawValue);
    if (fieldName.empty())
    {
        md->addValue(fieldValue);
    }
    else
    {
        md->setFieldValue(fieldName, fieldValue);
    }
}
Exemplo n.º 2
0
void XMPMetadataSource::loadReference(const MetaString& thisRefPath, const shared_ptr<Metadata>& md, MetadataStream& stream)
{
    XMP_Int64 id;
    MetaString tmpPath;
    MetaString refName;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, thisRefPath.c_str(), VMF_NS, REF_NAME, &tmpPath);
    if (!xmp->GetProperty(VMF_NS, tmpPath.c_str(), &refName, nullptr))
        refName = "";
    
    SXMPUtils::ComposeStructFieldPath(VMF_NS, thisRefPath.c_str(), VMF_NS, REF_ID, &tmpPath);
    if (!xmp->GetProperty_Int64(VMF_NS, tmpPath.c_str(), &id, nullptr))
    {
        VMF_EXCEPTION(DataStorageException, "Broken reference by path" + thisRefPath);
    }

    IdType realId = id;
    shared_ptr<Metadata> refTo = stream.getById(realId);
    if (!refTo)
    {
        auto it = idMap.find(realId);
        if (it == idMap.end())
        {
            VMF_EXCEPTION(DataStorageException, "Undefined reference by path " + thisRefPath);
        }
        InternalPath path = it->second;
        std::shared_ptr<MetadataSchema> refSchemaDesc = stream.getSchema(path.schema);
        std::shared_ptr<MetadataDesc> refMetadataDesc = refSchemaDesc->findMetadataDesc(path.metadata);
        loadMetadata(path.path, refMetadataDesc, stream);
        refTo = stream.getById(realId);
    }
    md->addReference(refTo, refName);
}
Exemplo n.º 3
0
void XMPMetadataSource::saveMetadata(const shared_ptr<Metadata>& md, const MetaString& thisPropertySetPath)
{
    if (md == nullptr)
        VMF_EXCEPTION(DataStorageException, "Trying to save nullptr metadata");

    MetaString pathToMetadata;

    auto it = idMap.find(md->getId());
    if (it == idMap.end())
    {
        xmp->AppendArrayItem(VMF_NS, thisPropertySetPath.c_str(), kXMP_PropValueIsArray, nullptr, kXMP_PropValueIsStruct);
        SXMPUtils::ComposeArrayItemPath(VMF_NS, thisPropertySetPath.c_str(), kXMP_ArrayLastItem, &pathToMetadata);
    }
    else
    {
        pathToMetadata = it->second.path;
    }

    saveMetadataId(pathToMetadata, md->getId());
    saveMetadataFrameIndex(pathToMetadata, md->getFrameIndex());
    saveMetadataNumOfFrames(pathToMetadata, md->getNumOfFrames());
    saveMetadataTime(pathToMetadata, md->getTime());
    saveMetadataDuration(pathToMetadata, md->getDuration());
    saveMetadataFields(pathToMetadata, md);
    saveMetadataReferences(pathToMetadata, md);
}
Exemplo n.º 4
0
Arquivo: Unit.cpp Projeto: vcmi/vcmi
void Unit::addNameReplacement(MetaString & text, const boost::logic::tribool & plural) const
{
	if(boost::logic::indeterminate(plural))
		text.addCreReplacement(creatureId(), getCount());
	else if(plural)
		text.addReplacement(MetaString::CRE_PL_NAMES, creatureIndex());
	else
		text.addReplacement(MetaString::CRE_SING_NAMES, creatureIndex());
}
Exemplo n.º 5
0
//
// MetaTable::setString
//
// If the metatable already contains a metastring of the given name, it will
// be edited to have the provided value. Otherwise, a new metastring will be
// added to the table with that value. 
//
void MetaTable::setString(const char *key, const char *newValue)
{
   MetaString *obj;

   if(!(obj = getObjectKeyAndTypeEx<MetaString>(key)))
      addString(key, newValue);
   else
      obj->setValue(newValue);
}
Exemplo n.º 6
0
Arquivo: Unit.cpp Projeto: vcmi/vcmi
std::string Unit::formatGeneralMessage(const int32_t baseTextId) const
{
	const int32_t textId = VLC->generaltexth->pluralText(baseTextId, getCount());

	MetaString text;
	text.addTxt(MetaString::GENERAL_TXT, textId);
	text.addCreReplacement(creatureId(), getCount());

	return text.toString();
}
Exemplo n.º 7
0
std::string CompleteQuest::questToString() const
{
	if(q.quest->missionType == CQuest::MISSION_NONE)
		return "inactive quest";

	MetaString ms;
	q.quest->getRolloverText(ms, false);

	return ms.toString();
}
Exemplo n.º 8
0
void XMPMetadataSource::loadMetadataId(const MetaString& pathToMetadata, IdType& id)
{
    MetaString pathToId;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToMetadata.c_str(), VMF_NS, METADATA_ID, &pathToId);
    XMP_Int64 idValue;
    if(!xmp->GetProperty_Int64(VMF_NS, pathToId.c_str(), &idValue, kXMP_NoOptions))
    {
        VMF_EXCEPTION(DataStorageException, "Broken property by path " + pathToMetadata);
    }
    id = (IdType) idValue;
}
Exemplo n.º 9
0
void XMPMetadataSource::saveMetadataFrameIndex(const MetaString& pathToProperty, const long long& frameIndex)
{
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, METADATA_FRAME_INDEX, &tmpPath);
    if (frameIndex >= 0)
        xmp->SetProperty_Int64(VMF_NS, tmpPath.c_str(), frameIndex);
    else if (frameIndex == Metadata::UNDEFINED_FRAME_INDEX)
        xmp->DeleteProperty(VMF_NS, tmpPath.c_str());
    else
        VMF_EXCEPTION(DataStorageException, "Can't save metadata frame index. Invalid frame index value");
}
Exemplo n.º 10
0
void XMPMetadataSource::saveMetadataNumOfFrames(const MetaString& pathToProperty, const long long& numOfFrames)
{
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, METADATA_NUM_OF_FRAMES, &tmpPath);
    if (numOfFrames > 0)
        xmp->SetProperty_Int64(VMF_NS, tmpPath.c_str(), numOfFrames);
    else if (numOfFrames == Metadata::UNDEFINED_FRAMES_NUMBER)
        xmp->DeleteProperty(VMF_NS, tmpPath.c_str());
    else
        VMF_EXCEPTION(DataStorageException, "Can't save metadata number of frames. Invalid number of frames value");
}
Exemplo n.º 11
0
void XMPMetadataSource::saveMetadataTime(const MetaString& pathToProperty, const long long& time)
{
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, METADATA_TIMESTAMP, &tmpPath);
    if (time >= 0)
        xmp->SetProperty_Int64(VMF_NS, tmpPath.c_str(), time);
    else if (time == Metadata::UNDEFINED_TIMESTAMP)
        xmp->DeleteProperty(VMF_NS, tmpPath.c_str());
    else
        VMF_EXCEPTION(DataStorageException, "Can't save metadata timestamp. Invalid timestamp value");
}
Exemplo n.º 12
0
void CQuestLog::selectQuest (int which)
{
	questIndex = which;
	currentQuest = &quests[which];
	minimap->currentQuest = currentQuest;

	MetaString text;
	std::vector<Component> components; //TODO: display them
	currentQuest->quest->getVisitText (text, components , currentQuest->quest->isCustomFirst, true);
	description->setText (text.toString()); //TODO: use special log entry text
	redraw();
}
Exemplo n.º 13
0
void XMPMetadataSource::saveMetadataDuration(const MetaString& pathToProperty, const long long& duration)
{
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, METADATA_DURATION, &tmpPath);
    if (duration > 0)
        xmp->SetProperty_Int64(VMF_NS, tmpPath.c_str(), duration);
    else if (duration == Metadata::UNDEFINED_DURATION)
        xmp->DeleteProperty(VMF_NS, tmpPath.c_str());
    else
        VMF_EXCEPTION(DataStorageException, "Can't save metadata duration. Invalid duration value");

}
Exemplo n.º 14
0
void XMPMetadataSource::saveProperty(const MetadataSet& property, const MetaString& pathToSchema, const MetaString& propertyName)
{
    if (property.empty())
    {
        // not loaded or empty. In any case nothing to do.
        return;
    }

    MetaString pathToPropertiesArray;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToSchema.c_str(), VMF_NS, SCHEMA_SET, &pathToPropertiesArray);

    MetaString thisPropertyPath = findProperty(pathToSchema, propertyName);
    if (thisPropertyPath.empty())
    {
        xmp->AppendArrayItem(VMF_NS, pathToPropertiesArray.c_str(), kXMP_PropValueIsArray, nullptr, kXMP_PropValueIsStruct);
        SXMPUtils::ComposeArrayItemPath(VMF_NS, pathToPropertiesArray.c_str(), kXMP_ArrayLastItem, &thisPropertyPath);
    }

    savePropertyName(thisPropertyPath, propertyName);
    xmp->SetStructField(VMF_NS, thisPropertyPath.c_str(), VMF_NS, PROPERTY_SET, nullptr, kXMP_PropValueIsArray);
    MetaString thisPropertySetPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, thisPropertyPath.c_str(), VMF_NS, PROPERTY_SET, &thisPropertySetPath);

    for(auto metadata = property.begin(); metadata != property.end(); ++metadata)
    {
        saveMetadata(*metadata, thisPropertySetPath);
    }
}
Exemplo n.º 15
0
void XMPMetadataSource::loadMetadataFrameIndex(const MetaString& pathToMetadata, long long& frameIndex)
{
    XMP_Int64 frameIndexValue;
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToMetadata.c_str(), VMF_NS, METADATA_FRAME_INDEX, &tmpPath);
    if(!xmp->GetProperty_Int64(VMF_NS, tmpPath.c_str(), &frameIndexValue, nullptr))
    {
        frameIndexValue = Metadata::UNDEFINED_FRAME_INDEX;
    }
    if(frameIndexValue < 0 && frameIndexValue != Metadata::UNDEFINED_FRAME_INDEX)
    {
        VMF_EXCEPTION(DataStorageException, "Can't load metadata frame index. Invalid frame index value");
    }
    frameIndex = frameIndexValue;
}
Exemplo n.º 16
0
void XMPMetadataSource::loadMetadataDuration(const MetaString& pathToProperty, long long& dur)
{
    XMP_Int64 duration;
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, METADATA_DURATION, &tmpPath);
    if (!xmp->GetProperty_Int64(VMF_NS, tmpPath.c_str(), &duration, nullptr))
    {
        duration = Metadata::UNDEFINED_DURATION;
    }
    if(duration < 0)
    {
        VMF_EXCEPTION(DataStorageException, "Can't load metadata duration. Invalid duration value");
    }
    dur = duration;
}
Exemplo n.º 17
0
void XMPMetadataSource::loadMetadataTime(const MetaString& pathToProperty, long long& time)
{
    XMP_Int64 timestamp;
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, METADATA_TIMESTAMP, &tmpPath);
    if (!xmp->GetProperty_Int64(VMF_NS, tmpPath.c_str(), &timestamp, nullptr))
    {
        timestamp = Metadata::UNDEFINED_TIMESTAMP;
    }
    if(timestamp < 0 && timestamp != Metadata::UNDEFINED_TIMESTAMP)
    {
        VMF_EXCEPTION(DataStorageException, "Can't load metadata timestamp. Invalid timestamp value");
    }
    time = timestamp;
}
Exemplo n.º 18
0
void XMPMetadataSource::loadMetadataNumOfFrames(const MetaString& pathToProperty, long long& num)
{
    XMP_Int64 numOfFrames;
    MetaString tmpPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, METADATA_NUM_OF_FRAMES, &tmpPath);
    if (!xmp->GetProperty_Int64(VMF_NS, tmpPath.c_str(), &numOfFrames, nullptr))
    {
        numOfFrames = Metadata::UNDEFINED_FRAMES_NUMBER;
    }
    if(numOfFrames < 0)
    {
        VMF_EXCEPTION(DataStorageException, "Can't load metadata number of frames. Invalid number of frames value");
    }
    num = numOfFrames;
}
Exemplo n.º 19
0
void CQuest::addReplacements(MetaString &out, const std::string &base) const
{
	switch(missionType)
	{
	case MISSION_KILL_CREATURE:
		out.addReplacement(stackToKill);
		if (std::count(base.begin(), base.end(), '%') == 2) //say where is placed monster
		{
			out.addReplacement(VLC->generaltexth->arraytxt[147+stackDirection]);
		}
		break;
	case MISSION_KILL_HERO:
		out.addReplacement(heroName);
		break;
	}
}
Exemplo n.º 20
0
void XMPMetadataSource::loadSchemaName(const MetaString &pathToSchema, MetaString& schemaName)
{
    if (!xmp->GetStructField(VMF_NS, pathToSchema.c_str(), VMF_NS, SCHEMA_NAME, &schemaName, nullptr))
    {
        VMF_EXCEPTION(DataStorageException, "Broken schema by path " + pathToSchema);
    }
}
Exemplo n.º 21
0
void XMPMetadataSource::loadPropertyName(const MetaString& pathToMetadata, MetaString& metadataName)
{
    if(!xmp->GetStructField(VMF_NS, pathToMetadata.c_str(), VMF_NS, PROPERTY_NAME, &metadataName, nullptr))
    {
        VMF_EXCEPTION(DataStorageException, "Corrupted property by path " + pathToMetadata);
    }
}
Exemplo n.º 22
0
std::string CGSeerHut::getHoverText(PlayerColor player) const
{
	std::string hoverName = getObjectName();
	if (ID == Obj::SEER_HUT && quest->progress != CQuest::NOT_ACTIVE)
	{
		hoverName = VLC->generaltexth->allTexts[347];
		boost::algorithm::replace_first(hoverName,"%s", seerName);
	}

	if (quest->progress & quest->missionType) //rollover when the quest is active
	{
		MetaString ms;
		getRolloverText (ms, true);
		hoverName += ms.toString();
	}
	return hoverName;
}
Exemplo n.º 23
0
void XMPMetadataSource::loadSchema(const MetaString &schemaName, MetadataStream &stream)
{
    MetaString schemaPath = findSchema(schemaName);
    if (schemaPath.empty())
    {
        VMF_EXCEPTION(DataStorageException, "Schema " + schemaName + " not found");
    }

    MetaString pathToProperties;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, schemaPath.c_str(), VMF_NS, SCHEMA_SET, &pathToProperties);
    SXMPIterator propIterator(*xmp, VMF_NS, pathToProperties.c_str(), kXMP_IterJustChildren);
    MetaString currentPropertyPath;
    while(propIterator.Next(NULL, &currentPropertyPath))
    {
        loadPropertyByPath(currentPropertyPath, schemaName, stream);
    }
}
Exemplo n.º 24
0
void XMPMetadataSource::loadPropertyByPath(const MetaString& pathToProperty, const MetaString& schemaName, MetadataStream& stream)
{
    shared_ptr<MetadataSchema> schema(stream.getSchema(schemaName));
    MetaString metadataName;
    loadPropertyName(pathToProperty, metadataName);
    MetaString pathToMetadataSet;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToProperty.c_str(), VMF_NS, PROPERTY_SET, &pathToMetadataSet);

    shared_ptr<MetadataDesc> description(schema->findMetadataDesc(metadataName));

    SXMPIterator mIter(*xmp, VMF_NS, pathToMetadataSet.c_str(), kXMP_IterJustChildren);
    MetaString pathToCurrentMetadata;
    while(mIter.Next(nullptr, &pathToCurrentMetadata))
    {
        loadMetadata(pathToCurrentMetadata, description, stream);
    }
    //unsorted stream fails on save
    stream.sortById();
}
Exemplo n.º 25
0
Arquivo: Unit.cpp Projeto: vcmi/vcmi
void Unit::addText(MetaString & text, ui8 type, int32_t serial, const boost::logic::tribool & plural) const
{
	if(boost::logic::indeterminate(plural))
		serial = VLC->generaltexth->pluralText(serial, getCount());
	else if(plural)
		serial = VLC->generaltexth->pluralText(serial, 2);
	else
		serial = VLC->generaltexth->pluralText(serial, 1);

	text.addTxt(type, serial);
}
Exemplo n.º 26
0
MetaString XMPMetadataSource::findProperty(const MetaString& pathToSchema, const MetaString& name)
{
    MetaString pathToSchemaSet;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToSchema.c_str(), VMF_NS, SCHEMA_SET, &pathToSchemaSet);
    SXMPIterator pIter(*xmp, VMF_NS, pathToSchemaSet.c_str(), kXMP_IterJustChildren);
    MetaString currentPropertyPath;
    while(pIter.Next(nullptr, &currentPropertyPath))
    {
        MetaString currentPropertyName;
        if (!xmp->GetStructField(VMF_NS, currentPropertyPath.c_str(), VMF_NS, PROPERTY_NAME, &currentPropertyName, kXMP_NoOptions))
        {
            VMF_EXCEPTION(DataStorageException, "Broken property by path " + currentPropertyPath);
        }
        if (currentPropertyName == name)
        {
            return currentPropertyPath;
        }
    }
    return MetaString("");
}
Exemplo n.º 27
0
void IBoatGenerator::getProblemText(MetaString &out, const CGHeroInstance *visitor) const
{
	switch(shipyardStatus())
	{
	case BOAT_ALREADY_BUILT:
		out.addTxt(MetaString::GENERAL_TXT, 51);
		break;
	case TILE_BLOCKED:
		if(visitor)
		{
			out.addTxt(MetaString::GENERAL_TXT, 134);
			out.addReplacement(visitor->name);
		}
		else
			out.addTxt(MetaString::ADVOB_TXT, 189);
		break;
	case NO_WATER:
		logGlobal->error("Shipyard without water! %s \t %d", o->pos.toString(), o->id.getNum());
		return;
	}
}
Exemplo n.º 28
0
void XMPMetadataSource::loadIds(const vmf::MetaString& pathToSchema)
{
    MetaString pathToPropertiesArray;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToSchema.c_str(), VMF_NS, SCHEMA_SET, &pathToPropertiesArray);
    MetaString schemaName;
    loadSchemaName(pathToSchema, schemaName);

    SXMPIterator pIter(*xmp, VMF_NS, pathToPropertiesArray.c_str(), kXMP_IterJustChildren);
    MetaString pathToCurrentProperty;
    while (pIter.Next(nullptr, &pathToCurrentProperty))
    {
        MetaString metadataName;
        loadPropertyName(pathToCurrentProperty, metadataName);

        MetaString pathToCurrentMetadataSet;
        SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToCurrentProperty.c_str(), VMF_NS, PROPERTY_SET, &pathToCurrentMetadataSet);
        SXMPIterator mIter(*xmp, VMF_NS, pathToCurrentMetadataSet.c_str(), kXMP_IterJustChildren);
        MetaString pathToCurrentMetadata;
        while (mIter.Next(nullptr, &pathToCurrentMetadata))
        {
            IdType id;
            loadMetadataId(pathToCurrentMetadata, id);
            InternalPath path;
            path.schema = schemaName;
            path.metadata = metadataName;
            path.path = pathToCurrentMetadata;
            idMap[id] = path;
        }
    }
}
Exemplo n.º 29
0
void XMPMetadataSource::saveMetadataFields(const MetaString& pathToMetadata, const shared_ptr<Metadata>& md)
{
    xmp->DeleteStructField(VMF_NS, pathToMetadata.c_str(), VMF_NS, METADATA_FIELDS);
    MetaString fieldsPath;
    SXMPUtils::ComposeStructFieldPath(VMF_NS, pathToMetadata.c_str(), VMF_NS, METADATA_FIELDS, &fieldsPath);
    vector<MetaString> fieldNames = md->getFieldNames();
    if (fieldNames.empty() && !md->empty())
    {
        for(auto it = md->begin(); it != md->end(); ++it)
        {
            saveField("", *it, fieldsPath);
        }
    }
    else
    {
        for(auto it = fieldNames.begin(); it != fieldNames.end(); ++it)
        {
            saveField(*it, md->getFieldValue(*it), fieldsPath);
        }
    }

}
Exemplo n.º 30
0
void CQuestLog::init()
{
	minimap = new CQuestMinimap (Rect (47, 33, 144, 144));
	description = new CTextBox ("", Rect(245, 33, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::WHITE);
	ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CQuestLog::close,this), 547, 401, "IOKAY.DEF", SDLK_RETURN);

	if (quests.size() > QUEST_COUNT)
		slider = new CSlider(203, 199, 230, boost::bind (&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, quests.size(), false, 0);

	for (int i = 0; i < quests.size(); ++i)
	{
		MetaString text;
		quests[i].quest->getRolloverText (text, false);
		if (quests[i].obj)
			text.addReplacement (quests[i].obj->getHoverText()); //get name of the object
		CQuestLabel * label = new CQuestLabel (Rect(28, 199 + i * 24, 172,30), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
		label->callback = boost::bind(&CQuestLog::selectQuest, this, i);
		labels.push_back(label);
	}

	recreateQuestList (0);
}