From 731fa488dd0a9c675a22283dd91003097468fed4 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 26 Mar 2017 19:48:28 -0400 Subject: [PATCH] cache: add texture manager --- .../net/runelite/cache/TextureManager.java | 76 +++++++++++++++++++ .../net/runelite/cache/TextureDumper.java | 13 +--- 2 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 cache/src/main/java/net/runelite/cache/TextureManager.java diff --git a/cache/src/main/java/net/runelite/cache/TextureManager.java b/cache/src/main/java/net/runelite/cache/TextureManager.java new file mode 100644 index 0000000000..8a5e38e1e6 --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/TextureManager.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017, Adam + * 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; + +import java.util.ArrayList; +import java.util.List; +import net.runelite.cache.definitions.TextureDefinition; +import net.runelite.cache.definitions.loaders.TextureLoader; +import net.runelite.cache.fs.Archive; +import net.runelite.cache.fs.File; +import net.runelite.cache.fs.Index; +import net.runelite.cache.fs.Store; + +public class TextureManager +{ + private final Store store; + private final List textures = new ArrayList<>(); + + public TextureManager(Store store) + { + this.store = store; + } + + public void load() + { + Index index = store.getIndex(IndexType.TEXTURES); + Archive archive = index.getArchive(0); + + TextureLoader loader = new TextureLoader(); + + for (File file : archive.getFiles()) + { + TextureDefinition texture = loader.load(file.getFileId(), file.getContents()); + textures.add(texture); + } + } + + public List getTextures() + { + return textures; + } + + public TextureDefinition findTexture(int id) + { + for (TextureDefinition td : textures) + { + if (td.getId() == id) + { + return td; + } + } + return null; + } +} diff --git a/cache/src/test/java/net/runelite/cache/TextureDumper.java b/cache/src/test/java/net/runelite/cache/TextureDumper.java index 4c12df4694..c64b2b3a03 100644 --- a/cache/src/test/java/net/runelite/cache/TextureDumper.java +++ b/cache/src/test/java/net/runelite/cache/TextureDumper.java @@ -30,10 +30,6 @@ import com.google.gson.GsonBuilder; import java.io.IOException; import java.nio.charset.Charset; import net.runelite.cache.definitions.TextureDefinition; -import net.runelite.cache.definitions.loaders.TextureLoader; -import net.runelite.cache.fs.Archive; -import net.runelite.cache.fs.File; -import net.runelite.cache.fs.Index; import net.runelite.cache.fs.Store; import org.junit.Rule; import org.junit.Test; @@ -62,14 +58,11 @@ public class TextureDumper { store.load(); - Index index = store.getIndex(IndexType.TEXTURES); - Archive archive = index.getArchive(0); + TextureManager tm = new TextureManager(store); + tm.load(); - for (File file : archive.getFiles()) + for (TextureDefinition texture : tm.getTextures()) { - TextureLoader loader = new TextureLoader(); - TextureDefinition texture = loader.load(file.getFileId(), file.getContents()); - Files.write(gson.toJson(texture), new java.io.File(outDir, texture.getId() + ".json"), Charset.defaultCharset()); ++count; }