mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-17 21:42:34 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b6730204e8 | |||
| d8dc621c62 | |||
| 739ae86966 | |||
| 3be16c644f | |||
| 805077d232 | |||
| db1a0683e2 | |||
| f489ad162f | |||
| df2dc25e34 |
@@ -48,6 +48,12 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def opacity(color, ratio = 1.0)
|
||||||
|
alpha = 255 * ratio
|
||||||
|
|
||||||
|
return Gosu::Color.rgba(color.red, color.green, color.blue, alpha)
|
||||||
|
end
|
||||||
|
|
||||||
def get_asset(path, hash, klass)
|
def get_asset(path, hash, klass)
|
||||||
asset = nil
|
asset = nil
|
||||||
hash.detect do |_asset, instance|
|
hash.detect do |_asset, instance|
|
||||||
|
|||||||
@@ -2,9 +2,23 @@ module CyberarmEngine
|
|||||||
class BoundingBox
|
class BoundingBox
|
||||||
attr_accessor :min, :max
|
attr_accessor :min, :max
|
||||||
|
|
||||||
def initialize(minx = 0, miny = 0, minz = 0, maxx = 0, maxy = 0, maxz = 0)
|
def initialize(*args)
|
||||||
@min = Vector.new(minx, miny, minz)
|
case args.size
|
||||||
@max = Vector.new(maxx, maxy, maxz)
|
when 0
|
||||||
|
@min = Vector.new(0, 0, 0)
|
||||||
|
@max = Vector.new(0, 0, 0)
|
||||||
|
when 2
|
||||||
|
@min = args.first.clone
|
||||||
|
@max = args.last.clone
|
||||||
|
when 4
|
||||||
|
@min = Vector.new(args[0], args[1], 0)
|
||||||
|
@max = Vector.new(args[2], args[3], 0)
|
||||||
|
when 6
|
||||||
|
@min = Vector.new(args[0], args[1], args[2])
|
||||||
|
@max = Vector.new(args[3], args[4], args[5])
|
||||||
|
else
|
||||||
|
raise "Invalid number of arguments! Got: #{args.size}, expected: 0, 2, 4, or 6."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Performs math operation, excluding @weight
|
# Performs math operation, excluding @weight
|
||||||
def operator(function, other)
|
private def operator(function, other)
|
||||||
if other.is_a?(Numeric)
|
if other.is_a?(Numeric)
|
||||||
Vector.new(
|
Vector.new(
|
||||||
@x.send(:"#{function}", other),
|
@x.send(:"#{function}", other),
|
||||||
@@ -160,5 +160,9 @@ module CyberarmEngine
|
|||||||
def to_s
|
def to_s
|
||||||
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_h
|
||||||
|
{x: @x, y: @y, z: @z, weight: @weight}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -6,7 +6,7 @@ module CyberarmEngine
|
|||||||
attr_reader :text, :textobject
|
attr_reader :text, :textobject
|
||||||
|
|
||||||
def initialize(text, options={})
|
def initialize(text, options={})
|
||||||
@text = text || ""
|
@text = text.to_s || ""
|
||||||
@options = options
|
@options = options
|
||||||
@size = options[:size] || 18
|
@size = options[:size] || 18
|
||||||
@font = options[:font] || "sans-serif"#Gosu.default_font_name
|
@font = options[:font] || "sans-serif"#Gosu.default_font_name
|
||||||
@@ -72,7 +72,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def height
|
def height
|
||||||
(@text.lines.count) * textobject.height
|
@text.lines.count > 0 ? (@text.lines.count) * textobject.height : @textobject.height
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ module CyberarmEngine
|
|||||||
module DSL
|
module DSL
|
||||||
def flow(options = {}, &block)
|
def flow(options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_container = Flow.new(options, block)
|
_container = Flow.new(options, block)
|
||||||
@containers << _container
|
@containers << _container
|
||||||
_container.build
|
_container.build
|
||||||
@@ -13,6 +14,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def stack(options = {}, &block)
|
def stack(options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_container = Stack.new(options, block)
|
_container = Stack.new(options, block)
|
||||||
@containers << _container
|
@containers << _container
|
||||||
_container.build
|
_container.build
|
||||||
@@ -24,6 +26,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def label(text, options = {}, &block)
|
def label(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = Label.new(text, options, block)
|
_element = Label.new(text, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -32,6 +35,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def button(text, options = {}, &block)
|
def button(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = Button.new(text, options, block) { if block.is_a?(Proc); block.call; end }
|
_element = Button.new(text, options, block) { if block.is_a?(Proc); block.call; end }
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -40,6 +44,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def edit_line(text, options = {}, &block)
|
def edit_line(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = EditLine.new(text, options, block)
|
_element = EditLine.new(text, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -48,6 +53,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def toggle_button(options = {}, &block)
|
def toggle_button(options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = ToggleButton.new(options, block)
|
_element = ToggleButton.new(options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -56,6 +62,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def check_box(text, options = {}, &block)
|
def check_box(text, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = CheckBox.new(text, options, block)
|
_element = CheckBox.new(text, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -64,6 +71,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def image(path, options = {}, &block)
|
def image(path, options = {}, &block)
|
||||||
options[:parent] = @containers.last
|
options[:parent] = @containers.last
|
||||||
|
options[:theme] = @current_theme
|
||||||
_element = Image.new(path, options, block)
|
_element = Image.new(path, options, block)
|
||||||
@containers.last.add(_element)
|
@containers.last.add(_element)
|
||||||
|
|
||||||
@@ -78,5 +86,9 @@ module CyberarmEngine
|
|||||||
def color(color)
|
def color(color)
|
||||||
@containers.last.color(color)
|
@containers.last.color(color)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_theme(theme)
|
||||||
|
@current_theme = theme
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -15,7 +15,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def initialize(options = {}, block = nil)
|
def initialize(options = {}, block = nil)
|
||||||
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
||||||
options = theme_defaults.merge(options)
|
options = theme_defaults(options)
|
||||||
@options = options
|
@options = options
|
||||||
@block = block
|
@block = block
|
||||||
|
|
||||||
@@ -206,6 +206,10 @@ module CyberarmEngine
|
|||||||
raise "#{self.class}#recalculate was not overridden!"
|
raise "#{self.class}#recalculate was not overridden!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reposition
|
||||||
|
raise "#{self.class}#reposition was not overridden!"
|
||||||
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
raise "#{self.class}#value was not overridden!"
|
raise "#{self.class}#value was not overridden!"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,21 +9,24 @@ module CyberarmEngine
|
|||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def theme_defaults
|
def theme_defaults(options)
|
||||||
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
||||||
|
_theme = THEME
|
||||||
|
_theme = _theme.merge(options[:theme]) if options[:theme]
|
||||||
|
options.delete(:theme)
|
||||||
|
|
||||||
hash = {}
|
hash = {}
|
||||||
class_names = self.class.ancestors
|
class_names = self.class.ancestors
|
||||||
class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! {|c| c.to_s.split("::").last.to_sym}.reverse!
|
class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! {|c| c.to_s.split("::").last.to_sym}.reverse!
|
||||||
|
|
||||||
class_names.each do |klass|
|
class_names.each do |klass|
|
||||||
next unless data = THEME.dig(klass)
|
next unless data = _theme.dig(klass)
|
||||||
data.each do |key, value|
|
data.each do |key, value|
|
||||||
hash.merge!(data)
|
hash.merge!(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
hash
|
hash.merge(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
THEME = {
|
THEME = {
|
||||||
@@ -86,6 +89,6 @@ module CyberarmEngine
|
|||||||
ToggleButton: { # < Button
|
ToggleButton: { # < Button
|
||||||
checkmark: "√"
|
checkmark: "√"
|
||||||
}
|
}
|
||||||
}
|
}.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
NAME = "InDev"
|
NAME = "InDev"
|
||||||
VERSION = "0.3.0"
|
VERSION = "0.6.0"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user