from sorter import Sorter portals = Sorter() links = [] lastportal = None #dim of last portal def conlast(cur): global lastportal ind = portals.index(cur) if lastportal == None: #self-connect and set as lastportal links[ind] = cur lastportal = cur else: #connect to last portal, connect last portal to self, and set lastportal as None links[ind] = lastportal links[portals.index(lastportal)] = cur lastportal = None def isportal(dim): if dim in portals: return True return False def link(dim): return links[portals.index(dim)] def unlink(dim): #remove portal from main list, and update the link of its pair global lastportal plink = links[portals.index(dim)] if plink != dim: conlast(plink) else: if dim == lastportal: lastportal = None def modportal(dim): if dim in portals: #remove portal unlink(dim) links.pop(portals.remove(dim)) else: #add portal links.insert(portals.insert(dim),()) conlast(dim) def load(data): lastportal = None if data[0] == 'None' else int(data[0]) portals = Sorter() links = [] for line in data[1:]: line = [int(num) for num in line.split(' ')] ind = portals.insert((line[0],line[1])) links.insert(ind, (line[2], line[3])) def save(): outtext = str(lastportal) + '\n' for portalind in range(len(portals)): outtext += str(portals[portalind][0]) + ' ' + str(portals[portalind][1]) + ' ' + str(links[portalind][0]) + ' ' + str(links[portalind][1]) + '\n' return outtext