summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorTom Black <[email protected]>2016-11-27 23:07:49 -0500
committerTom Black <[email protected]>2016-11-27 23:07:49 -0500
commit2b9aa6eeeb6d875f40807f7e0a2e35bec3690171 (patch)
tree5d02ff59129cd13378576b62096fcddd9cd1e984 /lib
parent31c23832be4de103bea840dffd86942fc7697b66 (diff)
downloadruby2d-2b9aa6eeeb6d875f40807f7e0a2e35bec3690171.tar.gz
ruby2d-2b9aa6eeeb6d875f40807f7e0a2e35bec3690171.zip
Remove things MRuby doesn't support
- Keyword arguments - `defined?` - Regex - `File`
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d/application.rb5
-rw-r--r--lib/ruby2d/color.rb9
-rw-r--r--lib/ruby2d/dsl.rb5
-rw-r--r--lib/ruby2d/image.rb10
-rw-r--r--lib/ruby2d/quad.rb4
-rw-r--r--lib/ruby2d/rectangle.rb2
-rw-r--r--lib/ruby2d/sprite.rb10
-rw-r--r--lib/ruby2d/square.rb2
-rw-r--r--lib/ruby2d/text.rb12
-rw-r--r--lib/ruby2d/triangle.rb4
-rw-r--r--lib/ruby2d/window.rb9
11 files changed, 44 insertions, 28 deletions
diff --git a/lib/ruby2d/application.rb b/lib/ruby2d/application.rb
index 52b50e1..c6924b1 100644
--- a/lib/ruby2d/application.rb
+++ b/lib/ruby2d/application.rb
@@ -12,8 +12,9 @@ module Ruby2D::Application
@@window.set(opts)
end
- def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc)
- @@window.on(mouse: mouse, key: key, key_up: key_up, key_down: key_down, controller: controller, &proc)
+ # def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc)
+ def on(args = {}, &proc)
+ @@window.on(args, &proc)
end
def on_key(&proc)
diff --git a/lib/ruby2d/color.rb b/lib/ruby2d/color.rb
index f39b3c1..c4f1925 100644
--- a/lib/ruby2d/color.rb
+++ b/lib/ruby2d/color.rb
@@ -48,8 +48,13 @@ module Ruby2D
# test whether input string is Hex color
def self.is_hex(a)
- result = !(/^#[0-9A-F]{6}$/i.match(a).nil?)
- return result
+ # result = !(/^#[0-9A-F]{6}$/i.match(a).nil?)
+ # return result
+ if (a.include? "#") && (a.length == 7)
+ true
+ else
+ false
+ end
end
# Color must be String, like 'red', or Array, like [1.0, 0, 0, 1.0]
diff --git a/lib/ruby2d/dsl.rb b/lib/ruby2d/dsl.rb
index dbc6390..20d088e 100644
--- a/lib/ruby2d/dsl.rb
+++ b/lib/ruby2d/dsl.rb
@@ -9,8 +9,9 @@ module Ruby2D::DSL
Application.set(opts)
end
- def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc)
- Application.on(mouse: mouse, key: key, key_up: key_up, key_down: key_down, controller: controller, &proc)
+ # def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc)
+ def on(args = {}, &proc)
+ Application.on(args, &proc)
end
def on_key(&proc)
diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb
index 5b29cee..2e18b44 100644
--- a/lib/ruby2d/image.rb
+++ b/lib/ruby2d/image.rb
@@ -7,20 +7,20 @@ module Ruby2D
def initialize(x, y, path)
- unless File.exists? path
- raise Error, "Cannot find image file `#{path}`"
- end
+ # unless File.exists? path
+ # raise Error, "Cannot find image file `#{path}`"
+ # end
@type_id = 3
@x, @y, @path = x, y, path
- if defined? DSL
+ if Module.const_defined? :DSL
Application.add(self)
end
end
def remove
- if defined? DSL
+ if Module.const_defined? :DSL
Application.remove(self)
end
end
diff --git a/lib/ruby2d/quad.rb b/lib/ruby2d/quad.rb
index 3185588..eca123d 100644
--- a/lib/ruby2d/quad.rb
+++ b/lib/ruby2d/quad.rb
@@ -20,7 +20,7 @@ module Ruby2D
@color = c
update_color(c)
- if defined? DSL
+ if Module.const_defined? :DSL
Application.add(self)
end
end
@@ -31,7 +31,7 @@ module Ruby2D
end
def remove
- if defined? DSL
+ if Module.const_defined? :DSL
Application.remove(self)
end
end
diff --git a/lib/ruby2d/rectangle.rb b/lib/ruby2d/rectangle.rb
index 1ee30d5..d6ec46c 100644
--- a/lib/ruby2d/rectangle.rb
+++ b/lib/ruby2d/rectangle.rb
@@ -11,7 +11,7 @@ module Ruby2D
update_coords(x, y, w, h)
update_color(c)
- if defined? DSL
+ if Module.const_defined? :DSL
Application.add(self)
end
end
diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb
index 6e3eae4..e327f7f 100644
--- a/lib/ruby2d/sprite.rb
+++ b/lib/ruby2d/sprite.rb
@@ -7,9 +7,9 @@ module Ruby2D
def initialize(x, y, path)
- unless File.exists? path
- raise Error, "Cannot find image file `#{path}`"
- end
+ # unless File.exists? path
+ # raise Error, "Cannot find image file `#{path}`"
+ # end
@type_id = 4
@x, @y, @path = x, y, path
@@ -20,7 +20,7 @@ module Ruby2D
@current_frame = 0
@current_frame_time = 0
- if defined? DSL
+ if Module.const_defined? :DSL
Application.add(self)
end
end
@@ -49,7 +49,7 @@ module Ruby2D
end
def remove
- if defined? DSL
+ if Module.const_defined? :DSL
Application.remove(self)
end
end
diff --git a/lib/ruby2d/square.rb b/lib/ruby2d/square.rb
index 0be909f..a4b8151 100644
--- a/lib/ruby2d/square.rb
+++ b/lib/ruby2d/square.rb
@@ -12,7 +12,7 @@ module Ruby2D
update_coords(x, y, s, s)
update_color(c)
- if defined? DSL
+ if Module.const_defined? :DSL
Application.add(self)
end
end
diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb
index dedfa39..ab4a204 100644
--- a/lib/ruby2d/text.rb
+++ b/lib/ruby2d/text.rb
@@ -8,17 +8,19 @@ module Ruby2D
def initialize(x=0, y=0, size=20, msg="Hello World!", font="Arial", c="white")
if File.exists? font
+
+ # if File.exists? font
@font = font
- else
- @font = resolve_path(font)
- end
+ # else
+ # @font = resolve_path(font)
+ # end
@type_id = 5
@x, @y, @size = x, y, size
@text, @color = msg, c
update_color(c)
- if defined? DSL
+ if Module.const_defined? :DSL
Application.add(self)
end
end
@@ -33,7 +35,7 @@ module Ruby2D
end
def remove
- if defined? DSL
+ if Module.const_defined? :DSL
Application.remove(self)
end
end
diff --git a/lib/ruby2d/triangle.rb b/lib/ruby2d/triangle.rb
index 9bb0a4e..8d4f373 100644
--- a/lib/ruby2d/triangle.rb
+++ b/lib/ruby2d/triangle.rb
@@ -16,7 +16,7 @@ module Ruby2D
@color = c
update_color(c)
- if defined? DSL
+ if Module.const_defined? :DSL
Application.add(self)
end
end
@@ -27,7 +27,7 @@ module Ruby2D
end
def remove
- if defined? DSL
+ if Module.const_defined? :DSL
Application.remove(self)
end
end
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index adbebfe..996dca2 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -82,7 +82,14 @@ module Ruby2D
true
end
- def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc)
+ # def on(mouse: nil, key: nil, key_up: nil, key_down: nil, controller: nil, &proc)
+ def on(args = {}, &proc)
+ mouse = args[:mouse]
+ key = args[:key]
+ key_up = args[:key_up]
+ key_down = args[:key_down]
+ controller = args[:controller]
+
unless mouse.nil?
# reg_mouse(btn, &proc)
end