blob: 3e8896865af1697abb98e1f312ef1c60990041e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
|