Permalink
Browse files

First commit that contains the new Resources API with all the refacto…

…rings.

With this commit, all resources in the LITIengine (namely: fonts, spritesheets, sounds, images, strings and maps) are now retrieved via this API.
This unifies the syntax of accessing resources and cleans up the actual Resource implementations by removing a ton of static stuff.

Examples for the change:
Spritesheet.find("some-sprite") -> Resources.spritesheets().get("some-sprite")
Sound.get("sound.ogg") -> Resources.sounds().get("sound.ogg")
Resources.getImage("img.png") -> Resources.images().get("img.png")
Resources.getFont("test.ttf") -> Resources.fonts().get("test.ttf")
Resources.get("localizable-string") -> Resources.strings().get("localizable-string")
Game.getMap("map-name") -> Resources.maps().get("map-name")
  • Loading branch information...
steffen-wilke committed Nov 23, 2018
1 parent cff282b commit e02f390f93e6d2e657e45d2350538dcdd4d3848e
Showing with 1,105 additions and 989 deletions.
  1. +6 −44 src/de/gurkenlabs/litiengine/Game.java
  2. +0 −234 src/de/gurkenlabs/litiengine/Resources.java
  3. +2 −1 src/de/gurkenlabs/litiengine/SpritesheetInfo.java
  4. +2 −7 src/de/gurkenlabs/litiengine/environment/Environment.java
  5. +3 −2 src/de/gurkenlabs/litiengine/environment/tilemap/HexagonalMapRenderer.java
  6. +3 −2 src/de/gurkenlabs/litiengine/environment/tilemap/OrthogonalMapRenderer.java
  7. +4 −3 src/de/gurkenlabs/litiengine/environment/tilemap/xml/Tileset.java
  8. +7 −228 src/de/gurkenlabs/litiengine/graphics/Spritesheet.java
  9. +4 −3 src/de/gurkenlabs/litiengine/graphics/animation/Animation.java
  10. +3 −2 src/de/gurkenlabs/litiengine/graphics/animation/AnimationController.java
  11. +7 −6 src/de/gurkenlabs/litiengine/graphics/animation/CreatureAnimationController.java
  12. +2 −1 src/de/gurkenlabs/litiengine/graphics/animation/EntityAnimationController.java
  13. +9 −7 src/de/gurkenlabs/litiengine/graphics/animation/PropAnimationController.java
  14. +2 −1 src/de/gurkenlabs/litiengine/graphics/emitters/xml/CustomEmitter.java
  15. +2 −2 src/de/gurkenlabs/litiengine/gui/GuiComponent.java
  16. +1 −1 src/de/gurkenlabs/litiengine/gui/ImageComponent.java
  17. +51 −0 src/de/gurkenlabs/litiengine/resources/Fonts.java
  18. +1 −1 src/de/gurkenlabs/litiengine/{graphics → resources}/ImageCache.java
  19. +69 −0 src/de/gurkenlabs/litiengine/resources/Images.java
  20. +15 −0 src/de/gurkenlabs/litiengine/resources/Maps.java
  21. +46 −0 src/de/gurkenlabs/litiengine/resources/Resources.java
  22. +118 −0 src/de/gurkenlabs/litiengine/resources/ResourcesContainer.java
  23. +33 −0 src/de/gurkenlabs/litiengine/resources/Sounds.java
  24. +195 −0 src/de/gurkenlabs/litiengine/resources/Spritesheets.java
  25. +139 −0 src/de/gurkenlabs/litiengine/resources/Strings.java
  26. +1 −24 src/de/gurkenlabs/litiengine/sound/Sound.java
  27. +2 −1 tests/de/gurkenlabs/litiengine/graphics/AnimationEmitterTests.java
  28. +30 −22 utiliti/src/de/gurkenlabs/utiliti/EditorScreen.java
  29. +56 −56 utiliti/src/de/gurkenlabs/utiliti/Icons.java
  30. +33 −33 utiliti/src/de/gurkenlabs/utiliti/MapSelectionPanel.java
  31. +72 −72 utiliti/src/de/gurkenlabs/utiliti/Program.java
  32. +13 −12 utiliti/src/de/gurkenlabs/utiliti/components/MapComponent.java
  33. +6 −4 utiliti/src/de/gurkenlabs/utiliti/swing/AssetPanel.java
  34. +8 −6 utiliti/src/de/gurkenlabs/utiliti/swing/AssetPanelItem.java
  35. +9 −9 utiliti/src/de/gurkenlabs/utiliti/swing/AssetTree.java
  36. +13 −7 utiliti/src/de/gurkenlabs/utiliti/swing/IconTreeListRenderer.java
  37. +6 −6 utiliti/src/de/gurkenlabs/utiliti/swing/dialogs/GridEditPanel.java
  38. +3 −3 utiliti/src/de/gurkenlabs/utiliti/swing/dialogs/MapPropertyPanel.java
  39. +2 −2 utiliti/src/de/gurkenlabs/utiliti/swing/dialogs/SpritesheetImportPanel.java
  40. +4 −4 utiliti/src/de/gurkenlabs/utiliti/swing/panels/CollisionBoxPanel.java
  41. +4 −4 utiliti/src/de/gurkenlabs/utiliti/swing/panels/CollisionPanel.java
  42. +19 −36 utiliti/src/de/gurkenlabs/utiliti/swing/panels/CreaturePanel.java
  43. +3 −3 utiliti/src/de/gurkenlabs/utiliti/swing/panels/CustomPanel.java
  44. +4 −4 utiliti/src/de/gurkenlabs/utiliti/swing/panels/EmitterPanel.java
  45. +31 −31 utiliti/src/de/gurkenlabs/utiliti/swing/panels/EmitterPropertyPanel.java
  46. +6 −6 utiliti/src/de/gurkenlabs/utiliti/swing/panels/LightSourcePanel.java
  47. +7 −7 utiliti/src/de/gurkenlabs/utiliti/swing/panels/MapObjectPanel.java
  48. +30 −75 utiliti/src/de/gurkenlabs/utiliti/swing/panels/PropPanel.java
  49. +5 −3 utiliti/src/de/gurkenlabs/utiliti/swing/panels/PropertyPanel.java
  50. +4 −4 utiliti/src/de/gurkenlabs/utiliti/swing/panels/SpawnpointPanel.java
  51. +3 −3 utiliti/src/de/gurkenlabs/utiliti/swing/panels/StaticShadowPanel.java
  52. +7 −7 utiliti/src/de/gurkenlabs/utiliti/swing/panels/TriggerPanel.java
