cohstats / coh2stats

Statistics, usage charts and other useful information for a game Company of Heroes 2
https://coh2stats.com
32 stars 26 forks source link

Generate filenames for new icons - commanders [Python] #98

Closed petrvecera closed 3 years ago

petrvecera commented 3 years ago

In commander patch 2021, we got new commander icons. The problem is that Relic did not update the coh2 tools where data about icons for each commander are saved --> we can't use our scripts to get the right filenames.

And the new icons have new names - we can't just replace them.

Task:

Write a python script (or modify the current python script) which generates the commanderData.json to have icons from the .xml files located in https://github.com/petrvecera/coh2ladders/tree/master/scripts/data/cu2021/commander

Bonus:

If you would be able to get (filter) those specific images from all the icons (https://github.com/petrvecera/coh2ladders/blob/master/scripts/data/all-img.7z) and put them into packages/web/public/resources/exportedIcons it would be awesome.

some85 commented 3 years ago

I might be able to pick this one up. If I'm understanding this right, we're just looking to pull icon file names from XML files?

Is the current script located at https://github.com/petrvecera/coh2ladders/blob/master/scripts/exportImages.py? I can modify it, but I have some questions:

  1. Is this script run in the same directory it's located in the repository?
  2. Where are commanderData.json and bulletinData.json located? In that script, I see a line to open it, but I don't see commanderData.json in the repository.
petrvecera commented 3 years ago

@some85 this task is little bit more complicated. It requires access to the game files and game tools. However I can modify it in a way that you should be able to do it without it! Please let me know if you want to tackle this. Thanks

Task: Write a new script, called fixCommanderImages.py

The task is to change lines in commanderData.json based on the xml files in https://github.com/petrvecera/coh2ladders/tree/master/scripts/data/cu2021/commander

"iconSmall": "Icons_commander_portrait_us_forces_commander_01",
"iconlarge": "Icons_commander_portrait_us_forces_commander_01_large",

Some idea how to proceed with this task:

Load all the xml files in scripts/data/cu2021/commander into a memory and add them to an array.

Open file commanderData.json load it into memory. For each commander. Look at the serverID:

 "186413": {
        "serverID": "186413",
        "commanderName": "Airborne Company",
        "description": "Focus your strategy around Allied air superiority. Deploy elite infantry units from the air and support them with weapon drops from cargo planes. If the enemy deploys heavy armor, call in a P-47 Thunderbolt to strafe the target.",
        "races": [
            "usf"
        ],
        "iconSmall": "Icons_commander_portrait_us_forces_commander_01",
        "iconlarge": "Icons_commander_portrait_us_forces_commander_01_large",

Look into your array of xml files and look for the serverID You should be able to match it:

              <Value>
                <Key>server_id</Key>
                <Type>Integer</Type>
                <Data>186413</Data>
              </Value>

Now you found the corresponding XML file for the commander ^^

Look for the fields:

   <Value>
            <Key>icon_secondary</Key>
            <Type>String</Type>
            <Data>Icons_commander_portrait_aef_commander_01</Data>
          </Value>

and

          <Value>
            <Key>icon</Key>
            <Type>String</Type>
            <Data>Icons_commander_portrait_aef_commander_01_small</Data>
          </Value>

Replace those values in json from commanderData.json. Btw previously they had normal and _large icon name. Now it's changed. Now the large is without anything and _small is the small icon.

Save the new JSON file.

Is this script run in the same directory it's located in the repository?

The scripts should run from the folder scripts/

some85 commented 3 years ago

@petrvecera

D'oh. I have no idea how I missed commanderData.json. Thanks for linking it and answering my questions.

I can take on this task the way you just described it with a new fixCommanderImages.py script. I haven't messed with the game files before (and I do have access to them), but perhaps after writing this script I can begin exploring it.

petrvecera commented 3 years ago

@some85 that file commanderData.json was not there before. I added it .

Btw if you do have the game files. The script which generates the commanderData.json is called bulletinsAndCommanders.py for it to properly work you have to set correct paths at the begging to S:/SteamLibrary/steamapps/common/Company of Heroes 2 and S:/SteamLibrary/steamapps/common/Company of Heroes 2 Tools/ when you run it it would generate commanderData.json

So you could edit this script bulletinsAndCommanders.py or you can create a new one. I think the script is little bit messy to understand so it might be easier to just create a new script. It's up to you how you want to tackle this issue. 👍

some85 commented 3 years ago

@petrvecera PR was created with a new script. Big thumbs up for the very detailed task descriptions.

I guessed that bulletinsAndCommanders.py generated the data, but it confused me since the lines in that code assumed commanderData.json existed to begin with. Hope this solves the issue nicely.

petrvecera commented 3 years ago

Looks great! I am gonna test it soon. 👍 Thank you very much for the contribution.