hitsounds/spelunker/generate_insane_diff.py

89 lines
2.2 KiB
Python
Raw Permalink Normal View History

2023-05-22 22:58:12 +00:00
import math
in_file_path = r"C:\Users\mzhan\OneDrive\Documents\deadcodehs\spelunker\Unknown Artist - Spelunker (IOException) [Insane].osu"
out_file_path = r"C:\Users\mzhan\AppData\Local\osu!\Songs\1145452 Unknown Artist - Spelunker\Unknown Artist - Spelunker (IOException) [Insane].osu"
radius = 88.0
CENTER_X = 256
CENTER_Y = 192
# start at (r, 0)
positions = []
theta = -math.pi / 2.0
for i in range(7):
positions.append((radius * math.cos(theta), radius * math.sin(theta)))
theta += 2.0 * math.pi / 7
print(positions)
with open(in_file_path, "rb") as f:
data = f.readlines()
def correct_position(x, y):
min_dist = None
min_idx = None
distances = []
for i, (px, py) in enumerate(positions):
dx = x - px
dy = y - py
distance = math.sqrt(dx * dx + dy * dy)
# print((x, y), (px, py), (dx, dy), distance)
distances.append(distance)
if min_dist is None or distance < min_dist:
min_dist = distance
min_idx = i
# print(min_dist, min_idx, sorted(distances))
return positions[min_idx]
with open(out_file_path, "wb") as f:
section = b""
c = 0
for line in data:
line = line.strip()
if not line: continue
if line.startswith(b"[") and line.endswith(b"]"):
section = line.lstrip(b"[").rstrip(b"]")
# print(section, line)
if section != b"HitObjects":
f.write(line + b"\n")
continue
parts = line.split(b",")
if len(parts) > 2:
x, y = correct_position(int(parts[0]) - CENTER_X, int(parts[1]) - CENTER_Y)
x = int(x) + CENTER_X
y = int(y) + CENTER_Y
parts[0] = str(x).encode("utf-8")
# print(parts)
parts[1] = str(y).encode("utf-8")
c = (c + 1) % len(positions)
if len(parts) > 3 and int(parts[3]) & 2 == 2:
sliderparts = parts[5].split(b"|")
ctype = sliderparts.pop(0)
newpart = [ctype]
for pt in sliderparts:
ax, ay = pt.split(b":")
ax = int(ax)
ay = int(ay)
ax2, ay2 = correct_position(ax - CENTER_X, ay - CENTER_Y)
ax2 = int(ax2) + CENTER_X
ay2 = int(ay2) + CENTER_Y
newpart.append(f"{ax2}:{ay2}".encode("utf-8"))
parts[5] = b"|".join(newpart)
line = b",".join(parts)
f.write(line + b"\n")