gosu_wrapper 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/version.rb +1 -1
  3. data/readme.md +126 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1e3045af1e3059febc285c2b27e425ba519f302
4
- data.tar.gz: 999b7a748f81020f05959d65aa6f2dbdd97c384f
3
+ metadata.gz: 917ff2ab23c3b32591b9ca6e6cb81b60e88aaf13
4
+ data.tar.gz: 96a2c3dd86049eef3b8b00c2d620e9d435154d75
5
5
  SHA512:
6
- metadata.gz: aa02328c1f134dd6889d6167984731e8fc401ff8cc2d0101676be6ac0f049669f09ba1a61816eb6672e3e3847bca691e177e8b43b978c7c52d2ddcbf3e0f538b
7
- data.tar.gz: b5f48a1a483744b98dbed7126a440b439085f36b4c05eb915ca3c4157b534469fefae1c8cb4077429720f74165613d10a0e19545148f010738629d455dc9245c
6
+ metadata.gz: 64d1346282045251db6f4de0300f6701087643d85e9a9bf875c415b77c77f34960b8b75f61c3cd8f4040bf08ce3054781b8d6ac38a1eced95657b4c3de26d835
7
+ data.tar.gz: d67cc8edbee1b432e7a61682f85dec118fc20193919a6f9cdf55cb9503ceb3b471f1fea5f6f9f1cad08d74bc4ba87beeb53caa97d48a9e094f7ff390dcd80c92
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GosuWrapper
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/readme.md CHANGED
@@ -0,0 +1,126 @@
1
+ ### Installing
2
+
3
+ _gosu and activesupport will be loaded as dependencies_
4
+
5
+ `gem install gosu_wrapper`
6
+
7
+ or in a gemfile: `gem 'gosu_wrapper'`
8
+
9
+ ### Usage
10
+
11
+ One public class is exposed, `GosuWrapper`. It's essentially a wrapper
12
+ over an anonymous `Gosu::Window` class that gets functionality added through
13
+ metaprogramming.
14
+
15
+ In lieue of a "getting started" snippet, I'm going to delegate that to the
16
+ [gosu_wrapper_snake_example](http://github.com/maxpleaner/gosu_wrapper_snake_example)
17
+ codebase and run through the API step-by-step here.
18
+
19
+ ---
20
+
21
+ **`#initialize(width:, height:, attributes:)`**
22
+
23
+ - This defines `#window` which is an instance of `Gosu::Window`.
24
+ - width & height are num pixels (of the total window).
25
+ - attributes is an array of symbols.
26
+ It must at least include `:window_height` and `:window_width`.
27
+ All of the keys in your app's state hash should be given here.
28
+ Each of them get attr_accessors defined on `#window` and shorthand
29
+ accessors using `method_missing` (see next section).
30
+
31
+ ---
32
+
33
+ **There are four instance methods added using `method_missing`**
34
+
35
+ 1. `#get_<attr>`
36
+ - delegates the getter to `window`
37
+ 2. `#set_<attr>(val)`
38
+ - delegates the setter to `window`
39
+ 3. `#change_<attr>(sym, arg)`
40
+ - a shorthand for some update operations
41
+ on non-mutable objects. For example `change_score(:+, 1)`
42
+ 4. `#get_or_set_<attr>(&blk)`
43
+ - returns the val if it's truthy, and otherwise sets the val equal
44
+ to the block result (returning it as well).
45
+
46
+ ---
47
+
48
+ **`#define_method_on_window(name, &blk)`**
49
+
50
+ - this should be a private method, but is used by a number of others so
51
+ it's worth explaing.
52
+ - It defines the method named `name` on `window` with `blk` as its body.
53
+ - Arguments are determined by the block
54
+ - The block is always invoked with the `GosuWrapper` instance as
55
+ the value of `self`
56
+
57
+ ---
58
+
59
+ **`#scope(*args, **keywords, &blk)`**
60
+
61
+ - another method that should be private; this is what handles
62
+ calling a proc with the `GosuWrapper` instance as the value of `self`.
63
+
64
+ ---
65
+
66
+ **`#config(&blk)`**
67
+
68
+ - mostly the same thing as `#scope` but is meant to be used publically.
69
+ - the only functional difference is this always returns `self`
70
+ (the `GosuWrapper` instance) whereas `#scope` returns the result of the
71
+ block.
72
+ - Like `#scope`, this is a classic DSL-style method which exists for the
73
+ sole purpose of saving keystrokes (using `instance_exec`)
74
+
75
+ ---
76
+
77
+ **`#add_hook(name, &blk)`**
78
+
79
+ - a "hook" conceptually is a method internally defined by `Gosu::Window`
80
+ that we're tapping into by overriding. Hooking into events `update`,
81
+ `button_down`, and `draw` are how the app works at a basic level.
82
+ - the `button_down` proc is passed an `id` which can be checked against
83
+ the values in `#buttons` to determine which key was pressed.
84
+ - `update` and `draw` are run every tick. Conceptually, `update`
85
+ is used to change the state and `draw` to represent it.
86
+
87
+ ---
88
+
89
+ **`#add_helper(name, &blk)`**
90
+
91
+ - functionally speaking this is the exact same thing as `add_hook` -
92
+ it defines a method on `Gosu::Window`.
93
+ - It exists to distinguish between built-in hooks like `update` from
94
+ custom methods.
95
+ - These can be called with `#invoke` or its alias `#call_helper`.
96
+
97
+ ---
98
+
99
+ **`#show`**
100
+
101
+ - Starts the game. Needs to be called only once.
102
+
103
+ ---
104
+
105
+ **`#draw_rect(start_x:, start_y:, end_x:, end_y:, color)`**
106
+
107
+ - Can be called from `draw` only. Fills the rectangle with `color`
108
+
109
+ ---
110
+
111
+ **`#colors`**
112
+
113
+ - a hash of name => color object pairs
114
+
115
+ ---
116
+
117
+ **`#buttons`**
118
+
119
+ - a hash of name => button id pairs
120
+
121
+ ---
122
+
123
+ **`#invoke/#call_helper/#dispatch/#call_hook`**
124
+
125
+ - all aliases for the same simple thing: calling a function on
126
+ `window` (the `Gosu::Window instance`).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxpleaner