diff --git a/DivaBot/DivaBot.jar b/DivaBot/DivaBot.jar index 482b82f..6573ef4 100644 Binary files a/DivaBot/DivaBot.jar and b/DivaBot/DivaBot.jar differ diff --git a/DivaBot/calibration_data.txt b/DivaBot/calibration_data.txt index f387198..f4dbc02 100644 --- a/DivaBot/calibration_data.txt +++ b/DivaBot/calibration_data.txt @@ -1,4 +1,4 @@ -521 -299 -1490 -842 +555 +318 +1630 +918 diff --git a/DivaBot/rectangle0.png b/DivaBot/rectangle0.png index c701e05..11ed267 100644 Binary files a/DivaBot/rectangle0.png and b/DivaBot/rectangle0.png differ diff --git a/DivaBot/rectangle1.png b/DivaBot/rectangle1.png index b81c338..e5d206c 100644 Binary files a/DivaBot/rectangle1.png and b/DivaBot/rectangle1.png differ diff --git a/DivaBot/rectangle2.png b/DivaBot/rectangle2.png index b8a7f2b..c20d3c7 100644 Binary files a/DivaBot/rectangle2.png and b/DivaBot/rectangle2.png differ diff --git a/DivaBot/rectangle3.png b/DivaBot/rectangle3.png index 599e55d..481e3ec 100644 Binary files a/DivaBot/rectangle3.png and b/DivaBot/rectangle3.png differ diff --git a/DivaBot/rectangle4.png b/DivaBot/rectangle4.png index 3991d54..dc2176b 100644 Binary files a/DivaBot/rectangle4.png and b/DivaBot/rectangle4.png differ diff --git a/DivaBot/src/sig/CustomRobot.java b/DivaBot/src/sig/CustomRobot.java index 25cb86f..8d9457a 100644 --- a/DivaBot/src/sig/CustomRobot.java +++ b/DivaBot/src/sig/CustomRobot.java @@ -33,7 +33,7 @@ public class CustomRobot extends Robot{ return super.createScreenCapture(r); } - public void refreshScreen() { + public void refreshScreen() throws IOException { //currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83)); if (CalibrationDataChanged()) { ReloadCalibrationData(); @@ -44,7 +44,7 @@ public class CustomRobot extends Robot{ currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83)); } } - private void ReloadCalibrationData() { + private void ReloadCalibrationData() throws IOException { lastCalibrationTime=calibration_file.lastModified(); String[] data = FileUtils.readFromFile("calibration_data.txt"); calibration_data[0]=Integer.parseInt(data[0]); @@ -57,7 +57,7 @@ public class CustomRobot extends Robot{ return calibration_file.exists()&&lastCalibrationTime!=calibration_file.lastModified(); } - public void refreshScoreScreen() { + public void refreshScoreScreen() throws IOException { if (CalibrationDataChanged()) { ReloadCalibrationData(); } diff --git a/DivaBot/src/sig/DrawCanvas.java b/DivaBot/src/sig/DrawCanvas.java index 531e17c..69ccf79 100644 --- a/DivaBot/src/sig/DrawCanvas.java +++ b/DivaBot/src/sig/DrawCanvas.java @@ -126,6 +126,7 @@ public class DrawCanvas extends JPanel implements KeyListener{ artist = obj.getString("artist");*/ if (MyRobot.p.songname!=null) { SongInfo currentSong = SongInfo.getByTitle(MyRobot.p.songname); + FileUtils.writetoFile(new String[] {MyRobot.p.songname}, "testencode.txt"); if (currentSong!=null) { if (currentSong.rating.has(difficulty)) { difficultyRating = currentSong.rating.getDouble(difficulty); diff --git a/DivaBot/src/sig/FutureToneBot.java b/DivaBot/src/sig/FutureToneBot.java index 69bdb29..523c431 100644 --- a/DivaBot/src/sig/FutureToneBot.java +++ b/DivaBot/src/sig/FutureToneBot.java @@ -193,7 +193,11 @@ public class FutureToneBot{ } catch (IOException | InterruptedException e) { e.printStackTrace(); } - MYROBOT.refreshScreen(); + try { + MYROBOT.refreshScreen(); + } catch (IOException e) { + e.printStackTrace(); + } } private boolean OnResultsScreen() { diff --git a/DivaBot/src/sig/MyRobot.java b/DivaBot/src/sig/MyRobot.java index 8d39743..59b619b 100644 --- a/DivaBot/src/sig/MyRobot.java +++ b/DivaBot/src/sig/MyRobot.java @@ -292,7 +292,7 @@ public class MyRobot{ lastfail=data.fail; new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+data.cool+"_"+data.fine+"_"+data.safe+"_"+data.sad+"_"+data.worst+"_"+data.percent+"" + "_"+data.combo+"_"+data.score+".png")); - results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.combo,data.score,data.fail)); + results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.mod,data.combo,data.score,data.fail)); SoundUtils.playSound("collect_item.wav"); //gotoxy(800,64); //click(); @@ -305,7 +305,8 @@ public class MyRobot{ MYROBOT.keyRelease(KeyEvent.VK_CONTROL); } } catch (IOException|NumberFormatException|IndexOutOfBoundsException e) { - + e.printStackTrace(); + System.out.println(e.getMessage()); } } else { if (results.size()>0) { @@ -393,9 +394,9 @@ public class MyRobot{ private boolean OnResultsScreen() throws IOException { //r.x-418, r.y-204 - ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png")); + /*ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png")); ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)),"png",new File("color2.png")); - ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png")); + ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png"));*/ Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0)); Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0)); Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0)); @@ -535,7 +536,11 @@ public class MyRobot{ public void actionPerformed(ActionEvent e) { //BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT))); //Buffered img ImageUtils.toCompatibleImage( - MYROBOT.refreshScreen(); + try { + MYROBOT.refreshScreen(); + } catch (IOException e2) { + e2.printStackTrace(); + } BufferedImage img = null; try { ImageIO.write(img=MYROBOT.createScreenCapture(new Rectangle(812,380,WIDTH,HEIGHT)),"png",new File("test.png")); @@ -549,7 +554,11 @@ public class MyRobot{ } } SongData.saveSongToFile(NEWSONGS[currentSong],col); - SongData.loadSongsFromFile(); + try { + SongData.loadSongsFromFile(); + } catch (IOException e1) { + e1.printStackTrace(); + } currentSong+=1; if (currentSong>=NEWSONGS.length) { System.out.println("DONE!"); @@ -619,6 +628,14 @@ public class MyRobot{ RunTest("test17.png",431,30,3,0,3,100.51f,"EXEX","HS",386,581700,false); RunTest("test18.png",427,86,5,1,4,92.45f,"EX","HS",136,526740,false); RunTest("test19.png",4,2,2,0,95,0.42f,"EXEX","HS",2,4130,true); + RunTest("test20.png",3,1,1,2,58,0.75f,"EX","HS",2,7810,true); + RunTest("test21.png",13,19,15,6,41,2.16f,"EX","HS",5,17860,true); + RunTest("test22.png",49,37,21,15,26,4.68f,"EX","HS",10,42210,true); + RunTest("test23.png",10,20,10,7,72,3.85f,"EXEX","HS",11,20050,true); + RunTest("test24.png",35,29,19,22,11,7.85f,"N","HD",17,29600,true); + RunTest("test25.png",175,75,13,10,32,50.84f,"E","SD",26,122670,false); + RunTest("test26.png",29,24,6,7,35,3.12f,"EXEX","HS",26,28100,true); + RunTest("test27.png",45,35,8,6,22,7.00f,"EX","HS",27,69780,true); RunTest("testimage.png",371,40,3,4,3,97.63f,"EX","HS",233,523750,false); RunTest("testimage2.png",942,71,1,0,3,97.02f,"EXEX","",714,951020,false); RunTest("testimage3.png",546,52,0,0,0,101.77f,"EX","",598,567430,false); @@ -689,12 +706,27 @@ public class MyRobot{ assert data.worst == _worst : "Expected worst count to be "+_worst+", got "+data.worst; assert data.percent == _percent : "Expected percent to be "+_percent+", got "+data.percent; assert data.fail == _fail : "Expected fail to be "+_fail+", got "+data.fail; - assert data.mod == _mod : "Expected mod to be "+_mod+", got "+data.mod; + assert data.mod.equals(_mod) : "Expected mod to be "+_mod+", got "+data.mod; assert data.difficulty == _difficulty : "Expected difficulty to be "+_difficulty+", got "+data.difficulty; assert data.combo == _combo : "Expected combo to be "+_combo+", got "+data.combo; assert data.score == _score : "Expected score to be "+_score+", got "+data.score; } catch(AssertionError e) { System.err.println("\t"+e.getMessage()+" "+"("+(System.currentTimeMillis()-startTime)+"ms)!"); + if (!debug) { + System.out.print("Automatically running in debug mode"); + FileUtils.deleteFile("debug"); + File f = new File("debug"); + f.mkdir(); + while (!f.exists()) { + try { + Thread.sleep(1000); + f.mkdir(); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + RunTest(_img,_cool,_fine,_safe,_sad,_worst,_percent,_difficulty,_mod,_combo,_score,_fail,true); + } System.exit(1); } System.out.println("\tPassed ("+(System.currentTimeMillis()-startTime)+"ms)!"); @@ -721,7 +753,8 @@ public class MyRobot{ MYROBOT = new CustomRobot(); MYROBOT.refreshScreen(); } catch (Exception e) { - JOptionPane.showOptionDialog(null, "Can't build the robot!", "Error", -1, 1, null, null, this); + e.printStackTrace(); + JOptionPane.showOptionDialog(null, e.getMessage(), "Error", -1, 1, null, null, this); System.exit(1); } X = SCREEN_X / 2; diff --git a/DivaBot/src/sig/Result.java b/DivaBot/src/sig/Result.java index 0533acc..4e5a256 100644 --- a/DivaBot/src/sig/Result.java +++ b/DivaBot/src/sig/Result.java @@ -33,6 +33,12 @@ public class Result { this.combo=combo; this.score=score; } + public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent,String mod,int combo, int score,boolean fail) { + this(song,diff,cool,fine,safe,sad,worst,percent,fail); + this.combo=combo; + this.score=score; + this.mod=mod; + } public String display() { return new StringBuilder(Integer.toString(cool)).append("/").append(fine) .append("/").append(safe).append("/").append(sad).append("/").append(worst).append(" ").append(percent).append("%") @@ -41,8 +47,9 @@ public class Result { public String displayDebug() { return new StringBuilder(Integer.toString(cool)).append(",").append(fine) .append(",").append(safe).append(",").append(sad).append(",").append(worst).append(",").append(percent).append("f") - .append(",\"").append(difficulty).append("\",\"").append(mod).append("\",").append(Boolean.toString(fail).toLowerCase()) - .append(",").append(combo).append(",").append(score).toString(); + .append(",\"").append(difficulty).append("\",\"").append(mod).append("\",").append(combo).append(",").append(score).append(",") + .append(Boolean.toString(fail).toLowerCase()) + .toString(); } public String toString() { return displayDebug(); diff --git a/DivaBot/src/sig/SongData.java b/DivaBot/src/sig/SongData.java index a798ea4..74b20e2 100644 --- a/DivaBot/src/sig/SongData.java +++ b/DivaBot/src/sig/SongData.java @@ -1,5 +1,6 @@ package sig; import java.awt.Color; +import java.io.IOException; import sig.utils.FileUtils; import sig.utils.ImageUtils; @@ -70,7 +71,7 @@ public class SongData { } FileUtils.logToFile(sb.toString(),"colorData"); } - public static void loadSongsFromFile() { + public static void loadSongsFromFile() throws IOException { String[] data = FileUtils.readFromFile("colorData"); MyRobot.SONGS = new SongData[data.length]; for (int i=0;iRECT_SEARCH_PCT.width) { int foundIndex = -1; @@ -268,7 +268,7 @@ public class TypeFace2 { xpointer=RECT_SEARCH_PCT2.x; ypointer=RECT_SEARCH_PCT2.y; trialloop: - while (ypointerRECT_SEARCH_PCT2.width) { int foundIndex = -1; @@ -401,7 +401,7 @@ public class TypeFace2 { ypointer=0; String total = ""; trialloop: - while (ypointer<4) { + while (ypointer<8) { xpointer=RECT_SEARCH_COOL.width-1; while (xpointer>22) { int distance = 0; @@ -491,7 +491,7 @@ public class TypeFace2 { ypointer=0; String total = ""; trialloop: - while (ypointer<4) { + while (ypointer<8) { xpointer=RECT_SEARCH_SCORE.width-1; while (xpointer>31) { int distance = 0; diff --git a/DivaBot/src/sig/utils/FileUtils.java b/DivaBot/src/sig/utils/FileUtils.java index 9e420ee..994329a 100644 --- a/DivaBot/src/sig/utils/FileUtils.java +++ b/DivaBot/src/sig/utils/FileUtils.java @@ -2,6 +2,7 @@ package sig.utils; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; @@ -34,27 +35,24 @@ import org.json.JSONException; import org.json.JSONObject; public class FileUtils { - public static String[] readFromFile(String filename) { + public static String[] readFromFile(String filename) throws IOException { File file = new File(filename); //System.out.println(file.getAbsolutePath()); List contents= new ArrayList(); if (file.exists()) { - try( - FileReader fw = new FileReader(filename); - BufferedReader bw = new BufferedReader(fw);) - { - String readline = bw.readLine(); + FileInputStream in = new FileInputStream(file); + InputStreamReader isr = new InputStreamReader(in,Charset.forName("UTF-8")); + BufferedReader br = new BufferedReader(isr); + String readline = br.readLine(); do { if (readline!=null) { //System.out.println(readline); contents.add(readline); - readline = bw.readLine(); + readline = br.readLine(); }} while (readline!=null); - fw.close(); - bw.close(); - } catch (IOException e) { - e.printStackTrace(); - } + br.close(); + isr.close(); + in.close(); } return contents.toArray(new String[contents.size()]); } @@ -272,8 +270,9 @@ public class FileUtils { } OutputStream out = new FileOutputStream(file,true); Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); + PrintWriter pw = new PrintWriter(writer); - + //pw.print('\uFEFF'); pw.println(message); pw.flush(); pw.close(); @@ -290,9 +289,10 @@ public class FileUtils { file.createNewFile(); } - FileWriter fw = new FileWriter(file,false); - PrintWriter pw = new PrintWriter(fw); - + OutputStream out = new FileOutputStream(file,true); + Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); + PrintWriter pw = new PrintWriter(writer); + pw.print('\uFEFF'); for (String s : data) { pw.println(s); } diff --git a/DivaBot/typeface.png b/DivaBot/typeface.png index dfca268..02940a6 100644 Binary files a/DivaBot/typeface.png and b/DivaBot/typeface.png differ diff --git a/DivaBot/typeface2.png b/DivaBot/typeface2.png index c55c7df..8f9561d 100644 Binary files a/DivaBot/typeface2.png and b/DivaBot/typeface2.png differ diff --git a/DivaBot/typeface3.png b/DivaBot/typeface3.png index 5b88023..8a12119 100644 Binary files a/DivaBot/typeface3.png and b/DivaBot/typeface3.png differ