PlayCover / PlayTools

Tools for keymapping, dynamic resolution, and more
GNU Affero General Public License v3.0
71 stars 56 forks source link

Keymap editor code refactor #147

Closed XuYicong closed 5 months ago

XuYicong commented 5 months ago

In prepare for adding editor related features, like swipe mapping and dynamic/static(free/fixed) joystick mode switcher.

Should not alter the behavior of the original code. If anything appears different it must be a bug.

Why this is necessary

Keymap editor code was the Voider version and hard to understand and modify.

Main changes

  1. Folder Keymap and Menu reorganized to Editor and Keymap.
  2. Class ControlData is removed, instead directly operate on underlying data structure.
  3. Original Menu folder moved to new Editor/Views/CircleMenu.
  4. Original ControlModel.swift split into multiple files under Elements folders under Editor/Models, Editor/Views and Editor/Controllers folders.
  5. Most code are under Editor folder. New Keymap folder has only two files Keymapping.swift for file read/write and KeyCodeNames.swift for key code/name definition.
  6. The data structure definition that's meant to keep synced with its PlayCover version is now moved from Keymapping.swift to Editor/Models/Elements/Element.swift.
  7. Original EditorController.swift split into Editor/Views/EditorView.swift and Editor/Controllers/EditorController.swift.
  8. Class JoystickButtonModel renamed to ChildButtonModel because it's used by both JoystickModel and DraggableButtonModel.

What's better

  1. There are more files and every file now has less code.
  2. UI-related code follows MVC pattern and is easy to modify.
  3. Correctly uses OOP.
  4. File and class names are more meaningful.