module Gamefic::Scriptable::Seeds
Public Instance Methods
Source
# File lib/gamefic/scriptable/seeds.rb, line 35 def construct name, klass, **opts ivname = "@#{name}" define_method(name) do return instance_variable_get(ivname) if instance_variable_defined?(ivname) instance_variable_set(ivname, make(klass, **unproxy(opts))) end seed { send(name) } define_singleton_method(name) { Proxy::Attr.new(name) } end
Construct an entity.
This method adds an instance method for the entity and a class method to reference it with a proxy.
@param name [Symbol, String] The method name for the entity @param klass [Class<Gamefic::Entity>] @return [void]
Source
# File lib/gamefic/scriptable/seeds.rb, line 52 def make klass, **opts seed { make(klass, **unproxy(opts)) } end
Add an entity to be seeded when the narrative gets instantiated.
@param klass [Class<Gamefic::Entity>] @return [void]
Source
# File lib/gamefic/scriptable/seeds.rb, line 22 def seed *methods, &block seeds.push(proc { methods.flatten.each { |method| send(method) } }) unless methods.empty? seeds.push block if block end
Set methods and procs that get executed when a narrative gets initialized.
@example
class Example < Gamefic::Plot attr_reader :thing seed do @thing = make Entity, name: 'thing' end end
Source
# File lib/gamefic/scriptable/seeds.rb, line 7 def seeds @seeds ||= [] end
@return [Array<Proc>]