class Demiurge::DSL::ZoneBuilder
Declare a “zone” block in the World File DSL
.
Monkeypatch to allow tmx_location
in World File zones.
Public Class Methods
new(name, engine, options = {})
click to toggle source
Constructor. See if this zone name already exists, and either create a new zone or append to the old one.
Calls superclass method
Demiurge::DSL::ActionItemBuilder::new
# 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
Public Instance Methods
agent(name, options = {}, &block)
click to toggle source
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.
# 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)
click to toggle source
Declare a location in this zone.
# 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)
click to toggle source
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.)
# 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