diff --git a/.gitignore b/.gitignore index 6ee3832..a7c2526 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +DungeonGenerator.jar + ################# ## Eclipse ################# @@ -16,6 +18,24 @@ local.properties .settings/ .loadpath out/ +.idea +.gradle + +################# +## Gradle +################# +.gradle/ +build/ +gradle/ +gradlew +gradlew.bat + +################# +## Project Build +################# +*.jar +!lib/*.jar +sources.txt # External tool builders .externalToolBuilders/ @@ -212,4 +232,4 @@ pip-log.txt #Mr Developer .mr.developer.cfg -/dist/ \ No newline at end of file +/dist/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 5c98b42..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/dictionaries/smoser.xml b/.idea/dictionaries/smoser.xml deleted file mode 100644 index 0a11be1..0000000 --- a/.idea/dictionaries/smoser.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 146ab09..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml deleted file mode 100644 index ff952c1..0000000 --- a/.idea/libraries/lib.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 1bb046f..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 81caa97..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index f821945..bc2e913 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,41 @@ And of course DungeonGenerator itself is open source with a [public repository]( Want to contribute? Great! Maybe the [Javadoc](https://naclador.de/mosers/DungeonGenerator/src/branch/master/docs) is useful? +### Building + +#### Using the build script (recommended) + +```bash +# Build the JAR +./build.sh jar + +# Clean build artifacts +./build.sh clean + +# Build and run +./build.sh run + +# Clean and rebuild +./build.sh all +``` + +#### Using Gradle + +If you have Gradle installed: + +```bash +# Build the JAR +gradle jar + +# Run the application +gradle run +``` + +#### Requirements + +- Java JDK 11 or higher +- All dependencies are included in the `lib/` folder + ### Todos - Implement more random stuff @@ -43,7 +78,7 @@ License The MIT License (MIT) -Copyright (c) 2019 Simon Moser IT +Copyright (c) 2025 Simon Moser IT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..caf70f7 --- /dev/null +++ b/build.gradle @@ -0,0 +1,70 @@ +plugins { + id 'java' + id 'application' +} + +group = 'eu.smoser' +version = '1.0' + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +repositories { + mavenCentral() + flatDir { + dirs 'lib' + } +} + +dependencies { + implementation files('lib/flatlaf-3.4.1.jar') + implementation files('lib/itext-2.1.7.jar') + implementation files('lib/jgraph-5.13.0.0.jar') + implementation files('lib/jgrapht-core-0.9.2.jar') + implementation files('lib/jgrapht-ext-0.9.2.jar') + implementation files('lib/jgraphx-2.0.0.1.jar') + implementation files('lib/pdfbox-app-2.0.33.jar') +} + +sourceSets { + main { + java { + srcDirs = ['src'] + } + resources { + srcDirs = ['src', 'resources'] + } + } +} + +application { + mainClass = 'eu.smoser.dungeongenerator.main.DungeonGeneratorUI' +} + +jar { + manifest { + attributes( + 'Main-Class': 'eu.smoser.dungeongenerator.main.DungeonGeneratorUI', + 'Class-Path': configurations.runtimeClasspath.files.collect { 'lib/' + it.name }.join(' ') + ) + } + from { + configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } + } + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + archiveBaseName = 'DungeonGenerator' +} + +tasks.register('buildJar') { + dependsOn jar + doLast { + println "JAR created: build/libs/DungeonGenerator-${version}.jar" + } +} + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' +} + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..d7a1d27 --- /dev/null +++ b/build.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# Build script for DungeonGenerator +# Usage: ./build.sh [clean|jar|run] + +set -e + +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BUILD_DIR="$PROJECT_DIR/build/classes" +JAR_FILE="$PROJECT_DIR/DungeonGenerator.jar" +LIB_DIR="$PROJECT_DIR/lib" +SRC_DIR="$PROJECT_DIR/src" +RESOURCES_DIR="$PROJECT_DIR/resources" + +# All library JARs +LIBS=$(find "$LIB_DIR" -name "*.jar" | tr '\n' ':') + +clean() { + echo "Cleaning build directory..." + rm -rf "$PROJECT_DIR/build" + rm -f "$JAR_FILE" + rm -f "$PROJECT_DIR/sources.txt" + echo "Clean complete." +} + +compile() { + echo "Compiling sources..." + mkdir -p "$BUILD_DIR" + + # Find all Java files + find "$SRC_DIR" -name "*.java" > "$PROJECT_DIR/sources.txt" + + # Compile + javac -cp "$LIBS" -d "$BUILD_DIR" @"$PROJECT_DIR/sources.txt" + + # Copy resources + cp -r "$RESOURCES_DIR"/* "$BUILD_DIR/" 2>/dev/null || true + cp "$SRC_DIR/version.properties" "$BUILD_DIR/" 2>/dev/null || true + + echo "Compilation complete." +} + +create_jar() { + compile + + echo "Creating JAR..." + mkdir -p "$BUILD_DIR/META-INF" + + # Create manifest + LIB_CLASSPATH=$(find "$LIB_DIR" -name "*.jar" -exec basename {} \; | sed 's/^/lib\//' | tr '\n' ' ') + cat > "$BUILD_DIR/META-INF/MANIFEST.MF" << EOF +Manifest-Version: 1.0 +Main-Class: eu.smoser.dungeongenerator.main.DungeonGeneratorUI +Class-Path: $LIB_CLASSPATH + +EOF + + # Create JAR + cd "$BUILD_DIR" + jar cfm "$JAR_FILE" META-INF/MANIFEST.MF . + cd "$PROJECT_DIR" + + echo "JAR created: $JAR_FILE" +} + +run_app() { + if [ ! -f "$JAR_FILE" ]; then + create_jar + fi + echo "Running DungeonGenerator..." + java -jar "$JAR_FILE" +} + +# Main +case "${1:-jar}" in + clean) + clean + ;; + compile) + compile + ;; + jar) + create_jar + ;; + run) + run_app + ;; + all) + clean + create_jar + ;; + *) + echo "Usage: $0 [clean|compile|jar|run|all]" + echo " clean - Remove build artifacts" + echo " compile - Compile Java sources" + echo " jar - Create executable JAR (default)" + echo " run - Build and run the application" + echo " all - Clean and build JAR" + exit 1 + ;; +esac + diff --git a/lib/flatlaf-3.4.1.jar b/lib/flatlaf-3.4.1.jar new file mode 100644 index 0000000..f79f175 Binary files /dev/null and b/lib/flatlaf-3.4.1.jar differ diff --git a/lib/pdfbox-app-2.0.2.jar b/lib/pdfbox-app-2.0.2.jar deleted file mode 100644 index c65e3c4..0000000 Binary files a/lib/pdfbox-app-2.0.2.jar and /dev/null differ diff --git a/lib/pdfbox-app-2.0.33.jar b/lib/pdfbox-app-2.0.33.jar new file mode 100644 index 0000000..ca90caf Binary files /dev/null and b/lib/pdfbox-app-2.0.33.jar differ diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..7405cef --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'DungeonGenerator' + diff --git a/sources.txt b/sources.txt new file mode 100644 index 0000000..4b11477 --- /dev/null +++ b/sources.txt @@ -0,0 +1,16 @@ +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/Exit.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/objects/ADungeonObject.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/objects/Enemy.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/objects/Encounters.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/objects/Magic.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/objects/Treasure.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/objects/Trap.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/objects/Special.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/Room.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/dungeon/Dungeon.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/util/Dice.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/util/Counter.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/main/DungeonGeneratorUI.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/main/EncounterGenerator.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/main/AGenerator.java +/opt/DungeonGenerator/src/eu/smoser/dungeongenerator/main/TreasureGenerator.java diff --git a/src/eu/smoser/dungeongenerator/dungeon/Dungeon.java b/src/eu/smoser/dungeongenerator/dungeon/Dungeon.java index adfbcc3..718a7a7 100644 --- a/src/eu/smoser/dungeongenerator/dungeon/Dungeon.java +++ b/src/eu/smoser/dungeongenerator/dungeon/Dungeon.java @@ -3,7 +3,6 @@ package eu.smoser.dungeongenerator.dungeon; import java.util.*; import eu.smoser.dungeongenerator.util.*; -import org.jgraph.graph.DefaultEdge; import org.jgrapht.UndirectedGraph; import org.jgrapht.graph.SimpleGraph; @@ -36,7 +35,7 @@ public class Dungeon { * Returns the greedy map * @return HashMap greedy HashMap */ - public HashMap GetGreedyMap(){ + public HashMap GetGreedyMap(){ return greedyMap; } @@ -78,8 +77,8 @@ public class Dungeon { * * @return UndirectedGraph from JGraphT */ - public UndirectedGraph toGraph() { - UndirectedGraph g = new SimpleGraph(DefaultEdge.class); + public UndirectedGraph toGraph() { + UndirectedGraph g = new SimpleGraph<>(Exit.class); rooms.forEach(g::addVertex); rooms.forEach((r) -> { for (Exit e : r.exits) { diff --git a/src/eu/smoser/dungeongenerator/main/AGenerator.java b/src/eu/smoser/dungeongenerator/main/AGenerator.java index abe1e82..21a9fc2 100644 --- a/src/eu/smoser/dungeongenerator/main/AGenerator.java +++ b/src/eu/smoser/dungeongenerator/main/AGenerator.java @@ -3,6 +3,8 @@ package eu.smoser.dungeongenerator.main; import javax.swing.*; abstract class AGenerator extends javax.swing.JFrame { + private static final long serialVersionUID = 1L; + AGenerator() { JButton jButtonStart = new JButton(); JPanel jPanel1 = new JPanel(); diff --git a/src/eu/smoser/dungeongenerator/main/DungeonGeneratorUI.java b/src/eu/smoser/dungeongenerator/main/DungeonGeneratorUI.java index ef9d758..cd2d0b3 100644 --- a/src/eu/smoser/dungeongenerator/main/DungeonGeneratorUI.java +++ b/src/eu/smoser/dungeongenerator/main/DungeonGeneratorUI.java @@ -23,6 +23,8 @@ */ package eu.smoser.dungeongenerator.main; +import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatLightLaf; import com.lowagie.text.BadElementException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; @@ -33,6 +35,8 @@ import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; import eu.smoser.dungeongenerator.dungeon.Dungeon; +import eu.smoser.dungeongenerator.dungeon.Exit; +import eu.smoser.dungeongenerator.dungeon.Room; import javax.swing.*; import java.net.*; import java.io.*; @@ -62,9 +66,11 @@ import org.apache.pdfbox.multipdf.PDFMergerUtility; */ public class DungeonGeneratorUI extends javax.swing.JFrame { - private Dungeon mDungeon; - private UndirectedGraph mGraph; - mxGraphComponent mGraphComponent; + private static final long serialVersionUID = 1L; + + private transient Dungeon mDungeon; + private transient UndirectedGraph mGraph; + transient mxGraphComponent mGraphComponent; /** * Creates new form DungeonGeneratorUI @@ -222,7 +228,7 @@ public class DungeonGeneratorUI extends javax.swing.JFrame { jMenu.setText("Datei"); - jMenuNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK)); + jMenuNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_DOWN_MASK)); jMenuNew.setText("Neuer Dungeon"); jMenuNew.setEnabled(false); jMenuNew.addActionListener(new java.awt.event.ActionListener() { @@ -307,7 +313,7 @@ public class DungeonGeneratorUI extends javax.swing.JFrame { }); jMenu.add(jMenuPdf); - jMenuClose.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK)); + jMenuClose.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_DOWN_MASK)); jMenuClose.setText("Beenden"); jMenuClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -381,10 +387,10 @@ public class DungeonGeneratorUI extends javax.swing.JFrame { } mDungeon.generate(size, type, mode); mGraph = mDungeon.toGraph(); - JGraphXAdapter graphAdapter = new JGraphXAdapter(mGraph); + JGraphXAdapter graphAdapter = new JGraphXAdapter<>(mGraph); mGraphComponent = new mxGraphComponent(graphAdapter); mGraphComponent.setEnabled(false); - Map edgeStyle = graphAdapter.getStylesheet().getDefaultEdgeStyle(); + Map edgeStyle = graphAdapter.getStylesheet().getDefaultEdgeStyle(); edgeStyle.put(mxConstants.STYLE_NOLABEL, true); edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.NONE); @@ -467,7 +473,7 @@ public class DungeonGeneratorUI extends javax.swing.JFrame { } try (FileWriter fw = new FileWriter(file, false)) { //System.setProperties(file); - GmlExporter gex = new GmlExporter(); + GmlExporter gex = new GmlExporter<>(); gex.setPrintLabels(GmlExporter.PRINT_EDGE_VERTEX_LABELS); gex.export(fw, mGraph); JOptionPane.showMessageDialog(this, "Gespeichert!"); @@ -708,28 +714,23 @@ public class DungeonGeneratorUI extends javax.swing.JFrame { * @param args the command line arguments */ public static void main(String args[]) { - /* Set the Nimbus look and feel */ - // - /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. - * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ + /* Set the FlatLaf look and feel for modern UI */ try { - for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Nimbus".equals(info.getName())) { - javax.swing.UIManager.setLookAndFeel(info.getClassName()); - break; + UIManager.setLookAndFeel(new FlatDarkLaf()); + } catch (Exception ex) { + System.err.println("Failed to initialize FlatLaf"); + // Fallback to Nimbus + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } } + } catch (Exception e) { + java.util.logging.Logger.getLogger(DungeonGeneratorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, e); } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(DungeonGeneratorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(DungeonGeneratorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(DungeonGeneratorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(DungeonGeneratorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } - // /* Create and display the form */ java.awt.EventQueue.invokeLater(() -> { diff --git a/src/eu/smoser/dungeongenerator/main/EncounterGenerator.java b/src/eu/smoser/dungeongenerator/main/EncounterGenerator.java index 6b17b59..035a63b 100644 --- a/src/eu/smoser/dungeongenerator/main/EncounterGenerator.java +++ b/src/eu/smoser/dungeongenerator/main/EncounterGenerator.java @@ -11,6 +11,8 @@ import java.util.Objects; * @author MrMcX */ public class EncounterGenerator extends AGenerator { + private static final long serialVersionUID = 1L; + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/src/eu/smoser/dungeongenerator/main/TreasureGenerator.java b/src/eu/smoser/dungeongenerator/main/TreasureGenerator.java index d1e5895..781ca05 100644 --- a/src/eu/smoser/dungeongenerator/main/TreasureGenerator.java +++ b/src/eu/smoser/dungeongenerator/main/TreasureGenerator.java @@ -9,6 +9,8 @@ import javax.swing.*; * @author mosers */ public class TreasureGenerator extends AGenerator { + private static final long serialVersionUID = 1L; + /** * This method is called from within the constructor to initialize the form. */