mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 03:53:39 +00:00
82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
#include "../../Platform/stdafx.h"
|
|
|
|
#include "Attribute.h"
|
|
#include "RangedAttribute.h"
|
|
#include "AttributeInstance.h"
|
|
#include "ModifiableAttributeInstance.h"
|
|
#include "ServersideAttributeMap.h"
|
|
|
|
AttributeInstance* ServersideAttributeMap::getInstance(Attribute* attribute) {
|
|
return BaseAttributeMap::getInstance(attribute);
|
|
}
|
|
|
|
AttributeInstance* ServersideAttributeMap::getInstance(eATTRIBUTE_ID id) {
|
|
AttributeInstance* result = BaseAttributeMap::getInstance(id);
|
|
|
|
// 4J: Removed legacy name
|
|
// If we didn't find it, search by legacy name
|
|
/*if (result == NULL)
|
|
{
|
|
AUTO_VAR(it, attributesByLegacy.find(name));
|
|
if(it != attributesByLegacy.end())
|
|
{
|
|
result = it->second;
|
|
}
|
|
}*/
|
|
|
|
return result;
|
|
}
|
|
|
|
AttributeInstance* ServersideAttributeMap::registerAttribute(
|
|
Attribute* attribute) {
|
|
AUTO_VAR(it, attributesById.find(attribute->getId()));
|
|
if (it != attributesById.end()) {
|
|
return it->second;
|
|
}
|
|
|
|
AttributeInstance* instance =
|
|
new ModifiableAttributeInstance(this, attribute);
|
|
attributesById.insert(std::pair<eATTRIBUTE_ID, AttributeInstance*>(
|
|
attribute->getId(), instance));
|
|
|
|
// 4J: Removed legacy name
|
|
// If this is a ranged attribute also add to legacy name map
|
|
/*RangedAttribute *rangedAttribute =
|
|
dynamic_cast<RangedAttribute*>(attribute); if (rangedAttribute != NULL &&
|
|
rangedAttribute->getImportLegacyName() != L"")
|
|
{
|
|
attributesByLegacy.insert(std::pair<std::wstring,
|
|
AttributeInstance*>(rangedAttribute->getImportLegacyName(), instance));
|
|
}*/
|
|
|
|
return instance;
|
|
}
|
|
|
|
void ServersideAttributeMap::onAttributeModified(
|
|
ModifiableAttributeInstance* attributeInstance) {
|
|
if (attributeInstance->getAttribute()->isClientSyncable()) {
|
|
dirtyAttributes.insert(attributeInstance);
|
|
}
|
|
}
|
|
|
|
std::unordered_set<AttributeInstance*>*
|
|
ServersideAttributeMap::getDirtyAttributes() {
|
|
return &dirtyAttributes;
|
|
}
|
|
|
|
std::unordered_set<AttributeInstance*>*
|
|
ServersideAttributeMap::getSyncableAttributes() {
|
|
std::unordered_set<AttributeInstance*>* result =
|
|
new std::unordered_set<AttributeInstance*>();
|
|
std::vector<AttributeInstance*> atts;
|
|
getAttributes(atts);
|
|
for (int i = 0; i < atts.size(); i++) {
|
|
AttributeInstance* instance = atts.at(i);
|
|
|
|
if (instance->getAttribute()->isClientSyncable()) {
|
|
result->insert(instance);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
} |