BundleLauncher moved to gradle script
This commit is contained in:
4
.github/workflows/push.yml
vendored
4
.github/workflows/push.yml
vendored
@@ -25,9 +25,9 @@ jobs:
|
|||||||
if: ${{ github.repository == 'Anuken/Mindustry' }}
|
if: ${{ github.repository == 'Anuken/Mindustry' }}
|
||||||
run: |
|
run: |
|
||||||
./gradlew updateBundles
|
./gradlew updateBundles
|
||||||
|
|
||||||
git diff --exit-code
|
git diff --exit-code
|
||||||
if [ $? ];
|
if [ $? ]; then
|
||||||
then
|
|
||||||
git add core/assets/bundles/*
|
git add core/assets/bundles/*
|
||||||
git commit -m "Automatic bundle update"
|
git commit -m "Automatic bundle update"
|
||||||
git push
|
git push
|
||||||
|
|||||||
@@ -2,12 +2,18 @@ sourceSets.main.java.srcDirs = ["src/"]
|
|||||||
|
|
||||||
|
|
||||||
import arc.files.Fi
|
import arc.files.Fi
|
||||||
|
import arc.func.Func2
|
||||||
import arc.graphics.Color
|
import arc.graphics.Color
|
||||||
import arc.graphics.Pixmap
|
import arc.graphics.Pixmap
|
||||||
import arc.packer.TexturePacker
|
import arc.packer.TexturePacker
|
||||||
import arc.struct.IntIntMap
|
import arc.struct.IntIntMap
|
||||||
import arc.struct.IntMap
|
import arc.struct.IntMap
|
||||||
|
import arc.struct.ObjectMap
|
||||||
|
import arc.struct.OrderedMap
|
||||||
|
import arc.struct.Seq
|
||||||
|
import arc.util.Log
|
||||||
import arc.util.async.Threads
|
import arc.util.async.Threads
|
||||||
|
import arc.util.io.PropertiesUtils
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
@@ -274,11 +280,105 @@ task updateScripts(dependsOn: classes, type: JavaExec){
|
|||||||
workingDir = "../"
|
workingDir = "../"
|
||||||
}
|
}
|
||||||
|
|
||||||
task updateBundles(dependsOn: classes, type: JavaExec){
|
task updateBundles{
|
||||||
file(genFolder).mkdirs()
|
doLast{
|
||||||
|
def 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;
|
||||||
|
}
|
||||||
|
|
||||||
mainClass = "mindustry.tools.BundleLauncher"
|
if(ch >= 0xE000){
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
String hex = Integer.toHexString((int)ch);
|
||||||
standardInput = System.in
|
outBuffer.append("\\u");
|
||||||
workingDir = "../core/assets/bundles/"
|
for(int j = 0; j < 4 - hex.length(); j++){
|
||||||
|
outBuffer.append('0');
|
||||||
|
}
|
||||||
|
outBuffer.append(hex);
|
||||||
|
}else{
|
||||||
|
outBuffer.append(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
OrderedMap<String, String> base = new OrderedMap<>();
|
||||||
|
PropertiesUtils.load(base, Fi.get("core/assets/bundles/bundle.properties").reader());
|
||||||
|
Seq<String> removals = new Seq<>();
|
||||||
|
|
||||||
|
Fi.get("core/assets/bundles").walk(child -> {
|
||||||
|
if(child.name().equals("bundle.properties") || child.toString().contains("output")) return;
|
||||||
|
|
||||||
|
Log.info("Parsing bundle: @", child);
|
||||||
|
|
||||||
|
OrderedMap<String, String> other = new OrderedMap<>();
|
||||||
|
|
||||||
|
//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) && key.contains(".details")){
|
||||||
|
extras.put(key, other.get(key));
|
||||||
|
}else if(!base.containsKey(key)){
|
||||||
|
removals.add(key);
|
||||||
|
Log.info("&lr- Removing unused key '@'...", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.info("&lr@ keys removed.", removals.size);
|
||||||
|
for(String s : removals){
|
||||||
|
other.remove(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
int added = 0;
|
||||||
|
|
||||||
|
for(String key : base.orderedKeys()){
|
||||||
|
if(other.get(key) == null || other.get(key).trim().isEmpty()){
|
||||||
|
other.put(key, base.get(key));
|
||||||
|
added++;
|
||||||
|
Log.info("&lc- Adding missing key '@'...", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
Log.info("Writing bundle to @", output);
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
|
//add everything ordered
|
||||||
|
for(String key : base.orderedKeys().copy().and(extras.keys().toSeq())){
|
||||||
|
if(other.get(key) == null) continue;
|
||||||
|
|
||||||
|
result.append(processor.get(key, other.get(key)));
|
||||||
|
other.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
child.writeString(result.toString());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
package mindustry.tools;
|
|
||||||
|
|
||||||
import arc.files.*;
|
|
||||||
import arc.func.*;
|
|
||||||
import arc.struct.*;
|
|
||||||
import arc.util.*;
|
|
||||||
import arc.util.io.*;
|
|
||||||
|
|
||||||
public class BundleLauncher{
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
OrderedMap<String, String> base = new OrderedMap<>();
|
|
||||||
PropertiesUtils.load(base, Fi.get("bundle.properties").reader());
|
|
||||||
Seq<String> removals = new Seq<>();
|
|
||||||
|
|
||||||
Fi.get(".").walk(child -> {
|
|
||||||
if(child.name().equals("bundle.properties") || child.toString().contains("output")) return;
|
|
||||||
|
|
||||||
Log.info("Parsing bundle: @", child);
|
|
||||||
|
|
||||||
OrderedMap<String, String> other = new OrderedMap<>();
|
|
||||||
|
|
||||||
//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) && key.contains(".details")){
|
|
||||||
extras.put(key, other.get(key));
|
|
||||||
}else if(!base.containsKey(key)){
|
|
||||||
removals.add(key);
|
|
||||||
Log.info("&lr- Removing unused key '@'...", key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.info("&lr@ keys removed.", removals.size);
|
|
||||||
for(String s : removals){
|
|
||||||
other.remove(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
int added = 0;
|
|
||||||
|
|
||||||
for(String key : base.orderedKeys()){
|
|
||||||
if(other.get(key) == null || other.get(key).trim().isEmpty()){
|
|
||||||
other.put(key, base.get(key));
|
|
||||||
added++;
|
|
||||||
Log.info("&lc- Adding missing key '@'...", key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
Log.info("Writing bundle to @", output);
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
|
|
||||||
//add everything ordered
|
|
||||||
for(String key : base.orderedKeys().copy().and(extras.keys().toSeq())){
|
|
||||||
if(other.get(key) == null) continue;
|
|
||||||
|
|
||||||
result.append(processor.get(key, other.get(key)));
|
|
||||||
other.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
child.writeString(result.toString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user