diff options
Diffstat (limited to 'src/ch/epfl/maze/graphics/Animation.java')
-rw-r--r-- | src/ch/epfl/maze/graphics/Animation.java | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ch/epfl/maze/graphics/Animation.java b/src/ch/epfl/maze/graphics/Animation.java index 47e0fc8..cd5fa38 100644 --- a/src/ch/epfl/maze/graphics/Animation.java +++ b/src/ch/epfl/maze/graphics/Animation.java | |||
@@ -19,6 +19,8 @@ import java.util.TreeMap; | |||
19 | /** | 19 | /** |
20 | * Handles the animation of a {@code Simulation} by extrapolating the positions | 20 | * Handles the animation of a {@code Simulation} by extrapolating the positions |
21 | * of animals. | 21 | * of animals. |
22 | * | ||
23 | * @author Pacien TRAN-GIRARD | ||
22 | */ | 24 | */ |
23 | 25 | ||
24 | public final class Animation { | 26 | public final class Animation { |
@@ -226,7 +228,9 @@ public final class Animation { | |||
226 | 228 | ||
227 | private BufferedImage loadImage(Animal animal) { | 229 | private BufferedImage loadImage(Animal animal) { |
228 | // path = "img/superclass/class.png" | 230 | // path = "img/superclass/class.png" |
229 | String folder = animal.getClass().getSuperclass().getSimpleName(); | 231 | String superClassName = animal.getClass().getSuperclass().getSimpleName(); |
232 | String[] superClassComponents = this.splitCamelCase(superClassName); | ||
233 | String folder = superClassComponents[superClassComponents.length - 1]; | ||
230 | String file = animal.getClass().getSimpleName(); | 234 | String file = animal.getClass().getSimpleName(); |
231 | String path = "img/" + folder + File.separator + file + ".png"; | 235 | String path = "img/" + folder + File.separator + file + ".png"; |
232 | 236 | ||
@@ -243,4 +247,23 @@ public final class Animation { | |||
243 | 247 | ||
244 | return img; | 248 | return img; |
245 | } | 249 | } |
250 | |||
251 | /** | ||
252 | * Splits a camel case string | ||
253 | * http://stackoverflow.com/a/2560017/1348634 | ||
254 | * | ||
255 | * @param s A string | ||
256 | * @return An array of words | ||
257 | */ | ||
258 | private static String[] splitCamelCase(String s) { | ||
259 | return s.replaceAll( | ||
260 | String.format("%s|%s|%s", | ||
261 | "(?<=[A-Z])(?=[A-Z][a-z])", | ||
262 | "(?<=[^A-Z])(?=[A-Z])", | ||
263 | "(?<=[A-Za-z])(?=[^A-Za-z])" | ||
264 | ), | ||
265 | " " | ||
266 | ).split(" "); | ||
267 | } | ||
268 | |||
246 | } | 269 | } |