mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-26 16:30:52 +01:00
WiredConditionMatchStatePosition now saves as JSON
This commit is contained in:
parent
fe52ad3458
commit
e6a5aaa279
@ -15,6 +15,8 @@ import gnu.trove.set.hash.THashSet;
|
|||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class WiredConditionMatchStatePosition extends InteractionWiredCondition {
|
public class WiredConditionMatchStatePosition extends InteractionWiredCondition {
|
||||||
public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT;
|
public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT;
|
||||||
@ -138,38 +140,42 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getWiredData() {
|
public String getWiredData() {
|
||||||
StringBuilder data = new StringBuilder(this.settings.size() + ":");
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
||||||
|
this.state,
|
||||||
if (this.settings.isEmpty()) {
|
this.position,
|
||||||
data.append("\t;");
|
this.direction,
|
||||||
} else {
|
new ArrayList<>(this.settings)
|
||||||
for (WiredMatchFurniSetting item : this.settings)
|
));
|
||||||
data.append(item.toString()).append(";");
|
|
||||||
}
|
|
||||||
|
|
||||||
data.append(":").append(this.state ? 1 : 0).append(":").append(this.direction ? 1 : 0).append(":").append(this.position ? 1 : 0);
|
|
||||||
|
|
||||||
return data.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
||||||
String[] data = set.getString("wired_data").split(":");
|
String wiredData = set.getString("wired_data");
|
||||||
|
|
||||||
int itemCount = Integer.valueOf(data[0]);
|
if (wiredData.startsWith("{")) {
|
||||||
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
||||||
|
this.state = data.state;
|
||||||
|
this.position = data.position;
|
||||||
|
this.direction = data.direction;
|
||||||
|
this.settings.addAll(data.settings);
|
||||||
|
} else {
|
||||||
|
String[] data = wiredData.split(":");
|
||||||
|
|
||||||
String[] items = data[1].split(";");
|
int itemCount = Integer.parseInt(data[0]);
|
||||||
|
|
||||||
for (int i = 0; i < itemCount; i++) {
|
String[] items = data[1].split(";");
|
||||||
String[] stuff = items[i].split("-");
|
|
||||||
|
|
||||||
if (stuff.length >= 5)
|
for (int i = 0; i < itemCount; i++) {
|
||||||
this.settings.add(new WiredMatchFurniSetting(Integer.valueOf(stuff[0]), stuff[1], Integer.valueOf(stuff[2]), Integer.valueOf(stuff[3]), Integer.valueOf(stuff[4])));
|
String[] stuff = items[i].split("-");
|
||||||
|
|
||||||
|
if (stuff.length >= 5)
|
||||||
|
this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4])));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = data[2].equals("1");
|
||||||
|
this.direction = data[3].equals("1");
|
||||||
|
this.position = data[4].equals("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = data[2].equals("1");
|
|
||||||
this.direction = data[3].equals("1");
|
|
||||||
this.position = data[4].equals("1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -198,4 +204,18 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class JsonData {
|
||||||
|
boolean state;
|
||||||
|
boolean position;
|
||||||
|
boolean direction;
|
||||||
|
List<WiredMatchFurniSetting> settings;
|
||||||
|
|
||||||
|
public JsonData(boolean state, boolean position, boolean direction, List<WiredMatchFurniSetting> settings) {
|
||||||
|
this.state = state;
|
||||||
|
this.position = position;
|
||||||
|
this.direction = direction;
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user