| 1257 | //----------------------------------------------------------------------------- |
| 1258 | |
| 1259 | void SimObject::setPrefixedDynamicDataField(StringTableEntry fieldName, const char *array, const char *value, const S32 fieldType) |
| 1260 | { |
| 1261 | // Sanity! |
| 1262 | AssertFatal(fieldName != NULL, "Cannot set object field value with NULL field name."); |
| 1263 | AssertFatal(value != NULL, "Field value cannot be NULL."); |
| 1264 | |
| 1265 | // Set value without prefix if no field type was specified. |
| 1266 | if (fieldType == -1) |
| 1267 | { |
| 1268 | setDataField(fieldName, NULL, value); |
| 1269 | return; |
| 1270 | } |
| 1271 | |
| 1272 | // Fetch the console base type. |
| 1273 | ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType(fieldType); |
| 1274 | |
| 1275 | // Did we find the console base type? |
| 1276 | if (pConsoleBaseType == NULL) |
| 1277 | { |
| 1278 | // No, so warn. |
| 1279 | Con::warnf("setPrefixedDynamicDataField() - Invalid field type '%d' specified for field '%s' with value '%s'.", |
| 1280 | fieldType, fieldName, value); |
| 1281 | } |
| 1282 | |
| 1283 | // Set value without prefix if there's no value or we didn't find the console base type. |
| 1284 | if (*value == 0 || pConsoleBaseType == NULL) |
| 1285 | { |
| 1286 | setDataField(fieldName, NULL, value); |
| 1287 | return; |
| 1288 | } |
| 1289 | |
| 1290 | // Fetch the field prefix. |
| 1291 | StringTableEntry fieldPrefix = pConsoleBaseType->getTypePrefix(); |
| 1292 | |
| 1293 | // Sanity. |
| 1294 | AssertFatal(fieldPrefix != NULL, "Field prefix cannot be NULL."); |
| 1295 | |
| 1296 | // Do we have a field prefix? |
| 1297 | if (fieldPrefix == StringTable->EmptyString()) |
| 1298 | { |
| 1299 | // No, so set the data field in the usual way. |
| 1300 | setDataField(fieldName, NULL, value); |
| 1301 | return; |
| 1302 | } |
| 1303 | |
| 1304 | // Yes, so fetch the length of the field prefix. |
| 1305 | const U32 fieldPrefixLength = dStrlen(fieldPrefix); |
| 1306 | |
| 1307 | // Yes, so does it start with the object field prefix? |
| 1308 | if (dStrnicmp(value, fieldPrefix, fieldPrefixLength) != 0) |
| 1309 | { |
| 1310 | // No, so set the data field in the usual way. |
| 1311 | setDataField(fieldName, NULL, value); |
| 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | // Yes, so set the data excluding the prefix. |
| 1316 | setDataField(fieldName, NULL, value + fieldPrefixLength); |
nothing calls this directly
no test coverage detected