Changeset View
Standalone View
binaries/data/mods/public/simulation/helpers/DamageTypes.js
DamageTypes.prototype.BuildSchema = function(helptext = "") | /** | ||||
* Builds a RelaxRNG schema based on currently valid elements. | |||||
* | |||||
* To prevent validation errors, disabled damage types are included in the schema. | |||||
* | |||||
* @param {string} helptext - Text displayed as help | |||||
wraitii: You're not actually displaying that :p | |||||
Done Inline ActionsYeah, should be added back line 12. Stan: Yeah, should be added back line 12. | |||||
Done Inline ActionsI don't even know where it is used ;) Freagarach: I don't even know where it is used ;) | |||||
* @return {string} - RelaxNG schema string | |||||
*/ | |||||
function BuildDamageTypesSchema(helptext = "") | |||||
Done Inline ActionsJust rename this to function BuildDamageTypesSchema() wraitii: Just rename this to `function BuildDamageTypesSchema()` | |||||
{ | { | ||||
Done Inline ActionsMTM: Clean this. Freagarach: MTM: Clean this. | |||||
return "<interleave>" + this.GetTypes().reduce((schema, type) => | return "<oneOrMore>" + | ||||
schema + "<element name='"+type+"' a:help='"+type+" "+helptext+"'><ref name='nonNegativeDecimal'/></element>", | "<element a:help='" + helptext + "'>" + | ||||
"") + "</interleave>"; | "<anyName>" + | ||||
}; | // Armour requires Foundation to not be a damage type. | ||||
"<except><name>Foundation</name></except>" + | |||||
Done Inline ActionsSpace between operators ? Stan: Space between operators ? | |||||
Done Inline ActionsAllow "AnyName" instead of hardcoding the damage name here. wraitii: Allow "AnyName" instead of hardcoding the damage name here. | |||||
Done Inline ActionsI'll look into this. Freagarach: I'll look into this. | |||||
Done Inline ActionsI can't seem to get this working: ERROR: CXeromyces: Parse error: in_memory_buffer:1: Element or text conflicts in interleave with this as the shema: let schema = "<oneOrMore>" + "<element a:help='" + helptext + "'>" + "<anyName/>" + "<ref name='nonNegativeDecimal'/>" + "</element>" + "</oneOrMore>"; Freagarach: I can't seem to get this working:
```
ERROR: CXeromyces: Parse error: in_memory_buffer:1… | |||||
Done Inline ActionsThis sent me for a bit of a loop... The problem is that this element's name (being any) might conflict with other elements at the same level. So you need to do something like: DamageTypes.prototype.BuildSchema = function(helptext = "", except = []) { return "<oneOrMore>" + "<element>" + "<anyName>" + (except.length ? ("<except>" + except.map(e => "<name>" + e + "</name>").join('') + "</except>") : "") + "</anyName>" + "<ref name='nonNegativeDecimal' />" + "</element>" + "</oneOrMore>"; }; and pass the appropriate list everywhere (which is annoying where there are many conflicts). Though I do think we should allow any name, so I would wait for D1950 first. wraitii: This sent me for a bit of a loop... The problem is that this element's name (being any) might… | |||||
Done Inline ActionsWe discussed that the "Armour" doesn't need the "Damage"-container, so there it can still conflict with "Foundation", right? And there the except "Foundation" needs to be given, then. If I read this correctly. Freagarach: We discussed that the "Armour" doesn't need the "Damage"-container, so there it can still… | |||||
Done Inline ActionsYou read this correctly indeed, but you need to pass ['Foundation'] as it can take a list. wraitii: You read this correctly indeed, but you need to pass `['Foundation']` as it can take a list. | |||||
"</anyName>" + | |||||
"<ref name='nonNegativeDecimal' />" + | |||||
Done Inline ActionsI've add some more time to think about this, and we don't need the "except" parameter. "<oneOrMore>" + "<element>" + "<anyName>" + // Armour requires Foundation to not be a damage type. "<except>name>Foundation</name></except>" + "</anyName>" + "<ref name='nonNegativeDecimal' />" + "</element>" + "</oneOrMore>" wraitii: I've add some more time to think about this, and we don't need the "except" parameter. | |||||
"</element>" + | |||||
"</oneOrMore>"; | |||||
} | |||||
DamageTypes = new DamageTypes(); | Engine.RegisterGlobal("BuildDamageTypesSchema", BuildDamageTypesSchema); | ||||
Done Inline ActionsWhere is this.GetTypes() defined ? Stan: Where is this.GetTypes() defined ?
Maybe you can access the attribute directly saving a… | |||||
Done Inline ActionsI'm not sure how the helper functions work, but it seems that "this" is the Globalscript of the DamageTypes? Freagarach: I'm not sure how the helper functions work, but it seems that "this" is the Globalscript of the… | |||||
Done Inline ActionsYou don't need the braces here :) Stan: You don't need the braces here :) | |||||
Done Inline ActionsAnd instead here use Engine.RegisterGlobal("BuildDamageTypesSchema", BuildDamageTypesSchema); wraitii: And instead here use `Engine.RegisterGlobal("BuildDamageTypesSchema", BuildDamageTypesSchema);` |
You're not actually displaying that :p