Sprayxe / valorant.js

An API Wrapper for valorant with oauth support
MIT License
18 stars 6 forks source link

Updated ItemParser to parse the new playerloadout data schema #17

Closed sudhxnva closed 3 years ago

sudhxnva commented 3 years ago

ItemParser Update to Handle New Format

Riot is sending data to the endpoint /personalization/v2/players/{accountID}/playerloadout in a revised format, which broke the old ItemParser implementation. Refer Issue #16 .

Here is the new format of data:

{
  "Subject": "16848a0d-ec55-5e7b-9ad8-6d51c6f2d54e",
  "Version": 344,
  "Guns": [
    {
      "ID": "1-4035-2937-7c09-27aa2a5c27a7",
      "SkinID": "d405272b-4388-578c-e33b-04842496b8c1",
      "SkinLevelID": "4d02d9fa-4cb4-4d87-bdf0-97bd5f960c12",
      "ChromaID": "0bf12530-4abb-8851-0420-199af20c2a2a",
      "CharmInstanceID": "f903bda0-fa8d-4b49-8ae6-ea7ede118eb5",
      "CharmID": "7cf1fc2c-4456-fa8f-b9f6-c9be7092163f",
      "CharmLevelID": "cf194771-4eb6-053e-6c0c-5a80dab14f39",
      "Attachments": []
    },
    { "deleted": "other guns for the sake of this example"},
  ],
  "Sprays": [
    {
      "EquipSlotID": "04af080a-4071-487b-61c0-5b9c0cfaac74",
      "SprayID": "0eb56d06-474d-fbec-372f-069286388bc5",
      "SprayLevelID": null
    },
    {
      "EquipSlotID": "5863985e-43ac-b05d-cb2d-139e72970014",
      "SprayID": "bc8917ee-4e11-0286-ff49-77b1e5b12fcb",
      "SprayLevelID": null
    },
    {
      "EquipSlotID": "0814b2fe-4512-60a4-5288-1fbdcec6ca48",
      "SprayID": "677dc003-4dbf-66a8-9116-4f8d7a9fb8d5",
      "SprayLevelID": null
    }
  ],
  "Identity": {
    "PlayerCardID": "5b27d2de-4a97-d6c1-76e7-669189c67072",
    "PlayerTitleID": "f3bf3c15-4e3b-6e58-64a3-8f9995f39370",
    "AccountLevel": 0
  },
  "Incognito": false
}

A new Identity property is now present. And it looks like it's returning the new "Account Level" feature Riot is releasing soon (source)

It is only a minor change, so I made a small refactor in the ItemParser code. It will return the Identity object, which contains the PlayerCardID and PlayerTitleID. (Since this is a refactor, this might break valorant.js dependants - well tbh it's already broken right now).

Also (off topic), looks like Riot is implementing an "Incognito" feature for Valorant? Inferring this from the last Incognito property. I don't know if this existed before.

sudhxnva commented 3 years ago

Wrote code to parse the sprays and add them to the PlayerInventory return object

Here's the example output now when valorant.playerApi..getInventory() is called:

{
  "Subject": "16848a0d-ec55-5e7b-9ad8-6d51c6f2d54e",
  "Version": 344,
  "GunSkins": {
    "Odin": "f454efd1-49cb-372f-7096-d394df615308",
    "Ares": "556646c0-46dd-6986-00df-a78d1c17f268",
    "Vandal": "b9ee2457-481c-6776-3f5b-0ca8e8f90c89",
    "Bulldog": "dbf7b813-4931-3b45-db2b-ea8d418b2b1d",
    "Phantom": "25a7f0f2-4bce-7e45-b4b0-ca9264f5dfcc",
    "Judge": "5d217dd0-4f2c-cfca-274e-3f8f9d518b13",
    "Bucky": "1322a9a8-49ad-bc3a-2319-fb866e21334c",
    "Frenzy": "7d05d1ce-4bf2-fa96-d8f4-dca86052e3d2",
    "Classic": "d653f4a7-4e92-2559-0a97-2c9d46d009b3",
    "Ghost": "0a6edcf0-4a64-0ed5-1b10-0e96c2eb4cb4",
    "Sheriff": "121bc438-4748-b2ee-2c58-768c8c26838b",
    "Shorty": "3a921c7b-4e8f-8543-bee8-01ba6da86874",
    "Operator": "aecab890-43b7-d719-06bc-9295e3d116dc",
    "Guardian": "96679876-4d41-683c-2e5c-2ea25ddd8fdf",
    "Marshal": "fd44b2d5-49ee-77ab-fa56-588f3ac0c268",
    "Spectre": "d405272b-4388-578c-e33b-04842496b8c1",
    "Stinger": "0cf70376-4150-39aa-5657-8890617bc0d1",
    "Melee": "24cf2882-48c7-f287-155a-a4b6b083baa4"
  },
  "Sprays": {
    "PreRound": "677dc003-4dbf-66a8-9116-4f8d7a9fb8d5",
    "MidRound": "0eb56d06-474d-fbec-372f-069286388bc5",
    "PostRound": "bc8917ee-4e11-0286-ff49-77b1e5b12fcb"
  },
  "Identity": {
    "PlayerCardID": "5b27d2de-4a97-d6c1-76e7-669189c67072",
    "PlayerTitleID": "f3bf3c15-4e3b-6e58-64a3-8f9995f39370",
    "AccountLevel": 0
  }
}
Sprayxe commented 3 years ago

Sorry for reading it this late, I will be updating the library tomorrow. Thank you for pointing out this issue!

sudhxnva commented 3 years ago

Thanks!

Sprayxe commented 3 years ago

Updated library