Skip to content

Commit

Permalink
Many changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazydiamonde committed Aug 28, 2023
1 parent 8941ba8 commit 728f920
Show file tree
Hide file tree
Showing 28 changed files with 1,175 additions and 401 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/WooGLEFX/Engine/ClipboardHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ public class ClipboardHandler {

public static EditorObject importFromClipboardString(String clipboard) {

System.out.println(clipboard);

//WOGEditor:circle<id=wheel;x=2;y=1024.9834;radius=120;material=machine;tag=mostlydeadly>

EditorObject object = null;
Expand Down
144 changes: 100 additions & 44 deletions src/main/java/com/WooGLEFX/Engine/FXCreator.java

Large diffs are not rendered by default.

639 changes: 508 additions & 131 deletions src/main/java/com/WooGLEFX/Engine/Main.java

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/java/com/WooGLEFX/Engine/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Renderer {
public static final Paint endWidescreen = Paint.valueOf("006030FF");
public static final Paint noLevel = Paint.valueOf("A0A0A0FF");
public static final Paint middleColor = Paint.valueOf("808080FF");
public static final Paint particleLabels = Paint.valueOf("A81CFF");

public static final Stop[] stops = new Stop[] { new Stop(0, javafx.scene.paint.Color.valueOf("802000FF")), new Stop(1, Color.valueOf("FFC040FF")) };

Expand Down
33 changes: 20 additions & 13 deletions src/main/java/com/WooGLEFX/File/AnimationReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public static int intFromBytes(byte[] input){
return output;
}

public static WoGAnimation readBinuni(byte[] binuni, String name){
public static WoGAnimation readBinuni(byte[] binuni, String name) {

if (debug) {
System.out.println("Opening binuni animation " + name);
}

byte[] HEADER = subsection(binuni, 0, 8);
byte[] HAS_COLOR = subsection(binuni, 8, 12);
Expand Down Expand Up @@ -215,7 +219,11 @@ public static WoGAnimation readBinuni(byte[] binuni, String name){

}

public static WoGAnimation readBinltl(byte[] binuni, String name){
public static WoGAnimation readBinltl(byte[] binuni, String name) {

if (debug) {
System.out.println("Opening binltl animation " + name);
}

byte[] HAS_COLOR = subsection(binuni, 0, 4);
byte[] HAS_ALPHA = subsection(binuni, 4, 8);
Expand Down Expand Up @@ -292,9 +300,9 @@ public static WoGAnimation readBinltl(byte[] binuni, String name){
System.out.println("Transform types:");
for (int type : transformTypes) {
switch (type) {
case 0 -> System.out.println(" (Scale)");
case 1 -> System.out.println(" (Rotate)");
case 2 -> System.out.println(" (Translate)");
case 0 -> System.out.println("0 (Scale)");
case 1 -> System.out.println("1 (Rotate)");
case 2 -> System.out.println("2 (Translate)");
}
}

Expand All @@ -303,14 +311,13 @@ public static WoGAnimation readBinltl(byte[] binuni, String name){
System.out.println("X form frames:");
for (int[] xFrame : xFormFrames) {
System.out.println(Arrays.toString(xFrame));
for (int i1 = 0; i1 < xFrame.length; i1++) {
if (i1 < xFrame.length - 1) {
System.out.println(Arrays.toString(subsection(binuni, xFrame[i1], xFrame[i1 + 1])));
} else {
for (int i1 = 0; i1 < xFrame.length - 1; i1++) {
if (xFrame[i1 + 1] != 0) {
System.out.println(Arrays.toString(subsection(binuni, xFrame[i1], xFrame[i1 + 1])));
}
}
}

System.out.println("Alpha frames: " + Arrays.toString(alphaFrames));
System.out.println("Color frames: " + Arrays.toString(colorFrames));
System.out.println("Sound frames: " + Arrays.toString(soundFrames));
Expand Down Expand Up @@ -379,10 +386,10 @@ public static WoGAnimation readBinltl(byte[] binuni, String name){
case 6 -> System.out.print("soundStrIdx");
case 7 -> System.out.print("interpolation type");
}
if (Math.abs(ByteBuffer.wrap(subsection(binuni, i * 4 + intFromBytes(STRING_TABLE_OFFSET), (i + 1) * 4 + intFromBytes(STRING_TABLE_OFFSET))).order(ByteOrder.LITTLE_ENDIAN).getInt()) > 999) {
System.out.println("): " + ByteBuffer.wrap(subsection(binuni, i * 4 + intFromBytes(STRING_TABLE_OFFSET), (i + 1) * 4 + intFromBytes(STRING_TABLE_OFFSET))).order(ByteOrder.LITTLE_ENDIAN).getFloat());
} else {
System.out.println("): " + ByteBuffer.wrap(subsection(binuni, i * 4 + intFromBytes(STRING_TABLE_OFFSET), (i + 1) * 4 + intFromBytes(STRING_TABLE_OFFSET))).order(ByteOrder.LITTLE_ENDIAN).getInt());
ByteBuffer byteBuffer = ByteBuffer.wrap(subsection(binuni, i * 4 + intFromBytes(STRING_TABLE_OFFSET), (i + 1) * 4 + intFromBytes(STRING_TABLE_OFFSET))).order(ByteOrder.LITTLE_ENDIAN);
switch (i2 % 8) {
case 0, 1, 2 -> System.out.println("): " + byteBuffer.getFloat());
case 3, 4, 5, 6, 7 -> System.out.println("): " + byteBuffer.getInt());
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/WooGLEFX/File/GlobalResourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public class GlobalResourceManager {
private static final ArrayList<Resource> oldResources = new ArrayList<>();
private static final ArrayList<Resource> newResources = new ArrayList<>();

public static ArrayList<Resource> getOldResources() {
return oldResources;
}
public static ArrayList<Resource> getNewResources() {
return newResources;
}

/**
* @param id The id (all caps property) of the resource.
* @param version Specifies which version of WoG (1.3 or 1.5).
Expand Down Expand Up @@ -52,6 +59,22 @@ public static Image getImage(String id, double version) throws FileNotFoundExcep

}

public static void updateResource(String id, double version) throws FileNotFoundException {
if (version == 1.3) {
for (Resource resource : oldResources) {
if (resource instanceof ImageResource imageResource && resource.getId().equals(id)) {
imageResource.setImage(FileManager.openImageFromFilePath(FileManager.getOldWOGdir() + "\\" + ((ImageResource) resource).getPath() + ".png"));
}
}
} else if (version == 1.5) {
for (Resource resource : newResources) {
if (resource instanceof ImageResource imageResource && resource.getId().equals(id)) {
imageResource.setImage(FileManager.openImageFromFilePath(FileManager.getNewWOGdir() + "\\" + ((ImageResource) resource).getPath() + ".png"));
}
}
}
}

public static TextString getText(String id, double version) throws FileNotFoundException {

if (version == 1.3) {
Expand Down
97 changes: 61 additions & 36 deletions src/main/java/com/WooGLEFX/File/LevelExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class LevelExporter {

Expand All @@ -35,7 +38,7 @@ public static String recursiveXMLexport(String export, EditorObject object, int
StringBuilder exportBuilder = new StringBuilder(export);
for (EditorAttribute attribute : object.getAttributes()) {
if (object instanceof Sound || object instanceof ResrcImage) {
if (attribute.getName().equals("id") || attribute.getName().equals("path")) {
if (attribute.getName().equals("REALid") || attribute.getName().equals("REALpath")) {
continue;
}
}
Expand All @@ -44,9 +47,13 @@ public static String recursiveXMLexport(String export, EditorObject object, int
exportBuilder.append(attribute.getName()).append("=\"\" ");
} else {
if (object instanceof Sound || object instanceof ResrcImage) {
exportBuilder.append(attribute.getName().substring(4)).append("=\"").append(attribute.getValue()).append("\" ");
} else {
exportBuilder.append(attribute.getName()).append("=\"").append(attribute.getValue()).append("\" ");
} else {
if (attribute.getValue().equals("") && attribute.getRequiredInFile()) {
exportBuilder.append(attribute.getName()).append("=\"").append(attribute.getDefaultValue()).append("\" ");
} else {
exportBuilder.append(attribute.getName()).append("=\"").append(attribute.getValue()).append("\" ");
}
}
}
}
Expand Down Expand Up @@ -354,7 +361,7 @@ public static void saveAsXML(WorldLevel worldLevel, String outputPathString, dou
File[] images = new File(FileManager.getOldWOGdir() + "\\res\\levels\\" + levelName).listFiles();
if (images != null) {
for (File imageFile : images) {
if (imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".png") || imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".ogg")) {
if (imageFile.getPath().lastIndexOf(".") != -1 && (imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".png") || imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".ogg"))) {
if (!Files.exists(Path.of(outputPath + "\\" + imageFile.getName()))) {
Files.copy(imageFile.toPath(), Path.of(outputPath + "\\" + imageFile.getName()));
}
Expand Down Expand Up @@ -396,6 +403,11 @@ public static void exportBallAsXML(_Ball ball, String outputPathString, double v
resourcesPathText += ".bin";
}

if (exportingInGoomod) {
ballsPathText += ".xml";
resourcesPathText += ".xml";
}

Path ballsPath = Path.of(ballsPathText);
Path resourcesPath = Path.of(resourcesPathText);
Path outputPath = Path.of(outputPathString);
Expand All @@ -413,13 +425,15 @@ public static void exportBallAsXML(_Ball ball, String outputPathString, double v
if (version == 1.3) {
AESBinFormat.encodeFile(new File(ballsPathText), ballXML.getBytes());
AESBinFormat.encodeFile(new File(resourcesPathText), resrcXML.getBytes());
if (Files.exists(Path.of(FileManager.getNewWOGdir() + "\\res\\balls\\" + name))) {
File[] images = new File(FileManager.getNewWOGdir() + "\\res\\balls\\" + name).listFiles();
if (images != null) {
for (File imageFile : images) {
if (imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".png") || imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".ogg")) {
if (!Files.exists(Path.of(outputPath + "\\" + imageFile.getName()))) {
Files.copy(imageFile.toPath(), Path.of(outputPath + "\\" + imageFile.getName()));
if (!exportingInGoomod) {
if (Files.exists(Path.of(FileManager.getNewWOGdir() + "\\res\\balls\\" + name))) {
File[] images = new File(FileManager.getNewWOGdir() + "\\res\\balls\\" + name).listFiles();
if (images != null) {
for (File imageFile : images) {
if (imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".png") || imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".ogg")) {
if (!Files.exists(Path.of(outputPath + "\\" + imageFile.getName()))) {
Files.copy(imageFile.toPath(), Path.of(outputPath + "\\" + imageFile.getName()));
}
}
}
}
Expand All @@ -429,13 +443,15 @@ public static void exportBallAsXML(_Ball ball, String outputPathString, double v
if (version == 1.5) {
Files.write(ballsPath, Collections.singleton(ballXML), StandardCharsets.UTF_8);
Files.write(resourcesPath, Collections.singleton(resrcXML), StandardCharsets.UTF_8);
if (Files.exists(Path.of(FileManager.getOldWOGdir() + "\\res\\balls\\" + name))) {
File[] images = new File(FileManager.getOldWOGdir() + "\\res\\balls\\" + name).listFiles();
if (images != null) {
for (File imageFile : images) {
if (imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".png") || imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".ogg")) {
if (!Files.exists(Path.of(outputPath + "\\" + imageFile.getName()))) {
Files.copy(imageFile.toPath(), Path.of(outputPath + "\\" + imageFile.getName()));
if (!exportingInGoomod) {
if (Files.exists(Path.of(FileManager.getOldWOGdir() + "\\res\\balls\\" + name))) {
File[] images = new File(FileManager.getOldWOGdir() + "\\res\\balls\\" + name).listFiles();
if (images != null) {
for (File imageFile : images) {
if (imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".png") || imageFile.getPath().substring(imageFile.getPath().lastIndexOf(".")).equals(".ogg")) {
if (!Files.exists(Path.of(outputPath + "\\" + imageFile.getName()))) {
Files.copy(imageFile.toPath(), Path.of(outputPath + "\\" + imageFile.getName()));
}
}
}
}
Expand All @@ -444,7 +460,6 @@ public static void exportBallAsXML(_Ball ball, String outputPathString, double v
}
}

//TODO export balls with the level
public static void exportGoomod(File file, WorldLevel level, ArrayList<_Ball> balls, boolean includeAddinInfo) {
String start = level.getVersion() == 1.3 ? FileManager.getOldWOGdir() : FileManager.getNewWOGdir();
try {
Expand All @@ -454,49 +469,59 @@ public static void exportGoomod(File file, WorldLevel level, ArrayList<_Ball> ba
}
for (EditorObject resource : level.getResources()) {
if (resource instanceof ResrcImage) {
if (!Files.exists(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("path").substring(0, resource.getAttribute("path").lastIndexOf("/"))))) {
if (!Files.exists(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath").substring(0, resource.getAttribute("REALpath").lastIndexOf("/"))))) {
try {
Files.createDirectories(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("path").substring(0, resource.getAttribute("path").lastIndexOf("/"))));
Files.createDirectories(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath").substring(0, resource.getAttribute("REALpath").lastIndexOf("/"))));
} catch (Exception e) {
Alarms.errorMessage(e);
}
}
try {
BufferedImage oldImage = SwingFXUtils.fromFXImage(GlobalResourceManager.getImage(resource.getAttribute("id"), level.getVersion()), null);
File newImageFile = new File(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("path") + ".png");
BufferedImage oldImage = SwingFXUtils.fromFXImage(GlobalResourceManager.getImage(resource.getAttribute("REALid"), level.getVersion()), null);
File newImageFile = new File(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath") + ".png");
ImageIO.write(oldImage, "png", newImageFile);
} catch (Exception e) {
Alarms.errorMessage(e);
}
} else if (resource instanceof Sound) {
if (!Files.exists(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath").substring(0, resource.getAttribute("REALpath").lastIndexOf("/"))))) {
try {
Files.createDirectories(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath").substring(0, resource.getAttribute("REALpath").lastIndexOf("/"))));
} catch (Exception e) {
Alarms.errorMessage(e);
}
}
try {
Files.copy(Path.of(start + "\\" + resource.getAttribute("REALpath") + ".ogg"), Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath") + ".ogg"));
} catch (Exception e) {
Alarms.errorMessage(e);
}
}
}

try {
ZipCompress.compress(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod");
if (Files.exists(file.toPath())) {
Files.delete(file.toPath());
}
Files.move(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod.zip"), file.toPath());
} catch (Exception e) {
Alarms.errorMessage(e);
}

for (_Ball ball : balls) {
try {
exportBallAsXML(ball, start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\compile\\res\\balls\\" + ball.getObjects().get(0).getAttribute("name"), level.getVersion(), true);
for (EditorObject resource : ball.getResources()) {
if (resource instanceof ResrcImage) {
if (!Files.exists(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("path").substring(0, resource.getAttribute("path").lastIndexOf("/"))))) {
Files.createDirectories(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("path").substring(0, resource.getAttribute("path").lastIndexOf("/"))));
if (!Files.exists(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath").substring(0, resource.getAttribute("REALpath").lastIndexOf("/"))))) {
Files.createDirectories(Path.of(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath").substring(0, resource.getAttribute("REALpath").lastIndexOf("/"))));
}
BufferedImage oldImage = SwingFXUtils.fromFXImage(GlobalResourceManager.getImage(resource.getAttribute("id"), level.getVersion()), null);
File newImageFile = new File(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("path") + ".png");
File newImageFile = new File(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod\\override\\" + resource.getAttribute("REALpath") + ".png");
ImageIO.write(oldImage, "png", newImageFile);
}
}
} catch (Exception e) {
Alarms.errorMessage(e);
}
}

try {
new ZipUtility().zip(new ArrayList<>(List.of(new File(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod").listFiles())), start + "\\res\\levels\\" + level.getLevelName() + "\\goomod.zip");
new File(start + "\\res\\levels\\" + level.getLevelName() + "\\goomod.zip").renameTo(file);
} catch (Exception e) {
Alarms.errorMessage(e);
}
}
}
Loading

0 comments on commit 728f920

Please sign in to comment.