User Tools

Site Tools


dragengine:modules:dragonscript:abstractions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
dragengine:modules:dragonscript:abstractions [2019/04/25 19:03] – created dragonlorddragengine:modules:dragonscript:abstractions [2020/04/03 10:21] – url move dragonlord
Line 1: Line 1:
 +{{tag>dragonscript project behavior}}
 <WRAP youarehere> <WRAP youarehere>
 [[:start|Start Page]] >> [[dragengine:modules:dragonscript:main|DragonScript Scripting Language]] >> **Abstraction Layers: How you want to build your Game** [[:start|Start Page]] >> [[dragengine:modules:dragonscript:main|DragonScript Scripting Language]] >> **Abstraction Layers: How you want to build your Game**
Line 14: Line 15:
 **Behavior Elements** are build on top of the **Scenery Elements** and provide a **composeable** way to build game logic. This is the fastest way to build your game by befitting elements with reusable **behavior** while still retaining all the powerful coupling to other script classes. **Behavior Elements** are build on top of the **Scenery Elements** and provide a **composeable** way to build game logic. This is the fastest way to build your game by befitting elements with reusable **behavior** while still retaining all the powerful coupling to other script classes.
  
-Behavior elements are created by subclassing from [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElementClass.html|BehaviorElementClass]] script class. This class extends the [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ElementClass.html|ElementClass]] script class with support to add **Behavior Definitions**. When a [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance is created these **behavior definitions** are used to befit the element with all the required functionality. All this can be done manually by using **Scenery Elements** but using **Behavior Elements** this boils down to just adding the **behavior definitions** you like to use.+Behavior elements are created by subclassing from [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElementClass.html|BehaviorElementClass]] script class. This class extends the [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ElementClass.html|ElementClass]] script class with support to add **Behavior Definitions**. When a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance is created these **behavior definitions** are used to befit the element with all the required functionality. All this can be done manually by using **Scenery Elements** but using **Behavior Elements** this boils down to just adding the **behavior definitions** you like to use.
  
-Behavior definitions are created by subclassing from [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/interfaceDragengine_1_1Scenery_1_1ECBehavior.html|ECBehavior]] script class. This stands for **Element Class Behavior**. Behavior definitions typically contain **Composeable Element Class** or **Element Class Property** instances with appropriate parameters set. This has a few nice properties making life simpler.+Behavior definitions are created by subclassing from [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/interfaceDragengine_1_1Scenery_1_1ECBehavior.html|ECBehavior]] script class. This stands for **Element Class Behavior**. Behavior definitions typically contain **Composeable Element Class** or **Element Class Property** instances with appropriate parameters set. This has a few nice properties making life simpler.
  
 Element class properties can be used with **XML Subclassing**. You can created a new element class just using an XML file (*.deeclass) and change the properties added by the behavior definition. This is especially useful for mappers to add variations of **Game Objects** without needing to touch script code for such a simple task. Element class properties can be used with **XML Subclassing**. You can created a new element class just using an XML file (*.deeclass) and change the properties added by the behavior definition. This is especially useful for mappers to add variations of **Game Objects** without needing to touch script code for such a simple task.
Line 22: Line 23:
 Furthermore **Element Stubs** used to create **Game Objects** in your game world use the same names as the element class properties. This allows mappers to modify behaviors on a per **Game Object** basis if required. Furthermore **Element Stubs** used to create **Game Objects** in your game world use the same names as the element class properties. This allows mappers to modify behaviors on a per **Game Object** basis if required.
  
-You can query [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElementClass.html|BehaviorElementClass]] if it contains behaviors of a specific type. Some behavior definitions can be used more than once on the same element class. In this case you can assign each instance a unique **identifier**. This identifier is used to distinguish between the behavior definition instances and acts also as prefix modified of the added element class properties.+You can query [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElementClass.html|BehaviorElementClass]] if it contains behaviors of a specific type. Some behavior definitions can be used more than once on the same element class. In this case you can assign each instance a unique **identifier**. This identifier is used to distinguish between the behavior definition instances and acts also as prefix modified of the added element class properties.
  
