Skip to content

Commit 07b9342

Browse files
committed
Initial commit
0 parents  commit 07b9342

6 files changed

Lines changed: 178 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build Windows Executable
2+
permissions: write-all
3+
on:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
build-windows:
9+
name: Build for Windows
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Install Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: 3.11
18+
- name: Install PyInstaller and Pillow
19+
run: |
20+
pip install pyinstaller
21+
pip install pillow
22+
- name: Run PyInstaller for BDSP_ColorVariation_JSONParser
23+
run: |
24+
set PYTHONOPTIMIZE=2
25+
pyinstaller --onefile --name="BDSP_ColorVariation_JSONParser" --console --icon=images\BDSP_ColorVariation_JSONParser.tga bdsp_colorvariation_jsonparser.py
26+
- name: Move Executable from dist to root directory
27+
run: |
28+
move dist\BDSP_ColorVariation_JSONParser.exe .
29+
rd /s /q dist
30+
shell: cmd
31+
- name: Create Automatic Windows Release
32+
uses: marvinpinto/action-automatic-releases@latest
33+
with:
34+
repo_token: ${{ secrets.GITHUB_TOKEN }}
35+
automatic_release_tag: latest
36+
prerelease: false
37+
title: Latest Build
38+
files: BDSP_ColorVariation_JSONParser.exe
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build Windows Executable with Nuitka
2+
permissions: write-all
3+
on:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
build-windows:
9+
name: Build for Windows
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Install Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: 3.11
18+
- name: Install imageio
19+
run: pip install imageio
20+
- name: Run Nuitka for BDSP_ColorVariation_JSONParser
21+
uses: Nuitka/Nuitka-Action@main
22+
with:
23+
nuitka-version: main
24+
script-name: bdsp_colorvariation_jsonparser.py
25+
mode: app
26+
windows-icon-from-ico: "images/BDSP_ColorVariation_JSONParser.tga"
27+
- name: Move Executable from build to root directory
28+
run: |
29+
move build\BDSP_ColorVariation_JSONParser.exe .
30+
rd /s /q build
31+
shell: cmd
32+
- name: Create Automatic Windows Release
33+
uses: marvinpinto/action-automatic-releases@latest
34+
with:
35+
repo_token: ${{ secrets.GITHUB_TOKEN }}
36+
automatic_release_tag: latest-nuitka
37+
prerelease: false
38+
title: Latest Nuitka Build
39+
files: BDSP_ColorVariation_JSONParser.exe

.github/workflows/greetings.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Greetings
2+
3+
on: [pull_request_target, issues]
4+
5+
jobs:
6+
greeting:
7+
runs-on: windows-latest
8+
permissions:
9+
issues: write
10+
pull-requests: write
11+
steps:
12+
- uses: actions/first-interaction@v1
13+
with:
14+
repo-token: ${{ secrets.GITHUB_TOKEN }}
15+
issue-message: "Are you absolutely sure there's an issue? Might want to double check, perhaps it's a feature."
16+
pr-message: "Yes, this will cause a crash later. Too bad!"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Pokémon Brilliant Diamond/Shining Pearl ColorVariation Parser
2+
This script outputs color information from `ColorVariation.json` files originated from Pokémon BD/SP video games.
3+
4+
Multiple JSON files are supported if provided as launch arguments.

bdsp_colorvariation_jsonparser.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""
2+
Script for parsing color information from Pokémon BD/SP ColorVariation.json files.
3+
"""
4+
import os
5+
import sys
6+
import json
7+
import argparse
8+
9+
10+
def print_json_color_data(file_path: str):
11+
"""
12+
Prints out information from ColorVariation.json file originating from Pokémon BD/SP games.
13+
:param file_path: Path to JSON file.
14+
"""
15+
if not os.path.exists(file_path):
16+
print("Path does not exist.")
17+
return
18+
if not os.path.isfile(file_path):
19+
print("Path is not a file.")
20+
return
21+
if not file_path.lower().endswith(".json"):
22+
print("Path is not a JSON file.")
23+
return
24+
with open(file_path, encoding="utf-8") as json_file:
25+
json_data = json.load(json_file)
26+
k = 0
27+
s = "00"
28+
while "Property" + s in json_data:
29+
property_data = json_data["Property" + s][0]
30+
print("Property" + s + ":")
31+
colors_data = property_data["colors"]
32+
current_material_index = -1
33+
for color_data in colors_data:
34+
if color_data is not None:
35+
c = color_data["channel"]
36+
if color_data["materialIndex"] > current_material_index:
37+
current_material_index = color_data["materialIndex"]
38+
print("Material Index: " + str(current_material_index) + ".")
39+
color_dict = color_data["color"]
40+
if color_dict is not None:
41+
color_dict_str = get_color_dict_str(color_dict)
42+
print(f"[{c:d}]: {color_dict_str}.")
43+
k = k + 1
44+
if k < 10:
45+
s = "0" + str(k)
46+
else:
47+
s = str(k)
48+
49+
50+
def get_color_dict_str(color_dict: dict) -> str:
51+
"""
52+
Converts color dict to printable string.
53+
:param color_dict: Color dict (R, G, B, A).
54+
:return: String.
55+
"""
56+
r = color_dict["r"]
57+
g = color_dict["g"]
58+
b = color_dict["b"]
59+
a = color_dict["a"]
60+
lc = f"({r:.8f}, {g:.8f}, {b:.8f}, {a:.8f})"
61+
hc = format(round(float(color_dict["r"]) * 255.0), "x").upper()
62+
hc = hc + format(round(float(color_dict["g"]) * 255.0), "x").upper()
63+
hc = hc + format(round(float(color_dict["b"]) * 255.0), "x").upper()
64+
return f"{lc} -> {hc}"
65+
66+
67+
if __name__ == "__main__":
68+
parser = argparse.ArgumentParser(prog="BD/SP ColorVariation Parser",
69+
description="Parser for Pokémon BD/SP "
70+
"ColorVariation.json files.")
71+
parser.add_argument("input_paths", nargs="*", type=str, default="",
72+
help="Input JSON files")
73+
args = parser.parse_args()
74+
if len(args.input_paths) < 1:
75+
input_path = input("JSON file path: ")
76+
print_json_color_data(input_path)
77+
else:
78+
for input_path in args.input_paths:
79+
print(f"{input_path}:")
80+
print_json_color_data(input_path)
81+
sys.exit(os.EX_OK)
670 KB
Binary file not shown.

0 commit comments

Comments
 (0)