Skip to content

Commit f24a9b3

Browse files
Refac builder
1 parent be9f13f commit f24a9b3

File tree

7 files changed

+40
-41
lines changed

7 files changed

+40
-41
lines changed

doc/linux-issues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Ok, so try this:
166166
In IntelliJ, right-click over the "Main" class of the 3d subproject and select "More Run/Debug -> Modify Run
167167
Configuration..."
168168

169-
In the run configuration, add the VM parameters input field and enter `-Dprism.verbose=true -Dprism.forceGPU=true`.
169+
In the run gameConfiguration, add the VM parameters input field and enter `-Dprism.verbose=true -Dprism.forceGPU=true`.
170170
Then run the application. And, you won't believe what you see in the console:
171171

172172
```

pacman-app-allgames/src/main/java/de/amr/pacmanfx/allgames/app/PacManGames3dApp.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public void start(Stage primaryStage) {
5050
.game(GameVariant.MS_PACMAN_XXL.name(),
5151
PacManXXL_MsPacMan_GameModel.class, mapSelectorXXL, PacManXXL_MsPacMan_UIConfig.class)
5252
// start pages are added to carousel in this order:
53-
.startPage(GameVariant.PACMAN.name(), ArcadePacMan_StartPage.class)
54-
.startPage(GameVariant.MS_PACMAN.name(), ArcadeMsPacMan_StartPage.class)
55-
.startPage(GameVariant.MS_PACMAN_TENGEN.name(), TengenMsPacMan_StartPage.class)
56-
.startPage(GameVariant.PACMAN_XXL.name(), PacManXXL_Common_StartPage.class) // MS_PACMAN_XXL uses this too
53+
.startPage(ArcadePacMan_StartPage.class, GameVariant.PACMAN.name())
54+
.startPage(ArcadeMsPacMan_StartPage.class, GameVariant.MS_PACMAN.name())
55+
.startPage(TengenMsPacMan_StartPage.class, GameVariant.MS_PACMAN_TENGEN.name())
56+
.startPage(PacManXXL_Common_StartPage.class, GameVariant.PACMAN_XXL.name(), GameVariant.MS_PACMAN_XXL.name())
5757
.dashboard(
5858
DashboardID.GENERAL, DashboardID.GAME_CONTROL,
5959
DashboardID.SETTINGS_3D,

pacman-app-arcade-mspacman/src/main/java/de/amr/pacmanfx/arcade/ms_pacman/ArcadeMsPacMan_App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void start(Stage primaryStage) {
2828
ArcadeMsPacMan_GameModel.class,
2929
ArcadeMsPacMan_UIConfig.class
3030
)
31-
.startPage(GAME_VARIANT, ArcadeMsPacMan_StartPage.class)
31+
.startPage(ArcadeMsPacMan_StartPage.class, GAME_VARIANT)
3232
.dashboard(
3333
DashboardID.GENERAL, DashboardID.GAME_CONTROL,
3434
DashboardID.SETTINGS_3D,

pacman-app-arcade-pacman/src/main/java/de/amr/pacmanfx/arcade/pacman/app/ArcadePacMan_App.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
public class ArcadePacMan_App extends Application {
2020

21-
private static final String GAME_VARIANT = GameVariant.PACMAN.name();
21+
private static final String GAME_VARIANT_NAME = GameVariant.PACMAN.name();
2222

2323
@Override
2424
public void start(Stage primaryStage) {
@@ -27,11 +27,11 @@ public void start(Stage primaryStage) {
2727
final double width = 1.2 * height;
2828
GameUI_Builder.createUI(primaryStage, width, height)
2929
.game(
30-
GAME_VARIANT,
30+
GAME_VARIANT_NAME,
3131
ArcadePacMan_GameModel.class,
3232
ArcadePacMan_UIConfig.class
3333
)
34-
.startPage(GAME_VARIANT, ArcadePacMan_StartPage.class)
34+
.startPage(ArcadePacMan_StartPage.class, GAME_VARIANT_NAME)
3535
.dashboard(
3636
DashboardID.GENERAL, DashboardID.GAME_CONTROL,
3737
DashboardID.SETTINGS_3D,

pacman-app-arcade-pacmanxxl/src/main/java/de/amr/pacmanfx/arcade/pacman_xxl/PacManXXL_Common_App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void start(Stage primaryStage) {
4343
DashboardID.KEYBOARD_SHORTCUTS_GLOBAL, DashboardID.KEYBOARD_SHORTCUTS_LOCAL,
4444
DashboardID.ABOUT
4545
)
46-
.startPage(PACMAN_XXL.name(),PacManXXL_Common_StartPage.class)
46+
.startPage(PacManXXL_Common_StartPage.class, PACMAN_XXL.name())
4747
.build()
4848
.show();
4949

pacman-app-tengen-mspacman/src/main/java/de/amr/pacmanfx/tengen/ms_pacman/app/TengenMsPacMan_App.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public class TengenMsPacMan_App extends Application {
2121

22-
private static final String GAME_VARIANT = MS_PACMAN_TENGEN.name();
22+
private static final String GAME_VARIANT_NAME = MS_PACMAN_TENGEN.name();
2323

2424
@Override
2525
public void start(Stage primaryStage) {
@@ -28,11 +28,11 @@ public void start(Stage primaryStage) {
2828
final double width = NES_ASPECT * height;
2929
GameUI_Builder.createUI(primaryStage, width, height)
3030
.game(
31-
GAME_VARIANT,
31+
GAME_VARIANT_NAME,
3232
TengenMsPacMan_GameModel.class,
3333
TengenMsPacMan_UIConfig.class
3434
)
35-
.startPage(GAME_VARIANT, TengenMsPacMan_StartPage.class)
35+
.startPage(TengenMsPacMan_StartPage.class, GAME_VARIANT_NAME)
3636
.dashboard(
3737
DashboardID.GENERAL, DashboardID.GAME_CONTROL,
3838
DashboardID.SETTINGS_3D,

pacman-ui/src/main/java/de/amr/pacmanfx/ui/GameUI_Builder.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
import javafx.stage.Stage;
1515

1616
import java.io.File;
17-
import java.util.Arrays;
18-
import java.util.LinkedHashMap;
19-
import java.util.List;
20-
import java.util.Map;
17+
import java.util.*;
2118

2219
public class GameUI_Builder {
2320

24-
private static class Configuration {
21+
private static class GameConfiguration {
2522
Class<?> gameModelClass;
26-
MapSelector mapSelector;
2723
Class<?> uiConfigClass;
24+
MapSelector mapSelector;
25+
}
26+
27+
private static class StartPageConfiguration {
2828
Class<?> startPageClass;
29+
List<String> gameVariants;
2930
}
3031

3132
public static GameUI_Builder createUI(Stage stage, double width, double height) {
@@ -34,16 +35,17 @@ public static GameUI_Builder createUI(Stage stage, double width, double height)
3435
}
3536

3637
private final PacManGames_UI_Impl ui;
37-
private final Map<String, Configuration> configurationByGameVariant = new LinkedHashMap<>();
38+
private final Map<String, GameConfiguration> configurationByGameVariant = new LinkedHashMap<>();
39+
private final List<StartPageConfiguration> startPageConfigs = new ArrayList<>();
3840
private List<DashboardID> dashboardIDs = List.of();
3941

4042
private GameUI_Builder(PacManGames_UI_Impl ui) {
4143
this.ui = ui;
4244
}
4345

44-
private Configuration configuration(String gameVariant) {
46+
private GameConfiguration configuration(String gameVariant) {
4547
if (!configurationByGameVariant.containsKey(gameVariant)) {
46-
configurationByGameVariant.put(gameVariant, new Configuration());
48+
configurationByGameVariant.put(gameVariant, new GameConfiguration());
4749
}
4850
return configurationByGameVariant.get(gameVariant);
4951
}
@@ -87,21 +89,17 @@ public GameUI_Builder game(
8789
return this;
8890
}
8991

90-
public GameUI_Builder startPage(String gameVariant, Class<?> startPageClass) {
92+
public GameUI_Builder startPage(Class<?> startPageClass, String... gameVariants) {
9193
if (startPageClass == null) {
9294
error("Start page class must not be null");
9395
}
94-
configuration(gameVariant).startPageClass = startPageClass;
95-
return this;
96-
}
97-
98-
public GameUI_Builder startPageShared(String gameVariant, String otherGameVariant) {
99-
Class<?> sharedStartPageClass = configuration(otherGameVariant).startPageClass;
100-
if (sharedStartPageClass == null) {
101-
error("Shared start page not found. Must define start page of shared game variant first!");
102-
throw new IllegalStateException();
96+
if (gameVariants == null) {
97+
error("Game variants list must not be null");
10398
}
104-
configuration(gameVariant).startPageClass = sharedStartPageClass;
99+
var config = new StartPageConfiguration();
100+
config.startPageClass = startPageClass;
101+
config.gameVariants = List.of(gameVariants);
102+
startPageConfigs.add(config);
105103
return this;
106104
}
107105

@@ -116,21 +114,22 @@ public GameUI_Builder dashboard(DashboardID... dashboardIDs) {
116114
public GameUI build() {
117115
validateConfiguration();
118116
configurationByGameVariant.keySet().forEach(gameVariant -> {
119-
Configuration configuration = configuration(gameVariant);
117+
GameConfiguration gameConfiguration = configuration(gameVariant);
120118
GameModel gameModel = createGameModel(
121-
configuration.gameModelClass,
122-
configuration.mapSelector,
119+
gameConfiguration.gameModelClass,
120+
gameConfiguration.mapSelector,
123121
ui.theGameContext(),
124122
highScoreFile(ui.theGameContext().theHomeDir(), gameVariant)
125123
);
126124
gameModel.init();
127125
ui.theGameContext().theGameController().registerGame(gameVariant, gameModel);
128-
ui.applyConfiguration(gameVariant, configuration.uiConfigClass);
129-
if (configuration.startPageClass != null) {
130-
StartPage startPage = createStartPage(gameVariant, configuration.startPageClass);
131-
ui.theStartPagesView().addStartPage(startPage);
132-
}
126+
ui.applyConfiguration(gameVariant, gameConfiguration.uiConfigClass);
133127
});
128+
for (StartPageConfiguration config : startPageConfigs) {
129+
StartPage startPage = createStartPage(config.gameVariants.getFirst(), config.startPageClass);
130+
ui.theStartPagesView().addStartPage(startPage);
131+
132+
}
134133
ui.thePlayView().dashboard().configure(dashboardIDs);
135134

136135
ui.theStartPagesView().selectStartPage(0);

0 commit comments

Comments
 (0)