Module: Demiurge::DSL

Defined in:
lib/demiurge/dsl.rb,
lib/demiurge/tmx.rb

Overview

This module contains the Builder classes that parse the World File DSL.

Since:

  • 0.0.1

Defined Under Namespace

Classes: ActionItemBuilder, AgentBuilder, LocationBuilder, TmxLocationBuilder, TopLevelBuilder, ZoneBuilder

Class Method Summary collapse

Class Method Details

.engine_from_dsl_files(*filenames) ⇒ Demiurge::Engine

This is a primary method for creating a new Demiurge Engine. It should be passed a list of filenames to load World File DSL from. It will return a fully-configured Engine which has called finished_init. If the Engine should load from an existing state-dump, that can be accomplished via load_state_from_dump.

Parameters:

  • filenames (Array<String>)

    An array of filenames, suitable for calling File.read on

Returns:

See Also:

Since:

  • 0.0.1



171
172
173
174
# File 'lib/demiurge/dsl.rb', line 171

def self.engine_from_dsl_files(*filenames)
  filename_string_pairs = filenames.flatten.map { |fn| [fn, File.read(fn)] }
  engine_from_dsl_text(*filename_string_pairs)
end

.engine_from_dsl_text(*specs) ⇒ Demiurge::Engine

This method takes either strings containing World File DSL text, or name/string pairs. If a pair is supplied, the name gives the origin of the text for error messages.

Parameters:

  • specs (Array<String>, Array<Array<String>>)

    Either an array of chunks of DSL text, or an Array of two-element Arrays. Each two-element Array is a String name followed by a String of DSL text

Returns:

See Also:

Since:

  • 0.0.1



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/demiurge/dsl.rb', line 186

def self.engine_from_dsl_text(*specs)
  builder = Demiurge::DSL::TopLevelBuilder.new

  specs.each do |spec|
    if spec.is_a?(String)
      builder.instance_eval spec
    elsif spec.is_a?(Array)
      if spec.size != 2
        raise "Not sure what to do with a #{spec.size}-elt array, normally this is a filename/string pair!"
      end
      builder.instance_eval spec[1], spec[0]
    else
      raise "Not sure what to do in engine_from_dsl_text with a #{spec.class}!"
    end
  end

  builder.built_engine
end