hasu 0.1.1 → 0.1.6

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
- SHA1:
3
- metadata.gz: a45d0dbe556192cdd7439d67b88b687a6169161b
4
- data.tar.gz: 6f286b979b972a9f4329892d0f0e31280749894f
2
+ SHA256:
3
+ metadata.gz: 8583e858bca02a15e8c5c5f4f61c929f0cc8de1df248df46c0c0188920d5e34c
4
+ data.tar.gz: 30c6cc0b25dcdd2c80108ab5c02dfb0b56d6a2f0fe5258eb06e414ddcd2af2e8
5
5
  SHA512:
6
- metadata.gz: d22f2e8e1f42f3dc0cca7f44bb42d125b8519e8a3518ac1bf7be26888d1c1b277a1888133e62ba2a369f899f58809b82d684317db5bcd8eabcb2f70afb1b062d
7
- data.tar.gz: f0b3fe40df87ac9840e4a7ed5b6a5d111ca14c52542f45adb199915f4d7b8bc0f51bd864b5463937048e5d78875207a15fdbf83bb2b5ae6ff6dd520f4fb17e68
6
+ metadata.gz: 3c6aa1c076649850a2bf7806274b2513abea42e8876cde7cdc5c256b90ab8faaacbfffdf7bc2bd6e0e6d7bd1c029aa6a11c26a95ebfb84275152f516464bbed9
7
+ data.tar.gz: '009c6cfd365db7a2842d2e60c8b219312523f886fb96dd2e8b059e199504690ec4900b5b1c1fdad24d12f2f4510f65a33fd92526fbeacaf7d01bbee234c5fc65'
data/README.md CHANGED
@@ -1 +1,94 @@
1
- Makes iterating with Gosu more better.
1
+ # Hasu
2
+
3
+ Helps you develop [Gosu](http://www.libgosu.org/) games more quickly.
4
+
5
+ ## How?
6
+
7
+ ### Hot code loading
8
+
9
+ Normally, when you change the code for a Gosu game, you have to close and restart the game for the code to take affect.
10
+ With Hasu, modified source files will be reloaded each time through the game loop.
11
+
12
+ ### Exception catching
13
+
14
+ When an exception bubbles up out of your game loop, Gosu will crash.
15
+ When an exception occurs in a Hasu game, Hasu pauses your game, prints the exception details into your window, and resumes your game once the code that fixes it is loaded.
16
+
17
+ ### Reset
18
+
19
+ Hot code loading unfortunately is worthless for your `initialize` method since your window will only be initialized once,
20
+ Instead of putting your game's setup code in `initialize`, place it in `reset` and press R whenever you want to re-initialize your game state.
21
+
22
+ ## Using Hasu
23
+
24
+ __The above features only work on Ruby 2+, though Hasu will still load on earlier versions (in case you want to pack up your game with Releasy).__
25
+
26
+ ### 0: Install Hasu
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ gem hasu
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install hasu
35
+
36
+ ### 1: Subclass `Hasu::Window` (or prepend `Hasu::Guard`).
37
+
38
+ Instead of subclassing `Gosu::Window`, use `Hasu::Window`:
39
+
40
+ ```ruby
41
+ class Game < Hasu::Window
42
+ def initialize
43
+ super(640, 480, false)
44
+ end
45
+
46
+ def reset
47
+ # ...
48
+ end
49
+
50
+ def update
51
+ # ...
52
+ end
53
+
54
+ def draw
55
+ # ...
56
+ end
57
+ end
58
+ ```
59
+
60
+ If you're using Chingu (or another library which has its own window subclass), you can prepend `Hasu::Guard` onto your window for the same effect:
61
+
62
+ ```ruby
63
+ class Game < Chingu::Window
64
+ prepend Hasu::Guard
65
+
66
+ def initialize
67
+ super(640, 480, false)
68
+ end
69
+
70
+ def reset
71
+ # ...
72
+ end
73
+
74
+ def update
75
+ # ...
76
+ end
77
+
78
+ def draw
79
+ # ...
80
+ end
81
+ end
82
+ ```
83
+
84
+ ### 2: Use `Hasu.load` to require your game's files.
85
+
86
+ For the files you want to be hot loaded, use `Hasu.load` instead of `require`.
87
+
88
+ ```ruby
89
+ Hasu.load "ball.rb"
90
+ ```
91
+
92
+ ### 3: Run your game with `.run`
93
+
94
+ Instead of `Game.new.show`, run your Hasu game with `Game.run`.
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "hasu", :path => "../../"
4
+ gem "chingu"
@@ -0,0 +1,30 @@
1
+ class Ball < Chingu::GameObject
2
+ SIZE = 20
3
+
4
+ def initialize(*)
5
+ super
6
+
7
+ @x = 320
8
+ @y = 240
9
+
10
+ @dx = rand * 10
11
+ @dy = rand * 10
12
+ end
13
+
14
+ def update
15
+ @x += @dx
16
+ if @x < 0 || @x > 640
17
+ @dx *= -1
18
+ end
19
+
20
+ @y += @dy
21
+ if @y < 0 || @y > 480
22
+ @dy *= -1
23
+ end
24
+ end
25
+
26
+ def draw
27
+ rect = Chingu::Rect.new(@x - SIZE/2, @y - SIZE/2, SIZE, SIZE)
28
+ $window.draw_rect(rect, Gosu::Color::RED, 0)
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require "chingu"
2
+ require "hasu"
3
+
4
+ Hasu.load "ball.rb"
5
+
6
+ class Game < Chingu::Window
7
+ prepend Hasu::Guard
8
+
9
+ def initialize
10
+ super(640, 480, false)
11
+ reset
12
+ end
13
+
14
+ def reset
15
+ Ball.create
16
+ Ball.create
17
+ end
18
+ end
19
+
20
+ Game.new.show
File without changes
File without changes
@@ -0,0 +1,52 @@
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_text(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
+ if id == Gosu::KbR
42
+ reset
43
+ else
44
+ begin
45
+ super(id)
46
+ rescue => e
47
+ Hasu.error = e
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module Hasu
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
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 unless Hasu.error
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
-
54
- def _hasu_font
55
- @_hasu_font ||= Gosu::Font.new(self, Gosu::default_font_name, 16)
56
- end
57
20
 
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(*args)
22
+ unless @running
23
+ @running = true
24
+ new(*args).show
69
25
  end
70
26
  end
71
27
  end
data/todo ADDED
@@ -0,0 +1,4 @@
1
+ guard "macro"
2
+ dead code removal
3
+ autoload?
4
+ constant reloading?
metadata CHANGED
@@ -1,55 +1,55 @@
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.6
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: 2020-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Prototype Gosu games with ease
@@ -59,17 +59,22 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
- - example/example.rb
68
- - example/rect.rb
67
+ - examples/chingu/Gemfile
68
+ - examples/chingu/ball.rb
69
+ - examples/chingu/game.rb
70
+ - examples/gosu/example.rb
71
+ - examples/gosu/rect.rb
69
72
  - hasu.gemspec
70
73
  - lib/hasu.rb
74
+ - lib/hasu/guard.rb
71
75
  - lib/hasu/version.rb
72
76
  - lib/hasu/window.rb
77
+ - todo
73
78
  homepage: https://github.com/michaelfairley/hasu
74
79
  licenses:
75
80
  - MIT
@@ -80,17 +85,16 @@ require_paths:
80
85
  - lib
81
86
  required_ruby_version: !ruby/object:Gem::Requirement
82
87
  requirements:
83
- - - '>='
88
+ - - ">="
84
89
  - !ruby/object:Gem::Version
85
90
  version: '0'
86
91
  required_rubygems_version: !ruby/object:Gem::Requirement
87
92
  requirements:
88
- - - '>='
93
+ - - ">="
89
94
  - !ruby/object:Gem::Version
90
95
  version: '0'
91
96
  requirements: []
92
- rubyforge_project:
93
- rubygems_version: 2.0.3
97
+ rubygems_version: 3.0.1
94
98
  signing_key:
95
99
  specification_version: 4
96
100
  summary: Prototype Gosu games with ease