module Gamefic::Scripting::Entities
Methods related to managing entities.
Public Instance Methods
Source
# File lib/gamefic/scripting/entities.rb, line 36 def destroy(entity) entity.children.each { |child| destroy child } entity.parent = nil entity_set.delete entity entity end
Source
# File lib/gamefic/scripting/entities.rb, line 14 def entities entity_set.to_a end
@return [Array<Gamefic::Entity>]
Source
# File lib/gamefic/scripting/entities.rb, line 43 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
Source
# File lib/gamefic/scripting/entities.rb, line 32 def make klass, **opts klass.new(**unproxy(opts)).tap { |entity| entity_set.add entity } end
Create an entity.
@example
class MyPlot < Gamefic::Plot seed { make Gamefic::Entity, name: 'thing' } end
@param klass [Class<Gamefic::Entity>] @return [Gamefic::Entity]
Source
# File lib/gamefic/scripting/entities.rb, line 61 def pick *args matches = find(*args) return nil unless matches.one? matches.first end
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.
@return [Gamefic::Entity, nil]
Source
# File lib/gamefic/scripting/entities.rb, line 75 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
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]
Source
# File lib/gamefic/scripting/entities.rb, line 19 def players player_set.to_a end
@return [Array<Gamefic::Actor, Gamefic::Active
>]
Private Instance Methods
Source
# File lib/gamefic/scripting/entities.rb, line 85 def entity_set @entity_set ||= Set.new end
Source
# File lib/gamefic/scripting/entities.rb, line 89 def player_set @player_set ||= Set.new end