Skip to content

Commit 523e59d

Browse files
committed
use consistent terminology: screen/state -> scene
1 parent f60a8e2 commit 523e59d

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

readme.md

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Roomy
22

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.
3+
**Roomy** is a scene 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.
44

55
## Installation
66

@@ -13,9 +13,9 @@ local roomy = require 'path.to.roomy' -- if it's in subfolders
1313

1414
## Usage
1515

16-
### Defining screens
16+
### Defining scenes
1717

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:
18+
A scene is defined as a table with functions for each event it should respond to. For example, a gameplay scene may look like this:
1919

2020
```lua
2121
local gameplay = {}
@@ -37,32 +37,32 @@ function gameplay:draw()
3737
end
3838
```
3939

40-
A screen table can contain anything, but it will likely have some combination of functions corresponding to LÖVE callbacks and Roomy events.
40+
A scene table can contain anything, but it will likely have some combination of functions corresponding to LÖVE callbacks and Roomy events.
4141

42-
### Creating a screen manager
42+
### Creating a scene manager
4343

4444
```lua
4545
local manager = roomy.new()
4646
```
4747

48-
Creates a new screen manager. You can create as many screen managers as you want, but you'll most likely want one global manager for the main screens of your game.
48+
Creates a new scene manager. You can create as many scene managers as you want, but you'll most likely want one global manager for the main scenes of your game.
4949

50-
### Switching screens
50+
### Switching scenes
5151

5252
```lua
53-
manager:enter(screen, ...)
53+
manager:enter(scene, ...)
5454
```
5555

56-
Changes the currently active screen.
56+
Changes the currently active scene.
5757

58-
### Pushing/popping screens
58+
### Pushing/popping scenes
5959

6060
```lua
61-
manager:push(screen, ...)
61+
manager:push(scene, ...)
6262
manager:pop()
6363
```
6464

65-
Managers use a stack to hold screens. You can push a screen onto the top of the stack, making it the currently active screen, and then pop it, resuming the previous state where it left off. This is useful for implementing pause screens, for example:
65+
Managers use a stack to hold scenes. You can push a scene onto the top of the stack, making it the currently active scene, and then pop it, resuming the previous state where it left off. This is useful for implementing pause screens, for example:
6666

6767
```lua
6868
local pause = {}
@@ -88,7 +88,7 @@ end
8888
manager:emit(event, ...)
8989
```
9090

91-
Calls `screen:[event]` on the active screen if that function exists. Additional arguments are passed to `screen.event`.
91+
Calls `scene:[event]` on the active scene if that function exists. Additional arguments are passed to `scene.event`.
9292

9393
### Hooking into LÖVE callbacks
9494

@@ -100,7 +100,7 @@ Adds code to the LÖVE callbacks to emit events for each callback (previously de
100100
- `include` - a list of callbacks to hook into. If this is defined, *only* these callbacks will be overridden.
101101
- `exclude` - a list of callbacks *not* to hook into. If this is defined, all of the callbacks except for these ones will be overridden.
102102

103-
As an example, the following code will cause the screen manager to hook into every callback except for `keypressed` and `mousepressed`.
103+
As an example, the following code will cause the scene manager to hook into every callback except for `keypressed` and `mousepressed`.
104104

105105
```lua
106106
manager:hook {
@@ -117,38 +117,38 @@ function love.load()
117117
end
118118
```
119119

120-
### Screen callbacks
120+
### Scene callbacks
121121

122-
Screens have a few special callbacks that are called when a screen is switched, pushed, or popped.
122+
Scenes have a few special callbacks that are called when a scene is switched, pushed, or popped.
123123

124124
```lua
125-
function screen:enter(previous, ...) end
125+
function scene:enter(previous, ...) end
126126
```
127127

128-
Called when a manager switches *to* this screen or if this screen is pushed on top of another screen.
129-
- `previous` - the previously active screen, or `false` if there was no previously active screen
128+
Called when a manager switches *to* this scene or if this scene is pushed on top of another scene.
129+
- `previous` - the previously active scene, or `false` if there was no previously active scene
130130
- `...` - additional arguments passed to `manager.switch` or `manager.push`
131131

132132
```lua
133-
function screen:leave(next, ...) end
133+
function scene:leave(next, ...) end
134134
```
135135

136-
Called when a manager switches *away from* this screen or if this screen is popped from the stack.
137-
- `next` - the screen that will be active next
136+
Called when a manager switches *away from* this scene or if this scene is popped from the stack.
137+
- `next` - the scene that will be active next
138138
- `...` - additional arguments passed to `manager.switch` or `manager.pop`
139139

140140
```lua
141-
function screen:pause(next, ...) end
141+
function scene:pause(next, ...) end
142142
```
143143

144-
Called when a screen is pushed on top of this screen.
145-
- `next` - the screen that was pushed on top of this screen
144+
Called when a scene is pushed on top of this scene.
145+
- `next` - the scene that was pushed on top of this scene
146146
- `...` - additional arguments passed to `manager.push`
147147

148148
```lua
149-
function screen:resume(previous, ...) end
149+
function scene:resume(previous, ...) end
150150
```
151151

152-
Called when a screen is popped and this screen becomes active again.
153-
- `previous` - the screen that was popped
152+
Called when a scene is popped and this scene becomes active again.
153+
- `previous` - the scene that was popped
154154
- `...` - additional arguments passed to `manager.pop`

roomy.lua

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local roomy = {
22
_VERSION = 'Roomy',
3-
_DESCRIPTION = 'Screen management for LÖVE.',
3+
_DESCRIPTION = 'Scene management for LÖVE.',
44
_URL = 'https://github.com/tesselode/roomy',
55
_LICENSE = [[
66
MIT License
@@ -79,29 +79,29 @@ local Manager = {}
7979
Manager.__index = Manager
8080

8181
function Manager:emit(event, ...)
82-
local state = self._stack[#self._stack]
83-
if state[event] then state[event](state, ...) end
82+
local scene = self._scenes[#self._scenes]
83+
if scene[event] then scene[event](scene, ...) end
8484
end
8585

8686
function Manager:enter(next, ...)
87-
local previous = self._stack[#self._stack]
87+
local previous = self._scenes[#self._scenes]
8888
self:emit('leave', next, ...)
89-
self._stack[#self._stack] = next
89+
self._scenes[#self._scenes] = next
9090
self:emit('enter', previous, ...)
9191
end
9292

9393
function Manager:push(next, ...)
94-
local previous = self._stack[#self._stack]
94+
local previous = self._scenes[#self._scenes]
9595
self:emit('pause', next, ...)
96-
self._stack[#self._stack + 1] = next
96+
self._scenes[#self._scenes + 1] = next
9797
self:emit('enter', previous, ...)
9898
end
9999

100100
function Manager:pop(...)
101-
local previous = self._stack[#self._stack]
102-
local next = self._stack[#self._stack - 1]
101+
local previous = self._scenes[#self._scenes]
102+
local next = self._scenes[#self._scenes - 1]
103103
self:emit('leave', next, ...)
104-
self._stack[#self._stack] = nil
104+
self._scenes[#self._scenes] = nil
105105
self:emit('resume', previous, ...)
106106
end
107107

@@ -122,7 +122,7 @@ end
122122

123123
function roomy.new()
124124
return setmetatable({
125-
_stack = {{}},
125+
_scenes = {{}},
126126
}, Manager)
127127
end
128128

0 commit comments

Comments
 (0)