Skip to content

Commit

Permalink
Merge pull request #1 from Skrelpoid/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Skrelpoid authored May 10, 2018
2 parents 94d38e1 + 80d9974 commit fc54c70
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 29 deletions.
15 changes: 11 additions & 4 deletions core/assets/OrderJsonREADME.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
This program is designed to sort JSON files alphabetically by their names of the first children layer. Everything else will be left exactly how it was. Although, it is possible that depending on your formatting, spaces could be replaced by tabs.
Dieses Programm sortiert JSON Dateien alphabetisch anhand der Namen der ersten children-Ebene. Alles andere wird so belassen wie es vorher war. Allerdings ist es moeglich, dass Leerzeichen durch Tabulatoren ersetzt werden.
To sort your JSON, place it into a folder that is next to this JAR. You can even have multiple files in a folder and also multiple folders next to this JAR for better organization. You can find the sorted JSON files in the folder you placed them in. If for some reason you also need your original JSON files backed up, click Create Backup to create folders alongside this JAR with your old files. To sort your files, simply press Start.
Um deine Datei(en) zu sortieren, lege sie in einen Ordner neben dieses JAR ab. Du kannst sogar mehrere Dateien in einen Ordern tun und mehrere Ordner neben diesem JAR fuer eine bessere Uebersichtlichtkeit. Die sortierten Dateien findest du im gleichen Ordner wieder. Wenn du ein Backup von deinen JSON Dateien brauchst, klicke auf Create Backup um deine alten Dateien in Backupordner neben diesem JAR zu kopieren. Um deine Dateien zu sortieren, klicke auf Start.
ENGLISH:
This program is designed to sort JSON files alphabetically by their names of the first children layer. Everything else will be left exactly how it was.
To sort your JSON, place the file or a folder with the files, next to this JAR.
You can even have multiple files in a folder and also multiple folders and files next to this JAR for better organization. You can find the sorted JSON files where you placed them. If for some reason you also need your original JSON files backed up, click Create Backup to create a backup folder alongside this JAR with your old files.
To sort your files, simply press Start.

GERMAN:
Dieses Programm sortiert JSON Dateien alphabetisch anhand der Namen der ersten children-Ebene. Alles andere wird so belassen wie es vorher war.
Um deine Datei(en) zu sortieren, lege sie selbst oder einen Ordner mit ihnen neben dieses JAR ab.
Du kannst sogar mehrere Dateien in einen Ordern tun und mehrere Ordner und Dateien neben diesem JAR haben fuer eine bessere Uebersichtlichtkeit. Die sortierten Dateien findest du da wo du deine Dateien abgelegt hast. Wenn du ein Backup von deinen JSON Dateien brauchst, klicke auf Create Backup um deine alten Dateien in einen Backupordner neben dieses JAR zu kopieren.
Um deine Dateien zu sortieren, klicke auf Start.
1 change: 1 addition & 0 deletions core/assets/Unsupported.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Oops, it seems like the directory you are trying to sort is not supported by Java/LibGdx. To fix this, create a new folder elsewhere, e.g. on your Desktop , name it SupportFix and then copy the content of the unsupported folder into it. Finally copy this program into it and run it. (Do not put this Program directly into your Desktop folder! Instead, copy it into a folder on your Desktop). If the problem persists, please open an issue on GitHub or message Skrelpoid directly.
15 changes: 11 additions & 4 deletions core/bin/OrderJsonREADME.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
This program is designed to sort JSON files alphabetically by their names of the first children layer. Everything else will be left exactly how it was. Although, it is possible that depending on your formatting, spaces could be replaced by tabs.
Dieses Programm sortiert JSON Dateien alphabetisch anhand der Namen der ersten children-Ebene. Alles andere wird so belassen wie es vorher war. Allerdings ist es moeglich, dass Leerzeichen durch Tabulatoren ersetzt werden.
To sort your JSON, place it into a folder that is next to this JAR. You can even have multiple files in a folder and also multiple folders next to this JAR for better organization. You can find the sorted JSON files in the folder you placed them in. If for some reason you also need your original JSON files backed up, click Create Backup to create folders alongside this JAR with your old files. To sort your files, simply press Start.
Um deine Datei(en) zu sortieren, lege sie in einen Ordner neben dieses JAR ab. Du kannst sogar mehrere Dateien in einen Ordern tun und mehrere Ordner neben diesem JAR fuer eine bessere Uebersichtlichtkeit. Die sortierten Dateien findest du im gleichen Ordner wieder. Wenn du ein Backup von deinen JSON Dateien brauchst, klicke auf Create Backup um deine alten Dateien in Backupordner neben diesem JAR zu kopieren. Um deine Dateien zu sortieren, klicke auf Start.
ENGLISH:
This program is designed to sort JSON files alphabetically by their names of the first children layer. Everything else will be left exactly how it was.
To sort your JSON, place the file or a folder with the files, next to this JAR.
You can even have multiple files in a folder and also multiple folders and files next to this JAR for better organization. You can find the sorted JSON files where you placed them. If for some reason you also need your original JSON files backed up, click Create Backup to create a backup folder alongside this JAR with your old files.
To sort your files, simply press Start.

