Class: Pixiurge::Display::Container

Inherits:
Pixiurge::Displayable show all
Defined in:
lib/pixiurge/displayable/container.rb

Overview

Sometimes it's useful to just have a container with one or more other Displayables inside. This allows both multiple Displayables without a custom type (e.g. a humanoid with a particle source attached) or to have multiple pieces with multiple transforms or animations (e.g. a shadow as a separate sprite that doesn't move up and down when the body jumps.)

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from Pixiurge::Displayable

#block_height, #block_width, #displayable_type, #location_displayable, #location_name, #name, #position, #x, #y

Instance Method Summary collapse

Methods inherited from Pixiurge::Displayable

#destroy_for_player, #move_for_player, #show_to_player

Constructor Details

#initialize(displayables, name:, engine_connector:) ⇒ Container

Constructor - create the container

Parameters:

  • displayables (Array<Pixiurge::Displayable>)

    An array of Displayable items as contents

  • name (String)

    The Demiurge item name for this Displayable

  • engine_connector (Pixiurge::EngineConnector)

    The Pixiurge EngineConnector this Displayable belongs to

Since:

  • 0.1.0



18
19
20
21
22
# File 'lib/pixiurge/displayable/container.rb', line 18

def initialize displayables, name:, engine_connector:
  @contents = displayables
  @displayable_type = "container"
  super(name: name, engine_connector: engine_connector)
end

Instance Attribute Details

#contentsObject (readonly)

Since:

  • 0.1.0



10
11
12
# File 'lib/pixiurge/displayable/container.rb', line 10

def contents
  @contents
end

Instance Method Details

#messages_to_show_player(player) ⇒ Array

Messages to show this Displayable to a player.

Parameters:

Returns:

  • (Array)

    Messages to show this container to the player

Since:

  • 0.1.0



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pixiurge/displayable/container.rb', line 29

def messages_to_show_player(player)
  show_contents_msgs = @contents.map do |d|
    msgs = d.messages_to_show_player(player)
    msgs[0].merge!(name: d.name)
    msgs
  end

  messages = super
  messages[0].merge!({ "contents" => show_contents_msgs })
  messages
end