ruby2d 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b065d85656f0f67ae270a815252551c10985caf1
4
- data.tar.gz: 6ed2d44d184eb36daabd4711e4ef7c74729d693c
3
+ metadata.gz: 52638279e5a91e2a8143e0a9485e0889d784757a
4
+ data.tar.gz: e3ed2e07e45e3a7ba53a7a8dae3ab625be09a444
5
5
  SHA512:
6
- metadata.gz: 29b0dff61f4a04bbb2bed6904a5c2c10aa6e1cf43e8114f0fecae6d77b19700ee430b087dec6e193cc6dd4210d5d11379a72ee9bde8b1b52d2ef4102f1a66153
7
- data.tar.gz: c08fda4f13944a3a3e8709a405f7c6f884596dc63d1be90d096614391468491b4b9d3a0d00aeb2d5617f9d3026d87f9dba382fc89cc99309ee4df94c6f90016b
6
+ metadata.gz: 00cf4e903c49e0cc3889a6cd8f6452d99773ba8b8af74c3d6d150c17bf552045745a96b0a477a1330c682f7bd3f9ce5c3bff7f179b0068f081a88f9a8a7d1fd9
7
+ data.tar.gz: f07cbe0a69a6c75209c24e1f4f514aa4d994ca678d3ac2371aae7fcfda08ebb529c4684abc55f85c9ea47d02c3b60043e787db08b3cc70138de79e50236cb169
@@ -1,84 +1,83 @@
1
1
  require 'mkmf'
2
2
 
3
+ S2D_VERSION = '0.2.1' # Minimum Simple 2D version required
4
+ $errors = []
5
+
3
6
  class String
4
7
  def colorize(c); "\e[#{c}m#{self}\e[0m" end
5
- def error; colorize('1;31') end
6
- def bold; colorize('1') end
8
+ def bold; colorize('1') end
9
+ def red; colorize('1;31') end
7
10
  end
8
11
 
9
- def print_errors(errors)
12
+ def print_errors
10
13
  puts "
11
- #{"== Ruby 2D Installation Errors =============================".bold}
12
-
13
- #{"Ruby 2D found some problems and was not installed:".error}
14
-
15
- #{errors.join("\n ")}
16
-
17
- #{"============================================================".bold}"
14
+ #{"== #{"Ruby 2D Installation Errors".red} =====================================\n"}
15
+ #{$errors.join("\n ")}\n
16
+ #{"===================================================================="}"
17
+ end
18
+
19
+ def check_s2d_version
20
+ unless Gem::Version.new(`simple2d --version`) >= Gem::Version.new(S2D_VERSION)
21
+ $errors << "Simple 2D needs to be updated for this version of Ruby 2D." <<
22
+ "Run the following, then try reinstalling this gem:\n" <<
23
+ " simple2d update".bold
24
+ print_errors
25
+ exit
26
+ end
18
27
  end
19
28
 
20
- errors = []
21
29
 
22
30
  # Install Simple 2D on supported platforms
23
31
 
24
32
  # OS X
25
33
  if RUBY_PLATFORM =~ /darwin/
26
- unless ARGV.include? "--no-brew"
27
- # Simple 2D not installed
28
- if `which simple2d`.empty?
29
- # Homebrew not installed, print and quit
30
- if `which brew`.empty?
31
- errors << "Ruby 2D uses a library called Simple 2D." <<
32
- "On OS X, this can be installed using Homebrew." <<
33
- "Install Homebrew, then try installing this gem again.\n" <<
34
- "Learn more at http://brew.sh"
35
- print_errors(errors)
36
- exit
37
- # Install Simple 2D using Homebrew
38
- else
39
- `brew tap simple2d/tap`
40
- `brew install simple2d`
41
- end
34
+
35
+ # Simple 2D not installed
36
+ if `which simple2d`.empty?
37
+
38
+ # Homebrew not installed
39
+ if `which brew`.empty?
40
+ $errors << "Ruby 2D uses a native library called Simple 2D." <<
41
+ "On OS X, this can be installed using Homebrew.\n" <<
42
+ "First, install #{"Homebrew".bold}. See instructions at #{"http://brew.sh".bold}" <<
43
+ "Then, run the following:\n" <<
44
+ " brew tap simple2d/tap".bold <<
45
+ " brew install simple2d".bold
46
+ print_errors
47
+ exit
42
48
 
