mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 04:32:35 +00:00
Initial support for using cyberarm_engine as a mruby mrbgem: Remove/disable usages of defined?, update old gosu mouse and keyboard constants, and replace one usage of window.button_down? with proper Gosu.button_down?
This commit is contained in:
@@ -66,6 +66,6 @@ require_relative "cyberarm_engine/model/material"
|
||||
require_relative "cyberarm_engine/model/model_object"
|
||||
require_relative "cyberarm_engine/model/parser"
|
||||
require_relative "cyberarm_engine/model/parsers/wavefront_parser"
|
||||
require_relative "cyberarm_engine/model/parsers/collada_parser" if defined?(Nokogiri)
|
||||
require_relative "cyberarm_engine/model/parsers/collada_parser" if RUBY_ENGINE != "mruby" && defined?(Nokogiri)
|
||||
|
||||
require_relative "cyberarm_engine/builtin/intro_state"
|
||||
|
||||
@@ -18,7 +18,7 @@ module CyberarmEngine
|
||||
|
||||
@gosu_logo = generate_proxy("Gosu", "Game Library", 0xff_111111)
|
||||
@ruby_logo = generate_proxy("Ruby", "Programming Language", 0xff_880000)
|
||||
@opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if defined?(OpenGL)
|
||||
@opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if RUBY_ENGINE != "mruby" && defined?(OpenGL)
|
||||
|
||||
base_time = Gosu.milliseconds
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def lighten(color, amount = 25)
|
||||
if defined?(color.alpha)
|
||||
if color.respond_to?(:alpha)
|
||||
Gosu::Color.rgba(color.red + amount, color.green + amount, color.blue + amount, color.alpha)
|
||||
else
|
||||
Gosu::Color.rgb(color.red + amount, color.green + amount, color.blue + amount)
|
||||
@@ -60,7 +60,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def darken(color, amount = 25)
|
||||
if defined?(color.alpha)
|
||||
if color.respond_to?(:alpha)
|
||||
Gosu::Color.rgba(color.red - amount, color.green - amount, color.blue - amount, color.alpha)
|
||||
else
|
||||
Gosu::Color.rgb(color.red - amount, color.green - amount, color.blue - amount)
|
||||
|
||||
@@ -103,7 +103,7 @@ module CyberarmEngine
|
||||
|
||||
def button_down(id)
|
||||
case id
|
||||
when Gosu::KbEnter, Gosu::KbReturn
|
||||
when Gosu::KB_ENTER, Gosu::KB_RETURN
|
||||
return unless @text_input.text.length.positive?
|
||||
|
||||
@history.text += "\n<c=999999>> #{@text_input.text}</c>"
|
||||
@@ -113,12 +113,12 @@ module CyberarmEngine
|
||||
handle_command
|
||||
@text_input.text = ""
|
||||
|
||||
when Gosu::KbUp
|
||||
when Gosu::KB_UP
|
||||
@command_history_index -= 1
|
||||
@command_history_index = 0 if @command_history_index.negative?
|
||||
@text_input.text = @command_history[@command_history_index]
|
||||
|
||||
when Gosu::KbDown
|
||||
when Gosu::KB_DOWN
|
||||
@command_history_index += 1
|
||||
if @command_history_index > @command_history.size - 1
|
||||
@text_input.text = "" unless @command_history_index > @command_history.size
|
||||
@@ -127,7 +127,7 @@ module CyberarmEngine
|
||||
@text_input.text = @command_history[@command_history_index]
|
||||
end
|
||||
|
||||
when Gosu::KbTab
|
||||
when Gosu::KB_TAB
|
||||
split = @text_input.text.split(" ")
|
||||
|
||||
if !@text_input.text.end_with?(" ") && split.size == 1
|
||||
@@ -142,7 +142,7 @@ module CyberarmEngine
|
||||
cmd.autocomplete(self)
|
||||
end
|
||||
|
||||
when Gosu::KbBacktick
|
||||
when Gosu::KB_BACKTICK
|
||||
# Remove backtick character from input
|
||||
@text_input.text = if @text_input.text.size > 1
|
||||
@text_input.text[0..@text_input.text.size - 2]
|
||||
@@ -151,7 +151,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
# Copy
|
||||
when Gosu::KbC
|
||||
when Gosu::KB_C
|
||||
if control_down? && shift_down?
|
||||
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
||||
p @memory
|
||||
@@ -160,7 +160,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
# Paste
|
||||
when Gosu::KbV
|
||||
when Gosu::KB_V
|
||||
if control_down? && shift_down?
|
||||
string = @text_input.text.chars.insert(caret_pos, @memory).join
|
||||
_caret_pos = caret_pos
|
||||
@@ -170,7 +170,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
# Cut
|
||||
when Gosu::KbX
|
||||
when Gosu::KB_X
|
||||
if control_down? && shift_down?
|
||||
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
||||
string = @text_input.text.chars
|
||||
@@ -182,7 +182,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
# Delete word to left of caret
|
||||
when Gosu::KbW
|
||||
when Gosu::KB_W
|
||||
if control_down?
|
||||
split = @text_input.text.split(" ")
|
||||
split.delete(split.last)
|
||||
@@ -190,7 +190,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
# Clear history
|
||||
when Gosu::KbL
|
||||
when Gosu::KB_L
|
||||
@history.text = "" if control_down?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,7 +42,7 @@ module CyberarmEngine
|
||||
@radius = if options[:radius]
|
||||
options[:radius]
|
||||
else
|
||||
defined?(@image.width) ? ((@image.width + @image.height) / 4) * scale : 1
|
||||
@image.respond_to?(:width) ? ((@image.width + @image.height) / 4) * scale : 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -149,6 +149,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def markup_width(text = @text)
|
||||
text = text.to_s
|
||||
|
||||
spacing = 0
|
||||
spacing += @border_size if @border
|
||||
spacing += @shadow_size if @shadow
|
||||
|
||||
@@ -196,7 +196,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def enter(_sender)
|
||||
@focus = false unless window.button_down?(Gosu::MsLeft)
|
||||
@focus = false unless Gosu.button_down?(Gosu::MS_LEFT)
|
||||
|
||||
if !@enabled
|
||||
update_styles(:disabled)
|
||||
@@ -316,7 +316,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def debug_draw
|
||||
return if defined?(GUI_DEBUG_ONLY_ELEMENT) && self.class == GUI_DEBUG_ONLY_ELEMENT
|
||||
# FIXME
|
||||
return# if const_defined?(GUI_DEBUG_ONLY_ELEMENT) && self.class == GUI_DEBUG_ONLY_ELEMENT
|
||||
|
||||
Gosu.draw_line(
|
||||
x, y, @debug_color,
|
||||
|
||||
@@ -156,7 +156,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def line_width(text)
|
||||
(@text.textobject.markup_width(text) + noncontent_width)
|
||||
(@text.textobject.markup_width(text.to_s) + noncontent_width)
|
||||
end
|
||||
|
||||
def value
|
||||
|
||||
@@ -63,7 +63,8 @@ module CyberarmEngine
|
||||
@tip.draw
|
||||
end
|
||||
|
||||
if defined?(GUI_DEBUG)
|
||||
# FIXME
|
||||
if false# defined?(GUI_DEBUG)
|
||||
Gosu.flush
|
||||
|
||||
@root_container.debug_draw
|
||||
@@ -121,9 +122,9 @@ module CyberarmEngine
|
||||
@mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
|
||||
@mouse_over = new_mouse_over
|
||||
|
||||
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MsLeft)
|
||||
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MsMiddle)
|
||||
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MsRight)
|
||||
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MS_LEFT)
|
||||
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MS_MIDDLE)
|
||||
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MS_RIGHT)
|
||||
|
||||
if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
|
||||
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
|
||||
@@ -151,13 +152,13 @@ module CyberarmEngine
|
||||
super
|
||||
|
||||
case id
|
||||
when Gosu::MsLeft
|
||||
when Gosu::MS_LEFT
|
||||
redirect_mouse_button(:left)
|
||||
when Gosu::MsMiddle
|
||||
when Gosu::MS_MIDDLE
|
||||
redirect_mouse_button(:middle)
|
||||
when Gosu::MsRight
|
||||
when Gosu::MS_RIGHT
|
||||
redirect_mouse_button(:right)
|
||||
when Gosu::KbF5
|
||||
when Gosu::KB_F5
|
||||
request_recalculate
|
||||
end
|
||||
|
||||
@@ -168,15 +169,15 @@ module CyberarmEngine
|
||||
super
|
||||
|
||||
case id
|
||||
when Gosu::MsLeft
|
||||
when Gosu::MS_LEFT
|
||||
redirect_released_mouse_button(:left)
|
||||
when Gosu::MsMiddle
|
||||
when Gosu::MS_MIDDLE
|
||||
redirect_released_mouse_button(:middle)
|
||||
when Gosu::MsRight
|
||||
when Gosu::MS_RIGHT
|
||||
redirect_released_mouse_button(:right)
|
||||
when Gosu::MsWheelUp
|
||||
when Gosu::MS_WHEEL_UP
|
||||
redirect_mouse_wheel(:up)
|
||||
when Gosu::MsWheelDown
|
||||
when Gosu::MS_WHEEL_DOWN
|
||||
redirect_mouse_wheel(:down)
|
||||
end
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ module CyberarmEngine
|
||||
attr_reader :hash
|
||||
|
||||
def initialize(hash = {})
|
||||
h = Marshal.load(Marshal.dump(hash))
|
||||
h = hash
|
||||
# h = Marshal.load(Marshal.dump(hash))
|
||||
|
||||
h[:default] = {}
|
||||
|
||||
|
||||
@@ -37,13 +37,16 @@ module CyberarmEngine
|
||||
|
||||
@last_frame_time = Gosu.milliseconds - 1
|
||||
@current_frame_time = Gosu.milliseconds
|
||||
self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}"
|
||||
self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.user_languages.join(', ')}"
|
||||
|
||||
@states = []
|
||||
@exit_on_opengl_error = false
|
||||
preload_default_shaders if respond_to?(:preload_default_shaders)
|
||||
|
||||
setup if defined?(setup)
|
||||
setup
|
||||
end
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def draw
|
||||
@@ -120,7 +123,7 @@ module CyberarmEngine
|
||||
def push_state(klass, options = {})
|
||||
options = { setup: true }.merge(options)
|
||||
|
||||
if klass.instance_of?(klass.class) && defined?(klass.options)
|
||||
if klass.instance_of?(klass.class) && klass.respond_to?(:options)
|
||||
@states << klass
|
||||
klass.setup if options[:setup]
|
||||
klass.post_setup if options[:setup]
|
||||
|
||||
29
mrbgem.rake
Normal file
29
mrbgem.rake
Normal file
@@ -0,0 +1,29 @@
|
||||
MRuby::Gem::Specification.new("mruby-cyberarm_engine") do |spec|
|
||||
spec.license = "MIT"
|
||||
spec.authors = "cyberarm"
|
||||
spec.summary = " Yet another framework for building games with Gosu"
|
||||
|
||||
lib_rbfiles = []
|
||||
# Dir.glob("#{File.expand_path("..", __FILE__)}/lib/**/*.rb").reject do |f|
|
||||
# File.basename(f.downcase, ".rb") == "cyberarm_engine" ||
|
||||
# File.basename(f.downcase, ".rb") == "opengl" ||
|
||||
# f.downcase.include?("/opengl/")
|
||||
# end.reverse!
|
||||
|
||||
local_path = File.expand_path("..", __FILE__)
|
||||
File.read("#{local_path}/lib/cyberarm_engine.rb").each_line do |line|
|
||||
line = line.strip
|
||||
|
||||
next unless line.start_with?("require_relative")
|
||||
|
||||
file = line.split("require_relative").last.strip.gsub("\"", "")
|
||||
|
||||
next if file.include?(" if ")
|
||||
|
||||
lib_rbfiles << "#{local_path}/lib/#{file}.rb"
|
||||
end
|
||||
|
||||
pp lib_rbfiles
|
||||
|
||||
spec.rbfiles = lib_rbfiles
|
||||
end
|
||||
Reference in New Issue
Block a user