Skip to content

Commit

Permalink
Implemented materials and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazydiamonde committed May 30, 2024
1 parent 1676c2a commit b1379b2
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 20 deletions.
Binary file modified WooGLE.jar
Binary file not shown.
22 changes: 16 additions & 6 deletions src/main/java/com/woogleFX/editorObjects/InputField.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.woogleFX.editorObjects;

import java.io.File;
import java.io.FileNotFoundException;

import com.woogleFX.file.BaseGameResources;
import com.woogleFX.file.FileManager;
import com.woogleFX.file.resourceManagers.AnimationManager;
import com.woogleFX.file.resourceManagers.ResourceManager;
import com.woogleFX.functions.LevelManager;
import com.woogleFX.file.resourceManagers.ParticleManager;
import com.woogleFX.structures.simpleStructures.Color;
Expand Down Expand Up @@ -228,18 +231,25 @@ private static boolean verifyResource(EditorObject object, InputField type, Stri
}

case MATERIAL -> {
// TODO: load materials from materials.xml
return true;
try {
ResourceManager.getMaterial(null, potential, object.getVersion());
return true;
} catch (FileNotFoundException ignored) {
return false;
}
}

case TAG -> {
// TODO: Check this against all tags
return true;
return BaseGameResources.TAGS.contains(potential);
}

case FONT -> {
// TODO: Check this against all fonts
return true;
try {
ResourceManager.getFont(null, potential, object.getVersion());
return true;
} catch (FileNotFoundException ignored) {
return false;
}
}

