Skip to content

Commit

Permalink
Run ruff formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
HappiePlant committed Aug 24, 2024
1 parent 16e5fab commit 30b64ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/minecraft_seven/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@

MINECRAFT_VERSION = "1.21"


def get_jar_path() -> str:
parser = argparse.ArgumentParser(description="Minecraft Seven Font Builder")
parser.add_argument("jar_path", nargs="?", default=None)
parser.add_argument("jar_path", nargs="?", default=None)
args = parser.parse_args()

if args.jar_path is not None:
jar_path: str = os.path.abspath(args.jar_path)
else:
jar_path = open_file(title="Select the 1.21 jar file", filetypes=[("JAR file", "*.jar")], multiple=False)
jar_path = open_file(
title="Select the 1.21 jar file",
filetypes=[("JAR file", "*.jar")],
multiple=False,
)
if jar_path == "":
raise ValueError("Something went wrong picking the jar file")

return jar_path


def check_minecraft_version(jar_path: str):
with ZipFile(jar_path, "r") as jar:
version_data = json.loads(jar.read("version.json"))
version = version_data['id']
version = version_data["id"]
if version != MINECRAFT_VERSION:
raise Exception("Minecraft version does not match")

Expand All @@ -34,8 +40,8 @@ def main() -> None:
check_minecraft_version(jar_path)
build_as_pixel_font_converter_batch(jar_path, MINECRAFT_VERSION)


return

if __name__ == '__main__':
main()

if __name__ == "__main__":
main()
37 changes: 26 additions & 11 deletions src/minecraft_seven/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ class Provider:
baseline: int
chars: list[str]


def get_assets(jar_path: str, tile_data: dict) -> (list[Provider], int):
with ZipFile(jar_path, 'r') as jar:
default_data: dict = json.loads(jar.read("assets/minecraft/font/include/default.json"))
space_data: dict = json.loads(jar.read("assets/minecraft/font/include/space.json"))
with ZipFile(jar_path, "r") as jar:
default_data: dict = json.loads(
jar.read("assets/minecraft/font/include/default.json")
)
space_data: dict = json.loads(
jar.read("assets/minecraft/font/include/space.json")
)
space_width = space_data["providers"][0]["advances"][" "]
providers: list[dict] = default_data["providers"]
new_providers: list[Provider] = []
for provider in providers:

new_provider: Provider = Provider()
texture_id: str = provider["file"]
new_provider.id = texture_id
texture_name = texture_id.replace("minecraft:", "assets/minecraft/textures/")
texture_name = texture_id.replace(
"minecraft:", "assets/minecraft/textures/"
)
new_provider.file = jar.read(texture_name)

provider_tile_data = tile_data["providers"][texture_id]
Expand All @@ -39,6 +45,7 @@ def get_assets(jar_path: str, tile_data: dict) -> (list[Provider], int):

return new_providers, space_width


def load_tile_data(mc_version: str) -> dict:
filename = "resources/" + mc_version + ".toml"
with open(filename, "r") as file:
Expand All @@ -51,7 +58,10 @@ def create_space_tile(width: int, height: int, space_width: int) -> Image:
draw.rectangle((0, 0, space_width - 2, height), fill="white")
return tile

def build_tileset(tileset_data: dict, providers: list[Provider], space_width: int) -> (Image, str):

def build_tileset(
tileset_data: dict, providers: list[Provider], space_width: int
) -> (Image, str):
tile_width = tileset_data["tile_width"]
tile_height = tileset_data["tile_height"]
tile_baseline = tileset_data["tile_baseline"]
Expand All @@ -74,9 +84,13 @@ def build_tileset(tileset_data: dict, providers: list[Provider], space_width: in
if char != "\x00":
print(char)
if char != " ":
char_img = font_img.crop((font_x, font_y, font_x + char_width, font_y + char_height))
char_img = font_img.crop(
(font_x, font_y, font_x + char_width, font_y + char_height)
)
else:
char_img = create_space_tile(char_width, char_height, space_width)
char_img = create_space_tile(
char_width, char_height, space_width
)
tileset.paste(char_img, (tileset_x, tile_height_offset))
glyphs += char

Expand All @@ -85,11 +99,12 @@ def build_tileset(tileset_data: dict, providers: list[Provider], space_width: in
font_x = 0
font_y += char_height


return tileset, glyphs


def convert_to_pixel_font_converter_batch(tileset: Image, glyphs: str, tileset_data: dict):
def convert_to_pixel_font_converter_batch(
tileset: Image, glyphs: str, tileset_data: dict
):
with open("resources/pixel_font_converter_settings.json") as settings_file:
settings = json.load(settings_file)

Expand All @@ -111,4 +126,4 @@ def build_as_pixel_font_converter_batch(jar_path: str, mc_version: str):
for provider in providers:
print(provider.id)
tileset, glyphs = build_tileset(tile_data["tileset"], providers, space_width)
convert_to_pixel_font_converter_batch(tileset, glyphs, tile_data["tileset"])
convert_to_pixel_font_converter_batch(tileset, glyphs, tile_data["tileset"])

0 comments on commit 30b64ef

Please sign in to comment.