Skip to content

Commit

Permalink
feat: handle resource pack fonts and tweak docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Jan 14, 2021
1 parent 34505d9 commit 57cce73
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 32 deletions.
44 changes: 22 additions & 22 deletions beet/library/data_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@


class Advancement(JsonFile, NamespaceFile):
"""Class representing a data pack advancement."""
"""Class representing an advancement."""

scope = ("advancements",)
extension = ".json"


@dataclass(eq=False)
class Function(TextFileBase[MutableSequence[str]], NamespaceFile):
"""Class representing a data pack function."""
"""Class representing a function."""

content: TextFileContent[MutableSequence[str]] = None
tags: Optional[MutableSequence[str]] = extra_field(default=None)
Expand All @@ -84,29 +84,29 @@ def bind(self, pack: "DataPack", namespace: str, path: str):


class LootTable(JsonFile, NamespaceFile):
"""Class representing a data pack loot table."""
"""Class representing a loot table."""

scope = ("loot_tables",)
extension = ".json"


class Predicate(JsonFile, NamespaceFile):
"""Class representing a data pack predicate."""
"""Class representing a predicate."""

scope = ("predicates",)
extension = ".json"


class Recipe(JsonFile, NamespaceFile):
"""Class representing a data pack recipe."""
"""Class representing a recipe."""

scope = ("recipes",)
extension = ".json"


@dataclass(eq=False)
class Structure(BinaryFileBase[StructureFileData], NamespaceFile):
"""Class representing a data pack structure file."""
"""Class representing a structure file."""

content: BinaryFileContent[StructureFileData] = None

Expand All @@ -129,7 +129,7 @@ def to_bytes(cls, content: StructureFileData) -> bytes:


class TagFile(JsonFile, NamespaceFile):
"""Base class for data pack tag files."""
"""Base class for tag files."""

extension = ".json"

Expand All @@ -146,100 +146,100 @@ def merge(self: TagFileType, other: TagFileType) -> bool: # type: ignore


class BlockTag(TagFile):
"""Class representing a data pack block tag."""
"""Class representing a block tag."""

scope = ("tags", "blocks")


class EntityTypeTag(TagFile):
"""Class representing a data pack entity tag."""
"""Class representing an entity tag."""

scope = ("tags", "entity_types")


class FluidTag(TagFile):
"""Class representing a data pack fluid tag."""
"""Class representing a fluid tag."""

scope = ("tags", "fluids")


class FunctionTag(TagFile):
"""Class representing a data pack function tag."""
"""Class representing a function tag."""

scope = ("tags", "functions")


class ItemTag(TagFile):
"""Class representing a data pack item tag."""
"""Class representing an item tag."""

scope = ("tags", "items")


class DimensionType(JsonFile, NamespaceFile):
"""Class representing a data pack dimension type."""
"""Class representing a dimension type."""

scope = ("dimension_type",)
extension = ".json"


class Dimension(JsonFile, NamespaceFile):
"""Class representing a data pack dimension."""
"""Class representing a dimension."""

scope = ("dimension",)
extension = ".json"


class Biome(JsonFile, NamespaceFile):
"""Class representing a data pack biome."""
"""Class representing a biome."""

scope = ("worldgen", "biome")
extension = ".json"


class ConfiguredCarver(JsonFile, NamespaceFile):
"""Class representing a data pack worldgen carver."""
"""Class representing a worldgen carver."""

scope = ("worldgen", "configured_carver")
extension = ".json"


class ConfiguredFeature(JsonFile, NamespaceFile):
"""Class representing a data pack worldgen feature."""
"""Class representing a worldgen feature."""

scope = ("worldgen", "configured_feature")
extension = ".json"


class ConfiguredStructureFeature(JsonFile, NamespaceFile):
"""Class representing a data pack worldgen structure feature."""
"""Class representing a worldgen structure feature."""

scope = ("worldgen", "configured_structure_feature")
extension = ".json"


class ConfiguredSurfaceBuilder(JsonFile, NamespaceFile):
"""Class representing a data pack worldgen surface builder."""
"""Class representing a worldgen surface builder."""

scope = ("worldgen", "configured_surface_builder")
extension = ".json"


class NoiseSettings(JsonFile, NamespaceFile):
"""Class representing a data pack worldgen noise settings."""
"""Class representing worldgen noise settings."""

scope = ("worldgen", "noise_settings")
extension = ".json"


class ProcessorList(JsonFile, NamespaceFile):
"""Class representing a data pack worldgen processor list."""
"""Class representing a worldgen processor list."""

scope = ("worldgen", "processor_list")
extension = ".json"


