From e9ed0512f72ca270a61c94c6b69c615c09c15bd9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 15 Dec 2019 21:12:41 -0500 Subject: [PATCH] Removed `Path` API usage --- core/src/io/anuke/mindustry/core/Version.java | 38 +++---- .../anuke/mindustry/tools/BundleLauncher.java | 100 ++++++++---------- .../io/anuke/mindustry/tools/Generators.java | 28 ++--- .../io/anuke/mindustry/tools/ImagePacker.java | 36 +++---- 4 files changed, 87 insertions(+), 115 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Version.java b/core/src/io/anuke/mindustry/core/Version.java index c2b3c515e4..8cc169d28c 100644 --- a/core/src/io/anuke/mindustry/core/Version.java +++ b/core/src/io/anuke/mindustry/core/Version.java @@ -7,8 +7,6 @@ import io.anuke.arc.files.*; import io.anuke.arc.util.*; import io.anuke.arc.util.io.*; -import java.io.*; - public class Version{ /** Build type. 'official' for official releases; 'custom' or 'bleeding edge' are also used. */ public static String type; @@ -26,29 +24,25 @@ public class Version{ public static void init(){ if(!enabled) return; - try{ - Fi file = OS.isAndroid || OS.isIos ? Core.files.internal("version.properties") : new Fi("version.properties", FileType.Internal); + Fi file = OS.isAndroid || OS.isIos ? Core.files.internal("version.properties") : new Fi("version.properties", FileType.Internal); - ObjectMap map = new ObjectMap<>(); - PropertiesUtils.load(map, file.reader()); + ObjectMap map = new ObjectMap<>(); + PropertiesUtils.load(map, file.reader()); - type = map.get("type"); - number = Integer.parseInt(map.get("number", "4")); - modifier = map.get("modifier"); - if(map.get("build").contains(".")){ - String[] split = map.get("build").split("\\."); - try{ - build = Integer.parseInt(split[0]); - revision = Integer.parseInt(split[1]); - }catch(Throwable e){ - e.printStackTrace(); - build = -1; - } - }else{ - build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1; + type = map.get("type"); + number = Integer.parseInt(map.get("number", "4")); + modifier = map.get("modifier"); + if(map.get("build").contains(".")){ + String[] split = map.get("build").split("\\."); + try{ + build = Integer.parseInt(split[0]); + revision = Integer.parseInt(split[1]); + }catch(Throwable e){ + e.printStackTrace(); + build = -1; } - }catch(IOException e){ - throw new RuntimeException(e); + }else{ + build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1; } } } diff --git a/tools/src/io/anuke/mindustry/tools/BundleLauncher.java b/tools/src/io/anuke/mindustry/tools/BundleLauncher.java index 7d99eadac2..30624ea663 100644 --- a/tools/src/io/anuke/mindustry/tools/BundleLauncher.java +++ b/tools/src/io/anuke/mindustry/tools/BundleLauncher.java @@ -1,14 +1,12 @@ package io.anuke.mindustry.tools; -import io.anuke.arc.collection.Array; -import io.anuke.arc.collection.OrderedMap; -import io.anuke.arc.func.Func2; -import io.anuke.arc.util.Log; -import io.anuke.arc.util.Strings; -import io.anuke.arc.util.io.PropertiesUtils; +import io.anuke.arc.collection.*; +import io.anuke.arc.files.*; +import io.anuke.arc.func.*; +import io.anuke.arc.util.*; +import io.anuke.arc.util.io.*; import java.io.*; -import java.nio.file.*; public class BundleLauncher{ @@ -17,58 +15,52 @@ public class BundleLauncher{ OrderedMap base = new OrderedMap<>(); PropertiesUtils.load(base, new InputStreamReader(new FileInputStream(file))); Array removals = new Array<>(); + Fi.get("").walk(child -> { + if(child.name().equals("bundle.properties") || child.isDirectory() || child.toString().contains("output")) + return; - Files.walk(Paths.get("")).forEach(child -> { - try{ - if(child.getFileName().toString().equals("bundle.properties") || Files.isDirectory(child) || child.toString().contains("output")) - return; + Log.info("Parsing bundle: {0}", child); - Log.info("Parsing bundle: {0}", child); + OrderedMap other = new OrderedMap<>(); + PropertiesUtils.load(other, child.reader(2048, "UTF-8")); + removals.clear(); - OrderedMap other = new OrderedMap<>(); - PropertiesUtils.load(other, Files.newBufferedReader(child, Strings.utf8)); - removals.clear(); - - for(String key : other.orderedKeys()){ - if(!base.containsKey(key)){ - removals.add(key); - Log.info("&lr- Removing unused key '{0}'...", key); - } + for(String key : other.orderedKeys()){ + if(!base.containsKey(key)){ + removals.add(key); + Log.info("&lr- Removing unused key '{0}'...", key); } - Log.info("&lr{0} keys removed.", removals.size); - for(String s : removals){ - other.remove(s); - } - - int added = 0; - - for(String key : base.orderedKeys()){ - if(!other.containsKey(key) || other.get(key).trim().isEmpty()){ - other.put(key, base.get(key)); - added++; - Log.info("&lc- Adding missing key '{0}'...", key); - } - } - - Func2 processor = (key, value) -> (key + " = " + value).replace("\\", "\\\\").replace("\n", "\\n") + "\n"; - - Path output = child.resolveSibling("output/" + child.getFileName()); - - Log.info("&lc{0} keys added.", added); - Log.info("Writing bundle to {0}", output); - StringBuilder result = new StringBuilder(); - - //add everything ordered - for(String key : base.orderedKeys()){ - result.append(processor.get(key, other.get(key))); - other.remove(key); - } - - Files.write(child, result.toString().getBytes(Strings.utf8)); - - }catch(IOException e){ - throw new RuntimeException(e); } + Log.info("&lr{0} keys removed.", removals.size); + for(String s : removals){ + other.remove(s); + } + + int added = 0; + + for(String key : base.orderedKeys()){ + if(!other.containsKey(key) || other.get(key).trim().isEmpty()){ + other.put(key, base.get(key)); + added++; + Log.info("&lc- Adding missing key '{0}'...", key); + } + } + + Func2 processor = (key, value) -> (key + " = " + value).replace("\\", "\\\\").replace("\n", "\\n") + "\n"; + + Fi output = child.sibling("output/" + child.name()); + + Log.info("&lc{0} keys added.", added); + Log.info("Writing bundle to {0}", output); + StringBuilder result = new StringBuilder(); + + //add everything ordered + for(String key : base.orderedKeys()){ + result.append(processor.get(key, other.get(key))); + other.remove(key); + } + + child.writeString(result.toString()); }); } diff --git a/tools/src/io/anuke/mindustry/tools/Generators.java b/tools/src/io/anuke/mindustry/tools/Generators.java index 91887f0383..e1ad420f50 100644 --- a/tools/src/io/anuke/mindustry/tools/Generators.java +++ b/tools/src/io/anuke/mindustry/tools/Generators.java @@ -1,21 +1,19 @@ package io.anuke.mindustry.tools; import io.anuke.arc.collection.*; +import io.anuke.arc.files.*; import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.math.*; import io.anuke.arc.util.*; import io.anuke.arc.util.noise.*; -import io.anuke.mindustry.tools.ImagePacker.*; import io.anuke.mindustry.ctype.*; +import io.anuke.mindustry.tools.ImagePacker.*; import io.anuke.mindustry.type.*; import io.anuke.mindustry.ui.*; import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.blocks.*; -import java.io.*; -import java.nio.file.*; - import static io.anuke.mindustry.Vars.*; public class Generators{ @@ -73,17 +71,13 @@ public class Generators{ for(Block block : content.blocks()){ TextureRegion[] regions = block.getGeneratedIcons(); - try{ - if(block instanceof Floor){ - block.load(); - for(TextureRegion region : block.variantRegions()){ - GenRegion gen = (GenRegion)region; - if(gen.path == null) continue; - Files.copy(gen.path, Paths.get("../editor/editor-" + gen.path.getFileName())); - } + if(block instanceof Floor){ + block.load(); + for(TextureRegion region : block.variantRegions()){ + GenRegion gen = (GenRegion)region; + if(gen.path == null) continue; + gen.path.copyTo(Fi.get("../editor/editor-" + gen.path.name())); } - }catch(IOException e){ - throw new RuntimeException(e); } if(regions.length == 0){ @@ -120,11 +114,7 @@ public class Generators{ } } - try{ - Files.delete(region.path); - }catch(IOException e){ - e.printStackTrace(); - } + region.path.delete(); out.save(block.name); } diff --git a/tools/src/io/anuke/mindustry/tools/ImagePacker.java b/tools/src/io/anuke/mindustry/tools/ImagePacker.java index b5a3787382..226155a245 100644 --- a/tools/src/io/anuke/mindustry/tools/ImagePacker.java +++ b/tools/src/io/anuke/mindustry/tools/ImagePacker.java @@ -1,24 +1,24 @@ package io.anuke.mindustry.tools; -import io.anuke.arc.Core; -import io.anuke.arc.collection.ObjectMap; +import io.anuke.arc.*; +import io.anuke.arc.collection.*; +import io.anuke.arc.files.*; import io.anuke.arc.graphics.g2d.*; -import io.anuke.arc.graphics.g2d.TextureAtlas.AtlasRegion; +import io.anuke.arc.graphics.g2d.TextureAtlas.*; import io.anuke.arc.util.*; import io.anuke.arc.util.Log.*; import io.anuke.mindustry.*; -import io.anuke.mindustry.core.ContentLoader; +import io.anuke.mindustry.core.*; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.nio.file.*; +import javax.imageio.*; +import java.awt.image.*; +import java.io.*; public class ImagePacker{ static ObjectMap regionCache = new ObjectMap<>(); static ObjectMap imageCache = new ObjectMap<>(); - public static void main(String[] args) throws IOException{ + public static void main(String[] args){ Vars.headless = true; Log.setLogger(new NoopLogHandler()); @@ -26,14 +26,11 @@ public class ImagePacker{ Vars.content.createBaseContent(); Log.setLogger(new DefaultLogHandler()); - Files.walk(Paths.get("../../../assets-raw/sprites_out")).forEach(path -> { + Fi.get("../../../assets-raw/sprites_out").walk(path -> { + String fname = path.nameWithoutExtension(); + try{ - if(Files.isDirectory(path)) return; - - String fname = path.getFileName().toString(); - fname = fname.substring(0, fname.length() - 4); - - BufferedImage image = ImageIO.read(path.toFile()); + BufferedImage image = ImageIO.read(path.file()); GenRegion region = new GenRegion(fname, path){ @Override @@ -59,9 +56,8 @@ public class ImagePacker{ regionCache.put(fname, region); imageCache.put(region, image); - }catch(IOException e){ - e.printStackTrace(); + throw new RuntimeException(e); } }); @@ -134,9 +130,9 @@ public class ImagePacker{ static class GenRegion extends AtlasRegion{ String name; boolean invalid; - Path path; + Fi path; - GenRegion(String name, Path path){ + GenRegion(String name, Fi path){ this.name = name; this.path = path; }