Skip to content

Commit 99e2a19

Browse files
misodeEpyonProjects
authored andcommitted
Try to fix backwards plugin
1 parent 48bef70 commit 99e2a19

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

gm4/plugins/backwards.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
from typing import Any, Tuple, Callable
33
from beet import Context, Pack, NamespaceFile, ItemModel
4-
from beet.core.utils import SupportedFormats
54

65
logger = logging.getLogger("gm4.backwards")
76

@@ -55,8 +54,7 @@ def backport(pack: Pack[Any], format: int, run: Callable[[str, NamespaceFile], N
5554
resources[(file_type, path)] = proxy[path]
5655

5756
for overlay in pack.overlays.values():
58-
overlay_formats = overlay.supported_formats or overlay.pack_format
59-
if check_formats(overlay_formats, format):
57+
if check_formats(overlay, format):
6058
for file_type in overlay.resolve_scope_map().values():
6159
proxy = overlay[file_type]
6260
for path in proxy.keys():
@@ -74,13 +72,23 @@ def backport(pack: Pack[Any], format: int, run: Callable[[str, NamespaceFile], N
7472
overlay[path] = new_resource
7573

7674

77-
def check_formats(supported: SupportedFormats, format: int):
78-
match supported:
79-
case int(value):
80-
return value == format
81-
case [min, max]:
82-
return min <= format <= max
83-
case { "min_inclusive": min, "max_inclusive": max }:
84-
return min <= format <= max
85-
case _:
86-
raise ValueError(f"Unknown supported_formats structure {supported}")
75+
def check_formats(overlay: Pack[Any], format: int):
76+
if overlay.min_format and overlay.max_format:
77+
return get_major(overlay.min_format) <= format <= get_major(overlay.max_format)
78+
if overlay.supported_formats:
79+
match overlay.supported_formats:
80+
case int(value):
81+
return value == format
82+
case [min, max]:
83+
return min <= format <= max
84+
case { "min_inclusive": min, "max_inclusive": max }:
85+
return min <= format <= max
86+
case _:
87+
raise ValueError(f"Unknown supported_formats structure {overlay.supported_formats}")
88+
if overlay.pack_format:
89+
return overlay.pack_format == format
90+
return False
91+
92+
93+
def get_major(format: int | tuple[int] | tuple[int, int]):
94+
return format if isinstance(format, int) else format[0]

0 commit comments

Comments
 (0)