38 lines
2.5 KiB
Python
38 lines
2.5 KiB
Python
import codecs
|
|
import re
|
|
import os
|
|
|
|
def replace_in_file(path):
|
|
with codecs.open(path, 'r', 'utf-8') as f:
|
|
content = f.read()
|
|
orig = content
|
|
content = content.replace('*selectedObject.MeshRenderer', 'selectedObject.GetComponent<MetaCoreMeshRendererComponent>()')
|
|
content = content.replace('*gameObject.MeshRenderer', 'gameObject.GetComponent<MetaCoreMeshRendererComponent>()')
|
|
content = content.replace('*gameObject.Camera', 'gameObject.GetComponent<MetaCoreCameraComponent>()')
|
|
content = content.replace('*gameObject.Light', 'gameObject.GetComponent<MetaCoreLightComponent>()')
|
|
|
|
content = content.replace('gameObject.PrefabInstance.reset()', 'gameObject.RemoveComponent<MetaCorePrefabInstanceMetadata>()')
|
|
content = content.replace('gameObject.Camera.reset()', 'gameObject.RemoveComponent<MetaCoreCameraComponent>()')
|
|
content = content.replace('gameObject.Light.reset()', 'gameObject.RemoveComponent<MetaCoreLightComponent>()')
|
|
content = content.replace('gameObject.MeshRenderer.reset()', 'gameObject.RemoveComponent<MetaCoreMeshRendererComponent>()')
|
|
|
|
content = content.replace('clonedObject.PrefabInstance = MetaCorePrefabInstanceMetadata{', 'clonedObject.AddComponent<MetaCorePrefabInstanceMetadata>(MetaCorePrefabInstanceMetadata{')
|
|
content = re.sub(r'(clonedObject\.AddComponent<MetaCorePrefabInstanceMetadata>\([\s\S]*?\n\s*\})(\s*;)', r'\1)\2', content)
|
|
|
|
content = content.replace('prefabObjectIterator->AddComponent<MetaCoreCameraComponent>(prefabObject.Camera);',
|
|
'if (prefabObject.Camera.has_value()) prefabObjectIterator->AddComponent<MetaCoreCameraComponent>(prefabObject.Camera.value());')
|
|
content = content.replace('prefabObjectIterator->AddComponent<MetaCoreLightComponent>(prefabObject.Light);',
|
|
'if (prefabObject.Light.has_value()) prefabObjectIterator->AddComponent<MetaCoreLightComponent>(prefabObject.Light.value());')
|
|
content = content.replace('prefabObjectIterator->AddComponent<MetaCoreMeshRendererComponent>(prefabObject.MeshRenderer);',
|
|
'if (prefabObject.MeshRenderer.has_value()) prefabObjectIterator->AddComponent<MetaCoreMeshRendererComponent>(prefabObject.MeshRenderer.value());')
|
|
|
|
if content != orig:
|
|
with codecs.open(path, 'w', 'utf-8') as f:
|
|
f.write(content)
|
|
print(f"Fixed {path}")
|
|
|
|
for root, _, files in os.walk('Source'):
|
|
for file in files:
|
|
if file.endswith('.cpp') or file.endswith('.h'):
|
|
replace_in_file(os.path.join(root, file))
|