mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
announce savefile error
This commit is contained in:
@@ -12,6 +12,7 @@ import java.io.*;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class SaveFileData extends HashMap<String, byte[]> {
|
public class SaveFileData extends HashMap<String, byte[]> {
|
||||||
|
public boolean hasError = false;
|
||||||
public void store(String key, SaveFileData subData) {
|
public void store(String key, SaveFileData subData) {
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
@@ -20,6 +21,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
captureException(e, key, subData);
|
captureException(e, key, subData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,6 +35,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +48,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,6 +61,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,6 +74,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +87,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,6 +102,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
stream.flush();
|
stream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,6 +115,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
captureException(e, key, subData);
|
captureException(e, key, subData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +128,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
captureException(e, key, subData);
|
captureException(e, key, subData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,6 +142,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,6 +158,7 @@ public class SaveFileData extends HashMap<String, byte[]> {
|
|||||||
objStream.flush();
|
objStream.flush();
|
||||||
put(key, stream.toByteArray());
|
put(key, stream.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
hasError = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,21 +40,19 @@ public class WorldSave {
|
|||||||
|
|
||||||
private final SignalList onLoadList = new SignalList();
|
private final SignalList onLoadList = new SignalList();
|
||||||
|
|
||||||
public final World getWorld()
|
public final World getWorld() {
|
||||||
{
|
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
public AdventurePlayer getPlayer()
|
|
||||||
{
|
public AdventurePlayer getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLoad(Runnable run)
|
public void onLoad(Runnable run) {
|
||||||
{
|
|
||||||
onLoadList.add(run);
|
onLoadList.add(run);
|
||||||
}
|
}
|
||||||
public PointOfInterestChanges getPointOfInterestChanges(String id)
|
|
||||||
{
|
public PointOfInterestChanges getPointOfInterestChanges(String id) {
|
||||||
if (!pointOfInterestChanges.containsKey(id))
|
if (!pointOfInterestChanges.containsKey(id))
|
||||||
pointOfInterestChanges.put(id, new PointOfInterestChanges());
|
pointOfInterestChanges.put(id, new PointOfInterestChanges());
|
||||||
return pointOfInterestChanges.get(id);
|
return pointOfInterestChanges.get(id);
|
||||||
@@ -69,8 +67,7 @@ public class WorldSave {
|
|||||||
try {
|
try {
|
||||||
try (FileInputStream fos = new FileInputStream(fileName);
|
try (FileInputStream fos = new FileInputStream(fileName);
|
||||||
InflaterInputStream inf = new InflaterInputStream(fos);
|
InflaterInputStream inf = new InflaterInputStream(fos);
|
||||||
ObjectInputStream oos = new ObjectInputStream(inf))
|
ObjectInputStream oos = new ObjectInputStream(inf)) {
|
||||||
{
|
|
||||||
currentSave.header = (WorldSaveHeader) oos.readObject();
|
currentSave.header = (WorldSaveHeader) oos.readObject();
|
||||||
SaveFileData mainData = (SaveFileData) oos.readObject();
|
SaveFileData mainData = (SaveFileData) oos.readObject();
|
||||||
currentSave.player.load(mainData.readSubData("player"));
|
currentSave.player.load(mainData.readSubData("player"));
|
||||||
@@ -95,9 +92,11 @@ public class WorldSave {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSafeFile(String name) {
|
public static boolean isSafeFile(String name) {
|
||||||
return filenameToSlot(name) != INVALID_SAVE_SLOT;
|
return filenameToSlot(name) != INVALID_SAVE_SLOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public int filenameToSlot(String name) {
|
static public int filenameToSlot(String name) {
|
||||||
if (name.equals("auto_save.sav"))
|
if (name.equals("auto_save.sav"))
|
||||||
return AUTO_SAVE_SLOT;
|
return AUTO_SAVE_SLOT;
|
||||||
@@ -144,12 +143,15 @@ public class WorldSave {
|
|||||||
public boolean autoSave() {
|
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() {
|
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() {
|
public boolean quickLoad() {
|
||||||
return load(QUICK_SAVE_SLOT);
|
return load(QUICK_SAVE_SLOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean save(String text, int currentSlot) {
|
public boolean save(String text, int currentSlot) {
|
||||||
header.name = text;
|
header.name = text;
|
||||||
|
|
||||||
@@ -159,16 +161,27 @@ public class WorldSave {
|
|||||||
try {
|
try {
|
||||||
try (FileOutputStream fos = new FileOutputStream(fileName);
|
try (FileOutputStream fos = new FileOutputStream(fileName);
|
||||||
DeflaterOutputStream def = new DeflaterOutputStream(fos);
|
DeflaterOutputStream def = new DeflaterOutputStream(fos);
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(def))
|
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();
|
header.saveDate = new Date();
|
||||||
oos.writeObject(header);
|
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());
|
|
||||||
|
|
||||||
oos.writeObject(mainData);
|
oos.writeObject(mainData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +195,10 @@ public class WorldSave {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void announceError() {
|
||||||
|
currentSave.player.getCurrentGameStage().setExtraAnnouncement("Error Saving File!\nPlease check forge.log");
|
||||||
|
}
|
||||||
|
|
||||||
public void clearChanges() {
|
public void clearChanges() {
|
||||||
pointOfInterestChanges.clear();
|
pointOfInterestChanges.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user