New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp resources api #191

Merged
merged 17 commits into from Nov 25, 2018

Conversation

Projects
None yet
3 participants
@steffen-wilke
Copy link
Collaborator

steffen-wilke commented Nov 25, 2018

This Pull Request contains breaking changes to the API and you most likely have to adjust the implementation of your game after updating to a new version

As a result of a recent forum discussion, I discovered some major inconsistencies when it comes to accessing resources in the LITIengine. With the changes of this PR, these have been addressed and the API has been unified such that all Resources are now accessed via the static Resources class.

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")

Also the infamous ImageCache has now been replaced:

ImageCache.IMAGES.get("my-image.png") -> Resources.images().get("my-image.png")
ImageCache.MAPS.get("my-image.png") -> Resources.images().get("my-image.png")
ImageCache.SPRITES.get("my-image.png") -> Resources.images().get("my-image.png")

See commit messages for further detail.

steffen-wilke and others added some commits Nov 23, 2018

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")
Basic improvements
The put method already removes an existing mapping
Use containsValue instead of values().contains
Use more atomic methods
Make the load method abstract
Add Javadoc to the ResourcesContainer class.
Add methods to actually add and remove ResourceContainerListener instances.
Moved MapLoader implementation to the Maps ResourcesContainer.
Adjusted visibility of ResourcesContainer constructors. No need for them to be protected since they're final anyway.
Remove ImageCache.MAPS.
It's basically an equivalent to the new Resources.images() API.
The only difference is that the new API doesn't distinguish between map-images, sprite-images and images in general.
This is because technically it's not really necessary and it does add more confusion than usefulness to the engine overall.
Remove the ImageCache.SPRITES.
Add a new ResourcesContainerClearedListener which provides a more convenient API for consumers that are only interested in cleared events.
Remove the ImageCache.
Example for new API:
ImageCache.IMAGES.get("my-image.png") -> Resources.images().get("my-image.png")
ImageCache.MAPS.get("my-image.png") -> Resources.images().get("my-image.png")
ImageCache.SPRITES.get("my-image.png") -> Resources.images().get("my-image.png")

Extended the ResourcesContainer implementation with the possibility of on-demand resource loading in case the container doesn't provides a resources with the requested name yet.

@steffen-wilke steffen-wilke requested a review from nightm4re94 Nov 25, 2018

steffen-wilke added some commits Nov 25, 2018

@nightm4re94
Copy link
Collaborator

nightm4re94 left a comment

Finally!
Looks good.

@steffen-wilke steffen-wilke merged commit 8b1ba91 into master Nov 25, 2018

2 of 3 checks passed

codeclimate 12 issues to fix
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@steffen-wilke steffen-wilke deleted the revamp-resources-api branch Nov 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment