diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java index 5f236e85..b6ce36db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/GlobalRegion.java @@ -31,7 +31,7 @@ public class GlobalRegion extends Region { static GlobalRegion instance; public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) { - super(null, new YAPIONObject(), flagStorage, regionData); + super("global", null, new YAPIONObject(), flagStorage, regionData); instance = this; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java index 31ce8786..2722bf18 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java @@ -137,7 +137,7 @@ public class Prototype { } } - public static Region generateRegion(YAPIONObject regionConfig, YAPIONObject regionData) { + 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")); @@ -150,7 +150,7 @@ public class Prototype { } else { flagStorage = new FlagStorage(); } - return new Region(prototype, regionConfig, flagStorage, regionData); + return new Region(name, prototype, regionConfig, flagStorage, regionData); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index c858a71e..b6737917 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.function.Consumer; @Getter public class Region { @@ -53,6 +54,7 @@ public class Region { private YAPIONObject regionData; + private String name; private Prototype prototype; private Set prototypes; @@ -71,6 +73,7 @@ public class Region { private Point minPointBuildExtension; private Point maxPointBuildExtension; + private String linkedRegionName = null; // Nullable private Region linkedRegion = null; // Nullable private FlagStorage flagStorage; @@ -78,12 +81,17 @@ public class Region { private SizedStack undoSessions; private SizedStack redoSessions; - public Region(Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) { + public Region(String name, Prototype prototype, YAPIONObject regionConfig, FlagStorage flagStorage, YAPIONObject regionData) { + this.name = name; this.regionData = regionData; if (prototype != null) { REGION_LIST.add(this); } + if (regionConfig.containsKey("linkedWith")) { + linkedRegionName = regionConfig.getPlainValue("linkedWith"); + } + prototypes = new HashSet<>(); if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) { regionConfig.getArray("prototypes").forEach(yapionAnyType -> { @@ -171,18 +179,40 @@ public class Region { return prototype != null ? prototype.getDisplayName() : ""; } + private void setLinkedRegion(Consumer regionConsumer) { + if (linkedRegionName == null) { + return; + } + if (linkedRegion != null) { + regionConsumer.accept(linkedRegion); + return; + } + for (Region region : REGION_LIST) { + if (region.name.equals(name)) { + linkedRegion = region; + regionConsumer.accept(linkedRegion); + return; + } + } + } + public void setPrototype(@NonNull Prototype prototype) { if (this.prototype == null) { return; } regionData.add("prototype", prototype.getName()); generatePrototypeData(prototype, minPoint); + setLinkedRegion(region -> { + region.regionData.add("prototype", prototype.getName()); + region.generatePrototypeData(prototype, region.minPoint); + }); } public void set(Flag flagType, Flag.Value value) { if (flagStorage.set(flagType, value)) { regionData.add("flagStorage", YAPIONSerializer.serialize(flagStorage)); } + setLinkedRegion(region -> region.set(flagType, value)); } public & Flag.Value> Flag.Value get(Flag flagType) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java index 5bd0ce7a..e1953ac4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java @@ -84,7 +84,7 @@ public class RegionLoader { optionsYapionObject.add(key, regionData); } - Prototype.generateRegion(regionConfig, regionData); + Prototype.generateRegion(key, regionConfig, regionData); }); YAPIONObject globalOptions = optionsYapionObject.getObject("global");