Skip to content

Commit

Permalink
Add first_url property to HexdocImage
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed May 23, 2024
1 parent 3a6f394 commit 2fab8f6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/hexdoc/graphics/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
model_validator,
)
from typing_extensions import TypeVar, override
from yarl import URL

from hexdoc.core import ItemStack, Properties, ResourceLocation
from hexdoc.minecraft.i18n import I18n, LocalizedStr
Expand Down Expand Up @@ -59,6 +60,10 @@ def template(cls):
def name(self):
return self._name

@property
@abstractmethod
def first_url(self) -> URL: ...

@abstractmethod
def _get_name(self, info: ValidationInfo) -> LocalizedStr: ...

Expand All @@ -76,6 +81,11 @@ class URLImage(HexdocImage[_T_ResourceLocation], template_id="hexdoc:single"):
url: PydanticURL
pixelated: bool = True

@property
@override
def first_url(self):
return self.url


class TextureImage(URLImage[ResourceLocation], InlineModel):
@override
Expand Down Expand Up @@ -142,6 +152,11 @@ def _get_name(self, info: ValidationInfo):
class CyclingImage(HexdocImage[_T_ResourceLocation], template_id="hexdoc:cycling"):
images: list[HexdocImage] = Field(min_length=1)

@property
@override
def first_url(self):
return self.images[0].first_url

@override
def _get_name(self, info: ValidationInfo):
return self.images[0].name
Expand Down

0 comments on commit 2fab8f6

Please sign in to comment.