Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Create skill tree from yaml #22

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions python/create_skill_tree_svg.py
Original file line number Diff line number Diff line change
@@ -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()
82 changes: 82 additions & 0 deletions python/input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: Some Interesting Title
author: John Doe
row:
0:
- 0a
- 0b
- 0c
- 0d
- 0e
- 0f
- 0g
1:
- 1a
- 1b
- 1c
- 1d
- 1e
- 1f
- 1g
2:
- 2a
- 2b
- 2c
- 2d
- 2e
- 2f
- 2g
3:
- 3a
- 3b
- 3c
- 3d
- 3e
- 3f
- 3g
4:
- 4a
- 4b
- 4c
- 4d
- 4e
- 4f
- 4g
5:
- 5a
- 5b
- 5c
- 5d
- 5e
- 5f
- 5g
6:
- 6a
- 6b
- 6c
- 6d
- 6e
- 6f
- 6g
7:
- 7a
- 7b
- 7c
- 7d
- 7e
- 7f
- 7g
8:
- 8a
- 8b
- 8c
- 8d
- 8e
- 8f
- 8g
9:
- 9a
- 9b
- 9c
- 9d
- 9e
Loading