Class: Pixiurge::Display::DisplayBuilder

Inherits:
Object
  • Object
show all
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.

Examples:

builder = Pixiurge::Display::DisplayBuilder.new(item, engine_connector: connector)
displayables = builder.built_objects

Since:

  • 0.1.0

Direct Known Subclasses

ContainerBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • item (Demiurge::StateItem)

    The Demiurge item corresponding to the Displayable

  • name (String)

    This Displayable's name, which must either be the same as the name of the Demiurge item or correspond to no other Demiurge item

  • engine_connector (Pixiurge::EngineConnector)

    The EngineConnector containing this Displayable

Since:

  • 0.1.0



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_objectsObject (readonly)

The objects built by this DisplayBuilder object

Since:

  • 0.1.0



13
14
15
# File 'lib/pixiurge/displayable/dsl.rb', line 13

def built_objects
  @built_objects
end

#engine_connectorObject (readonly)

The EngineConnector in which all this exists

Since:

  • 0.1.0



17
18
19
# File 'lib/pixiurge/displayable/dsl.rb', line 17

def engine_connector
  @engine_connector
end

#itemObject (readonly)

The Demiurge item for which a Displayable is being built

Since:

  • 0.1.0



15
16
17
# File 'lib/pixiurge/displayable/dsl.rb', line 15

def item
  @item
end

#nameObject (readonly)

The item name of the Demiurge item (and thus Displayable) being built

Since:

  • 0.1.0



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.

Yields:

  • An additional Displayable DSL block which creates one or more additional Displayables

Since:

  • 0.1.0



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

#invisiblevoid

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.

Since:

  • 0.1.0



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.

Parameters:

  • params (Hash)

    A hash of particle parameters

Since:

  • 0.1.0



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.

Parameters:

  • params (Hash)

    Parameters for the TileAnimatedSprite

Since:

  • 0.1.0



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.

Parameters:

  • filename (String)

    The server-side relative filename for the TMX file

Since:

  • 0.1.0



112
113
114
115
# File 'lib/pixiurge/displayable/dsl.rb', line 112

def tmx_map(filename, options = {})
  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