Skip to content

Commit

Permalink
Merge pull request #48 from ghostlypi/serial
Browse files Browse the repository at this point in the history
Serializer
  • Loading branch information
aehmttw authored Nov 24, 2024
2 parents d0b6c58 + e18b8a3 commit 5e274cc
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 236 deletions.
14 changes: 0 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,6 @@ tasks.jar {
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
}

tasks.jar {
archiveBaseName.set("Tanks")
archiveClassifier.set("")

duplicatesStrategy = DuplicatesStrategy.EXCLUDE

manifest {
from("src/main/java/META-INF/MANIFEST.MF")
}

// If you have dependencies that need to be included in the JAR
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
}

tasks.register<JavaExec>("run") {
description = "Runs the JAR file"
group = "application" // This puts the task in the "application" group in Gradle tasks list
Expand Down
16 changes: 0 additions & 16 deletions makefile

This file was deleted.

1 change: 0 additions & 1 deletion runConfigurations/Run.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</option>
<option name="taskNames">
<list>
<option value="clean" />
<option value="build" />
<option value="run" />
</list>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/basewindow/Model.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package basewindow;

import basewindow.transformation.AxisRotation;
import tanks.Drawing;
import tanks.tankson.Serializable;

import java.util.ArrayList;
import java.util.HashMap;

public class Model implements IModel
public class Model implements IModel, Serializable
{
public static Material defaultMaterial = new Material("");

Expand Down Expand Up @@ -493,4 +495,9 @@ public String toString()
{
return this.file;
}

public String serialize(){ return this.toString(); }
public Serializable deserialize(String s) {
return Drawing.drawing.createModel(s);
}
}
1 change: 0 additions & 1 deletion src/main/java/tanks/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ else if (ScreenPartyLobby.isClient)
{
customTanksMap.put(t.name, t);
}

ArrayList<EventTankPlayerCreate> playerEvents = new ArrayList<>();

Tank.currentID = 0;
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/tanks/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import tanks.bullet.DefaultBullets;
import tanks.tank.Tank;
import tanks.tank.TankPlayerRemote;
import tanks.tankson.ICopyable;
import tanks.tankson.Property;
import tanks.tankson.TanksON;
import tanks.tankson.TanksONable;
import tanks.tankson.*;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -60,15 +57,15 @@ public ShopItem()

public String toString()
{
return TanksON.objectToString(this);
return Serializer.toTanksON(this);
}

public static ShopItem fromString(String s)
{
if (!s.startsWith("{"))
return fromStringLegacy(s);

return (ShopItem) TanksON.parseObject(s);
return (ShopItem) Serializer.fromTanksON(s);
}

@Deprecated
Expand Down Expand Up @@ -107,7 +104,7 @@ public static CrusadeShopItem fromString(String s)
if (!s.startsWith("{"))
return fromStringLegacy(s);

return (CrusadeShopItem) TanksON.parseObject(s);
return (CrusadeShopItem) Serializer.fromTanksON(s);
}

@Deprecated
Expand Down Expand Up @@ -264,7 +261,7 @@ public static ItemStack<?> fromString(Player p, String s)
if (!s.startsWith("{"))
return fromStringLegacy(p, s);

ItemStack<?> i = (ItemStack<?>) TanksON.parseObject(s);
ItemStack<?> i = (ItemStack<?>) Serializer.fromTanksON(s);
i.player = p;
return i;
}
Expand Down Expand Up @@ -424,7 +421,7 @@ else if (i instanceof ItemShield)
@Override
public String toString()
{
return TanksON.objectToString(this);
return Serializer.toTanksON(this);
}
}

Expand Down Expand Up @@ -463,11 +460,11 @@ public String toString()
//
// return null;

return TanksON.objectToString(this);
return Serializer.toTanksON(this);
}

public static Item fromString(String s)
{
return (Item) TanksON.parseObject(s);
return (Item) Serializer.fromTanksON(s);
}
}
11 changes: 11 additions & 0 deletions src/main/java/tanks/network/SteamNetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ public boolean load()
this.initialized = true;
return true;
}
catch (SteamException e)
{
if (e.getMessage().equals("Native libraries not loaded.\n" +
"Ensure to call SteamAPI.loadLibraries() first!")) {
System.out.println("Running without SteamAPI: Non-Steam Build");
return false;
} else {
e.printStackTrace();
return false;
}
}
catch (Throwable e)
{
e.printStackTrace();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/tanks/tank/ITankField.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tanks.tank;

import tanks.tankson.ITanksONEditable;
import tanks.tankson.TanksONable;

@TanksONable("itank_field")
public interface ITankField extends ITanksONEditable
{
Tank resolve();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tanks/tank/Mine.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public double[] getLightInfo()
@Override
public String toString()
{
return TanksON.objectToString(this);
return Serializer.toTanksON(this);
}

@Override
Expand Down
54 changes: 9 additions & 45 deletions src/main/java/tanks/tank/TankAIControlled.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import tanks.obstacle.ObstacleTeleporter;
import tanks.registry.RegistryTank;
import tanks.tankson.Property;
import tanks.tankson.TanksON;
import tanks.tankson.Serializer;
import tanks.tankson.TanksONable;

import java.lang.reflect.Field;
import java.util.*;

import static java.lang.System.exit;
import static tanks.tank.TankPropertyCategory.*;

/** This class is the 'skeleton' tank class.
Expand Down Expand Up @@ -264,7 +265,7 @@ public SpawnedTankEntry(ITankField t, double weight)

public String toString()
{
return TanksON.objectToString(this);
return Serializer.toTanksON(this);
}
}

Expand Down Expand Up @@ -2947,53 +2948,13 @@ public void draw()
@Override
public String toString()
{
if (fromRegistry)
return "<" + this.name + ">";

return TanksON.objectToString(this);
// try
// {
// StringBuilder s = new StringBuilder("[");
//
// for (Field f : this.getClass().getFields())
// {
// Property a = f.getAnnotation(Property.class);
// if (a != null)
// {
// s.append(a.id());
// s.append("=");
//
// if (f.get(this) != null)
// {
// if (a.miscType() == Property.MiscType.description)
// {
// String desc = (String) f.get(this);
// s.append("<").append(desc.length()).append(">").append(desc);
// }
// else
// s.append(f.get(this));
// }
// else
// s.append("*");
//
// s.append(";");
// }
// }
//
// return s.append("]").toString();
// }
// catch (Exception e)
// {
// Game.exitToCrash(e);
// }
//
// return null;
return Serializer.toTanksON(this);
}

public static TankAIControlled fromString(String s)
{
if (s.startsWith("{"))
return (TankAIControlled) TanksON.parseObject(s);
return (TankAIControlled) Serializer.fromTanksON(s);
else
return fromStringLegacy(s, null);
}
Expand Down Expand Up @@ -3230,7 +3191,10 @@ else if (a.miscType() == Property.MiscType.spawnedTanks)
}
else if (a.miscType() == Property.MiscType.music)
{
f.set(t, new HashSet<>((HashSet<String>) f.get(this)));
if (f.get(this) != null)
f.set(t, new HashSet<>((HashSet<String>) f.get(this)));
else
f.set(t, new HashSet<>());
}
else
f.set(t, f.get(this));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/tanks/tankson/Serializable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tanks.tankson;

public interface Serializable {
public String serialize();
public Serializable deserialize(String s);
}
Loading

0 comments on commit 5e274cc

Please sign in to comment.