default -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public static EditorObject create(String name, EditorObject _parent, GameVersion
case "linearforcefield" -> new Linearforcefield(parent, version);
case "loopsound" -> new Loopsound(parent, version);
case "marker" -> new Marker(parent, version);
case "materials" -> new Materials(parent, version);
case "material" -> new Material(parent, version);
case "motor" -> new Motor(parent, version);
case "music" -> new Music(parent, version);
case "part" -> new Part(parent, version);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/woogleFX/file/BaseGameResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class BaseGameResources {
public static final Set<String> IMAGES = new HashSet<>();
public static final Set<String> SOUNDS = new HashSet<>();
public static final Set<String> PARTICLE_FX = new HashSet<>();
public static final Set<String> TAGS = new HashSet<>(List.of(
"ballbuster", "break=1", "deadly", "detaching",
"geomkiller", "mostlydeadly", "nodrag",
"stopsign", "unwalkable", "walkable"
));


private static void loadFileIntoSet(String file, Set<String> set) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/woogleFX/file/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,29 @@ public static ArrayList<EditorObject> openText(GameVersion version) throws Parse
}


public static ArrayList<EditorObject> openMaterials(GameVersion version) throws ParserConfigurationException, SAXException, IOException {

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

ArrayList<EditorObject> objects = new ArrayList<>();
ArrayList<EditorObject> resources = new ArrayList<>();

BallFileOpener defaultHandler = new BallFileOpener(objects, resources, version);
BallFileOpener.mode = 0;
if (version == GameVersion.OLD && !oldWOGdir.isEmpty()) {
File ballFile = new File(oldWOGdir + "\\properties\\materials.xml.bin");
byte[] bytes = AESBinFormat.decodeFile(ballFile);
String stringBytes = bytesToString(bytes);
saxParser.parse(new InputSource(new StringReader(stringBytes)), defaultHandler);
} else if (version == GameVersion.NEW && !newWOGdir.isEmpty()) {
File ballFile2 = new File(newWOGdir + "\\properties\\materials.xml");
saxParser.parse(ballFile2, defaultHandler);
}
return objects;
}


public static void saveProperties() throws IOException {
StringBuilder export = new StringBuilder("<properties>\n\n<oldWOG filepath=\"" + oldWOGdir + "\"/>\n<newWOG filepath=\"" + newWOGdir + "\"/>\n<gooBallPalette>\n");
for (int i = 0; i < PaletteManager.getPaletteBalls().size(); i++) {
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/woogleFX/file/resourceManagers/FontManager.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.woogleFX.file.FileManager;
import com.woogleFX.file.fileImport.AnimationReader;
import com.woogleFX.structures.GameVersion;
import com.worldOfGoo.resrc.Material;
import com.worldOfGoo.particle._Particle;
import com.worldOfGoo.resrc.Font;
import com.worldOfGoo.resrc.ResrcImage;
Expand Down Expand Up @@ -49,6 +50,7 @@ public static void init() {
openParticles(GameVersion.OLD);
openAnimations(GameVersion.OLD);
openText(GameVersion.OLD);
openMaterials(GameVersion.OLD);
}

newResources.clear();
Expand All @@ -57,6 +59,7 @@ public static void init() {
openParticles(GameVersion.NEW);
openAnimations(GameVersion.NEW);
openText(GameVersion.NEW);
openMaterials(GameVersion.NEW);
}

// Load particle names, remove duplicates, and sort them alphabetically
Expand Down Expand Up @@ -184,4 +187,25 @@ private static void openText(GameVersion version) {

}


private static void openMaterials(GameVersion version) {

ArrayList<EditorObject> toAddTo = version == GameVersion.OLD ? oldResources : newResources;

ArrayList<EditorObject> materialList;
try {
materialList = FileManager.openMaterials(version);
} catch (ParserConfigurationException | SAXException | IOException e) {
Alarms.errorMessage(e);
return;
}

for (EditorObject material : materialList) {
if (material instanceof Material) {
toAddTo.add(material);
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.woogleFX.file.FileManager;
import com.woogleFX.file.fileImport.FontReader;
import com.woogleFX.structures.GameVersion;
import com.worldOfGoo.resrc.Material;
import com.worldOfGoo.resrc.Font;
import com.worldOfGoo.resrc.ResrcImage;
import com.worldOfGoo.resrc.Sound;
Expand All @@ -23,6 +24,7 @@ private static boolean checkSingleResource(EditorObject resource, String id) {
else if (resource instanceof Sound sound) return sound.getAdjustedID().equals(id);
else if (resource instanceof Font font) return font.getAdjustedID().equals(id);
else if (resource instanceof TextString text) return text.getAttribute("id").stringValue().equals(id);
else if (resource instanceof Material mat) return mat.getAttribute("id").stringValue().equals(id);
else return false;

}
Expand Down Expand Up @@ -77,6 +79,14 @@ public static _Font getFont(ArrayList<EditorObject> resources, String id, GameVe
}


/** Returns a material corresponding with the given ID. */
public static Material getMaterial(ArrayList<EditorObject> resources, String id, GameVersion version) throws FileNotFoundException {
EditorObject resource = findResource(resources, id, version);
if (resource instanceof Material material) return material;
else throw new FileNotFoundException("Invalid material resource ID: \"" + id + "\" (version " + version + ")");
}


public static boolean updateResource(EditorObject resource, GameVersion version) {
String dir = FileManager.getGameDir(version);
if (resource instanceof ResrcImage resrcImage) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/worldOfGoo/resrc/Material.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.worldOfGoo.resrc;

import com.woogleFX.editorObjects.EditorObject;
import com.woogleFX.editorObjects.InputField;
import com.woogleFX.structures.GameVersion;

public class Material extends EditorObject {

public Material(EditorObject _parent, GameVersion version) {
super(_parent, "material", version);

addAttribute("id", InputField.ANY);
addAttribute("friction", InputField.NUMBER);
addAttribute("bounce", InputField.NUMBER);
addAttribute("minbouncevel", InputField.NUMBER);
addAttribute("stickiness", InputField.NUMBER);

}

}
12 changes: 12 additions & 0 deletions src/main/java/com/worldOfGoo/resrc/Materials.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.worldOfGoo.resrc;

import com.woogleFX.editorObjects.EditorObject;
import com.woogleFX.structures.GameVersion;

public class Materials extends EditorObject {

public Materials(EditorObject _parent, GameVersion version) {
super(_parent, "materials", version);
}

}

0 comments on commit b1379b2

Please sign in to comment.