Skip to content

Commit

Permalink
only use FilesTools
Browse files Browse the repository at this point in the history
fix BodyRect to json
  • Loading branch information
Kevin Andres committed Jul 13, 2021
1 parent a2d41bf commit 5033155
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 72 deletions.
Binary file modified out/artifacts/SpriteBodyEditor_jar/SpriteBodyEditor.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.andres_k.utils.configs.GlobalVariable;
import com.andres_k.utils.stockage.Pair;
import com.andres_k.utils.stockage.Tuple;
import com.andres_k.utils.tools.FilesTools;
import com.andres_k.utils.tools.MathTools;
import com.andres_k.utils.tools.StringTools;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.newdawn.slick.*;
Expand Down Expand Up @@ -233,7 +233,7 @@ public boolean loadJsonFile(String path) throws SlickException, JSONException {
File file = new File(GlobalVariable.folder + path.substring(0, path.indexOf(".")) + ".json");

if (file.exists() && !file.isDirectory()) {
this.bodyCreator = new BodyCreator(new JSONObject(StringTools.readFile(GlobalVariable.folder + path.substring(0, path.indexOf(".")) + ".json")));
this.bodyCreator = new BodyCreator(new JSONObject(FilesTools.readFile(GlobalVariable.folder + path.substring(0, path.indexOf(".")) + ".json")));
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.andres_k.utils.stockage.Tuple;
import com.andres_k.utils.tools.Console;
import com.andres_k.utils.tools.FilesTools;
import com.andres_k.utils.tools.StringTools;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
Expand Down Expand Up @@ -82,7 +81,7 @@ public void keyPressed(int key, char c) {
@Override
public void keyReleased(int key, char c) {
if (key == Input.KEY_ENTER && this.currentPath != null) {
if (StringTools.validFile(GlobalVariable.folder + this.currentPath.substring(0, this.currentPath.indexOf(".")) + ".json")) {
if (FilesTools.validFile(GlobalVariable.folder + this.currentPath.substring(0, this.currentPath.indexOf(".")) + ".json")) {
this.launchWithPath(new MessageFileLoad("admin", "admin", this.currentPath));
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.andres_k.utils.configs.GlobalVariable;
import com.andres_k.utils.tools.Console;
import com.andres_k.utils.tools.StringTools;
import com.andres_k.utils.tools.FilesTools;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
Expand Down Expand Up @@ -119,7 +119,7 @@ public BodySprite onClick(float x, float y) {

public void saveInFile() {
String jsonName = this.path.substring(0, this.path.indexOf(".")) + ".json";
StringTools.writeInFile(GlobalVariable.folder + jsonName, this.toString());
FilesTools.writeInFile(GlobalVariable.folder + jsonName, this.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ public void setFocused(boolean value) {

@Override
public String toString() {


return forWaterWar();
/*
JSONObject object = new JSONObject();

try {
Expand All @@ -216,31 +212,6 @@ public String toString() {
e.printStackTrace();
}

return object.toString();*/
}

private String forWaterWar() {
JSONObject object = new JSONObject();

try {
object.put("id", this.id);
object.put("type", this.type.getValue());
object.put("x", (int) (this.positions.getV1() - this.origin.getV1()));
object.put("y", (int) (this.positions.getV2() - this.origin.getV2()));
object.put("width", this.sizes.getV1().intValue());
object.put("height", this.sizes.getV2().intValue());
object.put("rotation", 0f);
object.put("component", "");

JSONArray array = new JSONArray();
for (String value : this.links) {
array.put(value);
}
object.put("links", array);
} catch (JSONException e) {
e.printStackTrace();
}

return object.toString();
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/andres_k/utils/tools/FilesTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

public class FilesTools {

public static boolean validFile(String path) {
File file = new File(path);

return (file.exists() && !file.isDirectory());
}

public static String readInput(InputStream inputStream) {
Scanner scan = new Scanner(inputStream).useDelimiter("\\A");

Expand Down
37 changes: 0 additions & 37 deletions src/main/java/com/andres_k/utils/tools/StringTools.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
package com.andres_k.utils.tools;

import java.io.*;

/**
* Created by andres_k on 24/03/2015.
*/

public class StringTools {

public static boolean validFile(String path) {
File file = new File(path);

return (file.exists() && !file.isDirectory());
}

public static String readFile(String fileName) {
String content = "";
File file = new File(fileName); //for ex foo.txt
Console.debug("file: " + file.getAbsolutePath());
try {
FileReader reader = new FileReader(file);
char[] chars = new char[(int) file.length()];
reader.read(chars);
content = new String(chars);
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}

public static void writeInFile(String fileName, String value) {
File file = new File(fileName);

try {
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(value);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public static String duplicateString(String value, int number) {
String result = "";

Expand Down

0 comments on commit 5033155

Please sign in to comment.