43
- # Simple 2D installed, update to latest version
49
+ # Homebrew installed, instruct to install Simple 2D
44
50
  else
45
- # Homebrew not installed
46
- if `which brew`.empty?
47
- # TODO: Check for latest version manually and update
48
- # Homebrew installed, get latest version of Simple 2D
49
- else
50
- # An alternative, but slower and updates all formulas:
51
- # `brew update`
52
- # `brew upgrade simple2d`
53
-
54
- `brew untap simple2d/tap`
55
- `brew tap simple2d/tap`
56
- `brew upgrade simple2d`
57
- end
51
+ $errors << "Ruby 2D uses a native library called Simple 2D." <<
52
+ "Install with Homebrew using:\n" <<
53
+ " brew tap simple2d/tap".bold <<
54
+ " brew install simple2d".bold
55
+ print_errors
56
+ exit
58
57
  end
59
58
  end
60
59
 
61
60
  # Linux
62
61
  elsif RUBY_PLATFORM =~ /linux/
63
- # If Simple 2D not installed
62
+
63
+ # Simple 2D not installed
64
64
  if `which simple2d`.empty?
65
- errors << "Ruby 2D uses a library called Simple 2D." <<
66
- "There's a script to make installation easy on Linux.\n" <<
67
- "Follow the instructions in the README to get started:" <<
68
- " https://github.com/simple2d/simple2d"
69
- print_errors(errors)
65
+ $errors << "Ruby 2D uses a native library called Simple 2D.\n" <<
66
+ "To install Simple 2D on Linux, follow the instructions" <<
67
+ "in the README: #{"https://github.com/simple2d/simple2d".bold}"
68
+ print_errors
70
69
  exit
71
70
  end
72
71
 
73
- # Windows
74
- elsif RUBY_PLATFORM =~ /mingw/
75
- puts "Ruby 2D doesn't support Windows yet :("
76
- exit
72
+ $CFLAGS << ' -std=c99'
77
73
  end
78
74
 
75
+ # Simple 2D installed, check version
76
+ check_s2d_version
77
+
79
78
  # Configure Simple 2D and create Makefile
80
79
 
81
80
  $LDFLAGS << ' ' << `simple2d --libs`
82
- $LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they cause problems
81
+ $LDFLAGS.gsub!(/\n/, ' ') # Remove newlines in flags, they cause problems
83
82
 
84
83
  create_makefile('ruby2d/ruby2d')
@@ -11,7 +11,7 @@
11
11
  VALUE self;
12
12
 
13
13
  // Simple 2D window
14
- Window *window;
14
+ S2D_Window *window;
15
15
 
16
16
  // Ruby data types
17
17
  static VALUE ruby2d_module;
@@ -20,13 +20,13 @@ static VALUE c_data_klass;
20
20
 
21
21
  // Structures for Ruby 2D classes
22
22
  struct image_data {
23
- Image img;
23
+ S2D_Image *img;
24
24
  };
25
25
  struct text_data {
26
- Text txt;
26
+ S2D_Text *txt;
27
27
  };
28
28
  struct sound_data {
29
- Sound snd;
29
+ S2D_Sound *snd;
30
30
  };
31
31
 
32
32
 
@@ -215,8 +215,8 @@ void render() {
215
215
  struct image_data *data;
216
216
  Data_Get_Struct(rb_iv_get(el, "@data"), struct image_data, data);
217
217
 
218
- data->img.x = NUM2DBL(rb_iv_get(el, "@x"));
219
- data->img.y = NUM2DBL(rb_iv_get(el, "@y"));
218
+ data->img->x = NUM2DBL(rb_iv_get(el, "@x"));
219
+ data->img->y = NUM2DBL(rb_iv_get(el, "@y"));
220
220
  S2D_DrawImage(data->img);
221
221
  }
