Skip to content
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

Scryfall small images download #12282

Merged
merged 17 commits into from
Jun 1, 2024

Conversation

tiera3
Copy link
Contributor

@tiera3 tiera3 commented May 23, 2024

Sorry I messed up the last version of this pull request by accidentally pushing a commit that didn't belong to it - and when I tried to delete the commit, I deleted the branch instead. So I have recreated here.

This addresses #11577 .

Add the Scryfall Small Images option
Use pseudo inheritance from the Scryfall Image Source Object
No longer accessing properties of CardImageUrls directly, but using getDownloadList to retrieve them.
Also added commented out section to include if ScryfallRework gets merged.
@tiera3 tiera3 marked this pull request as draft May 27, 2024 01:42
@tiera3 tiera3 marked this pull request as ready for review May 27, 2024 02:06
@tiera3
Copy link
Contributor Author

tiera3 commented May 27, 2024

rebased because PR 12283 was merged

public enum ScryfallImageSourceSmall implements CardImageSource {
instance;

private CardImageSource baseSource = ScryfallImageSource.instance;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JayDi85 what do you think of this style? I think it could make more sense to have ScryfallImageSource.LARGE and ScryfallImageSource.SMALL rather than this wrapper class. But it's not a big deal and this way should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like what Susucre suggested in my original PR #12263 .

My reasons for not doing so were:
a) I wasn't sure how to, and
b) I didn't want to change ScryfallImageSource.java because of other open PRs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m surprised why it’s not class with overrided methods or constructor param. You can use it here cause already merged in other PR, but I will refactor and remove that “base source” anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it’s not in master yet.

Copy link
Member

@JayDi85 JayDi85 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make original enum as class and use constructor here. It’s ok to combine enum and class.

IMG_0426

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or getInstance to simulate enum logic:

IMG_0427

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:
ScryfallImageSource - class with static “instance” field and “getInstance” method
ScryfallImageSourceSmall extends ScryfallImageSource with overrided modify and size methods

@tiera3 tiera3 mentioned this pull request May 28, 2024
@tiera3 tiera3 requested a review from JayDi85 May 30, 2024 04:53
Copy link
Member

@JayDi85 JayDi85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, few improves can be done

@@ -32,6 +33,14 @@ public enum ScryfallImageSource implements CardImageSource {
private final Map<CardDownloadData, String> preparedUrls = new HashMap<>();
private final int DOWNLOAD_TIMEOUT_MS = 100;

private Object readResolve() throws ObjectStreamException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for PR -- I don't see any usages of readResolve(). Looks like some outdated code. So it can be removed from all "instance style" classes.

Copy link
Contributor

@xenohedron xenohedron May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a weird java thing - see https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html for details. I don't know for sure if it's actually needed, but take care before removing.

edit: some discussion here https://stackoverflow.com/questions/1168348/java-serialization-readobject-vs-readresolve
the purpose is to enforce singleton pattern even when serialized

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this class doesn't extend Serializable so must not be needed here.

Copy link
Member

@JayDi85 JayDi85 May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. It required to support serialization of singleton classes (without that method each singleton object/instance will be duplicated with new object). Xmage don't use serialization of server side objects, so it's safe from such errors (miss hidden fields/methods). But it can be important for potentially game replay or restore feature (old implementation used serialization to save and load game states from a file).

So it's better to keep such method in all enum style classes (singleton).

@xenohedron
Copy link
Contributor

Beware of copying example code - you have to check that it works as intended. In this case a few other adjustments were needed (and I went ahead and simplified some other things while I was looking at it).

@xenohedron xenohedron merged commit f253777 into magefree:master Jun 1, 2024
2 checks passed
@tiera3 tiera3 deleted the ScryfallSmallImagesDownload branch June 8, 2024 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants