Added unique ids to Mapping and Paint

This commit is contained in:
Tats
2013-12-05 00:16:37 -05:00
parent b988a9a814
commit 80f2d92eab
8 changed files with 93 additions and 59 deletions

View File

@@ -25,29 +25,30 @@ MappingManager::MappingManager()
}
std::map<int, Mapping::ptr> MappingManager::getPaintMappings(const Paint::ptr paint) const
std::map<uint, Mapping::ptr> MappingManager::getPaintMappings(const Paint::ptr paint) const
{
std::map<int, Mapping::ptr> paintMappings;
for (int i=0; i<mappings.size(); i++)
std::map<uint, Mapping::ptr> paintMappings;
for (std::vector<Mapping::ptr>::const_iterator it = mappingVector.begin(); it != mappingVector.end(); ++it)
{
if (mappings[i]->getPaint() == paint)
paintMappings[i] = mappings[i];
if ((*it)->getPaint() == paint)
paintMappings[(*it)->getId()] = *it;
}
return paintMappings;
}
std::map<int, Mapping::ptr> MappingManager::getPaintMappings(int i) const
std::map<uint, Mapping::ptr> MappingManager::getPaintMappingsById(uint paintId) const
{
return getPaintMappings( paints[i] );
return getPaintMappings( paintMap.at(paintId) );
}
int MappingManager::addPaint(Paint::ptr paint)
uint MappingManager::addPaint(Paint::ptr paint)
{
paints.push_back(paint);
return paints.size()-1;
paintVector.push_back(paint);
paintMap[paint->getId()] = paint;
return paint->getId();
}
int MappingManager::addImage(const QString imagePath, int frameWidth, int frameHeight)
uint MappingManager::addImage(const QString imagePath, int frameWidth, int frameHeight)
{
Image* img = new Image(imagePath);
@@ -62,15 +63,15 @@ int MappingManager::addImage(const QString imagePath, int frameWidth, int frameH
//
//}
int MappingManager::addMapping(Mapping::ptr mapping)
uint MappingManager::addMapping(Mapping::ptr mapping)
{
if (std::find(paints.begin(), paints.end(), mapping->getPaint()) != paints.end())
{
mappings.push_back(mapping);
return mappings.size()-1;
}
else
return (-1);
// Make sure the paint to which this mapping refers to exists in the manager.
Q_ASSERT (std::find(paintVector.begin(), paintVector.end(), mapping->getPaint()) != paintVector.end());
mappingVector.push_back(mapping);
mappingMap[mapping->getId()] = mapping;
return mapping->getId();
}
//bool MappingManager::removeMapping(Mapping::ptr mapping)