SteamWar/BauSystem2.0
Archiviert
12
0

Add Region.linkedRegion

Dieser Commit ist enthalten in:
yoyosource 2021-04-18 19:00:19 +02:00
Ursprung 6c38686d0d
Commit 2fb682c7c7
4 geänderte Dateien mit 35 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -31,7 +31,7 @@ public class GlobalRegion extends Region {
static GlobalRegion instance; static GlobalRegion instance;
public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) { public GlobalRegion(FlagStorage flagStorage, YAPIONObject regionData) {
super(null, new YAPIONObject(), flagStorage, regionData); super("global", null, new YAPIONObject(), flagStorage, regionData);
instance = this; instance = this;
} }

Datei anzeigen

@ -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; Prototype prototype;
if (regionData.containsKey("prototype", String.class)) { if (regionData.containsKey("prototype", String.class)) {
prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype")); prototype = PROTOTYPE_MAP.get(regionData.getPlainValue("prototype"));
@ -150,7 +150,7 @@ public class Prototype {
} else { } else {
flagStorage = new FlagStorage(); flagStorage = new FlagStorage();
} }
return new Region(prototype, regionConfig, flagStorage, regionData); return new Region(name, prototype, regionConfig, flagStorage, regionData);
} }
} }

Datei anzeigen

@ -36,6 +36,7 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
@Getter @Getter
public class Region { public class Region {
@ -53,6 +54,7 @@ public class Region {
private YAPIONObject regionData; private YAPIONObject regionData;
private String name;
private Prototype prototype; private Prototype prototype;
private Set<Prototype> prototypes; private Set<Prototype> prototypes;
@ -71,6 +73,7 @@ public class Region {
private Point minPointBuildExtension; private Point minPointBuildExtension;
private Point maxPointBuildExtension; private Point maxPointBuildExtension;
private String linkedRegionName = null; // Nullable
private Region linkedRegion = null; // Nullable private Region linkedRegion = null; // Nullable
private FlagStorage flagStorage; private FlagStorage flagStorage;
@ -78,12 +81,17 @@ public class Region {
private SizedStack<EditSession> undoSessions; private SizedStack<EditSession> undoSessions;
private SizedStack<EditSession> redoSessions; private SizedStack<EditSession> 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; this.regionData = regionData;
if (prototype != null) { if (prototype != null) {
REGION_LIST.add(this); REGION_LIST.add(this);
} }
if (regionConfig.containsKey("linkedWith")) {
linkedRegionName = regionConfig.getPlainValue("linkedWith");
}
prototypes = new HashSet<>(); prototypes = new HashSet<>();
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) { if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
regionConfig.getArray("prototypes").forEach(yapionAnyType -> { regionConfig.getArray("prototypes").forEach(yapionAnyType -> {
@ -171,18 +179,40 @@ public class Region {
return prototype != null ? prototype.getDisplayName() : ""; return prototype != null ? prototype.getDisplayName() : "";
} }
private void setLinkedRegion(Consumer<Region> 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) { public void setPrototype(@NonNull Prototype prototype) {
if (this.prototype == null) { if (this.prototype == null) {
return; return;
} }
regionData.add("prototype", prototype.getName()); regionData.add("prototype", prototype.getName());
generatePrototypeData(prototype, minPoint); generatePrototypeData(prototype, minPoint);
setLinkedRegion(region -> {
region.regionData.add("prototype", prototype.getName());
region.generatePrototypeData(prototype, region.minPoint);
});
} }
public void set(Flag flagType, Flag.Value<?> value) { public void set(Flag flagType, Flag.Value<?> value) {
if (flagStorage.set(flagType, value)) { if (flagStorage.set(flagType, value)) {
regionData.add("flagStorage", YAPIONSerializer.serialize(flagStorage)); regionData.add("flagStorage", YAPIONSerializer.serialize(flagStorage));
} }
setLinkedRegion(region -> region.set(flagType, value));
} }
public <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag flagType) { public <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag flagType) {

Datei anzeigen

@ -84,7 +84,7 @@ public class RegionLoader {
optionsYapionObject.add(key, regionData); optionsYapionObject.add(key, regionData);
} }
Prototype.generateRegion(regionConfig, regionData); Prototype.generateRegion(key, regionConfig, regionData);
}); });
YAPIONObject globalOptions = optionsYapionObject.getObject("global"); YAPIONObject globalOptions = optionsYapionObject.getObject("global");