From f795f7533a7a988bc08fad43cbf6c038ad174e32 Mon Sep 17 00:00:00 2001 From: Tomo <68489118+tomodachi94@users.noreply.github.com> Date: Sat, 23 Dec 2023 14:52:43 -0800 Subject: [PATCH] bases.basecatalogitem: Init --- roblox/bases/basecatalogitem.py | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 roblox/bases/basecatalogitem.py diff --git a/roblox/bases/basecatalogitem.py b/roblox/bases/basecatalogitem.py new file mode 100644 index 00000000..375ef1d0 --- /dev/null +++ b/roblox/bases/basecatalogitem.py @@ -0,0 +1,47 @@ +""" + +This file contains the BaseCatalogItem object, which represents a Roblox catalog item ID. + +""" + +from __future__ import annotations +from typing import TYPE_CHECKING + +from .baseitem import BaseItem + +if TYPE_CHECKING: + from ..client import Client + + +class BaseCatalogItem(BaseItem): + """ + Represents a Roblox instance ID. + Instance IDs represent the ownership of a single Roblox item. + + Attributes: + id: The item ID. + item_type: The item's type, either 1 or 2. + """ + + def __init__(self, client: Client, catalog_item_id: int): + """ + Arguments: + client: The Client this object belongs to. + catalog_item_id: The ID of the catalog item. + """ + + self._client: Client = client + self.id: int = catalog_item_id + self.item_type: int = catalog_item_type + + # We need to redefine these special methods, as an asset and a bundle can have the same ID but not the same item_type + def __repr__(self): + return f"<{self.__class__.__name__} id={self.id} item_type={self.item_type}>" + + def __eq__(self, other): + return isinstance(other, self.__class__) and (other.id == self.id) and (other.item_type == self.item_type) + + def __ne__(self, other): + if isinstance(other, self.__class__): + return (other.id != self.id) and (other.item_type != self.item_type) + return True