|
| 1 | +import { saveDataJson } from "../utils/saveDataJson.js"; |
| 2 | +import { $t, languageData } from "./translations.js"; |
| 3 | +import { state } from "./main.js"; |
| 4 | +import specialNotes from "../utils/specialNotes.json" with { type: "json" }; |
| 5 | +import { getRarityColor } from "../utils/index.js"; |
| 6 | +import { getImageUrl } from "../constants.js"; |
| 7 | + |
| 8 | +const isSticker = item => { |
| 9 | + if (item.sticker_material === undefined) { |
| 10 | + return false; |
| 11 | + } |
| 12 | + |
| 13 | + // https://github.com/ByMykel/CSGO-API/issues/208 |
| 14 | + // Theses team roles stickers are not avaliable in the game, so we don't need to parse them |
| 15 | + if ( |
| 16 | + item.sticker_material.startsWith("team_roles_capsule") && |
| 17 | + item.sticker_material.endsWith("_foil") && |
| 18 | + item.sticker_material !== "team_roles_capsule/pro_foil" |
| 19 | + ) { |
| 20 | + return false; |
| 21 | + } |
| 22 | + |
| 23 | + // https://github.com/ByMykel/CSGO-API/issues/209 |
| 24 | + // These stickers are not avaliable in the game, so we don't need to parse them |
| 25 | + // Sticker | 3DMAX | DreamHack 2014 |
| 26 | + // Sticker | dAT team | DreamHack 2014 |
| 27 | + // Sticker | London Conspiracy | DreamHack 2014 |
| 28 | + // Sticker | mousesports | DreamHack 2014 |
| 29 | + if (["232", "234", "235", "236"].includes(item.object_id)) { |
| 30 | + return false; |
| 31 | + } |
| 32 | + |
| 33 | + if (!item.item_name.toLowerCase().includes("stickerkit_")) { |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + if (item.name.includes("graffiti")) { |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + if (item.name.includes("spray_")) { |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + return true; |
| 46 | +}; |
| 47 | + |
| 48 | +const getDescription = () => { |
| 49 | + return `${$t("keychain_kc_sticker_display_case_desc")}<br><br>${$t("csgo_tool_keychain_desc")}`; |
| 50 | +}; |
| 51 | + |
| 52 | +const getType = item => { |
| 53 | + if (item.tournament_player_id) { |
| 54 | + return "Autograph"; |
| 55 | + } |
| 56 | + |
| 57 | + if (item.tournament_team_id) { |
| 58 | + return "Team"; |
| 59 | + } |
| 60 | + |
| 61 | + if (item.tournament_event_id) { |
| 62 | + return "Event"; |
| 63 | + } |
| 64 | + |
| 65 | + return "Other"; |
| 66 | +}; |
| 67 | + |
| 68 | +const getEffect = item => { |
| 69 | + if ($t(item.item_name, true).includes("(Holo)") || $t(item.item_name, true).includes("(Holo, ")) { |
| 70 | + return "Holo"; |
| 71 | + } |
| 72 | + |
| 73 | + if ($t(item.item_name, true).includes("(Foil)")) { |
| 74 | + return "Foil"; |
| 75 | + } |
| 76 | + |
| 77 | + if ($t(item.item_name, true).includes("(Lenticular)")) { |
| 78 | + return "Lenticular"; |
| 79 | + } |
| 80 | + |
| 81 | + if ($t(item.item_name, true).includes("(Glitter)") || $t(item.item_name, true).includes("(Glitter, ")) { |
| 82 | + return "Glitter"; |
| 83 | + } |
| 84 | + |
| 85 | + if ($t(item.item_name, true).includes("(Gold)") || $t(item.item_name, true).includes("(Gold, ")) { |
| 86 | + return "Gold"; |
| 87 | + } |
| 88 | + |
| 89 | + return "Other"; |
| 90 | +}; |
| 91 | + |
| 92 | +const getMarketHashName = item => { |
| 93 | + // 1 - DreamHack 2013 |
| 94 | + if (item.tournament_event_id === 1) { |
| 95 | + return null; |
| 96 | + } |
| 97 | + |
| 98 | + // 3 - Katowice 2014 |
| 99 | + if (item.tournament_event_id === 3) { |
| 100 | + if ( |
| 101 | + (getType(item) === "Event" && item.sticker_material.includes("gold_foil")) || |
| 102 | + (getEffect(item) === "Foil" && getType(item) === "Team") |
| 103 | + ) { |
| 104 | + return null; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + // 4 - Cologne 2014 |
| 109 | + if (item.tournament_event_id === 4) { |
| 110 | + if (getEffect(item) === "Foil" || item.sticker_material === "cologne2014/esl_c") { |
| 111 | + return null; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + // 5 - DreamHack 2014, |
| 116 | + // 6 - Katowice 2015, |
| 117 | + // 7 - Cologne 2015, |
| 118 | + // 8 - Cluj-Napoca 2015 |
| 119 | + // 9 - Columbus 2016 |
| 120 | + // 10 - Cologne 2016 |
| 121 | + // 11 - Atlanta 2017 |
| 122 | + // 12 - Krakow 2017 |
| 123 | + // 13 - Boston 2018 |
| 124 | + // 14 - London 2018 |
| 125 | + // 15 - Katowice 2019 |
| 126 | + // 16 - Berlin 2019 |
| 127 | + if ([5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16].includes(item.tournament_event_id)) { |
| 128 | + if (item.item_rarity === "legendary" && getEffect(item) === "Gold") { |
| 129 | + return null; |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + if ( |
| 134 | + item.sticker_material.startsWith("tournament_assets/") || |
| 135 | + item.sticker_material.startsWith("danger_zone/") |
| 136 | + ) { |
| 137 | + return null; |
| 138 | + } |
| 139 | + |
| 140 | + return `${$t("keychain_kc_sticker_display_case", true)} | ${$t(item.item_name, true)}`; |
| 141 | +}; |
| 142 | + |
| 143 | +const parseItem = item => { |
| 144 | + const { cratesBySkins, proTeams, proPlayers, collectionsByStickers, cdnImages } = state; |
| 145 | + |
| 146 | + const image = |
| 147 | + cdnImages[`econ/stickers/${item.sticker_material.toLowerCase()}_1355_37`] ?? |
| 148 | + getImageUrl(`econ/stickers/${item.sticker_material.toLowerCase()}_1355_37`); |
| 149 | + |
| 150 | + // items_game.txt is named as dignitas but in translation as teamdignitas. |
| 151 | + if (item.item_name === "#StickerKit_dhw2014_dignitas_gold") { |
| 152 | + item.item_name = "#StickerKit_dhw2014_teamdignitas_gold"; |
| 153 | + } |
| 154 | + |
| 155 | + return { |
| 156 | + id: `sticker-slab-${item.object_id}`, |
| 157 | + name: `${$t("keychain_kc_sticker_display_case")} | ${$t(item.item_name)}`, |
| 158 | + description: getDescription(), |
| 159 | + def_index: item.object_id, |
| 160 | + rarity: item.item_rarity |
| 161 | + ? { |
| 162 | + id: `rarity_${item.item_rarity}`, |
| 163 | + name: $t(`rarity_${item.item_rarity}`), |
| 164 | + color: getRarityColor(`rarity_${item.item_rarity}`), |
| 165 | + } |
| 166 | + : { |
| 167 | + id: "rarity_default", |
| 168 | + name: $t("rarity_default"), |
| 169 | + color: getRarityColor("rarity_default"), |
| 170 | + }, |
| 171 | + special_notes: specialNotes?.[`sticker-${item.object_id}`], |
| 172 | + crates: |
| 173 | + cratesBySkins?.[`sticker-${item.object_id}`]?.map(i => ({ |
| 174 | + ...i, |
| 175 | + name: $t(i.name), |
| 176 | + })) ?? [], |
| 177 | + collections: |
| 178 | + collectionsByStickers?.[`sticker-${item.object_id}`]?.map(i => ({ |
| 179 | + ...i, |
| 180 | + name: $t(i.name), |
| 181 | + })) ?? [], |
| 182 | + type: getType(item), |
| 183 | + market_hash_name: getMarketHashName(item), |
| 184 | + effect: getEffect(item), |
| 185 | + tournament: item.tournament_event_id |
| 186 | + ? { |
| 187 | + id: item.tournament_event_id, |
| 188 | + name: $t(`csgo_tournament_event_nameshort_${item.tournament_event_id}`), |
| 189 | + } |
| 190 | + : undefined, |
| 191 | + team: proTeams[item.tournament_team_id] |
| 192 | + ? { |
| 193 | + ...proTeams[item.tournament_team_id], |
| 194 | + name: $t(`csgo_teamid_${item.tournament_team_id}`), |
| 195 | + } |
| 196 | + : undefined, |
| 197 | + player: proPlayers[item.tournament_player_id] ?? undefined, |
| 198 | + image, |
| 199 | + |
| 200 | + // Return original attributes from item_game.json |
| 201 | + original: { |
| 202 | + name: item.name, |
| 203 | + image_inventory: `econ/stickers/${item.sticker_material.toLowerCase()}_1355_37`, |
| 204 | + }, |
| 205 | + }; |
| 206 | +}; |
| 207 | + |
| 208 | +export const getStickersSlab = () => { |
| 209 | + const { stickerKits } = state; |
| 210 | + const { folder } = languageData; |
| 211 | + |
| 212 | + const stickers = stickerKits.filter(isSticker).map(parseItem); |
| 213 | + |
| 214 | + saveDataJson(`./public/api/${folder}/stickers_slab.json`, stickers); |
| 215 | +}; |
0 commit comments