GERMAN:
Dieses Programm sortiert JSON Dateien alphabetisch anhand der Namen der ersten children-Ebene. Alles andere wird so belassen wie es vorher war.
Um deine Datei(en) zu sortieren, lege sie selbst oder einen Ordner mit ihnen neben dieses JAR ab.
Du kannst sogar mehrere Dateien in einen Ordern tun und mehrere Ordner und Dateien neben diesem JAR haben fuer eine bessere Uebersichtlichtkeit. Die sortierten Dateien findest du da wo du deine Dateien abgelegt hast. Wenn du ein Backup von deinen JSON Dateien brauchst, klicke auf Create Backup um deine alten Dateien in einen Backupordner neben dieses JAR zu kopieren.
Um deine Dateien zu sortieren, klicke auf Start.
1 change: 1 addition & 0 deletions core/bin/Unsupported.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Oops, it seems like the directory you are trying to sort is not supported by Java/LibGdx. To fix this, create a new folder elsewhere, e.g. on your Desktop , name it SupportFix and then copy the content of the unsupported folder into it. Finally copy this program into it and run it. (Do not put this Program directly into your Desktop folder! Instead, copy it into a folder on your Desktop). If the problem persists, please open an issue on GitHub or message Skrelpoid directly.
Binary file modified core/bin/skrelpoid/orderjson/ConsoleStream$ConsoleWrite.class
Binary file not shown.
Binary file modified core/bin/skrelpoid/orderjson/ConsoleStream.class
Binary file not shown.
Binary file modified core/bin/skrelpoid/orderjson/JsonComparator.class
Binary file not shown.
Binary file not shown.
Binary file modified core/bin/skrelpoid/orderjson/OrderJson.class
Binary file not shown.
Binary file modified core/bin/skrelpoid/orderjson/Sorter$1.class
Binary file not shown.
Binary file modified core/bin/skrelpoid/orderjson/Sorter$2.class
Binary file not shown.
Binary file modified core/bin/skrelpoid/orderjson/Sorter.class
Binary file not shown.
6 changes: 6 additions & 0 deletions core/src/skrelpoid/orderjson/ConsoleStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public class ConsoleStream extends OutputStream {
private char[] buffer;
private int index;

// Stream to redirect System.out and System.err
public ConsoleStream(OrderJson app, int capacity) {
this.app = app;
buffer = new char[capacity];
index = 0;
}

// probably not used, maybe doesnt even work
@Override
public void write(int b) throws IOException {
char c = (char) b;
Expand All @@ -33,7 +35,10 @@ private void writeIfNeeded() {

@Override
public void write(byte[] b, int off, int len) throws IOException {
// get the string with the specified offset and length
String str = new String(b, off, len);
// write the string to the console on the next frame (to ensure thread
// safety)
Gdx.app.postRunnable(new ConsoleWrite(str));

}
Expand All @@ -47,6 +52,7 @@ public ConsoleWrite(String str) {

@Override
public void run() {
// append the text and scroll top the bottom of the text box
app.console.setText(app.console.getText().toString() + str);
app.scroll.scrollTo(0, 0, 100, 100);
}
Expand Down
6 changes: 5 additions & 1 deletion core/src/skrelpoid/orderjson/JsonComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import java.util.Comparator;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.JsonValue;

public class JsonComparator implements Comparator<JsonValue> {

// returns 0 if o1 and 02 are equal, -1 if o1s name comes before o2 name in
// the alphabet, 1 if o1s name comes after o2s name in the alphabet
@Override
public int compare(JsonValue o1, JsonValue o2) {
int compareValue = o1.name().compareTo(o2.name());
return compareValue > 0 ? 1 : compareValue < 0 ? -1 : 0;
// limit return value to -1, 0 and 1
return MathUtils.clamp(compareValue, -1, 1);
}

}
29 changes: 29 additions & 0 deletions core/src/skrelpoid/orderjson/NotSupportedException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package skrelpoid.orderjson;

import java.io.IOException;

//Exception for when file.isDirectory() returns true, but file.listFiles(fileFilter) return null
public class NotSupportedException extends IOException {

private static final long serialVersionUID = 5863814260599518183L;

public NotSupportedException() {
super();
}

public NotSupportedException(String message, Throwable cause) {
super(message, cause);

}

public NotSupportedException(String message) {
super(message);

}

public NotSupportedException(Throwable cause) {
super(cause);

}

}
28 changes: 27 additions & 1 deletion core/src/skrelpoid/orderjson/OrderJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class OrderJson implements ApplicationListener {

public static final String SKIN = "uiskin.json";
public static final String LOG_FILE = "OrderJsonLog.txt";

public Skin skin;
public Stage stage;
Expand All @@ -29,26 +30,32 @@ public class OrderJson implements ApplicationListener {
public ScrollPane scroll;
public Sorter sorter;

private int createLogIn = 0;

private String readme;

@Override
public void create() {
load();
buildGUI();
// stage receives input
Gdx.input.setInputProcessor(stage);
setUpConsole();
}

// redirect System.out and System.err to GUI
private void setUpConsole() {
System.setOut(new PrintStream(new ConsoleStream(this, 16)));
System.setErr(new PrintStream(new ConsoleStream(this, 16)));
}

// Load skin and readme
private void load() {
skin = new Skin(Gdx.files.internal(SKIN));
readme = Gdx.files.internal("OrderJsonREADME.txt").readString() + "\n";
}

// Create the GUI
private void buildGUI() {
view = new ExtendViewport(800, 480);
stage = new Stage(view);
Expand All @@ -58,6 +65,7 @@ private void buildGUI() {
start = new TextButton("Start", skin);
backup = new CheckBox("Create Backup", skin);
sorter = new Sorter(this);
// When Start is clicked, sorters clicked method is called
start.addListener(sorter);
console = new Label(readme, skin);
console.setWrap(true);
Expand All @@ -84,11 +92,17 @@ private void buildGUI() {

@Override
public void render() {
// Clear the screen
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
console.setText(console.getText().append(""));
if (createLogIn > 0) {
createLogIn--;
if (createLogIn == 0) {
writeLog();
}
}
}

@Override
Expand All @@ -108,4 +122,16 @@ public void resume() {
public void dispose() {
stage.dispose();
}

// creates log after inFrames frames have passed
public void createLog(int inFrames) {
createLogIn = inFrames;
}

// writes the log of the console to a file
private void writeLog() {
Gdx.files.local(LOG_FILE).writeString(console.getText().toString(), false);
System.out.println("A log was created at " + OrderJson.LOG_FILE);
System.out.println("---------------------------");
}
}
Loading

0 comments on commit fc54c70

Please sign in to comment.