forked from amethyst/blobfox
parent
e524e1cbbf
commit
74a88cf3af
@ -1,46 +0,0 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from cairosvg.surface import Surface
|
||||
from yaml import load
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Object:
|
||||
type: str
|
||||
src: Path | None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Overwrite:
|
||||
id: str
|
||||
color: str | None
|
||||
remove: bool = False
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Emote:
|
||||
name: str
|
||||
src: Path | None = None
|
||||
objects: list[Object] | None = None
|
||||
overwrite: list[Overwrite] | None = None
|
||||
|
||||
|
||||
class Generator:
|
||||
|
||||
def generate( self, declarationFile: Path, outputDir: Path = Path('.') ) -> None:
|
||||
if not declarationFile.exists():
|
||||
raise FileNotFoundError('Declaration file does not exist!')
|
||||
|
||||
if not outputDir.exists():
|
||||
outputDir.mkdir()
|
||||
|
||||
data = load( declarationFile.read_text(), None )
|
||||
print( data )
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gen = Generator()
|
||||
gen.generate( Path('./resources/blobfox.yml'), Path('./run') )
|
@ -0,0 +1,28 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing_extensions import Self
|
||||
|
||||
from data.object import Object
|
||||
from data.overwrite import Overwrite
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Emote:
|
||||
name: str
|
||||
origin: str
|
||||
base: str | None = None
|
||||
src: Path | None = None
|
||||
objects: list[Object] = None
|
||||
overwrites: list[Overwrite] = None
|
||||
|
||||
@classmethod
|
||||
def load( cls, data: list[dict], origin: str ) -> list[Self]:
|
||||
return [
|
||||
Emote(
|
||||
origin=origin,
|
||||
**entry | {
|
||||
'overwrites': Overwrite.load( entry.get( 'overwrites', [ ] ) ),
|
||||
'objects': Object.load( entry.get( 'objects', [ ] ) )
|
||||
}
|
||||
) for entry in data
|
||||
]
|
@ -0,0 +1,17 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Object:
|
||||
type: str
|
||||
src: Path | None
|
||||
|
||||
@classmethod
|
||||
def load( cls, data: list[dict] ) -> list[ Self ]:
|
||||
objects: list[ Object ] = []
|
||||
for obj in data or []:
|
||||
objects += [ Object( **obj ) ]
|
||||
|
||||
return objects
|
@ -0,0 +1,17 @@
|
||||
from dataclasses import dataclass
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Overwrite:
|
||||
id: str
|
||||
color: str | None
|
||||
remove: bool = False
|
||||
|
||||
@classmethod
|
||||
def load( cls, data: list[dict] ) -> list[Self]:
|
||||
overwrites: list[ Overwrite ] = [ ]
|
||||
for overwrite in data or [ ]:
|
||||
overwrites += [ Overwrite( **overwrite ) ]
|
||||
|
||||
return overwrites
|
@ -0,0 +1,52 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Final
|
||||
from collections.abc import Collection, Iterator
|
||||
|
||||
from data.emote import Emote
|
||||
|
||||
|
||||
# noinspection PyFinal
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class VariantList(Collection[Emote]):
|
||||
""" An immutable variant list """
|
||||
name: Final[ str ]
|
||||
basedOff: Final[ list[ str ] ]
|
||||
variants: Final[ tuple[Emote] ]
|
||||
|
||||
def __init__( self, name: str, variants: list[ dict ], basedOff: list[str] | None = None ) -> None:
|
||||
object.__setattr__(
|
||||
self,
|
||||
'variants',
|
||||
tuple( Emote.load( variants, name ) )
|
||||
)
|
||||
object.__setattr__( self, 'basesOff', basedOff or [] )
|
||||
object.__setattr__( self, 'name', name )
|
||||
|
||||
def __iter__( self ) -> Iterator[Emote ]:
|
||||
return self.variants.__iter__()
|
||||
|
||||
def __contains__( self, item: object ) -> bool:
|
||||
if isinstance( item, str ):
|
||||
for elem in self.variants:
|
||||
if elem.name == item:
|
||||
return True
|
||||
return False
|
||||
return item in self.variants
|
||||
|
||||
def __getitem__( self, item: int | str ) -> Emote:
|
||||
if isinstance( item, int ):
|
||||
return self.variants[ item ]
|
||||
|
||||
if isinstance( item, str ):
|
||||
for elem in self.variants:
|
||||
if elem.name == item:
|
||||
return elem
|
||||
raise KeyError( f'A variant with name "{item}" does not exist' )
|
||||
|
||||
raise ValueError( f'Invalid __getitem__ input: {item}' )
|
||||
|
||||
def __len__( self ) -> int:
|
||||
return len( self.variants )
|
||||
|
||||
def __repr__( self ) -> str:
|
||||
return f'VariantList{{name={self.name}, variants={repr(self.variants)}}}'
|
@ -0,0 +1,41 @@
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from cairosvg.surface import Surface
|
||||
|
||||
|
||||
from data.variantList import VariantList
|
||||
|
||||
|
||||
class Generator:
|
||||
declarations: dict[ str, VariantList ]
|
||||
surfaces: dict[ str, Surface ]
|
||||
|
||||
def __init__( self, declFile: Path ) -> None:
|
||||
if not declFile.exists():
|
||||
raise FileNotFoundError('Declaration file does not exist!')
|
||||
|
||||
self.recursiveLoad( declFile )
|
||||
|
||||
def recursiveLoad( self, declFile: Path ) -> None:
|
||||
variants = VariantList( **yaml.load( declFile.read_text(), yaml.FullLoader ) )
|
||||
self.declarations[ variants.name ] = variants
|
||||
|
||||
if variants.basedOff is not None:
|
||||
self.recursiveLoad( declFile.parent / f'{variants.basedOff}.yml' )
|
||||
|
||||
def generate( self, outputDir: Path = Path('.') ) -> None:
|
||||
"""
|
||||
Generates the images in the given folder
|
||||
\t
|
||||
:param outputDir: output directory
|
||||
"""
|
||||
if not outputDir.exists():
|
||||
outputDir.mkdir()
|
||||
|
||||
for variant in self.variants:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Generator( Path('./resources/blobfox.yml') ).generate( Path('./run') )
|
Loading…
Reference in new issue