-Once a [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance is created each behavior definitions adds a subclass of [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/interfaceDragengine_1_1Scenery_1_1ECBehaviorInstance.html|ECBehaviorInstance]]. These provide the actual behavior to the [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance. Here too you can query the element if it contains instances of a specific behavior.+Once a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance is created each behavior definitions adds a subclass of [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/interfaceDragengine_1_1Scenery_1_1ECBehaviorInstance.html|ECBehaviorInstance]]. These provide the actual behavior to the [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance. Here too you can query the element if it contains instances of a specific behavior.
  
 Behaviors are split in two groups: **Basic Behaviors** and **Complex Behaviors**. **Basic Behaviors** add a small basic building block of game logic like for example a component showing the visual appearance of a game object. These are highly reusable. **Complex Behaviors** on the other hand typically expect one or more **Basic Behaviors** to be present in the element class to provide a complex behavior for example animating the visual appearance. Behaviors are split in two groups: **Basic Behaviors** and **Complex Behaviors**. **Basic Behaviors** add a small basic building block of game logic like for example a component showing the visual appearance of a game object. These are highly reusable. **Complex Behaviors** on the other hand typically expect one or more **Basic Behaviors** to be present in the element class to provide a complex behavior for example animating the visual appearance.
Line 30: Line 31:
  
 The **DragonScript Scripting Module** provides these **Basic Behaviors** as starting help: The **DragonScript Scripting Module** provides these **Basic Behaviors** as starting help:
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]: Adds a [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Component.html|Component]] to the providing the **Visual Appearance** of an element. This behavior can be used multiple times. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]: Adds a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Component.html|Component]] to the providing the **Visual Appearance** of an element. This behavior can be used multiple times. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorCollider.html|ECBehaviorCollider]]: Adds a [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Collider.html|Collider]] to the element providing the **Physical Interaction** of an element. This contains collision detection of various kinds. This behavior can be used only once. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorCollider.html|ECBehaviorCollider]]: Adds a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Collider.html|Collider]] to the element providing the **Physical Interaction** of an element. This contains collision detection of various kinds. This behavior can be used only once. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorLight.html|ECBehaviorLight]]: Attaches a [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Light.html|Light]] to the element. This behavior can be used multiple times. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorLight.html|ECBehaviorLight]]: Attaches a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Light.html|Light]] to the element. This behavior can be used multiple times. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorSpeaker.html|ECBehaviorSpeaker]]: Attaches a [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Speaker.html|Speaker]] to the element. This behavior can be used multiple times. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorSpeaker.html|ECBehaviorSpeaker]]: Attaches a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Speaker.html|Speaker]] to the element. This behavior can be used multiple times. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTriggered.html|ECBehaviorTriggered]]: Adds support to be triggered by a **Trigger Expression**. This behavior can be used multiple times.+  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTriggered.html|ECBehaviorTriggered]]: Adds support to be triggered by a **Trigger Expression**. This behavior can be used multiple times.
  
 The **DragonScript Scripting Module** provides these **Complex Behaviors** as starting help: The **DragonScript Scripting Module** provides these **Complex Behaviors** as starting help:
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorAnimated.html|ECBehaviorAnimated]]: Adds support to animate a single [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]. This behavior can be used multiple times each instance animating a different [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorAnimated.html|ECBehaviorAnimated]]: Adds support to animate a single [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]. This behavior can be used multiple times each instance animating a different [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTwoStateAnimated.html|ECBehaviorTwoStateAnimated]]: Similar to [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorAnimated.html|ECBehaviorAnimated]] but supports switching between the animation states. A typical example would be a door which can be in an open or closed state.This behavior can be used multiple times. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTwoStateAnimated.html|ECBehaviorTwoStateAnimated]]: Similar to [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorAnimated.html|ECBehaviorAnimated]] but supports switching between the animation states. A typical example would be a door which can be in an open or closed state.This behavior can be used multiple times. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorMoveOnRail.html|ECBehaviorMoveOnRail]]: Adds support to move an [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorCollider.html|ECBehaviorCollider]] along a path laid out by the mapper using **Rail Corners**. This behavior can be used only once. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorMoveOnRail.html|ECBehaviorMoveOnRail]]: Adds support to move an [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorCollider.html|ECBehaviorCollider]] along a path laid out by the mapper using **Rail Corners**. This behavior can be used only once. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorConversation.html|ECBehaviorConversation]]: Adds support to play back a **Conversation** if triggered by [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTriggered.html|ECBehaviorTriggered]] or manually started. This behavior can be used only once. +  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorConversation.html|ECBehaviorConversation]]: Adds support to play back a **Conversation** if triggered by [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTriggered.html|ECBehaviorTriggered]] or manually started. This behavior can be used only once. 
-  * [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorHearSounds.html|ECBehaviorHearSounds]]: Adds a [[https://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1SoundLevelMeter.html|SoundLevelMeter]] to listen what sounds are playing around the element.+  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorHearSounds.html|ECBehaviorHearSounds]]: Adds a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1SoundLevelMeter.html|SoundLevelMeter]] to listen what sounds are playing around the element.
  
  
Line 98: Line 99:
 </code> </code>
  
 +If you want to also add run-time behavior on top of the behavior without creating your own behavior you can modify the code like this:
 +<code>
 +class MyTrainClass extends BehaviorElementClass
 +    ...
 +    protected func Element createElement()
 +        return MyTrain.new(this)
 +    end
 +end
  
 +class MyTrain extends BehaviorElement
 +    public func new(MyTrainClass eclass) super(eclass)
 +        ...
 +    end
 +end
 +</code>
 ====== Scenery Elements: Customized and Optimized for Special Needs ====== ====== Scenery Elements: Customized and Optimized for Special Needs ======
  
dragengine/modules/dragonscript/abstractions.txt · Last modified: 2024/03/14 16:43 by dragonlord