4
4
*/
5
5
package de .amr .pacmanfx .ui .layout ;
6
6
7
- import de .amr .pacmanfx .GameContext ;
8
7
import de .amr .pacmanfx .controller .GameState ;
9
8
import de .amr .pacmanfx .event .GameEvent ;
10
9
import de .amr .pacmanfx .lib .Vector2f ;
10
+ import de .amr .pacmanfx .model .GameLevel ;
11
11
import de .amr .pacmanfx .model .actors .ActorAnimationMap ;
12
12
import de .amr .pacmanfx .ui .*;
13
13
import de .amr .pacmanfx .ui ._2d .CrudeCanvasContainer ;
@@ -70,7 +70,6 @@ private static byte identifySceneSwitchType(GameScene sceneBefore, GameScene sce
70
70
private final ActionBindingManager actionBindings ;
71
71
72
72
private final GameUI ui ;
73
- private final GameContext gameContext ;
74
73
private final Scene parentScene ;
75
74
76
75
private BorderPane canvasLayer ;
@@ -83,9 +82,8 @@ private static byte identifySceneSwitchType(GameScene sceneBefore, GameScene sce
83
82
private final MiniGameView miniGameView ;
84
83
private final ContextMenu contextMenu = new ContextMenu ();
85
84
86
- public PlayView (GameUI ui , GameContext gameContext , Scene parentScene ) {
85
+ public PlayView (GameUI ui , Scene parentScene ) {
87
86
this .ui = requireNonNull (ui );
88
- this .gameContext = requireNonNull (gameContext );
89
87
this .parentScene = requireNonNull (parentScene );
90
88
this .miniGameView = new MiniGameView ();
91
89
this .dashboard = new Dashboard (ui );
@@ -183,8 +181,8 @@ public void draw() {
183
181
}
184
182
});
185
183
186
- if (miniGameView .isVisible () && ui .isCurrentGameSceneID (SCENE_ID_PLAY_SCENE_3D ) && gameContext .optGameLevel ().isPresent ()) {
187
- miniGameView .draw (ui , gameContext .theGameLevel ());
184
+ if (miniGameView .isVisible () && ui .isCurrentGameSceneID (SCENE_ID_PLAY_SCENE_3D ) && ui . theGameContext () .optGameLevel ().isPresent ()) {
185
+ miniGameView .draw (ui , ui . theGameContext () .theGameLevel ());
188
186
}
189
187
190
188
// Dashboard updates must be called from permanent clock task too!
@@ -210,20 +208,21 @@ public void onGameEvent(GameEvent gameEvent) {
210
208
Logger .trace ("Handle {}" , gameEvent );
211
209
switch (gameEvent .type ()) {
212
210
case LEVEL_CREATED -> {
211
+ GameLevel gameLevel = ui .theGameContext ().theGameLevel ();
213
212
GameUI_Config config = ui .theConfiguration ();
214
- ActorAnimationMap pacAnimationMap = config .createPacAnimations (gameContext . theGameLevel () .pac ());
215
- gameContext . theGameLevel () .pac ().setAnimations (pacAnimationMap );
216
- gameContext . theGameLevel () .ghosts ().forEach (ghost -> {
213
+ ActorAnimationMap pacAnimationMap = config .createPacAnimations (gameLevel .pac ());
214
+ gameLevel .pac ().setAnimations (pacAnimationMap );
215
+ gameLevel .ghosts ().forEach (ghost -> {
217
216
ActorAnimationMap ghostAnimationMap = config .createGhostAnimations (ghost );
218
217
ghost .setAnimations (ghostAnimationMap );
219
218
});
220
- miniGameView .onLevelCreated (ui , gameContext . theGameLevel () );
219
+ miniGameView .onLevelCreated (ui , gameLevel );
221
220
222
221
// size of game scene might have changed, so re-embed
223
222
ui .currentGameScene ().ifPresent (this ::embedGameScene );
224
223
}
225
224
case GAME_STATE_CHANGED -> {
226
- if (gameContext .theGameState () == GameState .LEVEL_COMPLETE ) {
225
+ if (ui . theGameContext () .theGameState () == GameState .LEVEL_COMPLETE ) {
227
226
miniGameView .onLevelCompleted ();
228
227
}
229
228
}
@@ -243,7 +242,7 @@ public CrudeCanvasContainer canvasContainer() {
243
242
}
244
243
245
244
public void updateGameScene (boolean reloadCurrent ) {
246
- final GameScene nextGameScene = ui .theConfiguration ().selectGameScene (gameContext );
245
+ final GameScene nextGameScene = ui .theConfiguration ().selectGameScene (ui . theGameContext () );
247
246
if (nextGameScene == null ) {
248
247
String errorMessage = " Katastrophe! Could not determine game scene!" ;
249
248
ui .showFlashMessageSec (30 , errorMessage );
@@ -279,9 +278,9 @@ public void updateGameScene(boolean reloadCurrent) {
279
278
public void quitCurrentGameScene () {
280
279
ui .currentGameScene ().ifPresent (gameScene -> {
281
280
gameScene .end ();
282
- gameContext .theGameController ().changeGameState (GameState .BOOT );
283
- gameContext .theGame ().resetEverything ();
284
- if (!gameContext . theCoinMechanism ().isEmpty ()) gameContext .theCoinMechanism ().consumeCoin ();
281
+ ui . theGameContext () .theGameController ().changeGameState (GameState .BOOT );
282
+ ui . theGameContext () .theGame ().resetEverything ();
283
+ if (!ui . theGameContext (). theCoinMechanism ().isEmpty ()) ui . theGameContext () .theCoinMechanism ().consumeCoin ();
285
284
ui .showStartView ();
286
285
Logger .info ("Current game scene ({}) has been quit" , gameScene .getClass ().getSimpleName ());
287
286
});
0 commit comments