diff --git a/ArcadeReader.java b/ArcadeReader.java index 024b984..a7fc82c 100644 --- a/ArcadeReader.java +++ b/ArcadeReader.java @@ -1,5 +1,10 @@ +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.regex.Pattern; import javax.imageio.ImageIO; @@ -131,40 +136,45 @@ public class ArcadeReader { final static int SDVX_B=7; final static int SDVX_C=8; final static int SDVX_D=9; - static Reader interpret(String filename) { + static Reader interpret(Path p) { + BufferedImage img; try { - BufferedImage img = ImageIO.read(Paths.get("tests",filename).toFile()); - if (img.getHeight()>img.getWidth()) { - return new SoundVoltexReader(); - } else { - Color col1 = new Color(img.getRGB(31, 41),true); - ColorRange range1 = new ColorRange(245,255,235,240,70,80); - Color col2 = new Color(img.getRGB(27, 1012),true); - ColorRange range2 = new ColorRange(245,255,160,170,195,205); - if (range1.colorInRange(col1)) { - return new PopnReader(); - } - if (col1.equals(Color.BLACK)) { - return new DDRReader(); - } - if (col1.equals(Color.WHITE)) { - return new ITGReader(); - } - if (range2.colorInRange(col2)) { - return new LoveLiveReader(); - } - } + img = ImageIO.read(p.toFile()); + return interpret(img); } catch (IOException e) { e.printStackTrace(); } return null; } + static Reader interpret(BufferedImage img) { + if (img.getHeight()>img.getWidth()) { + return new SoundVoltexReader(); + } else { + Color col1 = new Color(img.getRGB(31, 41),true); + ColorRange range1 = new ColorRange(245,255,235,240,70,80); + Color col2 = new Color(img.getRGB(27, 1012),true); + ColorRange range2 = new ColorRange(245,255,160,170,195,205); + if (range1.colorInRange(col1)) { + return new PopnReader(); + } + if (col1.equals(Color.BLACK)) { + return new DDRReader(); + } + if (col1.equals(Color.WHITE)) { + return new ITGReader(); + } + if (range2.colorInRange(col2)) { + return new LoveLiveReader(); + } + } + return null; + } static void test(String filename,Class reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo){ test(filename,reader,score,rank,notes,diff,pct,maxcombo,""); } static void test(String filename,Class reader,int score,int rank,int[] notes,int diff,double pct,int maxcombo,String other){ testCount++; - Reader r = interpret(filename); + Reader r = interpret(Paths.get("tests",filename)); r.interpretBoxes(Paths.get("tests",filename),true); Reader compare = new TestReader(score,rank,notes,diff,pct,maxcombo,other); if (!reader.isInstance(r)) { @@ -175,6 +185,10 @@ public class ArcadeReader { ArcadeReader.err(new Exception("Test \""+filename+"\" Failed:\nExpected:"+compare+"\nActual:"+r)); return; } + if (gamePath(r)==null) { + ArcadeReader.err(new Exception("Test \""+filename+"\" Failed:\nReason: gamePath for this reader type ("+r.getClass().getSimpleName()+") does not exist. Check the gamePath() function!")); + return; + } ArcadeReader.success(); } @@ -651,4 +665,86 @@ public class ArcadeReader { 21/*maxcombo*/, "{\"ex\":457,\"chip_scritical\":13,\"chip_critical\":15,\"chip_near\":31,\"chip_error\":201,\"long_scritical\":44,\"long_error\":241,\"vol_scritical\":91,\"vol_error\":272,\"failed\":true}"/*other*/); } + public static Path gamePath(Reader data) { + switch (data.getClass().getSimpleName()) { + case "DDRReader":{ + return Paths.get("database","ddr"); + } + case "ITGReader":{ + return Paths.get("database","itg"); + } + case "LoveLiveReader":{ + return Paths.get("database","lovelive"); + } + case "PopnReader":{ + return Paths.get("database","popn"); + } + case "SoundVoltexReader":{ + return Paths.get("database","sdvx"); + } + } + return null; + } + public static int getScore(String record) { + String searchString = "\"score\":"; + int index = record.indexOf(searchString)+searchString.length(); + int endIndex=record.indexOf(",",index); + return Integer.parseInt(record.substring(index,endIndex)); + } + public static String convertTitle(String str) { + return str.replaceAll(Pattern.quote("#"),"") + .replaceAll(Pattern.quote("%"),"") + .replaceAll(Pattern.quote("&"),"") + .replaceAll(Pattern.quote("{"),"") + .replaceAll(Pattern.quote("}"),"") + .replaceAll(Pattern.quote("\\"),"") + .replaceAll(Pattern.quote("<"),"") + .replaceAll(Pattern.quote(">"),"") + .replaceAll(Pattern.quote("*"),"") + .replaceAll(Pattern.quote("\""),"") + .replaceAll(Pattern.quote("?"),"") + .replaceAll(Pattern.quote("'"),"") + .replaceAll(Pattern.quote("/"),"") + .replaceAll(Pattern.quote("$"),"") + .replaceAll(Pattern.quote("!"),"") + .replaceAll(Pattern.quote(":"),"") + .replaceAll(Pattern.quote("@"),"") + .replaceAll(Pattern.quote("+"),"") + .replaceAll(Pattern.quote("`"),"") + .replaceAll(Pattern.quote("|"),"") + .replaceAll(Pattern.quote("="),""); + } + public static void submitToDatabase(Path p) { + //First we read and interpret what this image is. + BufferedImage img; + try { + img = ImageIO.read(p.toFile()); + Reader newImg = interpret(img); + Path getGamePath = gamePath(newImg); + newImg.interpretBoxes(p); + HashMap>> DATA = sigPlace.SONG_DATABASE; + HashMap> SONG_DATA=DATA.getOrDefault(newImg.getClass().getSimpleName(),new HashMap<>()); + List RECORDS = SONG_DATA.getOrDefault(convertTitle(newImg.getTitle()),new ArrayList<>()); + boolean found=false; + for (int i=0;i=990000) {rank=0;/*AAA*/} else if (score>=950000) {rank=1;/*AA+*/} else - if (score>=900000) {rank=2;/*AA*/} else - //if (score>=890000) {rank=3;/*AA-*/} else + if (score>=910000) {rank=2;/*AA*/} else + if (score>=900000) {rank=3;/*AA-*/} else if (score>=850000) {rank=4;/*A+*/} else - if (score>=800000) {rank=5;/*A*/} else - //if (score>=790000) {rank=6;/*A-*/} else + if (score>=810000) {rank=5;/*A*/} else + if (score>=800000) {rank=6;/*A-*/} else if (score>=750000) {rank=7;/*B+*/} else - if (score>=700000) {rank=8;/*B*/} else - //if (score>=690000) {rank=9;/*B-*/} else + if (score>=710000) {rank=8;/*B*/} else + if (score>=700000) {rank=9;/*B-*/} else if (score>=650000) {rank=10;/*C+*/} else - if (score>=600000) {rank=11;/*C*/} else - //if (score>=590000) {rank=12;/*C-*/} else + if (score>=610000) {rank=11;/*C*/} else + if (score>=600000) {rank=12;/*C-*/} else if (score>=550000) {rank=13;/*D+*/} else {rank=14;/*D*/} }break; diff --git a/readers/Reader.java b/readers/Reader.java index 02d3f2e..f519e0c 100644 --- a/readers/Reader.java +++ b/readers/Reader.java @@ -258,7 +258,7 @@ public abstract class Reader{ }; String convertToString(String[]data){ - return String.join("\n",data).replaceFirst(Pattern.quote("\n"),""); + return String.join(" ",data).replaceFirst(Pattern.quote(" "),""); } double convertToDouble(String[]data){return convertToDouble("",data);} @@ -339,6 +339,54 @@ public abstract class Reader{ + ", \"other\":" + other + ", \"pct\":" + pct + ", \"rank\":" + rank + ", \"score\":" + score + ", \"title\":\"" + title.replaceAll(Pattern.quote("\n"),"\\\\n") + "\"}"; } + public int getScore() { + return score; + } + public void setScore(int score) { + this.score = score; + } + public int getRank() { + return rank; + } + public void setRank(int rank) { + this.rank = rank; + } + public int[] getNotes() { + return notes; + } + public void setNotes(int[] notes) { + this.notes = notes; + } + public int getDifficulty() { + return difficulty; + } + public void setDifficulty(int difficulty) { + this.difficulty = difficulty; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public double getPct() { + return pct; + } + public void setPct(double pct) { + this.pct = pct; + } + public int getMaxcombo() { + return maxcombo; + } + public void setMaxcombo(int maxcombo) { + this.maxcombo = maxcombo; + } + public String getOther() { + return other; + } + public void setOther(String other) { + this.other = other; + } @Override public int hashCode() { final int prime = 31; diff --git a/result.png b/result.png index 46e0142..87be958 100644 Binary files a/result.png and b/result.png differ diff --git a/sigPlace.java b/sigPlace.java index 2d56ed7..632a3b3 100644 --- a/sigPlace.java +++ b/sigPlace.java @@ -36,6 +36,8 @@ public class sigPlace { static int PORT = 8080; static String SECRET = ""; + final static HashMap>> SONG_DATABASE = new HashMap<>(); + static double COLOR_ROTATION = 0; static boolean inCodeBlock = false; @@ -118,10 +120,12 @@ public class sigPlace { e.printStackTrace(); }*/ //new PopnReader().interpretBoxes(Paths.get("tests","popn8.png"),true); - ArcadeReader.runTests(); - PopnReader p = new PopnReader(); - p.interpretBoxes(Paths.get("tests","popn8.png")); - System.out.println(p); + //ArcadeReader.runTests(); + BufferedImage img; + ArcadeReader.submitToDatabase(Paths.get("tests","popn8.png")); + ArcadeReader.submitToDatabase(Paths.get("tests","popn7.png")); + ArcadeReader.submitToDatabase(Paths.get("tests","popn6.png")); + ArcadeReader.submitToDatabase(Paths.get("tests","popn5.png")); /* Path secretFile = Paths.get(".clientsecret"); List data; try { diff --git a/sub.png b/sub.png index 2630e77..5ec5e12 100644 Binary files a/sub.png and b/sub.png differ