Skip to content

Commit

Permalink
Build 0.1.0 Beta
Browse files Browse the repository at this point in the history
Build 0.1.0 Beta
  • Loading branch information
HackusatePvP committed May 7, 2024
2 parents 258a41a + 8ea449a commit 1284329
Show file tree
Hide file tree
Showing 68 changed files with 1,655 additions and 845 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Visual novel game engine based off of [RenPy](https://www.renpy.org/) built with [JavaFX](https://openjfx.io/).

**Community**
- [Website](), [Discord](), [YouTube]()
- [Website]() (Not yet created), [Discord]() (Not yet created), [YouTube](https://www.youtube.com/channel/UC4iv_X0Pi8FoHFMUHBkHw1A)

## Requirements
- [Java-17](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) (You can typically download this within your IDE.)
## Project Requirements
- [Java-17](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) (You can typically download this within your IDE)
- [intellij](https://www.jetbrains.com/idea/download/?section=windows) or [Eclipse](https://www.eclipse.org/downloads/)
- Maven (should come with your IDE.)
- [Maven](https://maven.apache.org/download.cgi) (Might come with your IDE)

## Application Requirements
- Java
Expand Down
11 changes: 2 additions & 9 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@
<groupId>me.piitex</groupId>
<artifactId>RenJava</artifactId>
<name>RenJava</name>
<version>0.0.757-SNAPSHOT</version>
<version>0.1.0-SNAPSHOT</version>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/jasperreports_extension.properties</include>
<include>**/tecsofti-fonts.xml</include>
<include>**/*.ttf</include>
<include>**/*.png</include>
<include>**/*.jpeg</include>
<include>**/*.webp</include>
<include>**/*.webm</include>
<include>**/*.mp3</include>
<include>**/*.wav</include>
<include>**/*.css</include>
<include>**/*.*</include>
</includes>
</resource>
</resources>
Expand Down
31 changes: 22 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.piitex</groupId>
<artifactId>RenJava</artifactId>
<version>0.0.802-SNAPSHOT</version>
<version>0.1.0-SNAPSHOT</version>
<name>RenJava</name>

<properties>
Expand Down Expand Up @@ -48,6 +48,26 @@
<artifactId>javafx-media</artifactId>
<version>21.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>21.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -177,14 +197,7 @@
<includes>
<include>**/jasperreports_extension.properties</include>
<include>**/tecsofti-fonts.xml</include>
<include>**/*.ttf</include>
<include>**/*.png</include>
<include>**/*.jpeg</include>
<include>**/*.webp</include>
<include>**/*.webm</include>
<include>**/*.mp3</include>
<include>**/*.wav</include>
<include>**/*.css</include>
<include>**/*.*</include>
</includes>
</resource>
</resources>
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/me/piitex/renjava/Game.java

This file was deleted.

138 changes: 102 additions & 36 deletions src/main/java/me/piitex/renjava/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,128 @@
import javafx.application.Application;
import javafx.stage.Stage;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;

import me.piitex.renjava.api.Game;
import me.piitex.renjava.api.loaders.ImageLoader;
import me.piitex.renjava.configuration.Configuration;
import me.piitex.renjava.configuration.RenJavaConfiguration;
import me.piitex.renjava.gui.GuiLoader;
import me.piitex.renjava.loggers.ApplicationLogger;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;

import java.util.HashSet;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Launch extends Application {

public static void main(String[] args) {
// Scans for all classes in all packages. (We need to do all packages because this allows the author the freedom to do their own package scheme.)
Collection<URL> allPackagePrefixes = Arrays.stream(Package.getPackages())
.map(Package::getName)
.map(s -> s.split("\\.")[0])
.distinct()
.map(ClasspathHelper::forPackage)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
ConfigurationBuilder config = new ConfigurationBuilder().addUrls(allPackagePrefixes)
.addScanners(Scanners.SubTypes);
Reflections reflections = new Reflections(config);

// Detect any classes that extend RenJava
for (Class<?> c : reflections.getSubTypesOf(RenJava.class)) {
try {
Object o = c.getDeclaredConstructor().newInstance();
RenJava renJava = (RenJava) o;
if (c.getDeclaredConstructor().isAnnotationPresent(Game.class)) {
Game game = c.getDeclaredConstructor().getAnnotation(Game.class);
renJava.name = game.name();
renJava.author = game.author();
renJava.version = game.version();
} else {
System.err.println("Please annotate your main constructor with Game.\n\t\t@Game\n\t\tpublic void " + c.getDeclaredConstructor().getName() + "() { }");
renJava.name = "Error";
renJava.author = "Error";
renJava.version = "Error";
File file = new File(System.getProperty("user.dir") + "/renjava/build.info");
boolean failed = true;

if (file.exists()) {
try (InputStream inputStream = new FileInputStream(file);
Scanner scanner = new Scanner(inputStream)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.toLowerCase().startsWith("main=")) {
String[] split = line.split("=");
String clazzName = split[1];
Class<?> clazz = Class.forName(clazzName);
loadClass(clazz, args);
failed = false;
break;
}
}
renJava.init(); // Initialize game
launch(args);
//c.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
e.printStackTrace();
} catch (IOException | ClassNotFoundException e) {
System.err.println("Failed to load class: " + e.getMessage());
}
}

if (failed) {
System.err.println("Build info not found. Scanning for RenJava class. This will have noticeable performance impact on low end computers.");
// Scans for all classes in all packages. (We need to do all packages because this allows the author the freedom to do their own package scheme.)
Collection<URL> allPackagePrefixes = Arrays.stream(Package.getPackages())
.map(Package::getName)
.map(s -> s.split("\\.")[0])
.distinct()
.map(ClasspathHelper::forPackage)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
ConfigurationBuilder config = new ConfigurationBuilder().addUrls(allPackagePrefixes)
.addScanners(Scanners.SubTypes);
Reflections reflections = new Reflections(config);

// Detect any classes that extend RenJava
for (Class<?> c : reflections.getSubTypesOf(RenJava.class)) {
loadClass(c, args);
return;
}
return;
}
}

private static void loadClass(Class<?> clazz, String[] args) {
//FIXME: For performance save the path of the main class to reduce loading time
try {
File file = new File(System.getProperty("user.dir") + "/renjava/build.info");
if (!file.exists()) {
file.createNewFile();
}

FileWriter writer = new FileWriter(file);
writer.append("main=").append(clazz.getName());
writer.close();
} catch (IOException e) {
System.err.println("Could not create the 'build.info' file. This might be a first time setup. Once the application opens please exit and relaunch.");
}

System.err.println("Could not initialize RenJava. Please make a class which extends 'RenJava'.");

try {
Object o = clazz.getDeclaredConstructor().newInstance();
RenJava renJava = (RenJava) o;
if (renJava.getClass().isAnnotationPresent(Game.class)) {
Game game = renJava.getClass().getAnnotation(Game.class);
renJava.name = game.name();
renJava.author = game.author();
renJava.version = game.version();
} else {
System.err.println("ERROR: Please annotate your main class with 'Game'.");
renJava.name = "Error";
renJava.author = "Error";
renJava.version = "Error";
}

// Build configuration
if (renJava.getClass().isAnnotationPresent(Configuration.class)) {
Configuration conf = renJava.getClass().getAnnotation(Configuration.class);
RenJavaConfiguration configuration = new RenJavaConfiguration(conf.title().replace("{version}", renJava.version).replace("{name}", renJava.name).replace("{author}", renJava.author), conf.width(), conf.height(), new ImageLoader(conf.windowIconPath()));
renJava.setConfiguration(configuration);

} else {
System.err.println("ERROR: Configuration annotation not found. Please annotate your main class with 'Configuration'");
RenJavaConfiguration configuration = new RenJavaConfiguration("Error", 1920, 1080, new ImageLoader("gui/window_icon.png"));
renJava.setConfiguration(configuration);
}

// Initialize the application logger
ApplicationLogger applicationLogger = new ApplicationLogger(clazz);
renJava.setLogger(applicationLogger.LOGGER);

renJava.getLogger().info("Initialized logger...");

renJava.init(); // Initialize game
launch(args);
//c.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
System.err.println("ERROR: Could initialize the RenJava framework: " + e.getMessage());
}
}

@Override
Expand Down
Loading

0 comments on commit 1284329

Please sign in to comment.