ruby2d 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ruby2d +1 -8
- data/ext/ruby2d/extconf.rb +2 -7
- data/ext/ruby2d/ruby2d.c +26 -0
- data/lib/ruby2d.rb +2 -1
- data/lib/ruby2d/colorize.rb +10 -0
- data/lib/ruby2d/font.rb +3 -3
- data/lib/ruby2d/image.rb +2 -2
- data/lib/ruby2d/music.rb +16 -0
- data/lib/ruby2d/sprite.rb +22 -13
- data/lib/ruby2d/text.rb +2 -19
- data/lib/ruby2d/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: befe5ad5a05dfdab4e9da310b4a016b138692dbd372f68b0fb9e5fa2c8836e78
|
4
|
+
data.tar.gz: 89523d76e354169eff325ea485b3afde30b085a1a9431d9b6135ef90eadee53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e47726fb332a184bc026898f5b50d67f7463f0cc57350a37200e71f74d35e66902aaae6c61704a8ef467de461f7c8335c59feb890dcd319de2ac000ddfa265a
|
7
|
+
data.tar.gz: eb887567fc2c23d9ea7d10c12b79b6392f1e572da82d2fdc0e1bb791298de33b5a1c942c125965b3cf002d6bffdbb1dd0f150023919b300503aaf577e0dbbbc1
|
data/bin/ruby2d
CHANGED
@@ -1,15 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'ruby2d/colorize'
|
2
3
|
require 'ruby2d/version'
|
3
4
|
require 'fileutils'
|
4
5
|
|
5
|
-
# Extending `String` to include some fancy colors
|
6
|
-
class String
|
7
|
-
def colorize(c); "\e[#{c}m#{self}\e[0m" end
|
8
|
-
def bold; colorize('1') end
|
9
|
-
def warn; colorize('1;33') end
|
10
|
-
def error; colorize('1;31') end
|
11
|
-
end
|
12
|
-
|
13
6
|
# The installed gem directory
|
14
7
|
@gem_dir = "#{Gem::Specification.find_by_name('ruby2d').gem_dir}"
|
15
8
|
|
data/ext/ruby2d/extconf.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'mkmf'
|
2
|
+
require_relative '../../lib/ruby2d/colorize'
|
2
3
|
|
3
4
|
S2D_VERSION = '1.0.1' # Simple 2D minimum version required
|
4
5
|
$errors = []
|
5
6
|
|
6
|
-
class String
|
7
|
-
def colorize(c); "\e[#{c}m#{self}\e[0m" end
|
8
|
-
def bold; colorize('1') end
|
9
|
-
def red; colorize('1;31') end
|
10
|
-
end
|
11
|
-
|
12
7
|
def print_errors
|
13
8
|
puts "
|
14
|
-
#{"== #{"Ruby 2D Installation Errors".
|
9
|
+
#{"== #{"Ruby 2D Installation Errors".error} =======================================\n"}
|
15
10
|
#{$errors.join("\n ")}\n
|
16
11
|
#{"======================================================================="}"
|
17
12
|
end
|
data/ext/ruby2d/ruby2d.c
CHANGED
@@ -65,6 +65,7 @@
|
|
65
65
|
#define r_define_module(name) mrb_define_module(mrb, name)
|
66
66
|
#define r_define_class(module, name) mrb_define_class_under(mrb, module, name, mrb->object_class)
|
67
67
|
#define r_define_method(class, name, function, args) mrb_define_method(mrb, class, name, function, args)
|
68
|
+
#define r_define_class_method(class, name, function, args) mrb_define_class_method(mrb, class, name, function, args)
|
68
69
|
#define r_args_none (MRB_ARGS_NONE())
|
69
70
|
#define r_args_req(n) MRB_ARGS_REQ(n)
|
70
71
|
// Helpers
|
@@ -87,6 +88,7 @@
|
|
87
88
|
#define r_define_module(name) rb_define_module(name)
|
88
89
|
#define r_define_class(module, name) rb_define_class_under(module, name, rb_cObject)
|
89
90
|
#define r_define_method(class, name, function, args) rb_define_method(class, name, function, args)
|
91
|
+
#define r_define_class_method(class, name, function, args) rb_define_singleton_method(class, name, function, args)
|
90
92
|
#define r_args_none 0
|
91
93
|
#define r_args_req(n) n
|
92
94
|
// Helpers
|
@@ -466,6 +468,12 @@ static R_VAL ruby2d_text_ext_init(R_VAL self) {
|
|
466
468
|
#endif
|
467
469
|
S2D_Log(S2D_INFO, "Init text: %s", RSTRING_PTR(r_iv_get(self, "@text")));
|
468
470
|
|
471
|
+
// Trim the font file string to its actual length on MRuby
|
472
|
+
#if MRUBY
|
473
|
+
mrb_value s = r_iv_get(self, "@font");
|
474
|
+
mrb_str_resize(mrb, s, RSTRING_LEN(s));
|
475
|
+
#endif
|
476
|
+
|
469
477
|
S2D_Text *txt = S2D_CreateText(
|
470
478
|
RSTRING_PTR(r_iv_get(self, "@font")),
|
471
479
|
RSTRING_PTR(r_iv_get(self, "@text")),
|
@@ -663,6 +671,21 @@ static R_VAL ruby2d_music_ext_stop(R_VAL self) {
|
|
663
671
|
}
|
664
672
|
|
665
673
|
|
674
|
+
/*
|
675
|
+
* Ruby2D::Music#ext_volume
|
676
|
+
*/
|
677
|
+
#if MRUBY
|
678
|
+
static R_VAL ruby2d_music_ext_volume(mrb_state* mrb, R_VAL self) {
|
679
|
+
mrb_value vol;
|
680
|
+
mrb_get_args(mrb, "o", &vol);
|
681
|
+
#else
|
682
|
+
static R_VAL ruby2d_music_ext_volume(R_VAL self, R_VAL vol) {
|
683
|
+
#endif
|
684
|
+
int mix_vol = NUM2INT(vol) == -1 ? -1 : MIX_MAX_VOLUME * NUM2INT(vol) / 100.0;
|
685
|
+
return INT2NUM(ceil(Mix_VolumeMusic(mix_vol) * 100.0 / MIX_MAX_VOLUME));
|
686
|
+
}
|
687
|
+
|
688
|
+
|
666
689
|
/*
|
667
690
|
* Ruby2D::Music#ext_fadeout
|
668
691
|
*/
|
@@ -1127,6 +1150,9 @@ void Init_ruby2d() {
|
|
1127
1150
|
// Ruby2D::Music#ext_stop
|
1128
1151
|
r_define_method(ruby2d_music_class, "ext_stop", ruby2d_music_ext_stop, r_args_none);
|
1129
1152
|
|
1153
|
+
// Ruby2D::Music#self.ext_volume
|
1154
|
+
r_define_class_method(ruby2d_music_class, "ext_volume", ruby2d_music_ext_volume, r_args_req(1));
|
1155
|
+
|
1130
1156
|
// Ruby2D::Music#ext_fadeout
|
1131
1157
|
r_define_method(ruby2d_music_class, "ext_fadeout", ruby2d_music_ext_fadeout, r_args_req(1));
|
1132
1158
|
|
data/lib/ruby2d.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
# String#colorize
|
2
|
+
|
3
|
+
# Extend `String` to include some fancy colors
|
4
|
+
class String
|
5
|
+
def colorize(c); "\e[#{c}m#{self}\e[0m" end
|
6
|
+
def bold; colorize('1') end
|
7
|
+
def info; colorize('1;34') end
|
8
|
+
def warn; colorize('1;33') end
|
9
|
+
def error; colorize('1;31') end
|
10
|
+
end
|
data/lib/ruby2d/font.rb
CHANGED
@@ -40,11 +40,11 @@ module Ruby2D
|
|
40
40
|
# Get the fonts directory for the current platform
|
41
41
|
def directory
|
42
42
|
if `uname`.include? 'Darwin' # macOS
|
43
|
-
|
43
|
+
'/Library/Fonts'
|
44
44
|
elsif `uname`.include? 'Linux'
|
45
|
-
|
45
|
+
'/usr/share/fonts'
|
46
46
|
elsif `uname`.include? 'MINGW'
|
47
|
-
|
47
|
+
'C:/Windows/Fonts'
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
data/lib/ruby2d/image.rb
CHANGED
@@ -7,8 +7,8 @@ module Ruby2D
|
|
7
7
|
attr_reader :path, :color
|
8
8
|
attr_accessor :x, :y, :width, :height, :rotate, :data
|
9
9
|
|
10
|
-
def initialize(opts = {})
|
11
|
-
@path =
|
10
|
+
def initialize(path, opts = {})
|
11
|
+
@path = path
|
12
12
|
|
13
13
|
unless RUBY_ENGINE == 'opal'
|
14
14
|
unless File.exists? @path
|
data/lib/ruby2d/music.rb
CHANGED
@@ -39,6 +39,22 @@ module Ruby2D
|
|
39
39
|
ext_stop
|
40
40
|
end
|
41
41
|
|
42
|
+
# Returns the previous volume setting, in percentage
|
43
|
+
def self.volume
|
44
|
+
self.ext_volume(-1)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set music volume, 0 to 100%
|
48
|
+
def self.volume=(v)
|
49
|
+
# If a negative value, volume will be 0
|
50
|
+
if v < 0 then v = 0 end
|
51
|
+
self.ext_volume(v)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Alias instance methods to class methods
|
55
|
+
def volume; Music.volume end
|
56
|
+
def volume=(v); Music.volume=(v) end
|
57
|
+
|
42
58
|
# Fade out music over provided milliseconds
|
43
59
|
def fadeout(ms)
|
44
60
|
ext_fadeout(ms)
|
data/lib/ruby2d/sprite.rb
CHANGED
@@ -4,7 +4,7 @@ module Ruby2D
|
|
4
4
|
class Sprite
|
5
5
|
include Renderable
|
6
6
|
|
7
|
-
attr_reader
|
7
|
+
attr_reader :x, :y, :width, :height
|
8
8
|
attr_accessor :rotate, :loop, :clip_x, :clip_y, :clip_width, :clip_height, :data
|
9
9
|
|
10
10
|
def initialize(path, opts = {})
|
@@ -78,7 +78,7 @@ module Ruby2D
|
|
78
78
|
# Set the x coordinate
|
79
79
|
def x=(x)
|
80
80
|
@x = @flip_x = x
|
81
|
-
if @flip == :
|
81
|
+
if @flip == :horizontal || @flip == :both
|
82
82
|
@flip_x = x + @width
|
83
83
|
end
|
84
84
|
end
|
@@ -86,7 +86,7 @@ module Ruby2D
|
|
86
86
|
# Set the y coordinate
|
87
87
|
def y=(y)
|
88
88
|
@y = @flip_y = y
|
89
|
-
if @flip == :
|
89
|
+
if @flip == :vertical || @flip == :both
|
90
90
|
@flip_y = y + @height
|
91
91
|
end
|
92
92
|
end
|
@@ -94,7 +94,7 @@ module Ruby2D
|
|
94
94
|
# Set the width
|
95
95
|
def width=(width)
|
96
96
|
@width = @flip_width = width
|
97
|
-
if @flip == :
|
97
|
+
if @flip == :horizontal || @flip == :both
|
98
98
|
@flip_width = -width
|
99
99
|
end
|
100
100
|
end
|
@@ -102,13 +102,18 @@ module Ruby2D
|
|
102
102
|
# Set the height
|
103
103
|
def height=(height)
|
104
104
|
@height = @flip_height = height
|
105
|
-
if @flip == :
|
105
|
+
if @flip == :vertical || @flip == :both
|
106
106
|
@flip_height = -height
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
# Play an animation
|
111
|
-
def play(
|
111
|
+
def play(opts = {}, &done_proc)
|
112
|
+
|
113
|
+
animation = opts[:animation]
|
114
|
+
loop = opts[:loop]
|
115
|
+
flip = opts[:flip]
|
116
|
+
|
112
117
|
if !@playing || (animation != @playing_animation && animation != nil) || flip != @flip
|
113
118
|
|
114
119
|
@playing = true
|
@@ -127,11 +132,11 @@ module Ruby2D
|
|
127
132
|
when Array
|
128
133
|
@first_frame = 0
|
129
134
|
@current_frame = 0
|
130
|
-
@last_frame
|
135
|
+
@last_frame = frames.length - 1
|
131
136
|
end
|
132
137
|
|
133
138
|
# Set looping
|
134
|
-
@loop = loop ==
|
139
|
+
@loop = loop == true || @defaults[:loop] ? true : false
|
135
140
|
|
136
141
|
set_frame
|
137
142
|
restart_time
|
@@ -151,8 +156,12 @@ module Ruby2D
|
|
151
156
|
# Flip the sprite
|
152
157
|
def flip_sprite(flip)
|
153
158
|
|
154
|
-
#
|
155
|
-
|
159
|
+
# The sprite width and height must be set for it to be flipped correctly
|
160
|
+
if (!@width || !@height) && flip
|
161
|
+
raise Error,
|
162
|
+
"Sprite width and height must be set in order to flip; " +
|
163
|
+
"occured playing animation `:#{@playing_animation}` with image `#{@path}`"
|
164
|
+
end
|
156
165
|
|
157
166
|
@flip = flip
|
158
167
|
|
@@ -163,13 +172,13 @@ module Ruby2D
|
|
163
172
|
@flip_height = @height
|
164
173
|
|
165
174
|
case flip
|
166
|
-
when :
|
175
|
+
when :horizontal
|
167
176
|
@flip_x = @x + @width
|
168
177
|
@flip_width = -@width
|
169
|
-
when :
|
178
|
+
when :vertical
|
170
179
|
@flip_y = @y + @height
|
171
180
|
@flip_height = -@height
|
172
|
-
when :
|
181
|
+
when :both # horizontal and vertical
|
173
182
|
@flip_x = @x + @width
|
174
183
|
@flip_width = -@width
|
175
184
|
@flip_y = @y + @height
|
data/lib/ruby2d/text.rb
CHANGED
@@ -7,11 +7,11 @@ module Ruby2D
|
|
7
7
|
attr_reader :text, :size, :width, :height, :font, :color
|
8
8
|
attr_accessor :x, :y, :rotate, :data
|
9
9
|
|
10
|
-
def initialize(opts = {})
|
10
|
+
def initialize(text, opts = {})
|
11
11
|
@x = opts[:x] || 0
|
12
12
|
@y = opts[:y] || 0
|
13
13
|
@z = opts[:z] || 0
|
14
|
-
@text =
|
14
|
+
@text = text.to_s
|
15
15
|
@size = opts[:size] || 20
|
16
16
|
@rotate = opts[:rotate] || 0
|
17
17
|
@font = opts[:font] || Font.default
|
@@ -40,22 +40,5 @@ module Ruby2D
|
|
40
40
|
@x < x and @x + @width > x and @y < y and @y + @height > y
|
41
41
|
end
|
42
42
|
|
43
|
-
private
|
44
|
-
|
45
|
-
def resolve_path(font)
|
46
|
-
if RUBY_PLATFORM =~ /darwin/
|
47
|
-
font_path = "/Library/Fonts/#{font}.ttf"
|
48
|
-
else
|
49
|
-
# Linux
|
50
|
-
font_path = "/usr/share/fonts/truetype/#{font}.ttf"
|
51
|
-
end
|
52
|
-
|
53
|
-
unless File.exists? font_path
|
54
|
-
raise Error, "Cannot find system font"
|
55
|
-
else
|
56
|
-
font_path
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
43
|
end
|
61
44
|
end
|
data/lib/ruby2d/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Black
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/ruby2d.rb
|
154
154
|
- lib/ruby2d/circle.rb
|
155
155
|
- lib/ruby2d/color.rb
|
156
|
+
- lib/ruby2d/colorize.rb
|
156
157
|
- lib/ruby2d/dsl.rb
|
157
158
|
- lib/ruby2d/exceptions.rb
|
158
159
|
- lib/ruby2d/font.rb
|