-
Notifications
You must be signed in to change notification settings - Fork 1
/
readscan.cs
129 lines (123 loc) · 5.08 KB
/
readscan.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace HazeronMapper
{
static class Readscan
{
public static string readscan(string scanfile, Galaxy galaxy)
{
string systemName = null;
string sectorName = null;
string systemLoc = null;
string sectorLoc = null;
bool readingWH = false;
int whlinecount = 0;
int whcount = 0;
string whname = null;
bool whpolarity = false;
string linkstosystemName = null;
string linktosystemLoc = null;
string linkstosectorName = null;
string linktosectorLoc = null;
//SectorObj sector = new SectorObj(sectorName, galaxy);
SectorObj sector = null;
SystemObj sys = null;
//debugging
int linecount = 0;
int sectorscount = 0;
int systemscount = 0;
string returnstring = null;
//using (StreamReader reader = new StreamReader(scanfile))
//{
//string line;
//while ((line = reader.ReadLine()) != null)
List<string> lines = new List<string>(scanfile.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
foreach (string line in lines)
{
linecount++;
if (!readingWH)
{
if (line.Contains("Wormholes"))
{
readingWH = true;
}
else if (line.Contains("Sector ("))
{
int index = line.IndexOf("(");
sectorName = line.Trim();
sectorLoc = line.Substring(index).Trim();
}
else if (line.Contains("System ("))
{
int index = line.IndexOf("(");
systemName = line.Remove(index - 7).Trim();
systemLoc = line.Substring(index).Trim();
}
else if (line.Contains("'") && line.Contains("(")) // Same as above but in case of missing system word. See: http://hazeron.com/phpBB3/viewtopic.php?f=6&t=6568
{
int index = line.IndexOf("(");
systemName = line.Remove(index - 1).Trim();
systemLoc = line.Substring(index).Trim();
}
}
else
{
whlinecount++;
if (sector == null)
{
sector = new SectorObj(sectorLoc, sectorName, galaxy);
sectorscount++;
sys = new SystemObj(systemLoc, systemName, galaxy.sectors_dictionary[sectorLoc]);
systemscount++;
returnstring = "Added " + systemName;
}
if (whlinecount == 1)
{
whname = line;
}
else if (line.Contains("Positive Wormhole"))
{
whpolarity = true;
}
else if (line.Contains("Negative Wormhole"))
{
whpolarity = false;
}
else if (whlinecount == 3)
{
int index = line.IndexOf("(");
linkstosystemName = line.Remove(index).Trim();
linktosystemLoc = line.Substring(index).Trim();
}
else if (whlinecount == 4)
{
int index = line.IndexOf("(");
linkstosectorName = line.Trim();
linktosectorLoc = line.Substring(index).Trim();
}
else if (whlinecount == 5)
{
WormHoleObj wh = new WormHoleObj(whname, whpolarity, galaxy.sectors_dictionary[sectorLoc].systems_dictionary[sys.location], galaxy);
//WormHoleObj wh = new WormHoleObj(whname, whpolarity, sys, galaxy);
SectorObj whlinksec = new SectorObj(linktosectorLoc, linkstosectorName, galaxy);
sectorscount++;
SystemObj whlinksys = new SystemObj(linktosystemLoc, linkstosystemName, galaxy.sectors_dictionary[linktosectorLoc]);
systemscount++;
wh.makelink(galaxy.sectors_dictionary[linktosectorLoc].systems_dictionary[whlinksys.location]);
whlinecount = 0;
whcount++;
}
}
if (line == "Primary")
{
break;
}
}
return returnstring;
}
}
}