summaryrefslogtreecommitdiffhomepage
path: root/lib/felflame/component_manager.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-12-30 07:28:14 -0500
committerrealtradam <[email protected]>2021-12-30 07:28:14 -0500
commitd03ce21592062aed27a571fda60483fcb3fba764 (patch)
treeb82c99051b378c18ad4a8af98292681869dfa5a7 /lib/felflame/component_manager.rb
parent38e1a046dcc0ecf5e3ec672ca466f02038b86a02 (diff)
downloadFelECS-arry.tar.gz
FelECS-arry.zip
Diffstat (limited to 'lib/felflame/component_manager.rb')
-rw-r--r--lib/felflame/component_manager.rb13
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)