Better bundle comment handling (#10704)
* Better bundle comment handling * Formatting
This commit is contained in:
@@ -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<String, String> base = new OrderedMap<>()
|
||||
PropertiesUtils.load(base, Fi.get("core/assets/bundles/bundle.properties").reader())
|
||||
Seq<String> removals = new Seq<>()
|
||||
|
||||
//map of line number to comment (or just empty string for blank line) content
|
||||
IntMap<String> 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<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<>()
|
||||
Seq<String> 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<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"
|
||||
(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())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user