diff --git a/tools/build.gradle b/tools/build.gradle index b029266302..6701a24f5f 100644 --- a/tools/build.gradle +++ b/tools/build.gradle @@ -6,6 +6,7 @@ import arc.func.Func2 import arc.graphics.Color import arc.graphics.Pixmap import arc.packer.TexturePacker +import arc.struct.IntMap import arc.struct.ObjectMap import arc.struct.OrderedMap import arc.struct.Seq @@ -283,36 +284,31 @@ task updateBundles{ OrderedMap base = new OrderedMap<>() PropertiesUtils.load(base, Fi.get("core/assets/bundles/bundle.properties").reader()) - Seq removals = new Seq<>() + + //map of line number to comment (or just empty string for blank line) content + IntMap commentAndBlankLines = new IntMap<>() + var lines = Fi.get("core/assets/bundles/bundle.properties").reader().readLines() + int offset = 0 + for(int i = 0; i < lines.size(); i++){ + var line = lines.get(i) + if(i > 0 && lines.get(i - 1).endsWith("\\")) offset++ //multiline value escaped with \\ at end of line + else if(line.isEmpty() || line.startsWith("#")) commentAndBlankLines.put(i - offset, line) + } Log.info("Updating bundles...") Fi.get("core/assets/bundles").walk(child -> { - if(child.name().equals("bundle.properties") || child.toString().contains("output")) return + if(child.name() == "bundle.properties" || child.toString().contains("output")) return + if(project.hasProperty("bundle") && child.name() != project.property("bundle")) return Log.info("| @", child.nameWithoutExtension()) OrderedMap other = new OrderedMap<>() - //find the last known comment of each line - ObjectMap 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 extras = new OrderedMap<>() + Seq removals = new Seq<>() + PropertiesUtils.load(other, child.reader()) - removals.clear() for(String key : other.orderedKeys()){ if(!base.containsKey(key) && key.contains(".details") && false){ @@ -338,16 +334,18 @@ task updateBundles{ } Func2 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" + (key + " =" + (value.trim().isEmpty() ? "" : " ") + uniEscape(value)).replace("\n", "\\n") + "\n" Fi output = child.sibling("output/" + child.name()) if(added > 0) Log.info("&lc@ keys added.", added) if(removals.size + added > 0) Log.info("Writing bundle to @", output) StringBuilder result = new StringBuilder() + int i = 0 //add everything ordered for(String key : base.orderedKeys().copy().add(extras.keys().toSeq())){ + //append any comments or blank lines as needed to match the english bundle + while(commentAndBlankLines.containsKey(i++)) result.append(commentAndBlankLines.get(i - 1) + "\n") if(other.get(key) == null) continue result.append(processor.get(key, other.get(key))) @@ -357,4 +355,4 @@ task updateBundles{ child.writeString(result.toString()) }) } -} \ No newline at end of file +}