3
3
import javax .swing .*;
4
4
import java .awt .*;
5
5
import java .awt .event .ActionEvent ;
6
- import java .awt .event .ActionListener ;
7
6
import java .awt .event .WindowAdapter ;
8
7
import java .awt .event .WindowEvent ;
9
8
import java .io .File ;
10
9
import java .io .FileWriter ;
11
- import java .lang .reflect .Array ;
12
- import java .util .*;
13
10
import java .util .List ;
11
+ import java .util .*;
14
12
15
13
@ SuppressWarnings ({"WeakerAccess" , "SameParameterValue" })
16
14
public class MainFrame extends JFrame {
@@ -32,7 +30,7 @@ public void windowClosing(WindowEvent we) {
32
30
}
33
31
});
34
32
35
- setSize (640 , 480 );
33
+ setSize (660 , 480 );
36
34
setResizable (false );
37
35
setLayout (null );
38
36
@@ -42,12 +40,13 @@ public void windowClosing(WindowEvent we) {
42
40
setTextAreas ();
43
41
setComboBoxes ();
44
42
45
- setVisible (true );
46
-
47
43
tfSeed .setText ("" );
48
44
tfSize .setText ("10" );
49
45
tfOffsetX .setText ("0" );
50
46
tfOffsetZ .setText ("0" );
47
+ cbDim .setSelectedItem ("overworld" );
48
+
49
+ setVisible (true );
51
50
}
52
51
53
52
public void generate (long wSeed , int chX , int chZ , String dim ) {
@@ -145,24 +144,21 @@ private long getSeed() {
145
144
return seed ;
146
145
}
147
146
148
- private void export () {
147
+ private void exportJM () {
149
148
if (result .isEmpty ())
150
149
calculate ();
151
150
File waypoints = new File ("waypoints" );
152
- if (!waypoints .exists ()) {
153
- //noinspection ResultOfMethodCallIgnored
154
- waypoints .mkdir ();
155
- }
156
- result .forEach (this ::writeWayPoint );
151
+ if (!waypoints .exists ()) waypoints .mkdir ();
152
+ result .forEach (this ::writeJMWayPoint );
157
153
}
158
154
159
- private void writeWayPoint (Coord coord , String name ) {
155
+ private void writeJMWayPoint (Coord coord , String name ) {
160
156
// Translate chunk coords to block coords
161
157
int x = coord .x * 16 + 8 ;
162
158
int y = coord .y ;
163
159
int z = coord .z * 16 + 8 ;
164
160
165
- String upName = name .substring (0 , 1 ).toUpperCase () + name .substring (1 , name . length () );
161
+ String upName = name .substring (0 , 1 ).toUpperCase () + name .substring (1 );
166
162
String wpName = upName + "_" + x + "," + y + "," + z ;
167
163
String fileName = "waypoints/" + wpName + "." + getCurrentDimID () + ".json" ;
168
164
@@ -172,21 +168,22 @@ private void writeWayPoint(Coord coord, String name) {
172
168
z *= 8 ;
173
169
}
174
170
175
- int hash = name . hashCode ( );
171
+ Color color = getColor ( name );
176
172
StringBuilder sb = new StringBuilder ("{" )
177
173
.append ("\" id\" : \" " ).append (wpName ).append ("\" , " )
178
174
.append ("\" name\" : \" " ).append (upName ).append ("\" , " )
179
175
.append ("\" icon\" : \" waypoint-normal.png\" , " )
180
176
.append ("\" x\" : " ).append (x ).append (", " )
181
177
.append ("\" y\" : " ).append (y ).append (", " )
182
178
.append ("\" z\" : " ).append (z ).append (", " )
183
- .append ("\" r\" : " ).append (( hash ) & 0xff ).append (", " )
184
- .append ("\" g\" : " ).append (( hash >> 8 ) & 0xff ).append (", " )
185
- .append ("\" b\" : " ).append (( hash >> 16 ) & 0xff ).append (", " )
179
+ .append ("\" r\" : " ).append (color . red ).append (", " )
180
+ .append ("\" g\" : " ).append (color . green ).append (", " )
181
+ .append ("\" b\" : " ).append (color . blue ).append (", " )
186
182
.append ("\" enable\" : true, " )
187
183
.append ("\" type\" : \" Normal\" , " )
188
184
.append ("\" origin\" : \" JourneyMap\" , " )
189
185
.append ("\" dimensions\" : [" ).append (getCurrentDimID ()).append ("]}" );
186
+
190
187
try (FileWriter file = new FileWriter (fileName )) {
191
188
file .write (sb .toString ());
192
189
file .flush ();
@@ -195,8 +192,50 @@ private void writeWayPoint(Coord coord, String name) {
195
192
}
196
193
}
197
194
195
+ private void exportMW () {
196
+ if (result .isEmpty ())
197
+ calculate ();
198
+
199
+ StringBuilder fileBuilder = new StringBuilder ()
200
+ .append ("# Configuration file\n \n " )
201
+ .append ("markers {\n " );
202
+
203
+ int id = 0 ;
204
+ for (Coord key : result .keySet ())
205
+ fileBuilder .append (this .writeMwWayPoint (id ++, key , result .get (key )));
206
+
207
+ fileBuilder
208
+ .append ("\t I:markerCount=" ).append (result .size ()).append ("\n " )
209
+ .append ("\t S:visibleGroup=all\n }\n " );
210
+ // .append("world {\n\tI:dimensionList <\n\t\t").append(getCurrentDimID()).append("\n\t>\n}");
211
+
212
+ try (FileWriter file = new FileWriter ("mapwriter.cfg" , false )) {
213
+ file .write (fileBuilder .toString ());
214
+ } catch (Exception e ) {
215
+ e .printStackTrace ();
216
+ }
217
+ }
218
+
219
+ private String writeMwWayPoint (int id , Coord coord , String name ) {
220
+ // Translate chunk coords to block coords
221
+ int x = coord .x * 16 + 8 , y = coord .y , z = coord .z * 16 + 8 ;
222
+ String upName = name .substring (0 , 1 ).toUpperCase () + name .substring (1 );
223
+ if (getCurrentDimID () == -1 ) {
224
+ x *= 8 ;
225
+ z *= 8 ;
226
+ }
227
+
228
+ Color color = getColor (name );
229
+ return "\t S:marker" + id + "=" + upName + ":" +
230
+ x + ":" + y + ":" + z + ":" + getCurrentDimID () + ":" +
231
+ color .hex + ":" + upName + "\n " ;
232
+ }
233
+
198
234
private int getCurrentDimID () {
199
- String dim = String .valueOf (cbDim .getSelectedItem ()).toLowerCase ();
235
+ return getDimID (String .valueOf (cbDim .getSelectedItem ()).toLowerCase ());
236
+ }
237
+
238
+ private int getDimID (String dim ) {
200
239
if (Dimensions .knownDimensions .containsKey (dim ))
201
240
return Dimensions .knownDimensions .get (dim );
202
241
JOptionPane .showMessageDialog (this , "Ask somebody to add the dimension to code." , "Unknown dimension: " + dim , JOptionPane .WARNING_MESSAGE );
@@ -206,7 +245,8 @@ private int getCurrentDimID() {
206
245
207
246
private void setButtons () {
208
247
setButton ("Calculate" , 10 , 40 , 95 , 25 , this ::calculate );
209
- setButton ("JM Export" , 110 , 40 , 95 , 25 , this ::export );
248
+ setButton ("JM Export" , 110 , 40 , 95 , 25 , this ::exportJM );
249
+ setButton ("MW Export" , 210 , 40 , 105 , 25 , this ::exportMW );
210
250
JButton btnRefresh = setButton ("↻" , 300 , 10 , 25 , 25 , this ::refresh );
211
251
btnRefresh .setMargin (new Insets (0 , 0 , 0 , 0 ));
212
252
}
@@ -227,8 +267,8 @@ private JButton setButton(String name, int x, int y, int w, int h, Runnable acti
227
267
private void setInputs () {
228
268
tfSeed = setTextField (100 , 10 , 200 , 25 );
229
269
tfSize = setTextField (380 , 10 , 50 , 25 );
230
- tfOffsetX = setTextField (300 , 40 , 50 , 25 );
231
- tfOffsetZ = setTextField (380 , 40 , 50 , 25 );
270
+ tfOffsetX = setTextField (390 , 40 , 50 , 25 );
271
+ tfOffsetZ = setTextField (470 , 40 , 50 , 25 );
232
272
}
233
273
234
274
private JTextField setTextField (int x , int y , int w , int h ) {
@@ -241,9 +281,9 @@ private JTextField setTextField(int x, int y, int w, int h) {
241
281
private void setLabels () {
242
282
setLabel ("World seed:" , 10 , 10 , 70 , 25 );
243
283
setLabel ("Size:" , 340 , 10 , 50 , 25 );
244
- setLabel ("Offset" , 230 , 40 , 50 , 25 );
245
- setLabel ("X:" , 280 , 40 , 50 , 25 );
246
- setLabel ("Z:" , 360 , 40 , 50 , 25 );
284
+ setLabel ("Offset" , 320 , 40 , 50 , 25 );
285
+ setLabel ("X:" , 365 , 40 , 50 , 25 );
286
+ setLabel ("Z:" , 450 , 40 , 50 , 25 );
247
287
}
248
288
249
289
private void setLabel (String text , int x , int y , int w , int h ) {
@@ -253,7 +293,7 @@ private void setLabel(String text, int x, int y, int w, int h) {
253
293
}
254
294
255
295
private void setTextAreas () {
256
- taOutput = setTextArea (10 , 70 , 615 , 375 );
296
+ taOutput = setTextArea (10 , 70 , 635 , 375 );
257
297
taOutput .setFont (new Font ("monospaced" , Font .PLAIN , 12 ));
258
298
}
259
299
@@ -271,8 +311,7 @@ private void setComboBoxes() {
271
311
Arrays .sort (dims );
272
312
cbDim = setComboBox (440 , 10 , 100 , 25 , dims );
273
313
cbDim .addActionListener (this ::refreshOres );
274
- cbOre = setComboBox (440 , 40 , 100 , 25 );
275
- cbDim .setSelectedItem ("overworld" );
314
+ cbOre = setComboBox (550 , 10 , 100 , 25 );
276
315
}
277
316
278
317
@ SafeVarargs
@@ -298,4 +337,23 @@ private void refreshOres(ActionEvent e) {
298
337
299
338
if (filteredOres .contains (oreName )) cbOre .setSelectedItem (oreName );
300
339
}
340
+
341
+ private Color getColor (String name ) {
342
+ return new Color (name .hashCode ());
343
+ }
344
+
345
+ private static class Color {
346
+ public int red ;
347
+ public int green ;
348
+ public int blue ;
349
+
350
+ public String hex ;
351
+
352
+ public Color (int hash ) {
353
+ red = (hash ) & 0xff ;
354
+ green = (hash >> 8 ) & 0xff ;
355
+ blue = (hash >> 16 ) & 0xff ;
356
+ hex = Integer .toHexString (hash & 0xffffff );
357
+ }
358
+ }
301
359
}
0 commit comments