myjian / mai-tools

mai-tools is a collection of useful tools for maimai and maimai DX.
https://myjian.github.io/mai-tools
GNU General Public License v3.0
39 stars 11 forks source link

Refactor SongDatabase #98

Open Luxusio opened 4 months ago

Luxusio commented 4 months ago

There is a lot of duplicated codes. (like getting exact level, display level, etc..)
This different code can potentially cause strange bugs for any page. (wrong usage of calculating stuffs)
And there is a source code to calculate difficulty for song Link in multiple places. It can also cause bugs.

So I have a plan to put all things in one place using Hexagonal Architecture. Here's the step to refactor it.

  1. Move some external api calls into API class. it would be located in common/infra folder.
  2. Create SongDatabaseFactory and move insertOrUpdateSong, updateSong, deleteSong, validate method into it.
  3. Create 3 public methods to simply get difficulty data.
    • new class SongDetails
      • it has readonly property, property: SongProperty | undefined
      • it has getLevel method, which returns exact difficulty number and display value at once.
    • new methods
      • getByGenre(type: (DX|Standard), name: string, genre: Genre): SongDetails
      • getByThumbnail(type: (DX|Standard), name: string, thumbnail: string): SongDetails
      • getByIdx(type: (DX|Standard), name: string, idx: string): SongDetails
  4. refactor all source code to use that method.
  5. add test code about using that method

I will push it as separated PR, because this can be a large refactoring.