@@ -6,26 +6,26 @@ import (
6
6
"github.com/hajimehoshi/ebiten/v2"
7
7
)
8
8
9
- type SceneTransition [T any , M SceneController [ T ] ] interface {
9
+ type SceneTransition [T any ] interface {
10
10
ProtoScene [T ]
11
- Start (fromScene , toScene Scene [T , M ], sm * SceneManager [T ])
11
+ Start (fromScene , toScene Scene [T ], sm SceneController [T ])
12
12
End ()
13
13
}
14
14
15
- type BaseTransition [T any , M SceneController [ T ] ] struct {
16
- fromScene Scene [T , M ]
17
- toScene Scene [T , M ]
18
- sm * SceneManager [T ]
15
+ type BaseTransition [T any ] struct {
16
+ fromScene Scene [T ]
17
+ toScene Scene [T ]
18
+ sm SceneController [T ]
19
19
}
20
20
21
- func (t * BaseTransition [T , M ]) Start (fromScene , toScene Scene [T , M ], sm * SceneManager [T ]) {
21
+ func (t * BaseTransition [T ]) Start (fromScene , toScene Scene [T ], sm SceneController [T ]) {
22
22
t .fromScene = fromScene
23
23
t .toScene = toScene
24
24
t .sm = sm
25
25
}
26
26
27
27
// Update updates the transition state
28
- func (t * BaseTransition [T , M ]) Update () error {
28
+ func (t * BaseTransition [T ]) Update () error {
29
29
// Update the scenes
30
30
err := t .fromScene .Update ()
31
31
if err != nil {
@@ -41,61 +41,41 @@ func (t *BaseTransition[T, M]) Update() error {
41
41
}
42
42
43
43
// Layout updates the layout of the scenes
44
- func (t * BaseTransition [T , M ]) Layout (outsideWidth , outsideHeight int ) (int , int ) {
44
+ func (t * BaseTransition [T ]) Layout (outsideWidth , outsideHeight int ) (int , int ) {
45
45
sw , sh := t .fromScene .Layout (outsideWidth , outsideHeight )
46
46
tw , th := t .toScene .Layout (outsideWidth , outsideHeight )
47
47
48
48
return MaxInt (sw , tw ), MaxInt (sh , th )
49
49
}
50
50
51
- func (s * SceneManager [T ]) ReturnFromTransition (scene , orgin Scene [T , * SceneManager [T ]]) {
52
- if c , ok := scene .(TransitionAwareScene [T , * SceneManager [T ]]); ok {
53
- c .PostTransition (orgin .Unload (), orgin )
54
- } else {
55
- scene .Load (orgin .Unload (), s )
56
- }
57
- s .current = scene
58
- }
59
-
60
- func (s * SceneManager [T ]) SwitchWithTransition (scene Scene [T , * SceneManager [T ]], transition SceneTransition [T , * SceneManager [T ]]) {
61
- sc := s .current .(Scene [T , * SceneManager [T ]])
62
- transition .Start (sc , scene , s )
63
- if c , ok := sc .(TransitionAwareScene [T , * SceneManager [T ]]); ok {
64
- scene .Load (c .PreTransition (scene ), s )
65
- } else {
66
- scene .Load (sc .Unload (), s )
67
- }
68
- s .current = transition
69
- }
70
-
71
51
// Ends transition to the next scene
72
- func (t * BaseTransition [T , M ]) End () {
73
- t .sm .ReturnFromTransition (t .toScene .(Scene [T , * SceneManager [ T ]] ), t .fromScene .(Scene [T , * SceneManager [ T ] ]))
52
+ func (t * BaseTransition [T ]) End () {
53
+ t .sm .ReturnFromTransition (t .toScene .(Scene [T ] ), t .fromScene .(Scene [T ]))
74
54
}
75
55
76
- type FadeTransition [T any , M SceneController [ T ] ] struct {
77
- BaseTransition [T , M ]
56
+ type FadeTransition [T any ] struct {
57
+ BaseTransition [T ]
78
58
factor float32 // factor used for the fade-in/fade-out effect
79
59
alpha float32 // alpha value used for the fade-in/fade-out effect
80
60
isFadingIn bool // whether the transition is currently fading in or out
81
61
frameUpdated bool
82
62
}
83
63
84
- func NewFadeTransition [T any , M SceneController [ T ]] (factor float32 ) * FadeTransition [T , M ] {
85
- return & FadeTransition [T , M ]{
64
+ func NewFadeTransition [T any ] (factor float32 ) * FadeTransition [T ] {
65
+ return & FadeTransition [T ]{
86
66
factor : factor ,
87
67
}
88
68
}
89
69
90
70
// Start starts the transition from the given "from" scene to the given "to" scene
91
- func (t * FadeTransition [T , M ]) Start (fromScene , toScene Scene [T , M ], sm * SceneManager [T ]) {
71
+ func (t * FadeTransition [T ]) Start (fromScene , toScene Scene [T ], sm SceneController [T ]) {
92
72
t .BaseTransition .Start (fromScene , toScene , sm )
93
73
t .alpha = 0
94
74
t .isFadingIn = true
95
75
}
96
76
97
77
// Update updates the transition state
98
- func (t * FadeTransition [T , M ]) Update () error {
78
+ func (t * FadeTransition [T ]) Update () error {
99
79
if ! t .frameUpdated {
100
80
// Update the alpha value based on the current state of the transition
101
81
if t .isFadingIn {
@@ -119,7 +99,7 @@ func (t *FadeTransition[T, M]) Update() error {
119
99
}
120
100
121
101
// Draw draws the transition effect
122
- func (t * FadeTransition [T , M ]) Draw (screen * ebiten.Image ) {
102
+ func (t * FadeTransition [T ]) Draw (screen * ebiten.Image ) {
123
103
toImg , fromImg := PreDraw (screen .Bounds (), t .fromScene , t .toScene )
124
104
toOp , fromOp := & ebiten.DrawImageOptions {}, & ebiten.DrawImageOptions {}
125
105
@@ -140,8 +120,8 @@ func (t *FadeTransition[T, M]) Draw(screen *ebiten.Image) {
140
120
t .frameUpdated = false
141
121
}
142
122
143
- type SlideTransition [T any , M SceneController [ T ] ] struct {
144
- BaseTransition [T , M ]
123
+ type SlideTransition [T any ] struct {
124
+ BaseTransition [T ]
145
125
factor float64 // factor used for the slide-in/slide-out effect
146
126
direction SlideDirection
147
127
offset float64
@@ -157,21 +137,21 @@ const (
157
137
BottomToTop
158
138
)
159
139
160
- func NewSlideTransition [T any , M SceneController [ T ]] (direction SlideDirection , factor float64 ) * SlideTransition [T , M ] {
161
- return & SlideTransition [T , M ]{
140
+ func NewSlideTransition [T any ] (direction SlideDirection , factor float64 ) * SlideTransition [T ] {
141
+ return & SlideTransition [T ]{
162
142
direction : direction ,
163
143
factor : factor ,
164
144
}
165
145
}
166
146
167
147
// Start starts the transition from the given "from" scene to the given "to" scene
168
- func (t * SlideTransition [T , M ]) Start (fromScene Scene [T , M ], toScene Scene [T , M ], sm * SceneManager [T ]) {
148
+ func (t * SlideTransition [T ]) Start (fromScene Scene [T ], toScene Scene [T ], sm SceneController [T ]) {
169
149
t .BaseTransition .Start (fromScene , toScene , sm )
170
150
t .offset = 0
171
151
}
172
152
173
153
// Update updates the transition state
174
- func (t * SlideTransition [T , M ]) Update () error {
154
+ func (t * SlideTransition [T ]) Update () error {
175
155
if ! t .frameUpdated {
176
156
// Update the offset value based on the current state of the transition
177
157
if t .offset >= 1.0 {
@@ -188,7 +168,7 @@ func (t *SlideTransition[T, M]) Update() error {
188
168
}
189
169
190
170
// Draw draws the transition effect
191
- func (t * SlideTransition [T , M ]) Draw (screen * ebiten.Image ) {
171
+ func (t * SlideTransition [T ]) Draw (screen * ebiten.Image ) {
192
172
toImg , fromImg := PreDraw (screen .Bounds (), t .fromScene , t .toScene )
193
173
toOp , fromOp := & ebiten.DrawImageOptions {}, & ebiten.DrawImageOptions {}
194
174
@@ -221,29 +201,29 @@ func (t *SlideTransition[T, M]) Draw(screen *ebiten.Image) {
221
201
222
202
// Timed Variants of the transition
223
203
224
- func NewTicksTimedFadeTransition [T any , M SceneController [ T ]] (duration time.Duration ) * FadeTransition [T , M ] {
225
- return NewFadeTransition [T , M ](float32 (DurationToFactor (float64 (ebiten .TPS ()), duration )))
204
+ func NewTicksTimedFadeTransition [T any ] (duration time.Duration ) * FadeTransition [T ] {
205
+ return NewFadeTransition [T ](float32 (DurationToFactor (float64 (ebiten .TPS ()), duration )))
226
206
}
227
207
228
- type TimedFadeTransition [T any , M SceneController [ T ] ] struct {
229
- FadeTransition [T , M ]
208
+ type TimedFadeTransition [T any ] struct {
209
+ FadeTransition [T ]
230
210
initialTime time.Time
231
211
duration time.Duration
232
212
}
233
213
234
- func NewDurationTimedFadeTransition [T any , M SceneController [ T ]] (duration time.Duration ) * TimedFadeTransition [T , M ] {
235
- return & TimedFadeTransition [T , M ]{
214
+ func NewDurationTimedFadeTransition [T any ] (duration time.Duration ) * TimedFadeTransition [T ] {
215
+ return & TimedFadeTransition [T ]{
236
216
duration : duration ,
237
- FadeTransition : * NewFadeTransition [T , M ](0. ),
217
+ FadeTransition : * NewFadeTransition [T ](0. ),
238
218
}
239
219
}
240
220
241
- func (t * TimedFadeTransition [T , M ]) Start (fromScene , toScene Scene [T , M ], sm * SceneManager [T ]) {
221
+ func (t * TimedFadeTransition [T ]) Start (fromScene , toScene Scene [T ], sm SceneController [T ]) {
242
222
t .FadeTransition .Start (fromScene , toScene , sm )
243
223
t .initialTime = Clock .Now ()
244
224
}
245
225
246
- func (t * TimedFadeTransition [T , M ]) Update () error {
226
+ func (t * TimedFadeTransition [T ]) Update () error {
247
227
if ! t .frameUpdated {
248
228
// Update the alpha value based on the current state of the transition
249
229
if t .isFadingIn {
@@ -267,29 +247,29 @@ func (t *TimedFadeTransition[T, M]) Update() error {
267
247
268
248
}
269
249
270
- func NewTicksTimedSlideTransition [T any , M SceneController [ T ]] (direction SlideDirection , duration time.Duration ) * SlideTransition [T , M ] {
271
- return NewSlideTransition [T , M ](direction , DurationToFactor (float64 (ebiten .TPS ()), duration ))
250
+ func NewTicksTimedSlideTransition [T any ] (direction SlideDirection , duration time.Duration ) * SlideTransition [T ] {
251
+ return NewSlideTransition [T ](direction , DurationToFactor (float64 (ebiten .TPS ()), duration ))
272
252
}
273
253
274
- type TimedSlideTransition [T any , M SceneController [ T ] ] struct {
275
- SlideTransition [T , M ]
254
+ type TimedSlideTransition [T any ] struct {
255
+ SlideTransition [T ]
276
256
initialTime time.Time
277
257
duration time.Duration
278
258
}
279
259
280
- func NewDurationTimedSlideTransition [T any , M SceneController [ T ]] (direction SlideDirection , duration time.Duration ) * TimedSlideTransition [T , M ] {
281
- return & TimedSlideTransition [T , M ]{
260
+ func NewDurationTimedSlideTransition [T any ] (direction SlideDirection , duration time.Duration ) * TimedSlideTransition [T ] {
261
+ return & TimedSlideTransition [T ]{
282
262
duration : duration ,
283
- SlideTransition : * NewSlideTransition [T , M ](direction , 0. ),
263
+ SlideTransition : * NewSlideTransition [T ](direction , 0. ),
284
264
}
285
265
}
286
266
287
- func (t * TimedSlideTransition [T , M ]) Start (fromScene , toScene Scene [T , M ], sm * SceneManager [T ]) {
267
+ func (t * TimedSlideTransition [T ]) Start (fromScene , toScene Scene [T ], sm SceneController [T ]) {
288
268
t .SlideTransition .Start (fromScene , toScene , sm )
289
269
t .initialTime = Clock .Now ()
290
270
}
291
271
292
- func (t * TimedSlideTransition [T , M ]) Update () error {
272
+ func (t * TimedSlideTransition [T ]) Update () error {
293
273
if ! t .frameUpdated {
294
274
// Update the offset value based on the current state of the transition
295
275
if t .offset >= 1.0 {
0 commit comments