-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert legacy color categories to new values throughout the code #2502
Convert legacy color categories to new values throughout the code #2502
Conversation
in cubes which had those values explicitly saved.
| 'Hybrid' | ||
| 'Lands'; | ||
|
||
export const COLOR_CATEGORIES = ['White', 'Blue', 'Black', 'Red', 'Green', 'Colorless', 'Multicolored', 'Hybrid', 'Lands'] as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using typescript const assertions so that we can use COLOR_CATEGORIES to check if a string is within its set of values. Could not see how to do that using the ColorCategory type itself.
@@ -228,6 +229,9 @@ function CSVtoCards(csvString, carddb) { | |||
} of camelizedRows) { | |||
if (name) { | |||
const upperSet = (set || '').toUpperCase(); | |||
|
|||
const validatedColorCategory = convertFromLegacyCardColorCategory(colorCategory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies when importing the CSV
@@ -195,14 +196,17 @@ function writeCard(res, card, maybe) { | |||
} else { | |||
imgBackUrl = ''; | |||
} | |||
|
|||
const colorCategory = cardutil.convertFromLegacyCardColorCategory(card.colorCategory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applies when writing the CSV
@@ -203,7 +236,7 @@ export const cardColorCategory = (card: Card): ColorCategory => { | |||
return 'Colorless'; | |||
} | |||
if (colors.length > 1) { | |||
return 'Multicolor'; | |||
return 'Multicolored'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found when exploring why some cards didn't show the right value in the Color Category dropdown, looked to be a recent typo. More places used Multicolored including on the Color category type
Ad concern 3, I'm pretty sure the idea is that "details" contains immutable information (from the user's perspective) directly loaded from the carddb JSONs, so it contains the default color category that is assigned to cards with this cardID. If a user overrides that default in their cube, it changes the color category directly on the Card object, which takes precedence over the default in "details". Since it looks like every Card has its colorCategory set explicitly to the default when created, you're right that it could be omitted from the details, but since those are just a copy-pasted object, there's not much of a point in explicitly deleting a single value. Ad concern 1, I'd say that depends on if the value is used anywhere (other than as a default for Card objects). If not, I think you can just change them and get rid of an inconsistency. If yes, then it depends on how much work changing all the usages is. One place I'd check for sure is card search. Ad concern 2, I think getPlaceholderCard should reflect whatever the format of actual cards in the carddb ends up being. Ad concern 4, who says you have to determine it based on color identity? The function gets the entire A word of caution here, though. The current behavior (buggy or not) means Hybrid is a category that has to be set explicitly, and it is never assigned to cards by default. So if you change that, you are possibly creating a situation where existing hybrid cards are sorted under Multicolored, but newly added hybrid cards appear under Hybrid, which feels like undesirable behavior with wide-reaching impact. Color Category is the default primary sort for all cubes, so any changes to its behavior should ve really carefully considered. |
has to be set by the cube owners.
Fixes #2505
Problem
Solution
Concerns
Testing
Existing behaviour
Used Cube's https://cubecobra.com/cube/list/jank and https://cubecobra.com/cube/list/trash-pile-test from the reported issues in Discord.
(r and m respectively)
2. Imported those into my local cube cobra using the current master branch. Many cards were categorized as "Other" using the color category sort (the default) per screenshots. For each first screenshot shows imported, then second shows after Display -> Show unsorted is on
Cube 1
Cube 2
Validated the legacy color categories in the cube JSON
Sorting by color identity works
New behaviour
The color category sorting works for the cubes imported from the previous section (no edits or anything to the cards)
Importing the cubes from CSV correctly has color category set
New color categories are saved in the cube JSON (on the card itself)
CSV export uses the current color categories (r -> Red in comparison)