diff --git a/src/js/Content/Features/Store/Wishlist/FWishlistHighlights.ts b/src/js/Content/Features/Store/Wishlist/FWishlistHighlights.ts index f591067a8..b8f036d18 100644 --- a/src/js/Content/Features/Store/Wishlist/FWishlistHighlights.ts +++ b/src/js/Content/Features/Store/Wishlist/FWishlistHighlights.ts @@ -1,7 +1,7 @@ import type CWishlist from "@Content/Features/Store/Wishlist/CWishlist"; import Feature from "@Content/Modules/Context/Feature"; import HighlightsTagsUtils2, {EHighlightStyle, type ItemSetup} from "@Content/Modules/Highlights/HighlightsTagsUtils2"; -import {Appid} from "@Content/Modules/Highlights/StoreIds"; +import AppId from "@Core/GameId/AppId"; export default class FWishlistHighlights extends Feature { @@ -26,7 +26,7 @@ export default class FWishlistHighlights extends Feature { return; } - const appids = this.context.wishlistData?.map(entry => new Appid(entry.appid)) ?? []; + const appids = this.context.wishlistData?.map(entry => new AppId(entry.appid)) ?? []; if (appids.length === 0) { return; diff --git a/src/js/Content/Features/Store/Wishlist/Utils/WishlistDOM.ts b/src/js/Content/Features/Store/Wishlist/Utils/WishlistDOM.ts index 755a1c5c8..ba35af31d 100644 --- a/src/js/Content/Features/Store/Wishlist/Utils/WishlistDOM.ts +++ b/src/js/Content/Features/Store/Wishlist/Utils/WishlistDOM.ts @@ -1,9 +1,9 @@ -import {Appid} from "@Content/Modules/Highlights/StoreIds"; import ASEventHandler from "@Content/Modules/ASEventHandler"; +import AppId from "@Core/GameId/AppId"; interface TDOMGame { node: HTMLElement, - appid?: Appid, + appid?: AppId, title?: { node: HTMLElement, value: string|null, @@ -76,9 +76,9 @@ export class WishlistDOM { return parent.querySelector("a.Fuz2JeT4RfI-[href*='/app/']"); } - appid(anchorNode: HTMLAnchorElement): Appid|null { + appid(anchorNode: HTMLAnchorElement): AppId|null { const m = anchorNode.href.match(/app\/(\d+)/)!; - return m ? new Appid(Number(m[1])) : null; + return m ? new AppId(Number(m[1])) : null; } observe(): void { diff --git a/src/js/Content/Modules/Highlights/HighlightsTagsUtils.ts b/src/js/Content/Modules/Highlights/HighlightsTagsUtils.ts index ef64f32e4..63eebe708 100644 --- a/src/js/Content/Modules/Highlights/HighlightsTagsUtils.ts +++ b/src/js/Content/Modules/Highlights/HighlightsTagsUtils.ts @@ -33,6 +33,9 @@ type Options = { coupon: boolean, } +/** + * @deprecated + */ export default class HighlightsTagsUtils { private static _highlightCssLoaded: boolean = false; diff --git a/src/js/Content/Modules/Highlights/HighlightsTagsUtils2.ts b/src/js/Content/Modules/Highlights/HighlightsTagsUtils2.ts index 9c5dcca5c..cf1efb184 100644 --- a/src/js/Content/Modules/Highlights/HighlightsTagsUtils2.ts +++ b/src/js/Content/Modules/Highlights/HighlightsTagsUtils2.ts @@ -2,9 +2,9 @@ import Settings from "@Options/Data/Settings"; import DynamicStore from "@Content/Modules/Data/DynamicStore"; import ITAD from "@Content/Modules/ITAD"; import InventoryApiFacade from "@Content/Modules/Facades/InventoryApiFacade"; -import type {StoreId} from "@Content/Modules/Highlights/StoreIds"; import DOMHelper from "@Content/Modules/DOMHelper"; import Tags from "@Content/Modules/Highlights/Tags.svelte"; +import type GameId from "@Core/GameId/GameId"; export const enum EHighlightStyle { BgGradient, @@ -97,14 +97,14 @@ export default class HighlightsTagsUtils2 { DOMHelper.insertCSS(css.join("\n")); } - public async query(ids: StoreId[]): Promise> { + public async query(ids: GameId[]): Promise> { const result: Map = new Map(); if (ids.length === 0) { return result; } - let query: StoreId[] = []; + let query: GameId[] = []; for(let id of ids) { if (this.cache.has(id.string)) { diff --git a/src/js/Content/Modules/Highlights/StoreIds.ts b/src/js/Content/Modules/Highlights/StoreIds.ts deleted file mode 100644 index e70cced74..000000000 --- a/src/js/Content/Modules/Highlights/StoreIds.ts +++ /dev/null @@ -1,42 +0,0 @@ - -export abstract class StoreId { - - private readonly full: string; - - protected constructor( - private type_: "app"|"sub"|"bundle", - private id_: number - ) { - this.full = `${this.type_}/${this.id_}`; - } - - get type(): "app"|"sub"|"bundle" { - return this.type_; - } - - get number(): number { - return this.id_; - } - - get string(): string { - return this.full; - }; -} - -export class Appid extends StoreId { - constructor(id: number) { - super("app", id); - } -} - -export class Subid extends StoreId { - constructor(id: number) { - super("app", id); - } -} - -export class Bundleid extends StoreId { - constructor(id: number) { - super("bundle", id); - } -} \ No newline at end of file diff --git a/src/js/Core/GameId/AppId.ts b/src/js/Core/GameId/AppId.ts index 83d2bcec3..73368ebf1 100644 --- a/src/js/Core/GameId/AppId.ts +++ b/src/js/Core/GameId/AppId.ts @@ -1,5 +1,7 @@ +import GameId from "@Core/GameId/GameId"; -export default class AppId { +// TODO refactor to return instance +export default class AppId extends GameId { static fromUrl(url: string) { const m = url.match(/(?:store\.steampowered|steamcommunity)\.com\/(?:app|games|market\/listings)\/(\d+)\/?/); @@ -65,4 +67,8 @@ export default class AppId { } return result; } + + constructor(id: number) { + super("app", id); + } } diff --git a/src/js/Core/GameId/BundleId.ts b/src/js/Core/GameId/BundleId.ts index 3ba2e5274..ec845273b 100644 --- a/src/js/Core/GameId/BundleId.ts +++ b/src/js/Core/GameId/BundleId.ts @@ -1,5 +1,7 @@ +import GameId from "@Core/GameId/GameId"; -export default class BundleId { +// TODO refactor to return instance +export default class BundleId extends GameId{ static fromUrl(url: string): number|null { const m = url.match(/(?:store\.steampowered|steamcommunity)\.com\/bundle\/(\d+)\/?/); @@ -25,4 +27,8 @@ export default class BundleId { return this.fromUrl(href); } + + constructor(id: number) { + super("bundle", id); + } } diff --git a/src/js/Core/GameId/GameId.ts b/src/js/Core/GameId/GameId.ts index 388dfd2f1..689e9830e 100644 --- a/src/js/Core/GameId/GameId.ts +++ b/src/js/Core/GameId/GameId.ts @@ -1,6 +1,24 @@ -export default class GameId { - static trimStoreId(storeId: string): number { - return Number(storeId.slice(storeId.indexOf("/") + 1)); +export default abstract class GameId { + + private readonly full: string; + + protected constructor( + private type_: "app"|"sub"|"bundle", + private id_: number + ) { + this.full = `${this.type_}/${this.id_}`; + } + + get type(): "app"|"sub"|"bundle" { + return this.type_; } + + get number(): number { + return this.id_; + } + + get string(): string { + return this.full; + }; } diff --git a/src/js/Core/GameId/SubId.ts b/src/js/Core/GameId/SubId.ts index 8fcd20c0c..a07d94bbb 100644 --- a/src/js/Core/GameId/SubId.ts +++ b/src/js/Core/GameId/SubId.ts @@ -1,4 +1,7 @@ -export default class SubId { +import GameId from "@Core/GameId/GameId"; + +// TODO refactor to return instance +export default class SubId extends GameId{ static fromUrl(url: string): number|null { const m = url.match(/(?:store\.steampowered|steamcommunity)\.com\/sub\/(\d+)\/?/); @@ -24,4 +27,8 @@ export default class SubId { return this.fromUrl(href); } + + constructor(id: number) { + super("sub", id); + } }