2021-04-18 09:10:30 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of the SteamWar software.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.steamwar.bausystem.region;
|
|
|
|
|
2021-12-22 14:05:44 +01:00
|
|
|
import lombok.AllArgsConstructor;
|
2021-04-18 15:34:31 +02:00
|
|
|
import lombok.Getter;
|
2021-04-18 15:17:05 +02:00
|
|
|
import yapion.hierarchy.types.YAPIONObject;
|
2021-04-18 15:48:15 +02:00
|
|
|
import yapion.hierarchy.types.YAPIONType;
|
2021-04-18 15:17:05 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
2021-04-18 15:22:18 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2021-04-18 15:17:05 +02:00
|
|
|
|
2021-04-18 15:34:31 +02:00
|
|
|
@Getter
|
2021-04-18 09:10:30 +02:00
|
|
|
public class Prototype {
|
2021-04-18 15:17:05 +02:00
|
|
|
|
2021-04-18 17:34:02 +02:00
|
|
|
static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
|
2021-12-22 14:05:44 +01:00
|
|
|
|
2021-07-04 20:49:44 +02:00
|
|
|
public static Prototype getByName(String name) {
|
|
|
|
return PROTOTYPE_MAP.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Prototype getByDisplayName(String name) {
|
|
|
|
return PROTOTYPE_MAP.values().stream().filter(prototype -> prototype.getDisplayName().equals(name)).findFirst().orElse(null);
|
|
|
|
}
|
2021-04-18 15:22:18 +02:00
|
|
|
|
2021-12-22 14:05:44 +01:00
|
|
|
@AllArgsConstructor
|
|
|
|
@Getter
|
|
|
|
public static class Skin {
|
|
|
|
private final String name;
|
2021-12-23 15:52:29 +01:00
|
|
|
private final String creator; // Nullable
|
2021-12-22 14:05:44 +01:00
|
|
|
private final File schematicFile;
|
|
|
|
private final File testblockSchematicFile; // Nullable
|
|
|
|
private final File buildSchematicFile; // Nullable
|
|
|
|
}
|
|
|
|
|
2021-04-18 15:22:18 +02:00
|
|
|
private final String name;
|
|
|
|
private final String displayName;
|
2021-12-22 14:05:44 +01:00
|
|
|
private final String defaultSkin;
|
|
|
|
private final Map<String, Skin> skinMap = new HashMap<>();
|
2021-04-18 15:22:18 +02:00
|
|
|
|
2021-04-18 15:17:05 +02:00
|
|
|
private final int sizeX;
|
|
|
|
private final int sizeY;
|
|
|
|
private final int sizeZ;
|
|
|
|
|
|
|
|
private final int floorOffset;
|
|
|
|
private final int waterOffset;
|
|
|
|
|
2021-04-18 15:48:15 +02:00
|
|
|
private final SubPrototype testblock; // Nullable
|
|
|
|
private final SubPrototype build; // Nullable
|
2021-04-18 15:17:05 +02:00
|
|
|
|
2021-05-03 16:32:44 +02:00
|
|
|
private final int copyPointOffsetX;
|
|
|
|
private final int copyPointOffsetY;
|
|
|
|
private final int copyPointOffsetZ;
|
|
|
|
|
2021-04-18 15:22:18 +02:00
|
|
|
public Prototype(String name, YAPIONObject yapionObject) {
|
|
|
|
this.name = name;
|
|
|
|
displayName = yapionObject.getPlainValueOrDefault("displayName", name);
|
|
|
|
|
2021-04-18 15:17:05 +02:00
|
|
|
sizeX = yapionObject.getPlainValue("sizeX");
|
|
|
|
sizeY = yapionObject.getPlainValue("sizeY");
|
|
|
|
sizeZ = yapionObject.getPlainValue("sizeZ");
|
|
|
|
|
2021-07-11 17:14:47 +02:00
|
|
|
copyPointOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0);
|
|
|
|
copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
|
|
|
|
copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
|
2021-05-03 16:32:44 +02:00
|
|
|
|
2021-04-18 15:17:05 +02:00
|
|
|
floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0);
|
|
|
|
waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0);
|
|
|
|
|
2021-04-18 16:21:03 +02:00
|
|
|
if (yapionObject.containsKey("testblock", YAPIONType.OBJECT)) {
|
2021-04-18 15:48:15 +02:00
|
|
|
testblock = new SubPrototype(yapionObject.getObject("testblock"));
|
|
|
|
} else {
|
|
|
|
testblock = null;
|
|
|
|
}
|
2021-04-18 16:21:03 +02:00
|
|
|
if (yapionObject.containsKey("build", YAPIONType.OBJECT)) {
|
2021-04-18 15:48:15 +02:00
|
|
|
build = new SubPrototype(yapionObject.getObject("build"));
|
|
|
|
} else {
|
|
|
|
build = null;
|
|
|
|
}
|
2021-05-03 16:58:01 +02:00
|
|
|
|
2021-12-22 14:05:44 +01:00
|
|
|
this.defaultSkin = yapionObject.getPlainValueOrDefault("defaultSkin", displayName);
|
|
|
|
if (yapionObject.containsKey("skins", YAPIONType.ARRAY)) {
|
|
|
|
yapionObject.getArray("skins").forEach(yapionAnyType -> {
|
|
|
|
YAPIONObject skinObject = (YAPIONObject) yapionAnyType;
|
|
|
|
String skinName = skinObject.getPlainValue("name");
|
2021-12-23 15:52:29 +01:00
|
|
|
String skinCreator = skinObject.getPlainValueOrDefault("creator", null);
|
2021-12-22 14:05:44 +01:00
|
|
|
String schematicFileName = skinObject.getPlainValue("schematic");
|
|
|
|
String testblockSchematicFileName = skinObject.getPlainValueOrDefault("testblockSchematic", null);
|
|
|
|
String buildSchematicFileName = skinObject.getPlainValueOrDefault("buildSchematic", null);
|
2021-12-23 17:12:59 +01:00
|
|
|
boolean disabled = skinObject.getPlainValueOrDefault("disabled", false);
|
|
|
|
if (disabled) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-23 15:52:29 +01:00
|
|
|
skinMap.put(skinName, new Skin(skinName, skinCreator, new File(schematicFileName), testblockSchematicFileName == null ? null : new File(testblockSchematicFileName), buildSchematicFileName == null ? null : new File(buildSchematicFileName)));
|
2021-12-22 14:05:44 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
String s = yapionObject.getPlainValueOrDefault("schematic", null);
|
|
|
|
File schematicFile = s == null ? null : new File(s);
|
|
|
|
File testblockSchematicFile = testblock != null ? testblock.getSchematicFile() : null;
|
|
|
|
File buildSchematicFile = build != null ? build.getSchematicFile() : null;
|
2021-12-23 15:52:29 +01:00
|
|
|
skinMap.put(displayName, new Skin(defaultSkin, null, schematicFile, testblockSchematicFile, buildSchematicFile));
|
2021-12-22 14:05:44 +01:00
|
|
|
}
|
|
|
|
|
2021-05-03 16:58:01 +02:00
|
|
|
if (PROTOTYPE_MAP.containsKey(name)) {
|
2021-05-03 17:26:58 +02:00
|
|
|
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
|
2021-11-09 20:18:09 +01:00
|
|
|
region._setPrototype(this);
|
2021-05-03 17:26:58 +02:00
|
|
|
});
|
2021-05-03 16:58:01 +02:00
|
|
|
}
|
|
|
|
PROTOTYPE_MAP.put(name, this);
|
2021-04-18 15:17:05 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:15 +02:00
|
|
|
@Getter
|
2021-04-18 15:17:05 +02:00
|
|
|
public static class SubPrototype {
|
|
|
|
|
|
|
|
private final int offsetX;
|
|
|
|
private final int offsetY;
|
|
|
|
private final int offsetZ;
|
|
|
|
|
|
|
|
private final int sizeX;
|
|
|
|
private final int sizeY;
|
|
|
|
private final int sizeZ;
|
|
|
|
|
2021-04-18 15:48:15 +02:00
|
|
|
private final File schematicFile; // Nullable
|
2021-04-18 15:17:05 +02:00
|
|
|
|
|
|
|
private final int extensionNegativeX;
|
|
|
|
private final int extensionPositiveX;
|
|
|
|
private final int extensionNegativeY;
|
|
|
|
private final int extensionPositiveY;
|
|
|
|
private final int extensionNegativeZ;
|
|
|
|
private final int extensionPositiveZ;
|
|
|
|
|
2021-04-20 08:20:53 +02:00
|
|
|
private boolean extensionRegistered;
|
|
|
|
|
2021-11-09 20:23:57 +01:00
|
|
|
private final boolean hasCopyPoint;
|
2021-11-09 20:18:09 +01:00
|
|
|
private final int copyOffsetX;
|
|
|
|
private final int copyOffsetY;
|
|
|
|
private final int copyOffsetZ;
|
|
|
|
|
2021-04-18 15:17:05 +02:00
|
|
|
private SubPrototype(YAPIONObject yapionObject) {
|
|
|
|
offsetX = yapionObject.getPlainValueOrDefault("offsetX", 0);
|
|
|
|
offsetY = yapionObject.getPlainValueOrDefault("offsetY", 0);
|
|
|
|
offsetZ = yapionObject.getPlainValueOrDefault("offsetZ", 0);
|
|
|
|
|
|
|
|
sizeX = yapionObject.getPlainValue("sizeX");
|
|
|
|
sizeY = yapionObject.getPlainValue("sizeY");
|
|
|
|
sizeZ = yapionObject.getPlainValue("sizeZ");
|
|
|
|
|
2021-04-18 16:21:03 +02:00
|
|
|
if (yapionObject.containsKey("schematic", String.class)) {
|
2021-04-18 15:48:15 +02:00
|
|
|
schematicFile = new File(yapionObject.getValue("schematic", String.class).get());
|
|
|
|
} else {
|
|
|
|
schematicFile = null;
|
|
|
|
}
|
2021-04-18 15:17:05 +02:00
|
|
|
|
2021-04-18 16:21:03 +02:00
|
|
|
if (yapionObject.containsKey("extensionX", Integer.class)) {
|
2021-04-18 15:17:05 +02:00
|
|
|
extensionNegativeX = yapionObject.getPlainValue("extensionX");
|
|
|
|
extensionPositiveX = yapionObject.getPlainValue("extensionX");
|
|
|
|
} else {
|
|
|
|
extensionNegativeX = yapionObject.getPlainValueOrDefault("extensionNegativeX", 0);
|
|
|
|
extensionPositiveX = yapionObject.getPlainValueOrDefault("extensionPositiveX", 0);
|
|
|
|
}
|
|
|
|
|
2021-04-18 16:21:03 +02:00
|
|
|
if (yapionObject.containsKey("extensionY", Integer.class)) {
|
2021-04-18 15:17:05 +02:00
|
|
|
extensionNegativeY = yapionObject.getPlainValue("extensionY");
|
|
|
|
extensionPositiveY = yapionObject.getPlainValue("extensionY");
|
|
|
|
} else {
|
|
|
|
extensionNegativeY = yapionObject.getPlainValueOrDefault("extensionNegativeY", 0);
|
|
|
|
extensionPositiveY = yapionObject.getPlainValueOrDefault("extensionPositiveY", 0);
|
|
|
|
}
|
|
|
|
|
2021-04-18 16:21:03 +02:00
|
|
|
if (yapionObject.containsKey("extensionZ", Integer.class)) {
|
2021-04-18 15:17:05 +02:00
|
|
|
extensionNegativeZ = yapionObject.getPlainValue("extensionZ");
|
|
|
|
extensionPositiveZ = yapionObject.getPlainValue("extensionZ");
|
|
|
|
} else {
|
|
|
|
extensionNegativeZ = yapionObject.getPlainValueOrDefault("extensionNegativeZ", 0);
|
|
|
|
extensionPositiveZ = yapionObject.getPlainValueOrDefault("extensionPositiveZ", 0);
|
|
|
|
}
|
2021-04-20 08:20:53 +02:00
|
|
|
|
|
|
|
extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0;
|
2021-11-09 20:18:09 +01:00
|
|
|
|
|
|
|
copyOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0);
|
|
|
|
copyOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
|
|
|
|
copyOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
|
2021-11-09 20:23:57 +01:00
|
|
|
hasCopyPoint = yapionObject.containsKey("copyOffsetX") || yapionObject.containsKey("copyOffsetY") || yapionObject.containsKey("copyOffsetZ");
|
2021-04-18 15:17:05 +02:00
|
|
|
}
|
2021-04-18 15:22:18 +02:00
|
|
|
}
|
2021-04-18 15:17:05 +02:00
|
|
|
|
2021-04-18 19:00:19 +02:00
|
|
|
public static Region generateRegion(String name, YAPIONObject regionConfig, YAPIONObject regionData) {
|
2021-04-18 17:34:02 +02:00
|
|
|
Prototype prototype;
|
|
|
|
if (regionData.containsKey("prototype", String.class)) {
|
|
|
|
prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype"));
|
|
|
|
} else {
|
|
|
|
prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype"));
|
|
|
|
}
|
|
|
|
FlagStorage flagStorage;
|
|
|
|
if (regionData.containsKey("flagStorage", YAPIONType.OBJECT)) {
|
2021-04-19 19:54:38 +02:00
|
|
|
flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage"));
|
2021-04-18 17:34:02 +02:00
|
|
|
} else {
|
|
|
|
flagStorage = new FlagStorage();
|
|
|
|
}
|
2021-04-18 19:00:19 +02:00
|
|
|
return new Region(name, prototype, regionConfig, flagStorage, regionData);
|
2021-04-18 15:17:05 +02:00
|
|
|
}
|
2021-04-18 09:10:30 +02:00
|
|
|
}
|