Class: Bestguigui::Tiled::Object
- Inherits:
-
Object
- Object
- Bestguigui::Tiled::Object
- Defined in:
- lib/bestguigui/tiled.rb
Overview
Un objet Tiled : position/dimensions en pixels + propriétés custom
(accessibles via [], comme déclarées dans l'éditeur).
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(data) ⇒ Object
constructor
A new instance of Object.
-
#tile_x ⇒ Object
Position convertie en coordonnées de tuile — pratique pour les marqueurs ponctuels (spawn, sortie...) placés comme un objet de la taille d'une tuile dans Tiled.
- #tile_y ⇒ Object
Constructor Details
#initialize(data) ⇒ Object
Returns a new instance of Object.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/bestguigui/tiled.rb', line 131 def initialize(data) @name = data["name"] @x = data["x"] @y = data["y"] @width = data["width"] @height = data["height"] @properties = (data["properties"] || []).each_with_object({}) do |property, hash| hash[property["name"].to_sym] = property["value"] end # Beaucoup de niveaux Tiled catégorisent leurs objets via une # propriété custom nommée "type" plutôt que le champ natif # type/class de l'objet (qui reste vide si tu n'utilises pas les # "Object Types" de l'éditeur) — priorité à la propriété custom. native_type = data["type"] || data["class"] # Tiled < 1.9 vs >= 1.9 @type = @properties[:type] || (native_type.nil? || native_type.empty? ? nil : native_type) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
129 130 131 |
# File 'lib/bestguigui/tiled.rb', line 129 def height @height end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
129 130 131 |
# File 'lib/bestguigui/tiled.rb', line 129 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
129 130 131 |
# File 'lib/bestguigui/tiled.rb', line 129 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
129 130 131 |
# File 'lib/bestguigui/tiled.rb', line 129 def type @type end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
129 130 131 |
# File 'lib/bestguigui/tiled.rb', line 129 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
129 130 131 |
# File 'lib/bestguigui/tiled.rb', line 129 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
129 130 131 |
# File 'lib/bestguigui/tiled.rb', line 129 def y @y end |
Instance Method Details
#[](key) ⇒ Object
160 161 162 |
# File 'lib/bestguigui/tiled.rb', line 160 def [](key) @properties[key] end |
#tile_x ⇒ Object
Position convertie en coordonnées de tuile — pratique pour les marqueurs ponctuels (spawn, sortie...) placés comme un objet de la taille d'une tuile dans Tiled.
152 153 154 |
# File 'lib/bestguigui/tiled.rb', line 152 def tile_x (x / width).floor end |
#tile_y ⇒ Object
156 157 158 |
# File 'lib/bestguigui/tiled.rb', line 156 def tile_y (y / height).floor end |