diff options
| author | Tom Black <[email protected]> | 2017-05-19 19:57:58 -0400 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-05-20 21:40:40 -0400 |
| commit | 09ed2811ad3ccb9af50028447fabbcee5b5c5ae2 (patch) | |
| tree | fb79eb28497e2ccc2d44b86a40034984649e9eb3 | |
| parent | 6ab1ad93c6ae1704fee0adb77dbcf8c721913a73 (diff) | |
| download | ruby2d-09ed2811ad3ccb9af50028447fabbcee5b5c5ae2.tar.gz ruby2d-09ed2811ad3ccb9af50028447fabbcee5b5c5ae2.zip | |
Remove trailing whitespace everywhere
It's what all the kids are doing
| -rw-r--r-- | Rakefile | 4 | ||||
| -rwxr-xr-x | bin/ruby2d | 48 | ||||
| -rw-r--r-- | ext/ruby2d/extconf.rb | 10 | ||||
| -rw-r--r-- | ext/ruby2d/ruby2d-opal.rb | 88 | ||||
| -rw-r--r-- | ext/ruby2d/ruby2d.c | 184 | ||||
| -rw-r--r-- | lib/ruby2d/application.rb | 20 | ||||
| -rw-r--r-- | lib/ruby2d/color.rb | 32 | ||||
| -rw-r--r-- | lib/ruby2d/dsl.rb | 16 | ||||
| -rw-r--r-- | lib/ruby2d/image.rb | 8 | ||||
| -rw-r--r-- | lib/ruby2d/line.rb | 6 | ||||
| -rw-r--r-- | lib/ruby2d/music.rb | 18 | ||||
| -rw-r--r-- | lib/ruby2d/quad.rb | 14 | ||||
| -rw-r--r-- | lib/ruby2d/rectangle.rb | 18 | ||||
| -rw-r--r-- | lib/ruby2d/renderable.rb | 6 | ||||
| -rw-r--r-- | lib/ruby2d/sound.rb | 12 | ||||
| -rw-r--r-- | lib/ruby2d/sprite.rb | 26 | ||||
| -rw-r--r-- | lib/ruby2d/square.rb | 8 | ||||
| -rw-r--r-- | lib/ruby2d/text.rb | 20 | ||||
| -rw-r--r-- | lib/ruby2d/triangle.rb | 10 | ||||
| -rw-r--r-- | lib/ruby2d/window.rb | 50 | ||||
| -rw-r--r-- | ruby2d.gemspec | 4 | ||||
| -rw-r--r-- | test/color_spec.rb | 14 | ||||
| -rw-r--r-- | test/dsl_spec.rb | 8 | ||||
| -rw-r--r-- | test/image_spec.rb | 4 | ||||
| -rw-r--r-- | test/spec_helper.rb | 4 | ||||
| -rw-r--r-- | test/sprite_spec.rb | 4 | ||||
| -rw-r--r-- | test/testcard.rb | 6 | ||||
| -rw-r--r-- | test/text_spec.rb | 4 |
28 files changed, 323 insertions, 323 deletions
@@ -88,13 +88,13 @@ namespace :test do get_args run_mri_test ARGV[1] end - + desc "Run native test" task :native do get_args run_native_test ARGV[1] end - + desc "Run web test" task :web do get_args @@ -48,18 +48,18 @@ end # Assemble the Ruby 2D library in one `.rb` file def make_lib FileUtils.mkdir_p 'build' - + lib_dir = "#{@gem_dir}/lib/ruby2d/" - + lib = "" @lib_files.each do |f| lib << File.read("#{lib_dir + f}.rb") + "\n\n" end - + lib << " include Ruby2D::DSL include Ruby2D\n" - + File.write('build/lib.rb', lib) end @@ -76,25 +76,25 @@ end # Build a native version of the provided Ruby application def build_native(rb_file) - + # Check if MRuby exists; if not, quit if `which mruby`.empty? puts "#{'Error:'.error} Can't find MRuby, which is needed to build native Ruby 2D applications.\n" exit end - + # Assemble the Ruby 2D library in one `.rb` file and compile to bytecode make_lib `mrbc -Bruby2d_lib -obuild/lib.c build/lib.rb` - + # Read the provided Ruby source file, copy to build dir and compile to bytecode - + File.open('build/src.rb', 'w') do |file| file << strip_require(rb_file) end - + `mrbc -Bruby2d_app -obuild/src.c build/src.rb` - + # Combine contents of C source files and bytecode into one file open('build/app.c', 'w') do |f| f << "#define MRUBY 1" << "\n\n" @@ -102,10 +102,10 @@ def build_native(rb_file) f << File.read("build/src.c") << "\n\n" f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c") end - + # Compile to native executable `cc build/app.c -lmruby \`simple2d --libs\` -o build/app` - + # Success! puts "Native app created at `build/app`" end @@ -113,22 +113,22 @@ end # Build a web-based version of the provided Ruby application def build_web(rb_file) - + # Assemble the Ruby 2D library in one `.rb` file and compile to JS make_lib `opal --compile --no-opal build/lib.rb > build/lib.js` - + # Read the provided Ruby source file, copy to build dir, and compile to JS - + File.open('build/src.rb', 'w') do |file| file << strip_require(rb_file) end - + `opal --compile --no-opal build/src.rb > build/src.js` - + FileUtils.cp "#{@gem_dir}/ext/ruby2d/ruby2d-opal.rb", "build/" `opal --compile --no-opal build/ruby2d-opal.rb > build/ruby2d-opal.js` - + # Combine contents of JS source files and compiled JS into one file open('build/app.js', 'w') do |f| f << File.read("#{@gem_dir}/assets/simple2d.js") << "\n\n" @@ -137,10 +137,10 @@ def build_web(rb_file) f << File.read("build/ruby2d-opal.js") << "\n\n" f << File.read("build/src.js") << "\n\n" end - + # Copy over HTML template FileUtils.cp "#{@gem_dir}/assets/template.html", "build/app.html" - + # Success! puts "Web app created at `build/app.js`", " Run by opening `build/app.html`" @@ -150,13 +150,13 @@ end # Build an application package for the current platform def build_package require 'fileutils' - + icon_path = "#{@gem_dir}/assets/app.icns" - + FileUtils.mkpath "build/App.app/Contents/MacOS" FileUtils.mkpath "build/App.app/Contents/Resources" FileUtils.cp icon_path, "build/App.app/Contents/Resources" - + info_plist = %( <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> @@ -177,7 +177,7 @@ def build_package </dict> </plist> ) - + File.open("build/App.app/Contents/Info.plist", 'w') { |f| f.write(info_plist) } FileUtils.cp "build/app", "build/App.app/Contents/MacOS/" puts "App written to `build/App.app`." diff --git a/ext/ruby2d/extconf.rb b/ext/ruby2d/extconf.rb index 1256333..1c3138e 100644 --- a/ext/ruby2d/extconf.rb +++ b/ext/ruby2d/extconf.rb @@ -32,10 +32,10 @@ case RUBY_PLATFORM # macOS when /darwin/ - + # Simple 2D not installed if `which simple2d`.empty? - + # Homebrew not installed if `which brew`.empty? $errors << "Ruby 2D uses a native library called Simple 2D." << @@ -46,7 +46,7 @@ when /darwin/ " brew install simple2d".bold print_errors exit - + # Homebrew installed, instruct to install Simple 2D else $errors << "Ruby 2D uses a native library called Simple 2D." << @@ -57,10 +57,10 @@ when /darwin/ exit end end - + # Linux and Windows / MinGW when /linux|mingw/ - + # Simple 2D not installed if `which simple2d`.empty? $errors << "Ruby 2D uses a native library called Simple 2D.\n" << diff --git a/ext/ruby2d/ruby2d-opal.rb b/ext/ruby2d/ruby2d-opal.rb index e160f77..534b01c 100644 --- a/ext/ruby2d/ruby2d-opal.rb +++ b/ext/ruby2d/ruby2d-opal.rb @@ -19,7 +19,7 @@ const $R2D_TEXT = 6; function on_key(e) { - + switch (e.type) { case S2D.KEY_DOWN: #{type = :down}; @@ -31,16 +31,16 @@ function on_key(e) { #{type = :up}; break; } - + #{$R2D_WINDOW.key_callback(type, `e.key`)}; } function on_mouse(e) { - + #{direction = nil} #{button = nil} - + switch (e.type) { case S2D.MOUSE_DOWN: #{type = :down}; @@ -56,7 +56,7 @@ function on_mouse(e) { #{type = :move}; break; } - + if (e.type == S2D.MOUSE_DOWN || e.type == S2D.MOUSE_UP) { switch (e.button) { case S2D.MOUSE_LEFT: @@ -76,7 +76,7 @@ function on_mouse(e) { break; } } - + #{$R2D_WINDOW.mouse_callback( type, button, direction, `e.x`, `e.y`, `e.delta_x`, `e.delta_y` @@ -94,30 +94,30 @@ function update() { function render() { - + // Set background color win.background.r = #{$R2D_WINDOW.get(:background).r}; win.background.g = #{$R2D_WINDOW.get(:background).g}; win.background.b = #{$R2D_WINDOW.get(:background).b}; win.background.a = #{$R2D_WINDOW.get(:background).a}; - + var objects = #{$R2D_WINDOW.objects}; - + for (var i = 0; i < objects.length; i++) { - + var el = objects[i]; - + switch (el.type_id) { - + case $R2D_TRIANGLE: - + S2D.DrawTriangle( el.x1, el.y1, el.c1.r, el.c1.g, el.c1.b, el.c1.a, el.x2, el.y2, el.c2.r, el.c2.g, el.c2.b, el.c2.a, el.x3, el.y3, el.c3.r, el.c3.g, el.c3.b, el.c3.a ); break; - + case $R2D_QUAD: S2D.DrawQuad( el.x1, el.y1, el.c1.r, el.c1.g, el.c1.b, el.c1.a, @@ -126,7 +126,7 @@ function render() { el.x4, el.y4, el.c4.r, el.c4.g, el.c4.b, el.c4.a ); break; - + case $R2D_LINE: S2D.DrawLine( el.x1, el.y1, el.x2, el.y2, el.width, @@ -136,26 +136,26 @@ function render() { el.c4.r, el.c4.g, el.c4.b, el.c4.a ); break; - + case $R2D_IMAGE: el.data.x = el.x; el.data.y = el.y; - + if (el.width != Opal.nil) el.data.width = el.width; if (el.height != Opal.nil) el.data.height = el.height; - + el.data.color.r = el.color.r; el.data.color.g = el.color.g; el.data.color.b = el.color.b; el.data.color.a = el.color.a; - + S2D.DrawImage(el.data); break; - + case $R2D_SPRITE: el.data.x = el.x; el.data.y = el.y; - + S2D.ClipSprite( el.data, el.clip_x, @@ -163,23 +163,23 @@ function render() { el.clip_w, el.clip_h ); - + S2D.DrawSprite(el.data); break; - + case $R2D_TEXT: el.data.x = el.x; el.data.y = el.y; - + el.data.color.r = el.color.r; el.data.color.g = el.color.g; el.data.color.b = el.color.b; el.data.color.a = el.color.a; - + S2D.DrawText(el.data); break; } - + } }` @@ -197,86 +197,86 @@ module Ruby2D });` end end - + class Sprite def ext_sprite_init(path) `#{self}.data = S2D.CreateSprite(path);` end end - + class Text def ext_text_init `#{self}.data = S2D.CreateText(#{self}.font, #{self}.text, #{self}.size);` @width = `#{self}.data.width;` @height = `#{self}.data.height;` end - + def ext_text_set(msg) `S2D.SetText(#{self}.data, #{msg});` @width = `#{self}.data.width;` @height = `#{self}.data.height;` end end - + class Sound def ext_sound_init(path) `#{self}.data = S2D.CreateSound(path);` end - + def ext_sound_play `S2D.PlaySound(#{self}.data);` end end - + class Music def ext_music_init(path) `#{self}.data = S2D.CreateMusic(path);` end - + def ext_music_play `S2D.PlayMusic(#{self}.data, #{self}.loop);` end - + def ext_music_pause `S2D.PauseMusic();` end - + def ext_music_resume `S2D.ResumeMusic();` end - + def ext_music_stop `S2D.StopMusic();` end - + def ext_music_fadeout(ms) `S2D.FadeOutMusic(ms);` end end - + class Window def ext_window_show $R2D_WINDOW = self - + ` var width = #{$R2D_WINDOW.get(:width)}; var height = #{$R2D_WINDOW.get(:height)}; - + var vp_w = #{$R2D_WINDOW.get(:viewport_width)}; var viewport_width = vp_w != Opal.nil ? vp_w : width; - + var vp_h = #{$R2D_WINDOW.get(:viewport_height)}; var viewport_height = vp_h != Opal.nil ? vp_h : height; - + win = S2D.CreateWindow( #{$R2D_WINDOW.get(:title)}, width, height, update, render, "ruby2d-app", {} ); - + win.viewport.width = viewport_width; win.viewport.height = viewport_height; win.on_key = on_key; win.on_mouse = on_mouse; - + S2D.Show(win);` end end diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c index 29aae4f..3aad03e 100644 --- a/ext/ruby2d/ruby2d.c +++ b/ext/ruby2d/ruby2d.c @@ -241,16 +241,16 @@ static R_VAL ruby2d_text_init(R_VAL self) { #endif sprintf(S2D_msg, "Init text: %s", RSTRING_PTR(r_iv_get(self, "@text"))); S2D_Log(S2D_msg, S2D_INFO); - + S2D_Text *txt = S2D_CreateText( RSTRING_PTR(r_iv_get(self, "@font")), RSTRING_PTR(r_iv_get(self, "@text")), NUM2DBL(r_iv_get(self, "@size")) ); - + r_iv_set(self, "@width", INT2NUM(txt->width)); r_iv_set(self, "@height", INT2NUM(txt->height)); - + r_iv_set(self, "@data", r_data_wrap_struct(text, txt)); return R_NIL; } @@ -268,12 +268,12 @@ static R_VAL ruby2d_text_set(R_VAL self, R_VAL text) { #endif S2D_Text *txt; r_data_get_struct(self, "@data", &text_data_type, S2D_Text, txt); - + S2D_SetText(txt, RSTRING_PTR(text)); - + r_iv_set(self, "@width", INT2NUM(txt->width)); r_iv_set(self, "@height", INT2NUM(txt->height)); - + return R_NIL; } @@ -449,9 +449,9 @@ static void free_music(S2D_Music *mus) { * Simple 2D `on_key` input callback function */ static void on_key(S2D_Event e) { - + R_VAL type; - + switch (e.type) { case S2D_KEY_DOWN: type = r_char_to_sym("down"); @@ -463,7 +463,7 @@ static void on_key(S2D_Event e) { type = r_char_to_sym("up"); break; } - + r_funcall(ruby2d_window, "key_callback", 2, type, r_str_new(e.key)); } @@ -472,9 +472,9 @@ static void on_key(S2D_Event e) { * Simple 2D `on_mouse` input callback function */ void on_mouse(S2D_Event e) { - + R_VAL type = R_NIL; R_VAL button = R_NIL; R_VAL direction = R_NIL; - + switch (e.type) { case S2D_MOUSE_DOWN: // type, button, x, y @@ -495,7 +495,7 @@ void on_mouse(S2D_Event e) { type = r_char_to_sym("move"); break; } - + if (e.type == S2D_MOUSE_DOWN || e.type == S2D_MOUSE_UP) { switch (e.button) { case S2D_MOUSE_LEFT: @@ -515,10 +515,10 @@ void on_mouse(S2D_Event e) { break; } } - + // Bug in MRuby: If `button` or `direction` are symbols (created with // r_char_to_sym), they will always both be `nil`. Use `r_str_new` for now. - + r_funcall( ruby2d_window, "mouse_callback", 7, type, button, direction, INT2NUM(e.x), INT2NUM(e.y), INT2NUM(e.delta_x), INT2NUM(e.delta_y) @@ -530,9 +530,9 @@ void on_mouse(S2D_Event e) { * Simple 2D `on_controller` input callback function */ static void on_controller(S2D_Event e) { - + R_VAL type = R_NIL; - + switch (e.type) { case S2D_AXIS: type = r_char_to_sym("axis"); @@ -544,7 +544,7 @@ static void on_controller(S2D_Event e) { type = r_char_to_sym("button_up"); break; } - + r_funcall( ruby2d_window, "controller_callback", 5, INT2NUM(e.which), type, INT2NUM(e.axis), INT2NUM(e.value), INT2NUM(e.button) @@ -556,17 +556,17 @@ static void on_controller(S2D_Event e) { * Simple 2D `update` callback function */ static void update() { - + // Set the cursor r_iv_set(ruby2d_window, "@mouse_x", INT2NUM(window->mouse.x)); r_iv_set(ruby2d_window, "@mouse_y", INT2NUM(window->mouse.y)); - + // Store frames r_iv_set(ruby2d_window, "@frames", DBL2NUM(window->frames)); - + // Store frame rate r_iv_set(ruby2d_window, "@fps", DBL2NUM(window->fps)); - + // Call update proc, `window.update` r_funcall(ruby2d_window, "update_callback", 0); } @@ -576,32 +576,32 @@ static void update() { * Simple 2D `render` callback function */ static void render() { - + // Set background color R_VAL bc = r_iv_get(ruby2d_window, "@background"); window->background.r = NUM2DBL(r_iv_get(bc, "@r")); window->background.g = NUM2DBL(r_iv_get(bc, "@g")); window->background.b = NUM2DBL(r_iv_get(bc, "@b")); window->background.a = NUM2DBL(r_iv_get(bc, "@a")); - + // Read window objects R_VAL objects = r_iv_get(ruby2d_window, "@objects"); int num_objects = NUM2INT(r_funcall(objects, "length", 0)); - + // Switch on each object type for (int i = 0; i < num_objects; ++i) { - + R_VAL el = r_ary_entry(objects, i); int type_id = NUM2INT(r_iv_get(el, "@type_id")); - + // Switch on the object's type_id switch(type_id) { - + case R2D_TRIANGLE: { R_VAL c1 = r_iv_get(el, "@c1"); R_VAL c2 = r_iv_get(el, "@c2"); R_VAL c3 = r_iv_get(el, "@c3"); - + S2D_DrawTriangle( NUM2DBL(r_iv_get(el, "@x1")), NUM2DBL(r_iv_get(el, "@y1")), @@ -609,14 +609,14 @@ static void render() { NUM2DBL(r_iv_get(c1, "@g")), NUM2DBL(r_iv_get(c1, "@b")), NUM2DBL(r_iv_get(c1, "@a")), - + NUM2DBL(r_iv_get(el, "@x2")), NUM2DBL(r_iv_get(el, "@y2")), NUM2DBL(r_iv_get(c2, "@r")), NUM2DBL(r_iv_get(c2, "@g")), NUM2DBL(r_iv_get(c2, "@b")), NUM2DBL(r_iv_get(c2, "@a")), - + NUM2DBL(r_iv_get(el, "@x3")), NUM2DBL(r_iv_get(el, "@y3")), NUM2DBL(r_iv_get(c3, "@r")), @@ -626,13 +626,13 @@ static void render() { ); } break; - + case R2D_QUAD: { R_VAL c1 = r_iv_get(el, "@c1"); R_VAL c2 = r_iv_get(el, "@c2"); R_VAL c3 = r_iv_get(el, "@c3"); R_VAL c4 = r_iv_get(el, "@c4"); - + S2D_DrawQuad( NUM2DBL(r_iv_get(el, "@x1")), NUM2DBL(r_iv_get(el, "@y1")), @@ -640,21 +640,21 @@ static void render() { NUM2DBL(r_iv_get(c1, "@g")), NUM2DBL(r_iv_get(c1, "@b")), NUM2DBL(r_iv_get(c1, "@a")), - + NUM2DBL(r_iv_get(el, "@x2")), NUM2DBL(r_iv_get(el, "@y2")), NUM2DBL(r_iv_get(c2, "@r")), NUM2DBL(r_iv_get(c2, "@g")), NUM2DBL(r_iv_get(c2, "@b")), NUM2DBL(r_iv_get(c2, "@a")), - + NUM2DBL(r_iv_get(el, "@x3")), NUM2DBL(r_iv_get(el, "@y3")), NUM2DBL(r_iv_get(c3, "@r")), NUM2DBL(r_iv_get(c3, "@g")), NUM2DBL(r_iv_get(c3, "@b")), NUM2DBL(r_iv_get(c3, "@a")), - + NUM2DBL(r_iv_get(el, "@x4")), NUM2DBL(r_iv_get(el, "@y4")), NUM2DBL(r_iv_get(c4, "@r")), @@ -664,35 +664,35 @@ static void render() { ); } break; - + case R2D_LINE: { R_VAL c1 = r_iv_get(el, "@c1"); R_VAL c2 = r_iv_get(el, "@c2"); R_VAL c3 = r_iv_get(el, "@c3"); R_VAL c4 = r_iv_get(el, "@c4"); - + S2D_DrawLine( NUM2DBL(r_iv_get(el, "@x1")), NUM2DBL(r_iv_get(el, "@y1")), NUM2DBL(r_iv_get(el, "@x2")), NUM2DBL(r_iv_get(el, "@y2")), NUM2DBL(r_iv_get(el, "@width")), - + NUM2DBL(r_iv_get(c1, "@r")), NUM2DBL(r_iv_get(c1, "@g")), NUM2DBL(r_iv_get(c1, "@b")), NUM2DBL(r_iv_get(c1, "@a")), - + NUM2DBL(r_iv_get(c2, "@r")), NUM2DBL(r_iv_get(c2, "@g")), NUM2DBL(r_iv_get(c2, "@b")), NUM2DBL(r_iv_get(c2, "@a")), - + NUM2DBL(r_iv_get(c3, "@r")), NUM2DBL(r_iv_get(c3, "@g")), NUM2DBL(r_iv_get(c3, "@b")), NUM2DBL(r_iv_get(c3, "@a")), - + NUM2DBL(r_iv_get(c4, "@r")), NUM2DBL(r_iv_get(c4, "@g")), NUM2DBL(r_iv_get(c4, "@b")), @@ -700,36 +700,36 @@ static void render() { ); } break; - + case R2D_IMAGE: { S2D_Image *img; r_data_get_struct(el, "@data", &image_data_type, S2D_Image, img); - + img->x = NUM2DBL(r_iv_get(el, "@x")); img->y = NUM2DBL(r_iv_get(el, "@y")); - + R_VAL w = r_iv_get(el, "@width"); R_VAL h = r_iv_get(el, "@height"); if (r_test(w)) img->width = NUM2INT(w); if (r_test(h)) img->height = NUM2INT(h); - + R_VAL c = r_iv_get(el, "@color"); img->color.r = NUM2DBL(r_iv_get(c, "@r")); img->color.g = NUM2DBL(r_iv_get(c, "@g")); img->color.b = NUM2DBL(r_iv_get(c, "@b")); img->color.a = NUM2DBL(r_iv_get(c, "@a")); - + S2D_DrawImage(img); } break; - + case R2D_SPRITE: { S2D_Sprite *spr; r_data_get_struct(el, "@data", &sprite_data_type, S2D_Sprite, spr); - + spr->x = NUM2DBL(r_iv_get(el, "@x")); spr->y = NUM2DBL(r_iv_get(el, "@y")); - + S2D_ClipSprite( spr, NUM2INT(r_iv_get(el, "@clip_x")), @@ -737,24 +737,24 @@ static void render() { NUM2INT(r_iv_get(el, "@clip_w")), NUM2INT(r_iv_get(el, "@clip_h")) ); - + S2D_DrawSprite(spr); } break; - + case R2D_TEXT: { S2D_Text *txt; r_data_get_struct(el, "@data", &text_data_type, S2D_Text, txt); - + txt->x = NUM2DBL(r_iv_get(el, "@x")); txt->y = NUM2DBL(r_iv_get(el, "@y")); - + R_VAL c = r_iv_get(el, "@color"); txt->color.r = NUM2DBL(r_iv_get(c, "@r")); txt->color.g = NUM2DBL(r_iv_get(c, "@g")); txt->color.b = NUM2DBL(r_iv_get(c, "@b")); txt->color.a = NUM2DBL(r_iv_get(c, "@a")); - + S2D_DrawText(txt); } break; @@ -772,17 +772,17 @@ static R_VAL ruby2d_show(mrb_state* mrb, R_VAL self) { static R_VAL ruby2d_show(R_VAL self) { #endif ruby2d_window = self; - + if (r_test(r_iv_get(self, "@diagnostics"))) { S2D_Diagnostics(true); } - + // Get window attributes char *title = RSTRING_PTR(r_iv_get(self, "@title")); int width = NUM2INT(r_iv_get(self, "@width")); int height = NUM2INT(r_iv_get(self, "@height")); int flags = 0; - + // Get window flags if (r_test(r_iv_get(self, "@resizable"))) { flags = flags | S2D_RESIZABLE; @@ -796,29 +796,29 @@ static R_VAL ruby2d_show(R_VAL self) { if (r_test(r_iv_get(self, "@highdpi"))) { flags = flags | S2D_HIGHDPI; } - + // Check viewport size and set - + R_VAL vp_w = r_iv_get(self, "@viewport_width"); int viewport_width = r_test(vp_w) ? NUM2INT(vp_w) : width; - + R_VAL vp_h = r_iv_get(self, "@viewport_height"); int viewport_height = r_test(vp_h) ? NUM2INT(vp_h) : height; - + // Create and show window - + window = S2D_CreateWindow( title, width, height, update, render, flags ); - + window->viewport.width = viewport_width; window->viewport.height = viewport_height; window->on_key = on_key; window->on_mouse = on_mouse; window->on_controller = on_controller; - + S2D_Show(window); - + atexit(free_window); return R_NIL; } @@ -841,91 +841,91 @@ int main(void) { // Open the MRuby environment mrb = mrb_open(); if (!mrb) { /* handle error */ } - + // Load the Ruby 2D library mrb_load_irep(mrb, ruby2d_lib); - + // Add missing MRuby classes, methods R_CLASS file_class = mrb_define_class(mrb, "File", mrb->object_class); mrb_define_class_method(mrb, file_class, "exists?", file_exists, r_args_req(1)); - + #else /* * Ruby C extension init */ void Init_ruby2d() { #endif - + // Ruby2D R_CLASS ruby2d_module = r_define_module("Ruby2D"); - + // Ruby2D::Image R_CLASS ruby2d_image_class = r_define_class(ruby2d_module, "Image"); - + // Ruby2D::Image#init r_define_method(ruby2d_image_class, "ext_image_init", ruby2d_image_init, r_args_req(1)); - + // Ruby2D::Sprite R_CLASS ruby2d_sprite_class = r_define_class(ruby2d_module, "Sprite"); - + // Ruby2D::Sprite#init r_define_method(ruby2d_sprite_class, "ext_sprite_init", ruby2d_sprite_init, r_args_req(1)); - + // Ruby2D::Text R_CLASS ruby2d_text_class = r_define_class(ruby2d_module, "Text"); - + // Ruby2D::Text#init r_define_method(ruby2d_text_class, "ext_text_init", ruby2d_text_init, r_args_none); - + // Ruby2D::Text#ext_text_set r_define_method(ruby2d_text_class, "ext_text_set", ruby2d_text_set, r_args_req(1)); - + // Ruby2D::Sound R_CLASS ruby2d_sound_class = r_define_class(ruby2d_module, "Sound"); - + // Ruby2D::Sound#init r_define_method(ruby2d_sound_class, "ext_sound_init", ruby2d_sound_init, r_args_req(1)); - + // Ruby2D::Sound#play r_define_method(ruby2d_sound_class, "ext_sound_play", ruby2d_sound_play, r_args_none); - + // Ruby2D::Music R_CLASS ruby2d_music_class = r_define_class(ruby2d_module, "Music"); - + // Ruby2D::Music#init r_define_method(ruby2d_music_class, "ext_music_init", ruby2d_music_init, r_args_req(1)); - + // Ruby2D::Music#play r_define_method(ruby2d_music_class, "ext_music_play", ruby2d_music_play, r_args_none); - + // Ruby2D::Music#pause r_define_method(ruby2d_music_class, "ext_music_pause", ruby2d_music_pause, r_args_none); - + // Ruby2D::Music#resume r_define_method(ruby2d_music_class, "ext_music_resume", ruby2d_music_resume, r_args_none); - + // Ruby2D::Music#stop r_define_method(ruby2d_music_class, "ext_music_stop", ruby2d_music_stop, r_args_none); - + // Ruby2D::Music#fadeout r_define_method(ruby2d_music_class, "ext_music_fadeout", ruby2d_music_fadeout, r_args_req(1)); - + // Ruby2D::Window R_CLASS ruby2d_window_class = r_define_class(ruby2d_module, "Window"); - + // Ruby2D::Window#show r_define_method(ruby2d_window_class, "ext_window_show", ruby2d_show, r_args_none); - + // Ruby2D::Window#close r_define_method(ruby2d_window_class, "ext_window_close", ruby2d_close, r_args_none); - + #if MRUBY // Load the Ruby 2D app mrb_load_irep(mrb, ruby2d_app); - + // If an exception, print error if (mrb->exc) mrb_print_error(mrb); - + // Close the MRuby environment mrb_close(mrb); #endif diff --git a/lib/ruby2d/application.rb b/lib/ruby2d/application.rb index 9984399..d04af70 100644 --- a/lib/ruby2d/application.rb +++ b/lib/ruby2d/application.rb @@ -3,43 +3,43 @@ module Ruby2D::Application class << self @@window = Ruby2D::Window.new - + def get(sym) @@window.get(sym) end - + def set(opts) @@window.set(opts) end - + def on(event, &proc) @@window.on(event, &proc) end - + def off(event_descriptor) @@window.off(event_descriptor) end - + def add(o) @@window.add(o) end - + def remove(o) @@window.remove(o) end - + def clear @@window.clear end - + def update(&proc) @@window.update(&proc) end - + def show @@window.show end - + def close @@window.close end diff --git a/lib/ruby2d/color.rb b/lib/ruby2d/color.rb index 1103c1b..768ebce 100644 --- a/lib/ruby2d/color.rb +++ b/lib/ruby2d/color.rb @@ -15,18 +15,18 @@ module Ruby2D def length @colors.length end - + def opacity; @colors[0].opacity end - + def opacity=(opacity) @colors.each do |color| color.opacity = opacity end end end - + attr_reader :r, :g, :b, :a - + # Based on clrs.cc @@colors = { 'navy' => '#001F3F', @@ -49,7 +49,7 @@ module Ruby2D 'black' => '#111111', 'random' => '' } - + def initialize(c) if !self.class.is_valid? c raise Error, "`#{c}` is not a valid color" @@ -68,19 +68,19 @@ module Ruby2D end end end - + # Check if string is a proper hex value def self.is_hex?(s) # MRuby doesn't support regex, otherwise we'd do: # !(/^#[0-9A-F]{6}$/i.match(a).nil?) s.class == String && s[0] == '#' && s.length == 7 end - + # Check if the color is valid def self.is_valid?(c) @@colors.key?(c) || # keyword self.is_hex?(c) || # hexadecimal value - + # Array of Floats from 0.0..1.0 c.class == Array && c.length == 4 && c.all? { |el| @@ -97,15 +97,15 @@ module Ruby2D Color.new(input) end end - + def opacity; @a end - + def opacity=(opacity) @a = opacity end - + private - + # TODO: Only `Number` supported in JS # Convert from Fixnum (0..255) to Float (0.0..1.0) def to_f(a) @@ -115,19 +115,19 @@ module Ruby2D end return b end - + # Convert from hex value (e.g. #FFF000) to Float (0.0..1.0) def hex_to_f(h) h = (h[1..-1]).chars.each_slice(2).map(&:join) a = [] - + h.each do |el| a.push(el.to_i(16)) end - + a.push(255) return to_f(a) end - + end end diff --git a/lib/ruby2d/dsl.rb b/lib/ruby2d/dsl.rb index 2d55f22..aeca4fa 100644 --- a/lib/ruby2d/dsl.rb +++ b/lib/ruby2d/dsl.rb @@ -4,33 +4,33 @@ module Ruby2D::DSL def get(sym) Application.get(sym) end - + def set(opts) Application.set(opts) end - + def on(event, &proc) Application.on(event, &proc) end - + def off(event_descriptor) Application.off(event_descriptor) end - + def update(&proc) Application.update(&proc) end - + def clear Application.clear end - + def show Application.show end - + def close Application.close end - + end diff --git a/lib/ruby2d/image.rb b/lib/ruby2d/image.rb index 89c447b..6660a4d 100644 --- a/lib/ruby2d/image.rb +++ b/lib/ruby2d/image.rb @@ -6,15 +6,15 @@ module Ruby2D attr_accessor :x, :y, :width, :height, :data attr_reader :path, :color - + def initialize(x, y, path, z=0) - + unless RUBY_ENGINE == 'opal' unless File.exists? path raise Error, "Cannot find image file `#{path}`" end end - + @type_id = 4 @x, @y, @path = x, y, path @z = z @@ -22,7 +22,7 @@ module Ruby2D ext_image_init(path) add end - + def color=(c) @color = Color.new(c) end diff --git a/lib/ruby2d/line.rb b/lib/ruby2d/line.rb index 4832379..9ef534e 100644 --- a/lib/ruby2d/line.rb +++ b/lib/ruby2d/line.rb @@ -13,14 +13,14 @@ module Ruby2D self.color = c add end - + def color=(c) @color = Color.from(c) update_color(@color) end - + private - + def update_color(c) if c.is_a? Color::Set if c.length == 4 diff --git a/lib/ruby2d/music.rb b/lib/ruby2d/music.rb index bd7df45..2437019 100644 --- a/lib/ruby2d/music.rb +++ b/lib/ruby2d/music.rb @@ -2,39 +2,39 @@ module Ruby2D class Music - + attr_accessor :data, :loop attr_reader :path - + def initialize(path) - + unless RUBY_ENGINE == 'opal' unless File.exists? path raise Error, "Cannot find audio file `#{path}`" end end - + @path = path @loop = false ext_music_init(path) end - + def play ext_music_play end - + def pause ext_music_pause end - + def resume ext_music_resume end - + def stop ext_music_stop end - + def fadeout(ms) ext_music_fadeout(ms) end diff --git a/lib/ruby2d/quad.rb b/lib/ruby2d/quad.rb index 60994a5..e3906c0 100644 --- a/lib/ruby2d/quad.rb +++ b/lib/ruby2d/quad.rb @@ -1,7 +1,7 @@ # quad.rb module Ruby2D - class Quad + class Quad include Renderable # Coordinates in clockwise order, starting at top left: # x1,y1 == top left @@ -12,25 +12,25 @@ module Ruby2D :x2, :y2, :c2, :x3, :y3, :c3, :x4, :y4, :c4 - + attr_reader :color - + def initialize(x1=0, y1=0, x2=100, y2=0, x3=100, y3=100, x4=100, y4=100, c='white', z=0) @type_id = 2 @x1, @y1, @x2, @y2, @x3, @y3, @x4, @y4 = x1, y1, x2, y2, x3, y3, x4, y4 @z = z - + self.color = c add end - + def color=(c) @color = Color.from(c) update_color(@color) end - + private - + def update_color(c) if c.is_a? Color::Set if c.length == 4 diff --git a/lib/ruby2d/rectangle.rb b/lib/ruby2d/rectangle.rb index 37ff3c7..569b8b5 100644 --- a/lib/ruby2d/rectangle.rb +++ b/lib/ruby2d/rectangle.rb @@ -2,9 +2,9 @@ module Ruby2D class Rectangle < Quad - + attr_reader :x, :y, :width, :height - + def initialize(x=0, y=0, w=200, h=100, c='white', z=0) @type_id = 2 @x, @y, @width, @height = x, y, w, h @@ -14,33 +14,33 @@ module Ruby2D self.color = c add end - + def x=(x) @x = @x1 = x @x2 = x + @width @x3 = x + @width @x4 = x end - + def y=(y) @y = @y1 = y @y2 = y @y3 = y + @height @y4 = y + @height end - + def width=(w) @width = w update_coords(@x, @y, w, @height) end - + def height=(h) @height = h update_coords(@x, @y, @width, h) end - + private - + def update_coords(x, y, w, h) @x1 = x @y1 = y @@ -51,6 +51,6 @@ module Ruby2D @x3 = x + w @y3 = y + h end - + end end diff --git a/lib/ruby2d/renderable.rb b/lib/ruby2d/renderable.rb index 888c29f..d80482a 100644 --- a/lib/ruby2d/renderable.rb +++ b/lib/ruby2d/renderable.rb @@ -13,17 +13,17 @@ module Ruby2D Application.add(self) end end - + def remove if Module.const_defined? :DSL Application.remove(self) end end - + def opacity self.color.opacity end - + def opacity=(val) self.color.opacity = val end diff --git a/lib/ruby2d/sound.rb b/lib/ruby2d/sound.rb index 776d718..c7b03e6 100644 --- a/lib/ruby2d/sound.rb +++ b/lib/ruby2d/sound.rb @@ -2,25 +2,25 @@ module Ruby2D class Sound - + attr_accessor :data attr_reader :path - + def initialize(path) - + unless RUBY_ENGINE == 'opal' unless File.exists? path raise Error, "Cannot find audio file `#{path}`" end end - + @path = path ext_sound_init(path) end - + def play ext_sound_play end - + end end diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb index 4d6ac23..999e66d 100644 --- a/lib/ruby2d/sprite.rb +++ b/lib/ruby2d/sprite.rb @@ -2,7 +2,7 @@ module Ruby2D class Sprite - + attr_accessor :x, :y, :clip_x, :clip_y, :clip_w, :clip_h, :data attr_reader :z @@ -11,7 +11,7 @@ module Ruby2D # unless File.exists? path # raise Error, "Cannot find image file `#{path}`" # end - + @type_id = 5 @x, @y, @path = x, y, path @clip_x, @clip_y, @clip_w, @clip_h = 0, 0, 0, 0 @@ -27,16 +27,16 @@ module Ruby2D Application.add(self) end end - + def start(x, y, w, h) @default = [x, y, w, h] clip(x, y, w, h) end - + def add(animations) @animations.merge!(animations) end - + def animate(animation) if @current_animation != animation @current_frame = 0 @@ -45,31 +45,31 @@ module Ruby2D end animate_frames(@animations[animation]) end - + def reset clip(@default[0], @default[1], @default[2], @default[3]) @current_animation = nil end - + # TODO: Sprite already has an `add` method, have to reconsile # def add # if Module.const_defined? :DSL # Application.add(self) # end # end - + def remove if Module.const_defined? :DSL Application.remove(self) end end - + private - + def clip(x, y, w, h) @clip_x, @clip_y, @clip_w, @clip_h = x, y, w, h end - + def animate_frames(frames) if @current_frame_time < frames[@current_frame][4] clip_with_current_frame(frames) @@ -83,11 +83,11 @@ module Ruby2D @current_frame_time = 0 end end - + def clip_with_current_frame(frames) clip(frames[@current_frame][0], frames[@current_frame][1], frames[@current_frame][2], frames[@current_frame][3]) end - + end end diff --git a/lib/ruby2d/square.rb b/lib/ruby2d/square.rb index 66347ec..26a929d 100644 --- a/lib/ruby2d/square.rb +++ b/lib/ruby2d/square.rb @@ -2,9 +2,9 @@ module Ruby2D class Square < Rectangle - + attr_reader :size - + def initialize(x=0, y=0, s=100, c='white', z=0) @type_id = 2 @x, @y = x, y @@ -15,11 +15,11 @@ module Ruby2D self.color = c add end - + def size=(s) self.width = self.height = @size = s end - + private :width=, :height= end end diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb index 022f79c..d3c525f 100644 --- a/lib/ruby2d/text.rb +++ b/lib/ruby2d/text.rb @@ -3,18 +3,18 @@ module Ruby2D class Text include Renderable - + attr_accessor :x, :y, :data attr_reader :text, :size, :width, :height, :font, :color - + def initialize(x=0, y=0, text="Hello World!", size=20, font=nil, c='white', z=0) - + # if File.exists? font @font = font # else # @font = resolve_path(font) # end - + @type_id = 6 @x, @y, @size = x, y, size @z = z @@ -23,18 +23,18 @@ module Ruby2D ext_text_init add end - + def text=(msg) @text = msg.to_s ext_text_set(@text) end - + def color=(c) @color = Color.new(c) end - + private - + def resolve_path(font) if RUBY_PLATFORM =~ /darwin/ font_path = "/Library/Fonts/#{font}.ttf" @@ -42,13 +42,13 @@ module Ruby2D # Linux font_path = "/usr/share/fonts/truetype/#{font}.ttf" end - + unless File.exists? font_path raise Error, "Cannot find system font" else font_path end end - + end end diff --git a/lib/ruby2d/triangle.rb b/lib/ruby2d/triangle.rb index cf6e24a..eb6b07f 100644 --- a/lib/ruby2d/triangle.rb +++ b/lib/ruby2d/triangle.rb @@ -3,12 +3,12 @@ module Ruby2D class Triangle include Renderable - + attr_accessor :x1, :y1, :c1, :x2, :y2, :c2, :x3, :y3, :c3 attr_reader :color, :type_id - + def initialize(x1=50, y1=0, x2=100, y2=100, x3=0, y3=100, c='white', z=0) @type_id = 1 @x1, @y1 = x1, y1 @@ -19,14 +19,14 @@ module Ruby2D self.color = c add end - + def color=(c) @color = Color.from(c) update_color(@color) end - + private - + def update_color(c) if c.is_a? Color::Set if c.length == 3 diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb index 837b55a..9970861 100644 --- a/lib/ruby2d/window.rb +++ b/lib/ruby2d/window.rb @@ -2,10 +2,10 @@ module Ruby2D class Window - + attr_reader :objects attr_accessor :mouse_x, :mouse_y, :frames, :fps - + MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y) KeyEvent = Struct.new(:type, :key) ControllerEvent = Struct.new(:which, :type, :axis, :value, :button) @@ -46,7 +46,7 @@ module Ruby2D @update_proc = Proc.new {} @diagnostics = false end - + def new_event_key @event_key = @event_key.next end @@ -71,7 +71,7 @@ module Ruby2D when :diagnostics; @diagnostics end end - + def set(opts) # Store new window attributes, or ignore if nil @title = opts[:title] || @title @@ -88,7 +88,7 @@ module Ruby2D @highdpi = opts[:highdpi] || @highdpi @diagnostics = opts[:diagnostics] || @diagnostics end - + def add(o) case o when nil @@ -99,12 +99,12 @@ module Ruby2D add_object(o) end end - + def remove(o) if o == nil raise Error, "Cannot remove '#{o.class}' from window!" end - + if i = @objects.index(o) @objects.delete_at(i) true @@ -112,36 +112,36 @@ module Ruby2D false end end - + def clear @objects.clear end - + def update(&proc) @update_proc = proc true end - + def on(event, &proc) event_id = new_event_key @events[event][event_id] = proc EventDescriptor.new(event, event_id) end - + def off(event_descriptor) @events[event_descriptor.type].delete(event_descriptor.id) end def key_callback(type, key) # puts "===", "type: #{type}", "key: #{key}" - + key = key.downcase - + # All key events @events[:key].each do |id, e| e.call(KeyEvent.new(type, key)) end - + case type # When key is pressed, fired once when :down @@ -160,17 +160,17 @@ module Ruby2D end end end - + def mouse_callback(type, button, direction, x, y, delta_x, delta_y) # Convert to symbols (see MRuby bug in native extension) button = button.to_sym unless button == nil direction = direction.to_sym unless direction == nil - + # All mouse events @events[:mouse].each do |id, e| e.call(MouseEvent.new(type, button, direction, x, y, delta_x, delta_y)) end - + case type # When mouse button pressed when :down @@ -194,13 +194,13 @@ module Ruby2D end end end - + def controller_callback(which, type, axis, value, button) # All controller events @events[:controller].each do |id, e| e.call(ControllerEvent.new(which, type, axis, value, button)) end - + case type # When controller axis motion, like analog sticks when :axis @@ -219,21 +219,21 @@ module Ruby2D end end end - + def update_callback @update_proc.call end - + def show ext_window_show end - + def close ext_window_close end - + private - + def add_object(o) if [email protected]?(o) index = @objects.index do |object| @@ -249,6 +249,6 @@ module Ruby2D false end end - + end end diff --git a/ruby2d.gemspec b/ruby2d.gemspec index 0ab5176..dc38f74 100644 --- a/ruby2d.gemspec +++ b/ruby2d.gemspec @@ -9,11 +9,11 @@ Gem::Specification.new do |s| s.license = 'MIT' s.author = 'Tom Black' s.email = '[email protected]' - + s.required_ruby_version = '>= 2.0.0' s.add_dependency 'opal', '~> 0.10' s.add_development_dependency 'rspec', '~> 3.5' - + s.files = Dir.glob('lib/**/*') + Dir.glob('assets/**/*') + Dir.glob('ext/**/*.{c,js,rb}') diff --git a/test/color_spec.rb b/test/color_spec.rb index 0fb65c8..299f403 100644 --- a/test/color_spec.rb +++ b/test/color_spec.rb @@ -1,37 +1,37 @@ require 'ruby2d' RSpec.describe Ruby2D::Color do - + describe '#is_valid?' do it 'determines if a color string is valid' do expect(Ruby2D::Color.is_valid? 'red').to eq true expect(Ruby2D::Color.is_valid? 'balloons').to eq false end - + it 'determines if a color string is a valid hex value' do expect(Ruby2D::Color.is_valid? '#c0c0c0').to eq true expect(Ruby2D::Color.is_valid? '#00000').to eq false expect(Ruby2D::Color.is_valid? '123456').to eq false end - + it 'determines if an array is a valid color' do expect(Ruby2D::Color.is_valid? [1, 0, 0.0, 1.0]).to eq true expect(Ruby2D::Color.is_valid? [1.0, 0, 0]).to eq false end - + it 'prevents color values that are out of range' do expect(Ruby2D::Color.is_valid? [1.2, 0, 0, 0]).to eq false expect(Ruby2D::Color.is_valid? [0, 0, -0.1, 0]).to eq false expect(Ruby2D::Color.is_valid? [0, 0, 0, 2]).to eq false end end - + describe '#new' do it 'raises error on bad color' do expect { Ruby2D::Color.new 42 }.to raise_error Ruby2D::Error end end - + describe '#opacity' do it 'sets and returns the opacity' do s1 = Square.new @@ -42,5 +42,5 @@ RSpec.describe Ruby2D::Color do expect(s2.opacity).to eq 0.7 end end - + end diff --git a/test/dsl_spec.rb b/test/dsl_spec.rb index 522b29e..4337046 100644 --- a/test/dsl_spec.rb +++ b/test/dsl_spec.rb @@ -2,7 +2,7 @@ require 'ruby2d' include Ruby2D::DSL RSpec.describe Ruby2D::DSL do - + describe '#get' do it 'gets the default window attributes' do expect(get :width).to eq 640 @@ -10,7 +10,7 @@ RSpec.describe Ruby2D::DSL do expect(get :title).to eq "Ruby 2D" end end - + describe '#set' do it 'sets a single window attribute' do set width: 300 @@ -18,7 +18,7 @@ RSpec.describe Ruby2D::DSL do expect(get :height).to eq 480 expect(get :title).to eq "Ruby 2D" end - + it 'sets multiple window attributes at a time' do set width: 800, height: 600, title: "Hello tests!" expect(get :width).to eq 800 @@ -26,5 +26,5 @@ RSpec.describe Ruby2D::DSL do expect(get :title).to eq "Hello tests!" end end - + end diff --git a/test/image_spec.rb b/test/image_spec.rb index 43950c9..3eb5d86 100644 --- a/test/image_spec.rb +++ b/test/image_spec.rb @@ -1,11 +1,11 @@ require 'ruby2d' RSpec.describe Ruby2D::Image do - + describe '#new' do it "raises exception if image file doesn't exist" do expect { Image.new(0, 0, 'bad_image.png') }.to raise_error(Ruby2D::Error) end end - + end diff --git a/test/spec_helper.rb b/test/spec_helper.rb index d93bff8..b69dfa6 100644 --- a/test/spec_helper.rb +++ b/test/spec_helper.rb @@ -2,11 +2,11 @@ RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end - + config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end - + # Silence output when running tests original_stderr = $stderr original_stdout = $stdout diff --git a/test/sprite_spec.rb b/test/sprite_spec.rb index 42268be..441ca6e 100644 --- a/test/sprite_spec.rb +++ b/test/sprite_spec.rb @@ -1,11 +1,11 @@ require 'ruby2d' RSpec.describe Ruby2D::Sprite do - + describe '#new' do it 'creates a new sprite' do Ruby2D::Sprite.new(0, 0, "tests/media/sprite_sheet.png") end end - + end diff --git a/test/testcard.rb b/test/testcard.rb index a6341c7..b573579 100644 --- a/test/testcard.rb +++ b/test/testcard.rb @@ -239,16 +239,16 @@ end update do pointer.x = (get :mouse_x) - 5 pointer.y = (get :mouse_y) - 7 - + if flash > 0 pointer_outline.color = [0, 1, 0, 1] flash -= 1 else pointer_outline.color = [0, 1, 0, 0] end - + s1.animate(:forwards) - + if (get :frames) % 20 == 0 fps.text = "FPS: #{(get :fps).round(3)}" end diff --git a/test/text_spec.rb b/test/text_spec.rb index 1dc6189..ad12cbf 100644 --- a/test/text_spec.rb +++ b/test/text_spec.rb @@ -1,14 +1,14 @@ require 'ruby2d' RSpec.describe Ruby2D::Text do - + describe '#text=' do it 'maps Time to string' do t = Text.new(0, 0, Time.now, 40, "test/media/bitstream_vera/vera.ttf") t.text = Time.new(1, 1, 1, 1, 1, 1, 1) expect(t.text).to eq "0001-01-01 01:01:01 +0000" end - + it 'maps Number to string' do t = Text.new(0, 0, 0, 40, "test/media/bitstream_vera/vera.ttf") t.text = 0 |
