mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-04-01 23:31:06 +00:00
Added some patch code to restore lost script names from the recent data model change
This commit is contained in:
parent
e3b9387719
commit
ffb848f386
OutlawEditor/src/main/java/org/badvision/outlaweditor
@ -2,10 +2,15 @@ package org.badvision.outlaweditor.data;
|
||||
|
||||
import java.util.List;
|
||||
import org.badvision.outlaweditor.Application;
|
||||
import org.badvision.outlaweditor.data.xml.Field;
|
||||
import org.badvision.outlaweditor.data.xml.Global;
|
||||
import org.badvision.outlaweditor.data.xml.NamedEntity;
|
||||
import org.badvision.outlaweditor.data.xml.Scope;
|
||||
import org.badvision.outlaweditor.data.xml.Script;
|
||||
import org.badvision.outlaweditor.data.xml.Scripts;
|
||||
|
||||
public class DataUtilities {
|
||||
|
||||
public static void ensureGlobalExists() {
|
||||
if (Application.gameData.getGlobal() == null) {
|
||||
Application.gameData.setGlobal(new Global());
|
||||
@ -16,20 +21,26 @@ public class DataUtilities {
|
||||
if (entities == null) {
|
||||
return;
|
||||
}
|
||||
entities.sort((a,b)->{
|
||||
entities.sort((a, b) -> {
|
||||
String nameA = a == null ? "" : nullSafe(a.getName());
|
||||
String nameB = b == null ? "" : nullSafe(b.getName());
|
||||
if (nameA.equalsIgnoreCase("init")) return -1;
|
||||
if (nameB.equalsIgnoreCase("init")) return 1;
|
||||
if (nameA.equalsIgnoreCase("init")) {
|
||||
return -1;
|
||||
}
|
||||
if (nameB.equalsIgnoreCase("init")) {
|
||||
return 1;
|
||||
}
|
||||
return nameA.compareTo(nameB);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static String nullSafe(String str) {
|
||||
if (str == null) return "";
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
public static String uppercaseFirst(String str) {
|
||||
StringBuilder b = new StringBuilder(str);
|
||||
int i = 0;
|
||||
@ -38,5 +49,26 @@ public class DataUtilities {
|
||||
i = b.indexOf(" ", i) + 1;
|
||||
} while (i > 0 && i < b.length());
|
||||
return b.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanupScriptName(Script script) {
|
||||
if (script.getName() != null) {
|
||||
return;
|
||||
}
|
||||
script.getBlock().getFieldOrMutationOrStatement().stream()
|
||||
.filter((obj) -> (obj instanceof Field && ((Field) obj).getName().equalsIgnoreCase("NAME")))
|
||||
.forEach((obj) -> {
|
||||
script.setName(((Field) obj).getValue());
|
||||
});
|
||||
}
|
||||
|
||||
public static void cleanupScriptNames(Scope s) {
|
||||
if (s.getScripts() == null || s.getScripts().getScript() == null) return;
|
||||
s.getScripts().getScript().forEach(DataUtilities::cleanupScriptName);
|
||||
}
|
||||
|
||||
public static void cleanupAllScriptNames() {
|
||||
cleanupScriptNames(Application.gameData.getGlobal());
|
||||
Application.gameData.getMap().forEach(DataUtilities::cleanupScriptNames);
|
||||
}
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ public class UIAction {
|
||||
TilesetUtils.clear();
|
||||
Application.gameData = newData;
|
||||
DataUtilities.ensureGlobalExists();
|
||||
DataUtilities.cleanupAllScriptNames();
|
||||
ApplicationUIController.getController().updateSelectors();
|
||||
break;
|
||||
case Quit:
|
||||
|
Loading…
x
Reference in New Issue
Block a user