3 Commits

Author SHA1 Message Date
89b32977e5 Functional mod list 2024-05-07 05:26:54 -05:00
21653702c3 the c, the h, the e, the m 2024-05-07 04:26:40 -05:00
4086dfd319 implement mod list load 2024-05-07 00:47:43 -05:00
5 changed files with 93 additions and 35 deletions

View File

@@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="StringOperationCanBeSimplified" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreStringConstructor" value="true" />
</inspection_tool>
</profile>
</component>

10
.idea/libraries/net_lingala_zip4j.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="net.lingala.zip4j" type="repository">
<properties maven-id="net.lingala.zip4j:zip4j:2.11.5" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/lingala/zip4j/zip4j/2.11.5/zip4j-2.11.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@@ -8,5 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="org.json-1.6-20240205" level="project" />
<orderEntry type="library" name="net.lingala.zip4j" level="project" />
</component>
</module>

View File

@@ -21,8 +21,7 @@ import org.json.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.*;
import java.util.*;
import javax.swing.*;
@@ -45,7 +44,7 @@ public class Main {
//public int gameversion; //TODO detect a game version and compatibility? // no
public int priority = 0; //unused
public String friendlyName;
public String description;
public String description = "";
public String game; //TODO for multi game support
public int loaderversion = 0; //minimum required vint or feature level from Firestar
public String author; // if null, "Author is unknown."

View File

@@ -26,7 +26,14 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.math.RoundingMode;
import java.nio.file.*;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.regex.Pattern;
import net.lingala.zip4j.*;
import net.lingala.zip4j.exception.ZipException;
import org.json.JSONObject;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
@@ -57,38 +64,11 @@ public class MissPiggy implements ActionListener {
private int selectedItem;
public String priorityList;
// Initialize the main window
public void Action(/*Main entryPoint*/) {
/// DEBUG ///
Main.Mod testModEntry = new Main().new Mod(); //this is retarded? we're making a new object of a certain type, why the fuck do you care where it comes from? static or regardless??
testModEntry.friendlyName = "Example Mod 1";
testModEntry.description = "Example Mod 1";
testModEntry.game = "2048";
testModEntry.path = "/home/bonkyboo/madarao_sneaky2_square.png"; //used to test file sizes
testModEntry.version = 1;
//testModEntry.priority = 0; //will discard this in favor of the list index for simplicity
Main.Mods.add(testModEntry);
Main.Mod testModEntry2 = new Main().new Mod();
testModEntry2.friendlyName = "Example Mod 2";
testModEntry2.description = "Example Mod 2";
testModEntry2.author = "Daniel Chang";
testModEntry2.game = "2048";
testModEntry2.path = "/home/bonkyboo/chengou.mp4";
testModEntry2.version = 1;
testModEntry2.loaderversion = 0;
Main.Mods.add(testModEntry2);
Main.Mod testModEntry3 = new Main().new Mod();
testModEntry3.friendlyName = "Example Mod 3";
testModEntry3.description = "Example Mod 3";
testModEntry3.author = "John Dekka";
testModEntry3.game = "2048";
testModEntry3.path = "/home/bonkyboo/round2.mp4";
testModEntry3.version = 1;
testModEntry3.loaderversion = 0;
Main.Mods.add(testModEntry3);
///-/////-///
// populate menu bar
// populate menu bar
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
toolsMenu = new JMenu("Tools");
@@ -103,6 +83,8 @@ public class MissPiggy implements ActionListener {
toolsMenu.add(new JMenuItem("Edit Metadata")); // disabled if a mod is not selected from the list
toolsMenu.add(new JMenuItem("Generate New Mod from Folder..."));
toolsMenu.add(new JMenuItem("Create Soundtrack Mod..."));
//toolsMenu.add(new JMenuItem("Download Mod from URL")); // TODO: implement. move option to File menu. should be ez
helpMenu.add(new JMenuItem("About Firestar"));
@@ -114,6 +96,7 @@ public class MissPiggy implements ActionListener {
frame.add(frameContainer); // initialize window contents -- will be handled by IntelliJ IDEA
InitializeModListStructure();
InitializeModListInGUI(); // present mod list
fileMenu.getItem(0).addActionListener(this);
@@ -128,12 +111,12 @@ public class MissPiggy implements ActionListener {
descriptionField.getDocument().putProperty("filterNewlines", Boolean.FALSE);
modList.addListSelectionListener(e -> {
String authorDisplay;
File pathReference = new File(Main.Mods.get(modList.getSelectedIndex()).path);
File pathReference = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path);
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.UP);
float modFileSize = pathReference.length(); //precise units
String modFileSizeStr = String.valueOf(modFileSize);
String modFileSizeUnits = "bytes";
String modFileSizeUnits = "bytes"; //todo: don't show decimals for bytes
if (pathReference.length() >= 1024) {
modFileSizeStr = String.valueOf(df.format(modFileSize / 1024));
modFileSizeUnits = "Kilobytes";
@@ -176,6 +159,63 @@ public class MissPiggy implements ActionListener {
frame.setVisible(true);
}
public void InitializeModListStructure() {
// cleanup
Main.Mods.clear();
// get current list of mods from file
// todo: rewrite when modpacks/playlists are added
try {
priorityList = new String(Files.readAllBytes(Paths.get(System.getProperty("user.home") + "/.firestar/mods/index")));
} catch (IOException e) {
File priorityListFileHandle = new File(System.getProperty("user.home") + "/.firestar/mods/index");
new File(System.getProperty("user.home") + "/.firestar/mods/").mkdirs();
if(!priorityListFileHandle.isFile()){
try {
priorityListFileHandle.createNewFile();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
priorityList = "";
}
// initialize data structures from each list entry
String[] pListArray = priorityList.split("\n");
Arrays.sort(pListArray);
System.out.println("Initializing modList from file with length of " + pListArray.length + " units"); //debug
for (String s : pListArray) {
/*
Do nothing if the index number is not valid.
there probably is not a practical reason to do this, but I want to eliminate any undefined behaviors while we're here.
we'll also eliminate any syntax errors caused by the lack of a = sign
*/
if (s.split("=")[0].matches("[0-9]+=*")) {
//append mod to list from substring
Main.Mod m = new Main().new Mod();
m.path = s.substring(s.indexOf("=") + 1);
System.out.println("found file " + m.path);
//get json metadata from zip comment
JSONObject metadata;
try {
metadata = new JSONObject(new ZipFile(System.getProperty("user.home") + "/.firestar/mods/" + m.path).getComment());
} catch (ZipException e) {
throw new RuntimeException(e); //todo: fault tolerance
}
if (metadata.has("friendlyName")) {m.friendlyName = metadata.get("friendlyName").toString();} else {m.friendlyName = m.path;}
if (metadata.has("description")) {m.description = metadata.get("description").toString();}
if (metadata.has("version")) {m.version = Integer.parseInt(metadata.get("version").toString());}
if (metadata.has("author")) {m.author = metadata.get("author").toString();}
if (metadata.has("loaderversion")) {m.loaderversion = Integer.parseInt(metadata.get("loaderversion").toString());}
if (metadata.has("game")) {m.game = metadata.get("game").toString();}
//send to list
Main.Mods.add(m);
}
}
}
public void InitializeModListInGUI() { // i really wanted this to be "lights, camera, action" but the code organizing kept getting stupider and stupider so i gave up
// cleanup
descriptionField.setText("Select a mod from the list on the right to view more details, or to make changes to your installation.");