Skip to content

Commit

Permalink
fix: restoring support for card conjurer
Browse files Browse the repository at this point in the history
  • Loading branch information
Guibod committed Feb 26, 2023
1 parent 756bc03 commit f97b523
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 758 deletions.
13 changes: 8 additions & 5 deletions src/mightstone/services/cardconjurer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ async def _fetch_font(self, font: TemplateFont, base_uri: str = None):
async with aiofiles.open(uri) as f:
buffer = BytesIO(await f.read())
elif parsed_uri.scheme in ("http", "https"):
f = self.client.get(uri)
buffer = f.content
f = await self.client.get(uri)
buffer = BytesIO(f.content)
else:
raise RuntimeError(f"Unknown scheme {parsed_uri.scheme}")

Expand All @@ -239,13 +239,16 @@ async def _fetch_image(self, img: CCImage, base_uri: str = None):
logger.info("Fetching image %s", uri)
if parsed_uri.scheme == "file":
async with aiofiles.open(uri) as f:
fo = BytesIO(await f.read())
self.assets_images[id(img)] = self._image_potentially_from_svg(fo)
self.assets_images[id(img)] = self._image_potentially_from_svg(
BytesIO(await f.read())
)
return

if parsed_uri.scheme in ("http", "https"):
f = await self.client.get(uri)
self.assets_images[id(img)] = self._image_potentially_from_svg(f.content)
self.assets_images[id(img)] = self._image_potentially_from_svg(
BytesIO(f.content)
)
return

raise ValueError(f"URI: {uri} scheme is not supported")
Expand Down
13 changes: 10 additions & 3 deletions src/mightstone/services/cardconjurer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class Mask(MightstoneModel):
src: str


class Variant(MightstoneModel):
name: str
src: str
thumb: str
x: Optional[int]


class FilterOverlay(MightstoneModel):
type: Literal[Filters.COLOR_OVERLAY]
color: Color
Expand Down Expand Up @@ -267,8 +274,8 @@ class TemplateContextImageSet(MightstoneModel):
"""

prototype: Dict[str, Any]
variants: Dict[str, Dict[str, Any]]
masks: Optional[Dict[str, Mask]]
variants: List[Variant]
masks: Optional[List[Mask]]


class TemplateFont(MightstoneModel):
Expand Down Expand Up @@ -302,7 +309,7 @@ class TemplateContext(MightstoneModel):
"""

ui: Any
image_sets: List[Dict[str, TemplateContextImageSet]] = Field(alias="imageSets")
image_sets: List[TemplateContextImageSet] = Field(alias="imageSets")
fonts: List[TemplateFont] = []
symbolExtension: Optional[Dict[str, List[TemplateExtension]]]

Expand Down
90 changes: 75 additions & 15 deletions tests/mightstone/services/cardconjurer/Dimirova Smiley.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
"type": "image",
"name": "Blue Frame",
"src": "custom/11-20-22/blue.png",
"thumb": "custom/11-20-22/thumb-blue.png"
"thumb": "custom/11-20-22/thumb-blue.png",
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "image",
Expand All @@ -61,9 +65,17 @@
{
"type": "image",
"name": "Right Half",
"src": "general/rightHalf.svg"
"src": "general/rightHalf.svg",
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "image",
Expand All @@ -74,9 +86,17 @@
{
"type": "image",
"name": "Title",
"src": "custom/11-20-22/title.svg"
"src": "custom/11-20-22/title.svg",
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "image",
Expand All @@ -87,9 +107,17 @@
{
"type": "image",
"name": "Type",
"src": "custom/11-20-22/type.svg"
"src": "custom/11-20-22/type.svg",
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "image",
Expand All @@ -100,9 +128,17 @@
{
"type": "image",
"name": "Rules",
"src": "custom/11-20-22/rules.svg"
"src": "custom/11-20-22/rules.svg",
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "image",
Expand All @@ -113,9 +149,17 @@
{
"type": "image",
"name": "Pinline",
"src": "custom/11-20-22/pinline.svg"
"src": "custom/11-20-22/pinline.svg",
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "image",
Expand Down Expand Up @@ -179,7 +223,11 @@
"x": 725,
"width": 50
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "group",
Expand Down Expand Up @@ -353,7 +401,11 @@
"rotation": 90,
"align": "center"
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "group",
Expand All @@ -371,7 +423,11 @@
"width": 640,
"height": 35
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
},
{
"type": "image",
Expand All @@ -382,6 +438,10 @@
"width": 1632,
"height": 2220
}
]
],
"x": 0,
"y": 0,
"width": 1500,
"height": 2100
}
}

0 comments on commit f97b523

Please sign in to comment.