Commit 11e140ff authored by Nathan Lovato's avatar Nathan Lovato Committed by Dmitry Kazakov

Batch exporter add-on: update export code for Krita 4.3

parent 06450d56
import os
import json
from pathlib import Path
class COAToolsFormat:
......@@ -30,7 +30,6 @@ class COAToolsFormat:
COA Tools need to import the files
"""
# For each top-level node (Group Layer)
cfg = self.cfg
export_dir = output_dir
for wn in self.nodes:
children = wn.children
......@@ -52,7 +51,7 @@ class COAToolsFormat:
fn, sheet_meta = child.saveCOASpriteSheet(export_dir)
else:
fn = child.saveCOA(export_dir)
path = Path(fn)
node = child.node
coords = node.bounds().getCoords()
relative_coords = coords
......@@ -77,9 +76,7 @@ class COAToolsFormat:
"opacity": self.remap(node.opacity(), 0, 255, 0, 1),
"pivot_offset": [0.0, 0.0],
"position": relative_coords,
"resource_path": fn.replace(
export_dir + os.path.sep + cfg["outDir"] + os.path.sep, ""
),
"resource_path": str(path.relative_to(Path(export_dir))),
"rotation": 0.0,
"scale": [1.0, 1.0],
"tiles_x": tiles_x,
......@@ -88,12 +85,8 @@ class COAToolsFormat:
"z": idx - len(children) + 1,
}
coa_data["nodes"].append(coa_entry)
json_data = json.dumps(coa_data, sort_keys=True, indent=4, separators=(",", ": "))
with open(
export_dir + os.path.sep + cfg["outDir"] + os.path.sep + wn.name + ".json", "w"
) as fh:
fh.write(json_data)
Path(export_dir, wn.name + ".json").write_text(json_data)
except ValueError as e:
self.showError(e)
......@@ -4,7 +4,7 @@ from collections import OrderedDict
CONFIG = {
"outDir": "export",
"rootPat": r"^root",
"rootPat": "root",
"sym": r"[^a-zA-Z0-9_-]",
"error": {"msg": "ERROR: {}", "timeout": 8000},
"done": {"msg": "DONE: {}", "timeout": 5000},
......
import os
import re
from pathlib import Path
from ..Config import CONFIG
def exportPath(cfg, path, dirname=""):
return os.path.join(dirname, subRoot(cfg, path))
return dirname / subRoot(cfg, path)
def subRoot(cfg, path):
patF, patR = cfg["rootPat"], CONFIG["outDir"]
return re.sub(patF, patR, path, count=1)
original = Path(path)
rootless = (
original.relateive_to(patF)
if original.parents and original.parents[0] == patF
else original
)
return patR / rootless
_sanitizer_re = re.compile(CONFIG["sym"])
def sanitize(path):
ps = path.split(os.path.sep)
ps = map(lambda p: re.sub(CONFIG["sym"], "_", p), ps)
ps = os.path.sep.join(ps)
return ps
ps = map(lambda p: _sanitizer_re.sub("_", p), Path(path).parts)
return str(Path(*ps))
[tool.black]
line-length=100
include = '\.py$'
exclude = '''
/(
\.git
| Dependencies
)/
'''
\ No newline at end of file
exclude = '/(\.git)/'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment