oleksandr-shvets / behavioral-ecsy-system

abstract Entity-Component System, that splits the main tick method into small Behaviour functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

behavioral-ecsy-system

This is abstract ECSY System, that splits the execute method into behaviours.
Behaviours is the pure functions, related to Query. Functions, that takes data from one components and transfer it to other componens.

Example

class InputSystem extends BehaviouralSystem {
    static behaviours = {
         mouseClick: {
          read: [MouseEvent], // readable components
          write: [MouseInput], // mutable components
          execute: ({MouseEvent: button}, {MouseInput: buttons}) => buttons.push(button)
        },
        mouseMovement: {
            read: [MouseEvent, Window],
            write: [MouseInput], 
            execute: ({
                MouseEvent: {clientX, clientY}, 
                Window: {innerWidth, innerHeight}
              }, 
              {MouseInput: position}
            ) => {
              position.x = clientX / innerWidth * 2 - 1
              position.y = clientY / innerHeight * -2 + 1
            }
        }
    }
}
// InputSystem.queries will be generated automatically
                                         

About

abstract Entity-Component System, that splits the main tick method into small Behaviour functions.

License:Mozilla Public License 2.0


Languages

Language:JavaScript 100.0%