Skip to content

Commit

Permalink
moved things to SolGame because its more relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
Steampunkery committed Dec 21, 2017
1 parent e5d0407 commit 65e0677
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.destinationsol.game.planet.SysConfig;
import org.destinationsol.game.ship.FarShip;
import org.destinationsol.game.ship.hulls.HullConfig;
import org.destinationsol.menu.NewShipScreen;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.JsonValue;
Expand Down Expand Up @@ -140,7 +139,10 @@ public void fill(SolGame game, HullConfigManager hullConfigManager, ItemManager
createStarPorts(game);
ArrayList<SolSystem> systems = game.getPlanetMan().getSystems();

String moduleName = NewShipScreen.playerSpawnConfigIdMap.get(game.getShipName());
// Associates each ship with it's module
game.getShipsModules();

String moduleName = game.playerSpawnConfigIdMap.get(game.getShipName());
moduleName = moduleName.split(":")[0];

Json json = Assets.getJson(moduleName + ":startingStation");
Expand Down
26 changes: 26 additions & 0 deletions engine/src/main/java/org/destinationsol/game/SolGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.JsonValue;

import org.destinationsol.CommonDrawer;
import org.destinationsol.Const;
import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.assets.Assets;
import org.destinationsol.assets.json.Json;
import org.destinationsol.common.DebugCol;
import org.destinationsol.common.SolMath;
import org.destinationsol.files.HullConfigManager;
Expand Down Expand Up @@ -57,9 +61,13 @@
import org.destinationsol.ui.DebugCollector;
import org.destinationsol.ui.TutorialManager;
import org.destinationsol.ui.UiDrawer;
import org.terasology.assets.ResourceUrn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SolGame {
private final GameScreens gameScreens;
Expand Down Expand Up @@ -100,6 +108,9 @@ public class SolGame {
private float timeFactor;
private float respawnMoney;
private HullConfig respawnHull;

// This map is initialized after the player selects their ship, it maps the human readable names of ships to their internal URIs
public Map<String, String> playerSpawnConfigIdMap = new HashMap<String, String>();

public SolGame(SolApplication cmp, String shipName, boolean tut, CommonDrawer commonDrawer) {
solApplication = cmp;
Expand Down Expand Up @@ -205,6 +216,21 @@ private void createPlayer(String shipName) {
objectManager.addObjDelayed(hero);
objectManager.resetDelays();
}

public void getShipsModules() {
Set<ResourceUrn> configUrnList = Assets.getAssetHelper().list(Json.class, "[a-z]*:playerSpawnConfig");

for (ResourceUrn configUrn : configUrnList) {
Json json = Assets.getJson(configUrn.toString());
JsonValue rootNode = json.getJsonValue();

for (JsonValue node : rootNode) {
playerSpawnConfigIdMap.put(node.name, node.getString("hull"));
}

json.dispose();
}
}

public void onGameEnd() {
saveShip();
Expand Down
18 changes: 7 additions & 11 deletions engine/src/main/java/org/destinationsol/menu/NewShipScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

package org.destinationsol.menu;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.JsonValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.destinationsol.GameOptions;
import org.destinationsol.SolApplication;
import org.destinationsol.assets.Assets;
Expand All @@ -32,11 +33,9 @@
import org.destinationsol.ui.UiDrawer;
import org.terasology.assets.ResourceUrn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.JsonValue;

public class NewShipScreen implements SolUiScreen {
private final TextureAtlas.AtlasRegion bgTex;
Expand All @@ -48,8 +47,6 @@ public class NewShipScreen implements SolUiScreen {
private SolUiControl playerSpawnConfigControl;
private int playerSpawnConfigIndex = 0;
private List<String> playerSpawnConfigNames = new ArrayList<>();
// This map is initialized after the player selects their ship, it maps the human readable names of ships to their internal URIs
public static Map<String, String> playerSpawnConfigIdMap = new HashMap<String, String>();

NewShipScreen(MenuLayout menuLayout, GameOptions gameOptions) {
loadPlayerSpawnConfigs();
Expand Down Expand Up @@ -125,7 +122,6 @@ private void loadPlayerSpawnConfigs() {

for (JsonValue node : rootNode) {
playerSpawnConfigNames.add(node.name);
playerSpawnConfigIdMap.put(node.name, node.getString("hull"));
}

json.dispose();
Expand Down

0 comments on commit 65e0677

Please sign in to comment.