Skip to content

Commit

Permalink
Added concept of promo games, which are those that will be added if n…
Browse files Browse the repository at this point in the history
…ot present in prefs.
  • Loading branch information
lanceewing committed May 9, 2024
1 parent 41e85cf commit 083aa28
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions core/src/main/java/com/agifans/agile/HomeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,6 @@ public HomeScreen(Agile agile, DialogHandler dialogHandler) {
this.dialogHandler = dialogHandler;

AppConfig appConfig = loadAppConfig();
appConfigMap = new TreeMap<String, AppConfigItem>();
for (AppConfigItem appConfigItem : appConfig.getApps()) {
appConfigMap.put(appConfigItem.getName(), appConfigItem);
}

// Convert back from TreeMap, to guarantee ordering on first render.
appConfig = convertAppConfigItemMapToAppConfig(appConfigMap);

buttonTextureMap = new HashMap<String, Texture>();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Expand Down Expand Up @@ -178,6 +171,18 @@ public HomeScreen(Agile agile, DialogHandler dialogHandler) {
landscapeInputProcessor.addProcessor(this);
}

private void addPromoGames(Map<String, AppConfigItem> appConfigMap) {
if (!appConfigMap.containsKey("Let Them Eat Cake")) {
AppConfigItem appConfigItem = new AppConfigItem();
appConfigItem.setGameId("LTEC");
appConfigItem.setName("Let Them Eat Cake");
appConfigItem.setDisplayName("Let Them Eat Cake");
appConfigItem.setFilePath("/games/ltec.zip");
appConfigItem.setFileType("ZIP");
appConfigMap.put(appConfigItem.getName(), appConfigItem);
}
}

private AppConfig loadAppConfig() {
Json json = getJson();
String appConfigJson = null;
Expand All @@ -192,8 +197,18 @@ private AppConfig loadAppConfig() {
appConfigJson = DEFAULT_APP_CONFIG_JSON;
}
}
agile.getPreferences().putString(HOME_SCREEN_APP_LIST_PREF_NAME, appConfigJson);
return json.fromJson(AppConfig.class, appConfigJson);

AppConfig appConfig = json.fromJson(AppConfig.class, appConfigJson);
appConfigMap = new TreeMap<String, AppConfigItem>();
for (AppConfigItem appConfigItem : appConfig.getApps()) {
appConfigMap.put(appConfigItem.getName(), appConfigItem);
}

if (Gdx.app.getType().equals(ApplicationType.WebGL)) {
addPromoGames(appConfigMap);
}

return saveAppConfigMap();
}

private Texture createWhitePixelTexture() {
Expand Down Expand Up @@ -708,11 +723,14 @@ private AppConfig convertAppConfigItemMapToAppConfig(Map<String, AppConfigItem>
/**
* Converts the AppConfigItem Map to JSON and stores in the associated
* preference.
*
* @return The saved AppConfig.
*/
private void saveAppConfigMap() {
private AppConfig saveAppConfigMap() {
AppConfig appConfig = convertAppConfigItemMapToAppConfig(appConfigMap);
String appConfigJson = getJson().prettyPrint(appConfig);
agile.getPreferences().putString(HOME_SCREEN_APP_LIST_PREF_NAME, appConfigJson);
return appConfig;
}

/**
Expand Down

0 comments on commit 083aa28

Please sign in to comment.