mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-24 09:56:32 +07:00
Better bundle updater implementation
This commit is contained in:
parent
ef1084302f
commit
8717fd8b33
@ -247,38 +247,38 @@ task pack(dependsOn: [classes, configurations.runtimeClasspath]){
|
||||
task genSprites(dependsOn: classes, type: JavaExec){
|
||||
finalizedBy 'antialiasGen'
|
||||
|
||||
main = "mindustry.tools.ImagePacker"
|
||||
mainClass = "mindustry.tools.ImagePacker"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = genFolder
|
||||
}
|
||||
|
||||
task updateBundles(dependsOn: classes, type: JavaExec){
|
||||
file(genFolder).mkdirs()
|
||||
|
||||
main = "mindustry.tools.BundleLauncher"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../core/assets/bundles/"
|
||||
}
|
||||
|
||||
task fontgen(dependsOn: classes, type: JavaExec){
|
||||
main = "mindustry.tools.FontGenerator"
|
||||
mainClass = "mindustry.tools.FontGenerator"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../"
|
||||
}
|
||||
|
||||
task icongen(dependsOn: classes, type: JavaExec){
|
||||
main = "mindustry.tools.IconConverter"
|
||||
mainClass = "mindustry.tools.IconConverter"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../core/assets-raw"
|
||||
}
|
||||
|
||||
task updateScripts(dependsOn: classes, type: JavaExec){
|
||||
main = "mindustry.tools.ScriptMainGenerator"
|
||||
mainClass = "mindustry.tools.ScriptMainGenerator"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../"
|
||||
}
|
||||
|
||||
task updateBundles(dependsOn: classes, type: JavaExec){
|
||||
file(genFolder).mkdirs()
|
||||
|
||||
mainClass = "mindustry.tools.BundleLauncher"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../core/assets/bundles/"
|
||||
}
|
@ -12,19 +12,38 @@ public class BundleLauncher{
|
||||
OrderedMap<String, String> base = new OrderedMap<>();
|
||||
PropertiesUtils.load(base, Fi.get("bundle.properties").reader());
|
||||
Seq<String> removals = new Seq<>();
|
||||
String str = Fi.get("bundle.properties").readString();
|
||||
ObjectSet<String> newlines = Seq.with(str.split("\n")).select(l -> l.contains(" = ") && str.indexOf(l) + l.length() < str.length() - 2 && str.charAt(str.indexOf(l) + l.length() + 1) == '\n').map(l -> l.split(" = ")[0]).asSet();
|
||||
|
||||
Fi.get(".").walk(child -> {
|
||||
if(child.name().equals("bundle.properties") || child.toString().contains("output")) return;
|
||||
if(child.name().equals("bundle.properties") || child.toString().contains("output") || !child.name().equals("bundle_ko.properties")) return;
|
||||
|
||||
Log.info("Parsing bundle: @", child);
|
||||
|
||||
OrderedMap<String, String> other = new OrderedMap<>();
|
||||
PropertiesUtils.load(other, child.reader(2048, "UTF-8"));
|
||||
|
||||
//find the last known comment of each line
|
||||
ObjectMap<String, String> comments = new ObjectMap<>();
|
||||
StringBuilder curComment = new StringBuilder();
|
||||
|
||||
for(String line : Seq.with(child.readString().split("\n", -1))){
|
||||
if(line.startsWith("#") || line.isEmpty()){
|
||||
curComment.append(line).append("\n");
|
||||
}else if(line.contains("=")){
|
||||
String lastKey = line.substring(0, line.indexOf("=")).trim();
|
||||
if(curComment.length() != 0){
|
||||
comments.put(lastKey, curComment.toString());
|
||||
curComment.setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ObjectMap<String, String> extras = new OrderedMap<>();
|
||||
PropertiesUtils.load(other, child.reader());
|
||||
removals.clear();
|
||||
|
||||
for(String key : other.orderedKeys()){
|
||||
if(!base.containsKey(key)){
|
||||
if(!base.containsKey(key) && key.contains(".details")){
|
||||
extras.put(key, other.get(key));
|
||||
}else if(!base.containsKey(key)){
|
||||
removals.add(key);
|
||||
Log.info("&lr- Removing unused key '@'...", key);
|
||||
}
|
||||
@ -44,7 +63,9 @@ public class BundleLauncher{
|
||||
}
|
||||
}
|
||||
|
||||
Func2<String, String, String> processor = (key, value) -> (key + " = " + value).replace("\\", "\\\\").replace("\n", "\\n") + "\n" + (newlines.contains(key) ? "\n" : "");
|
||||
Func2<String, String, String> processor = (key, value) ->
|
||||
(comments.containsKey(key) ? comments.get(key) : "") + //append last known comment if present
|
||||
(key + " =" + (value.trim().isEmpty() ? "" : " ") + uniEscape(value)).replace("\n", "\\n") + "\n";
|
||||
Fi output = child.sibling("output/" + child.name());
|
||||
|
||||
Log.info("&lc@ keys added.", added);
|
||||
@ -52,7 +73,7 @@ public class BundleLauncher{
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
//add everything ordered
|
||||
for(String key : base.orderedKeys()){
|
||||
for(String key : base.orderedKeys().and(extras.keys().toSeq())){
|
||||
result.append(processor.get(key, other.get(key)));
|
||||
other.remove(key);
|
||||
}
|
||||
@ -61,4 +82,29 @@ public class BundleLauncher{
|
||||
});
|
||||
}
|
||||
|
||||
static String uniEscape(String string){
|
||||
StringBuilder outBuffer = new StringBuilder();
|
||||
int len = string.length();
|
||||
for(int i = 0; i < len; i++){
|
||||
char ch = string.charAt(i);
|
||||
if((ch > 61) && (ch < 127)){
|
||||
outBuffer.append(ch == '\\' ? "\\\\" : ch);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ch >= 0xE000){
|
||||
String hex = Integer.toHexString(ch);
|
||||
outBuffer.append("\\u");
|
||||
for(int j = 0; j < 4 - hex.length(); j++){
|
||||
outBuffer.append('0');
|
||||
}
|
||||
outBuffer.append(hex);
|
||||
}else{
|
||||
outBuffer.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
return outBuffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user