Skip to content

Commit

Permalink
rel 2024.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Sep 12, 2024
1 parent 454fa88 commit 4c6b55d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 80 deletions.
24 changes: 12 additions & 12 deletions documentation/reference/nxtheme_creator/process_themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

[Show source in process_themes.py:101](../../../nxtheme_creator/process_themes.py#L101)

Process images from the specified input directory to generate Nintendo Switch themes. This
function handles the following tasks:
1. Walks through the input directory to collect images and associate them with themes.
2. Resolves and validates configuration paths for layout files.
3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
executable.
Process images from the specified input directory to generate Nintendo Switch themes. This
function handles the following tasks:
1. Walks through the input directory to collect images and associate them with themes.
2. Resolves and validates configuration paths for layout files.
3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
executable.

#### Arguments

Expand Down Expand Up @@ -53,10 +53,10 @@ If the files are still not found, it tries to append `.json` to the filenames an

#### Arguments

- `nxthemebin` *str* - The path to the `nxtheme` executable, used to locate the default
`Layouts` directory.
- `conf` *dict* - A dictionary containing layout configuration. The keys should be screen types
(e.g., 'home', 'lock') and the values should be file paths or filenames.
- `nxthemebin` *str* - The path to the `nxtheme` executable, used to locate the default
`Layouts` directory.
- `conf` *dict* - A dictionary containing layout configuration. The keys should be screen types
(e.g., 'home', 'lock') and the values should be file paths or filenames.

#### Returns

Expand Down Expand Up @@ -87,8 +87,8 @@ theme names and corresponding images for each component.
Type: *dict*
the final theme_image_map

**Example**:
Given the following directory structure:
**Example**:
Given the following directory structure:

```
input_directory/
Expand Down
137 changes: 70 additions & 67 deletions nxtheme_creator/process_themes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Underlying machineary to generate custom themes for your Nintendo Switch from your images. """
"""Underlying machineary to generate custom themes for your Nintendo Switch from your images."""

import os
import re
Expand All @@ -10,38 +10,38 @@

def walkfiletree(inputdir: str) -> dict:
"""Create a theme_image_map from an input directory by walking the dir and getting
theme names and corresponding images for each component.
:param str inputdir: the directory to walk
:return dict: the final theme_image_map
**Example**:
Given the following directory structure:
```
input_directory/
├── ThemeA/
│ ├── home.jpg
│ ├── lock.jpg
│ └── apps,news.jpg
└── ThemeB/
├── home.dds
└── lock.dds
```
Calling `walkfiletree("input_directory")` would produce:
```json
{
"ThemeA": {
"home": "/path/to/input_directory/ThemeA/home.jpg",
"lock": "/path/to/input_directory/ThemeA/lock.jpg",
"apps": "/path/to/input_directory/ThemeA/apps,news.jpg",
"news": "/path/to/input_directory/ThemeA/apps,news.jpg"
},
"ThemeB": {
"home": "/path/to/input_directory/ThemeB/home.dds",
"lock": "/path/to/input_directory/ThemeB/lock.dds"
}
}
```
theme names and corresponding images for each component.
:param str inputdir: the directory to walk
:return dict: the final theme_image_map
**Example**:
Given the following directory structure:
```
input_directory/
├── ThemeA/
│ ├── home.jpg
│ ├── lock.jpg
│ └── apps,news.jpg
└── ThemeB/
├── home.dds
└── lock.dds
```
Calling `walkfiletree("input_directory")` would produce:
```json
{
"ThemeA": {
"home": "/path/to/input_directory/ThemeA/home.jpg",
"lock": "/path/to/input_directory/ThemeA/lock.jpg",
"apps": "/path/to/input_directory/ThemeA/apps,news.jpg",
"news": "/path/to/input_directory/ThemeA/apps,news.jpg"
},
"ThemeB": {
"home": "/path/to/input_directory/ThemeB/home.dds",
"lock": "/path/to/input_directory/ThemeB/lock.dds"
}
}
```
"""
theme_image_map = {}

Expand All @@ -68,17 +68,17 @@ def walkfiletree(inputdir: str) -> dict:

def resolveConf(nxthemebin: str, conf: dict) -> dict:
"""
Resolve the file paths for layout configurations specified in the `conf` dictionary.
This function checks if the specified layout files exist. If they do not, it attempts
to find the files in a default `Layouts` directory relative to the `nxthemebin` executable.
If the files are still not found, it tries to append `.json` to the filenames and checks again.
Resolve the file paths for layout configurations specified in the `conf` dictionary.
This function checks if the specified layout files exist. If they do not, it attempts
to find the files in a default `Layouts` directory relative to the `nxthemebin` executable.
If the files are still not found, it tries to append `.json` to the filenames and checks again.
:param str nxthemebin: The path to the `nxtheme` executable, used to locate the default
`Layouts` directory.
:param dict conf: A dictionary containing layout configuration. The keys should be screen types
(e.g., 'home', 'lock') and the values should be file paths or filenames.
:param str nxthemebin: The path to the `nxtheme` executable, used to locate the default
`Layouts` directory.
:param dict conf: A dictionary containing layout configuration. The keys should be screen types
(e.g., 'home', 'lock') and the values should be file paths or filenames.
:return dict: The updated `conf` dictionary with resolved file paths.
:return dict: The updated `conf` dictionary with resolved file paths.
"""
for screen_type in SCREEN_TYPES:
fname = conf.get(screen_type)
Expand All @@ -94,26 +94,26 @@ def resolveConf(nxthemebin: str, conf: dict) -> dict:
if not layout.exists():
msg = f"{conf[screen_type]} or {layout} does not exist :("
raise RuntimeError(msg)
conf[screen_type] = layout
conf[screen_type] = str(layout)
return conf


def processImages(nxthemebin: str, inputdir: str, outputdir: str, config: dict) -> None:
"""
Process images from the specified input directory to generate Nintendo Switch themes. This
function handles the following tasks:
1. Walks through the input directory to collect images and associate them with themes.
2. Resolves and validates configuration paths for layout files.
3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
executable.
:param str nxthemebin: The path to the `nxtheme` executable used for building themes.
:param str inputdir: The directory containing the input images for the themes.
:param str outputdir: The directory where the generated theme files will be saved.
:param dict config: A dictionary containing configuration options such as the author name,
and paths to layout files.
:return: None
Process images from the specified input directory to generate Nintendo Switch themes. This
function handles the following tasks:
1. Walks through the input directory to collect images and associate them with themes.
2. Resolves and validates configuration paths for layout files.
3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
executable.
:param str nxthemebin: The path to the `nxtheme` executable used for building themes.
:param str inputdir: The directory containing the input images for the themes.
:param str outputdir: The directory where the generated theme files will be saved.
:param dict config: A dictionary containing configuration options such as the author name,
and paths to layout files.
:return: None
"""
themeimgmap = walkfiletree(inputdir=inputdir)
config = resolveConf(nxthemebin, conf=config)
Expand All @@ -125,16 +125,19 @@ def processImages(nxthemebin: str, inputdir: str, outputdir: str, config: dict)
for component_name, image_path in theme.items():
name = f"{theme_name}_{component_name}"
(Path(outputdir) / theme_name).mkdir(exist_ok=True, parents=True)
cmd = [
nxthemebin,
"buildNX",
component_name,
image_path,
config.get(component_name) or "",
f"name={name}",
f"author={author_name}",
f"out={outputdir}/{theme_name}/{name}.nxtheme",
]
if os.name != "nt": # Not Windows, so run with mono
cmd = ["mono"] + cmd
subprocess.run(
[
nxthemebin,
"buildNX",
component_name,
image_path,
config.get(component_name) or "",
f"name={name}",
f"author={author_name}",
f"out={outputdir}/{theme_name}/{name}.nxtheme",
],
cmd,
check=False,
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nxtheme_creator"
version = "2024"
version = "2024.0.1"
license = "mit"
description = ""
authors = ["FredHappyface"]
Expand Down

0 comments on commit 4c6b55d

Please sign in to comment.