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;
import lombok.AllArgsConstructor;
import lombok.Getter;
import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType;
@ -31,7 +32,7 @@ import java.util.Map;
public class Prototype {
static final Map<String, Prototype> PROTOTYPE_MAP = new HashMap<>();
public static Prototype getByName(String name) {
return PROTOTYPE_MAP.get(name);
}
@ -40,15 +41,24 @@ public class Prototype {
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 displayName;
private final String defaultSkin;
private final Map<String, Skin> skinMap = new HashMap<>();
private final int sizeX;
private final int sizeY;
private final int sizeZ;
private final File schematicFile;
private final int floorOffset;
private final int waterOffset;
@ -71,8 +81,6 @@ public class Prototype {
copyPointOffsetY = yapionObject.getPlainValueOrDefault("copyOffsetY", 0);
copyPointOffsetZ = yapionObject.getPlainValueOrDefault("copyOffsetZ", 0);
schematicFile = new File(yapionObject.getValue("schematic", String.class).get());
floorOffset = yapionObject.getPlainValueOrDefault("floorOffset", 0);
waterOffset = yapionObject.getPlainValueOrDefault("waterOffset", 0);
@ -87,6 +95,24 @@ public class Prototype {
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)) {
Region.getRegion(PROTOTYPE_MAP.remove(name)).forEach(region -> {
region._setPrototype(this);

Datei anzeigen

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