@@ -35,23 +35,30 @@ public class Main {
35
35
36
36
private static final String DEFAULT_FILE_NAME = "Generated Deck" ;
37
37
38
- public static void main (String [] args ) {
39
- //DeckListLocation [DestinationLocation] [Colored MarginLeft MarginTop MarginRight MarginBottom]
40
- if (args .length == 1 ){//defaults margin settings [deckListLocation]
38
+ public static void main (String [] args ) {
39
+ /*
40
+ // <desk_list_location>
41
+ // <desk_list_location> <destination>
42
+ // <desk_list_location> <use_image> <colored>
43
+ // <desk_list_location> <destination> <use_image> <colored> [--left=<px>] [--top=<px>] [--right=<px>] [--bottom=<px>]
44
+ */
45
+
46
+ if (args .length == 1 ){//desk_list_location
41
47
File deckListFile = new File (args [0 ]);
42
48
if (!deckListFile .exists ()){
43
49
System .out .println ("File doesn't exist" );
44
50
System .exit (0 );
45
51
}
46
52
File dest = getDefaultFileName (DEFAULT_FILE_NAME , 0 );
53
+ System .out .println (dest );
47
54
boolean overwrite = overwrite (dest );
48
55
if (overwrite ){
49
56
System .out .println ("Generating..." );
50
- generate (deckListFile , dest , false , marginLeft , marginTop , marginRight , marginBottom );
51
- System .out .println ("Finished, File Location : " +dest .getPath ());
57
+ generate (deckListFile , dest , false , false , marginLeft , marginTop , marginRight , marginBottom );
58
+ System .out .println ("Finished, File Location : " +dest .getAbsolutePath ());
52
59
}
53
60
}
54
- else if (args .length == 2 ){//default margin settings [deskListLocation, destinationLocation]
61
+ else if (args .length == 2 ){//desk_list_location destination
55
62
File deckListFile = new File (args [0 ]);
56
63
if (!deckListFile .exists ()){
57
64
System .out .println ("File doesn't exist" );
@@ -61,32 +68,70 @@ else if(args.length == 2){//default margin settings [deskListLocation, destinati
61
68
boolean overwrite = overwrite (destinationFile );
62
69
if (overwrite ){
63
70
System .out .println ("Generating..." );
64
- generate (deckListFile , destinationFile , false , marginLeft , marginTop , marginRight , marginBottom );
65
- System .out .println ("Finished, File Location : " +destinationFile .getPath ());
71
+ generate (deckListFile , destinationFile , false , false , marginLeft , marginTop , marginRight , marginBottom );
72
+ System .out .println ("Finished, File Location : " +destinationFile .getAbsolutePath ());
66
73
}
67
74
}
68
- else if (args .length == 7 ){//[deskListLocation, destinationLocation, colored, left, top, right, bottom]
75
+ else if (args .length == 3 ){//desk_list_location <use_image> < colored>
69
76
File deckListFile = new File (args [0 ]);
70
77
if (!deckListFile .exists ()){
71
78
System .out .println ("File doesn't exist" );
72
79
System .exit (0 );
73
80
}
74
- File destinationFile = new File ( touchUpFileName ( args [1 ]) );
81
+ boolean useImage = getBoolean ( args [1 ], false );
75
82
boolean colored = getBoolean (args [2 ], false );
76
- float left = getFloat (args [3 ], marginLeft );
77
- float top = getFloat (args [4 ], marginTop );
78
- float right = getFloat (args [5 ], marginRight );
79
- float bottom = getFloat (args [6 ], marginBottom );
80
83
84
+ File dest = getDefaultFileName (DEFAULT_FILE_NAME , 0 );
85
+ boolean overwrite = overwrite (dest );
86
+ if (overwrite ){
87
+ System .out .println ("Generating..." );
88
+ generate (deckListFile , dest , useImage , colored , marginLeft , marginTop , marginRight , marginBottom );
89
+ System .out .println ("Finished, File Location : " +dest .getAbsolutePath ());
90
+ }
91
+ }
92
+ else if (args .length >= 4 && args .length <= 8 ){//<desk_list_location> <destination> <use_image> <colored> [--left=<px>] [--top=<px>] [--right=<px>] [--bottom=<px>]
93
+ File deckListFile = new File (args [0 ]);
94
+ if (!deckListFile .exists ()){
95
+ System .out .println ("File doesn't exist" );
96
+ System .exit (0 );
97
+ }
98
+
99
+ boolean useImage = getBoolean (args [2 ], false );
100
+ boolean colored = getBoolean (args [3 ], false );
101
+
102
+ float left = marginLeft ;
103
+ float top = marginTop ;
104
+ float right = marginRight ;
105
+ float bottom = marginBottom ;
106
+
107
+ for (int i =4 ;i <args .length ;i ++){
108
+ String param = args [i ];
109
+ if (param .startsWith ("--" )){
110
+ if (param .startsWith ("left" , 2 )){
111
+ left = getFloat (param .substring (param .indexOf ("=" ) + 1 ), marginLeft );
112
+ }
113
+ else if (param .startsWith ("top" , 2 )){
114
+ top = getFloat (param .substring (param .indexOf ("=" ) + 1 ), marginTop );
115
+ }
116
+ else if (param .startsWith ("right" , 2 )){
117
+ right = getFloat (param .substring (param .indexOf ("=" ) + 1 ), marginRight );
118
+ }
119
+ else if (param .startsWith ("bottom" , 2 )){
120
+ bottom = getFloat (param .substring (param .indexOf ("=" ) + 1 ), marginBottom );
121
+ }
122
+ }
123
+ }
124
+
125
+ File destinationFile = new File (touchUpFileName (args [1 ]));
81
126
boolean overwrite = overwrite (destinationFile );
82
127
if (overwrite ){
83
128
System .out .println ("Generating..." );
84
- generate (deckListFile , destinationFile , colored , left , top , right , bottom );
85
- System .out .println ("Finished, File Location : " +destinationFile .getPath ());
129
+ generate (deckListFile , destinationFile , useImage , colored , left , top , right , bottom );
130
+ System .out .println ("Finished, File Location : " +destinationFile .getAbsolutePath ());
86
131
}
87
132
}
88
133
else {
89
- System .out .println ("Nothing Generated, Requires DeckListLocation " );
134
+ System .out .println ("Invalid Command " );
90
135
}
91
136
}
92
137
@@ -150,14 +195,15 @@ private static boolean overwrite(File file){
150
195
*
151
196
* @param deckList
152
197
* @param destination
198
+ * @param useImage
153
199
* @param colored
154
200
* @param left
155
201
* @param top
156
202
* @param right
157
203
* @param bottom
158
204
* @return true if the deck successfully generated, false if an error occured
159
205
*/
160
- private static boolean generate (File deckList , File destination , boolean colored , float left , float top , float right , float bottom ){
206
+ private static boolean generate (File deckList , File destination , boolean useImage , boolean colored , float left , float top , float right , float bottom ){
161
207
if (!deckList .exists ()){
162
208
return false ;
163
209
}
@@ -173,7 +219,7 @@ private static boolean generate(File deckList, File destination, boolean colored
173
219
174
220
CardCreator creator = new CardCreator (document , cb );
175
221
for (Card card : cards ){
176
- creator .renderCard (card , !colored );
222
+ creator .renderCard (card , useImage , !colored );
177
223
}
178
224
document .close ();
179
225
return true ;
@@ -210,9 +256,11 @@ private static ArrayList<Card> getCards(ArrayList<String> cardIds){
210
256
CardFetcher cardFetch = new CardFetcher ();
211
257
ArrayList <Card > cards = new ArrayList <>();
212
258
for (String id : cardIds ){
213
- Card card = cardFetch .fetch (id );
214
- if (card != null ){
215
- cards .add (card );
259
+ if (!id .startsWith ("!" ) && !id .startsWith (("#" ))){
260
+ Card card = cardFetch .fetch (id );
261
+ if (card != null ){
262
+ cards .add (card );
263
+ }
216
264
}
217
265
}
218
266
return cards ;
0 commit comments