Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 85f12de

Browse files
committed
Minor fixes - pulled custom value handling in MOSR into a separate method, multi-lined some inline variables
1 parent 5072edb commit 85f12de

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Entities/MOSRotating.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -479,30 +479,34 @@ int MOSRotating::ReadProperty(std::string propName, Reader &reader)
479479
reader >> m_DamageMultiplier;
480480
m_DamageMultiplierRedefined = true;
481481
} else if (propName == "AddCustomValue") {
482-
std::string customValueType, customKey, customValue;
483-
reader >> customValueType;
484-
customKey = reader.ReadPropName();
485-
customValue = reader.ReadPropValue();
486-
if (customValueType == "NumberValue") {
487-
try {
488-
SetNumberValue(customKey, std::stod(customValue));
489-
} catch (const std::invalid_argument) {
490-
reader.ReportError("Tried to read a non-number value for SetNumberValue.");
491-
}
492-
} else if (customValueType == "StringValue") {
493-
SetStringValue(customKey, customValue);
494-
} else {
495-
reader.ReportError("Invalid CustomValue type " + customValueType);
496-
}
497-
// Artificially end reading this property since we got all we needed
498-
reader.NextProperty();
482+
ReadCustomValueProperty(reader);
499483
} else
500484
// See if the base class(es) can find a match instead
501485
return MOSprite::ReadProperty(propName, reader);
502486

503487
return 0;
504488
}
505489

490+
void MOSRotating::ReadCustomValueProperty(Reader &reader) {
491+
std::string customValueType;
492+
reader >> customValueType;
493+
std::string customKey = reader.ReadPropName();
494+
std::string customValue = reader.ReadPropValue();
495+
if (customValueType == "NumberValue") {
496+
try {
497+
SetNumberValue(customKey, std::stod(customValue));
498+
} catch (const std::invalid_argument) {
499+
reader.ReportError("Tried to read a non-number value for SetNumberValue.");
500+
}
501+
} else if (customValueType == "StringValue") {
502+
SetStringValue(customKey, customValue);
503+
} else {
504+
reader.ReportError("Invalid CustomValue type " + customValueType);
505+
}
506+
// Artificially end reading this property since we got all we needed
507+
reader.NextProperty();
508+
}
509+
506510

507511
//////////////////////////////////////////////////////////////////////////////////////////
508512
// Virtual method: Save

Entities/MOSRotating.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,12 @@ ENTITYALLOCATION(MOSRotating)
12181218

12191219
void Clear();
12201220

1221+
/// <summary>
1222+
/// Handles reading for custom values, dealing with the various types of custom values.
1223+
/// </summary>
1224+
/// <param name="reader">A Reader lined up to the custom value type to be read.</param>
1225+
void ReadCustomValueProperty(Reader &reader);
1226+
12211227

12221228
// Disallow the use of some implicit methods.
12231229
MOSRotating(const MOSRotating &reference);

0 commit comments

Comments
 (0)