mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
capture adventure SaveFileData exception to sentry
This commit is contained in:
@@ -5,30 +5,27 @@ import com.badlogic.gdx.graphics.PixmapIO;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import forge.Forge;
|
||||
import io.sentry.Hint;
|
||||
import io.sentry.Sentry;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SaveFileData extends HashMap<String,byte[]>
|
||||
{
|
||||
public void store(String key,SaveFileData subData)
|
||||
{
|
||||
public class SaveFileData extends HashMap<String, byte[]> {
|
||||
public void store(String key, SaveFileData subData) {
|
||||
try {
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
objStream.writeObject(subData);
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
captureException(e, key, subData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void store(String key,float subData)
|
||||
{
|
||||
public void store(String key, float subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -39,8 +36,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void store(String key,double subData)
|
||||
{
|
||||
|
||||
public void store(String key, double subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -51,8 +48,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void store(String key,int subData)
|
||||
{
|
||||
|
||||
public void store(String key, int subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -63,8 +60,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void store(String key,long subData)
|
||||
{
|
||||
|
||||
public void store(String key, long subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -75,8 +72,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void store(String key,boolean subData)
|
||||
{
|
||||
|
||||
public void store(String key, boolean subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -87,8 +84,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void store(String key, Pixmap pixmap)
|
||||
{
|
||||
|
||||
public void store(String key, Pixmap pixmap) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
|
||||
@@ -101,8 +98,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void storeObject(String key,Object subData)
|
||||
{
|
||||
|
||||
public void storeObject(String key, Object subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -110,11 +107,11 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
captureException(e, key, subData);
|
||||
}
|
||||
}
|
||||
public void store(String key,String subData)
|
||||
{
|
||||
|
||||
public void store(String key, String subData) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -122,12 +119,11 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
objStream.flush();
|
||||
put(key, stream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
captureException(e, key, subData);
|
||||
}
|
||||
}
|
||||
|
||||
public void store(String key, Vector2 vector) {
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -139,8 +135,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void store(String key, Rectangle rectangle) {
|
||||
|
||||
public void store(String key, Rectangle rectangle) {
|
||||
try {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(stream);
|
||||
@@ -155,31 +151,26 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
}
|
||||
}
|
||||
|
||||
public SaveFileData readSubData(String key)
|
||||
{
|
||||
public SaveFileData readSubData(String key) {
|
||||
if (!containsKey(key))
|
||||
return null;
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
return (SaveFileData) objStream.readObject();
|
||||
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Object readObject(String key)
|
||||
{
|
||||
|
||||
public Object readObject(String key) {
|
||||
if (!containsKey(key))
|
||||
return null;
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
return objStream.readObject();
|
||||
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Forge.delayedSwitchBack();
|
||||
@@ -188,12 +179,11 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String readString(String key)
|
||||
{
|
||||
|
||||
public String readString(String key) {
|
||||
if (!containsKey(key))
|
||||
return null;
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
return objStream.readUTF();
|
||||
@@ -208,7 +198,6 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
if (!containsKey(key))
|
||||
return 0;
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
return objStream.readLong();
|
||||
@@ -218,12 +207,11 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public float readFloat(String key)
|
||||
{
|
||||
|
||||
public float readFloat(String key) {
|
||||
if (!containsKey(key))
|
||||
return 0.0f;
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
return objStream.readFloat();
|
||||
@@ -234,12 +222,10 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public double readDouble(String key)
|
||||
{
|
||||
public double readDouble(String key) {
|
||||
if (!containsKey(key))
|
||||
return 0.0;
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
return objStream.readDouble();
|
||||
@@ -249,25 +235,23 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
public Vector2 readVector2(String key)
|
||||
{
|
||||
|
||||
public Vector2 readVector2(String key) {
|
||||
if (!containsKey(key))
|
||||
return new Vector2();
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
float x = objStream.readFloat();
|
||||
float y = objStream.readFloat();
|
||||
return new Vector2(x, y);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new Vector2();
|
||||
}
|
||||
public Rectangle readRectangle(String key)
|
||||
{
|
||||
|
||||
public Rectangle readRectangle(String key) {
|
||||
if (!containsKey(key))
|
||||
return new Rectangle();
|
||||
try {
|
||||
@@ -279,7 +263,6 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
float width = objStream.readFloat();
|
||||
float height = objStream.readFloat();
|
||||
return new Rectangle(x, y, width, height);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -287,19 +270,16 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Pixmap readPixmap(String key)
|
||||
{
|
||||
public Pixmap readPixmap(String key) {
|
||||
if (!containsKey(key))
|
||||
return null;
|
||||
return new Pixmap(get(key), 0, get(key).length);
|
||||
}
|
||||
public int readInt(String key)
|
||||
{
|
||||
|
||||
public int readInt(String key) {
|
||||
if (!containsKey(key))
|
||||
return 0;
|
||||
try {
|
||||
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(get(key));
|
||||
ObjectInputStream objStream = new DecompressibleInputStream(stream);
|
||||
return objStream.readInt();
|
||||
@@ -309,8 +289,8 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public boolean readBool(String key)
|
||||
{
|
||||
|
||||
public boolean readBool(String key) {
|
||||
if (!containsKey(key))
|
||||
return false;
|
||||
try {
|
||||
@@ -325,8 +305,12 @@ public class SaveFileData extends HashMap<String,byte[]>
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void captureException(Exception e, String key, Object object) {
|
||||
Hint hint = new Hint();
|
||||
hint.set(key, object);
|
||||
Sentry.captureException(e, hint);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
static class DecompressibleInputStream extends ObjectInputStream {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user