summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/util/ObjectLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland/fourpuzzle/util/ObjectLoader.java')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/util/ObjectLoader.java49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java index 7f7128f..2000a1c 100755 --- a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java +++ b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java
@@ -8,9 +8,9 @@ package com.fourisland.fourpuzzle.util;
8import com.fourisland.fourpuzzle.PuzzleApplication; 8import com.fourisland.fourpuzzle.PuzzleApplication;
9import java.awt.Color; 9import java.awt.Color;
10import java.awt.image.BufferedImage; 10import java.awt.image.BufferedImage;
11import java.io.File;
12import java.io.IOException; 11import java.io.IOException;
13import java.io.InputStream; 12import java.io.InputStream;
13import java.net.URL;
14import java.util.HashMap; 14import java.util.HashMap;
15import java.util.Map.Entry; 15import java.util.Map.Entry;
16import java.util.logging.Level; 16import java.util.logging.Level;
@@ -56,14 +56,8 @@ public class ObjectLoader {
56 if (!objectCache.containsKey(type + "/" + name)) 56 if (!objectCache.containsKey(type + "/" + name))
57 { 57 {
58 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); 58 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
59 String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; 59 String filename = getFilename(type, name, "png");
60 InputStream str = rm.getClassLoader().getResourceAsStream(filename); 60 InputStream str = rm.getClassLoader().getResourceAsStream(filename);
61
62 if (str == null)
63 {
64 throw new ResourceNotFoundException(type, name);
65 }
66
67 BufferedImage bImg = null; 61 BufferedImage bImg = null;
68 try { 62 try {
69 bImg = ImageIO.read(str); 63 bImg = ImageIO.read(str);
@@ -82,14 +76,8 @@ public class ObjectLoader {
82 if (!objectCache.containsKey(type + "/" + name)) 76 if (!objectCache.containsKey(type + "/" + name))
83 { 77 {
84 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); 78 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
85 String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; 79 String filename = getFilename(type, name, "png");
86 InputStream str = rm.getClassLoader().getResourceAsStream(filename); 80 InputStream str = rm.getClassLoader().getResourceAsStream(filename);
87
88 if (str == null)
89 {
90 throw new ResourceNotFoundException(type, name);
91 }
92
93 BufferedImage bImg = null; 81 BufferedImage bImg = null;
94 try { 82 try {
95 bImg = ImageIO.read(str); 83 bImg = ImageIO.read(str);
@@ -120,13 +108,8 @@ public class ObjectLoader {
120 if (!objectCache.containsKey("Music/" + name)) 108 if (!objectCache.containsKey("Music/" + name))
121 { 109 {
122 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); 110 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
123 String filename = rm.getResourcesDir() + "music/" + name + ".mid"; 111 String filename = getFilename("Music", name, "mid");
124 InputStream str = rm.getClassLoader().getResourceAsStream(filename); 112 InputStream str = rm.getClassLoader().getResourceAsStream(filename);
125 if (str == null)
126 {
127 throw new ResourceNotFoundException("Music", name);
128 }
129
130 Sequence seq = null; 113 Sequence seq = null;
131 try { 114 try {
132 seq = MidiSystem.getSequence(str); 115 seq = MidiSystem.getSequence(str);
@@ -147,7 +130,7 @@ public class ObjectLoader {
147 if (!objectCache.containsKey("Sound/" + name)) 130 if (!objectCache.containsKey("Sound/" + name))
148 { 131 {
149 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); 132 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
150 String filename = rm.getResourcesDir() + "sound/" + name + ".wav"; 133 String filename = getFilename("Sound", name, "wav");
151 InputStream soundFile = rm.getClassLoader().getResourceAsStream(filename); 134 InputStream soundFile = rm.getClassLoader().getResourceAsStream(filename);
152 AudioInputStream ais = null; 135 AudioInputStream ais = null;
153 try { 136 try {
@@ -155,7 +138,7 @@ public class ObjectLoader {
155 } catch (UnsupportedAudioFileException ex) { 138 } catch (UnsupportedAudioFileException ex) {
156 Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); 139 Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex);
157 } catch (IOException ex) { 140 } catch (IOException ex) {
158 throw new ResourceNotFoundException("Sound", name); 141 Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex);
159 } 142 }
160 143
161 AudioFormat af = ais.getFormat(); 144 AudioFormat af = ais.getFormat();
@@ -181,4 +164,24 @@ public class ObjectLoader {
181 return (Clip) objectCache.get("Sound/" + name); 164 return (Clip) objectCache.get("Sound/" + name);
182 } 165 }
183 166
167 public static String getFilename(String type, String name, String ex)
168 {
169 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
170 String f = rm.getResourcesDir() + type.toLowerCase() + "/" + name + "." + ex;
171 URL fu = rm.getClassLoader().getResource(f);
172
173 if (fu == null)
174 {
175 f = "com/fourisland/fourpuzzle/resources/" + type.toLowerCase() + "/" + name + "." + ex;
176 fu = rm.getClassLoader().getResource(f);
177
178 if (fu == null)
179 {
180 throw new ResourceNotFoundException(type, name);
181 }
182 }
183
184 return f;
185 }
186
184} 187}