SteamWar/BauSystem2.0
Archiviert
12
0

Add Prototype.skinMap
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-12-22 14:05:44 +01:00
Ursprung f993649923
Commit fd7eeb9177
2 geänderte Dateien mit 55 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONType;
@ -40,15 +41,24 @@ public class Prototype {
return PROTOTYPE_MAP.values().stream().filter(prototype -> prototype.getDisplayName().equals(name)).findFirst().orElse(null); return PROTOTYPE_MAP.values().stream().filter(prototype -> prototype.getDisplayName().equals(name)).findFirst().orElse(null);
} }
@AllArgsConstructor
@Getter
public static class Skin {
private final String name;
private final File schematicFile;
private final File testblockSchematicFile; // Nullable
private final File buildSchematicFile; // Nullable
}
private final String name; private final String name;
private final String displayName; private final String displayName;
private final String defaultSkin;
private final Map<String, Skin> skinMap = new HashMap<>();
private final int sizeX; private final int sizeX;
private final int sizeY; private final int sizeY;
private final int sizeZ; private final int sizeZ;
private final File schematicFile;
private final int floorOffset; private final int floorOffset;
private final int waterOffset; private final int waterOffset;
@ -71,8 +81,6 @@ public class Prototype {
copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0); copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0); copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
schematicFile = new File(yapionObject.getValue("schematic", String.class).get());
floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0); floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0);
waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0); waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0);
@ -87,6 +95,24 @@ public class Prototype {
build = null; build = null;
} }
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 schematicFileName = skinObject.getPlainValue("schematic");
String testblockSchematicFileName = skinObject.getPlainValueOrDefault("testblockSchematic", null);
String buildSchematicFileName = skinObject.getPlainValueOrDefault("buildSchematic", null);
skinMap.put(skinName, new Skin(skinName, 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, schematicFile, testblockSchematicFile, buildSchematicFile));
}
if (PROTOTYPE_MAP.containsKey(name)) { if (PROTOTYPE_MAP.containsKey(name)) {
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> { Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
region._setPrototype(this); region._setPrototype(this);

Datei anzeigen

@ -79,6 +79,7 @@ public class Region {
private String name; private String name;
private Prototype prototype; private Prototype prototype;
private Set<String> prototypes; private Set<String> prototypes;
private String skin;
private Point minPoint; private Point minPoint;
private Point maxPoint; private Point maxPoint;
@ -143,6 +144,9 @@ public class Region {
} else if (regionConfig.containsKey("prototype")) { } else if (regionConfig.containsKey("prototype")) {
generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point); generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point);
} }
if (prototype != null) {
skin = regionConfig.getPlainValueOrDefault("skin", prototype.getDefaultSkin());
}
if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) { if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) {
flagStorage.set(Flag.TNT, TNTMode.DENY); flagStorage.set(Flag.TNT, TNTMode.DENY);
@ -155,6 +159,7 @@ public class Region {
} }
this.prototype = prototype; this.prototype = prototype;
this.skin = prototype.getDefaultSkin();
this.minPoint = point; this.minPoint = point;
this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1); this.maxPoint = point.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
@ -266,7 +271,7 @@ public class Region {
} }
public String getDisplayName() { public String getDisplayName() {
return prototype != null ? prototype.getDisplayName() : ""; return prototype != null ? prototype.getSkinMap().get(skin).getName() : "";
} }
private void setLinkedRegion(Predicate<Region> regionConsumer) { private void setLinkedRegion(Predicate<Region> regionConsumer) {
@ -303,6 +308,18 @@ public class Region {
return true; return true;
} }
public boolean setSkin(@NonNull String skinName) {
if (!prototype.getSkinMap().containsKey(skinName)) {
return false;
}
this.skin = skinName;
setLinkedRegion(region -> {
region.skin = skinName;
return true;
});
return true;
}
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)) {
RegionUtils.save(this); RegionUtils.save(this);
@ -369,12 +386,12 @@ public class Region {
} }
switch (regionType) { switch (regionType) {
case TESTBLOCK: case TESTBLOCK:
return prototype.getTestblock().getSchematicFile() != null; return prototype.getSkinMap().get(skin).getTestblockSchematicFile() != null;
case BUILD: case BUILD:
return prototype.getBuild().getSchematicFile() != null; return prototype.getSkinMap().get(skin).getBuildSchematicFile() != null;
default: default:
case NORMAL: case NORMAL:
return prototype.getSchematicFile() != null; return prototype.getSkinMap().get(skin).getSchematicFile() != null;
} }
} }
@ -421,13 +438,13 @@ public class Region {
case BUILD: case BUILD:
pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2); pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getBuild().getSchematicFile(); tempFile = prototype.getSkinMap().get(skin).getBuildSchematicFile();
} }
break; break;
case TESTBLOCK: case TESTBLOCK:
pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0); pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getTestblock().getSchematicFile(); tempFile = prototype.getSkinMap().get(skin).getTestblockSchematicFile();
pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2); pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2);
} else { } else {
clipboard = schematic.load(); clipboard = schematic.load();
@ -448,7 +465,7 @@ public class Region {
case NORMAL: case NORMAL:
pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2); pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2);
if (schematic == null) { if (schematic == null) {
tempFile = prototype.getSchematicFile(); tempFile = prototype.getSkinMap().get(skin).getSchematicFile();
} }
break; break;
} }