diff --git a/DivaBot/.gitignore b/DivaBot/.gitignore index 6413e54..e8276ca 100644 --- a/DivaBot/.gitignore +++ b/DivaBot/.gitignore @@ -11,3 +11,5 @@ /39/ /1925/ /39みゅーじっく!/ +*.png +!/*.png \ No newline at end of file diff --git a/DivaBot/rectangle0.png b/DivaBot/rectangle0.png new file mode 100644 index 0000000..41ff5ef Binary files /dev/null and b/DivaBot/rectangle0.png differ diff --git a/DivaBot/rectangle1.png b/DivaBot/rectangle1.png new file mode 100644 index 0000000..4e6a7f8 Binary files /dev/null and b/DivaBot/rectangle1.png differ diff --git a/DivaBot/rectangle2.png b/DivaBot/rectangle2.png new file mode 100644 index 0000000..4b214e1 Binary files /dev/null and b/DivaBot/rectangle2.png differ diff --git a/DivaBot/rectangle3.png b/DivaBot/rectangle3.png new file mode 100644 index 0000000..3e88fe4 Binary files /dev/null and b/DivaBot/rectangle3.png differ diff --git a/DivaBot/rectangle4.png b/DivaBot/rectangle4.png new file mode 100644 index 0000000..020f9d1 Binary files /dev/null and b/DivaBot/rectangle4.png differ diff --git a/DivaBot/src/sig/CustomRobot.java b/DivaBot/src/sig/CustomRobot.java new file mode 100644 index 0000000..265be64 --- /dev/null +++ b/DivaBot/src/sig/CustomRobot.java @@ -0,0 +1,43 @@ +package sig; + +import java.awt.AWTException; +import java.awt.GraphicsDevice; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import sig.utils.ImageUtils; + +public class CustomRobot extends Robot{ + + BufferedImage currentScreen; + BufferedImage scoreCurrentScreen; + + public CustomRobot() throws AWTException { + super(); + } + + public CustomRobot(GraphicsDevice screen) throws AWTException { + super(screen); + } + + public void refreshScreen() { + currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83)); + } + public void refreshScoreScreen() { + scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23,204+85,912-18,586-83)); + } + + public synchronized BufferedImage createScreenCapture(Rectangle r) { + BufferedImage img2 = ImageUtils.toBufferedImage(currentScreen.getScaledInstance(1227, 690, BufferedImage.SCALE_AREA_AVERAGING)); + return img2.getSubimage(r.x-418, r.y-204, r.width, r.height); + } + public synchronized BufferedImage createNormalScreenCapture(Rectangle r) { + return currentScreen.getSubimage((int)((r.x-418)*(894d/1227)), (int)((r.y-204)*(503d/690)), (int)Math.ceil(r.width*(894d/1227)), (int)Math.ceil(r.height*(503d/690))); + //return super.createScreenCapture(new Rectangle(r.x-418,r.y-204,912-18,586-83)); + } +} diff --git a/DivaBot/src/sig/DrawCanvas.java b/DivaBot/src/sig/DrawCanvas.java index 25db34a..9b14741 100644 --- a/DivaBot/src/sig/DrawCanvas.java +++ b/DivaBot/src/sig/DrawCanvas.java @@ -57,7 +57,9 @@ public class DrawCanvas extends JPanel implements KeyListener{ BufferedImage overallbar; BufferedImage panel,paneloverlay,songpanel,songpaneloverlay; long ratingTime = System.currentTimeMillis()-10000; + long bestPlayTime = System.currentTimeMillis()-10000; int lastRating = -1; + double lastScore = 0d; Thread t = null; boolean scrolling = false; int scrollX = 0; @@ -111,7 +113,7 @@ public class DrawCanvas extends JPanel implements KeyListener{ passes=0; fcCount=0; artist=""; - this.repaint(0,0,1400,100); + this.repaint(0,0,1400,1000); if (t!=null && t.isAlive()) { t.stop(); } @@ -132,6 +134,7 @@ public class DrawCanvas extends JPanel implements KeyListener{ JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty); if (obj.has("cool")) { bestPlay = new Result(MyRobot.p.songname,difficulty,obj.getInt("cool"),obj.getInt("fine"),obj.getInt("safe"),obj.getInt("sad"),obj.getInt("worst"),(float)obj.getDouble("percent")); + lastScore = obj.getDouble("score"); } else { bestPlay = null; } @@ -182,11 +185,21 @@ public class DrawCanvas extends JPanel implements KeyListener{ g2.drawImage(panel, 484,935,null); g2.drawImage(panel, 968,935,null); - DrawUtils.drawOutlineText(g2, programFont, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), ((romanizedname.length()>0)?romanizedname:englishname)); - - DrawUtils.drawOutlineText(g2, programFontSmall, 8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),((bestPlay!=null)?bestPlay.display():"")); + String songDisplay = ((romanizedname.length()>0)?romanizedname:englishname) + " - " + artist; + Rectangle2D bounds = TextUtils.calculateStringBoundsFont(songDisplay, programFont); + if (bounds.getWidth()>675) { + DrawUtils.drawOutlineText(g2, programFontSmall, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay); + } else { + DrawUtils.drawOutlineText(g2, programFont, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay); + } + + if ((bestPlayTime>System.currentTimeMillis()-10000)) { + DrawUtils.drawOutlineText(g2, programFont, 8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-bestPlayTime))/5,255)), new Color(0,0,0,64),"New Record!"); + } else { + DrawUtils.drawOutlineText(g2, programFontSmall, 8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),((bestPlay!=null)?bestPlay.display():"")); + } if ((ratingTime>System.currentTimeMillis()-10000)) { - DrawUtils.drawOutlineText(g2, programFont, 484+8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64),"Rating up! "+lastRating+" -> "+overallrating); + DrawUtils.drawOutlineText(g2, programFontSmall, 484+8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64),"Rating up! "+lastRating+" -> "+overallrating); } else { DrawUtils.drawOutlineText(g2, programFont, 484+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),Integer.toString(overallrating)); } diff --git a/DivaBot/src/sig/Filter.java b/DivaBot/src/sig/Filter.java new file mode 100644 index 0000000..29ffcf1 --- /dev/null +++ b/DivaBot/src/sig/Filter.java @@ -0,0 +1,22 @@ +package sig; + +import java.awt.Color; +import java.awt.Point; + +public class Filter { + Point red_threshold; + Point green_threshold; + Point blue_threshold; + + public Filter(Point red_threshold, Point green_threshold, Point blue_threshold) { + this.red_threshold = red_threshold; + this.green_threshold = green_threshold; + this.blue_threshold = blue_threshold; + } + + public boolean isWithinThreshold(Color c) { + return c.getRed()>=red_threshold.x && c.getRed()<=red_threshold.y && + c.getGreen()>=green_threshold.x && c.getGreen()<=green_threshold.y && + c.getBlue()>=blue_threshold.x && c.getBlue()<=blue_threshold.y; + } +} diff --git a/DivaBot/src/sig/MyRobot.java b/DivaBot/src/sig/MyRobot.java index 974ac63..f4c1341 100644 --- a/DivaBot/src/sig/MyRobot.java +++ b/DivaBot/src/sig/MyRobot.java @@ -30,6 +30,8 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.text.AttributedString; import java.util.ArrayList; import java.util.Arrays; @@ -115,7 +117,7 @@ public class MyRobot{ boolean lastfail; long lastSongSelectTime = System.currentTimeMillis(); - static TypeFace typeface1,typeface2; + static TypeFace2 typeface1,typeface2; static Thread t = null; String prevSongTitle = ""; @@ -208,7 +210,7 @@ public class MyRobot{ //602,260 16,222,202 //901,460 220-255,220-255,160-220 - if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) { + if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0 && false) { lastSongSelectTime=System.currentTimeMillis(); //gotoxy(800,64); //click(); @@ -226,25 +228,27 @@ public class MyRobot{ //System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,553,115,26)))); //System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)))); //System.out.println(typeface2.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1428,361,128,30)))); + ImageIO.write(MYROBOT.createNormalScreenCapture(new Rectangle(418,204,1227,690)),"png",new File("scoreimage.png")); File tmp = new File("tmp"); if (tmp.exists()) { FileUtils.deleteFile(tmp); } else { tmp.mkdir(); } - int cool = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,451,115,26)),new File(tmp,"cool")); - int fine = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,484,115,26)),new File(tmp,"fine")); - int safe = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,518,115,26)),new File(tmp,"safe")); - int sad = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,553,115,26)),new File(tmp,"sad")); - int worst = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),new File(tmp,"worst")); + int cool = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,451,115,26)),new File(tmp,"cool")); + int fine = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,484,115,26)),new File(tmp,"fine")); + int safe = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,518,115,26)),new File(tmp,"safe")); + int sad = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,553,115,26)),new File(tmp,"sad")); + int worst = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,583,115,26)),new File(tmp,"worst")); - boolean fail = textFailPixel(MYROBOT.createScreenCapture(new Rectangle(952,385,1,1))); + boolean fail = textFailPixel(MYROBOT.createNormalScreenCapture(new Rectangle(952,385,1,1))); /*try { ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),"png",new File("worst.png")); } catch (IOException e) { e.printStackTrace(); }*/ - float percent = (float)typeface2.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1428,361,128,30)),new File(tmp,"percent"))/100f; + float percent = (float)typeface2.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1428,361,128,30)),new File(tmp,"percent"))/100f; + ImageIO.write(MYROBOT.createNormalScreenCapture(new Rectangle(418,204,1227,690)),"png",new File("test.png")); if (cool==-1 || fine==-1 || safe==-1 || sad==-1 || worst==-1 || percent==-0.01f) { System.out.println("Waiting for results to populate..."); } else @@ -260,18 +264,6 @@ public class MyRobot{ int playId = songFolderFiles.length; File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId); playFolder.mkdir(); - try { - /*FileUtils.copyFileDir(new File(tmp,"cool"), new File(playFolder,"cool")); - FileUtils.copyFileDir(new File(tmp,"fine"), new File(playFolder,"fine")); - FileUtils.copyFileDir(new File(tmp,"safe"), new File(playFolder,"safe")); - FileUtils.copyFileDir(new File(tmp,"sad"), new File(playFolder,"sad")); - FileUtils.copyFileDir(new File(tmp,"worst"), new File(playFolder,"worst")); - FileUtils.copyFileDir(new File(tmp,"percent"), new File(playFolder,"percent"));*/ - //FileUtils.deleteFile(tmp); - ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(418,204,1227,690)),"png",new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+cool+"_"+fine+"_"+safe+"_"+sad+"_"+worst+"_"+percent+".png")); - } catch (IOException e) { - e.printStackTrace(); - } recordedResults=true; lastcool=cool; lastfine=fine; @@ -280,7 +272,7 @@ public class MyRobot{ lastworst=worst; lastpercent=percent; lastfail=fail; - + new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+cool+"_"+fine+"_"+safe+"_"+sad+"_"+worst+"_"+percent+".png")); results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail)); SoundUtils.playSound("collect_item.wav"); //gotoxy(800,64); @@ -345,7 +337,15 @@ public class MyRobot{ try { JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2"); + JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty); p.lastRating = p.overallrating; + if (obj2.has("score")) { + double newScore = obj2.getDouble("score"); + if (newScore>p.lastScore) { + p.bestPlayTime=System.currentTimeMillis(); + } + p.lastScore = newScore; + } p.overallrating = (int)obj.getDouble("rating"); if (p.lastRating