50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import sys
|
|
|
|
file_path = 'c:/Users/beng/Godot/Projects/tekton-enet/scenes/main.tscn'
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
power_up_ui_start = -1
|
|
power_up_ui_end = -1
|
|
touch_controls_idx = -1
|
|
|
|
for i, line in enumerate(lines):
|
|
if line.startswith('[node name="PowerUpInventoryUI"'):
|
|
power_up_ui_start = i
|
|
elif power_up_ui_start != -1 and line.startswith('[node ') and power_up_ui_end == -1:
|
|
if 'parent="PowerUpInventoryUI"' not in line:
|
|
power_up_ui_end = i
|
|
|
|
if line.startswith('[node name="TouchControls" type="Control" parent="TouchLayer"'):
|
|
touch_controls_idx = i
|
|
|
|
if power_up_ui_end == -1:
|
|
power_up_ui_end = len(lines)
|
|
|
|
if power_up_ui_start != -1 and touch_controls_idx != -1:
|
|
# Extract the block
|
|
block = lines[power_up_ui_start:power_up_ui_end]
|
|
|
|
# Modify the parent
|
|
block[0] = block[0].replace('parent="."', 'parent="TouchLayer/TouchControls"')
|
|
|
|
# Remove from original location
|
|
del lines[power_up_ui_start:power_up_ui_end]
|
|
|
|
# Adjust touch_controls_idx if it was after the removed block
|
|
if touch_controls_idx > power_up_ui_end:
|
|
touch_controls_idx -= (power_up_ui_end - power_up_ui_start)
|
|
|
|
# Find end of TouchControls block/properties to insert
|
|
insert_idx = touch_controls_idx + 1
|
|
while insert_idx < len(lines) and not lines[insert_idx].startswith('['):
|
|
insert_idx += 1
|
|
|
|
lines = lines[:insert_idx] + block + lines[insert_idx:]
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
f.writelines(lines)
|
|
print('Successfully moved PowerUpInventoryUI to TouchLayer/TouchControls')
|
|
else:
|
|
print(f'Failed to find nodes: star={power_up_ui_start}, touch={touch_controls_idx}')
|