module Gamefic::Scripting::Entities

def destroy(entity)

def destroy(entity)
  entity.children.each { |child| destroy child }
  entity.parent = nil
  entity_set.delete entity
  entity
end

def entities

Returns:
  • (Array) -
def entities
  entity_set.to_a
end

def entity_set

def entity_set
  @entity_set ||= Set.new
end

def find *args

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

def make klass, **opts

Returns:
  • (Gamefic::Entity) -

Parameters:
  • klass (Class) --
def make klass, **opts
  klass.new(**unproxy(opts)).tap { |entity| entity_set.add entity }
end

def pick *args

Returns:
  • (Gamefic::Entity, nil) -
def pick *args
  matches = find(*args)
  return nil unless matches.one?
  matches.first
end

def pick! *args

Returns:
  • (Gamefic::Entity) -

Parameters:
  • args (Array) --

Raises:
  • (RuntimeError) - if a unique match was not found.
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

def player_set

def player_set
  @player_set ||= Set.new
end

def players

Returns:
  • (Array) -
def players
  player_set.to_a
end