hasu 0.1.1 → 0.1.2

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: a45d0dbe556192cdd7439d67b88b687a6169161b
4
- data.tar.gz: 6f286b979b972a9f4329892d0f0e31280749894f
3
+ metadata.gz: 89e96997e9e719db654653cd173a498b3305b4da
4
+ data.tar.gz: 4e0929abf8fca155cf9c5df2f67bda0b938e66bd
5
5
  SHA512:
6
- metadata.gz: d22f2e8e1f42f3dc0cca7f44bb42d125b8519e8a3518ac1bf7be26888d1c1b277a1888133e62ba2a369f899f58809b82d684317db5bcd8eabcb2f70afb1b062d
7
- data.tar.gz: f0b3fe40df87ac9840e4a7ed5b6a5d111ca14c52542f45adb199915f4d7b8bc0f51bd864b5463937048e5d78875207a15fdbf83bb2b5ae6ff6dd520f4fb17e68
6
+ metadata.gz: 2d9b059732fc224e354955f7185add04fa1b0777a0dc5237faff70d510fd67f0498236e176454909d65da7485dfc488c68e3a6f48e24b1ff76609ff9ecefc2e7
7
+ data.tar.gz: 5f2b5f95aa172a674ff0fc33dcd52be08e012e6afb9ef9ff68e27c3b193565c5ce6897215b8b5423f90f860a81724f27742beb7bf2af451b039c1dcf3d29646e
@@ -0,0 +1,55 @@
1
+ module Hasu
2
+ module Guard
3
+ def update(*)
4
+ if Hasu.reload!
5
+ Hasu.error = nil
6
+ end
7
+ unless Hasu.error
8
+ super
9
+ end
10
+ rescue => e
11
+ Hasu.error = e
12
+ end
13
+
14
+ def reset
15
+ super if defined?(super)
16
+ Hasu.error = nil
17
+ rescue => e
18
+ Hasu.error = e
19
+ end
20
+
21
+ def draw(*)
22
+ if Hasu.error
23
+ ([Hasu.error.inspect] + Hasu.error.backtrace).each_with_index do |line, i|
24
+ _hasu_font.draw(line.gsub("\n",''), 10, 10 + i * 16, 0)
25
+ end
26
+ else
27
+ begin
28
+ super
29
+ rescue => e
30
+ Hasu.error = e
31
+ draw
32
+ end
33
+ end
34
+ end
35
+
36
+ def _hasu_font
37
+ @_hasu_font ||= Gosu::Font.new(self, Gosu::default_font_name, 16)
38
+ end
39
+
40
+ def button_down(id)
41
+ case id
42
+ when Gosu::KbEscape
43
+ close
44
+ when Gosu::Window.char_to_button_id('r')
45
+ reset
46
+ else
47
+ begin
48
+ super(id)
49
+ rescue => e
50
+ Hasu.error = e
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Hasu
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,71 +1,27 @@
1
1
  require "gosu"
2
-
3
- class Hasu::Window < Gosu::Window
4
- def self.inherited(other)
5
- includer = caller.first.split(":").first
6
- Hasu.reloads[includer] = File.mtime(includer)
7
- end
8
-
9
- def self.run
10
- unless @running
11
- @running = true
12
- new.show
2
+ require "hasu/guard"
3
+
4
+ module Hasu
5
+ class Window < Gosu::Window
6
+ def self.inherited(other)
7
+ includer = caller.first.split(":").first
8
+ Hasu.reloads[includer] = File.mtime(includer)
9
+ if other.respond_to?(:prepend, true)
10
+ other.send(:prepend, Hasu::Guard)
11
+ else
12
+ warn "Most of Hasu's nifty features (e.g. error catching, file reloading) are only available on Ruby >= 2.0."
13
+ end
13
14
  end
14
- end
15
15
 
16
- def initialize(*)
17
- super
18
- reset
19
- end
20
-
21
- def update(*)
22
- if Hasu.reload!
23
- Hasu.error = nil
24
- end
25
- unless Hasu.error
16
+ def initialize(*)
26
17
  super
18
+ reset
27
19
  end
28
- rescue => e
29
- Hasu.error = e
30
- end
31
-
32
- def reset
33
- super if defined?(super)
34
- Hasu.error = nil
35
- rescue => e
36
- Hasu.error = e
37
- end
38
-
39
- def draw(*)
40
- if Hasu.error
41
- ([Hasu.error.inspect] + Hasu.error.backtrace).each_with_index do |line, i|
42
- _hasu_font.draw(line.gsub("\n",''), 10, 10 + i * 16, 0)
43
- end
44
- else
45
- begin
46
- super
47
- rescue => e
48
- Hasu.error = e
49
- draw
50
- end
51
- end
52
- end
53
20
 
54
- def _hasu_font
55
- @_hasu_font ||= Gosu::Font.new(self, Gosu::default_font_name, 16)
56
- end
57
-
58
- def button_down(id)
59
- case id
60
- when Gosu::KbEscape
61
- close
62
- when Gosu::Window.char_to_button_id('r')
63
- reset
64
- else
65
- begin
66
- super(id)
67
- rescue => e
68
- Hasu.error = e
21
+ def self.run
22
+ unless @running
23
+ @running = true
24
+ new.show
69
25
  end
70
26
  end
71
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hasu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Fairley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-13 00:00:00.000000000 Z
11
+ date: 2013-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -68,6 +68,7 @@ files:
68
68
  - example/rect.rb
69
69
  - hasu.gemspec
70
70
  - lib/hasu.rb
71
+ - lib/hasu/guard.rb
71
72
  - lib/hasu/version.rb
72
73
  - lib/hasu/window.rb
73
74
  homepage: https://github.com/michaelfairley/hasu