forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_method.py
More file actions
51 lines (42 loc) · 1.5 KB
/
Copy pathreplace_method.py
File metadata and controls
51 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
filepath = "osu.Game/Screens/Edit/EditorBeatmap.cs"
with open(filepath, 'r') as f:
content = f.read()
old_method = """ public int findInsertionIndex(IReadOnlyList<HitObject> list, double startTime)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].StartTime > startTime)
return i - 1;
}
return list.Count - 1;
}"""
new_method = """ public int findInsertionIndex(IReadOnlyList<HitObject> list, double startTime)
{
int min = 0;
int max = list.Count - 1;
while (min <= max)
{
int mid = min + (max - min) / 2;
if (list[mid].StartTime <= startTime)
min = mid + 1;
else
max = mid - 1;
}
return min - 1;
}"""
if old_method not in content:
# Try normalizing line endings or whitespace if needed, but let's check exact match first
# Maybe try stripping whitespace
# Actually, I'll print a snippet to debug if it fails
print("Method not found!")
# Find approximate location
start_idx = content.find("public int findInsertionIndex")
if start_idx != -1:
print("Found start at:", start_idx)
print("Content snippet:")
print(content[start_idx:start_idx+300])
sys.exit(1)
new_content = content.replace(old_method, new_method)
with open(filepath, 'w') as f:
f.write(new_content)