Skip to content

Commit 7339326

Browse files
committed
Fixed a major crash, added additive searching + multi-set searching.
1 parent 3b01222 commit 7339326

10 files changed

Lines changed: 224 additions & 78 deletions

File tree

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v0.00.07
2+
3+
- Fixed a crash that happened if a card had no legalities in the DB
4+
- Added warning for doing a broad search when no filters are set
5+
- Added an additive search (Adding to existing results)
6+
- Searches now support searching across multiple sets in the filters (program would hang indefinitely before)
7+
8+
==========
19
v0.00.06
210

311
- Added new (optional) simplified view to shorten export logs and make them more readable

com/gmail/nossr50/MainApplicationWindow.java

Lines changed: 86 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@
1818
import org.eclipse.swt.widgets.Composite;
1919
import org.eclipse.swt.widgets.Text;
2020

21-
import com.gmail.nossr50.datatypes.LegalFlags;
2221
import com.gmail.nossr50.enums.AppState;
2322
import com.gmail.nossr50.enums.ButtonType;
2423
import com.gmail.nossr50.enums.ExportType;
2524
import com.gmail.nossr50.enums.FieldType;
2625
import com.gmail.nossr50.enums.LegalTypes;
27-
import com.gmail.nossr50.enums.StyleFlags;
28-
import com.gmail.nossr50.enums.ExportFlags;
26+
import com.gmail.nossr50.flags.ExportFlags;
27+
import com.gmail.nossr50.flags.LegalFlags;
28+
import com.gmail.nossr50.flags.QueryFlags;
29+
import com.gmail.nossr50.flags.StyleFlags;
2930
import com.gmail.nossr50.runnables.DialogThread;
3031
import com.gmail.nossr50.runnables.ExportThread;
3132
import com.gmail.nossr50.runnables.QueryThread;
3233

3334
import com.gmail.nossr50.tools.CardImageManager;
3435
import com.gmail.nossr50.tools.ExportExample;
3536
import com.gmail.nossr50.tools.UpdateTimerTask;
36-
import com.sun.prism.paint.Color;
37-
3837
import io.magicthegathering.javasdk.api.CardAPI;
3938
import io.magicthegathering.javasdk.api.SetAPI;
4039
import io.magicthegathering.javasdk.resource.Card;
@@ -51,16 +50,14 @@
5150
import org.eclipse.swt.widgets.ProgressBar;
5251
import org.eclipse.swt.custom.StyledText;
5352
import org.eclipse.wb.swt.SWTResourceManager;
54-
import org.eclipse.swt.events.SelectionAdapter;
55-
import org.eclipse.swt.events.SelectionEvent;
5653

