Removed Path API usage

This commit is contained in:
Anuken
2019-12-15 21:12:41 -05:00
parent 0cf39bf5c3
commit e9ed0512f7
4 changed files with 87 additions and 115 deletions
@@ -7,8 +7,6 @@ import io.anuke.arc.files.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.arc.util.io.*; import io.anuke.arc.util.io.*;
import java.io.*;
public class Version{ public class Version{
/** Build type. 'official' for official releases; 'custom' or 'bleeding edge' are also used. */ /** Build type. 'official' for official releases; 'custom' or 'bleeding edge' are also used. */
public static String type; public static String type;
@@ -26,7 +24,6 @@ public class Version{
public static void init(){ public static void init(){
if(!enabled) return; 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<String, String> map = new ObjectMap<>(); ObjectMap<String, String> map = new ObjectMap<>();
@@ -47,8 +44,5 @@ public class Version{
}else{ }else{
build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1; build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1;
} }
}catch(IOException e){
throw new RuntimeException(e);
}
} }
} }
@@ -1,14 +1,12 @@
package io.anuke.mindustry.tools; package io.anuke.mindustry.tools;
import io.anuke.arc.collection.Array; import io.anuke.arc.collection.*;
import io.anuke.arc.collection.OrderedMap; import io.anuke.arc.files.*;
import io.anuke.arc.func.Func2; import io.anuke.arc.func.*;
import io.anuke.arc.util.Log; import io.anuke.arc.util.*;
import io.anuke.arc.util.Strings; import io.anuke.arc.util.io.*;
import io.anuke.arc.util.io.PropertiesUtils;
import java.io.*; import java.io.*;
import java.nio.file.*;
public class BundleLauncher{ public class BundleLauncher{
@@ -17,16 +15,14 @@ public class BundleLauncher{
OrderedMap<String, String> base = new OrderedMap<>(); OrderedMap<String, String> base = new OrderedMap<>();
PropertiesUtils.load(base, new InputStreamReader(new FileInputStream(file))); PropertiesUtils.load(base, new InputStreamReader(new FileInputStream(file)));
Array<String> removals = new Array<>(); Array<String> removals = new Array<>();
Fi.get("").walk(child -> {
Files.walk(Paths.get("")).forEach(child -> { if(child.name().equals("bundle.properties") || child.isDirectory() || child.toString().contains("output"))
try{
if(child.getFileName().toString().equals("bundle.properties") || Files.isDirectory(child) || child.toString().contains("output"))
return; return;
Log.info("Parsing bundle: {0}", child); Log.info("Parsing bundle: {0}", child);
OrderedMap<String, String> other = new OrderedMap<>(); OrderedMap<String, String> other = new OrderedMap<>();
PropertiesUtils.load(other, Files.newBufferedReader(child, Strings.utf8)); PropertiesUtils.load(other, child.reader(2048, "UTF-8"));
removals.clear(); removals.clear();
for(String key : other.orderedKeys()){ for(String key : other.orderedKeys()){
@@ -52,7 +48,7 @@ public class BundleLauncher{
Func2<String, String, String> processor = (key, value) -> (key + " = " + value).replace("\\", "\\\\").replace("\n", "\\n") + "\n"; Func2<String, String, String> processor = (key, value) -> (key + " = " + value).replace("\\", "\\\\").replace("\n", "\\n") + "\n";
Path output = child.resolveSibling("output/" + child.getFileName()); Fi output = child.sibling("output/" + child.name());
Log.info("&lc{0} keys added.", added); Log.info("&lc{0} keys added.", added);
Log.info("Writing bundle to {0}", output); Log.info("Writing bundle to {0}", output);
@@ -64,11 +60,7 @@ public class BundleLauncher{
other.remove(key); other.remove(key);
} }
Files.write(child, result.toString().getBytes(Strings.utf8)); child.writeString(result.toString());
}catch(IOException e){
throw new RuntimeException(e);
}
}); });
} }
@@ -1,21 +1,19 @@
package io.anuke.mindustry.tools; package io.anuke.mindustry.tools;
import io.anuke.arc.collection.*; import io.anuke.arc.collection.*;
import io.anuke.arc.files.*;
import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.*; import io.anuke.arc.math.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.arc.util.noise.*; import io.anuke.arc.util.noise.*;
import io.anuke.mindustry.tools.ImagePacker.*;
import io.anuke.mindustry.ctype.*; import io.anuke.mindustry.ctype.*;
import io.anuke.mindustry.tools.ImagePacker.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.ui.*; import io.anuke.mindustry.ui.*;
import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.*; import io.anuke.mindustry.world.blocks.*;
import java.io.*;
import java.nio.file.*;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public class Generators{ public class Generators{
@@ -73,18 +71,14 @@ public class Generators{
for(Block block : content.blocks()){ for(Block block : content.blocks()){
TextureRegion[] regions = block.getGeneratedIcons(); TextureRegion[] regions = block.getGeneratedIcons();
try{
if(block instanceof Floor){ if(block instanceof Floor){
block.load(); block.load();
for(TextureRegion region : block.variantRegions()){ for(TextureRegion region : block.variantRegions()){
GenRegion gen = (GenRegion)region; GenRegion gen = (GenRegion)region;
if(gen.path == null) continue; if(gen.path == null) continue;
Files.copy(gen.path, Paths.get("../editor/editor-" + gen.path.getFileName())); gen.path.copyTo(Fi.get("../editor/editor-" + gen.path.name()));
} }
} }
}catch(IOException e){
throw new RuntimeException(e);
}
if(regions.length == 0){ if(regions.length == 0){
continue; continue;
@@ -120,11 +114,7 @@ public class Generators{
} }
} }
try{ region.path.delete();
Files.delete(region.path);
}catch(IOException e){
e.printStackTrace();
}
out.save(block.name); out.save(block.name);
} }
@@ -1,24 +1,24 @@
package io.anuke.mindustry.tools; package io.anuke.mindustry.tools;
import io.anuke.arc.Core; import io.anuke.arc.*;
import io.anuke.arc.collection.ObjectMap; import io.anuke.arc.collection.*;
import io.anuke.arc.files.*;
import io.anuke.arc.graphics.g2d.*; 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.*;
import io.anuke.arc.util.Log.*; import io.anuke.arc.util.Log.*;
import io.anuke.mindustry.*; import io.anuke.mindustry.*;
import io.anuke.mindustry.core.ContentLoader; import io.anuke.mindustry.core.*;
import javax.imageio.ImageIO; import javax.imageio.*;
import java.awt.image.BufferedImage; import java.awt.image.*;
import java.io.IOException; import java.io.*;
import java.nio.file.*;
public class ImagePacker{ public class ImagePacker{
static ObjectMap<String, TextureRegion> regionCache = new ObjectMap<>(); static ObjectMap<String, TextureRegion> regionCache = new ObjectMap<>();
static ObjectMap<TextureRegion, BufferedImage> imageCache = new ObjectMap<>(); static ObjectMap<TextureRegion, BufferedImage> imageCache = new ObjectMap<>();
public static void main(String[] args) throws IOException{ public static void main(String[] args){
Vars.headless = true; Vars.headless = true;
Log.setLogger(new NoopLogHandler()); Log.setLogger(new NoopLogHandler());
@@ -26,14 +26,11 @@ public class ImagePacker{
Vars.content.createBaseContent(); Vars.content.createBaseContent();
Log.setLogger(new DefaultLogHandler()); 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{ try{
if(Files.isDirectory(path)) return; BufferedImage image = ImageIO.read(path.file());
String fname = path.getFileName().toString();
fname = fname.substring(0, fname.length() - 4);
BufferedImage image = ImageIO.read(path.toFile());
GenRegion region = new GenRegion(fname, path){ GenRegion region = new GenRegion(fname, path){
@Override @Override
@@ -59,9 +56,8 @@ public class ImagePacker{
regionCache.put(fname, region); regionCache.put(fname, region);
imageCache.put(region, image); imageCache.put(region, image);
}catch(IOException e){ }catch(IOException e){
e.printStackTrace(); throw new RuntimeException(e);
} }
}); });
@@ -134,9 +130,9 @@ public class ImagePacker{
static class GenRegion extends AtlasRegion{ static class GenRegion extends AtlasRegion{
String name; String name;
boolean invalid; boolean invalid;
Path path; Fi path;
GenRegion(String name, Path path){ GenRegion(String name, Fi path){
this.name = name; this.name = name;
this.path = path; this.path = path;
} }