A Typescript port of Ash Framework, an entity framework for game development
by Richard Lord. This is the bundle package containing the following packages:
Javascript which is a language that typescript is compiling to, is dynamic.
Class properties that are declared but not yet instantiated doesn't have a type.
In AS3 when Node fields are null, but they are declared as some type, that
information is kept at runtime.
Adding typescript to javascript gave us code completion and type checking,
but information about type is dropped as soon as code is compiled to javascript
and not available at runtime. To overcome that issue there is a need to provide
type information. To do that you have to add a static propTypes field. This
way type information is available in compile and runtime. Example:
As you can see there is some code duplication here. To avoid that there are
2 solutions available to choose from in @ash.ts/tools package - @keep decorator
and defineNode helper.
Second important difference is exported JSON format. It's similar but not the
same. All object codecs return object that implements EncodedObject interface.
All use the same "value" key. AS3 version use different keys for different
types.
This utility class is also declared as abstract class with updateNode method
marked as required. There are also 2 optional callback methods that can be
declared in an inherited class:
// required publicupdateNode(node:MovementNode, time:number):void { // update logic } // optional publicnodeAdded = (node:MovementNode) => { // logic to execute when new node is added to the system }; // optional publicnodeRemoved = (node:MovementNode) => { // logic to execute when new node is removed from the system }; }
A Typescript port of Ash Framework, an entity framework for game development by Richard Lord. This is the bundle package containing the following packages:
Differences between typescript and AS3 version
As this is a port to a different language, there are some changes to the API.
Nodes
Javascript which is a language that typescript is compiling to, is dynamic. Class properties that are declared but not yet instantiated doesn't have a type. In AS3 when Node fields are null, but they are declared as some type, that information is kept at runtime. Adding typescript to javascript gave us code completion and type checking, but information about type is dropped as soon as code is compiled to javascript and not available at runtime. To overcome that issue there is a need to provide type information. To do that you have to add a static
propTypes
field. This way type information is available in compile and runtime. Example:As you can see there is some code duplication here. To avoid that there are 2 solutions available to choose from in
@ash.ts/tools
package -@keep
decorator anddefineNode
helper.Using
@keep
decorator:Using
defineNode
helper:or shortest and recommended method:
Systems
Base System class is declared as abstract class with these methods marked as required to be declared in an inherited class.
public abstract addToEngine(engine:Engine):void;
public abstract removeFromEngine(engine:Engine):void;
public abstract update(time:number):void;
Example usage:
IO
This package provides (de)serialization of the Engine. Because of how js handle types, you need to provide additional string to Class map. Eg.:
Other way to create Map (array of [string, Class] tuples):
If you export all components in one file, you can use this method:
If your components are more complex objects, remember to also add all used Classes. Eg. if you use PIXI you might want to add DisplayObject class.
Second important difference is exported JSON format. It's similar but not the same. All object codecs return object that implements EncodedObject interface. All use the same "value" key. AS3 version use different keys for different types.
Typescript exported json example:
value can be any valid json, eg. array in ArrayObjectCodec, number, boolean or string in NativeObjectCodec or object in most other codecs.
ListIteratingSystem
This utility class is also declared as abstract class with
updateNode
method marked as required. There are also 2 optional callback methods that can be declared in an inherited class:protected nodeAdded?:(node:Node) => void;
protected nodeRemoved?:(node:Node) => void;
Example usage: