コード例 #1
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_empty_with_image():
    pack = ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue")))
    assert pack
    assert pack == ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue")))
    assert pack != ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="red")))
    assert pack != ResourcePack(image=PngFile(Image.new("RGB", (16, 16), color="blue")))
    assert dict(pack) == {}
コード例 #2
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_mcmeta_properties():
    pack = ResourcePack()
    pack.description = "Something"
    pack.pack_format = 1

    assert pack.mcmeta.content == {
        "pack": {"description": "Something", "pack_format": 1}
    }
コード例 #3
0
def test_vanilla_shaders(snapshot: Any, minecraft_resource_pack: Path):
    pack = ResourcePack(path=minecraft_resource_pack)
    assert snapshot("json") == pack.shader_posts["minecraft:spider"].data
    assert snapshot(
        "json") == pack.shader_programs["minecraft:entity_outline"].data
    assert snapshot() == pack.fragment_shaders["minecraft:wobble"].text
    assert snapshot() == pack.vertex_shaders["minecraft:sobel"].text
コード例 #4
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_texture(snapshot: Any):
    image = Image.new("RGB", (64, 64))
    d = ImageDraw.Draw(image)
    d.text((10, 10), "hello", fill="white")

    pack = ResourcePack("custom")
    pack["custom:hello"] = Texture(image)

    assert snapshot("resource_pack") == pack
コード例 #5
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_texture_mcmeta(snapshot: Any):
    image = Image.new("RGB", (64, 128))
    d = ImageDraw.Draw(image)
    d.text((10, 10), "hello", fill="white")
    d.text((10, 74), "world", fill="white")

    pack = ResourcePack("custom")
    pack["custom:hello"] = Texture(image, mcmeta={"animation": {"frametime": 20}})

    assert snapshot("resource_pack") == pack
コード例 #6
0
def test_empty():
    assert Document() == Document()
    assert Document().data == DataPack()
    assert Document().assets == ResourcePack()
    assert Document().get_text() == ""
    empty = "# Lectern snapshot\n\nThe data pack and resource pack are empty.\n"
    assert Document().get_markdown() == empty
    assert Document().get_markdown(emit_external_files=True) == (empty, {})
    assert Document(text="Nothing to see here") == Document()
    assert Document(markdown="Nothing to see here") == Document()
コード例 #7
0
ファイル: item_models.py プロジェクト: OrangeUtan/Hats
def item_models(ctx: Context, opts: HatsOptions):
    """Create item models used for custom model data"""

    assets = ResourcePack()

    registry = HatRegistry.get(opts.cmd_id)

    overrides = []
    for category, hats in registry.categories.items():
        overrides += [ModelOverride(hat.cmd, hat.model_path(category)) for hat in hats]
    overrides = sorted(overrides, key=lambda o: o.cmd)

    item_head_name = opts.default_item_head.split(":")[1]
    item_inventory_name = opts.default_item_inventory.split(":")[1]

    assets.models[f"minecraft:item/{item_head_name}"] = Model(
        ctx.template.render(f"models/{item_head_name}.json", overrides=overrides)
    )
    assets.models[f"minecraft:item/{item_inventory_name}"] = Model(
        ctx.template.render(f"models/{item_inventory_name}.json", overrides=overrides)
    )

    return assets
コード例 #8
0
    def apply_directives(
        self,
        directives: Mapping[str, Directive],
        fragments: Iterable[Fragment],
        loaders: Iterable[FragmentLoader] = (),
    ) -> Tuple[ResourcePack, DataPack]:
        """Apply directives into a blank data pack and a blank resource pack."""
        assets, data = ResourcePack(), DataPack()

        for fragment in fragments:
            for loader in loaders:
                fragment = loader(fragment, directives)
                if not fragment:
                    break
            if fragment:
                directives[fragment.directive](fragment, assets, data)

        return assets, data
コード例 #9
0
ファイル: directive.py プロジェクト: mcbeet/lectern
    def __init__(
        self,
        assets: Optional[ResourcePack] = None,
        data: Optional[DataPack] = None,
    ):
        super().__init__()
        self.resolvers = []
        self.assets = assets or ResourcePack()
        self.data = data or DataPack()

        self["data_pack"] = DataPackDirective()
        self["resource_pack"] = ResourcePackDirective()
        self["skip"] = SkipDirective()

        @self.add_resolver
        def _(self: DirectiveRegistry):
            for pack in [self.assets, self.data]:
                for file_type in pack.resolve_scope_map().values():
                    name = snake_case(file_type.__name__)
                    self[name] = NamespacedResourceDirective(file_type)