@@ -29,6 +29,7 @@
import de.gurkenlabs.litiengine.input.Input.InputGameAdapter;
import de.gurkenlabs.litiengine.physics.IPhysicsEngine;
import de.gurkenlabs.litiengine.physics.PhysicsEngine;
import de.gurkenlabs.litiengine.resources.Resources;
import de.gurkenlabs.litiengine.sound.ISoundEngine;
import de.gurkenlabs.litiengine.sound.SoundEngine;
import de.gurkenlabs.litiengine.util.ArrayUtilities;
@@ -79,7 +80,6 @@
private static final SoundEngine soundEngine;
private static final IPhysicsEngine physicsEngine;

private static final List<IMap> maps;
private static final List<ITileset> tilesets;
private static final GameMetrics metrics;

@@ -105,14 +105,14 @@
soundEngine = new SoundEngine();
metrics = new GameMetrics();
gameInfo = new GameInfo();
maps = new CopyOnWriteArrayList<>();

tilesets = new CopyOnWriteArrayList<>();
gameTime = new GameTime();

// init configuration before init method in order to use configured values
// to initialize components
configuration = new GameConfiguration();

addGameListener(new InputGameAdapter());
}

@@ -210,40 +210,6 @@ public static IGameLoop getLoop() {
return gameLoop;
}

/**
* Get a Map that was already loaded into memory by its name.
* It is important that maps always have a unique name because only the first match will be retrieved.
*
* @param mapName
* the name of the map you want to load
*
* @return
* null if no map with the provided name was found, otherwise the first found map.
*/
public static IMap getMap(final String mapName) {
if (mapName == null || mapName.isEmpty() || maps.isEmpty()) {
return null;
}

for (final IMap map : maps) {
if (map.getName().equals(mapName)) {
return map;
}
}

return null;
}

