Module: Gamefic::Scriptable::Entities
Overview
Note:
The public versions of the entity and player arrays are frozen. Authors need access to them but shouldn’t modify them directly. Use #make and #destroy instead.
Scriptable methods related to managing entities.
Instance Method Summary collapse
- #destroy(entity) ⇒ Object
- #entities ⇒ Array<Gamefic::Entity>
- #entity_vault ⇒ Object
-
#make(klass, **opts) ⇒ Gamefic::Entity
Create an entity.
-
#pick(description) ⇒ Gamefic::Entity?
Pick an entity based on a unique name or description.
-
#pick!(description) ⇒ Gamefic::Entity?
Same as #pick, but raise an error if a unique match could not be found.
- #player_vault ⇒ Object
- #players ⇒ Array<Gamefic::Actor, Gamefic::Active>
Methods included from Proxy
Instance Method Details
#destroy(entity) ⇒ Object
46 47 48 49 50 |
# File 'lib/gamefic/scriptable/entities.rb', line 46 def destroy entity entity.children.each { |child| destroy child } entity.parent = nil entity_vault.delete entity end |
#entities ⇒ Array<Gamefic::Entity>
23 24 25 |
# File 'lib/gamefic/scriptable/entities.rb', line 23 def entities entity_vault.array end |
#entity_vault ⇒ Object
14 15 16 |
# File 'lib/gamefic/scriptable/entities.rb', line 14 def entity_vault @entity_vault ||= Vault.new end |
#make(klass, **opts) ⇒ Gamefic::Entity
Create an entity.
42 43 44 |
# File 'lib/gamefic/scriptable/entities.rb', line 42 def make klass, **opts entity_vault.add klass.new(**unproxy(opts)) end |
#pick(description) ⇒ Gamefic::Entity?
Pick an entity based on a unique name or description. Return nil if an entity could not be found or there is more than one possible match.
57 58 59 |
# File 'lib/gamefic/scriptable/entities.rb', line 57 def pick description Gamefic::Query::General.new(entities).query(nil, description).match end |
#pick!(description) ⇒ Gamefic::Entity?
Same as #pick, but raise an error if a unique match could not be found.
65 66 67 68 69 70 71 72 73 |
# File 'lib/gamefic/scriptable/entities.rb', line 65 def pick! description ary = Gamefic::Query::General.new(entities, ambiguous: true).query(nil, description).match raise "no entity matching '#{description}'" if ary.nil? raise "multiple entities matching '#{description}': #{ary.join_and}" unless ary.one? ary.first end |
#player_vault ⇒ Object
18 19 20 |
# File 'lib/gamefic/scriptable/entities.rb', line 18 def player_vault @player_vault ||= Vault.new end |
#players ⇒ Array<Gamefic::Actor, Gamefic::Active>
28 29 30 |
# File 'lib/gamefic/scriptable/entities.rb', line 28 def players player_vault.array end |