class TemplatePool(JsonFile, NamespaceFile):
"""Class representing a data pack worldgen template pool."""
"""Class representing a worldgen template pool."""

scope = ("worldgen", "template_pool")
extension = ".json"
Expand Down
58 changes: 48 additions & 10 deletions beet/library/resource_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"ResourcePackNamespace",
"Blockstate",
"Model",
"Font",
"GlyphSizeFile",
"TrueTypeFont",
"ShaderPost",
"ShaderProgram",
"FragmentShader",
Expand All @@ -13,76 +16,105 @@
]


from copy import deepcopy
from dataclasses import dataclass
from typing import Optional

from PIL import Image as img

from beet.core.file import BinaryFileContent, JsonFile, PngFile, TextFile
from beet.core.file import BinaryFile, BinaryFileContent, JsonFile, PngFile, TextFile
from beet.core.utils import JsonDict, extra_field

from .base import Namespace, NamespaceFile, NamespacePin, NamespaceProxyDescriptor, Pack


class Blockstate(JsonFile, NamespaceFile):
"""Class representing a resource pack block state."""
"""Class representing a blockstate."""

scope = ("blockstates",)
extension = ".json"


class Model(JsonFile, NamespaceFile):
"""Class representing a resource pack model."""
"""Class representing a model."""

scope = ("models",)
extension = ".json"


class Font(JsonFile, NamespaceFile):
"""Class representing a font configuration file."""

scope = ("font",)
extension = ".json"

def merge(self, other: "Font") -> bool: # type: ignore
providers = self.data.setdefault("providers", [])

for provider in other.data.get("providers", []):
providers.append(deepcopy(provider))
return True


class GlyphSizeFile(BinaryFile, NamespaceFile):
"""Class representing a legacy unicode glyph size file."""

scope = ("font",)
extension = ".bin"


class TrueTypeFont(BinaryFile, NamespaceFile):
"""Class representing a TrueType font."""

scope = ("font",)
extension = ".ttf"


class ShaderPost(JsonFile, NamespaceFile):
"""Class representing a resource pack shader post."""
"""Class representing a shader post-processing pipeline."""

scope = ("shaders", "post")
extension = ".json"


class ShaderProgram(JsonFile, NamespaceFile):
"""Class representing a resource pack shader program."""
"""Class representing a shader program."""

scope = ("shaders", "program")
extension = ".json"


class FragmentShader(TextFile, NamespaceFile):
"""Class representing a resource pack fragment shader."""
"""Class representing a fragment shader."""

scope = ("shaders", "program")
extension = ".fsh"


class VertexShader(TextFile, NamespaceFile):
"""Class representing a resource pack vertex shader."""
"""Class representing a vertex shader."""

scope = ("shaders", "program")
extension = ".vsh"


class Text(TextFile, NamespaceFile):
"""Class representing a resource pack text file."""
"""Class representing a text file."""

scope = ("texts",)
extension = ".txt"


class TextureMcmeta(JsonFile, NamespaceFile):
"""Class representing a resource pack texture mcmeta."""
"""Class representing a texture mcmeta."""

scope = ("textures",)
extension = ".png.mcmeta"


@dataclass(eq=False)
class Texture(PngFile, NamespaceFile):
"""Class representing a resource pack texture."""
"""Class representing a texture."""

content: BinaryFileContent[img.Image] = None
mcmeta: Optional[JsonDict] = extra_field(default=None)
Expand All @@ -103,6 +135,9 @@ class ResourcePackNamespace(Namespace):
# fmt: off
blockstates = NamespacePin(Blockstate)
models = NamespacePin(Model)
fonts = NamespacePin(Font)
glyph_sizes = NamespacePin(GlyphSizeFile)
truetype_fonts = NamespacePin(TrueTypeFont)
shader_posts = NamespacePin(ShaderPost)
shader_programs = NamespacePin(ShaderProgram)
fragment_shaders = NamespacePin(FragmentShader)
Expand All @@ -122,6 +157,9 @@ class ResourcePack(Pack[ResourcePackNamespace]):
# fmt: off
blockstates = NamespaceProxyDescriptor(Blockstate)
models = NamespaceProxyDescriptor(Model)
fonts = NamespaceProxyDescriptor(Font)
glyph_sizes = NamespaceProxyDescriptor(GlyphSizeFile)
truetype_fonts = NamespaceProxyDescriptor(TrueTypeFont)
shader_posts = NamespaceProxyDescriptor(ShaderPost)
shader_programs = NamespaceProxyDescriptor(ShaderProgram)
fragment_shaders = NamespaceProxyDescriptor(FragmentShader)
Expand Down

0 comments on commit 57cce73

Please sign in to comment.