diff options
author | Feynman's Fedora <hdawg7797@yahoo.com> | 2019-06-29 23:06:59 -0400 |
---|---|---|
committer | Feynman's Fedora <hdawg7797@yahoo.com> | 2019-06-29 23:09:54 -0400 |
commit | cf642ffb90f15495100b107582f11a7a0bae412f (patch) | |
tree | a7addbd7a2d4c7200d826c625d52a340fed4c83a /isportal.py |
final commit
Diffstat (limited to 'isportal.py')
-rw-r--r-- | isportal.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/isportal.py b/isportal.py new file mode 100644 index 0000000..3e88968 --- /dev/null +++ b/isportal.py @@ -0,0 +1,56 @@ +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 |