@@ -10,88 +10,105 @@ class SkinsTab
1010public:
1111 static void Render ()
1212 {
13- static bool skinsOpen = true ;
13+ // todo add sorting
14+
15+ static bool bOnOpen = true ;
1416 if (ImGui::BeginTabItem (" Skins" ))
1517 {
16- static std::string result;
17- static Json::Value root;
18-
19- // todo improve performance
20- // and combobox to sort by name, date etc
21-
22- if (skinsOpen)
18+ if (bOnOpen)
2319 {
24- skinsOpen = false ;
25- result = http-> Request ( " GET " , " https://127.0.0.1/lol-inventory/v2/inventory/CHAMPION_SKIN " , " " , auth-> leagueHeader , " " , " " , auth-> leaguePort );
20+ bOnOpen = false ;
21+ ownedSkins. clear ( );
2622
27- Json::CharReaderBuilder builder;
28- const std::unique_ptr<Json::CharReader> reader (builder.newCharReader ());
29- JSONCPP_STRING err;
23+ static Json::Value root;
24+ static Json::CharReaderBuilder builder;
25+ static const std::unique_ptr<Json::CharReader> reader (builder.newCharReader ());
26+ static JSONCPP_STRING err;
3027
31- if (!reader->parse (result.c_str (), result.c_str () + static_cast <int >(result.length ()), &root, &err))
32- result = " Failed to parse JSON" ;
33- }
34-
35- if (root.isArray ())
36- {
37- ImGui::Text (" Skins owned: %d" , root.size ());
28+ std::string getSkins = http->Request (" GET" , " https://127.0.0.1/lol-inventory/v2/inventory/CHAMPION_SKIN" , " " , auth->leagueHeader , " " , " " , auth->leaguePort );
3829
39- for (Json::Value::ArrayIndex i = 0 ; i < root. size (); ++i )
30+ if (reader-> parse (getSkins. c_str (), getSkins. c_str () + static_cast < int >(getSkins. length ()), &root, &err) )
4031 {
41- ImGui::Separator ();
42- std::string itemId = root[i][" itemId" ].asString ();
43- if (!champSkins.empty ())
32+ if (root.isArray ())
4433 {
45- bool found = false ;
46- for (auto champ : champSkins)
34+ for (Json::Value::ArrayIndex i = 0 ; i < root.size (); ++i)
4735 {
48- if (itemId.substr (0 , std::to_string (champ.key ).size ()) == std::to_string (champ.key ))
36+ Skin skin;
37+
38+ skin.inventoryType = root[i][" inventoryType" ].asString ().c_str ();;
39+ skin.itemId = root[i][" itemId" ].asInt ();
40+ skin.ownershipType = root[i][" ownershipType" ].asString ().c_str ();
41+ skin.isVintage = root[i][" payload" ][" isVintage" ].asBool ();
42+ skin.purchaseDate = root[i][" purchaseDate" ].asString ().c_str ();
43+ skin.qunatity = root[i][" quantity" ].asInt ();
44+ skin.uuid = root[i][" uuid" ].asString ().c_str ();
45+
46+ if (!champSkins.empty ())
4947 {
50- for (auto skin : champ.skins )
48+ bool found = false ;
49+ for (auto champ : champSkins)
5150 {
52- if (itemId == skin. first )
51+ for ( auto s : champ. skins )
5352 {
54- ImGui::Text (" Name: %s" , skin.second .c_str ());
55- found = true ;
56- break ;
53+ if (skin.itemId == std::stoi (s.first ))
54+ {
55+ skin.name = s.second .c_str ();
56+ found = true ;
57+ break ;
58+ }
5759 }
60+ if (found)
61+ break ;
5862 }
59- if (found)
60- break ;
6163 }
64+ ownedSkins.emplace_back (skin);
6265 }
6366 }
67+ }
68+ }
6469
65- ImGui::Text (" inventoryType: %s" , root[i][" inventoryType" ].asString ().c_str ());
66- ImGui::Text (" itemId: %s" , itemId.c_str ());
67- ImGui::Text (" ownershipType: %s" , root[i][" ownershipType" ].asString ().c_str ());
68- auto payloadObj = root[i][" payload" ];
69- ImGui::Text (" isVintage: %d" , payloadObj[" isVintage" ].asInt ());
70- std::string purchaseDateFormatted = root[i][" purchaseDate" ].asString ();
71- size_t fintTPos = purchaseDateFormatted.find (" T" );
72- size_t finddDotPos = purchaseDateFormatted.find (" ." );
73- size_t findMinusPos = purchaseDateFormatted.find (" -" );
74- if (findMinusPos == std::string::npos)
75- {
76- purchaseDateFormatted = purchaseDateFormatted.substr (0 , finddDotPos);
77- purchaseDateFormatted.insert (4 , " -" );
78- purchaseDateFormatted.insert (7 , " -" );
79- purchaseDateFormatted.replace (fintTPos + 2 , 1 , " " );
80- purchaseDateFormatted.insert (fintTPos + 2 + 3 , " :" );
81- purchaseDateFormatted.insert (fintTPos + 2 + 3 + 3 , " :" );
82- }
83- else
84- {
85- purchaseDateFormatted = purchaseDateFormatted.substr (0 , finddDotPos);
86- purchaseDateFormatted.replace (fintTPos, 1 , " " );
87- }
88- ImGui::Text (" purchaseDate: %s" , purchaseDateFormatted.c_str ());
89- ImGui::Text (" quantity: %d" , root[i][" quantity" ].asInt ());
90- ImGui::Text (" uuid: %s" , root[i][" uuid" ].asString ().c_str ());
70+ ImGui::Text (" Skins owned: %d" , ownedSkins.size ());
71+
72+ for (Skin skin : ownedSkins)
73+ {
74+ ImGui::Separator ();
75+ if (!skin.name .empty ())
76+ ImGui::Text (" name: %s" , skin.name .c_str ());
77+ // else if (!champSkins.empty())
78+ // ImGui::Text("name: Chroma"); // todo find a way to get chroma's name
79+ ImGui::Text (" inventoryType: %s" , skin.inventoryType .c_str ());
80+ ImGui::Text (" itemId: %d" , skin.itemId );
81+ ImGui::Text (" ownershipType: %s" , skin.ownershipType .c_str ());
82+ ImGui::Text (" isVintage: %d" , skin.isVintage );
83+ ImGui::Text (" purchaseDate: %s" , skin.purchaseDate .c_str ());
84+
85+ /* std::string purchaseDateFormatted = root[i]["purchaseDate"].asString();
86+ size_t fintTPos = purchaseDateFormatted.find("T");
87+ size_t finddDotPos = purchaseDateFormatted.find(".");
88+ size_t findMinusPos = purchaseDateFormatted.find("-");
89+ if (findMinusPos == std::string::npos)
90+ {
91+ purchaseDateFormatted = purchaseDateFormatted.substr(0, finddDotPos);
92+ purchaseDateFormatted.insert(4, "-");
93+ purchaseDateFormatted.insert(7, "-");
94+ purchaseDateFormatted.replace(fintTPos + 2, 1, " ");
95+ purchaseDateFormatted.insert(fintTPos + 2 + 3, ":");
96+ purchaseDateFormatted.insert(fintTPos + 2 + 3 + 3, ":");
97+ }
98+ else
99+ {
100+ purchaseDateFormatted = purchaseDateFormatted.substr(0, finddDotPos);
101+ purchaseDateFormatted.replace(fintTPos, 1, " ");
91102 }
103+ ImGui::Text("purchaseDate: %s", purchaseDateFormatted.c_str());*/
104+
105+ ImGui::Text (" quantity: %d" , skin.qunatity );
106+ ImGui::Text (" uuid: %s" , skin.uuid .c_str ());
92107 }
108+
93109 ImGui::EndTabItem ();
94110 }
95- else skinsOpen = true ;
111+ else
112+ bOnOpen = true ;
96113 }
97114};
0 commit comments