cache: add texture manager
This commit is contained in:
76
cache/src/main/java/net/runelite/cache/TextureManager.java
vendored
Normal file
76
cache/src/main/java/net/runelite/cache/TextureManager.java
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 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;
|
||||
|
||||
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<TextureDefinition> 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<TextureDefinition> getTextures()
|
||||
{
|
||||
return textures;
|
||||
}
|
||||
|
||||
public TextureDefinition findTexture(int id)
|
||||
{
|
||||
for (TextureDefinition td : textures)
|
||||
{
|
||||
if (td.getId() == id)
|
||||
{
|
||||
return td;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user