Skip to content

Commit

Permalink
Merge pull request #1563 from heinezen/fix/asset-path-union
Browse files Browse the repository at this point in the history
Always handle asset path as `UnionPath`
  • Loading branch information
TheJJ authored Oct 8, 2023
2 parents 688255c + 2ea6e0e commit 01c1cf7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
14 changes: 8 additions & 6 deletions openage/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from . import default_dirs

if typing.TYPE_CHECKING:
from openage.util.fslike.directory import Directory
from openage.util.fslike.union import UnionPath


def get_asset_path(custom_asset_dir: str = None) -> Directory:
def get_asset_path(custom_asset_dir: str = None) -> UnionPath:
"""
Returns a Path object for the game assets.
Expand All @@ -33,13 +33,15 @@ def get_asset_path(custom_asset_dir: str = None) -> Directory:
the game as its data source(s).
"""

# mount the possible locations in an union:
result = Union().root

# if we're in devmode, use only the in-repo asset folder
if not custom_asset_dir and config.DEVMODE:
return Directory(os.path.join(config.BUILD_SRC_DIR, "assets")).root
result.mount(Directory(os.path.join(config.BUILD_SRC_DIR, "assets")).root)
return result

# else, mount the possible locations in an union:
# overlay the global dir and the user dir.
result = Union().root
# else overlay the global dir and the user dir.

# the cmake-determined folder for storing assets
global_data = Path(config.GLOBAL_ASSET_DIR)
Expand Down
3 changes: 2 additions & 1 deletion openage/convert/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
if typing.TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
from openage.util.fslike.directory import Directory
from openage.util.fslike.union import UnionPath
from openage.util.fslike.path import Path


def convert_assets(
assets: Directory,
assets: UnionPath,
args: Namespace,
srcdir: Directory = None
) -> None:
Expand Down
8 changes: 6 additions & 2 deletions openage/convert/service/init/api_export_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
from .modpack_search import get_modpack_info

if typing.TYPE_CHECKING:
from openage.util.fslike.directory import Directory
from openage.util.fslike.union import UnionPath


CURRENT_API_VERSION = "0.4.0"


def api_export_required(asset_dir: Directory) -> bool:
def api_export_required(asset_dir: UnionPath) -> bool:
"""
Returns true if the openage nyan API modpack cannot be found.
TODO: Remove once the API modpack is generated by default.
:param asset_dir: The asset directory to search in.
:type asset_dir: UnionPath
:returns: True if the openage nyan API modpack cannot be found, else False.
"""
modpack_dir = asset_dir / "converted" / "engine"

Expand Down
6 changes: 3 additions & 3 deletions openage/convert/service/init/conversion_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from .modpack_search import enumerate_modpacks

if typing.TYPE_CHECKING:
from openage.util.fslike.directory import Directory
from openage.util.fslike.union import UnionPath


def conversion_required(asset_dir: Directory) -> bool:
def conversion_required(asset_dir: UnionPath) -> bool:
"""
Check if an asset conversion is required to run the game.
Expand All @@ -24,7 +24,7 @@ def conversion_required(asset_dir: Directory) -> bool:
- the converted assets are outdated
:param asset_dir: The asset directory to check.
:type asset_dir: Directory
:type asset_dir: UnionPath
:return: True if an asset conversion is required, else False.
"""
try:
Expand Down
14 changes: 7 additions & 7 deletions openage/convert/service/init/modpack_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from ....log import info, dbg

if typing.TYPE_CHECKING:
from openage.util.fslike.directory import Directory
from openage.util.fslike.union import UnionPath


def enumerate_modpacks(modpacks_dir: Directory) -> set[str]:
def enumerate_modpacks(modpacks_dir: UnionPath) -> set[str]:
"""
Enumerate openage modpacks in a directory.
:param asset_dir: The asset directory to search in.
:type asset_dir: Directory
:type asset_dir: UnionPath
:returns: A list of modpack names that were found.
:rtype: set[str]
"""
Expand All @@ -42,12 +42,12 @@ def enumerate_modpacks(modpacks_dir: Directory) -> set[str]:
return modpacks


def get_modpack_info(modpack_dir: Directory) -> dict[str, typing.Any]:
def get_modpack_info(modpack_dir: UnionPath) -> dict[str, typing.Any]:
"""
Get information about an openage modpack from its definition file.
:param modpack_dir: Modpack root directory.
:type modpack_dir: Directory
:type modpack_dir: UnionPath
:returns: Modpack information.
:rtype: dict[str, typing.Any]
Expand All @@ -56,7 +56,7 @@ def get_modpack_info(modpack_dir: Directory) -> dict[str, typing.Any]:
:raises toml.TomlDecodeError: If the modpack definition file is malformed.
"""
if not modpack_dir.exists():
info("Modpack directory %s not found", modpack_dir.root.name)
info("Modpack directory %s not found", modpack_dir.name)
raise FileNotFoundError("Modpack directory not found")

modpack_def = modpack_dir / "modpack.toml"
Expand All @@ -68,7 +68,7 @@ def get_modpack_info(modpack_dir: Directory) -> dict[str, typing.Any]:
return content

except FileNotFoundError as err:
dbg("Modpack definition file not found; ncould not find %s", modpack_def)
dbg("Modpack definition file not found; could not find %s", modpack_def)
raise err

except TypeError as err:
Expand Down

0 comments on commit 01c1cf7

Please sign in to comment.