5754
public class MainApplicationWindow {
5855

5956
private Shell shell;
6057
private CardImageManager cardImageManager;
6158

6259
private String appName = "MTG JSON Tool";
63-
private String ver = "v0.00.06";
60+
private String ver = "v0.00.07";
6461
private String author = "nossr50";
6562

6663
public static int secondsPassed = 0;
@@ -132,7 +129,8 @@ public class MainApplicationWindow {
132129
*/
133130

134131
//Buttons that do something complicated
135-
private static Button filter_btn_fetch;
132+
private static Button filter_btn_newSearch;
133+
private static Button filter_btn_additiveSearch;
136134
private static Button rt_btn_export;
137135
private static Button btnCustomExport;
138136
private static Button filter_btn_clear;
@@ -178,6 +176,7 @@ public class MainApplicationWindow {
178176
*/
179177

180178
private Listener listener_fetch;
179+
private Listener listener_additive_search;
181180
private Listener listener_export;
182181
private Listener listener_custom_export;
183182
private Listener listener_clear;
@@ -206,7 +205,7 @@ public class MainApplicationWindow {
206205
/*
207206
* Other vars
208207
*/
209-
public static ArrayList<Card> results;
208+
public static HashMap<Integer, Card> results;
210209
public static AppState curState = AppState.IDLE;
211210

212211
/*
@@ -243,6 +242,7 @@ public class MainApplicationWindow {
243242
private Label result_lbl_manaCost;
244243
private Label lblStats_1;
245244
private Button btnSimplifiedStats;
245+
246246

247247

248248
/**
@@ -339,7 +339,7 @@ protected void createContents() {
339339
filter_lbl_setName.setBounds(6, 34, 66, 15);
340340

341341
ft_setName = new Text(filterComp, SWT.BORDER);
342-
ft_setName.setText("Amonkhet");
342+
ft_setName.setText("Amonkhet, Ixalan, Dominaria");
343343
ft_setName.setBounds(78, 31, 250, 21);
344344

345345
Label filter_lbl_colors = new Label(filterComp, SWT.NONE);
@@ -480,15 +480,15 @@ protected void createContents() {
480480

481481
filter_lbl_header_note1 = new Label(grpQuery, SWT.NONE);
482482
filter_lbl_header_note1.setAlignment(SWT.CENTER);
483-
filter_lbl_header_note1.setBounds(10, 37, 258, 15);
483+
filter_lbl_header_note1.setBounds(10, 16, 258, 15);
484484
filter_lbl_header_note1.setText("Tip: Fields can be blank!");
485485

486-
filter_btn_fetch = new Button(grpQuery, SWT.NONE);
487-
filter_btn_fetch.setBounds(10, 71, 116, 25);
488-
filter_btn_fetch.setText("Fetch Results");
486+
filter_btn_newSearch = new Button(grpQuery, SWT.NONE);
487+
filter_btn_newSearch.setBounds(10, 71, 116, 25);
488+
filter_btn_newSearch.setText("New Search");
489489

490490
filter_btn_clear = new Button(grpQuery, SWT.NONE);
491-
filter_btn_clear.setBounds(152, 71, 116, 25);
491+
filter_btn_clear.setBounds(81, 37, 116, 25);
492492
filter_btn_clear.setText("Clear Fields");
493493

494494
queryProgressBar = new ProgressBar(grpQuery, SWT.INDETERMINATE | SWT.SMOOTH | SWT.HORIZONTAL);
@@ -507,6 +507,11 @@ protected void createContents() {
507507
filter_lbl_progressBar.setText("Querying mtg-json.com DB...");
508508
filter_lbl_progressBar.setVisible(false);
509509

510+
filter_btn_additiveSearch = new Button(grpQuery, SWT.NONE);
511+
filter_btn_additiveSearch.setText("Additive Search");
512+
filter_btn_additiveSearch.setBounds(152, 71, 116, 25);
513+
filter_btn_additiveSearch.setEnabled(false);
514+
510515
styledWarning = new StyledText(filterComp, SWT.BORDER | SWT.WRAP);
511516
styledWarning.setSelectionBackground(SWTResourceManager.getColor(SWT.COLOR_TRANSPARENT));
512517
styledWarning.setSelectionForeground(SWTResourceManager.getColor(255, 0, 0));
@@ -670,12 +675,24 @@ public void handleEvent(Event e) {
670675
}
671676
};
672677

678+
listener_additive_search = new Listener() {
679+
public void handleEvent(Event e) {
680+
switch (e.type) {
681+
case SWT.Selection:
682+
{
683+
fetchButtonPressed(QueryFlags.ADDITIVE_SEARCH);
684+
break;
685+
}
686+
}
687+
}
688+
};
689+
673690
listener_fetch = new Listener() {
674691
public void handleEvent(Event e) {
675692
switch (e.type) {
676693
case SWT.Selection:
677694
{
678-
fetchButtonPressed();
695+
fetchButtonPressed(QueryFlags.CLEAR_SEARCH);
679696
break;
680697
}
681698
}
@@ -914,7 +931,8 @@ public void handleEvent(Event arg0) {
914931
rt_btn_export.addListener(SWT.Selection, listener_export);
915932
btnCustomExport.addListener(SWT.Selection, listener_custom_export);
916933
filter_btn_clear.addListener(SWT.Selection, listener_clear);
917-
filter_btn_fetch.addListener(SWT.Selection, listener_fetch);
934+
filter_btn_newSearch.addListener(SWT.Selection, listener_fetch);
935+
filter_btn_additiveSearch.addListener(SWT.Selection, listener_additive_search);
918936

919937
styledWarning.setSelection(0, 9);
920938
styledWarning.update();
@@ -1196,7 +1214,7 @@ private void initPresets()
11961214

11971215
synchronized private void updateResultFields(int selectionIndex)
11981216
{
1199-
Card curCard = results.get(selectionIndex);
1217+
Card curCard = (Card) results.values().toArray()[selectionIndex];
12001218

12011219
if(curCard != null)
12021220
{
@@ -1279,14 +1297,14 @@ public void run() {
12791297
}
12801298
}
12811299

1282-
public static void initLegalities()
1300+
synchronized public static void initLegalities()
12831301
{
12841302
if(legalityTracker == null)
12851303
legalityTracker = new HashMap<Integer, Integer>();
12861304

12871305
System.out.println("Updating Legalities...");
12881306

1289-
for(Card curCard : results)
1307+
for(Card curCard : results.values())
12901308
{
12911309
//To keep track of whether or not we've found legality for this card
12921310
HashMap<LegalTypes, Boolean> legalityMap = new HashMap<LegalTypes, Boolean>();
@@ -1299,23 +1317,24 @@ public static void initLegalities()
12991317
int legality = 0;
13001318

13011319
for(LegalTypes lt : LegalTypes.values()) {
1302-
for(Legality leg : curCard.getLegalities())
1303-
{
1304-
if(leg.getFormat().toString().contains(lt.toString()))
1320+
if(curCard.getLegalities() != null)
1321+
for(Legality leg : curCard.getLegalities())
13051322
{
1306-
//Only flag a card as having found legality if it matches Legal or Banned
1307-
if(leg.getLegality().toString().contains("Legal"))
1308-
{
1309-
legality = legality | lt.getLegalityFlag();
1310-
legalityMap.put(lt, true); //Tracking for whether or not we have a missing legality
1311-
}
1312-
1313-
else if (leg.getLegality().toString().contains("Banned"))
1323+
if(leg.getFormat().toString().contains(lt.toString()))
13141324
{
1315-
legalityMap.put(lt, true); //Tracking for whether or not we have a missing legality
1325+
//Only flag a card as having found legality if it matches Legal or Banned
1326+
if(leg.getLegality().toString().contains("Legal"))
1327+
{
1328+
legality = legality | lt.getLegalityFlag();
1329+
legalityMap.put(lt, true); //Tracking for whether or not we have a missing legality
1330+
}
1331+
1332+
else if (leg.getLegality().toString().contains("Banned"))
1333+
{
1334+
legalityMap.put(lt, true); //Tracking for whether or not we have a missing legality
1335+
}
13161336
}
13171337
}
1318-
}
13191338

13201339

13211340
}
@@ -1454,7 +1473,7 @@ private void simpleExportButtonPressed()
14541473
if(rt_btn_export.isEnabled())
14551474
{
14561475
//Executes the Export script in a new thread
1457-
ExportThread et = new ExportThread(results, ExportType.SIMPLE, ExportFlags.NAMES, StyleFlags.NOFLAGS);
1476+
ExportThread et = new ExportThread((ArrayList<Card>) results.values(), ExportType.SIMPLE, ExportFlags.NAMES, StyleFlags.NOFLAGS);
14581477
Thread thread = new Thread(et);
14591478

14601479
thread.start();
@@ -1466,7 +1485,7 @@ private void exportButtonPressed()
14661485
if(rt_btn_export.isEnabled())
14671486
{
14681487
//Executes the Export script in a new thread
1469-
ExportThread et = new ExportThread(results, ExportType.STANDARD, ExportFlags.NOFLAGS, StyleFlags.NOFLAGS);
1488+
ExportThread et = new ExportThread((ArrayList<Card>) results.values(), ExportType.STANDARD, ExportFlags.NOFLAGS, StyleFlags.NOFLAGS);
14701489
Thread thread = new Thread(et);
14711490

14721491
thread.start();
@@ -1478,7 +1497,7 @@ private void customExportButtonPressed()
14781497
if(btnCustomExport.isEnabled())
14791498
{
14801499
//Executes the Export script in a new thread with custom flags
1481-
ExportThread et = new ExportThread(results, ExportType.CUSTOM, getExportFlags(), getStyleFlags());
1500+
ExportThread et = new ExportThread((ArrayList<Card>) results.values(), ExportType.CUSTOM, getExportFlags(), getStyleFlags());
14821501
Thread thread = new Thread(et);
14831502

14841503
thread.start();
@@ -1601,12 +1620,12 @@ private void clearButtonPressed()
16011620
}
16021621
}
16031622

1604-
private void fetchButtonPressed()
1623+
private void fetchButtonPressed(int flags)
16051624
{
1606-
if(filter_btn_fetch.isEnabled())
1625+
if(filter_btn_newSearch.isEnabled())
16071626
{
16081627
//Executes the Query in a new thread
1609-
QueryThread qt = new QueryThread(getFilters());
1628+
QueryThread qt = new QueryThread(getFilters(), flags);
16101629
Thread thread = new Thread(qt);
16111630

16121631
thread.start();
@@ -1615,13 +1634,15 @@ private void fetchButtonPressed()
16151634

16161635
synchronized private static void disableButtons()
16171636
{
1618-
filter_btn_fetch.setEnabled(false);
1637+
filter_btn_newSearch.setEnabled(false);
1638+
filter_btn_additiveSearch.setEnabled(false);
16191639
filter_btn_clear.setEnabled(false);
16201640
rt_btn_export.setEnabled(false);
16211641
btnCustomExport.setEnabled(false);
16221642
btnSimpleExport.setEnabled(false);
16231643

1624-
filter_btn_fetch.update();
1644+
filter_btn_newSearch.update();
1645+
filter_btn_additiveSearch.update();
16251646
rt_btn_export.update();
16261647
filter_btn_clear.update();
16271648
btnCustomExport.update();
@@ -1633,18 +1654,22 @@ synchronized private static void enableButtons()
16331654

16341655
if(curState == AppState.IDLE || curState == AppState.FINISHED)
16351656
{
1636-
filter_btn_fetch.setEnabled(true);
1657+
filter_btn_newSearch.setEnabled(true);
16371658
}
16381659

16391660
if(curState == AppState.FINISHED)
16401661
{
1662+
if(numResults > 0)
1663+
filter_btn_additiveSearch.setEnabled(true);
1664+
16411665
rt_btn_export.setEnabled(true);
16421666
btnCustomExport.setEnabled(true);
16431667
btnSimpleExport.setEnabled(true);
16441668
}
16451669

16461670

1647-
filter_btn_fetch.update();
1671+
filter_btn_newSearch.update();
1672+
filter_btn_additiveSearch.update();
16481673
filter_btn_clear.update();
16491674
rt_btn_export.update();
16501675
btnCustomExport.update();
@@ -1766,7 +1791,7 @@ public static void updateResults()
17661791
resultList.removeAll();
17671792

17681793
if(results != null && results.size() > 0) {
1769-
for(Card curCard : results)
1794+
for(Card curCard : results.values())
17701795
{
17711796
resultList.add(curCard.getName());
17721797
}
@@ -1857,22 +1882,22 @@ public void run() {
18571882
filter_lbl_thinkTime.setVisible(true);
18581883
filter_lbl_progressBar.setVisible(true);
18591884

1860-
filter_btn_fetch.setVisible(false);
1885+
filter_btn_newSearch.setVisible(false);
1886+
filter_btn_additiveSearch.setVisible(false);
18611887
filter_btn_clear.setVisible(false);
18621888
filter_lbl_header_note1.setVisible(false);
18631889

1864-
filter_btn_fetch.update();
1890+
filter_btn_newSearch.update();
1891+
filter_btn_additiveSearch.update();
18651892
filter_btn_clear.update();
18661893
filter_lbl_header_note1.update();
18671894

1868-
18691895
filter_lbl_thinkTime.update();
18701896
filter_lbl_progressBar.update();
18711897

18721898
timer.schedule(new UpdateTimerTask(), 1000l, 1000l); // Run once a second
18731899
}
18741900
});
1875-
18761901
}
18771902

18781903
synchronized public static void asyncUpdateTimer()
@@ -1903,11 +1928,13 @@ public void run() {
19031928
filter_lbl_thinkTime.update();
19041929
filter_lbl_progressBar.update();
19051930

1906-
filter_btn_fetch.setVisible(true);
1931+
filter_btn_newSearch.setVisible(true);
1932+
filter_btn_additiveSearch.setVisible(true);
19071933
filter_btn_clear.setVisible(true);
19081934
filter_lbl_header_note1.setVisible(true);
19091935

1910-
filter_btn_fetch.update();
1936+
filter_btn_newSearch.update();
1937+
filter_btn_additiveSearch.update();
19111938
filter_btn_clear.update();
19121939
filter_lbl_header_note1.update();
19131940
}
@@ -1918,4 +1945,12 @@ synchronized public static void setNumResults(int resultCount)
19181945
{
19191946
numResults = resultCount;
19201947
}
1948+
1949+
public static void addCardAdditive(Card card)
1950+
{
1951+
if(results.get(card.getMultiverseid()) == null)
1952+
{
1953+
results.put(card.getMultiverseid(), card);
1954+
}
1955+
}
19211956
}

com/gmail/nossr50/enums/LegalTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.gmail.nossr50.enums;
22

3-
import com.gmail.nossr50.datatypes.*;
3+
import com.gmail.nossr50.flags.*;
44

55
public enum LegalTypes {
66
MODERN("Modern", LegalFlags.MODERN, LegalFlags.MISS_MODERN),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.gmail.nossr50.enums;
1+
package com.gmail.nossr50.flags;
22

33
public class ExportFlags {
44
public static final int NOFLAGS = 0; // In binary: 00000

0 commit comments

Comments
 (0)