Skip to content

Commit 1ae023c

Browse files
committed
Add owns column to store table
1 parent 6f8b648 commit 1ae023c

5 files changed

Lines changed: 105 additions & 8 deletions

File tree

src/components/store_table.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class StoreTable extends Table {
2020
};
2121

2222
#actionButtonElement;
23+
#oldNotificationElement;
2324

2425
static TAB = {
2526
GENERAL: 0,
@@ -75,6 +76,21 @@ export default class StoreTable extends Table {
7576
}
7677

7778
// Build Table Header
79+
const cachedNotificationElement = CreateElement("span", {
80+
text: "(Cached)"
81+
});
82+
83+
BindTooltip(cachedNotificationElement, "The information below was loaded from cache and may no longer be accurate.");
84+
85+
this.#oldNotificationElement = CreateElement("span", {
86+
text: "(Old)",
87+
style: {
88+
display: "none",
89+
}
90+
});
91+
92+
BindTooltip(this.#oldNotificationElement, "The information below may be outdated and will be updated when the page is refreshed.");
93+
7894
const tableHeaderElement = CreateElement("thead", {
7995
children: [
8096
CreateElement("tr", {
@@ -175,6 +191,26 @@ export default class StoreTable extends Table {
175191
})
176192
]
177193
}),
194+
this.#store.inventoryLoaded && CreateElement("th", {
195+
class: "cs2s_table_store_owned_column",
196+
children: [
197+
CreateElement("span", {
198+
class: "cs2s_table_column",
199+
id: "owned_column",
200+
text: "Owned",
201+
children: [
202+
CreateElement("div", {
203+
class: "cs2s_table_column_sort",
204+
})
205+
],
206+
onclick: (event) => {
207+
this._SortRows({ event: event, columns: ["owned"]});
208+
}
209+
}),
210+
this.#store.inventoryLoadedFromCache && cachedNotificationElement,
211+
this.#oldNotificationElement
212+
]
213+
}),
178214
CreateElement("th", {
179215
class: "cs2s_table_store_price_column",
180216
children: [
@@ -319,6 +355,10 @@ export default class StoreTable extends Table {
319355
html: `${item.section_name} — ${item.team_1} (${item.team_1_score}) — ${item.team_2} (${item.team_2_score})`
320356
})
321357
),
358+
this.#store.inventoryLoaded && CreateElement("td", {
359+
class: "cs2s_table_store_owned_column",
360+
text: item.owned
361+
}),
322362
CreateElement("td", {
323363
class: "cs2s_table_store_price_column",
324364
children: [
@@ -585,7 +625,14 @@ export default class StoreTable extends Table {
585625
}
586626

587627
newTab.location.href = purchaseUrl;
588-
this.#inventoryChanged = true;
628+
629+
if (!this.#inventoryChanged) {
630+
this.#inventoryChanged = true;
631+
632+
if (this.#store.inventoryLoaded && !this.#store.inventoryLoadedFromCache) {
633+
this.#oldNotificationElement.style.display = "";
634+
}
635+
}
589636

590637
loadingPopup.Hide();
591638
} catch (e) {

src/components/table.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ export default class Table {
255255

256256
if (!resetSort) {
257257
if (asc) {
258-
options.event.target.querySelector(".cs2s_table_column_sort").classList.add("cs2s_table_column_sort_asc");
258+
options.event.currentTarget.querySelector(".cs2s_table_column_sort").classList.add("cs2s_table_column_sort_asc");
259259
} else {
260-
options.event.target.querySelector(".cs2s_table_column_sort").classList.add("cs2s_table_column_sort_desc");
260+
options.event.currentTarget.querySelector(".cs2s_table_column_sort").classList.add("cs2s_table_column_sort_desc");
261261
}
262262
}
263263
}

src/core/script.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,8 @@ class Script {
934934
return OPERATION_ERROR.FAILED_TO_LOAD;
935935
}
936936

937+
const inventory = await this.GetInventory(options);
938+
937939
try {
938940
await store.LoadStoreContents(progressCallback);
939941
} catch (e) {
@@ -942,6 +944,10 @@ class Script {
942944
return e.OPERATION_ERROR ?? OPERATION_ERROR.FAILED_TO_LOAD;
943945
}
944946

947+
if (inventory instanceof Inventory) {
948+
store.LoadInventory(inventory);
949+
}
950+
945951
return store;
946952
});
947953
}

src/cs2/items/store.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import Icons from './icons';
55

66
export default class Store {
77
items;
8+
inventoryLoaded = false;
9+
inventoryLoadedFromCache;
810

911
#storeData;
1012
#tournamentData;
@@ -90,8 +92,8 @@ export default class Store {
9092
const map_name = Constant.TOURNAMENT_MAPS[match.roundstats_legacy.map_id];
9193
const stage_id = match.roundstats_legacy.reservation.tournament_event.event_stage_id;
9294
const section = this.#tournamentData.tournamentinfo.sections.find(section => section.groups.find(group => group.stage_ids.includes(stage_id)));
93-
const team_1 = match.roundstats_legacy.reservation.tournament_teams[0].team_name;
94-
const team_2 = match.roundstats_legacy.reservation.tournament_teams[1].team_name;
95+
const team_1 = match.roundstats_legacy.reservation.tournament_teams[0];
96+
const team_2 = match.roundstats_legacy.reservation.tournament_teams[1];
9597
const is_highlight = section.sectionid >= highlightSectionIDStart;
9698
const hash_name = this.#GetHashName(item, map_name, is_highlight);
9799
const non_highlight_hash_name = this.#GetHashName(item, map_name); // Highlight packages use the same icons as non-highlight packages
@@ -126,13 +128,16 @@ export default class Store {
126128
layout_weight: this.#storeData.price_sheet.store_banner_layout[item.def_index]?.w,
127129
tournament_id: item.tournament_id,
128130
requires_supplemental_data: item.requires_supplemental_data,
131+
stage_id: stage_id,
129132
section_id: section.sectionid,
130133
section_name: section.name,
131-
team_1: team_1,
134+
team_1: team_1.team_name,
135+
team_1_id: team_1.team_id,
132136
team_1_score: match.roundstats_legacy.team_scores[0],
133-
team_2: team_2,
137+
team_2: team_2.team_name,
138+
team_2_id: team_2.team_id,
134139
team_2_score: match.roundstats_legacy.team_scores[1],
135-
teams_normalized: `${team_1} ${team_2}`.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(),
140+
teams_normalized: `${team_1.team_name} ${team_2.team_name}`.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(),
136141
match_result: match.roundstats_legacy.match_result
137142
});
138143
}
@@ -147,6 +152,36 @@ export default class Store {
147152
await Icons.FetchMarketIcons(new Set([...storeItemsToGetIconsFor, ...marketItemsToGetIconsFor]), progressCallback);
148153
}
149154

155+
LoadInventory(inventory) {
156+
for (const item of this.items) {
157+
item.owned = [...inventory.items, ...inventory.storedItems].filter(x => {
158+
if (x.iteminfo.def_index == item.id) {
159+
return true;
160+
}
161+
162+
// Coupon items
163+
if (!item.requires_supplemental_data && item.hash_name && x.full_name == item.hash_name) {
164+
return true;
165+
}
166+
167+
// Souvenir packages
168+
if (item.requires_supplemental_data
169+
&& x.full_name == item.hash_name
170+
&& x.attributes["tournament event stage id"] == item.stage_id
171+
&& x.attributes["tournament event team0 id"] == item.team_1_id
172+
&& x.attributes["tournament event team1 id"] == item.team_2_id
173+
) {
174+
return true;
175+
}
176+
177+
return false;
178+
}).length;
179+
}
180+
181+
this.inventoryLoaded = true;
182+
this.inventoryLoadedFromCache = inventory.loadedFromCache;
183+
}
184+
150185
FormatCurrency(valueInCents) {
151186
let currencyFormat = (valueInCents / 100).toFixed(2);
152187

src/css/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,14 @@
735735
width: 450px;
736736
}
737737

738+
.cs2s_table_store_owned_column {
739+
width: 165px;
740+
741+
.cs2s_has_tooltip {
742+
color: #737373;
743+
}
744+
}
745+
738746
.cs2s_table_store_price_column {
739747
width: 200px;
740748

@@ -1073,6 +1081,7 @@
10731081
font-weight: normal;
10741082
font-size: 13px;
10751083
max-width: 275px;
1084+
height: 20px;
10761085

10771086
&::before {
10781087
content: "";

0 commit comments

Comments
 (0)