@@ -5,22 +5,29 @@ sceneman.active = nil
5
5
-- Create a new scene
6
6
function sceneman :newscene ()
7
7
local scene = {}
8
+ scene .loaded = false
9
+ scene .started = false
8
10
9
11
function scene :load () end
10
12
function scene :start () end
11
13
function scene :tofront () end
12
14
function scene :toback () end
13
- function scene :stop () end
14
- function scene :quit (...)
15
- -- By default we simply call the
16
- -- stop function
17
- self :stop (... )
15
+ function scene :clean () end
16
+ function scene :stop (...) end
17
+ function scene :quit (...) end
18
+
19
+ function scene :isloaded ()
20
+ return self .loaded
18
21
end
19
22
20
23
function scene :isactive ()
21
24
return sceneman .active == self
22
25
end
23
26
27
+ function scene :isstarted ()
28
+ return self .started
29
+ end
30
+
24
31
function scene :update () end
25
32
function scene :draw () end
26
33
30
37
-- Create and register a new scene
31
38
function sceneman :new (name )
32
39
local scene = self :newscene ()
33
- -- local index = #self.scenes
34
- -- self.scenes[index + 1] = scene
35
40
self .scenes [name ] = scene
36
41
return scene
37
42
end
@@ -50,11 +55,20 @@ function sceneman:get(name)
50
55
return scene
51
56
end
52
57
53
- -- Call the load function of all the
54
- -- scenes
55
- function sceneman :load (...)
56
- for _ , scene in pairs (self .scenes ) do
57
- scene :load (... )
58
+ -- Call the load function of a
59
+ -- a single scene
60
+ function sceneman :load (name , ...)
61
+ local scene = self :get (name )
62
+ scene :load (... )
63
+ scene .loaded = true
64
+ return self
65
+ end
66
+
67
+ -- Call the load function
68
+ -- of every scenes
69
+ function sceneman :loadall (...)
70
+ for name , scene in pairs (self .scenes ) do
71
+ sceneman :load (name , ... )
58
72
end
59
73
60
74
return self
71
85
function sceneman :start (name , ...)
72
86
local scene = self :get (name )
73
87
scene :start (... )
88
+ scene .started = true
74
89
self .active = scene
75
90
return self
76
91
end
@@ -111,29 +126,52 @@ end
111
126
function sceneman :stop (...)
112
127
if self :hasactive () then
113
128
self .active :stop (... )
129
+ self .active .started = false
114
130
end
115
131
116
132
self .active = nil
117
133
return self
118
134
end
119
135
120
- -- Call the stop function of every
121
- -- registered scenes
136
+ -- Stop all scenes wich
137
+ -- are started
122
138
function sceneman :stopall (...)
123
139
for _ , scene in pairs (self .scenes ) do
124
- self .active :stop (... )
140
+ if scene :isstarted () then
141
+ scene :stop (... )
142
+ scene .started = false
143
+ end
125
144
end
126
145
127
146
self .active = nil
128
147
return self
129
148
end
130
149
131
- -- Call the stop function of each scenes
132
- function sceneman :quit (...)
133
- for _ , scene in pairs (self .scenes ) do
150
+ -- Call the quit method of
151
+ -- the given scene, wich
152
+ -- unload allocated ressources
153
+ -- trough the load function
154
+ function sceneman :quit (name , ...)
155
+ local scene = self :get (name )
156
+
157
+ if scene == self .active then
158
+ error (' scenman: can\' t quit active scene' )
159
+ end
160
+
161
+ if scene :isloaded () then
134
162
scene :quit (... )
135
163
end
136
164
165
+ scene .loaded = false
166
+ return self
167
+ end
168
+
169
+ -- Call the quit method of
170
+ -- every scene
171
+ function sceneman :quitall (...)
172
+ for name , _ in pairs (self .scenes ) do
173
+ self :quit (name , ... )
174
+ end
137
175
return self
138
176
end
139
177
0 commit comments