hasu 0.1.2 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 89e96997e9e719db654653cd173a498b3305b4da
4
- data.tar.gz: 4e0929abf8fca155cf9c5df2f67bda0b938e66bd
2
+ SHA256:
3
+ metadata.gz: 2626ba7b3bce85ad0d28a0e03c030f467ac125645433ec73ccfe33bc8e810aff
4
+ data.tar.gz: 29d5261508848eb357dea64142f8cefee1b025225edaa4c060686f71f45bf504
5
5
  SHA512:
6
- metadata.gz: 2d9b059732fc224e354955f7185add04fa1b0777a0dc5237faff70d510fd67f0498236e176454909d65da7485dfc488c68e3a6f48e24b1ff76609ff9ecefc2e7
7
- data.tar.gz: 5f2b5f95aa172a674ff0fc33dcd52be08e012e6afb9ef9ff68e27c3b193565c5ce6897215b8b5423f90f860a81724f27742beb7bf2af451b039c1dcf3d29646e
6
+ metadata.gz: 0f308311c2206f5903322c3e1f161d0519c73579b8b46a5f227bce19ac1477fc8d4bb5136e1297118c63f260abe405931707db234a18e0b1e5af12ed6a19745b
7
+ data.tar.gz: fb627249f8ac7386b4f843d3fcce21779c3f238f9043e29f5a636bf2ea5c93179357db6a8c16eb40a7e96be08bb9f32d1f862456cdccb7b37e4ebf9c97600005
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
data/lib/hasu.rb CHANGED
@@ -7,7 +7,7 @@ module Hasu
7
7
  end
8
8
 
9
9
  def self.load(path)
10
- reloads[path] = File.exists?(path) ? File.mtime(path) : Time.now
10
+ reloads[path] = File.exist?(path) ? File.mtime(path) : Time.now
11
11
  begin
12
12
  super
13
13
  true
@@ -31,7 +31,7 @@ module Hasu
31
31
  end
32
32
 
33
33
  def self.reload!
34
- to_reload = reloads.select{|f,t| File.exists?(f) && File.mtime(f) > t}
34
+ to_reload = reloads.select{|f,t| File.exist?(f) && File.mtime(f) > t}
35
35
 
36
36
  !to_reload.empty? && to_reload.all? do |file,_|
37
37
  puts "Reloading #{file}"
data/lib/hasu/guard.rb CHANGED
@@ -21,7 +21,7 @@ module Hasu
21
21
  def draw(*)
22
22
  if Hasu.error
23
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)
24
+ _hasu_font.draw_text(line.gsub("\n",''), 10, 10 + i * 16, 0)
25
25
  end
26
26
  else
27
27
  begin
@@ -38,10 +38,7 @@ module Hasu
38
38
  end
39
39
 
40
40
  def button_down(id)
41
- case id
42
- when Gosu::KbEscape
43
- close
44
- when Gosu::Window.char_to_button_id('r')
41
+ if id == Gosu::KbR
45
42
  reset
46
43
  else
47
44
  begin
data/lib/hasu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hasu
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/hasu/window.rb CHANGED
@@ -15,13 +15,13 @@ module Hasu
15
15
 
16
16
  def initialize(*)
17
17
  super
18
- reset
18
+ reset unless Hasu.error
19
19
  end
20
20
 
21
- def self.run
21
+ def self.run(*args)
22
22
  unless @running
23
23
  @running = true
24
- new.show
24
+ new(*args).show
25
25
  end
26
26
  end
27
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.2
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Fairley
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-14 00:00:00.000000000 Z
11
+ date: 2021-02-22 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,40 +59,43 @@ 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
71
74
  - lib/hasu/guard.rb
72
75
  - lib/hasu/version.rb
73
76
  - lib/hasu/window.rb
77
+ - todo
74
78
  homepage: https://github.com/michaelfairley/hasu
75
79
  licenses:
76
80
  - MIT
77
81
  metadata: {}
78
- post_install_message:
82
+ post_install_message:
79
83
  rdoc_options: []
80
84
  require_paths:
81
85
  - lib
82
86
  required_ruby_version: !ruby/object:Gem::Requirement
83
87
  requirements:
84
- - - '>='
88
+ - - ">="
85
89
  - !ruby/object:Gem::Version
86
90
  version: '0'
87
91
  required_rubygems_version: !ruby/object:Gem::Requirement
88
92
  requirements:
89
- - - '>='
93
+ - - ">="
90
94
  - !ruby/object:Gem::Version
91
95
  version: '0'
92
96
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.0.3
95
- signing_key:
97
+ rubygems_version: 3.2.3
98
+ signing_key:
96
99
  specification_version: 4
97
100
  summary: Prototype Gosu games with ease
98
101
  test_files: []