Skip to content

Instantly share code, notes, and snippets.

@spotco
Created December 10, 2016 06:49
Show Gist options
  • Select an option

  • Save spotco/ad9fedfba349fd6e5fbecdcd06cd0cdf to your computer and use it in GitHub Desktop.

Select an option

Save spotco/ad9fedfba349fd6e5fbecdcd06cd0cdf to your computer and use it in GitHub Desktop.
osu_to_lua.py
import sys
import re
MODE_GENERAL, MODE_TIMINGPOINTS, MODE_HITOBJECTS = range(3)
current_mode = None
dict_out = {
"AudioFilename" : "Unknown",
"AudioLeadIn" : 0,
"HitObjects" : []
}
for line in open(sys.argv[1],'r').read().split("\n"):
line = line.strip()
if len(line) == 0:
current_mode = None
continue
match = re.match(r"\[(\w+)\]",line)
if match != None:
if line == "[General]":
current_mode = MODE_GENERAL
elif line == "[TimingPoints]":
current_mode = MODE_TIMINGPOINTS
elif line == "[HitObjects]":
current_mode = MODE_HITOBJECTS
else:
current_mode = None
else:
if current_mode == MODE_GENERAL:
if "AudioLeadIn" in line:
dict_out["AudioLeadIn"] = int(line.split(": ")[1])
if "AudioFilename" in line:
dict_out["AudioFilename"] = line.split(": ")[1]
elif current_mode == MODE_TIMINGPOINTS:
continue
elif current_mode == MODE_HITOBJECTS:
elements = line.split(",")
dict_out["HitObjects"].append({
"Time" : int(elements[2]),
"Type" : int(elements[3])
})
print "local rtv = {}"
print "rtv.%s = \"%s\"" % ("AudioAssetId","")
print "rtv.%s = \"%s\"" % ("AudioFilename",dict_out["AudioFilename"])
print "rtv.%s = %s" % ("AudioLeadIn",dict_out["AudioLeadIn"])
print "rtv.HitObjects = {"
for i in range(0,len(dict_out["HitObjects"])):
itr = dict_out["HitObjects"][i]
print " [%d] = { Time = %d; Type = %d };" %(i+1,itr["Time"],itr["Type"])
print "}"
print "return rtv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment