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 resources 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 ;) | |||||
* @param additional - Array of additional data elements. Time, xp, treasure, etc. | |||||
* @param subtypes - If true, damageType subtypes will be included as well. | |||||
* @return RelaxNG schema string | |||||
Done Inline ActionsJust rename this to function BuildDamageTypesSchema() wraitii: Just rename this to `function BuildDamageTypesSchema()` | |||||
*/ | |||||
Done Inline ActionsMTM: Clean this. Freagarach: MTM: Clean this. | |||||
DamageTypes.prototype.BuildSchema = function(helptext = "", additional = [], subtypes = false) | |||||
{ | { | ||||
return this.GetTypes().reduce((schema, type) => | let datatype = "<data type='nonNegativeDecimal'/>"; | ||||
schema + "<element name='"+type+"' a:help='"+type+" "+helptext+"'><ref name='nonNegativeDecimal'/></element>", | |||||
""); | let damageTypes = this.GetTypes(); | ||||
let schema = ""; | |||||
for (let damageType of damageTypes.concat(additional)) | |||||
schema += | |||||
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. | |||||
"<optional>" + | |||||
"<element name='"+damageType+"' a:help='"+damageType+" "+helptext+"'><ref name='nonNegativeDecimal'/></element>" + | |||||
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. | |||||
"</optional>"; | |||||
if (!subtypes) | |||||
return "<interleave>" + schema + "</interleave>"; | |||||
for (let damageType of damageTypes) | |||||
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… | |||||
for (let damageSubType in damageType.subtypes) | |||||
schema += | |||||
"<optional>" + | |||||
"<element name='" + damageType.code + "." + damageSubType + "'>" + | |||||
datatype + | |||||
"</element>" + | |||||
"</optional>"; | |||||
return "<interleave>" + schema + "</interleave>"; | |||||
}; | |||||
/** | |||||
* Builds the value choices for a RelaxNG `<choice></choice>` object, based on currently valid resources. | |||||
* | |||||
* @oaram subtypes - If set to true, the choices returned will be damageType subtypes, rather than main types | |||||
* @return String of RelaxNG Schema `<choice/>` values. | |||||
*/ | |||||
DamageTypes.prototype.BuildChoicesSchema = function(subtypes = false) | |||||
{ | |||||
let schema = ""; | |||||
let damageTypes = this.GetTypes(); | |||||
if (!subtypes) | |||||
for (let damageType of damageTypes) | |||||
schema += "<value>" + damageType + "</value>"; | |||||
else | |||||
for (let damageType of damageTypes) | |||||
for (let subtype in damageType.subtypes) | |||||
schema += "<value>" + damageType.code + "." + subtype + "</value>"; | |||||
Done Inline ActionsYou don't need the braces here :) Stan: You don't need the braces here :) | |||||
return "<choice>" + schema + "</choice>"; | |||||
}; | }; | ||||
DamageTypes = new DamageTypes(); | DamageTypes = new DamageTypes(); | ||||
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