-
Notifications
You must be signed in to change notification settings - Fork 7
/
stateReader.java
144 lines (123 loc) · 3.93 KB
/
stateReader.java
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.ImageIO;
import java.awt.Color;
public class stateReader
{
static ArrayList<Color> visitedProvinces = new ArrayList<Color>();
static ArrayList<Color> visitedStates = new ArrayList<Color>();
static ArrayList<Integer> provinceIndexes = new ArrayList<Integer>();
static ArrayList<ArrayList<Integer>> colours = new ArrayList<ArrayList<Integer>>();
static ArrayList<String[]> csvData = new ArrayList<String[]>();
static BufferedImage states, provinces;
static int index;
static Color stateColor, provinceColor;
static FileWriter fw;
final static Color BLACK = new Color(0,0,0);
public static void csvReader()
{
String row;
BufferedReader csvReader;
try
{
csvReader = new BufferedReader(new FileReader("definition.csv"));
while ((row = csvReader.readLine()) != null)
{
csvData.add(row.split(";"));
}
}
catch(Exception e)
{
System.out.println("File Error");
}
}
public static void main(String[] args)
{
csvReader();
try
{
states=ImageIO.read(new File("states.png"));
}
catch(Exception e)
{
System.out.println("File not found");
}
try
{
provinces=ImageIO.read(new File("provinces.png"));
}
catch(Exception e)
{
System.out.println("File not found");
}
for (int i=0;i<states.getHeight();i++)
{
System.out.println((100*i)/states.getHeight()+"%");
for (int j=0;j<states.getWidth();j++)
{
stateColor=new Color(states.getRGB(j,i),true);
if(!stateColor.equals(BLACK))
{
provinceColor=new Color(provinces.getRGB(j,i),true);
index=visitedStates.indexOf(stateColor);
if(index<0)
{
visitedStates.add(stateColor);
colours.add(new ArrayList<Integer>());
index=visitedStates.size()-1;
}
if(visitedProvinces.indexOf(provinceColor)<0)
{
visitedProvinces.add(provinceColor);
for(String[] s:csvData)
{
if(Integer.parseInt(s[1])==provinceColor.getRed()&&Integer.parseInt(s[2])==provinceColor.getGreen()&&Integer.parseInt(s[3])==provinceColor.getBlue())
{
colours.get(index).add(Integer.parseInt(s[0]));
break;
}
}
}
}
}
}
for(int i=0;i<colours.size();i++)
{
try
{
fw = new FileWriter(new File(Integer.toString(i)+"-"+Integer.toString(visitedStates.get(i).getRed())+","+Integer.toString(visitedStates.get(i).getGreen())+","+Integer.toString(visitedStates.get(i).getBlue())+".txt"));
fw.write("state={\n");
fw.write("\tid="+i+"\n");
fw.write("\tname=\"STATE_"+i+"\" # \n");
fw.write("\tmanpower = \n\n");
fw.write("\tstate_category = \n\n");
fw.write("\thistory={\n");
fw.write("\t\towner = \n");
fw.write("\t\tvictory_points = { }\n");
fw.write("\t\tbuildings = {\n");
fw.write("\t\t\tinfrastructure =\n");
fw.write("\t\t\tindustrial_complex =\n");
fw.write("\t\t\tarms_factory =\n");
fw.write("\t\t\tdockyard =\n");
fw.write("\t\t}\n");
fw.write("\t\tadd_core_of =\n");
fw.write("\t}\n");
fw.write("\tprovinces={\n");
fw.write("\t\t");
for(int j:colours.get(i))
{
fw.write(j+" ");
}
fw.write("\n");
fw.write("\t}\n");
fw.write("}");
fw.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
}