Skip to content

Commit

Permalink
made spawn stations work
Browse files Browse the repository at this point in the history
  • Loading branch information
Steampunkery committed Dec 21, 2017
1 parent 9efb5ac commit 8cd615b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
19 changes: 12 additions & 7 deletions engine/src/main/java/org/destinationsol/assets/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
*/
package org.destinationsol.assets;

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

import org.destinationsol.assets.audio.OggMusic;
import org.destinationsol.assets.audio.OggSound;
import org.destinationsol.assets.emitters.Emitter;
Expand All @@ -26,11 +32,8 @@
import org.terasology.assets.ResourceUrn;
import org.terasology.module.ModuleEnvironment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;

/**
* A high-level wrapper over the AssetHelper class.
Expand All @@ -40,6 +43,8 @@
public abstract class Assets {
private static AssetHelper assetHelper;
private static Set<ResourceUrn> textureList;
// 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>();

/**
* Initializes the class for loading assets using the given environment.
Expand Down
24 changes: 19 additions & 5 deletions engine/src/main/java/org/destinationsol/game/GalaxyFiller.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.destinationsol.game;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.JsonValue;
import java.util.ArrayList;

import org.destinationsol.Const;
import org.destinationsol.assets.Assets;
import org.destinationsol.assets.json.Json;
Expand All @@ -39,7 +39,9 @@
import org.destinationsol.game.ship.FarShip;
import org.destinationsol.game.ship.hulls.HullConfig;

import java.util.ArrayList;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.JsonValue;
import com.google.gson.JsonParseException;

public class GalaxyFiller {
private static final float STATION_CONSUME_SECTOR = 45f;
Expand Down Expand Up @@ -120,6 +122,15 @@ private FarShip build(SolGame game, ShipConfig cfg, Faction faction, boolean mai
}
return s;
}

public JsonValue checkRootNull(Json json) {
JsonValue node = json.getJsonValue();
if (node.isNull()) {
throw new JsonParseException(String.format("Root node was not found in asset %s", node.name, json.toString()));
} else {
return node;
}
}

public void fill(SolGame game, HullConfigManager hullConfigManager, ItemManager itemManager) {
if (DebugOptions.NO_OBJS) {
Expand All @@ -128,8 +139,11 @@ public void fill(SolGame game, HullConfigManager hullConfigManager, ItemManager
createStarPorts(game);
ArrayList<SolSystem> systems = game.getPlanetMan().getSystems();

Json json = Assets.getJson("engine:mainStationConfig");
JsonValue rootNode = json.getJsonValue();
String moduleName = Assets.playerSpawnConfigIdMap.get(game.getShipName());
moduleName = moduleName.split(":")[0];

Json json = Assets.getJson(moduleName + ":startingStation");
JsonValue rootNode = checkRootNull(json);

ShipConfig mainStationCfg = ShipConfig.load(hullConfigManager, rootNode, itemManager);

Expand Down
10 changes: 10 additions & 0 deletions engine/src/main/java/org/destinationsol/game/SolGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class SolGame {
private final GalaxyFiller galaxyFiller;
private final ArrayList<SolItem> respawnItems;
private SolShip hero;
private String shipName; // Not updated in-game. Can be changed using setter
private float timeStep;
private float time;
private boolean paused;
Expand Down Expand Up @@ -136,6 +137,7 @@ public SolGame(SolApplication cmp, String shipName, boolean tut, CommonDrawer co
mountDetectDrawer = new MountDetectDrawer();
respawnItems = new ArrayList<>();
timeFactor = 1;
this.shipName = shipName;

// from this point we're ready!
planetManager.fill(solNames);
Expand Down Expand Up @@ -517,6 +519,14 @@ public MountDetectDrawer getMountDetectDrawer() {
public TutorialManager getTutMan() {
return tutorialManager;
}

public String getShipName() {
return shipName;
}

public void setShipName(String newName) {
shipName = newName;
}

public void beforeHeroDeath() {
if (hero == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private void loadPlayerSpawnConfigs() {

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

json.dispose();
Expand Down

0 comments on commit 8cd615b

Please sign in to comment.