gosu_wrapper 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1e3045af1e3059febc285c2b27e425ba519f302
4
+ data.tar.gz: 999b7a748f81020f05959d65aa6f2dbdd97c384f
5
+ SHA512:
6
+ metadata.gz: aa02328c1f134dd6889d6167984731e8fc401ff8cc2d0101676be6ac0f049669f09ba1a61816eb6672e3e3847bca691e177e8b43b978c7c52d2ddcbf3e0f538b
7
+ data.tar.gz: b5f48a1a483744b98dbed7126a440b439085f36b4c05eb915ca3c4157b534469fefae1c8cb4077429720f74165613d10a0e19545148f010738629d455dc9245c
data/bin/gosu_wrapper ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gosu_wrapper'
3
+ class GosuWrapper::CLI < Thor
4
+ desc "test", "run tests"
5
+ def test
6
+ puts "No tests have been wrritten"
7
+ exit
8
+ end
9
+ end
10
+ GosuWrapper::CLI.start ARGV
@@ -0,0 +1,10 @@
1
+ class GosuWrapper
2
+ Buttons = {
3
+ up: Gosu::KB_UP,
4
+ down: Gosu::KB_DOWN,
5
+ right: Gosu::KB_RIGHT,
6
+ left: Gosu::KB_LEFT,
7
+ enter: Gosu::KB_ENTER,
8
+ escape: Gosu::KB_ESCAPE
9
+ }
10
+ end
@@ -0,0 +1,15 @@
1
+ class GosuWrapper
2
+ color = Gosu::Color
3
+ Colors = {
4
+ none: color::NONE,
5
+ black: color::BLACK,
6
+ grap: color::GRAY,
7
+ white: color::WHITE,
8
+ aqua: color::AQUA,
9
+ red: color::RED,
10
+ green: color::GREEN,
11
+ blue: color::BLUE,
12
+ fuchsia: color::FUCHSIA,
13
+ cyan: color::CYAN,
14
+ }
15
+ end
@@ -0,0 +1,65 @@
1
+ class GosuWrapper
2
+ module Util
3
+
4
+ # ================================================
5
+ def method_missing_for(regex, type:, &definition_blk)
6
+ # Regex should include a match group
7
+ # type should be either :instance or :class
8
+ # Definition blk is run unless there's an existing method with the same name.
9
+ # if caller_blk is provided, it will be passed to definition_blk's invocation
10
+ #
11
+ # Example:
12
+ #
13
+ # class Animal
14
+ # extend Util
15
+ # attr_reader :noises
16
+ # def initialize
17
+ # @noises = { cat: "meow" }
18
+ # end
19
+ # method_missing_for /^(.+)_goes$/ do |match, arg|
20
+ # puts @noises[match]
21
+ # end
22
+ # end
23
+ #
24
+ # Animal.new.cat_goes # => "meow"
25
+ #
26
+ # Through the use of an anonymous modules (adding method_missing to the
27
+ # inheritance chain vs overwriting it with define_method), this can be
28
+ # used multiple times.
29
+ #
30
+ anon_module = Module.new do |mod|
31
+ define_method(:method_missing) do |name, *args, **keywords, &caller_blk|
32
+ match = name.to_s.scan(regex).flatten[0]
33
+ if match
34
+ if respond_to?(name)
35
+ send(name, *args, &caller_blk)
36
+ else
37
+ if type == :instance
38
+ instance_eval &(
39
+ definition_blk.call(match, *args, **keywords, &caller_blk)
40
+ )
41
+ elsif type == :class
42
+ singleton_class.class_exec &(
43
+ definition_blk.call(match, *args, **keywords, &caller_blk)
44
+ )
45
+ end
46
+ end
47
+ else
48
+ super(name, *args, **keywords, &caller_blk)
49
+ end
50
+ end
51
+ end
52
+
53
+ base = case type
54
+ when :instance
55
+ self
56
+ when :class
57
+ self.singleton_class
58
+ end
59
+ base.prepend anon_module
60
+
61
+ end
62
+ # ================================================
63
+
64
+ end
65
+ end
@@ -0,0 +1,139 @@
1
+ require 'gosu'
2
+ require 'active_support/all'
3
+
4
+ Gem.find_files("gosu_wrapper/**/*.rb").each &method(:require)
5
+
6
+ class GosuWrapper
7
+
8
+ extend Util
9
+
10
+ attr_reader :window_constructor, :window, :window_attributes,
11
+ :hooks, :helpers
12
+
13
+ def initialize(width:, height:, attributes:)
14
+ @window_constructor = Class.new(Gosu::Window) do
15
+ const_set("Attributes", attributes)
16
+ attr_accessor *attributes
17
+ end
18
+ @window_attributes = @window_constructor::Attributes
19
+ @window = @window_constructor.new(width, height)
20
+ @window.window_height = height
21
+ @window.window_width = width
22
+ @hooks = []
23
+ @helpers = []
24
+ end
25
+
26
+ # Delegate "set_<attr>" setters to window
27
+ method_missing_for /^set_(.+)$/, type: :instance do |window_attr, val|
28
+ Proc.new do
29
+ if window_attr.to_sym.in? window_attributes
30
+ window.instance_variable_set("@#{window_attr}", val)
31
+ end
32
+ val
33
+ end
34
+ end
35
+
36
+ # Delegate "get_<attr>" getters to window
37
+ method_missing_for /^get_(.+)$/, type: :instance do |window_attr|
38
+ Proc.new do
39
+ if window_attr.to_sym.in? window_attributes
40
+ window.instance_variable_get("@#{window_attr}")
41
+ end
42
+ end
43
+ end
44
+
45
+ # Delegate "get_or_set_<attr>" getters to window
46
+ method_missing_for /^get_or_set_(.+)$/, type: :instance do |window_attr, &blk|
47
+ Proc.new do
48
+ if window_attr.to_sym.in? window_attributes
49
+ send(:"get_#{window_attr}") || send(
50
+ :"set_#{window_attr}",
51
+ instance_eval(&blk)
52
+ )
53
+ end
54
+ end
55
+ end
56
+
57
+ # Delegate "change_<attr>" non-destructive setters to window
58
+ # i.e. change_x(:+, 1) is equivalent to @x += 1
59
+ method_missing_for /^change_(.+)$/, type: :instance do |window_attr, method_name, val|
60
+ Proc.new do
61
+ if window_attr.to_sym.in? window_attributes
62
+ window.instance_variable_set(
63
+ "@#{window_attr}",
64
+ window.instance_variable_get("@#{window_attr}").send(method_name, val)
65
+ )
66
+ end
67
+ end
68
+ end
69
+
70
+ # Methods are defined on the window's anonyous class
71
+ # The generated method's body is always invoked with the App instance's scope.
72
+ def define_method_on_window(name, &blk)
73
+ app = self
74
+ window.define_singleton_method(name) do |*args, **keywords|
75
+ app.scope(*args, **keywords, &blk)
76
+ end
77
+ end
78
+
79
+ def add_hook(name, &blk)
80
+ hooks << name
81
+ define_method_on_window(name, &blk)
82
+ end
83
+
84
+ def add_helper(name, &blk)
85
+ helpers << name
86
+ define_method_on_window(name, &blk)
87
+ end
88
+
89
+ def show
90
+ window.show
91
+ end
92
+
93
+ def image(path:)
94
+ Gosu::Image.new(path)
95
+ end
96
+
97
+ def draw_rect(start_x:, start_y:, end_x:, end_y:, color:, **_)
98
+ width = end_x - start_x
99
+ height = end_y - start_y
100
+ Gosu.draw_rect(start_x, start_y, width, height, color)
101
+ end
102
+
103
+ def colors
104
+ Colors
105
+ end
106
+
107
+ def buttons
108
+ Buttons
109
+ end
110
+
111
+ # A wrapper over instance_exec i.e. app.scope { set_x 200 }
112
+ # Always returns self (app)
113
+ # Be aware that this only sets the scope for one level
114
+ # i.e. if you call a method in the passed block, it'll use a different scope
115
+ def scope(*args, **keywords, &blk)
116
+ if keywords.blank?
117
+ instance_exec *args, &blk
118
+ else
119
+ instance_exec *args, **keywords, &blk
120
+ end
121
+ end
122
+
123
+ # config is the same as scope, but returns self
124
+ def config(&blk)
125
+ scope &blk
126
+ self
127
+ end
128
+
129
+ # Call a method which is defined on window.
130
+ # Although this could have been overloaded onto get_<attr>,
131
+ # to avoid namin conflicts that's limited to instance variables
132
+ def invoke(name, *args, **keywords, &blk)
133
+ window.send(name, *args, **keywords, &blk)
134
+ end
135
+ alias call_helper invoke
136
+ alias dispatch invoke
137
+ alias call_hook invoke
138
+
139
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module GosuWrapper
2
+ VERSION = '0.0.1'
3
+ end
data/readme.md ADDED
File without changes
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gosu_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - maxpleaner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gosu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email: maxpleaner@gmail.com
43
+ executables:
44
+ - gosu_wrapper
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/gosu_wrapper
49
+ - lib/gosu_wrapper.rb
50
+ - lib/gosu_wrapper/buttons.rb
51
+ - lib/gosu_wrapper/colors.rb
52
+ - lib/gosu_wrapper/util.rb
53
+ - lib/version.rb
54
+ - readme.md
55
+ homepage: http://github.com/maxpleaner/gosu_wrapper
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.3'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.5.1
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.5.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: wrawrapper for gosu 2d game lib
79
+ test_files: []