@ -1,5 +1,10 @@
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
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 ;
import javax.imageio.ImageIO ;
@ -131,40 +136,45 @@ public class ArcadeReader {
final static int SDVX_B = 7 ;
final static int SDVX_B = 7 ;
final static int SDVX_C = 8 ;
final static int SDVX_C = 8 ;
final static int SDVX_D = 9 ;
final static int SDVX_D = 9 ;
static Reader interpret ( String filename ) {
static Reader interpret ( Path p ) {
BufferedImage img ;
try {
try {
BufferedImage img = ImageIO . read ( Paths . get ( "tests" , filename ) . toFile ( ) ) ;
img = ImageIO . read ( p . toFile ( ) ) ;
if ( img . getHeight ( ) > img . getWidth ( ) ) {
return interpret ( img ) ;
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 ( ) ;
}
}
} catch ( IOException e ) {
} catch ( IOException e ) {
e . printStackTrace ( ) ;
e . printStackTrace ( ) ;
}
}
return null ;
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 ) {
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 , "" ) ;
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 ) {
static void test ( String filename , Class < ? > reader , int score , int rank , int [ ] notes , int diff , double pct , int maxcombo , String other ) {
testCount + + ;
testCount + + ;
Reader r = interpret ( filename ) ;
Reader r = interpret ( Paths . get ( "tests" , filename ) ) ;
r . interpretBoxes ( Paths . get ( "tests" , filename ) , true ) ;
r . interpretBoxes ( Paths . get ( "tests" , filename ) , true ) ;
Reader compare = new TestReader ( score , rank , notes , diff , pct , maxcombo , other ) ;
Reader compare = new TestReader ( score , rank , notes , diff , pct , maxcombo , other ) ;
if ( ! reader . isInstance ( r ) ) {
if ( ! reader . isInstance ( r ) ) {
@ -175,6 +185,10 @@ public class ArcadeReader {
ArcadeReader . err ( new Exception ( "Test \"" + filename + "\" Failed:\nExpected:" + compare + "\nActual:" + r ) ) ;
ArcadeReader . err ( new Exception ( "Test \"" + filename + "\" Failed:\nExpected:" + compare + "\nActual:" + r ) ) ;
return ;
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 ( ) ;
ArcadeReader . success ( ) ;
}
}
@ -651,4 +665,86 @@ public class ArcadeReader {
21 /*maxcombo*/ ,
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*/ ) ;
"{\"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 < String , HashMap < String , List < String > > > DATA = sigPlace . SONG_DATABASE ;
HashMap < String , List < String > > SONG_DATA = DATA . getOrDefault ( newImg . getClass ( ) . getSimpleName ( ) , new HashMap < > ( ) ) ;
List < String > RECORDS = SONG_DATA . getOrDefault ( convertTitle ( newImg . getTitle ( ) ) , new ArrayList < > ( ) ) ;
boolean found = false ;
for ( int i = 0 ; i < RECORDS . size ( ) ; i + + ) {
String s = RECORDS . get ( i ) ;
int score = getScore ( s ) ;
if ( score < newImg . getScore ( ) ) {
//Insert here.
found = true ;
RECORDS . add ( i , newImg . toString ( ) ) ;
break ;
}
}
if ( ! found ) {
RECORDS . add ( newImg . toString ( ) ) ;
}
SONG_DATA . put ( convertTitle ( newImg . getTitle ( ) ) , RECORDS ) ;
DATA . put ( newImg . getClass ( ) . getSimpleName ( ) , SONG_DATA ) ;
System . out . println ( DATA ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
}
}