Class: Demiurge::DSL::ZoneBuilder
- Inherits:
-
ActionItemBuilder
- Object
- ActionItemBuilder
- Demiurge::DSL::ZoneBuilder
- Defined in:
- lib/demiurge/dsl.rb,
lib/demiurge/tmx.rb
Overview
Monkeypatch to allow tmx_location in World File zones.
Constant Summary
Constants inherited from ActionItemBuilder
ActionItemBuilder::LEGAL_OPTIONS
Instance Attribute Summary
Attributes inherited from ActionItemBuilder
Instance Method Summary collapse
-
#agent(name, options = {}, &block) ⇒ Object
Declare an agent in this zone.
-
#initialize(name, engine, options = {}) ⇒ ZoneBuilder
constructor
Constructor.
-
#location(name, options = {}, &block) ⇒ Object
Declare a location in this zone.
-
#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.
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.
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, = {}) @existing = .delete("existing") if @existing old_type = @existing.state_type new_type = ["type"] if new_type && old_type != new_type raise("Can't reopen zone with type #{(["type"] || "Unspecified").inspect} after creating with type #{old_type.inspect}!") end ["no_build"] = true @built_item = @existing end super(name, engine, .merge("type" => ["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.
541 542 543 544 545 546 547 |
# File 'lib/demiurge/dsl.rb', line 541 def agent(name, = {}, &block) state = { "zone" => @name, "home_zone" => @name }.merge() builder = AgentBuilder.new(name, @engine, "type" => ["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.
529 530 531 532 533 534 535 |
# File 'lib/demiurge/dsl.rb', line 529 def location(name, = {}, &block) state = { "zone" => @name, "home_zone" => @name }.merge() builder = LocationBuilder.new(name, @engine, "type" => ["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.)
58 59 60 61 62 63 64 |
# File 'lib/demiurge/tmx.rb', line 58 def tmx_location(name, = {}, &block) state = { "zone" => @name }.merge() builder = TmxLocationBuilder.new(name, @engine, "type" => ["type"] || "TmxLocation", "state" => state) builder.instance_eval(&block) @built_item.state["contents"] << name nil end |