upload
This commit is contained in:
commit
62e284866b
22 files changed
+3080
No files matched your search
@@ -0,0 +1,52 @@
|
||||
"""osu! 譜面(.osu)解析:回傳打擊物件清單,供 importers 使用"""
|
||||
|
||||
|
||||
def parse_osu(path):
|
||||
sections, cur = {}, None
|
||||
for raw in open(path, encoding="utf-8"):
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("//"):
|
||||
continue
|
||||
if line.startswith("[") and line.endswith("]"):
|
||||
cur = line[1:-1]
|
||||
sections[cur] = []
|
||||
elif cur:
|
||||
sections[cur].append(line)
|
||||
|
||||
diff = dict(l.split(":", 1) for l in sections["Difficulty"])
|
||||
slider_mult = float(diff["SliderMultiplier"])
|
||||
|
||||
timing = []
|
||||
for l in sections["TimingPoints"]:
|
||||
p = l.split(",")
|
||||
timing.append((float(p[0]), float(p[1]), p[6] == "1" if len(p) > 6 else True))
|
||||
|
||||
objs = []
|
||||
for l in sections["HitObjects"]:
|
||||
p = l.split(",")
|
||||
t, typ, sound = int(p[2]), int(p[3]), int(p[4])
|
||||
o = {"time": t, "kat": bool(sound & (2 | 8)), "big": bool(sound & 4)}
|
||||
if typ & 8: # spinner / denden
|
||||
o["kind"] = "spinner"
|
||||
o["end"] = int(p[5])
|
||||
elif typ & 2: # slider / drumroll
|
||||
beat, sv = beat_at(timing, t)
|
||||
length, slides = float(p[7]), int(p[6])
|
||||
o["kind"] = "drumroll"
|
||||
o["end"] = int(t + length / (slider_mult * 100 * sv) * beat * slides)
|
||||
else:
|
||||
o["kind"] = "hit"
|
||||
objs.append(o)
|
||||
return objs
|
||||
|
||||
|
||||
def beat_at(timing, t):
|
||||
beat, sv = 500.0, 1.0
|
||||
for time, val, uninherited in timing:
|
||||
if time > t:
|
||||
break
|
||||
if uninherited:
|
||||
beat, sv = val, 1.0
|
||||
else:
|
||||
sv = -100.0 / val
|
||||
return beat, sv
|
||||
Reference in new issue
Block a user