mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
announce savefile error
This commit is contained in:
@@ -12,6 +12,7 @@ import java.io.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SaveFileData extends HashMap<String, byte[]> {
|
||||
public boolean hasError = false;
|
||||
public void store(String key, SaveFileData subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
@@ -20,6 +21,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
captureException(e, key, subData);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +35,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -45,6 +48,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -57,6 +61,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -69,6 +74,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -81,6 +87,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -95,6 +102,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
stream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -107,6 +115,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
captureException(e, key, subData);
|
||||
}
|
||||
}
|
||||
@@ -119,6 +128,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
captureException(e, key, subData);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +142,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -147,6 +158,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
hasError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,53 +26,50 @@ import java.util.zip.InflaterInputStream;
|
||||
/**
|
||||
* Represents everything that will be saved, like the player and the world.
|
||||
*/
|
||||
public class WorldSave {
|
||||
public class WorldSave {
|
||||
|
||||
static final public int AUTO_SAVE_SLOT =-1;
|
||||
static final public int QUICK_SAVE_SLOT =-2;
|
||||
static final public int INVALID_SAVE_SLOT =-3;
|
||||
static final WorldSave currentSave=new WorldSave();
|
||||
static final public int AUTO_SAVE_SLOT = -1;
|
||||
static final public int QUICK_SAVE_SLOT = -2;
|
||||
static final public int INVALID_SAVE_SLOT = -3;
|
||||
static final WorldSave currentSave = new WorldSave();
|
||||
public WorldSaveHeader header = new WorldSaveHeader();
|
||||
private final AdventurePlayer player=new AdventurePlayer();
|
||||
private final World world=new World();
|
||||
private final PointOfInterestChanges.Map pointOfInterestChanges= new PointOfInterestChanges.Map();
|
||||
private final AdventurePlayer player = new AdventurePlayer();
|
||||
private final World world = new World();
|
||||
private final PointOfInterestChanges.Map pointOfInterestChanges = new PointOfInterestChanges.Map();
|
||||
|
||||
|
||||
private final SignalList onLoadList=new SignalList();
|
||||
private final SignalList onLoadList = new SignalList();
|
||||
|
||||
public final World getWorld()
|
||||
{
|
||||
public final World getWorld() {
|
||||
return world;
|
||||
}
|
||||
public AdventurePlayer getPlayer()
|
||||
{
|
||||
|
||||
public AdventurePlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void onLoad(Runnable run)
|
||||
{
|
||||
public void onLoad(Runnable run) {
|
||||
onLoadList.add(run);
|
||||
}
|
||||
public PointOfInterestChanges getPointOfInterestChanges(String id)
|
||||
{
|
||||
if(!pointOfInterestChanges.containsKey(id))
|
||||
pointOfInterestChanges.put(id,new PointOfInterestChanges());
|
||||
|
||||
public PointOfInterestChanges getPointOfInterestChanges(String id) {
|
||||
if (!pointOfInterestChanges.containsKey(id))
|
||||
pointOfInterestChanges.put(id, new PointOfInterestChanges());
|
||||
return pointOfInterestChanges.get(id);
|
||||
}
|
||||
|
||||
static public boolean load(int currentSlot) {
|
||||
|
||||
String fileName = WorldSave.getSaveFile(currentSlot);
|
||||
if(!new File(fileName).exists())
|
||||
if (!new File(fileName).exists())
|
||||
return false;
|
||||
new File(getSaveDir()).mkdirs();
|
||||
try {
|
||||
try(FileInputStream fos = new FileInputStream(fileName);
|
||||
InflaterInputStream inf = new InflaterInputStream(fos);
|
||||
ObjectInputStream oos = new ObjectInputStream(inf))
|
||||
{
|
||||
try (FileInputStream fos = new FileInputStream(fileName);
|
||||
InflaterInputStream inf = new InflaterInputStream(fos);
|
||||
ObjectInputStream oos = new ObjectInputStream(inf)) {
|
||||
currentSave.header = (WorldSaveHeader) oos.readObject();
|
||||
SaveFileData mainData=(SaveFileData)oos.readObject();
|
||||
SaveFileData mainData = (SaveFileData) oos.readObject();
|
||||
currentSave.player.load(mainData.readSubData("player"));
|
||||
GamePlayerUtil.getGuiPlayer().setName(currentSave.player.getName());
|
||||
try {
|
||||
@@ -95,9 +92,11 @@ public class WorldSave {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isSafeFile(String name) {
|
||||
return filenameToSlot(name)!= INVALID_SAVE_SLOT;
|
||||
return filenameToSlot(name) != INVALID_SAVE_SLOT;
|
||||
}
|
||||
|
||||
static public int filenameToSlot(String name) {
|
||||
if (name.equals("auto_save.sav"))
|
||||
return AUTO_SAVE_SLOT;
|
||||
@@ -131,10 +130,10 @@ public class WorldSave {
|
||||
public static WorldSave generateNewWorld(String name, boolean male, int race, int avatarIndex, ColorSet startingColorIdentity, DifficultyData diff, AdventureModes mode, int customDeckIndex, CardEdition starterEdition, long seed) {
|
||||
currentSave.world.generateNew(seed);
|
||||
currentSave.pointOfInterestChanges.clear();
|
||||
boolean chaos=mode==AdventureModes.Chaos;
|
||||
boolean custom=mode==AdventureModes.Custom;
|
||||
Deck starterDeck = Config.instance().starterDeck(startingColorIdentity,diff,mode,customDeckIndex,starterEdition);
|
||||
currentSave.player.create(name, starterDeck, male, race, avatarIndex, chaos, custom, diff);
|
||||
boolean chaos = mode == AdventureModes.Chaos;
|
||||
boolean custom = mode == AdventureModes.Custom;
|
||||
Deck starterDeck = Config.instance().starterDeck(startingColorIdentity, diff, mode, customDeckIndex, starterEdition);
|
||||
currentSave.player.create(name, starterDeck, male, race, avatarIndex, chaos, custom, diff);
|
||||
currentSave.player.setWorldPosY((int) (currentSave.world.getData().playerStartPosY * currentSave.world.getData().height * currentSave.world.getTileSize()));
|
||||
currentSave.player.setWorldPosX((int) (currentSave.world.getData().playerStartPosX * currentSave.world.getData().width * currentSave.world.getTileSize()));
|
||||
currentSave.onLoadList.emit();
|
||||
@@ -142,14 +141,17 @@ public class WorldSave {
|
||||
}
|
||||
|
||||
public boolean autoSave() {
|
||||
return save("auto save"+ SaveLoadScene.instance().getSaveFileSuffix(),AUTO_SAVE_SLOT);
|
||||
return save("auto save" + SaveLoadScene.instance().getSaveFileSuffix(), AUTO_SAVE_SLOT);
|
||||
}
|
||||
|
||||
public boolean quickSave() {
|
||||
return save("quick save"+ SaveLoadScene.instance().getSaveFileSuffix(),QUICK_SAVE_SLOT);
|
||||
return save("quick save" + SaveLoadScene.instance().getSaveFileSuffix(), QUICK_SAVE_SLOT);
|
||||
}
|
||||
|
||||
public boolean quickLoad() {
|
||||
return load(QUICK_SAVE_SLOT);
|
||||
}
|
||||
|
||||
public boolean save(String text, int currentSlot) {
|
||||
header.name = text;
|
||||
|
||||
@@ -157,18 +159,29 @@ public class WorldSave {
|
||||
new File(getSaveDir()).mkdirs();
|
||||
|
||||
try {
|
||||
try(FileOutputStream fos = new FileOutputStream(fileName);
|
||||
DeflaterOutputStream def= new DeflaterOutputStream(fos);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(def))
|
||||
{
|
||||
header.saveDate= new Date();
|
||||
oos.writeObject(header);
|
||||
SaveFileData mainData=new SaveFileData();
|
||||
mainData.store("player",currentSave.player.save());
|
||||
mainData.store("world",currentSave.world.save());
|
||||
mainData.store("worldStage", WorldStage.getInstance().save());
|
||||
mainData.store("pointOfInterestChanges",currentSave.pointOfInterestChanges.save());
|
||||
try (FileOutputStream fos = new FileOutputStream(fileName);
|
||||
DeflaterOutputStream def = new DeflaterOutputStream(fos);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(def)) {
|
||||
SaveFileData player = currentSave.player.save();
|
||||
SaveFileData world = currentSave.world.save();
|
||||
SaveFileData worldStage = WorldStage.getInstance().save();
|
||||
SaveFileData poiChanges = currentSave.pointOfInterestChanges.save();
|
||||
|
||||
if (player.hasError || world.hasError || worldStage.hasError || poiChanges.hasError) {
|
||||
announceError();
|
||||
return false;
|
||||
}
|
||||
|
||||
SaveFileData mainData = new SaveFileData();
|
||||
mainData.store("player", player);
|
||||
mainData.store("world", world);
|
||||
mainData.store("worldStage", worldStage);
|
||||
mainData.store("pointOfInterestChanges", poiChanges);
|
||||
if (mainData.hasError) {
|
||||
announceError();
|
||||
}
|
||||
header.saveDate = new Date();
|
||||
oos.writeObject(header);
|
||||
oos.writeObject(mainData);
|
||||
}
|
||||
|
||||
@@ -182,6 +195,10 @@ public class WorldSave {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void announceError() {
|
||||
currentSave.player.getCurrentGameStage().setExtraAnnouncement("Error Saving File!\nPlease check forge.log");
|
||||
}
|
||||
|
||||
public void clearChanges() {
|
||||
pointOfInterestChanges.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user