Class: Demiurge::DSL::ZoneBuilder

Inherits:
ActionItemBuilder show all
Defined in:
lib/demiurge/dsl.rb,
lib/demiurge/tmx.rb

Overview

Monkeypatch to allow tmx_location in World File zones.

Since:

  • 0.0.1

Constant Summary

Constants inherited from ActionItemBuilder

ActionItemBuilder::LEGAL_OPTIONS

Instance Attribute Summary

Attributes inherited from ActionItemBuilder

#built_item

Instance Method Summary collapse

Methods inherited from ActionItemBuilder

#__state_internal, #define_action, #display, #every_X_ticks, #on_intention, #on_notification, #position, #state

Constructor Details

#initialize(name, engine, options = {}) ⇒ ZoneBuilder

Constructor. See if this zone name already exists, and either create a new zone or append to the old one.

Since:

  • 0.0.1



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/demiurge/dsl.rb', line 512

def initialize(name, engine, options = {})
  @existing = options.delete("existing")
  if @existing
    old_type = @existing.state_type
    new_type = options["type"]
    if new_type && old_type != new_type
      raise("Can't reopen zone with type #{(options["type"] || "Unspecified").inspect} after creating with type #{old_type.inspect}!")
    end
    options["no_build"] = true
    @built_item = @existing
  end
  super(name, engine, options.merge("type" => options["type"] || "Zone"))
  @locations = []
  @agents = []
end

Instance Method Details

#agent(name, options = {}, &block) ⇒ Object

Declare an agent in this zone. If the agent doesn't get a location declaration, by default the agent will usually be invisible (not an interactable location) but will be instantiable as a parent.

Since:

  • 0.0.1



541
542
543
544
545
546
547
# File 'lib/demiurge/dsl.rb', line 541

def agent(name, options = {}, &block)
  state = { "zone" => @name, "home_zone" => @name }.merge(options)
  builder = AgentBuilder.new(name, @engine, "type" => options["type"] || "Agent", "state" => state)
  builder.instance_eval(&block)
  @built_item.state["contents"] << name
  nil
end

#location(name, options = {}, &block) ⇒ Object

Declare a location in this zone.

Since:

  • 0.0.1



529
530
531
532
533
534
535
# File 'lib/demiurge/dsl.rb', line 529

def location(name, options = {}, &block)
  state = { "zone" => @name, "home_zone" => @name }.merge(options)
  builder = LocationBuilder.new(name, @engine, "type" => options["type"] || "Location", "state" => state)
  builder.instance_eval(&block)
  @built_item.state["contents"] << name
  nil
end

#tmx_location(name, options = {}, &block) ⇒ Object

This is currently an ugly monkeypatch to allow declaring a "tmx_location" separate from other kinds of declarable StateItems. This remains ugly until the plugin system catches up with the intrusiveness of what TMX needs to plug in (which isn't bad, but the plugin system barely exists.)

Since:

  • 0.0.1



58
59
60
61
62
63
64
# File 'lib/demiurge/tmx.rb', line 58

def tmx_location(name, options = {}, &block)
  state = { "zone" => @name }.merge(options)
  builder = TmxLocationBuilder.new(name, @engine, "type" => options["type"] || "TmxLocation", "state" => state)
  builder.instance_eval(&block)
  @built_item.state["contents"] << name
  nil
end