Entity
Jabr Type: StoreAn Entity is an object (a Jabr store specifically) that is usually part of a scene graph. Basically your game is made up of all kinds of objects like characters, bushes, interactive elements like switches. These types of things are each represented by an entity, and the thing that holds them is the EntityList (a.k.a. this game's version of a scene graph).
An Entity may have any number of properties, however it tends to have a few standard set of properties which plugins tend to expect. These include position and sizing properties like x, y (and z for 3d games), and width and height, (and depth for 3d games). Other properties may include renderPriority (which determines the order that things are drawn) or plugin specific methods.
It may also have the .children property. This property contains an array that functions identically to the EntityList, meaning you can have Entity objects nested inside of each other (allowing it to function as both an Entity and an EntityList).
EntityList
Jabr Type: SignalThe EntityList is a Jabr Signal which contains an array of Entity objects. We can read and write the current list of entities by using the .get() and .set() methods. Here is a basic example of using an EntityList
import {EntityList, Entity} from 'lilis-engine'
const entities = EntityList() // Defaults to an empty array
const character = Entity({x: 0, y: 0, width: 5, height: 5, imageURL: '/player.png'})
entities.set([character]) // Add the character to our entity list
console.log(entities.get()) // Now returns an array with a single Entity inside
As you can see, our core library exports really aren't very complicated. Also, because Jabr provides methods to listen to changes in Signal values plugins can automatically listen to our EntityList to know when Entity objects have been added or removed. We can even use it ourselves if we wish, for example:
import {EntityList, Entity} from 'lilis-engine'
const entityList = EntityList()
entityList.addListener(newEntities =>{
console.log(newEntities)
}) // Add a debug listener so we can listen for changes
entityList.set([Entity({x: 12, y: 12})]) // Ta-daa, our debug listener is immediately called with our new entity array.
Constantly assigning a new array each time our EntityList's value changes can get annoying. That's why the game engine adds a few helper methods to the EntityList, specifically .addChild, .removeChild, and .hasChild. They abstract away the need to manually do array manipulation. If you've used other game engines this might look familiar:
import {Entity, EntityList} from 'lilis-engine'
const entityList = EntityList()
const character = entityList.addChild(Entity({x: 0, y: 0, width: 5, height: 5, imageURL: '/player.png'}))
console.log(entityList.get())
We now have the same entityList value as doing this:
entityList.set([character])
Plus if there were other entities on there already we wouldn't have to do this (because setting a new array as the EntityList value overwrites the old array entirely):
entityList.set(entityList.get().concat(entity))