This repository was archived by the owner on Apr 1, 2023. It is now read-only.
More appropiate data structures & less code repetition#88
Merged
marioortizmanero merged 7 commits intomasterfrom Apr 7, 2020
Merged
More appropiate data structures & less code repetition#88marioortizmanero merged 7 commits intomasterfrom
marioortizmanero merged 7 commits intomasterfrom
Conversation
Member
Author
|
Hey @AndrewAmmerlaan can you give this branch a quick try before I merge it into master, if you have time? I've made sure it works well, but it has so many internal changes anything could go wrong :P |
Contributor
Seems to be working just fine 👍 Test suite seems fine as well: |
Member
Author
|
Great, thanks! I'm merging it :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related to #83, this merges
APIDataandPlayerDatainto a base class to avoid code duplication.This means that instead of using enums with custom
__new__methods internally, a list ofPlayerData/APIDataimmutable dataclasses is used. This reduces boilerplate a lot and allows to mergeload_api_dataandload_player_datafromSetupWidgetinto a single method.I first thought of using a dict to store the data associated to the ID:
but in the end it was easier to be able to use
PlayerData.idto access the ID rather than having to searchPlayerDatato obtain the dict key:As this method doesn't guarantee that the IDs are equal, I've made a test to make sure of that. I'm still not really sure if this is the best way to do it, though. This is how Enum works underneath anyway, so the behavior remains the same.
I've also done something similar with the config options. Using dataclasses and inheritance rather than a custom enum makes using it more idiomatic and straightforward.
I removed
BaseMethodData.platforms: Tuple[Platform]in place ofBaseMethodData.compatible: bool. This is already done withBaseMethodData.installed, because it's not necessary to store the dependent modules per se, only whether it's installed or not. It also doesn't change as the program runs, so it doesn't make sense to checkCURRENT_PLATFORM in PlayerData.platformswhenever I want to know if it's available. Furthermore, if the API/Player wasn't available on the system for any other reason than the OS, it would be impossible to check it currently.As a small plus, the Config arguments now have a text with the default value in its description.