https://github.com/maxiy01/tstl-tiny-ecs
Declarations for tiny-ecs, Entity Component System for Lua that's simple, flexible, and useful.
https://github.com/maxiy01/tstl-tiny-ecs
ecs lua tstl typescript typescript-to-lua
Last synced: about 2 months ago
JSON representation
Declarations for tiny-ecs, Entity Component System for Lua that's simple, flexible, and useful.
- Host: GitHub
- URL: https://github.com/maxiy01/tstl-tiny-ecs
- Owner: maxiy01
- Created: 2021-11-18T10:33:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-18T13:32:35.000Z (over 3 years ago)
- Last Synced: 2025-03-26T11:01:39.118Z (about 2 months ago)
- Topics: ecs, lua, tstl, typescript, typescript-to-lua
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TSTL tiny-ecs
Declarations for [tiny-ecs](https://github.com/bakpakin/tiny-ecs), Entity Component System for Lua that's simple, flexible, and useful.
| Command | Description |
|-|-|
| `yarn add -D tstl-tiny-ecs` | Install these declarations |
| `yarn add bakpakin/tiny-ecs` | Install tiny-ecs |Upon installation these declarations can be linked to a _tsconfig.json_ file.
```json
{
"compilerOptions": {
"types": [
"tstl-tiny-ecs"
]
}
}
```And used within any _.ts_ file.
```ts
import * as tiny from "tiny";
declare let world: tiny.World;class Vec2
{
constructor(public x: number = 0, public y: number = 0)
{
}
}interface HasPositionComponent
{
position: Vec2;
}interface HasVelocityComponent
{
velocity: Vec2;
}class Unit implements HasPositionComponent, HasVelocityComponent
{
position: Vec2;
velocity: Vec2;
constructor(pos_x: number = 0, pos_y: number = 0, vx: number = 0, vy: number = 0)
{
this.position = new Vec2(pos_x,pos_y);
this.velocity = new Vec2(vx,vy);
}
}declare let unit: Unit;
love.load = () => {
world = tiny.world();
unit = new Unit(0,0,10,5);world.addEntity(unit);
let physicsSystem = tiny.processingSystem();
physicsSystem.filter = tiny.requireAll('position','velocity');
physicsSystem.process = (e: HasPositionComponent & HasVelocityComponent, dt: number) => {
e.position.x += e.velocity.x*dt;
e.position.y += e.velocity.y*dt;
};world.addSystem(physicsSystem);
};love.update = (dt: number) => {
world.update(dt);
print("unit.x =",unit.position.x,"; unit.y =",unit.position.y);
}
```Make sure to append `";./node_modules/tiny-ecs/?.lua"` to your `package.path` in a _conf.ts_ file (this is run first) to assist where Lua looks for modules.
```ts
package.path += ";./node_modules/tiny-ecs/?.lua";
```Also you need to add `"typescript-to-lua/language-extensions"` to _tsconfig.json_ file.
```json
{
"compilerOptions": {
"types": [
"typescript-to-lua/language-extensions"
]
}
}
```