Class: Pixiurge::Displayable
- Inherits:
-
Object
- Object
- Pixiurge::Displayable
- Defined in:
- lib/pixiurge/displayable.rb
Overview
A Pixiurge Displayable handles server-side display of in-world simulated items. This doesn't directly mess with Javascript or Pixi.js code, but it sets up data for display primitives like sprites, TMX areas, particles, animations and so on.
The Player knows what objects are being displayed, while the Displayables know how to send messages to display themselves.
More complex visual groupings like tilemap areas and humanoid bodies inherit from this class.
Direct Known Subclasses
Pixiurge::Display::Container, Pixiurge::Display::Invisible, Pixiurge::Display::ParticleSource, Pixiurge::Display::TextEffect, Pixiurge::Display::TileAnimatedSprite, Pixiurge::Display::TmxMap
Instance Attribute Summary collapse
- #block_height ⇒ Object readonly
-
#block_width ⇒ Object
readonly
For a tiled-type area, #block_width and #block_height are the tile height and width of this Displayable in pixels.
-
#displayable_type ⇒ Object
readonly
You can't just be a "Displayable", you need a concrete child class.
- #location_displayable ⇒ Object readonly
- #location_name ⇒ Object readonly
-
#name ⇒ Object
readonly
Name, which should be the same as the Demiurge item name if there is one.
-
#position ⇒ Object
This is the most recently-displayed position of this Displayable.
-
#x ⇒ Object
readonly
Most recently-displayed coordinate and location.
- #y ⇒ Object readonly
Instance Method Summary collapse
-
#destroy_for_player(player) ⇒ void
Hide this Displayable from a player.
-
#initialize(name:, engine_connector:) ⇒ Displayable
constructor
Constructor.
-
#messages_to_show_player(player) ⇒ Array
Return zero or more messages for #show_to_player.
-
#move_for_player(player, old_position, new_position, options = {}) ⇒ void
Animate the motion of this Displayable from an old location to a new location for the stated player.
-
#show_to_player(player) ⇒ void
Show this Displayable to a player by sending a DISPLAY_SHOW_DISPLAYABLE message.
Constructor Details
#initialize(name:, engine_connector:) ⇒ Displayable
Constructor
61 62 63 64 65 66 67 68 |
# File 'lib/pixiurge/displayable.rb', line 61 def initialize name:, engine_connector: @name = name @engine_connector = engine_connector # Most child classes should override this @block_width = 1 @block_height = 1 end |
Instance Attribute Details
#block_height ⇒ Object (readonly)
49 50 51 |
# File 'lib/pixiurge/displayable.rb', line 49 def block_height @block_height end |
#block_width ⇒ Object (readonly)
For a tiled-type area, #block_width and #block_height are the tile height and width of this Displayable in pixels. This isn't the tile size of this object's location - it's the tile size of this object itself for any items that might move inside of it or on top of it.
48 49 50 |
# File 'lib/pixiurge/displayable.rb', line 48 def block_width @block_width end |
#displayable_type ⇒ Object (readonly)
You can't just be a "Displayable", you need a concrete child class. Each child class gets a string to represent it in the network protocol.
28 29 30 |
# File 'lib/pixiurge/displayable.rb', line 28 def displayable_type @displayable_type end |
#location_displayable ⇒ Object (readonly)
41 42 43 |
# File 'lib/pixiurge/displayable.rb', line 41 def location_displayable @location_displayable end |
#location_name ⇒ Object (readonly)
40 41 42 |
# File 'lib/pixiurge/displayable.rb', line 40 def location_name @location_name end |
#name ⇒ Object (readonly)
Name, which should be the same as the Demiurge item name if there is one.
23 24 25 |
# File 'lib/pixiurge/displayable.rb', line 23 def name @name end |
#position ⇒ Object
This is the most recently-displayed position of this Displayable. When it changes, fields like #x and #location_name get updated automatically.
54 55 56 |
# File 'lib/pixiurge/displayable.rb', line 54 def position @position end |
#x ⇒ Object (readonly)
Most recently-displayed coordinate and location. This can vary significantly from the Demiurge item's location during a long series of movement notifications - the Demiurge item may already be at the final location, while the notifications go one at a time through the places in between. In general the EngineConnector will assign these coordinates and tell the Displayable to play a movement animation, but the Displayable can't easily know exactly what happens when.
38 39 40 |
# File 'lib/pixiurge/displayable.rb', line 38 def x @x end |
#y ⇒ Object (readonly)
39 40 41 |
# File 'lib/pixiurge/displayable.rb', line 39 def y @y end |
Instance Method Details
#destroy_for_player(player) ⇒ void
This method returns an undefined value.
Hide this Displayable from a player. The default method assumes this Displayable uses a SpriteStack and has set the spritesheet and spritestack names already. For other display methods, override this method in a subclass.
138 139 140 |
# File 'lib/pixiurge/displayable.rb', line 138 def destroy_for_player(player) player. Pixiurge::Protocol::Outgoing::DISPLAY_DESTROY_DISPLAYABLE, self.name end |
#messages_to_show_player(player) ⇒ Array
Return zero or more messages for #show_to_player. An empty array of messages mean "don't show" or "no messages are required to show." The primary reason for this having an independent existence is for containers and other Displayables that can contain other Displayables - this is a way "hide" this Displayable inside another one.
The specific #messages_to_show_player superclass method is for parent-class information. A child class will either replace this information or supplement it, depending. Calling "super" in a child implementation isn't mandatory but may be useful.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pixiurge/displayable.rb', line 117 def (player) [{ "type" => @displayable_type, "displayable" => { "x" => @x, "y" => @y, "location_block_width" => @location_displayable ? @location_displayable.block_width : nil, "location_block_height" => @location_displayable ? @location_displayable.block_height : nil, "position" => @position, } }] end |
#move_for_player(player, old_position, new_position, options = {}) ⇒ void
This method returns an undefined value.
Animate the motion of this Displayable from an old location to a new location for the stated player. This will be handled by the EngineConnector, usually as part of showing various things to multiple players.
When doing an animation or other transition, it's important to specify the older and newer coordinates. This can't easily use state in the item itself for both old and new positions - the same transition may need to be made for many viewing players, so setting the state as "part of the transition" doesn't work well. Further complicating things, different players aren't guaranteed to be seeing this Displayable object in the same state at the start of the transition, since they could have just arrived and missed an animation, for example.
162 163 164 |
# File 'lib/pixiurge/displayable.rb', line 162 def move_for_player(player, old_position, new_position, = {}) player.( Pixiurge::Protocol::Outgoing::DISPLAY_MOVE_DISPLAYABLE, @name, { "old_position" => old_position, "position" => new_position, "options" => } ) end |
#show_to_player(player) ⇒ void
This method returns an undefined value.
Show this Displayable to a player by sending a DISPLAY_SHOW_DISPLAYABLE message. Be very careful overriding this method - a Displayable that uses something other than a single DISPLAY_SHOW_DISPLAYABLE may not work properly if put inside a Container or other Displayable that contains other Displayables.
95 96 97 98 99 |
# File 'lib/pixiurge/displayable.rb', line 95 def show_to_player(player) msgs = (player) return if msgs.nil? || msgs.empty? player.(Pixiurge::Protocol::Outgoing::DISPLAY_SHOW_DISPLAYABLE, @name, *msgs) end |