cache: split sprite exporter from dumper
This commit is contained in:
@@ -212,8 +212,8 @@ public class Cache
|
||||
|
||||
private static void dumpSprites(Store store, File spritedir) throws IOException
|
||||
{
|
||||
SpriteDumper dumper = new SpriteDumper(store, spritedir);
|
||||
SpriteManager dumper = new SpriteManager(store);
|
||||
dumper.load();
|
||||
dumper.dump();
|
||||
dumper.export(spritedir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,29 +24,26 @@
|
||||
*/
|
||||
package net.runelite.cache;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
import net.runelite.cache.definitions.SpriteDefinition;
|
||||
import net.runelite.cache.definitions.exporters.SpriteExporter;
|
||||
import net.runelite.cache.definitions.loaders.SpriteLoader;
|
||||
import net.runelite.cache.fs.Archive;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Store;
|
||||
|
||||
public class SpriteDumper
|
||||
public class SpriteManager
|
||||
{
|
||||
private final Store store;
|
||||
private final File outDir;
|
||||
private final List<SpriteDefinition> sprites = new ArrayList<>();
|
||||
|
||||
public SpriteDumper(Store store, File outDir)
|
||||
public SpriteManager(Store store)
|
||||
{
|
||||
this.store = store;
|
||||
this.outDir = outDir;
|
||||
}
|
||||
|
||||
public void load()
|
||||
@@ -69,32 +66,25 @@ public class SpriteDumper
|
||||
}
|
||||
}
|
||||
|
||||
public void dump() throws IOException
|
||||
public List<SpriteDefinition> getSprites()
|
||||
{
|
||||
for (SpriteDefinition def : sprites)
|
||||
return sprites;
|
||||
}
|
||||
|
||||
public void export(File outDir) throws IOException
|
||||
{
|
||||
for (SpriteDefinition sprite : sprites)
|
||||
{
|
||||
// I don't know why this happens
|
||||
if (def.getHeight() <= 0 || def.getWidth() <= 0)
|
||||
if (sprite.getHeight() <= 0 || sprite.getWidth() <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
dump(def, outDir);
|
||||
SpriteExporter exporter = new SpriteExporter(sprite);
|
||||
File png = new File(outDir, sprite.getId() + "-" + sprite.getFrame() + ".png");
|
||||
|
||||
exporter.exportTo(png);
|
||||
}
|
||||
}
|
||||
|
||||
public static void dump(SpriteDefinition sprite, File outDir) throws IOException
|
||||
{
|
||||
BufferedImage image = getBufferedImage(sprite);
|
||||
File targ = new File(outDir, sprite.getId() + "-" + sprite.getFrame() + ".png");
|
||||
targ.mkdirs();
|
||||
ImageIO.write(image, "png", targ);
|
||||
}
|
||||
|
||||
private static BufferedImage getBufferedImage(SpriteDefinition def)
|
||||
{
|
||||
BufferedImage bi = new BufferedImage(def.getWidth(), def.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
bi.setRGB(0, 0, def.getWidth(), def.getHeight(), def.getPixels(), 0, def.getWidth());
|
||||
return bi;
|
||||
}
|
||||
}
|
||||
54
cache/src/main/java/net/runelite/cache/definitions/exporters/SpriteExporter.java
vendored
Normal file
54
cache/src/main/java/net/runelite/cache/definitions/exporters/SpriteExporter.java
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.definitions.exporters;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import net.runelite.cache.definitions.SpriteDefinition;
|
||||
|
||||
public class SpriteExporter
|
||||
{
|
||||
private final SpriteDefinition sprite;
|
||||
|
||||
public SpriteExporter(SpriteDefinition sprite)
|
||||
{
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public BufferedImage export()
|
||||
{
|
||||
BufferedImage bi = new BufferedImage(sprite.getWidth(), sprite.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
bi.setRGB(0, 0, sprite.getWidth(), sprite.getHeight(), sprite.getPixels(), 0, sprite.getWidth());
|
||||
return bi;
|
||||
}
|
||||
|
||||
public void exportTo(File file) throws IOException
|
||||
{
|
||||
BufferedImage image = export();
|
||||
ImageIO.write(image, "png", file);
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SpriteDumperTest
|
||||
public class SpriteManagerTest
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpriteDumperTest.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpriteManagerTest.class);
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = StoreLocation.getTemporaryFolder();
|
||||
@@ -49,12 +49,11 @@ public class SpriteDumperTest
|
||||
{
|
||||
store.load();
|
||||
|
||||
SpriteDumper dumper = new SpriteDumper(
|
||||
store,
|
||||
dumpDir
|
||||
SpriteManager dumper = new SpriteManager(
|
||||
store
|
||||
);
|
||||
dumper.load();
|
||||
dumper.dump();
|
||||
dumper.export(dumpDir);
|
||||
}
|
||||
|
||||
logger.info("Dumped to {}", dumpDir);
|
||||
Reference in New Issue
Block a user