def genWarpLocs(readfile="warps_insert.j", headerfile="locations_header.j", keyword="//insert", cwd="lua"): cwd = util.find(cwd, util.root) writefile = util.find(headerfile.replace("_header", "_insert"), util.root) headerfile = util.find(headerfile, util.root) names = util.getInsertFileData(readfile)[0] globalsStr = "" insertStr = "" for nameData in names: data = nameData.split("|") name = data[0] locName = name + " loc" idName = name + " id" if name not in special: globalsStr += "\tlocation " + util.name2Var(locName) + "\n" insertStr += "\tset " + util.name2Var( locName) + " = getNPCLoc(" + util.name2Var(idName) + ")\n" w = open(headerfile, 'r') t = w.read() w.close() t = t.replace("//globals", globalsStr) t = t.replace("//insert", insertStr) w = open(writefile, 'w') print >> w, t w.close()
def genWarpInit(readfile="warps_insert.j", headerfile="warp_init_header.j", keyword="//insert", cwd="lua"): cwd = util.find(cwd, util.root) writefile = util.find(headerfile.replace("_header", "_insert"), util.root) headerfile = util.find(headerfile, util.root) names = util.getInsertFileData(readfile)[0] insertStr = "" for nameData in names: data = nameData.split("|") name = data[0] exitName = name + " exit" isActive = "true" if len(data) > 1: isActive = data[1] if name not in special and getIsExit.findall(name) == []: insertStr += "\t\tset w = Warp.create(\"" + exitName + " to " + name + "\", " + util.name2Var( name) + "_LOC)\n" insertStr += "\t\tset playerDatum[i].warps[" + util.name2Var( exitName) + "] = w\n" insertStr += "\t\tset w = Warp.create(\"" + name + " to " + exitName + "\", " + util.name2Var( exitName) + "_LOC)\n" insertStr += "\t\tset playerDatum[i].warps[" + util.name2Var( name) + "] = w\n" if isActive == "false": insertStr += "\t\tset w.isActive = false\n" w = open(headerfile, 'r') t = w.read() w.close() t = t.replace("//insert", insertStr) w = open(writefile, 'w') print >> w, t w.close()
def genWarpInit(readfile = "warps_insert.j", headerfile = "warp_init_header.j", keyword = "//insert", cwd = "lua"): cwd = util.find(cwd, util.root) writefile = util.find(headerfile.replace("_header", "_insert"), util.root) headerfile = util.find(headerfile, util.root) names = util.getInsertFileData(readfile)[0] insertStr = "" for nameData in names: data = nameData.split("|") name = data[0] exitName = name + " exit" isActive = "true" if len(data) > 1: isActive = data[1] if name not in special and getIsExit.findall(name) == []: insertStr += "\t\tset w = Warp.create(\"" + exitName + " to " + name + "\", " + util.name2Var(name) + "_LOC)\n" insertStr += "\t\tset playerDatum[i].warps[" + util.name2Var(exitName) + "] = w\n" insertStr += "\t\tset w = Warp.create(\"" + name + " to " + exitName + "\", " + util.name2Var(exitName) + "_LOC)\n" insertStr += "\t\tset playerDatum[i].warps[" + util.name2Var(name) + "] = w\n" if isActive == "false": insertStr += "\t\tset w.isActive = false\n" w = open(headerfile, 'r') t = w.read() w.close() t = t.replace("//insert", insertStr) w = open(writefile, 'w') print>>w, t w.close()
def itemConstants(itemFile, constantsFile, cwd, keywords = KW, suffix = ""): cwd = util.find(cwd, util.root) fileName = util.find(itemFile, cwd) path = os.path.join(CONSTANTS_DIR, constantsFile) w = open(fileName, 'r') t = w.read() w.close() libName = itemFile.replace("_insert.j", "") header = "library " + libName.title() + "Constants\n" header = header.replace("_", "") header += "globals\n" itemId = getId.findall(t)[0] varNames = [util.name2Var(x) for x in getItemName.findall(t)] totals = [int(x) for x in getTotal.findall(t)] if totals != []: for var in range(0, len(varNames)): for x in range(0, totals[var]): header += "\tconstant integer " + varNames[var] + "_" + str(x) + suffix + " = '" + itemId + "'\n" itemId = util.add(itemId) else: for var in range(0, len(varNames)): header += "\tconstant integer " + varNames[var] + suffix + " = '" + itemId + "'\n" itemId = util.add(itemId) header += "endglobals\nendlibrary" w = open(path, 'w') print>>w, header w.close()
def itemConstants(itemFile, constantsFile, cwd, keywords=KW, suffix=""): cwd = util.find(cwd, util.root) fileName = util.find(itemFile, cwd) path = os.path.join(CONSTANTS_DIR, constantsFile) w = open(fileName, 'r') t = w.read() w.close() libName = itemFile.replace("_insert.j", "") header = "library " + libName.title() + "Constants\n" header = header.replace("_", "") header += "globals\n" itemId = getId.findall(t)[0] varNames = [util.name2Var(x) for x in getItemName.findall(t)] totals = [int(x) for x in getTotal.findall(t)] if totals != []: for var in range(0, len(varNames)): for x in range(0, totals[var]): header += "\tconstant integer " + varNames[var] + "_" + str( x) + suffix + " = '" + itemId + "'\n" itemId = util.add(itemId) else: for var in range(0, len(varNames)): header += "\tconstant integer " + varNames[ var] + suffix + " = '" + itemId + "'\n" itemId = util.add(itemId) header += "endglobals\nendlibrary" w = open(path, 'w') print >> w, header w.close()
def genWarpLocs(readfile = "warps_insert.j", headerfile = "locations_header.j", keyword = "//insert", cwd = "lua"): cwd = util.find(cwd, util.root) writefile = util.find(headerfile.replace("_header", "_insert"), util.root) headerfile = util.find(headerfile, util.root) names = util.getInsertFileData(readfile)[0] globalsStr = "" insertStr = "" for nameData in names: data = nameData.split("|") name = data[0] locName = name + " loc" idName = name + " id" if name not in special: globalsStr += "\tlocation " + util.name2Var(locName) + "\n" insertStr += "\tset " + util.name2Var(locName) + " = getNPCLoc(" + util.name2Var(idName) + ")\n" w = open(headerfile, 'r') t = w.read() w.close() t = t.replace("//globals", globalsStr) t = t.replace("//insert", insertStr) w = open(writefile, 'w') print>>w, t w.close()
def rawCns(insertFile, constantsFile, suffix = "id"): """Takes an insert file as an argument and creates a vJASS library, which contains each of the objects' rawcodes represented as JASS constant integers.""" data = util.getInsertFileData(insertFile) names = [x.split("|")[0] for x in data[0]] ids = data[1] if len(names) != len(ids): print "Error: The size of names and ids is not the same!" return #build the first part of the library header = "library " + util.name2Lib(insertFile.replace("_insert.j", "") + suffix) + "Constants\n" header = header.replace("_", "") header += "globals\n" #now for each name, create a constant integer for x in range(0, len(names)): header += "\tconstant integer " + util.name2Var(names[x] + "_" + suffix) + " = \'" + ids[x] + "\'\n" header += "endglobals\nendlibrary" path = os.path.join(CONSTANTS_DIR, constantsFile) w = open(path, 'w') print>>w, header w.close()