Skip to content

Commit

Permalink
move savestate into a saves directory
Browse files Browse the repository at this point in the history
  • Loading branch information
gilmore606 committed Jul 20, 2018
1 parent 639bfd0 commit 1f3de34
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ build/
# URE
*.region
*.area
saves/*

17 changes: 14 additions & 3 deletions src/main/java/ure/areas/UCartographer.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public boolean accept(File dir, String name) {
* @return the region
*/
protected URegion loadRegion(File file) {
String path = commander.savePath();
try (
FileInputStream stream = new FileInputStream(file);
FileInputStream stream = new FileInputStream(path + file);
GZIPInputStream gzip = new GZIPInputStream(stream)
) {
return objectMapper.readValue(gzip, URegion.class);
Expand Down Expand Up @@ -163,6 +164,14 @@ public UArea getStartArea() {
return getArea(startArea);
}

/**
* Get the name of the current world. By default this is used to name the savestate file.
* @return
*/
public String worldName() {
return null;
}

public void setStartArea(String label) {
startArea = label;
}
Expand All @@ -182,7 +191,8 @@ protected UArea FetchArea(String label, String labelname, int labeldata) {
return area;

if (commander.config.isPersistentAreas()) {
File file = new File(label + ".area");
String path = commander.savePath();
File file = new File(path + label + ".area");
try (
FileInputStream stream = new FileInputStream(file);
GZIPInputStream gzip = new GZIPInputStream(stream)
Expand All @@ -207,8 +217,9 @@ protected UArea FetchArea(String label, String labelname, int labeldata) {
* @param filename
*/
protected void persist(Object object, String filename) {
String path = commander.savePath();
if (commander.config.isPersistentAreas()) {
File file = new File(filename);
File file = new File(path + filename);
try (
FileOutputStream stream = new FileOutputStream(file);
GZIPOutputStream gzip = new GZIPOutputStream(stream)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ure/examplegame/ExampleGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public void startUp() {

player = new UPlayer("Player", '@', UColor.COLOR_WHITE, true, new UColor(0.3f, 0.3f, 0.6f), 3, 4);
cartographer = new ExampleCartographer();
commander.registerComponents(player, renderer, thingCzar, actorCzar, cartographer);
cartographer.setupRegions();
cartographer.startLoader();
commander.registerComponents(player, renderer, thingCzar, actorCzar, cartographer);

area = cartographer.getStartArea();

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ure/sys/UCommander.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ public void detachModal(UModal modal) {
}
}

/**
* Get the filesystem path to the current savestate (the world we're playing now), or the top level save path.
* @return
*/
public String savePath() {
String world = cartographer.worldName();
if (world == null)
return config.getSavePath();
else
return config.getSavePath() + world + "/";
}

void launchVaulted() {
File dirfile = new File(config.getResourcePath() + "vaults/");
ArrayList<String> filelist = new ArrayList<>();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ure/sys/UConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class UConfig {
// Game functionality

private String resourcePath = "src/main/resources/"; // path to resource files
private String savePath = "saves/"; // path to game save files

private boolean backgroundLoader = true; // load and save areas in the background?
private boolean persistentAreas = true; // persist and recover generated areas?
private boolean runNeighborAreas = true; // keep areas we just left awake?
Expand Down Expand Up @@ -432,6 +434,8 @@ public void setLightHueToActors(float lightHueToActors) {

public String getResourcePath() { return resourcePath; }
public void setResourcePath(String path) { resourcePath = path; }
public String getSavePath() { return savePath; }
public void setSavePath(String path) { savePath = path; }

public boolean isPersistentAreas() {
return persistentAreas;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ure/ui/modals/UModalURESplash.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class UModalURESplash extends UModal {

public UModalURESplash() {
super(null, "", UColor.COLOR_BLACK);
logo = new RexFile("ure_logo.xp");
logo = new RexFile("src/main/resources/ure_logo.xp");
alpha = 0f;
}

Expand Down
File renamed without changes.

0 comments on commit 1f3de34

Please sign in to comment.