Component
A pure data container that is contained by a single entity.
Require
Section titled “Require”If the concord folder is in the root directory of your game, you can import this module like so:
Component = require('concord.component')Exports
Section titled “Exports”| Name | Type | Description |
|---|---|---|
getName |
fun(self: |
Component): string |
hasName |
fun(self: |
Component): boolean |
serialize |
fun(self: |
Component): table|nil |
deserialize |
fun(self: |
Component, data: table): nil |
removed |
fun(self: |
Component, replaced: boolean): nil |
Creates a new ComponentClass and registers it by name.
component = Component.new( name, populate )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
name |
string |
Unique name of the ComponentClass |
populate |
fun(component: Component, ...) |
: nil Function that populates a Component with values |
Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
component |
ComponentClass |
hasName
Section titled “hasName”Returns true if the Component has a name.
boolean = component:hasName()Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
boolean |
boolean |
getName
Section titled “getName”Returns the name of the Component.
string = component:getName()Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
string |
string |
removed
Section titled “removed”Callback for when the Component is removed or replaced in an Entity.
component:removed( replaced )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
replaced |
boolean |
True when the Component is being overwritten, false when it is being removed |
serialize
Section titled “serialize”Callback for when the Component is serialized as part of an Entity.
component:serialize()Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
table|nil |
Serialized data, or nil to omit this Component |
deserialize
Section titled “deserialize”Callback for when the Component is deserialized from serialized data.
component:deserialize( data )Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
data |
table |
Serialized data to copy onto this Component |