Trouv / willos-graveyard

Sokoban puzzle game made for GMTK 2021 game jam - Joined Together
3 stars 0 forks source link

refactor: agnosticize SokobanPlugin, and other improvements #89

Closed Trouv closed 1 year ago

Trouv commented 1 year ago

Summary

This makes SokobanPlugin "agnostic", meaning that it's no longer dependent on willos-graveyard, and could be extracted into its own crate. I think agnosticized plugins are partially good as they give us the opportunity to contribute the plugin to the wider bevy community, and partially good because they encourage good coding practices. The fact that the most central, core logic of the game can be completely decoupled from the rest of the game is a good sign that our organization and ECS practices aren't "tangled up" in any way.

Implementation

Agnosticization

Assumes that the user is spawning levels with bevy_ecs_ldtk.

  1. Replace WilloMovementEvent with SokobanCommands. This allows users to command the plugin to move blocks, handling collisions, pushes, etc.
  2. Add PushTracker marker component and PushEvent. Users can addPushTrackerto an entity so that, whenever that entity pushes another block, aPushEventis fired. Being pushed into pushing another entity will also causePushEvent`s.
  3. Move Willo's push animation logic to willo module.
  4. Remove scheduling restrictions that were only necessary for animation.
  5. Move WallBundle LDtk registrations to new wall module.
  6. Rewrite filters depending on willo-specific code to be sokoban-specific instead.
  7. Move push translation logic to willo module.
  8. Make plugin generic over its iyes_loopless state.
  9. Add SokobanLayerIdentifier resource for defining which LDtk layer should be used for determining level bounds, tile size, etc.

Other improvements

  1. Rename RigidBody to SokobanBlock, give it a nice API for bevy_ecs_ldtk users.
  2. Create CollisionMap type alias.
  3. Simplify (and rename) recursive push_collision_map_entry function.
  4. Update CollisionMap immutably in push_collision_map_entry function.
  5. Simplify (and rename) flush_sokoban_commands system.
  6. Improve error handling with appropriate warnings/expects.
  7. Flesh out documentation.
  8. Add iyes_loopless run criteria to system scheduling, which should improve performance
  9. Add unit tests for push_collision_map_entry function.
  10. Add unit tests for the entire plugin.
  11. Probably some other stuff, but I can't remember it all...

Adding those tests is important, not just because these are the first tests in the entire game, but the chances that a PR introduced some game-breaking bugs are at an all-time high with this one.