Fixé bug de lancement en runtime
This commit is contained in:
parent
c7b6450ba3
commit
0c965d4738
|
@ -1,5 +1,7 @@
|
||||||
package galaxyoyo.unknown.api.editor.sprites;
|
package galaxyoyo.unknown.api.editor.sprites;
|
||||||
|
|
||||||
|
import galaxyoyo.unknown.client.main.Main;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -8,12 +10,16 @@ import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
@ -26,16 +32,39 @@ public class SpriteRegister
|
||||||
private static Map<String, List<List<Double>>> nameToCoords;
|
private static Map<String, List<List<Double>>> nameToCoords;
|
||||||
private static Map<String, Category> sprites = new HashMap<String, Category>();
|
private static Map<String, Category> sprites = new HashMap<String, Category>();
|
||||||
|
|
||||||
public static void unpack()
|
public static void unpack() throws IOException, URISyntaxException
|
||||||
{
|
{
|
||||||
try
|
if (Main.isInDevelopmentMode())
|
||||||
{
|
{
|
||||||
File dir = new File(SpriteRegister.class.getResource("/assets").toURI());
|
File dir = new File(SpriteRegister.class.getResource("/assets").toURI());
|
||||||
unpackDir(dir);
|
unpackDir(dir);
|
||||||
}
|
}
|
||||||
catch (URISyntaxException | IOException e)
|
else
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
@SuppressWarnings("deprecation")
|
||||||
|
String path = URLDecoder.decode(SpriteRegister.class.getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||||
|
path = path.substring(1, path.length());
|
||||||
|
File jarFile = new File(path);
|
||||||
|
|
||||||
|
if(jarFile.isFile())
|
||||||
|
{
|
||||||
|
JarFile jar = new JarFile(jarFile);
|
||||||
|
Enumeration<JarEntry> entries = jar.entries();
|
||||||
|
while (entries.hasMoreElements())
|
||||||
|
{
|
||||||
|
JarEntry je = entries.nextElement();
|
||||||
|
String name = je.getName();
|
||||||
|
if (name.startsWith("assets/"))
|
||||||
|
{
|
||||||
|
File f = new File(name);
|
||||||
|
if (name.endsWith("/"))
|
||||||
|
f.mkdirs();
|
||||||
|
else if (!f.isFile())
|
||||||
|
Files.copy(jar.getInputStream(je), Paths.get(f.toURI()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jar.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.awt.Graphics2D;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.HeadlessException;
|
import java.awt.HeadlessException;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -66,7 +67,15 @@ public class Main
|
||||||
|
|
||||||
Locale.setDefault(Locale.FRANCE);
|
Locale.setDefault(Locale.FRANCE);
|
||||||
|
|
||||||
DEV = Main.class.getClassLoader().getResource("/META-INF/MANIFEST.MF") == null;
|
try
|
||||||
|
{
|
||||||
|
new File(Main.class.getResource("/assets").toURI());
|
||||||
|
DEV = true;
|
||||||
|
}
|
||||||
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
DEV = false;
|
||||||
|
}
|
||||||
|
|
||||||
Logger LOGGER = (Logger) LogManager.getRootLogger();
|
Logger LOGGER = (Logger) LogManager.getRootLogger();
|
||||||
ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build();
|
ConsoleAppender console = ConsoleAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern("[%d{dd/MM/yyyy}] [%d{HH:mm:ss}] [%t] [%c] [%p] %m%n").build()).setName("Console").build();
|
||||||
|
@ -110,7 +119,14 @@ public class Main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
SpriteRegister.unpack();
|
SpriteRegister.unpack();
|
||||||
|
}
|
||||||
|
catch (IOException | URISyntaxException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
SpriteRegister.refreshAllSprites();
|
SpriteRegister.refreshAllSprites();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue