Ticket #2936: relativetemplates.patch
File relativetemplates.patch, 8.3 KB (added by , 9 years ago) |
---|
-
source/simulation2/components/CCmpFootprint.cpp
59 59 "<choice>" 60 60 "<element name='Square' a:help='Set the footprint to a square of the given size'>" 61 61 "<attribute name='width' a:help='Size of the footprint along the left/right direction (in metres)'>" 62 "<ref name='positiveDecimal '/>"62 "<ref name='positiveDecimalAttribute'/>" 63 63 "</attribute>" 64 64 "<attribute name='depth' a:help='Size of the footprint along the front/back direction (in metres)'>" 65 "<ref name='positiveDecimal '/>"65 "<ref name='positiveDecimalAttribute'/>" 66 66 "</attribute>" 67 67 "</element>" 68 68 "<element name='Circle' a:help='Set the footprint to a circle of the given size'>" 69 69 "<attribute name='radius' a:help='Radius of the footprint (in metres)'>" 70 "<ref name='positiveDecimal '/>"70 "<ref name='positiveDecimalAttribute'/>" 71 71 "</attribute>" 72 72 "</element>" 73 73 "</choice>" -
source/simulation2/components/CCmpObstruction.cpp
112 112 "<choice>" 113 113 "<element name='Static'>" 114 114 "<attribute name='width'>" 115 "<ref name='positiveDecimal '/>"115 "<ref name='positiveDecimalAttribute'/>" 116 116 "</attribute>" 117 117 "<attribute name='depth'>" 118 "<ref name='positiveDecimal '/>"118 "<ref name='positiveDecimalAttribute'/>" 119 119 "</attribute>" 120 120 "</element>" 121 121 "<element name='Unit'>" 122 122 "<attribute name='radius'>" 123 "<ref name='positiveDecimal '/>"123 "<ref name='positiveDecimalAttribute'/>" 124 124 "</attribute>" 125 125 "</element>" 126 126 "<element name='Obstructions'>" … … 138 138 "</attribute>" 139 139 "</optional>" 140 140 "<attribute name='width'>" 141 "<ref name='positiveDecimal '/>"141 "<ref name='positiveDecimalAttribute'/>" 142 142 "</attribute>" 143 143 "<attribute name='depth'>" 144 "<ref name='positiveDecimal '/>"144 "<ref name='positiveDecimalAttribute'/>" 145 145 "</attribute>" 146 146 "</element>" 147 147 "</zeroOrMore>" -
source/simulation2/components/CCmpVisualActor.cpp
146 146 "</element>" 147 147 "<element name='Box' a:help='Sets the selection shape to a box of specified dimensions'>" 148 148 "<attribute name='width'>" 149 "<ref name='positiveDecimal '/>"149 "<ref name='positiveDecimalAttribute'/>" 150 150 "</attribute>" 151 151 "<attribute name='height'>" 152 "<ref name='positiveDecimal '/>"152 "<ref name='positiveDecimalAttribute'/>" 153 153 "</attribute>" 154 154 "<attribute name='depth'>" 155 "<ref name='positiveDecimal '/>"155 "<ref name='positiveDecimalAttribute'/>" 156 156 "</attribute>" 157 157 "</element>" 158 158 "<element name='Cylinder' a:help='Sets the selection shape to a cylinder of specified dimensions'>" 159 159 "<attribute name='radius'>" 160 "<ref name='positiveDecimal '/>"160 "<ref name='positiveDecimalAttribute'/>" 161 161 "</attribute>" 162 162 "<attribute name='height'>" 163 "<ref name='positiveDecimal '/>"163 "<ref name='positiveDecimalAttribute'/>" 164 164 "</attribute>" 165 165 "</element>" 166 166 "</choice>" -
source/simulation2/docs/SimulationDocs.h
314 314 For early development of a new component, you can set the schema to <code><ref name='anything'/></code> to allow any content. 315 315 If you don't define @c GetSchema, then the default is <code><empty/></code> (i.e. there must be no elements). 316 316 317 nonNegativeDecimal supports a basic operation attribute that is performed upon its parent's elements. Valid methods are "add", 318 "sub", "mul", and "div". If the parent templates appears like so: 319 @code 320 <Entity> 321 <Example> 322 <Name>Semi-Humanoids</Name> 323 <Height>9000</Height> 324 <Eyes/> 325 </Example> 326 <!-- ... other components ... --> 327 </Entity> 328 @endcode 329 and the child template appears like so: 330 @code 331 <Entity> 332 <Example> 333 <Name>Barney</Name> 334 <Height method="add">5</Height> 335 <Eyes/> 336 </Example> 337 <!-- ... other components ... --> 338 </Entity> 339 @endcode 340 then Barney would have a height of 9005. 317 341 318 342 @section allowing-js-interfaces Allowing interfaces to be implemented in JS 319 343 -
source/simulation2/system/ComponentManager.cpp
1085 1085 std::string schema = 1086 1086 "<grammar xmlns='http://relaxng.org/ns/structure/1.0' xmlns:a='http://ns.wildfiregames.com/entity' datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'>" 1087 1087 "<define name='nonNegativeDecimal'>" 1088 "<optional><attribute name='method'/></optional>" 1088 1089 "<data type='decimal'><param name='minInclusive'>0</param></data>" 1089 1090 "</define>" 1090 1091 "<define name='positiveDecimal'>" 1092 "<optional><attribute name='method'/></optional>" 1091 1093 "<data type='decimal'><param name='minExclusive'>0</param></data>" 1092 1094 "</define>" 1095 "<define name='positiveDecimalAttribute'>" 1096 "<data type='decimal'><param name='minExclusive'>0</param></data>" 1097 "</define>" 1093 1098 "<define name='anything'>" 1094 1099 "<zeroOrMore>" 1095 1100 "<choice>" -
source/simulation2/system/ParamNode.cpp
78 78 79 79 bool hasSetValue = false; 80 80 81 // Look for special attributes82 81 int at_disable = xmb.GetAttributeID("disable"); 83 82 int at_replace = xmb.GetAttributeID("replace"); 83 int at_method = xmb.GetAttributeID("method"); 84 84 int at_datatype = xmb.GetAttributeID("datatype"); 85 85 bool replacing = false; 86 enum method { 87 ADD, 88 SUB, 89 MUL, 90 DIV, 91 INVALID 92 } method = INVALID; 86 93 { 87 94 XERO_ITER_ATTR(element, attr) 88 95 { … … 96 103 m_Childs.erase(name); 97 104 replacing = true; 98 105 } 106 else if (attr.Name == at_method) 107 { 108 if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"add") 109 method = ADD; 110 else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"sub") 111 method = SUB; 112 else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"mul") 113 method = MUL; 114 else if (std::wstring(attr.Value.begin(), attr.Value.end()) == L"div") 115 method = DIV; 116 else 117 LOGWARNING(L"Invalid method '%ls'", attr.Value.c_str()); 118 } 99 119 } 100 120 } 101 121 { … … 142 162 143 163 // Add this element as a child node 144 164 CParamNode& node = m_Childs[name]; 165 if (method != INVALID) 166 { 167 // TODO: Support parsing of data types other than fixed; log warnings in other cases 168 fixed oldval = node.ToFixed(); 169 fixed mod = fixed::FromString(CStrW(value)); 170 switch (method) 171 { 172 case SUB: mod = -mod; 173 case ADD: 174 node.m_Value = (oldval + mod).ToString().FromUTF8(); 175 break; 176 case MUL: 177 node.m_Value = (oldval.Multiply(mod)).ToString().FromUTF8(); 178 break; 179 case DIV: 180 if (mod.IsZero()) 181 { 182 // Even though it's undefined, just return the original value 183 LOGWARNING(L"Attempted divide-by-zero in '%hs'%ls'.", name.c_str(), sourceIdentifier ? (L" in '" + std::wstring(sourceIdentifier) + L"'").c_str() : L""); 184 break; 185 } 186 node.m_Value = (oldval / mod).ToString().FromUTF8(); 187 break; 188 } 189 hasSetValue = true; 190 } 145 191 if (!hasSetValue) 146 192 node.m_Value = value; 147 193 … … 155 201 XERO_ITER_ATTR(element, attr) 156 202 { 157 203 // Skip special attributes 158 if (attr.Name == at_replace) continue; 204 if (attr.Name == at_replace || attr.Name == at_method) 205 continue; 159 206 // Add any others 160 207 std::string attrName = xmb.GetAttributeString(attr.Name); 161 208 node.m_Childs["@" + attrName].m_Value = attr.Value.FromUTF8();