コード例 #10
0
def test_sounds():
    pack = ResourcePack()
    pack["minecraft:block/note_block/banjo_1"] = Sound(
        b"abc", event="block.note_block.banjo", subtitle="foo"
    )
    pack["minecraft:block/note_block/banjo_2"] = Sound(
        b"123", event="block.note_block.banjo", weight=2, pitch=1.1
    )

    config = {
        "block.note_block.banjo": {
            "sounds": [
                "block/note_block/banjo_1",
                {"name": "block/note_block/banjo_2", "weight": 2, "pitch": 1.1},
            ],
            "subtitle": "foo",
        }
    }

    assert pack["minecraft"].sound_config == SoundConfig(config)
コード例 #11
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_merge(snapshot: Any):
    p1 = ResourcePack("p1")
    p1["custom:red"] = Texture(Image.new("RGB", (32, 32), color="red"))

    p2 = ResourcePack("p2")
    p2["custom:green"] = Texture(Image.new("RGB", (32, 32), color="green"))

    blink = Image.new("RGB", (32, 64), color="blue")
    d = ImageDraw.Draw(blink)
    d.rectangle([0, 32, 32, 64], fill="white")

    p3 = ResourcePack("p3")
    p3["other:blue"] = Texture(blink, mcmeta={"animation": {"frametime": 20}})

    p1.merge(p2)
    p1.merge(p3)

    assert snapshot("resource_pack") == p1
コード例 #12
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
import pytest
from PIL import Image, ImageDraw

from beet import JsonFile, PngFile, ResourcePack, Texture


def test_default():
    assert ResourcePack() == ResourcePack()
    assert not ResourcePack()


@pytest.mark.parametrize(  # type: ignore
    "pack",
    [
        ResourcePack("p1"),
        ResourcePack("p2", mcmeta=JsonFile({"pack": {"description": "world"}})),
        ResourcePack(
            "p3", mcmeta=JsonFile({"pack": {"description": "world", "pack_format": 42}})
        ),
    ],
)
def test_empty(snapshot: Any, pack: ResourcePack):
    assert snapshot("resource_pack") == pack
    assert not pack
    assert dict(pack) == {}


def test_empty_with_image():
    pack = ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue")))
    assert pack
コード例 #13
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_default():
    assert ResourcePack() == ResourcePack()
    assert not ResourcePack()
コード例 #14
0
ファイル: directive.py プロジェクト: mcbeet/lectern
 def __call__(self, fragment: Fragment, assets: ResourcePack,
              data: DataPack):
     assets.load(self.bundle_pack_fragment(fragment))
コード例 #15
0
def test_vanilla_particles(snapshot: SnapshotFixture, minecraft_resource_pack: Path):
    pack = ResourcePack(path=minecraft_resource_pack)
    assert snapshot("json") == pack.particles["minecraft:end_rod"].data
コード例 #16
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_empty_namespaces():
    pack = ResourcePack()

    assert not pack
    assert not pack["hello"]
    assert not pack["world"]
コード例 #17
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_vanilla_zip(minecraft_resource_pack: Path, tmp_path: Path):
    pack = ResourcePack(path=minecraft_resource_pack)
    zipped_pack = pack.save(tmp_path, zipped=True)
    assert ResourcePack(path=zipped_pack) == ResourcePack(path=zipped_pack)
コード例 #18
0
ファイル: test_resource_pack.py プロジェクト: OrangeUtan/beet
def test_vanilla_compare(minecraft_resource_pack: Path):
    assert ResourcePack(path=minecraft_resource_pack) == ResourcePack(
        path=minecraft_resource_pack
    )
コード例 #19
0
ファイル: pytest_plugin.py プロジェクト: mcbeet/beet
 def load(self, path: Path) -> ResourcePack:
     return ignore_name(ResourcePack(path=path))
コード例 #20
0
ファイル: conftest.py プロジェクト: misode/beet
 def dump(self, path: Path, value: ResourcePack):
     value.save(path, overwrite=True)
コード例 #21
0
ファイル: conftest.py プロジェクト: misode/beet
 def load(self, path: Path) -> ResourcePack:
     return ResourcePack(path=next(path.iterdir()))
コード例 #22
0
def test_resource_pack():
    pack = ResourcePack()
    doc = Document(assets=pack)
    assert doc.assets is pack