/**
* Get a list of maps that are already loaded into memory.
*
* @return
* a list of all previously loaded maps
*/
public static List<IMap> getMaps() {
return maps;
}

public static List<ITileset> getTilesets() {
return tilesets;
}
@@ -355,7 +321,7 @@ public static void init(String... args) {
}

getScreenManager().getRenderComponent().onFpsChanged(fps -> getMetrics().setFramesPerSecond(fps));
getScreenManager().setIconImage(Resources.getImage("litiengine-icon.png"));
getScreenManager().setIconImage(Resources.images().get("litiengine-icon.png"));

// init mouse inputs
getScreenManager().getRenderComponent().addMouseListener(Input.mouse());
@@ -390,11 +356,7 @@ public static void load(final String gameResourceFile) {

int mapCnt = 0;
for (final IMap m : file.getMaps()) {
if (getMaps().stream().anyMatch(x -> x.getName().equals(m.getName()))) {
continue;
}

getMaps().add(m);
Resources.maps().add(m.getName(), m);
mapCnt++;
}

@@ -414,7 +376,7 @@ public static void load(final String gameResourceFile) {

final List<Spritesheet> loadedSprites = new ArrayList<>();
for (final SpritesheetInfo tileset : file.getSpriteSheets()) {
final Spritesheet sprite = Spritesheet.load(tileset);
final Spritesheet sprite = Resources.spritesheets().load(tileset);
loadedSprites.add(sprite);
}

This file was deleted.

Oops, something went wrong.
@@ -10,6 +10,7 @@
import javax.xml.bind.annotation.XmlTransient;

import de.gurkenlabs.litiengine.graphics.Spritesheet;
import de.gurkenlabs.litiengine.resources.Resources;
import de.gurkenlabs.litiengine.util.ArrayUtilities;
import de.gurkenlabs.litiengine.util.ImageProcessing;

@@ -39,7 +40,7 @@ public SpritesheetInfo() {
public SpritesheetInfo(final Spritesheet sprite) {
this(sprite.getSpriteWidth(), sprite.getSpriteHeight(), sprite.getName());
this.setImage(ImageProcessing.encodeToString(sprite.getImage(), sprite.getImageFormat()));
this.setKeyframes(Spritesheet.getCustomKeyFrameDurations(sprite));
this.setKeyframes(Resources.spritesheets().getCustomKeyFrameDurations(sprite));
}

public SpritesheetInfo(final BufferedImage image, String name, final int width, final int height) {
@@ -42,7 +42,6 @@
import de.gurkenlabs.litiengine.environment.tilemap.IMap;
import de.gurkenlabs.litiengine.environment.tilemap.IMapObject;
import de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer;
import de.gurkenlabs.litiengine.environment.tilemap.MapLoader;
import de.gurkenlabs.litiengine.environment.tilemap.MapProperty;
import de.gurkenlabs.litiengine.environment.tilemap.MapUtilities;
import de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint;
@@ -54,6 +53,7 @@
import de.gurkenlabs.litiengine.graphics.StaticShadowLayer;
import de.gurkenlabs.litiengine.graphics.StaticShadowType;
import de.gurkenlabs.litiengine.graphics.emitters.Emitter;
import de.gurkenlabs.litiengine.resources.Resources;
import de.gurkenlabs.litiengine.util.TimeUtilities;
import de.gurkenlabs.litiengine.util.geom.GeometricUtilities;
import de.gurkenlabs.litiengine.util.io.FileUtilities;
@@ -102,12 +102,7 @@ public Environment(final IMap map) {

public Environment(final String mapPath) {
this();
final IMap loadedMap = Game.getMap(FileUtilities.getFileName(mapPath));
if (loadedMap == null) {
this.map = MapLoader.load(mapPath);
} else {
this.map = loadedMap;
}
this.map = Resources.maps().get(FileUtilities.getFileName(mapPath));
Game.getPhysicsEngine().setBounds(new Rectangle(this.getMap().getSizeInPixels()));
}

Oops, something went wrong.

0 comments on commit e02f390

Please sign in to comment.