Class: Pixiurge::Display::DisplayBuilder
- Inherits:
-
Object
- Object
- Pixiurge::Display::DisplayBuilder
- Defined in:
- lib/pixiurge/displayable/dsl.rb
Overview
The DisplayBuilder class handles the Display DSL in Demiurge Display blocks for Pixiurge. It will pull the "display" block from a Demiurge item to create a Pixiurge Displayable for it.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#built_objects ⇒ Object
readonly
The objects built by this DisplayBuilder object.
-
#engine_connector ⇒ Object
readonly
The EngineConnector in which all this exists.
-
#item ⇒ Object
readonly
The Demiurge item for which a Displayable is being built.
-
#name ⇒ Object
readonly
The item name of the Demiurge item (and thus Displayable) being built.
Instance Method Summary collapse
-
#container { ... } ⇒ void
Create a Displayable container holding one or more other Displayables.
-
#initialize(item, name: item.name, engine_connector:, &disp) ⇒ DisplayBuilder
constructor
Constructor.
-
#invisible ⇒ void
Create an invisible Displayable - not only does it not show up on the screen, but it sends no messages to the players.
-
#particle_source(params) ⇒ void
Create a Displayable particle source according to the passed particle parameters.
-
#tile_animated_sprite(params) ⇒ void
Create a TileAnimatedSprite as the given Displayable.
-
#tmx_map(filename, options = {}) ⇒ void
Create a TMX tilemap as the given Displayable.
Constructor Details
#initialize(item, name: item.name, engine_connector:, &disp) ⇒ DisplayBuilder
Constructor. This takes a Demiurge item, which supplies the Displayable's name unless a different name is supplied by keyword.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pixiurge/displayable/dsl.rb', line 29 def initialize(item, name: item.name, engine_connector:, &disp) # Several things, such as @item, @name and @engine_connector are intentionally available from the DSL @item = item @name = item.name @engine_connector = engine_connector # Built_objects is a readable attribute to get the final result out @built_objects = [] self.instance_eval(&disp) if disp # Create the built objects from the block end |
Instance Attribute Details
#built_objects ⇒ Object (readonly)
The objects built by this DisplayBuilder object
13 14 15 |
# File 'lib/pixiurge/displayable/dsl.rb', line 13 def built_objects @built_objects end |
#engine_connector ⇒ Object (readonly)
The EngineConnector in which all this exists
17 18 19 |
# File 'lib/pixiurge/displayable/dsl.rb', line 17 def engine_connector @engine_connector end |
#item ⇒ Object (readonly)
The Demiurge item for which a Displayable is being built
15 16 17 |
# File 'lib/pixiurge/displayable/dsl.rb', line 15 def item @item end |
#name ⇒ Object (readonly)
The item name of the Demiurge item (and thus Displayable) being built
19 20 21 |
# File 'lib/pixiurge/displayable/dsl.rb', line 19 def name @name end |
Instance Method Details
#container { ... } ⇒ void
This method returns an undefined value.
Create a Displayable container holding one or more other Displayables.
61 62 63 64 65 66 67 |
# File 'lib/pixiurge/displayable/dsl.rb', line 61 def container(&block) builder = ::Pixiurge::Display::ContainerBuilder.new(item, name: @name, engine_connector: @engine_connector) raise("Display container must supply a block!") unless block_given? builder.instance_eval(&block) raise("Display container must contain at least one item!") if builder.built_objects.empty? add_built_object ::Pixiurge::Display::Container.new(builder.built_objects, name: @name, engine_connector: @engine_connector) end |
#invisible ⇒ void
This method returns an undefined value.
Create an invisible Displayable - not only does it not show up on the screen, but it sends no messages to the players. If you want no Displayable for something, this is the closest equivalent.
86 87 88 |
# File 'lib/pixiurge/displayable/dsl.rb', line 86 def invisible add_built_object ::Pixiurge::Display::Invisible.new(name: @name, engine_connector: @engine_connector) end |
#particle_source(params) ⇒ void
This method returns an undefined value.
Create a Displayable particle source according to the passed particle parameters.
75 76 77 |
# File 'lib/pixiurge/displayable/dsl.rb', line 75 def particle_source(params) add_built_object ::Pixiurge::Display::ParticleSource.new(params, name: @name, engine_connector: @engine_connector) end |
#tile_animated_sprite(params) ⇒ void
This method returns an undefined value.
Create a TileAnimatedSprite as the given Displayable. These sprites show animations from tilesheets, and can transition continuously between multiple animations for things like standing-and-idle animations.
For details of the parameters, see TileAnimatedSprite.
101 102 103 |
# File 'lib/pixiurge/displayable/dsl.rb', line 101 def tile_animated_sprite(params) add_built_object ::Pixiurge::Display::TileAnimatedSprite.new(params, name: @name, engine_connector: @engine_connector) end |
#tmx_map(filename, options = {}) ⇒ void
This method returns an undefined value.
Create a TMX tilemap as the given Displayable. The given TMX filename will be quietly converted to JSON behind the scenes and sent with a separate AJAX loader request.
112 113 114 115 |
# File 'lib/pixiurge/displayable/dsl.rb', line 112 def tmx_map(filename, = {}) cache_entry = Demiurge::Tmx::TmxLocation.default_cache.cache_entry("manasource", filename) add_built_object ::Pixiurge::Display::TmxMap.new(cache_entry, name: @name, engine_connector: @engine_connector) end |