222
222
  break;
@@ -234,8 +234,8 @@ void render() {
234
234
  struct text_data *data;
235
235
  Data_Get_Struct(rb_iv_get(el, "@data"), struct text_data, data);
236
236
 
237
- data->txt.x = NUM2DBL(rb_iv_get(el, "@x"));
238
- data->txt.y = NUM2DBL(rb_iv_get(el, "@y"));
237
+ data->txt->x = NUM2DBL(rb_iv_get(el, "@x"));
238
+ data->txt->y = NUM2DBL(rb_iv_get(el, "@y"));
239
239
  S2D_DrawText(data->txt);
240
240
  }
241
241
  break;
@@ -253,9 +253,10 @@ static VALUE ruby2d_show(VALUE s) {
253
253
  char *title = RSTRING_PTR(rb_iv_get(self, "@title"));
254
254
  int width = NUM2INT(rb_iv_get(self, "@width"));
255
255
  int height = NUM2INT(rb_iv_get(self, "@height"));
256
+ int flags = 0;
256
257
 
257
258
  window = S2D_CreateWindow(
258
- title, width, height, update, render, 0
259
+ title, width, height, update, render, flags
259
260
  );
260
261
 
261
262
  window->on_key = on_key;
@@ -5,20 +5,17 @@ module Ruby2D
5
5
 
6
6
  attr_accessor :x, :y, :size, :text
7
7
 
8
- def initialize(x=0, y=0, size=20, text="Hello World!", font="Arial", c="white")
9
- if font.include? '.'
10
- unless File.exists? font
11
- raise Error, "Cannot find font file!"
12
- else
13
- @font = font
14
- end
8
+ def initialize(x=0, y=0, size=20, msg="Hello World!", font="Arial", c="white")
9
+
10
+ if File.exists? font
11
+ @font = font
15
12
  else
16
13
  @font = resolve_path(font)
17
14
  end
18
15
 
19
16
  @type_id = 4
20
17
  @x, @y, @size = x, y, size
21
- @text, @color = text, c
18
+ @text, @color = msg, c
22
19
  update_color(c)
23
20
 
24
21
  if defined? Ruby2D::DSL
@@ -44,14 +41,18 @@ module Ruby2D
44
41
  private
45
42
 
46
43
  def resolve_path(font)
47
- # TODO: Consider CSS names, like 'serif', 'san-serif', 'monospace'
48
44
  if RUBY_PLATFORM =~ /darwin/
49
45
  font_path = "/Library/Fonts/#{font}.ttf"
50
- unless File.exists? font_path
51
- raise Error, "Cannot find system font!"
52
- end
46
+ else
47
+ # Linux
48
+ font_path = "/usr/share/fonts/truetype/#{font}.ttf"
49
+ end
50
+
51
+ unless File.exists? font_path
52
+ raise Error, "Cannot find system font"
53
+ else
54
+ font_path
53
55
  end
54
- font_path
55
56
  end
56
57
 
57
58
  def update_color(c)
@@ -1,5 +1,5 @@
1
1
  # version.rb
2
2
 
3
3
  module Ruby2D
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -38,16 +38,15 @@ module Ruby2D
38
38
  end
39
39
 
40
40
  def set(opts)
41
- if opts.include? :title
42
- @title = opts[:title]
43
- end
44
-
45
- if opts.include? :width
46
- @width = opts[:width]
47
- end
48
-
49
- if opts.include? :height
50
- @height = opts[:height]
41
+ valid_keys = [:title, :width, :height]
42
+ valid_opts = opts.reject { |k| !valid_keys.include?(k) }
43
+ if !valid_opts.empty?
44
+ @title = valid_opts[:title]
45
+ @width = valid_opts[:width]
46
+ @height = valid_opts[:height]
47
+ return true
48
+ else
49
+ return false
51
50
  end
52
51
  end
53
52
 
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Black
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-01 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -70,8 +70,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.5.1
73
+ rubygems_version: 2.6.3
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Ruby 2D
77
77
  test_files: []
78
+ has_rdoc: