summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze')
-rw-r--r--src/ch/epfl/maze/graphics/Animation.java22
1 files changed, 1 insertions, 21 deletions
diff --git a/src/ch/epfl/maze/graphics/Animation.java b/src/ch/epfl/maze/graphics/Animation.java
index 497d417..9882231 100644
--- a/src/ch/epfl/maze/graphics/Animation.java
+++ b/src/ch/epfl/maze/graphics/Animation.java
@@ -220,9 +220,7 @@ public final class Animation {
220 */ 220 */
221 private BufferedImage loadImage(Animal animal) { 221 private BufferedImage loadImage(Animal animal) {
222 // path = "img/superclass/class.png" 222 // path = "img/superclass/class.png"
223 String superClassName = animal.getClass().getSuperclass().getSimpleName(); 223 String folder = animal.getClass().getSuperclass().getSimpleName();
224 String[] superClassComponents = Animation.splitCamelCase(superClassName);
225 String folder = superClassComponents[superClassComponents.length - 1];
226 String file = animal.getClass().getSimpleName(); 224 String file = animal.getClass().getSimpleName();
227 String path = "img/" + folder + File.separator + file + ".png"; 225 String path = "img/" + folder + File.separator + file + ".png";
228 226
@@ -240,22 +238,4 @@ public final class Animation {
240 return img; 238 return img;
241 } 239 }
242 240
243 /**
244 * Splits a camel case string
245 * http://stackoverflow.com/a/2560017/1348634
246 *
247 * @param s A string
248 * @return An array of words
249 */
250 private static String[] splitCamelCase(String s) {
251 return s.replaceAll(
252 String.format("%s|%s|%s",
253 "(?<=[A-Z])(?=[A-Z][a-z])",
254 "(?<=[^A-Z])(?=[A-Z])",
255 "(?<=[A-Za-z])(?=[^A-Za-z])"
256 ),
257 " "
258 ).split(" ");
259 }
260
261} 241}