-
Notifications
You must be signed in to change notification settings - Fork 1
/
addRemove.lua
79 lines (76 loc) · 2.49 KB
/
addRemove.lua
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function addStation()
for i=numStops[currentTimeTable], currentStation, -1 do
for j=0, timeTableFileLength-1 do
timeTableData[currentTimeTable][(i+1)*timeTableFileLength+j] = timeTableData[currentTimeTable][i*timeTableFileLength+j]
end
end
numStops[currentTimeTable] = numStops[currentTimeTable] + 1
if specialButtonHeld then
editData[2] = editData[2] + timeTableFileLength
end
end
function removeStation()
for i=currentStation, numStops[currentTimeTable]-1 do
for j=0, timeTableFileLength-1 do
timeTableData[currentTimeTable][(i)*timeTableFileLength+j] = timeTableData[currentTimeTable][(i+1)*timeTableFileLength+j]
end
end
numStops[currentTimeTable] = math.floor(numStops[currentTimeTable] - 0.5)
if editData[2] > numStops[currentTimeTable]*timeTableFileLength then
editData[2] = editData[2] - timeTableFileLength
end
end
function addTimeTable()
for i=numTimeTables, currentTimeTable, -1 do
for j=0, masterFileLength-1 do
timeTableData[0][(i+1)*masterFileLength+j] = timeTableData[0][i*masterFileLength+j]
end
end
timeTableData[0][(currentTimeTable+1)*masterFileLength+1] = timeTableData[0][(currentTimeTable+1)*masterFileLength+1].." new"
--Pick a new filename
local candidateName
for j=1, numTimeTables*30 do
candidateName = 'TT'..j
local candidateFound = false
for i=1, numTimeTables+1 do
if timeTableData[0][i*masterFileLength] == candidateName then
break
elseif i == numTimeTables+1 then
candidateFound = true
end
end
if candidateFound then
timeTableData[0][(currentTimeTable+1)*masterFileLength] = candidateName
break
end
end
for i=numTimeTables, currentTimeTable, -1 do
timeTableData[i+1] = timeTableData[i]
numStops[i+1] = numStops[i]
end
numTimeTables = numTimeTables + 1
currentTimeTable = currentTimeTable + 1
--attempt at solving entanglement of timetables
saveTimeTable(currentTimeTable)
loadTimeTable(currentTimeTable)
end
function removeTimeTable()
if numTimeTables ~= 1 then
if currentTimeTable ~= numTimeTables then
for i=currentTimeTable, numTimeTables-1 do
for j=0, masterFileLength-1 do
timeTableData[0][(i)*masterFileLength+j] = timeTableData[0][(i+1)*masterFileLength+j]
end
end
timeTableData[0][(numTimeTables)*masterFileLength] = nil
for i=currentTimeTable, numTimeTables-1 do
timeTableData[i] = timeTableData[i+1]
numStops[i] = numStops[i+1]
end
end
numTimeTables = numTimeTables - 1
if currentTimeTable > numTimeTables then
currentTimeTable = currentTimeTable - 1
end
end
end