SteamWar/BauSystem2.0
Archiviert
12
0
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
BauSystem2.0/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java

221 Zeilen
9.4 KiB
Java

/*
* 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;
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
public class Prototype {
2021-04-18 15:17:05 +02:00
static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
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
@AllArgsConstructor
@Getter
public static class Skin {
private final String name;
private final String creator; // Nullable
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;
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");
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
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");
String skinCreator = skinObject.getPlainValueOrDefault("creator", null);
String schematicFileName = skinObject.getPlainValue("schematic");
String testblockSchematicFileName = skinObject.getPlainValueOrDefault("testblockSchematic", null);
String buildSchematicFileName = skinObject.getPlainValueOrDefault("buildSchematic", null);
boolean disabled = skinObject.getPlainValueOrDefault("disabled", false);
if (disabled) {
return;
}
skinMap.put(skinName, new Skin(skinName, skinCreator, new File(schematicFileName), testblockSchematicFileName == null ? null : new File(testblockSchematicFileName), buildSchematicFileName == null ? null : new File(buildSchematicFileName)));
});
} 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;
skinMap.put(displayName, new Skin(defaultSkin, null, schematicFile, testblockSchematicFile, buildSchematicFile));
}
2021-05-03 16:58:01 +02:00
if (PROTOTYPE_MAP.containsKey(name)) {
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
region._setPrototype(this);
});
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;
private final boolean hasCopyPoint;
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;
copyOffsetX = yapionObject.getPlainValueOrDefault("copyOffsetX", 0);
copyOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
copyOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
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) {
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)) {
flagStorage = FlagStorage.createStorage(regionData.getObject("flagStorage"));
} 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
}
}