mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2024-11-17 04:44:23 +00:00
Adding addComponent and removeComponent shortcut functions.
This commit is contained in:
parent
fe7e2854de
commit
7b283d5f86
20
tiny.lua
20
tiny.lua
@ -37,6 +37,8 @@ local select = select
|
||||
local tiny_manageEntities
|
||||
local tiny_manageSystems
|
||||
local tiny_addEntity
|
||||
local tiny_addComponent
|
||||
local tiny_removeComponent
|
||||
local tiny_addSystem
|
||||
local tiny_add
|
||||
local tiny_removeEntity
|
||||
@ -460,6 +462,22 @@ function tiny.addEntity(world, entity)
|
||||
end
|
||||
tiny_addEntity = tiny.addEntity
|
||||
|
||||
--- Adds a component to an Entity in the world
|
||||
-- Shortcut for calling addEntity after adding a component. Returns the entity.
|
||||
function tiny.addComponent(world, entity, component_name, component_object)
|
||||
entity[component_name] = component_object
|
||||
return tiny.addEntity(world, entity)
|
||||
end
|
||||
tiny_addComponent = tiny.addComponent
|
||||
|
||||
--- Removes a component from an Entity in the world
|
||||
-- Shortcut for calling addEntity after removing a component. Returns the entity.
|
||||
function tiny.removeComponent(world, entity, component_name)
|
||||
entity[component_name] = nil
|
||||
return tiny.addEntity(world, entity)
|
||||
end
|
||||
tiny_removeComponent = tiny.removeComponent
|
||||
|
||||
--- Adds a System to the world. Returns the System.
|
||||
function tiny.addSystem(world, system)
|
||||
assert(system.world == nil, "System already belongs to a World.")
|
||||
@ -843,6 +861,8 @@ worldMetaTable = {
|
||||
__index = {
|
||||
add = tiny.add,
|
||||
addEntity = tiny.addEntity,
|
||||
addComponent = tiny.addComponent,
|
||||
removeComponent = tiny.removeComponent,
|
||||
addSystem = tiny.addSystem,
|
||||
remove = tiny.remove,
|
||||
removeEntity = tiny.removeEntity,
|
||||
|
Loading…
Reference in New Issue
Block a user