From d03ce21592062aed27a571fda60483fcb3fba764 Mon Sep 17 00:00:00 2001 From: realtradam Date: Thu, 30 Dec 2021 07:28:14 -0500 Subject: . --- docs/FelFlame/Entities.html | 229 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 188 insertions(+), 41 deletions(-) (limited to 'docs/FelFlame/Entities.html') diff --git a/docs/FelFlame/Entities.html b/docs/FelFlame/Entities.html index 2dd13c9..aca4cac 100644 --- a/docs/FelFlame/Entities.html +++ b/docs/FelFlame/Entities.html @@ -148,6 +148,30 @@

Add any number components to the Entity.

+ + + +
  • + + + #component(manager = nil) ⇒ Component + + + + + + + + + + + + + +
    +

    A single component from a component manager.

    +
    +
  • @@ -306,7 +330,14 @@ 9 10 11 -12 +12 +13 +14 +15 +16 +17 +18 +19
    # File 'lib/felflame/entity_manager.rb', line 7
    @@ -315,6 +346,13 @@
       # Add each component
       add(*components)
     
    +  # Fancy method redirection for when the `component` method is called
    +  @component_redirect = Object.new
    +  @component_redirect.instance_variable_set(:@entity, self)
    +  @component_redirect.define_singleton_method(:[]) do |component_manager|
    +    instance_variable_get(:@entity).component(component_manager)
    +  end
    +
       self.class._data.push self
     end
    @@ -393,23 +431,23 @@
     
     
    -36
    -37
    -38
    -39
    -40
    -41
    -42
    -43
    -44
    -45
    -46
    -47
    -48
    -49
    +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 -
    # File 'lib/felflame/entity_manager.rb', line 36
    +      
    # File 'lib/felflame/entity_manager.rb', line 63
     
     def add(*components_to_add)
       components_to_add.each do |component|
    @@ -428,6 +466,109 @@
         
       
     
    +
    +    
    +      
    +

    + + #component(manager = nil) ⇒ Component + + + + + +

    +
    + +

    A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation.

    + + +
    +
    +
    + +
    +

    Examples:

    + + +
    @entity.component[@component_manager] # array notation
    +@entity.component(@component_manager) # method notation
    + +
    +

    Parameters:

    +
      + +
    • + + manager + + + (ComponentManager) + + + (defaults to: nil) + + + — +
      +

      If you pass nil you can then use array notation to access the same value.

      +
      + +
    • + +
    + +

    Returns:

    +
      + +
    • + + + (Component) + + + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +33
    +34
    +35
    +36
    +37
    +38
    +39
    +40
    +41
    +42
    +43
    +44
    +
    +
    # File 'lib/felflame/entity_manager.rb', line 33
    +
    +def component(manager = nil)
    +  if manager.nil?
    +    @component_redirect
    +  else
    +    if components[manager].nil?
    +      raise "This entity(#{self}) doesnt have any components of this type: #{manager}"
    +    elsif components[manager].length > 1
    +      Warning.warn("This entity has MANY of this component but you called the method that is intended for having a single of this component type.\nYou may have a bug in your logic.")
    +    end
    +    components[manager].first
    +  end
    +end
    +
    @@ -469,12 +610,12 @@
     
     
    -16
    -17
    -18
    +23 +24 +25
    -
    # File 'lib/felflame/entity_manager.rb', line 16
    +      
    # File 'lib/felflame/entity_manager.rb', line 23
     
     def components
       @components ||= {}
    @@ -528,19 +669,19 @@
           
     
     
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    +49 +50 +51 +52 +53 +54 +55 +56 +57 +58
    -
    # File 'lib/felflame/entity_manager.rb', line 22
    +      
    # File 'lib/felflame/entity_manager.rb', line 49
     
     def delete
       components.each do |component_manager, component_array|
    @@ -621,23 +762,29 @@
           
     
     
    -66
    -67
    -68
    -69
    -70
    -71
    -72
    -73
    +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103
    -
    # File 'lib/felflame/entity_manager.rb', line 66
    +      
    # File 'lib/felflame/entity_manager.rb', line 93
     
     def remove(*components_to_remove)
       components_to_remove.each do |component|
         check_systems component, :removal_triggers if component.entities.include? self
         component.entities.delete self
         components[component.class].delete component
    +    if components[component.class].empty?
    +      components.delete component.class
    +    end
       end
       true
     end
    @@ -651,7 +798,7 @@ -- cgit v1.2.3