Skip to content

Commit

Permalink
feat: add atlases support for mc 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RitikShah authored and vberlier committed Feb 1, 2023
1 parent d3282d6 commit f1f0443
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions beet/library/resource_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from copy import deepcopy
from dataclasses import dataclass
from typing import Any, ClassVar, Dict, Optional, Tuple, Type
from contextlib import suppress

try:
from PIL.Image import Image
Expand Down Expand Up @@ -260,6 +261,53 @@ class Particle(JsonFile):
extension: ClassVar[str] = ".json"


class Atlas(JsonFile):
"""Class representing an atlas configuration file."""

scope: ClassVar[Tuple[str, ...]] = ("atlases",)
extension: ClassVar[str] = ".json"

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

for value in other.data.get("sources", []):
if value not in values:
values.append(deepcopy(value))
return True

def append(self, other: "Atlas"):
"""Append values from another atlas."""

self.merge(other)

def prepend(self, other: "Atlas"):
"""Prepend values from another atlas."""

values = self.data.setdefault("sources", [])

for value in other.data.get("sources", []):
if value not in values:
values.insert(0, deepcopy(value))

def add(self, value: str):
"""Add an entry."""

values = self.data.setdefault("sources", [])
if value not in values:
values.append(value)

def remove(self, value: str):
"""Remove an entry."""

values = self.data.setdefault("sources", [])
with suppress(ValueError):
values.remove(value)

@classmethod
def default(cls) -> JsonDict:
return {"sources": []}


class ResourcePackNamespace(Namespace):
"""Class representing a resource pack namespace."""

Expand Down

0 comments on commit f1f0443

Please sign in to comment.