Skip to content

Commit

Permalink
Handle images from the base game properly, autoconvert @2x images to …
Browse files Browse the repository at this point in the history
…non-2x
  • Loading branch information
meh2481 committed Dec 26, 2023
1 parent 7013b5d commit 5e53c0b
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/main/java/com/WooGLEFX/Engine/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.WooGLEFX.EditorObjects._Ball;
import com.WooGLEFX.File.AnimationReader;
import com.WooGLEFX.File.BaseGameResources;
import com.WooGLEFX.File.FileManager;
import com.WooGLEFX.File.GlobalResourceManager;
import com.WooGLEFX.File.LevelExporter;
Expand Down Expand Up @@ -1183,12 +1184,39 @@ public static void importImage(File resrcFile) {
}

String imgPath = resrcFile.getPath();
if (level.getVersion() == 1.3) {
if (resrcFile.getPath().contains(FileManager.getOldWOGdir())) {
imgPath = resrcFile.getPath().replace(FileManager.getOldWOGdir(), "");
}
} else if (level.getVersion() == 1.5) {
if (resrcFile.getPath().contains(FileManager.getNewWOGdir())) {
imgPath = resrcFile.getPath().replace(FileManager.getNewWOGdir(), "");
}
}

if (!resrcFile.getPath().contains("\\res\\")) {
String rescTestPath = imgPath.replace("\\", "/");
String resourcePath = ("res\\levels\\" + level.getLevelName() + "\\" + normalizedFilename).replace("\\", "/");
if (rescTestPath.startsWith("/")) {
rescTestPath = rescTestPath.substring(1);
}
if (rescTestPath.endsWith(".png")) {
rescTestPath = rescTestPath.substring(0, rescTestPath.length() - 4);
}
if (rescTestPath.endsWith("@2x")) {
// Strip @2x suffix, since this is handled transparently by the game already
rescTestPath = rescTestPath.substring(0, rescTestPath.length() - 3);
}
if (!BaseGameResources.containsImage(rescTestPath)) {
ImageIO.write(image, "png", new File(path + "\\res\\levels\\" + level.getLevelName() + "\\"
+ normalizedFilename + ".png"));
imgPath = path + "\\res\\levels\\" + level.getLevelName() + "\\" + normalizedFilename
+ ".png";
} else {
imgPath = resourcePath = rescTestPath;
if (normalizedFilename.endsWith("@2x")) {
// Strip @2x suffix from here too
normalizedFilename = normalizedFilename.substring(0, normalizedFilename.length() - 3);
}
}

String imageResourceName = "IMAGE_SCENE_" + level.getLevelName().toUpperCase() + "_"
Expand All @@ -1198,12 +1226,12 @@ public static void importImage(File resrcFile) {
imageResourceObject.setAttribute("id", imageResourceName);
imageResourceObject.setAttribute(
"path",
("res\\levels\\" + level.getLevelName() + "\\" + normalizedFilename).replace("\\", "/")
resourcePath
);
imageResourceObject.setAttribute("REALid", imageResourceName);
imageResourceObject.setAttribute(
"REALpath",
("res\\levels\\" + level.getLevelName() + "\\" + normalizedFilename).replace("\\", "/")
resourcePath
);

int whereToPlaceResource = 0;
Expand Down

0 comments on commit 5e53c0b

Please sign in to comment.