{{tag>dragonscript project behavior gettingstarted}} [[:start|Start Page]] >> [[dragengine:modules:dragonscript:main|DragonScript Scripting Language]] >> [[abstractions|Abstraction Layers]] >> **XML Element Classes** ====== XML Element Classes ====== {{ youtube>heBLyt3b6G0?1000x591 }} \\ Video explaining what behavior factories are, what they can be used for and how they are created. Shown using ExampleApp which contains an example for this. XML Element classes allow to create new element classes using an XML file (''*.deeclass'') instead of writing script code. XML element classes always subclass from an existing script class or XML element class. Using an XML element class you can change properties added by the behavior definitions. Element class properties are typically in the form ''behavior.property'' or ''behavior(id).property''. The identifier is omitted if it is empty string. For example the ECBehaviorComponent behavior uses the prefix ''component.''. Hence ''component.model'' would set the _model_ property. The same for an ECBehaviorComponent with the identifier ''second''. Here the name would be ''component(second).model''. Behaviors can be complex and nested. This allows behaviors to add other behaviors to achieve their goals. Such nested behaviors need to be differentiated from other behaviors of the same kind. The rule is to prefix the property names of the behaviors with their parent prefix to make them unique. For example if you have a fictional behavior MyBehavior with the prefix ''mybehavior.'' which adds one or more ECBehaviorComponent then the property names of those component behaviors would look like ''mybehavior.component.model'' or ''mybehavior.component(second).model''. This nesting can go deeper depending on how complex of a behavior you are designing. In general it is favorable to keep the nesting as little as possible as this is easier to use for team members and modders. ===== Behavior Factories ===== Scripted element classes can be also assigned a list of #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorFactor.html,Behavior Factories~@#. This allows the user to add behaviors to XML element classes if they are in the list of allowed behavior factories. The DragonScript module provides the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1GenericBehaviorElementClass.html,GenericBehaviorElementClass~@# which contains the factories of all DragonScript module provided behavior factories. You can create your own behaviors and make them available to the generic behavior element class by extending #@LinkApiDocDEDS2_HTML~classDragengine_1_1BaseGameApp.html,BaseGameApp.createAndAddBehaviorFactories()~@#. Adding behaviors is done using the ''behavior'' tag. Some behaviors require additional parameters during construction time. These parameters can be defined inside the ''behavior'' tag using the same tags as you use to define element properties. The behavior documentation list the supported parameters. After adding a behavior you can set the element properties outside the ''behavior'' tag as you usually would do. To simplify the adding of behaviors properties of a just added behavior can be also defined by moving the property tags inside the ''behavior'' tag. If you do this you have to remove the behavior property prefix from the property names leaving being only the ''.'' as first character in the name. This way the DragonScript module prepends the behavior property prefix while setting the property values. This is easier to write, increases readability and has less possibility for errors. It is thus recommended to set properties of just added behaviors in this way. (TODO: add video of behavior factories) ===== XML File Structure ===== @startuml object "elementClass" as elementClass { <#transparent,#transparent>|behavior|| |string| string| |float| float| |integer| int| |boolean| bool| |vector| vector3| |vector2| vector2| |point| point2| |point3| point3| |borderSize| borderSize| |rectArea| rectArea| |floatRectArea| floatRectArea| |color| color4| |null| null| |list|| |map|| } object "behavior" as behavior { <#transparent,#transparent>|string| string| |float| float| |integer| int| |boolean| bool| |vector| vector3| |vector2| vector2| |point| point2| |point3| point3| |borderSize| borderSize| |rectArea| rectArea| |floatRectArea| floatRectArea| |color| color4| |null| null| |list|| |map|| } elementClass --> behavior object "list" as list { <#transparent,#transparent>|string| string| |float| float| |integer| int| |boolean| bool| |vector| vector3| |vector2| vector2| |point| point2| |point3| point3| |borderSize| borderSize| |rectArea| rectArea| |floatRectArea| floatRectArea| |color| color4| |null| null| |list|| |map|| } elementClass --> list object "map" as map { <#transparent,#transparent>|string| string| |float| float| |integer| int| |boolean| bool| |vector| vector3| |vector2| vector2| |point| point2| |point3| point3| |borderSize| borderSize| |rectArea| rectArea| |floatRectArea| floatRectArea| |color| color4| |null| null| |list|| |map|| } elementClass --> map @enduml ===== Tags ===== ==== elementClass ==== ^Attribute^Description^Required^Default^ |name|Unique name of the element class to create.|true|-| |class|Name of the element class to subclass.|true|-| ^Tag^Description^Occurance^Default^ |behavior|Add behavior to element class.|0..N|-| |string|Set named element property to string type value. Tag content is string value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. |0..N|empty string| |float|Set named element property to float type value. Tag content is float value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. |0..N|0| |integer|Set named element property to integer type value. Tag content is integer value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. |0..N|0| |boolean|Set named element property to boolean type value. Tag content is boolean value where ''true'', ''yes'', ''1'' are true values and ''false'', ''no'', ''0'' are false values. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. |0..N|false| |vector|Set named element property to floating point vector type value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |vector2|Set named element property to floating point vector2 type value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point|Set named element property to integer point type value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point3|Set named element property to integer point3 type value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |borderSize|Set named element property to integer borderSize type value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * left: Left value. Optional. Defaults to ''0''. * top: Top value. Optional. Defaults to ''0''. * right: Right value. Optional. Defaults to ''0''. * bottom: Bottom value. Optional. Defaults to ''0''. * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. |0..N|-| |rectArea|Set named element property to integer rectArea type value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |floatRectArea|Set named element property to floating point rectArea type value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |color|Set named element property to floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to ''1''. * hex: Set color using hex notation. Value can be ''#rrggbb'' or ''#rrggbbaa'' with components in the range from ''00'' to ''ff''. Both upper and lower case are valid. Optional. Convenience attribute. * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. |0..N|-| |null|Set named element property to null value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. |0..N|-| |list|Set named element property to Array value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. |0..N|-| |map|Set named element property to Dictionary value. Attributes: * name: Name of the property to set. Same name as used for stub properties in world editor. Required. |0..N|-| ==== behavior ==== ^Attribute^Description^Required^Default^ |type|Unique name of the behavior to add to the element class. Only names matching behavior factories added to the super element class can be used.|true|-| |id|Unique identifier of behavior. Required to be used if multiple behaviors of the same type are added.|false|empty string| ^Tag^Description^Occurance^Default^ |string|Set named element property to string type value. Tag content is string value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. |0..N|empty string| |float|Set named element property to float type value. Tag content is float value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. |0..N|0| |integer|Set named element property to integer type value. Tag content is integer value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. |0..N|0| |boolean|Set named element property to boolean type value. Tag content is boolean value where ''true'', ''yes'', ''1'' are true values and ''false'', ''no'', ''0'' are false values. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. |0..N|false| |vector|Set named element property to floating point vector type value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |vector2|Set named element property to floating point vector2 type value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point|Set named element property to integer point type value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point3|Set named element property to integer point3 type value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |borderSize|Set named element property to integer borderSize type value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * left: Left value. Optional. Defaults to ''0''. * top: Top value. Optional. Defaults to ''0''. * right: Right value. Optional. Defaults to ''0''. * bottom: Bottom value. Optional. Defaults to ''0''. * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. |0..N|-| |rectArea|Set named element property to integer rectArea type value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |floatRectArea|Set named element property to floating point rectArea type value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |color|Set named element property to floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to ''1''. * hex: Set color using hex notation. Value can be ''#rrggbb'' or ''#rrggbbaa'' with components in the range from ''00'' to ''ff''. Both upper and lower case are valid. Optional. Convenience attribute. * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. |0..N|-| |null|Set named element property to null value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. |0..N|-| |list|Set named element property to Array value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. |0..N|-| |map|Set named element property to Dictionary value. Attributes: * name: Name of the parameter/property to set. If the name begins with with ''.'' the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required. |0..N|-| ==== list ==== ^Tag^Description^Occurance^Default^ |string|String type value. Tag content is string value.|0..N|empty string| |float|Float type value. Tag content is float value.|0..N|0| |integer|Integer type value. Tag content is integer value.|0..N|0| |boolean|Boolean type value. Tag content is boolean value where ''true'', ''yes'', ''1'' are true values and ''false'', ''no'', ''0'' are false values.|0..N|false| |vector|Floating point vector type value. Attributes: * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |vector2|Floating point vector2 type value. Attributes: * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point|Integer point type value. Attributes: * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point3|Integer point3 type value. Attributes: * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |borderSize|Integer borderSize type value. Attributes: * left: Left value. Optional. Defaults to ''0''. * top: Top value. Optional. Defaults to ''0''. * right: Right value. Optional. Defaults to ''0''. * bottom: Bottom value. Optional. Defaults to ''0''. * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. |0..N|-| |rectArea|Integer rectArea type value. Attributes: * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |floatRectArea|Floating point rectArea type value. Attributes: * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |color|Floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes: * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to ''1''. * hex: Set color using hex notation. Value can be ''#rrggbb'' or ''#rrggbbaa'' with components in the range from ''00'' to ''ff''. Both upper and lower case are valid. Optional. Convenience attribute. * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. |0..N|-| |null|Null value.|0..N|-| |list|Array value.|0..N|-| |map|Dictionary value.|0..N|-| ==== map ==== ^Tag^Description^Occurance^Default^ |string|Set string value. Attributes: * key: Key to assign value to. Required. |0..N|empty string| |float|Set float type value. Tag content is float value. Attributes: * key: Key to assign value to. Required. |0..N|0| |integer|Set integer type value. Tag content is integer value. Attributes: * key: Key to assign value to. Required. |0..N|0| |boolean|Set boolean type value. Tag content is boolean value where ''true'', ''yes'', ''1'' are true values and ''false'', ''no'', ''0'' are false values. Attributes: * key: Key to assign value to. Required. |0..N|false| |vector|Set floating point vector type value. Attributes: * key: Key to assign value to. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |vector2|Set floating point vector2 type value. Attributes: * key: Key to assign value to. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point|Set integer point type value. Attributes: * key: Key to assign value to. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |point3|Set integer point3 type value. Attributes: * key: Key to assign value to. Required. * x: X coordinate of vector. Optional. Defaults to ''0''. * y: Y coordinate of vector. Optional. Defaults to ''0''. * z: Z coordinate of vector. Optional. Defaults to ''0''. |0..N|-| |borderSize|Set integer borderSize type value. Attributes: * key: Key to assign value to. Required. * left: Left value. Optional. Defaults to ''0''. * top: Top value. Optional. Defaults to ''0''. * right: Right value. Optional. Defaults to ''0''. * bottom: Bottom value. Optional. Defaults to ''0''. * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. |0..N|-| |rectArea|Set integer rectArea type value. Attributes: * key: Key to assign value to. Required. * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |floatRectArea|Set floating point rectArea type value. Attributes: * key: Key to assign value to. Required. * x1: Left value. Optional. Defaults to ''0''. * y1: Top value. Optional. Defaults to ''0''. * x2: Right value. Optional. Defaults to ''0''. * y2: Bottom value. Optional. Defaults to ''0''. |0..N|-| |color|Set floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes: * key: Key to assign value to. Required. * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to ''0''. * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to ''1''. * hex: Set color using hex notation. Value can be ''#rrggbb'' or ''#rrggbbaa'' with components in the range from ''00'' to ''ff''. Both upper and lower case are valid. Optional. Convenience attribute. * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. |0..N|-| |null|Set null value. Attributes: * key: Key to assign value to. Required. |0..N|-| |list|Set Array value. Attributes: * key: Key to assign value to. Required. |0..N|-| |map|Set Dictionary value. Attributes: * key: Key to assign value to. Required. |0..N|-| ===== Examples ===== This example creates a simple XML element class based on the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1SimpleElementClass.html,SimpleElementClass~@#. It modifies some element properties to use a specific model, skin and rig resource. The path are either absolute path (if starting with ''/'') or relative to the directory the ''*.deeclass'' file is located in. ++++ Show Example| box.demodel /content/materials/concrete/material.deskin box.derig box.demodel box:position,0,0.3,-0.05:extends,1.3,0.5,1.3 ++++ This example creates a complex XML element class which is based on the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1GenericBehaviorElementClass.html,GenericBehaviorElementClass~@#. This allows adding behaviors inside the ''*.deeclass'' file avoiding the need to write an explicit script class to do the same. This is the example file used in the behavior factory video above. ++++ Show Example| /content/models/box/box.demodel /content/models/box/box.derig customColor.deskin Background Dragoness Text Left Text Right Text Center customColor color1 customColor color1.png color2 customColor color2.png color3 customColor color3.png color4 customColor color4.png color5 customColor color5.png 50 0.5 1 /content/emitters/flame1.depemit /content/emitters/smoke.depemit /content/sound/crackle.ogg 15 0.5 ++++