|
| 1 | +""" |
| 2 | +
|
| 3 | +This file contains the BaseCatalogItem object, which represents a Roblox catalog item ID. |
| 4 | +
|
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | +from typing import TYPE_CHECKING |
| 9 | + |
| 10 | +from .baseitem import BaseItem |
| 11 | + |
| 12 | +if TYPE_CHECKING: |
| 13 | + from ..client import Client |
| 14 | + |
| 15 | + |
| 16 | +class BaseCatalogItem(BaseItem): |
| 17 | + """ |
| 18 | + Represents a Roblox instance ID. |
| 19 | + Instance IDs represent the ownership of a single Roblox item. |
| 20 | +
|
| 21 | + Attributes: |
| 22 | + id: The item ID. |
| 23 | + item_type: The item's type, either 1 or 2. |
| 24 | + """ |
| 25 | + |
| 26 | + def __init__(self, client: Client, catalog_item_id: int): |
| 27 | + """ |
| 28 | + Arguments: |
| 29 | + client: The Client this object belongs to. |
| 30 | + catalog_item_id: The ID of the catalog item. |
| 31 | + """ |
| 32 | + |
| 33 | + self._client: Client = client |
| 34 | + self.id: int = catalog_item_id |
| 35 | + self.item_type: int = catalog_item_type |
| 36 | + |
| 37 | + # We need to redefine these special methods, as an asset and a bundle can have the same ID but not the same item_type |
| 38 | + def __repr__(self): |
| 39 | + return f"<{self.__class__.__name__} id={self.id} item_type={self.item_type}>" |
| 40 | + |
| 41 | + def __eq__(self, other): |
| 42 | + return isinstance(other, self.__class__) and (other.id == self.id) and (other.item_type == self.item_type) |
| 43 | + |
| 44 | + def __ne__(self, other): |
| 45 | + if isinstance(other, self.__class__): |
| 46 | + return (other.id != self.id) and (other.item_type != self.item_type) |
| 47 | + return True |
0 commit comments