diff options
Diffstat (limited to 'lib/felflame/component_manager.rb')
| -rw-r--r-- | lib/felflame/component_manager.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb index c513498..ca5be89 100644 --- a/lib/felflame/component_manager.rb +++ b/lib/felflame/component_manager.rb @@ -184,11 +184,22 @@ module FelFlame end # Entities that have this component - # @return [Array<Integer>] + # @return [Array<Component>] def entities @entities ||= [] end + # A single entity. Use this if you expect the component to only belong to one entity and you want to access it. + # @return [Component] + def entity + if entities.empty? + Warning.warn("This component belongs to NO entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.") + elsif entities.length > 1 + Warning.warn("This component belongs to MANY entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.") + end + entities.first + end + # Update attribute values using a hash or keywords. # @return [Hash<Symbol, Value>] Hash of updated attributes def update_attrs(**opts) |
