Fixed new label dsl methods requiring options to be provided, upgraded Image to accept either a path or an image and to enable replacing image using #value=

This commit is contained in:
2021-01-05 20:39:13 -06:00
parent 886680ab31
commit 732dc2c957
3 changed files with 20 additions and 4 deletions

View File

@@ -25,7 +25,7 @@ module CyberarmEngine
"Para", "Para",
"Inscription" "Inscription"
].each do |const| ].each do |const|
define_method(:"#{const.downcase}") do |text, options, &block| define_method(:"#{const.downcase}") do |text, options = {}, &block|
options[:parent] = element_parent options[:parent] = element_parent
options[:theme] = current_theme options[:theme] = current_theme

View File

@@ -1,11 +1,13 @@
module CyberarmEngine module CyberarmEngine
class Element class Element
class Image < Element class Image < Element
def initialize(path, options = {}, block = nil) def initialize(path_or_image, options = {}, block = nil)
super(options, block) super(options, block)
@path = path @path = path_or_image if path_or_image.is_a?(String)
@image = Gosu::Image.new(path_or_image, retro: @options[:retro], tileable: @options[:tileable]) if @path
@image = path_or_image unless @path
@image = Gosu::Image.new(path, retro: @options[:image_retro])
@scale_x = 1 @scale_x = 1
@scale_y = 1 @scale_y = 1
end end
@@ -48,6 +50,19 @@ module CyberarmEngine
end end
def value def value
@image
end
def value=(path_or_image, retro: false, tileable: false)
@path = path_or_image if path_or_image.is_a?(String)
@image = Gosu::Image.new(path_or_image, retro: retro, tileable: tileable) if @path
@image = path_or_image unless @path
recalculate
end
def path
@path @path
end end
end end

View File

@@ -103,6 +103,7 @@ module CyberarmEngine
Image: { # < Element Image: { # < Element
color: Gosu::Color::WHITE, color: Gosu::Color::WHITE,
tileable: false,
retro: false retro: false
}, },