mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 13:23:56 -07:00
Add "mul_round" op to template parsing to support multiplying-then-rounding.
This allows using arbitrary 'mul' values with Integer types, instead of having to switch them to Decimal types. The ParamNode is not aware of validation (thus types) so a better solution is incredibly non-trivial. Differential Revision: https://code.wildfiregames.com/D268 This was SVN commit r22003.
This commit is contained in:
parent
d91702a16b
commit
19f600cfa2
2 changed files with 8 additions and 14 deletions
|
|
@ -1104,28 +1104,16 @@ void CComponentManager::SendGlobalMessage(entity_id_t ent, const CMessage& msg)
|
|||
|
||||
std::string CComponentManager::GenerateSchema() const
|
||||
{
|
||||
std::string numericOperation =
|
||||
"<optional>"
|
||||
"<attribute name='op'>"
|
||||
"<choice>"
|
||||
"<value>add</value>"
|
||||
"<value>mul</value>"
|
||||
"</choice>"
|
||||
"</attribute>"
|
||||
"</optional>";
|
||||
std::string schema =
|
||||
"<grammar xmlns='http://relaxng.org/ns/structure/1.0' xmlns:a='http://ns.wildfiregames.com/entity' datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'>"
|
||||
"<define name='decimal'>"
|
||||
"<data type='decimal'/>"
|
||||
+ numericOperation +
|
||||
"</define>"
|
||||
"<define name='nonNegativeDecimal'>"
|
||||
"<data type='decimal'><param name='minInclusive'>0</param></data>"
|
||||
+ numericOperation +
|
||||
"</define>"
|
||||
"<define name='positiveDecimal'>"
|
||||
"<data type='decimal'><param name='minExclusive'>0</param></data>"
|
||||
+ numericOperation +
|
||||
"</define>"
|
||||
"<define name='anything'>"
|
||||
"<zeroOrMore>"
|
||||
|
|
|
|||
|
|
@ -83,7 +83,8 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const
|
|||
enum op {
|
||||
INVALID,
|
||||
ADD,
|
||||
MUL
|
||||
MUL,
|
||||
MUL_ROUND
|
||||
} op = INVALID;
|
||||
bool replacing = false;
|
||||
bool filtering = false;
|
||||
|
|
@ -117,6 +118,8 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const
|
|||
op = ADD;
|
||||
else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul")
|
||||
op = MUL;
|
||||
else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul_round")
|
||||
op = MUL_ROUND;
|
||||
else
|
||||
LOGWARNING("Invalid op '%ls'", attr.Value);
|
||||
}
|
||||
|
|
@ -178,7 +181,10 @@ void CParamNode::ApplyLayer(const XMBFile& xmb, const XMBElement& element, const
|
|||
node.m_Value = (oldval + mod).ToString().FromUTF8();
|
||||
break;
|
||||
case MUL:
|
||||
node.m_Value = (oldval.Multiply(mod)).ToString().FromUTF8();
|
||||
node.m_Value = oldval.Multiply(mod).ToString().FromUTF8();
|
||||
break;
|
||||
case MUL_ROUND:
|
||||
node.m_Value = fixed::FromInt(oldval.Multiply(mod).ToInt_RoundToNearest()).ToString().FromUTF8();
|
||||
break;
|
||||
}
|
||||
hasSetValue = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue