From 72cfa5682cb654c54aa80ecfa17ea4a9145a8583 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Apr 2021 15:48:15 +0200 Subject: [PATCH] Add PrototypeLoader Add RegionLoader --- .../steamwar/bausystem/region/Prototype.java | 28 ++++++++++++++----- .../de/steamwar/bausystem/region/Region.java | 3 ++ .../region/loader/PrototypeLoader.java | 26 +++++++++++++++++ .../bausystem/region/loader/RegionLoader.java | 26 +++++++++++++++++ 4 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java index 9c7aa190..0352007e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.region; import lombok.Getter; import yapion.hierarchy.types.YAPIONObject; +import yapion.hierarchy.types.YAPIONType; import java.io.File; import java.util.HashMap; @@ -43,8 +44,8 @@ public class Prototype { private final int floorOffset; private final int waterOffset; - private final SubPrototype testblock; - private final SubPrototype build; + private final SubPrototype testblock; // Nullable + private final SubPrototype build; // Nullable public Prototype(String name, YAPIONObject yapionObject) { PROTOTYPE_MAP.put(name, this); @@ -61,10 +62,19 @@ public class Prototype { floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0); waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0); - testblock = new SubPrototype(yapionObject.getObject("testblock")); - build = new SubPrototype(yapionObject.getObject("build")); + if (yapionObject.hasValue("testblock", YAPIONType.OBJECT)) { + testblock = new SubPrototype(yapionObject.getObject("testblock")); + } else { + testblock = null; + } + if (yapionObject.hasValue("build", YAPIONType.OBJECT)) { + build = new SubPrototype(yapionObject.getObject("build")); + } else { + build = null; + } } + @Getter public static class SubPrototype { private final int offsetX; @@ -75,7 +85,7 @@ public class Prototype { private final int sizeY; private final int sizeZ; - private final File schematicFile; + private final File schematicFile; // Nullable private final int extensionNegativeX; private final int extensionPositiveX; @@ -93,7 +103,11 @@ public class Prototype { sizeY = yapionObject.getPlainValue("sizeY"); sizeZ = yapionObject.getPlainValue("sizeZ"); - schematicFile = new File(yapionObject.getValue("schematic", String.class).get()); + if (yapionObject.hasValue("schematic", String.class)) { + schematicFile = new File(yapionObject.getValue("schematic", String.class).get()); + } else { + schematicFile = null; + } if (yapionObject.hasValue("extensionX", Integer.class)) { extensionNegativeX = yapionObject.getPlainValue("extensionX"); @@ -121,7 +135,7 @@ public class Prototype { } } - public Region generateRegion() { + public static Region generateRegion(YAPIONObject regionConfig, YAPIONObject regionData) { return null; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index e11c04f6..e482fc89 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -19,8 +19,11 @@ package de.steamwar.bausystem.region; +import lombok.Getter; + import java.util.Set; +@Getter public class Region { private Prototype prototype; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java new file mode 100644 index 00000000..079d53ac --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java @@ -0,0 +1,26 @@ +/* + * 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 . + */ + +package de.steamwar.bausystem.region.loader; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class PrototypeLoader { +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java new file mode 100644 index 00000000..6a26a07b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java @@ -0,0 +1,26 @@ +/* + * 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 . + */ + +package de.steamwar.bausystem.region.loader; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class RegionLoader { +}