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. 29
      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,6 +163,7 @@ public class MyRobot{
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
@ -201,8 +202,8 @@ public class MyRobot{
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
gotoxy(800,64);
click();
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
@ -274,8 +275,8 @@ public class MyRobot{
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail));
SoundUtils.playSound("collect_item.wav");
gotoxy(800,64);
click();
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
@ -409,6 +410,10 @@ public class MyRobot{
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//572,453
//Red: 100-200, Blue: 200-255 Purple (EXEX)
//Red: 150-255, Green: < 50 Blue: < 50 (EX)
@ -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