SteamWar/BauSystem2.0
Archiviert
12
0

Simplify If and Jump

Dieser Commit ist enthalten in:
yoyosource 2021-04-28 08:18:28 +02:00
Ursprung 98dfe9ed11
Commit 6f8ae5ab6d
3 geänderte Dateien mit 23 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -25,4 +25,20 @@ public interface SpecialCommand {
default String asString(String value) {
return value;
}
default void jumpToIndex(ScriptExecutor scriptExecutor, String jumpPoint) {
scriptExecutor.jumpPoints.computeIfPresent(jumpPoint, (s, integer) -> {
scriptExecutor.setIndex(integer);
return integer;
});
}
default void jumpToIndexWithMessage(ScriptExecutor scriptExecutor, String jumpPoint, String message) {
Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null);
if (jp == null) {
scriptExecutor.getPlayer().sendMessage(message);
return;
}
scriptExecutor.setIndex(jp);
}
}

Datei anzeigen

@ -42,12 +42,13 @@ public class If implements SpecialCommand {
if (command[2].equals("exists")) {
if (scriptExecutor.isVariable(command[1])) {
setIndex(scriptExecutor, command[3]);
jumpToIndex(scriptExecutor, command[3]);
} else {
if (command.length > 4) {
setIndex(scriptExecutor, command[4]);
jumpToIndex(scriptExecutor, command[4]);
}
}
return true;
}
Value v1 = scriptExecutor.getOrItselfValue(command[1]);
@ -55,20 +56,15 @@ public class If implements SpecialCommand {
if (v1.getClass() != v2.getClass()) {
// This is intended
if (command.length > 4) {
scriptExecutor.setIndex((int) asLong(command[4]));
jumpToIndex(scriptExecutor, command[4]);
}
return true;
}
if (v1.asString().equals(v2.asString())) {
setIndex(scriptExecutor, command[3]);
jumpToIndex(scriptExecutor, command[3]);
} else if (command.length > 4) {
setIndex(scriptExecutor, command[4]);
jumpToIndex(scriptExecutor, command[4]);
}
return true;
}
private void setIndex(ScriptExecutor scriptExecutor, String name) {
Integer jp = scriptExecutor.jumpPoints.getOrDefault(name, null);
if (jp != null) scriptExecutor.setIndex(jp);
}
}

Datei anzeigen

@ -29,12 +29,7 @@ public class Jump implements SpecialCommand {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt");
return true;
}
Integer jumpPoint = scriptExecutor.jumpPoints.getOrDefault(command[1], null);
if (jumpPoint == null) {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDer Jump-Point (" + command[1] + ") ist nicht definiert.");
return true;
}
scriptExecutor.setIndex(jumpPoint);
jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.PREFIX + "§cDer Jump-Point (" + command[1] + ") ist nicht definiert.");
return true;
}
}