13 "Actor":
"actors_based",
14 "Actor2D":
"actor_2d_based",
15 "Scene":
"scene_based"
21 for i, c
in enumerate(name):
22 if c.isupper()
and i != 0
and not name[i-1].isupper():
29 if len(sys.argv) != 3:
30 print(
"Usage: create_class.py <Actor|Actor2D|Scene> <ClassName>")
33 base_type = sys.argv[1]
34 class_name = sys.argv[2]
36 if base_type
not in SUPPORTED_BASES:
37 print(f
"Error: Unsupported base type '{base_type}'")
38 print(
"Supported types: Actor, Actor2D, Scene")
42 script_dir = os.path.dirname(os.path.abspath(__file__))
43 project_root = os.path.abspath(os.path.join(script_dir,
".."))
44 template_dir = os.path.join(script_dir,
"Templates")
45 include_dir = os.path.join(project_root,
"Include")
46 source_dir = os.path.join(project_root,
"Source")
48 if not os.path.isdir(include_dir)
or not os.path.isdir(source_dir):
49 print(
"Error: Include/ or Source/ directory not found.")
50 print(
"Make sure you are inside a valid RenderingEngine project.")
53 template_prefix = SUPPORTED_BASES[base_type]
55 header_template = os.path.join(template_dir, template_prefix +
".hpp.in")
56 source_template = os.path.join(template_dir, template_prefix +
".cpp.in")
58 if not os.path.isfile(header_template)
or not os.path.isfile(source_template):
59 print(
"Error: Template files not found.")
64 header_output = os.path.join(include_dir, class_file_name +
".hpp")
65 source_output = os.path.join(source_dir, class_file_name +
".cpp")
67 if os.path.exists(header_output)
or os.path.exists(source_output):
68 print(
"Error: Class files already exist.")
72 with open(header_template,
"r")
as f:
73 header_content = f.read()
75 header_content = header_content.replace(
"@CLASS_NAME@", class_name)
76 header_content = header_content.replace(
"@CLASS_FILE_NAME@", class_file_name)
78 with open(header_output,
"w")
as f:
79 f.write(header_content)
82 with open(source_template,
"r")
as f:
83 source_content = f.read()
85 source_content = source_content.replace(
"@CLASS_NAME@", class_name)
86 source_content = source_content.replace(
"@CLASS_FILE_NAME@", class_file_name)
88 with open(source_output,
"w")
as f:
89 f.write(source_content)
91 print(f
"Successfully created class '{class_name}'")
92 print(f
" Header: {header_output}")
93 print(f
" Source: {source_output}")
96if __name__ ==
"__main__":
def pascal_to_snake(name)