get level length

This commit is contained in:
potzplitz 2024-05-11 22:39:19 +02:00
parent 4ccdb53aa0
commit a80723c695
9 changed files with 73 additions and 107 deletions

20
pom.xml
View file

@ -17,21 +17,11 @@
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20231013</version> <version>20231013</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.7</version> <version>2.7</version>
</dependency> </dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>3.4</version>
</dependency>
<dependency> <dependency>
<groupId>com.alex1304.jdash</groupId> <groupId>com.alex1304.jdash</groupId>
<artifactId>jdash-client</artifactId> <artifactId>jdash-client</artifactId>
@ -57,15 +47,15 @@
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
<version>1.15</version> <version>1.15</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
<dependency> <dependency>
<groupId>org.kohsuke</groupId> <groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId> <artifactId>github-api</artifactId>
<version>1.127</version> <version>1.127</version>
</dependency>
<dependency>
<groupId>io.qtjambi</groupId>
<artifactId>qtjambi</artifactId>
<version>6.7.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View file

@ -14,6 +14,7 @@ import javax.swing.JTextArea;
import api.GetApiData; import api.GetApiData;
import gui.MainGUI; import gui.MainGUI;
import readsafefile.SafeFileManager;
import settingsfunctions.LoadSettings; import settingsfunctions.LoadSettings;
import settingsfunctions.MigrateData; import settingsfunctions.MigrateData;
@ -98,9 +99,6 @@ public class DownloadLevels {
MigrateData migrate = new MigrateData(); MigrateData migrate = new MigrateData();
migrate.migrateData(); migrate.migrateData();
RequestLevelLength req = new RequestLevelLength();
req.request();
try { try {
gui.build(); gui.build();
} catch (IOException e) { } catch (IOException e) {

View file

@ -1,51 +0,0 @@
package data;
import api.GetApiData;
import database.Sqlite;
import gui.LoadingStatus;
public class RequestLevelLength {
GetApiData data = new GetApiData();
FetchData fetch = new FetchData();
Sqlite sql = new Sqlite("levels");
LoadingStatus status = new LoadingStatus();
public void request() {
sql.queryData("levels");
status.initialize();
status.changeState("API wird auf Levellänge abgefragt...");
Thread thread = new Thread(new Runnable( ) {
@Override
public void run() {
for(int i = 0; i < ManageFiles.getMissinglevels().size(); i++) {
status.update(sql.getLevelname().get(sql.getRawLevelNames().indexOf(sql.getRawLevelNames().get(i))), i);
sql.modifyData(sql.getLevelname().get(sql.getRawLevelNames().indexOf(sql.getRawLevelNames().get(i))),
Boolean.parseBoolean(sql.getCompleted().get(i).toString()),
sql.getAttempts().get(i).intValue(),
sql.getLocked().get(i).booleanValue(),
sql.getPbarr().get(i),
"" + data.getLevelLength(Integer.parseInt(sql.getLevelID().get(sql.getRawLevelNames().indexOf(ManageFiles.getMissinglevels().get(i)))))
);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
thread.start();
}
}

View file

@ -214,7 +214,7 @@ public class Sqlite {
status = LoadingStatus.getInstance(); // Holen der Singleton-Instanz status = LoadingStatus.getInstance(); // Holen der Singleton-Instanz
status.initialize(); status.initialize();
status.changeState("Datenbank wird sortiert...");
ArrayList<String> levelnamelocal = new ArrayList<String>(); ArrayList<String> levelnamelocal = new ArrayList<String>();
ArrayList<String> levelIDlocal = new ArrayList<String>(); ArrayList<String> levelIDlocal = new ArrayList<String>();
@ -248,6 +248,8 @@ status = LoadingStatus.getInstance(); // Holen der Singleton-Instanz
int index = 0; int index = 0;
status.changeState("Datenbank wird sortiert...", maxPlacement);
// Durchlaufen Sie die Platzierungen und holen Sie die Daten entsprechend // Durchlaufen Sie die Platzierungen und holen Sie die Daten entsprechend
for (int i = 1; i <= maxPlacement; i++) { for (int i = 1; i <= maxPlacement; i++) {
String sql = "SELECT * FROM " + tablename + " WHERE placement = " + i; String sql = "SELECT * FROM " + tablename + " WHERE placement = " + i;
@ -278,7 +280,7 @@ status = LoadingStatus.getInstance(); // Holen der Singleton-Instanz
// Erstelle eine neue Tabelle mit dem ursprünglichen Namen // Erstelle eine neue Tabelle mit dem ursprünglichen Namen
createNewTable(tablename); createNewTable(tablename);
status.changeState("Daten werden in neue Tabelle migriert..."); status.changeState("Daten werden in neue Tabelle migriert...", levelnamelocal.size());
// Füge Daten in die neue Tabelle ein // Füge Daten in die neue Tabelle ein
String insert = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed, locked, personalBest, levelLength) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; String insert = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed, locked, personalBest, levelLength) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

View file

@ -70,8 +70,8 @@ public class LoadingStatus {
main.dispose(); main.dispose();
} }
public void changeState(String state) { public void changeState(String state, int arrsize) {
bar.setMaximum(data.allLevels().size()); bar.setMaximum(arrsize);
bar.setValue(0); bar.setValue(0);
info.setText(state); info.setText(state);
area.setText(""); area.setText("");

View file

@ -36,6 +36,7 @@ import javax.swing.JScrollPane;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import api.GetApiData;
import data.SortData; import data.SortData;
import database.Sqlite; import database.Sqlite;
@ -59,6 +60,7 @@ public class MainGUI {
public JLabel idshow = new JLabel("ID"); public JLabel idshow = new JLabel("ID");
public JLabel qualify = new JLabel("Qualifikation"); public JLabel qualify = new JLabel("Qualifikation");
public JLabel attemptslabel = new JLabel("Attempts"); public JLabel attemptslabel = new JLabel("Attempts");
public JLabel lengthLabel = new JLabel("Länge");
public JCheckBox filtercompleted = new JCheckBox("Nach geschafft filtern"); public JCheckBox filtercompleted = new JCheckBox("Nach geschafft filtern");
public Button copyid = new Button("Level ID kopieren"); public Button copyid = new Button("Level ID kopieren");
public Button showinfos = new Button("Mehr Infos anzeigen"); public Button showinfos = new Button("Mehr Infos anzeigen");
@ -83,6 +85,8 @@ public class MainGUI {
Sqlite data = new Sqlite("levels"); Sqlite data = new Sqlite("levels");
data.queryData("levels"); data.queryData("levels");
GetApiData api = new GetApiData();
//sort.sort(); //sort.sort();
gridLayout.setRows(data.getLevelname().size()); gridLayout.setRows(data.getLevelname().size());
@ -117,19 +121,21 @@ public class MainGUI {
idshow.setBounds(10, 110, 164, 30); idshow.setBounds(10, 110, 164, 30);
copyid.setBounds(10, 190, 164, 30); copyid.setBounds(10, 210, 164, 30);
qualify.setBounds(10, 130, 164, 30); qualify.setBounds(10, 130, 164, 30);
attemptslabel.setBounds(10, 150, 164, 30); attemptslabel.setBounds(10, 150, 164, 30);
lengthLabel.setBounds(10, 170, 164, 30);
settings.setBounds(1, 1, 60, 60); settings.setBounds(1, 1, 60, 60);
settings.setFont(settings.getFont().deriveFont(30f)); settings.setFont(settings.getFont().deriveFont(30f));
settings.setBackground(Color.LIGHT_GRAY); settings.setBackground(Color.LIGHT_GRAY);
showinfos.setBounds(12, 237, 160, 30); showinfos.setBounds(12, 257, 160, 30);
showcalc.setBounds(12, 283, 160, 30); showcalc.setBounds(12, 303, 160, 30);
startgame.setBounds(12, 560, 160, 30); startgame.setBounds(12, 560, 160, 30);
@ -143,7 +149,7 @@ public class MainGUI {
elements.infopanel().setVisible(false); elements.infopanel().setVisible(false);
separator.setBounds(0, 30, 300, 30); separator.setBounds(0, 30, 300, 30);
separator2.setBounds(0 ,160, 400, 30); separator2.setBounds(0 ,180, 400, 30);
creator.setBounds(10, 50, 164, 30); creator.setBounds(10, 50, 164, 30);
@ -310,7 +316,7 @@ public class MainGUI {
contents.addMouseListener(new MouseListener() { contents.addMouseListener(new MouseListener() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
showinfos.addActionListener(new ActionListener() { showinfos.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -328,14 +334,30 @@ public class MainGUI {
attemptslabel.setText("Attempts: " + data.getAttempts().get(index)); attemptslabel.setText("Attempts: " + data.getAttempts().get(index));
level.setVerticalAlignment(SwingConstants.CENTER); level.setVerticalAlignment(SwingConstants.CENTER);
String levellength = data.getLevelLength().get(index);
lengthLabel.setText("Länge: lädt...");
if(data.getLevelLength().get(index).equals("N/A")) {
if(req == 0) {
levellength = api.getLevelLength(Integer.parseInt(data.getLevelID().get(index)));
data.modifyData(data.getLevelname().get(index), comp[index], Integer.parseInt(attempts.getText()), lockbool[index], data.getPbarr().get(index), levellength);
System.out.println("request");
}
}
lengthLabel.setText("Länge: " + levellength);
copyid.addActionListener(new ActionListener() { copyid.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
StringSelection stringSelection = new StringSelection(data.getLevelID().get(index)); StringSelection stringSelection = new StringSelection(data.getLevelID().get(index));
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null); clipboard.setContents(stringSelection, null);
} }
});
});
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
@ -556,6 +578,7 @@ public class MainGUI {
elements.infopanel().add(showinfos); elements.infopanel().add(showinfos);
elements.infopanel().add(attemptslabel); elements.infopanel().add(attemptslabel);
elements.infopanel().add(showcalc); elements.infopanel().add(showcalc);
elements.infopanel().add(lengthLabel);
// elements.infopanel().add(startgame); // elements.infopanel().add(startgame);
main.add(search); main.add(search);

View file

@ -3,7 +3,6 @@
requires org.json; requires org.json;
requires org.apache.commons.io; requires org.apache.commons.io;
requires java.datatransfer; requires java.datatransfer;
requires com.formdev.flatlaf;
requires jdash.client; requires jdash.client;
requires jdash.common; requires jdash.common;
requires jlayer; requires jlayer;

View file

@ -17,6 +17,11 @@ public class ReadAttemptsFromXML {
public Map<String, String> newbestMap = new HashMap<>(); public Map<String, String> newbestMap = new HashMap<>();
public Map<String, String> lengthMap = new HashMap<>(); public Map<String, String> lengthMap = new HashMap<>();
public Map<String, String> getLengthMap() {
System.out.println("size getLengthMap in function: " + lengthMap.size());
return lengthMap;
}
public void readAttempts() { public void readAttempts() {
try { try {
File xmlFile = new File("C:\\ExtremeDemonList\\userdata\\CCGameManager.dat.xml"); File xmlFile = new File("C:\\ExtremeDemonList\\userdata\\CCGameManager.dat.xml");
@ -66,20 +71,15 @@ public class ReadAttemptsFromXML {
} }
} }
} }
if (attemptsValue != null && percentValue != null && lengthValue != null) {
if(lengthValue != null) {
lengthMap.put(currentLevelID, lengthValue);
}
if (attemptsValue != null && percentValue != null) {
tempAttempts.put(currentLevelID, attemptsValue ); // + "," + percentValue tempAttempts.put(currentLevelID, attemptsValue ); // + "," + percentValue
newbestMap.put(currentLevelID, percentValue); newbestMap.put(currentLevelID, percentValue);
lengthMap.put(currentLevelID, lengthValue);
} }
} }
} }
System.out.println("lengthmap size: " + lengthMap.size());
attempts.putAll(tempAttempts); attempts.putAll(tempAttempts);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -1,14 +1,21 @@
package readsafefile; package readsafefile;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import data.FetchData; import data.FetchData;
import data.ManageFiles;
import database.Sqlite; import database.Sqlite;
import gui.AttemptsProgress; import gui.AttemptsProgress;
public class SafeFileManager { public class SafeFileManager {
private String[] lengthArr = {"Tiny", "Short", "Medium", "Long", "XL", "Platformer", "N/A"}; private String[] lengthArr = {"TINY", "SHORT", "MEDIUM", "LONG", "XL", "PLATFORMER", "N/A"};
public Map<String, String> lengthComp = new HashMap<>();
private Sqlite database = new Sqlite("levels");
private ReadAttemptsFromXML read = new ReadAttemptsFromXML();
public void DecryptSafeFile() throws IOException { public void DecryptSafeFile() throws IOException {
DecryptXOR.decryptAndWriteFiles(); DecryptXOR.decryptAndWriteFiles();
@ -16,14 +23,11 @@ public class SafeFileManager {
public void ReadIndexAttempts() throws IOException { public void ReadIndexAttempts() throws IOException {
read.readAttempts();
AttemptsProgress prog = new AttemptsProgress(); AttemptsProgress prog = new AttemptsProgress();
prog.build(); prog.build();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Sqlite database = new Sqlite("levels");
database.queryData("levels"); database.queryData("levels");
FetchData fetch = new FetchData(); FetchData fetch = new FetchData();
try { try {
@ -32,20 +36,19 @@ public class SafeFileManager {
e.printStackTrace(); e.printStackTrace();
} }
ReadAttemptsFromXML read = new ReadAttemptsFromXML(); System.out.println("size lengthMap: " + read.getLengthMap().size());
lengthComp.putAll(read.lengthMap);
read.readAttempts();
String attempts; String attempts;
String percent; String percent;
String length;
for(int i = 0; i < database.getLevelID().size(); i++) { for(int i = 0; i < database.getLevelID().size(); i++) {
attempts = read.attempts.get(database.getLevelID().get(i)); attempts = read.attempts.get(database.getLevelID().get(i));
percent = read.newbestMap.get(database.getLevelID().get(i)); percent = read.newbestMap.get(database.getLevelID().get(i));
length = read.lengthMap.get(database.getLevelID().get(i));
if(read.lengthMap.get(database.getLevelID().get(i)) != null) {
System.out.println(lengthArr[Integer.parseInt(read.lengthMap.get(database.getLevelID().get(i)))]);
}
if(attempts == null) { if(attempts == null) {
attempts = 0 + ""; attempts = 0 + "";
@ -53,14 +56,16 @@ public class SafeFileManager {
if(percent == null) { if(percent == null) {
percent = 0 + ""; percent = 0 + "";
} }
if(length == null) {
length = 6 + "";
}
prog.update(database.getLevelname().get(i), Integer.parseInt(attempts), Integer.parseInt(percent), i); prog.update(database.getLevelname().get(i), Integer.parseInt(attempts), Integer.parseInt(percent), i);
if(!database.getLocked().get(i)) { if(!database.getLocked().get(i)) {
database.modifyData(database.getLevelname().get(i), Boolean.parseBoolean(database.getCompleted().get(i)), Integer.parseInt(attempts), database.getLocked().get(i), percent, database.getLevelLength().get(i)); database.modifyData(database.getLevelname().get(i), Boolean.parseBoolean(database.getCompleted().get(i)), Integer.parseInt(attempts), database.getLocked().get(i), percent, lengthArr[Integer.parseInt(length)]);
} }
} }
prog.close(); prog.close();
}
});
thread.start();
} }
} }