forked from EratoNysiad/ScheduledDispatchScheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadHandling.lua
88 lines (84 loc) · 2.96 KB
/
loadHandling.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
80
81
82
83
84
85
86
87
88
--Initialise timeTableData[0]
function isLineOOB(num)
if num == 0 then
return numTimeTables
elseif num > numTimeTables then
return 1
else
return num
end
end
function createMasterFile()
local masterFileRaw, masterFileSize = love.filesystem.read( 'ttdata/ttmf.dat' )
local masterFile = {''} --LuA dOeSnT rEqUiRe InItIaLiSaTiOn. Fuck you, it does. Or at least here
local tableX = 0
if masterFileRaw == nil then
love.filesystem.write( 'ttdata/ttmf.dat', "File,Name,Colour,Start,Repeat,End,Turnaround\nTT1,Line Number 1,14,512,30,2300,-1\nTT2,Different name for 2,7,1230,60,1000,1\nTT3,Line3AAAA,6,504,60,2300,-1" )
masterFileRaw, masterFileSize = love.filesystem.read( 'ttdata/ttmf.dat' )
end
for i=1, masterFileSize do
local currentCharacter = masterFileRaw:sub(i,i)
if currentCharacter ~= nil then
if currentCharacter == ',' or currentCharacter == '\n' then
tableX = tableX + 1
elseif masterFile[tableX] == nil then
masterFile[tableX] = currentCharacter
else
masterFile[tableX] = masterFile[tableX] .. currentCharacter
end
else
textToPrint = "oh god oh fuck"
return
end
end
timeTableData[0] = masterFile
numTimeTables = math.floor((tableX + 1)/masterFileLength -1)
currentTimeTable = isLineOOB(currentTimeTable)
end
function loadTimeTable(i)
local ttFileRaw, ttFileSize = love.filesystem.read( 'ttdata/'.. timeTableData[0][i*masterFileLength] ..'.dat' )
local ttFile = {} --LuA dOeSnT rEqUiRe InItIaLiSaTiOn. Fuck you, it does. Or at least here
local tableX = 0
if ttFileRaw == nil then
local printData
if i == 1 then
printData = "Code,Dist,Time,Wait,rTime,rWait\nICK,0,0,0,0,0\nTYY,6,6,2,0,0\nAMG,24,24,10,0,0\nJNHM,12,12,0,0,0\nHMJ,3,3,2,0,0"
elseif i == 3 then
printData = "Code,Dist,Time,Wait,rTime,rWait\nICK,0,0,0,0,0\nTYY,6,6,2,0,0\nAMG,24,24,10,0,0\nJNHM,12,12,0,0,0\nHMJ,3,3,2,0,0"
else
printData = "Code,Dist,Time,Wait,rTime,rWait\nDTYY,0,0,0,6,2\nTYY,-6,6,2,20,2\nAMG,24,21,10,13,10\nJNHM,12,12,0,2,0\nHMJ,3,3,2,0,0"
end
love.filesystem.write( 'ttdata/'.. timeTableData[0][i*masterFileLength] ..'.dat', printData )
ttFileRaw, ttFileSize = love.filesystem.read( 'ttdata/'.. timeTableData[0][i*masterFileLength] ..'.dat' )
end
for j=1, ttFileSize do
local currentCharacter = ttFileRaw:sub(j,j)
if currentCharacter ~= nil then
if currentCharacter == ',' or currentCharacter == '\n' then
tableX = tableX + 1
elseif ttFile[tableX] == nil then
ttFile[tableX] = currentCharacter
else
ttFile[tableX] = ttFile[tableX] .. currentCharacter
end
else
textToPrint = "oh god oh fuck"
return
end
end
timeTableData[i] = ttFile
numStops[i] = math.floor((tableX+1)/timeTableFileLength-1)
-- fix stupid bug
if timeTableData[0][i*masterFileLength+6] == tostring(1) then
timeTableData[0][i*masterFileLength+6] = 1
end
end
function reloadData()
love.filesystem.createDirectory( 'ttdata/' )
createMasterFile()
for i=1, numTimeTables do
loadTimeTable(i)
end
editData = {0,0}
currentStation=0
end