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

Implement the "Environment manager" #202

Merged
merged 11 commits into from Dec 19, 2018

Conversation

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

steffen-wilke commented Dec 19, 2018

This pull request solves the feature request #196.
API changes:

  • Game.getEnvironment() -> Game.world().environment()
  • Game.getCamera() -> Game.world().camera()
  • Game.addEnvironmentLoadedListener(EnvironmentLoadedListener) -> Game.world().addLoadedListener(EnvironmentLoadedListener)
  • Game.loadEnvironment(IEnvironment) -> Game.world().loadEnvironment(IEnvironment)

API additions:

  • Game.world().addLoadedListener(String mapName, EnvironmentLoadedListener listener)
  • Game.world().addUnloadedListener(String mapName, EnvironmentUnloadedListener listener)
  • Game.world().addListener(String mapName, EnvironmentListener listener)
  • and the remove listener equivalents
  • Game.world().attach(String mapName, IUpdateable updateable)
  • Game.world().detach(String mapName, IUpdateable updateable)
  • Game.world().getEnvironments()
  • Game.world().getEnvironment(String mapName)
  • Game.world().getEnvironment(IMap map)
  • Game.world().loadEnvironment(String mapName)
  • Game.world().loadEnvironment(IMap map)

It's now possible to attach game logic to different states of an Environment life cycle. This logic will be executed on a per-map basis:

  • Game.world().addLoadedListener("test-map", e -> { /* do stuff */ });
  • Game.world().addUnloadedListener("test-map", e -> { /* do stuff */ });
  • Game.world().attach("test-map", () -> { /* do stuff */ });

Using the attach method allows to execute logic in the game's main loop if the map is currently active.

Also, it is now possible to access resources via an alias which can e.g. be used for maps since they have to have a globally unique name. A map that was originally loaded via:
Resources.maps().get("tests/de/gurkenlabs/litiengine/environment/tilemap/xml/test-map.tmx")
can be also accessed like:
Resources.maps().get("test-map")

steffen-wilke added some commits Dec 17, 2018

Move the environment and camera API to the GameWorld class.
This can now be accessed via
 - Game.world().camera()
 - Game.world().environment()

Issue #196
Enhanced the GameWorld implementation
Add a lot of API sugar that e.g. allows to load/get environments by a map/name or register listeners for a particular mapname.
Improve environment event handling.
Simplify the naming of the listener callback methods.
Add basic unit tests for listeners.
Issue #196
Clear the GameWorld when terminating the Game.
Call map specific event listeners.
Add test cases for new events.
Add a reference from entity to the environment
Also ensure that the entity is only present on one environment at a time.
Issue #196
Implement the possibility to register updatables that are only called…
… when the specified environment (identified by mapname) is currently active.
Make it possible to retrieve resources via an alias.
This allows to directly access a map by its name instead of having to identify it via it's full resource path.
Right now this is only implemented for maps because we require map names to be unique for a LITIengine game anyway.

Remove the identifier from the IEnvironment. It was previously added for this branch but has now been replaced by a mapName based logic.
Add documentation to the Game.world() method.
@TheRamenChef

This comment has been minimized.

Copy link
Collaborator

TheRamenChef commented Dec 19, 2018

Also, it is now possible to access resources via an alias which can e.g. be used for maps since they have to have a globally unique name. A map that was originally loaded via:
Resources.maps().get("tests/de/gurkenlabs/litiengine/environment/tilemap/xml/test-map.tmx")
can be also accessed like:
Resources.maps().get("test-map")

Can the "get map by name" bit use a separate method?

@steffen-wilke steffen-wilke merged commit 419c41f into master Dec 19, 2018

2 of 3 checks passed

codeclimate 22 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 environment-manager branch Dec 19, 2018

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