pkmn / ps

Modular Pokémon Showdown
MIT License
110 stars 16 forks source link

Pack/Unpack does not follow showdown formatting when including team name, format and folder. #20

Closed JeremieLeblanc closed 1 year ago

JeremieLeblanc commented 1 year ago

Describe the bug:

When packing, unpacking, or exporting a Team, the name, format and folder are all ignored...

Example:

An example of this is trying to import a saved team from the Showdown's localStorage.

The packed team (from LocalStorage) looks like this:

gen9vgc2023series2]Team Name|Nickname|amoonguss||effectspore|||||||50|

The imported Team looks like this:

{
  "data": undefined,
  "folder": undefined,
  "format": undefined,
  "name": undefined,
  "team": [
    {
      "name": "gen9vgc2023series2]Team Name",
      "species": "Nickname",
      "item": "amoonguss",
      "ability": "",
      "moves": [
        "effectspore"
      ],
      "nature": "",
      "evs": {
        "hp": 0,
        "atk": 0,
        "def": 0,
        "spa": 0,
        "spd": 0,
        "spe": 0
      },
      "ivs": {
        "hp": 31,
        "atk": 31,
        "def": 31,
        "spa": 31,
        "spd": 31,
        "spe": 31
      },
      "happiness": null,
      "hpType": "",
      "pokeball": "",
      "gigantamax": false,
      "dynamaxLevel": 10,
      "teraType": ""
    }
  ]
}

Expected behavior:

I would expect the imported Team to look like this instead

{
  "data": undefined,
  "folder": undefined,
  "format": "gen9vgc2023series2",
  "name": "Team Name",
  "team": [
    {
      "name": "Nickname",
      "species": "amoonguss",
      "item": "",
      "ability": "effectspore",
      "moves": [ ],
      "nature": "",
      "evs": {
        "hp": 0,
        "atk": 0,
        "def": 0,
        "spa": 0,
        "spd": 0,
        "spe": 0
      },
      "ivs": {
        "hp": 31,
        "atk": 31,
        "def": 31,
        "spa": 31,
        "spd": 31,
        "spe": 31
      }
    }
  ]
}

I would also expect the export to include those details as well.

The import method seems to work correctly when using === [format] team name === but the export does not add those details.

=== [gen9vgc2023series2] Team Name ===

Nickname (Amoonguss)  
Ability: Effect Spore  
Level: 50  
Tera Type: Grass  
scheibo commented 1 year ago

Showdown's teambuilder team restore format is not a documented team format. However, I think the intended logic for @pkmn/sets's fromString logic had meant to still support this, it was just wired up incorrectly. v5.0.4 includes the fix for this, but you must use Teams.fromString not unpack (which is intended to be very liberal in what it will accept, be it JSON/the proper import format/whatever the teambuilder happens to accept).

Thanks for the bug report :)