module Gamefic::Scriptable::Entities
Scriptable
methods related to managing entities.
@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.
Public Instance Methods
destroy(entity)
click to toggle source
# 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()
click to toggle source
@return [Array<Gamefic::Entity>]
# File lib/gamefic/scriptable/entities.rb, line 23 def entities entity_vault.array end
entity_vault()
click to toggle source
# File lib/gamefic/scriptable/entities.rb, line 14 def entity_vault @entity_vault ||= Vault.new end
find(*args)
click to toggle source
# File lib/gamefic/scriptable/entities.rb, line 52 def find *args args.inject(entities) do |entities, arg| case arg when String result = Scanner.scan(entities, arg) result.remainder.empty? ? result.match : [] else entities.that_are(arg) end end end
make(klass, **opts)
click to toggle source
Create an entity.
@example
class MyPlot < Gamefic::Plot seed { make Gamefic::Entity, name: 'thing' } end
@param [Class<Gamefic::Entity>] @param args [Hash] @return [Gamefic::Entity]
# File lib/gamefic/scriptable/entities.rb, line 42 def make klass, **opts entity_vault.add klass.new(**unproxy(opts)) end
pick(*args)
click to toggle source
Pick a unique entity based on the given arguments. String
arguments are used to scan the entities for matching names and synonyms. Return nil if an entity could not be found or there is more than one possible match.
@param description [Array] @return [Gamefic::Entity, nil]
# File lib/gamefic/scriptable/entities.rb, line 71 def pick *args matches = find(*args) return nil unless matches.one? matches.first end
pick!(*args)
click to toggle source
Same as pick
, but raise an error if a unique match could not be found.
@raise [RuntimeError] if a unique match was not found.
@param args [Array] @return [Gamefic::Entity]
# File lib/gamefic/scriptable/entities.rb, line 85 def pick! *args matches = find(*args) raise "no entity matching '#{args.inspect}'" if matches.empty? raise "multiple entities matching '#{args.inspect}': #{matches.join_and}" unless matches.one? matches.first end
player_vault()
click to toggle source
# File lib/gamefic/scriptable/entities.rb, line 18 def player_vault @player_vault ||= Vault.new end
players()
click to toggle source
@return [Array<Gamefic::Actor, Gamefic::Active
>]
# File lib/gamefic/scriptable/entities.rb, line 28 def players player_vault.array end