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

Update draftable edition sections #6631

Open
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

Ayora29
Copy link
Contributor

@Ayora29 Ayora29 commented Nov 25, 2024

  • FileSection.java : Use a LinkedHashMap to parse edition section, preserving section order and improve performance.
  • CardEdition.java : Increment art index when multiple cards with the same name are in the same sheet. Add new section names, remove irrelevant ones.
  • Edition txt files of draftable sets : update "sections" and "Booster=" parts to better reflect reallity (cf scryfall and mtg.fandom.com) and reduce amount of unecessary additionnal sections/sheets.
  • printsheets.txt : remove unecessary or dead sections
  • No card addition, no card remove, no cards in different order compared to before (exept some basic lands)
  • I have tested drafts for all editions that I have modified

@Agetian
Copy link
Contributor

Agetian commented Nov 26, 2024

Is this branch now ready? Can someone please test and confirm/approve? Leaving it open for a long time may result in a similar effect as before (the need to merge + some difficult to track issues)

@paulsnoops
Copy link
Contributor

I didn't think those changes to MH3 edition were causing the crash so I've just tested again and it's still crashing for me:

main > java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
at java.base/java.util.Objects.checkIndex(Objects.java:365)
at java.base/java.util.ArrayList.get(ArrayList.java:428)
at forge.util.FileSection.parseSections(FileSection.java:109)
at forge.game.GameFormat$Reader.read(GameFormat.java:375)
at forge.game.GameFormat$Reader.read(GameFormat.java:345)
at forge.util.storage.StorageReaderRecursiveFolderWithUserFolder.readAll(StorageReaderRecursiveFolderWithUserFolder.java:105)
at forge.util.storage.StorageBase.(StorageBase.java:44)
at forge.game.GameFormat$Collection.(GameFormat.java:465)
at forge.model.FModel.initialize(FModel.java:208)
at forge.Singletons.initializeOnce(Singletons.java:56)
at forge.view.Main.main(Main.java:64)

@Agetian
Copy link
Contributor

Agetian commented Nov 26, 2024

Hmm, probably worth checking out in the debugger which file it's unhappy about in particular... I'm only going to be able to do this on the weekend, so hopefully someone is faster, hehe :)

@Ayora29
Copy link
Contributor Author

Ayora29 commented Nov 26, 2024

@paulsnoops @Agetian Ok, you should have a blank file that I don't have and it is causing the Index out of bounds Execption.
May be a custom set file or something like that?
I have added a check for empty text in the parseSections method.
The error should be gone now hopefully.

if(!result.containsKey(section)) {
result.put(section, new ArrayList<>());
if(null != lines && !lines.isEmpty()){
do{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a do/while instead of a for loop?

for(int lineNumber = 0; lineNumber < lines.size(); lineNumber++) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is code optimization. it allows to do the same thing with less line of code and less if statetemens inside the loop.

Copy link
Contributor

@tehdiplomat tehdiplomat Nov 27, 2024

Choose a reason for hiding this comment

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

I worry that you embed the increment here. lineNumber++ which might confuse people of what is actually going on, and if someone decides to add code that interacts with lineNumber after this increment, it won't be the same value as what gets used on the line itself. Your structure is definitely better than before, but i think getting rid of the forloop actually adds unintended complexity for the next developer.

    if(null == lines) {
        return result;
    }
    for(int lineNumber = 0; lineNumber<lines.size(); lineNumber++) {
                String line = lines.get(lineNumber);
                if (line.startsWith("[") && line.endsWith("]")) {
                    section = line.substring(1, line.length() - 1);
                    if(!result.containsKey(section)) {
                        result.put(section, new ArrayList<>());
                    }
                }
                else if(null != section && !line.isEmpty() && !line.startsWith("#")){
                    result.get(section).add(line);
                }
            }

In fact, we don't even care about the line number, so we could just do...

if (lines == null) {
   return result;
}

for(String line : lines) {
   if (line.startsWith("#") continue;

   if (line.startsWith("[") && line.endsWith("]")) {
          section = line.substring(1, line.length() - 1);
          if(!result.containsKey(section)) {
                 result.put(section, new ArrayList<>());
          }
    } else if(null != section && !line.isEmpty()){
        result.get(section).add(line);
    }
}

Copy link
Contributor

@tehdiplomat tehdiplomat Nov 27, 2024

Choose a reason for hiding this comment

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

This also seems like we're potentially adding lines to sections that can be just spaces now? since we aren't trimming or string comparison equivilants of that. I didn't even notice what the old function looked like since you had moved the function up the file, and the diff wasn't side by side.

@paulsnoops
Copy link
Contributor

@paulsnoops @Agetian Ok, you should have a blank file that I don't have and it is causing the Index out of bounds Execption. May be a custom set file or something like that? I have added a check for empty text in the parseSections method. The error should be gone now hopefully.

It loads fine now, thanks for supporting custom editions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants