| 141 | } |
| 142 | |
| 143 | bool CRPGStatsManager::SetAttributeString(CRPGStats_Object * object, const char * attributeName, const char * value) |
| 144 | { |
| 145 | int attributeIndex; |
| 146 | auto typeInfo = GetAttributeInfo(object, attributeName, attributeIndex); |
| 147 | if (typeInfo == nullptr) { |
| 148 | Debug("CRPGStatsManager::SetAttributeString(): Couldn't fetch type info for %s.%s", object->Name, attributeName); |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | if (strcmp(typeInfo->Name.Str, "FixedString") == 0) { |
| 153 | Debug("CRPGStatsManager::SetAttributeString(): Couldn't set %s.%s: Updating FixedStrings not supported YET!", object->Name, attributeName); |
| 154 | } |
| 155 | else if (typeInfo->Values.ItemCount > 0) { |
| 156 | auto enumIndex = typeInfo->Values.Find(value); |
| 157 | if (enumIndex != nullptr) { |
| 158 | object->IndexedProperties[attributeIndex] = *enumIndex; |
| 159 | } |
| 160 | else { |
| 161 | Debug("CRPGStatsManager::SetAttributeString(): Couldn't set %s.%s: Value is not a valid enum label", object->Name, attributeName); |
| 162 | return false; |
| 163 | } |
| 164 | } |
| 165 | else { |
| 166 | Debug("CRPGStatsManager::SetAttributeString(): Couldn't set %s.%s: Inappropriate type", object->Name, attributeName); |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | bool CRPGStatsManager::SetAttributeInt(CRPGStats_Object * object, const char * attributeName, int32_t value) |
| 174 | { |