abstract class Entitas::Component

Overview

Inherit this class if you want to create a component which you can add to an entity. Optionally, you can add these attributes: @[Component::Unique]: the code generator will generate additional methods for the context to ensure that only one entity with this component exists. E.g. context.is_animating = true or context.SetResources(); @[Context(MyContextName), Context(MyOtherContextName)]: You can make this component to be available only in the specified contexts.

@[Component::Unique, Context(Game), Context(User)]
class Foo < Entitas::Component
  prop :size, Int32
  prop :default, String, default: "foo"
end

Conmponets can also be declared using existing classes without inheritance. The special macro property_alias will need to be used to alias any pre-existing methods as component values

@[Context(Test3)]
class Vector3 < Array(Int32)
  property_alias :size, Int32, default: 0
  define_property :age, Int32, default: 0
end

Included Modules

Defined in:

entitas.cr
entitas/component.cr
entitas/generators/component.cr
entitas/macros/component.cr

Constant Summary

COMPONENT_KLASSES = [] of Entitas::Component::ComponentTypes
COMPONENT_NAMES = COMPONENT_TO_INDEX_MAP.keys.map(&.to_s)
COMPONENT_TO_INDEX_MAP = {} of Entitas::Component::ComponentTypes => Index

A hash to map of class of Component to enum Index

INDEX_TO_COMPONENT_MAP = {} of Index => Entitas::Component::ComponentTypes

A hash to map of enum Index to class of Component

TOTAL_COMPONENTS = 0

The total number of componets

Class Method Summary

Instance Method Summary

Macro Summary

Instance methods inherited from module Entitas::IComponent

init(**args) init, is_unique? : Bool is_unique?, reset reset

Class Method Detail

def self.total_components : Int32 #

Instance Method Detail

def total_components : Int32 #

The total amount of components an entity can possibly have.


Macro Detail

macro create_index #

[View source]