Refactor for new stream layout

secondmonitor
sigonasr2 4 years ago
parent 3d37343311
commit 76aa65c49e
  1. 13
      DivaBot/colorData
  2. 21
      DivaBot/src/sig/DrawCanvas.java
  3. 455
      DivaBot/src/sig/MyRobot.java
  4. 18
      DivaBot/src/sig/SongData.java
  5. 4
      DivaBot/src/sig/utils/ImageUtils.java

File diff suppressed because one or more lines are too long

@ -6,6 +6,8 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.font.TextAttribute;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
@ -29,7 +31,7 @@ import sig.utils.FileUtils;
import sig.utils.ImageUtils;
import sig.utils.TextUtils;
public class DrawCanvas extends JPanel{
public class DrawCanvas extends JPanel implements KeyListener{
String difficulty;
String panelText;
Font programFont = new Font("Open Sans Condensed", Font.PLAIN, 32);
@ -187,4 +189,21 @@ public class DrawCanvas extends JPanel{
g2.drawImage(overallbar, 1349, 0,null);
//System.out.println(System.currentTimeMillis()-startTime+"ms");
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println(e.getKeyChar());
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
}

@ -73,7 +73,7 @@ import sig.utils.SoundUtils;
import sig.utils.WebUtils;
public class MyRobot{
static Robot MYROBOT;
static CustomRobot MYROBOT;
Color SCREEN[][];
static SongData SONGS[];
static String SONGNAMES[] = new String[] {"Yellow","The secret garden","Tell Your World","愛言葉","Weekender Girl","歌に形はないけれど","えれくとりっく・えんじぇぅ","神曲","カンタレラ","巨大少女","クローバー♣クラブ","恋スルVOC@LOID","桜ノ雨","39","深海シティアンダーグラウンド","深海少女","積乱雲グラフィティ","千年の独奏歌","ダブルラリアット","ハジメテノオト","初めての恋が終わる時","packaged","Palette","FREELY TOMORROW","from Y to Y","みくみくにしてあげる♪","メルト","モノクロ∞ブルースカイ","ゆめゆめ","16 -out of the gravity-","ACUTE","インタビュア","LOL -lots of laugh-","Glory 3usi9","soundless voice","ジェミニ","白い雪のプリンセスは","スキキライ","タイムマシン","Dear","DECORATOR","トリコロール・エア・ライン","Nostalogic","Hand in Hand","Fire◎Flower","ブラック★ロックシューター","メテオ","ワールドイズマイン","アマツキツネ","erase or zero","エレクトロサチュレイタ","on the rocks","からくりピエロ","カラフル×メロディ","Catch the Wave","キャットフード","サマーアイドル","shake it!","Just Be Friends","スイートマジック","SPiCa -39's Giving Day Edition-","番凩","テレカクシ思春期","天樂","どういうことなの!?","東京テディベア","どりーみんチュチュ","トリノコシティ","ネトゲ廃人シュプレヒコール","No Logic","ハイハハイニ","はじめまして地球人さん","*ハロー、プラネット。 (I.M.PLSE-EDIT)","Hello, Worker","忘却心中","magnet","右肩の蝶","結ンデ開イテ羅刹ト骸","メランコリック","リモコン","ルカルカ★ナイトフィーバー","炉心融解","WORLD'S END UMBRELLA","アカツキアライヴァル","アゲアゲアゲイン","1925","え?あぁ、そう。","エイリアンエイリアン","ODDS&ENDS","君の体温","こっち向いて Baby","壊セ壊セ","39みゅーじっく!","サンドリヨン","SING&SMILE","スノーマン","DYE","なりすましゲンガー","ヒバナ","ヒビカセ","ブラックゴールド","ミラクルペイント","指切り","ありふれたせかいせいふく","アンハッピーリフレイン","大江戸ジュリアナイト","ゴーストルール","こちら、幸福安心委員会です。","孤独の果て -extend edition-","ジターバグ","Sweet Devil","砂の惑星","テオ","初音ミクの消失 -DEAD END-","秘密警察","妄想スケッチ","リンちゃんなう!","ローリンガール","ロキ","ロミオとシンデレラ","エンヴィキャットウォーク","骸骨楽団とリリア","サイハテ","ジグソーパズル","千本桜","ピアノ×フォルテ×スキャンダル","Blackjack","ぽっぴっぽー","裏表ラバーズ","Sadistic.Music∞Factory","デンパラダイム","二次元ドリームフィーバー","ネガポジ*コンティニューズ","初音ミクの激唱","ワールズエンド・ダンスホール","ココロ","システマティック・ラヴ","Knife","二息歩行","PIANOGIRL","夢喰い白黒バク","ブレス・ユア・ブレス","恋は戦争","あなたの歌姫","Starduster","StargazeR","リンリンシグナル","Rosary Pale","多重未来のカルテット~QUARTET THEME~","LIKE THE WIND","AFTER BURNER"};
@ -163,120 +163,21 @@ public class MyRobot{
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
p.repaint(0, 0, 1400, 100);
}
GetCurrentSong();
GetCurrentDifficulty();
recordedResults=false;
if (selectedSong!=null && difficulty!=null) {
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
p.pullData(selectedSong.title,difficulty);
prevSongTitle=selectedSong.title;
prevDifficulty=difficulty;
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
try {
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
p.repaint(0, 0, 1400, 100);
}
}
lastSongSelectTime = System.currentTimeMillis();
} else {
if (overlayHidden) {
overlayHidden=false;
p.repaint(0, 0, 1400, 100);
}
/*selectedSong=new SongData("test",new Color[] {});
difficulty="EXEX";*/
if ((selectedSong!=null && difficulty!=null) /*|| true*/) {
//Look for the results screen.
//602,217 254,254,254
//602,260 16,222,202
//901,460 220-255,220-255,160-220
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
gotoxy(800,64);
click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
//1885,761
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,451,115,26))));
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,484,115,26))));
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,518,115,26))));
//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))));
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"));
boolean fail = textFailPixel(MYROBOT.createScreenCapture(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;
if (cool==-1 || fine==-1 || safe==-1 || sad==-1 || worst==-1 || percent==-0.01f) {
System.out.println("Waiting for results to populate...");
} else
if (fail!=lastfail || cool!=lastcool || lastfine!=fine || lastsafe!=safe || lastsad!=sad || lastworst!=worst /*|| lastpercent!=percent*/){
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+cool+"/"+fine+"/"+safe+"/"+sad+"/"+worst+" "+percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+cool+"/"+fine+"/"+safe+"/"+sad+"/"+worst+" "+percent+"%");
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
File[] songFolderFiles = songFolder.listFiles();
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;
lastsafe=safe;
lastsad=sad;
lastworst=worst;
lastpercent=percent;
lastfail=fail;
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail));
SoundUtils.playSound("collect_item.wav");
gotoxy(800,64);
click();
MYROBOT.setAutoDelay(0);
GetCurrentSong();
GetCurrentDifficulty();
recordedResults=false;
if (selectedSong!=null && difficulty!=null) {
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
p.pullData(selectedSong.title,difficulty);
prevSongTitle=selectedSong.title;
prevDifficulty=difficulty;
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
@ -284,130 +185,234 @@ public class MyRobot{
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
} else {
if (results.size()>0) {
recordingResults=true;
for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("song", r.songName));
params.add(new BasicNameValuePair("username", "sigonasr2"));
params.add(new BasicNameValuePair("authentication_token", "sig"));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", "HS"));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
lastSongSelectTime = System.currentTimeMillis();
} else {
if (overlayHidden) {
overlayHidden=false;
p.repaint(0, 0, 1400, 100);
}
/*selectedSong=new SongData("test",new Color[] {});
difficulty="EXEX";*/
if ((selectedSong!=null && difficulty!=null) /*|| true*/) {
//Look for the results screen.
//602,217 254,254,254
//602,260 16,222,202
//901,460 220-255,220-255,160-220
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
//1885,761
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,451,115,26))));
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,484,115,26))));
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,518,115,26))));
//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))));
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"));
boolean fail = textFailPixel(MYROBOT.createScreenCapture(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;
if (cool==-1 || fine==-1 || safe==-1 || sad==-1 || worst==-1 || percent==-0.01f) {
System.out.println("Waiting for results to populate...");
} else
if (fail!=lastfail || cool!=lastcool || lastfine!=fine || lastsafe!=safe || lastsad!=sad || lastworst!=worst /*|| lastpercent!=percent*/){
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+cool+"/"+fine+"/"+safe+"/"+sad+"/"+worst+" "+percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+cool+"/"+fine+"/"+safe+"/"+sad+"/"+worst+" "+percent+"%");
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
//Execute and get the response.
HttpResponse response = null;
File[] songFolderFiles = songFolder.listFiles();
int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir();
try {
response = httpclient.execute(httppost);
/*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();
}
HttpEntity entity = response.getEntity();
recordedResults=true;
lastcool=cool;
lastfine=fine;
lastsafe=safe;
lastsad=sad;
lastworst=worst;
lastpercent=percent;
lastfail=fail;
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail));
SoundUtils.playSound("collect_item.wav");
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
} else {
if (results.size()>0) {
recordingResults=true;
for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("song", r.songName));
params.add(new BasicNameValuePair("username", "sigonasr2"));
params.add(new BasicNameValuePair("authentication_token", "sig"));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", "HS"));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
}
}
results.clear();
results.clear();
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
p.lastRating = p.overallrating;
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
/*MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_ALT);
MYROBOT.keyPress(KeyEvent.VK_TAB);
MYROBOT.keyRelease(KeyEvent.VK_ALT);
MYROBOT.setAutoDelay(5000);
MYROBOT.keyRelease(KeyEvent.VK_TAB);
boolean first=true;
for (Result r : results) {
if (!first) {
MYROBOT.setAutoDelay(5000);
} else {
first=false;
MYROBOT.setAutoDelay(100);
TYPE_DELAY=50;
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
p.lastRating = p.overallrating;
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
StringSelection selection = new StringSelection((r.songName.equalsIgnoreCase("PIANOGIRL"))?"PIANO*GIRL":r.songName);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_V);
MYROBOT.keyRelease(KeyEvent.VK_V);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
MYROBOT.setAutoDelay(100);
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.cool));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.fine));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.safe));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.sad));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.worst));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(r.difficulty);
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Float.toString(r.percent));
/*MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_ALT);
MYROBOT.keyPress(KeyEvent.VK_TAB);
MYROBOT.keyRelease(KeyEvent.VK_ALT);
MYROBOT.setAutoDelay(5000);
MYROBOT.keyRelease(KeyEvent.VK_TAB);
boolean first=true;
for (Result r : results) {
if (!first) {
MYROBOT.setAutoDelay(5000);
} else {
first=false;
MYROBOT.setAutoDelay(100);
TYPE_DELAY=50;
}
StringSelection selection = new StringSelection((r.songName.equalsIgnoreCase("PIANOGIRL"))?"PIANO*GIRL":r.songName);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_V);
MYROBOT.keyRelease(KeyEvent.VK_V);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
MYROBOT.setAutoDelay(100);
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.cool));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.fine));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.safe));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.sad));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Integer.toString(r.worst));
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(r.difficulty);
MYROBOT.keyPress(KeyEvent.VK_TAB);
type(Float.toString(r.percent));
MYROBOT.keyPress(KeyEvent.VK_TAB);
MYROBOT.keyRelease(KeyEvent.VK_TAB);
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_ALT);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_1);
MYROBOT.keyRelease(KeyEvent.VK_1);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
MYROBOT.keyRelease(KeyEvent.VK_ALT);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
}
results.clear();
sleep(1000);
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_ALT);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_1);
MYROBOT.keyRelease(KeyEvent.VK_1);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_TAB);
MYROBOT.keyRelease(KeyEvent.VK_ALT);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.setAutoDelay(250);
MYROBOT.keyRelease(KeyEvent.VK_TAB);
*/
recordingResults=false;
}
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
results.clear();
sleep(1000);
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_ALT);
MYROBOT.keyPress(KeyEvent.VK_TAB);
MYROBOT.keyRelease(KeyEvent.VK_ALT);
MYROBOT.setAutoDelay(250);
MYROBOT.keyRelease(KeyEvent.VK_TAB);
*/
recordingResults=false;
}
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//572,453
//Red: 100-200, Blue: 200-255 Purple (EXEX)
@ -436,7 +441,7 @@ public class MyRobot{
difficulty="H";
}
}
private void GetCurrentSong() {
private void GetCurrentSong() throws IOException {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)));
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
@ -444,6 +449,8 @@ public class MyRobot{
col[i*HEIGHT+j]=new Color(img.getRGB(i,j),true);
}
}
/*File f = new File("test.png");
ImageIO.write(img,"png",f);*/
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
@ -497,9 +504,10 @@ public class MyRobot{
e1.printStackTrace();
}
/*InputMap inputMap = p.getInputMap(condition);
InputMap inputMap = p.getInputMap(condition);
ActionMap actionMap = p.getActionMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "Press");
actionMap.put("Press", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
@ -515,7 +523,7 @@ public class MyRobot{
System.out.println((++currentSong>=NEWSONGS.length)?"DONE!":NEWSONGS[currentSong]);
//System.out.println(title.getText());
}
});*/
});
/*inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "Press"); //DEBUG KEYS.
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "Identifier");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), "Toggle");*/
@ -670,9 +678,10 @@ public class MyRobot{
System.out.println(" Passed ("+(System.currentTimeMillis()-startTime)+"ms)!");
}
public static boolean checkSongSelect() {
public static boolean checkSongSelect() throws IOException {
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(1255,824,20,20)).getRGB(10, 10));
onSongSelect = c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
System.out.println(onSongSelect+"/"+c);
return onSongSelect;
}
@ -687,7 +696,7 @@ public class MyRobot{
updateScreenInfo();
setKeyMap();
try {
MYROBOT = new Robot();
MYROBOT = new CustomRobot();
} catch (Exception e) {
JOptionPane.showOptionDialog(null, "Can't build the robot!", "Error", -1, 1, null, null, this);
System.exit(1);

@ -2,6 +2,7 @@ package sig;
import java.awt.Color;
import sig.utils.FileUtils;
import sig.utils.ImageUtils;
public class SongData {
String title;
@ -22,21 +23,20 @@ public class SongData {
}
public static SongData compareData(Color[] data) {
int closestDistance = Integer.MAX_VALUE;
SongData closestSong = null;
for (SongData s : MyRobot.SONGS) {
int matched = 0;
int distance = 0;
for (int i=0;i<s.songCode.length;i++) {
if (data[i].equals(s.songCode[i])) {
matched++;
}
distance += ImageUtils.distanceToColor(s.songCode[i],data[i]);
}
if (matched/(double)s.songCode.length>=TOLERANCE) {
//System.out.println(matched+"/"+s.songCode.length+" pixels matched for song "+s.title);
return s;
} else {
if (distance<closestDistance) {
//System.out.println(matched+"/"+s.songCode.length+" pixels matched for song "+s.title);
closestSong=s;
closestDistance=distance;
}
}
return null;
return closestSong;
}
public static void saveSongToFile(String title, Color[] data) {

@ -1,5 +1,6 @@
package sig.utils;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
@ -111,4 +112,7 @@ public class ImageUtils {
// Return the buffered image
return bimage;
}
public static double distanceToColor(Color p2, Color p1) {
return Math.sqrt(Math.pow(p2.getRed()-p1.getRed(), 2)+Math.pow(p2.getGreen()-p1.getGreen(), 2)+Math.pow(p2.getBlue()-p1.getBlue(), 2));
}
}

Loading…
Cancel
Save