You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copy file name to clipboardExpand all lines: readme.md
+20-31
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Roomy
2
2
3
-
**Roomy** is a screen management library for LÖVE. It facilitates organizing game code by the different "screens" in the game, such as the title screen, gameplay screen, and pause screen.
3
+
**Roomy** is a screen management library for LÖVE. It helps organize game code by the different "screens" in the game, such as the title screen, gameplay screen, and pause screen.
4
4
5
5
## Installation
6
6
@@ -15,7 +15,7 @@ local roomy = require 'path.to.roomy' -- if it's in subfolders
15
15
16
16
### Defining screens
17
17
18
-
A screen is defined as a table with self functions for each event it should respond to. For example, a gameplay screen may look like this:
18
+
A screen is defined as a table with functions for each event it should respond to. For example, a gameplay screen may look like this:
19
19
20
20
```lua
21
21
localgameplay= {}
@@ -82,23 +82,13 @@ function game:keypressed(key)
82
82
end
83
83
```
84
84
85
-
### Applying screen changes
86
-
87
-
```lua
88
-
manager:apply()
89
-
```
90
-
91
-
Calling `switch`, `push`, and `pop` does not apply screen changes immediately. Rather, they are queued up and applied all at once when `apply` is called. Placing `manager.apply` at a specific point in the game loop (right before updating, for instance) alleviates some potential issues with inputs meant for one screen being sent to another screen.
92
-
93
-
Note that if you use `manager.hook`, you don't need to call this manually.
94
-
95
85
### Emitting events
96
86
97
87
```lua
98
88
manager:emit(event, ...)
99
89
```
100
90
101
-
Calls `screen:[event]` on the active screen if that function exists.
91
+
Calls `screen:[event]` on the active screen if that function exists. Additional arguments are passed to `screen.event`.
102
92
103
93
### Hooking into LÖVE callbacks
104
94
@@ -107,59 +97,58 @@ manager:hook(options)
107
97
```
108
98
109
99
Adds code to the LÖVE callbacks to emit events for each callback (previously defined behavior will be preserved). `options` is an optional table with the following keys:
110
-
-`applyBefore` - the name of the callback to run `manager:apply()` at the start of. Set this to `false` to disable this behavior. Defaults to `update`.
111
-
-`callbacks` - a list of callbacks to hook into. Defaults to all LÖVE callbacks (except for `errhand`).
112
-
-`skip` - a list of callbacks not to hook into. If defined, all LÖVE callbacks will be hooked except for the ones in this list. Note that you will get an error if you define both `callbacks` and `skip`.
100
+
-`include` - a list of callbacks to hook into. If this is defined, *only* these callbacks will be overridden.
101
+
-`exclude` - a list of callbacks *not* to hook into. If this is defined, all of the callbacks except for these ones will be overridden.
113
102
114
-
As an example, the following code will cause the screen manager to hook into every callback except for `keypressed` and `mousepressed`, and screen changes will be applied at the beginning of `love.draw`.
103
+
As an example, the following code will cause the screen manager to hook into every callback except for `keypressed` and `mousepressed`.
115
104
116
105
```lua
117
106
manager:hook {
118
-
skip= {'keypressed', 'mousepressed'},
119
-
applyBefore='draw',
107
+
exclude= {'keypressed', 'mousepressed'},
120
108
}
121
109
```
122
110
111
+
**Note:** because this function overrides the LOVE callbacks, you'll want to call this *after* you've defined them. I recommend using this function in the body of `love.load`, like this:
112
+
113
+
```lua
114
+
functionlove.load()
115
+
manager:hook()
116
+
manager:switch(gameplay)
117
+
end
118
+
```
119
+
123
120
### Screen callbacks
124
121
125
122
Screens have a few special callbacks that are called when a screen is switched, pushed, or popped.
126
123
127
124
```lua
128
125
functionscreen:enter(previous, ...) end
129
126
```
127
+
130
128
Called when a manager switches *to* this screen or if this screen is pushed on top of another screen.
131
129
-`previous` - the previously active screen, or `false` if there was no previously active screen
132
130
-`...` - additional arguments passed to `manager.switch` or `manager.push`
133
131
134
132
```lua
135
133
functionscreen:leave(next, ...) end
136
134
```
135
+
137
136
Called when a manager switches *away from* this screen or if this screen is popped from the stack.
138
137
-`next` - the screen that will be active next
139
138
-`...` - additional arguments passed to `manager.switch` or `manager.pop`
140
139
141
140
```lua
142
141
functionscreen:pause(next, ...) end
143
142
```
143
+
144
144
Called when a screen is pushed on top of this screen.
145
145
-`next` - the screen that was pushed on top of this screen
146
146
-`...` - additional arguments passed to `manager.push`
147
147
148
148
```lua
149
149
functionscreen:resume(previous, ...) end
150
150
```
151
+
151
152
Called when a screen is popped and this screen becomes active again.
152
153
-`previous` - the screen that was popped
153
154
-`...` - additional arguments passed to `manager.pop`
154
-
155
-
## License
156
-
157
-
MIT License
158
-
159
-
Copyright (c) 2019 Andrew Minnich
160
-
161
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
162
-
163
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
164
-
165
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0 commit comments