summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/TextureDecoder.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/TextureDecoder.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/TextureDecoder.java')
-rw-r--r--NET/worlds/scape/TextureDecoder.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/NET/worlds/scape/TextureDecoder.java b/NET/worlds/scape/TextureDecoder.java
new file mode 100644
index 0000000..42477db
--- /dev/null
+++ b/NET/worlds/scape/TextureDecoder.java
@@ -0,0 +1,73 @@
+package NET.worlds.scape;
+
+import NET.worlds.network.URL;
+import java.io.File;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+
+public abstract class TextureDecoder {
+ protected static Hashtable handlers = new Hashtable();
+ private static TextureDecoder defaultDecoder;
+ private static String allExts;
+
+ static {
+ addHandler(defaultDecoder = new FileTextureDecoder());
+ addHandler(new StandardTextureDecoder());
+ addHandler(new ScapePicTextureDecoder());
+ }
+
+ protected abstract String getExts();
+
+ protected abstract Texture read(String var1, String var2);
+
+ private static void addHandler(TextureDecoder decoder) {
+ StringTokenizer e = new StringTokenizer(decoder.getExts(), ";");
+
+ while (e.hasMoreTokens()) {
+ String ext = e.nextToken().toLowerCase();
+ handlers.put(ext, decoder);
+ if (allExts == null) {
+ allExts = ext;
+ } else {
+ allExts = allExts + File.pathSeparator + ext;
+ }
+ }
+ }
+
+ public static String getAllExts() {
+ return allExts;
+ }
+
+ public static String getJavaExts() {
+ return new StandardTextureDecoder().getExts();
+ }
+
+ public static Texture decode(URL url, String filename) {
+ return decode(url, url.getAbsolute(), filename);
+ }
+
+ public static Texture decode(URL url, String lookupName, String filename) {
+ Texture tex = FileTexture.dictLookup(lookupName);
+ if (tex != null) {
+ return tex;
+ } else {
+ String urlName = url.getInternal();
+ int delim = urlName.lastIndexOf(46);
+ int lastPath = urlName.lastIndexOf(47);
+ lastPath = Math.max(lastPath, urlName.lastIndexOf(92));
+ lastPath = Math.max(lastPath, urlName.lastIndexOf(58));
+ if (delim > lastPath) {
+ String ext = urlName.substring(delim + 1).toLowerCase();
+ TextureDecoder decoder = (TextureDecoder)handlers.get(ext);
+ if (decoder != null) {
+ Texture t = decoder.read(lookupName, filename);
+ if (t.textureID != 0) {
+ return t;
+ }
+ }
+ }
+
+ return null;
+ }
+ }
+}