flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.14k stars 895 forks source link

Feature Request: Modify Prefix and View Cache Keys #3237

Open arthasyou opened 1 month ago

arthasyou commented 1 month ago

Problem to solve

The current implementation of the Images class lacks flexibility in two areas:

  1. Changing the prefix value after instantiation.
  2. Viewing all the keys present in the image cache.

Proposal

I propose the addition of two features to the Images class:

  1. Change Prefix Value:

    • Implement a method like setPrefix(String newPrefix) that updates the _prefix variable and ensures all cached paths are updated accordingly.
  2. View Cache Keys:

    • Implement a method like List<String> getCacheKeys() that returns a list of all keys currently stored in the _assets map.

These enhancements would greatly improve the flexibility and usability of the Images class.

More information

These features would align with the asset management practices seen in other frameworks and libraries, making it easier for developers to manage assets dynamically and ensure better cache management.

Other

spydon commented 1 month ago

Sound like good additions!

  1. I would use a setter here instead (and expose a getter)
  2. For this one I would just do List<String> get keys => _assets.keys;

You didn't check the box for working on a PR for this, so I guess we'll wait for someone else to pick this up (if you don't change your mind).

arthasyou commented 1 month ago

ill do it ty

spydon commented 1 month ago

I just had a look at images, and it already provides a setter for for the prefix, so it is only the getter for the keys that is needed.