mirror of
https://github.com/sjpiper145/MakerSkillTree.git
synced 2025-10-16 11:52:50 +02:00
✨Create skill tree from yaml
Added a rough python script that reads from a yaml file (see input.yml example) and creates a svg skill tree.
This commit is contained in:
parent
e9888c085d
commit
e70562051b
3 changed files with 1029 additions and 0 deletions
67
python/create_skill_tree_svg.py
Executable file
67
python/create_skill_tree_svg.py
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
#!/bin/env python
|
||||
import argparse
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def load_yaml(file_path):
|
||||
with open(file_path) as file:
|
||||
return yaml.safe_load(file)
|
||||
|
||||
|
||||
def load_svg_template(file_path):
|
||||
with open(file_path) as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def process_svg(template, data):
|
||||
# Replace title and author
|
||||
processed = template.replace("{{ title }}", data["title"])
|
||||
processed = processed.replace("{{ author }}", data["author"])
|
||||
|
||||
displacement = (0, 9, 19, 29, 39, 49, 59, 69)
|
||||
for i in range(10):
|
||||
for j in range(7):
|
||||
if i < 9:
|
||||
box_number = i + displacement[j]
|
||||
elif i == 9:
|
||||
box_number = i + displacement[j + 1]
|
||||
if j >= 5:
|
||||
continue
|
||||
value = data["row"][i][j]
|
||||
placeholder = f"{{{{ box_{box_number:03d} }}}}"
|
||||
processed = processed.replace(placeholder, str(value))
|
||||
|
||||
return processed
|
||||
|
||||
|
||||
def save_processed_svg(content, output_path):
|
||||
with open(output_path, "w") as file:
|
||||
file.write(content)
|
||||
|
||||
|
||||
def main():
|
||||
svg_template_path = "skill_tree_template.svg.j2"
|
||||
|
||||
parser = argparse.ArgumentParser(description="Process SVG template with YAML data.")
|
||||
parser.add_argument("input_yaml", help="Path to input YAML file")
|
||||
parser.add_argument("output_svg", help="Path to output processed SVG file")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Load YAML data
|
||||
yaml_data = load_yaml(args.input_yaml)
|
||||
|
||||
# Load SVG template
|
||||
svg_template = load_svg_template(svg_template_path)
|
||||
|
||||
# Process SVG
|
||||
processed_svg = process_svg(svg_template, yaml_data)
|
||||
|
||||
# Save processed SVG
|
||||
save_processed_svg(processed_svg, args.output_svg)
|
||||
|
||||
print(f"Processed SVG saved to {args.output_svg}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue