Skip to content

Commit

Permalink
Build 0.0.757
Browse files Browse the repository at this point in the history
Build 0.0.757
  • Loading branch information
HackusatePvP committed Feb 18, 2024
2 parents dd8bf6c + 0c6c94d commit b6eb943
Show file tree
Hide file tree
Showing 46 changed files with 805 additions and 626 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ build/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store
/.idea/
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>me.piitex</groupId>
<artifactId>RenJava</artifactId>
<name>RenJava</name>
<version>0.0.539-SNAPSHOT</version>
<version>0.0.757-SNAPSHOT</version>
<build>
<resources>
<resource>
Expand Down
8 changes: 4 additions & 4 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.733-SNAPSHOT</version>
<version>0.0.757-SNAPSHOT</version>
<name>RenJava</name>

<properties>
Expand Down Expand Up @@ -36,17 +36,17 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19.0.2.1</version>
<version>21.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19.0.2.1</version>
<version>21.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>19.0.2.1</version>
<version>21.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/me/piitex/renjava/RenJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import me.piitex.renjava.addons.Addon;
import me.piitex.renjava.addons.AddonLoader;
import me.piitex.renjava.api.builders.ButtonBuilder;
Expand All @@ -27,7 +29,6 @@
import me.piitex.renjava.gui.Menu;
import me.piitex.renjava.gui.layouts.impl.VerticalLayout;
import me.piitex.renjava.gui.overlay.ButtonOverlay;
import me.piitex.renjava.gui.splashscreen.SplashScreenView;
import me.piitex.renjava.gui.StageType;

import java.io.IOException;
Expand Down Expand Up @@ -85,6 +86,8 @@ public abstract class RenJava {
private final Collection<EventListener> registeredListeners = new HashSet<>();
private final Collection<PersistentData> registeredData = new HashSet<>();

protected String buildVersion;

private static RenJava instance;

/**
Expand Down Expand Up @@ -153,7 +156,7 @@ public Logger getLogger() {
}

public String getBuildVersion() {
return "0.0.311";
return buildVersion;
}

public Stage getStage() {
Expand Down Expand Up @@ -263,7 +266,7 @@ public Collection<PersistentData> getRegisteredData() {
/**
* Registers an {@link EventListener} to handle game events.
* <p>
* The {@code registerListener} method is used to register an {@link EventListener} that handles game events.
* This method is used to register an {@link EventListener} that handles game events.
* Event listeners can listen for specific events and perform actions in response to those events.
* <p>
* To register an event listener, pass an instance of the event listener class that implements the {@link EventListener} interface
Expand Down Expand Up @@ -294,8 +297,12 @@ public void buildStage(Stage stage) {
logger.warning("No window icon set. Please set a window icon for a better user experience.");
}

stage.initStyle(StageStyle.DECORATED);

if (getSettings().isFullscreen()) {
stage.setFullScreen(true);
} else {
stage.setMaximized(true);
}
stage.setTitle(getName());

Expand Down Expand Up @@ -378,7 +385,7 @@ public void buildStage(Stage stage) {
*
* @return A `SplashScreenView` object representing the splash screen view to be displayed.
*/
public abstract SplashScreenView buildSplashScreen();
public abstract Menu buildSplashScreen();

/**
* Called to create the main menu. (This is NOT optional)
Expand All @@ -388,12 +395,14 @@ public void buildStage(Stage stage) {

public Menu buildSideMenu() {
// Don't build background image
Menu menu = new Menu(new ImageLoader("gui/overlay/main_menu.png"), 350, 500);
Menu menu = new Menu(350, 500, new ImageLoader("gui/overlay/main_menu.png"));

Font uiFont = RenJava.getInstance().getConfiguration().getUiFont().getFont();

ButtonOverlay startButton = new ButtonOverlay(new ButtonBuilder("menu-start-button", "Start", Color.BLACK, 1, 1));
ButtonOverlay loadButton = new ButtonOverlay(new ButtonBuilder("menu-load-button", "Load", Color.BLACK, 1, 1));
ButtonOverlay optionsButton = new ButtonOverlay(new ButtonBuilder("menu-preference-button", "Preferences", Color.BLACK, 1, 1));
ButtonOverlay aboutButton = new ButtonOverlay(new ButtonBuilder("menu-about-button", "About", Color.BLACK, 1, 1));
ButtonOverlay startButton = new ButtonOverlay(new ButtonBuilder("menu-start-button", "Start", uiFont, Color.BLACK, 1, 1));
ButtonOverlay loadButton = new ButtonOverlay(new ButtonBuilder("menu-load-button", "Load", uiFont, Color.BLACK, 1, 1));
ButtonOverlay optionsButton = new ButtonOverlay(new ButtonBuilder("menu-preference-button", "Preferences", uiFont, Color.BLACK, 1, 1));
ButtonOverlay aboutButton = new ButtonOverlay(new ButtonBuilder("menu-about-button", "About", uiFont, Color.BLACK, 1, 1));

// Create vbox for the buttons. You can also do an HBox
VerticalLayout layout = new VerticalLayout(200, 500);
Expand All @@ -409,7 +418,7 @@ public Menu buildSideMenu() {
}

public Menu buildLoadMenu() {
Menu menu = new Menu(new ImageLoader("gui/main_menu.png"), 1920, 1080);
Menu menu = new Menu(1920, 1080, new ImageLoader("gui/main_menu.png"));

return menu;
}
Expand Down
44 changes: 42 additions & 2 deletions src/main/java/me/piitex/renjava/RenLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Properties;
import java.util.stream.Stream;

import me.piitex.renjava.api.builders.FontLoader;
Expand All @@ -20,6 +21,7 @@ public class RenLoader {
public RenLoader(RenJava renJava) {
this.renJava = renJava;
renJava.getLogger().info("Starting processes...");
renJava.buildVersion = getVersion();
setupMain();
setupGame();
startPreProcess();
Expand All @@ -39,6 +41,11 @@ private void setupMain() {
} catch (IOException e) {
e.printStackTrace();
}
for (File file : new File(System.getProperty("user.dir")).listFiles()) {
if (file.getName().endsWith(".txt.lck")) {
file.delete();
}
}
}

private void setupGame() {
Expand Down Expand Up @@ -78,8 +85,6 @@ private void startPreProcess() {
renJava.preEnabled();

// Build setting file
File directory = new File(System.getProperty("user.dir") + "/renjava/");
directory.mkdir();
renJava.setSettings(new SettingsProperties());

// After this method jump to GuiLoader. Loading is a little confusing if you want an idea of how the loader works, check out the Launch class.
Expand All @@ -90,4 +95,39 @@ private void startPreProcess() {
private void loadRPAFiles() {
// load rpa files
}

public synchronized String getVersion() {
String version = null;

// try to load from maven properties first
try {
Properties p = new Properties();
InputStream is = getClass().getResourceAsStream("/META-INF/maven/me.piitex/RenJava/pom.properties");
if (is != null) {
p.load(is);
version = p.getProperty("version", "");
}
} catch (Exception e) {
// ignore
}

// fallback to using Java API
if (version == null) {
Package aPackage = getClass().getPackage();
if (aPackage != null) {
version = aPackage.getImplementationVersion();
if (version == null) {
version = aPackage.getSpecificationVersion();
}
}
}

if (version == null) {
// we could not compute the version so use a blank
version = "";
}

return version.replace("-SNAPSHOT", "");
}

}
6 changes: 3 additions & 3 deletions src/main/java/me/piitex/renjava/addons/AddonLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public AddonLoader(Logger logger) {

public void load() {
File directory = new File(System.getProperty("user.dir") + "/addons/");
if (directory.mkdir()) {
logger.warning("Created directory '" + "addons" + "'.");
}
logger.info("Initializing Addon Loader...");
int size = directory.listFiles().length;
if (size == 0) {
Expand Down Expand Up @@ -92,8 +95,6 @@ public void load() {

while (!validations.isEmpty()) {
lateLoaders.forEach((file, string) -> {
logger.info("Last Validation: " + lastValidated);
logger.info("Validating: " + file.getName());
if (lastValidated.get().equalsIgnoreCase(file.getName())) {
logger.severe("Could not initialize " + file.getName() + ": May be the result of a missing dependency.");
validations.remove(file);
Expand Down Expand Up @@ -159,7 +160,6 @@ private void initAddon(File file, @Nullable Collection<Addon> dependencies) thro
if (clazzString.endsWith(".class")) {
String clazzName = clazzString.replace('/', '.').substring(0, clazzString.length() - 6); // removes the .class at the end

// FIXME: 12/24/2023 This has some serious security concerns. This executes code from any jar inside of addons and offers no real detection for malicious code.
// Authors should warn users about using pirated versions or getting addons from unknown sources.
Class<?> clazz = cl.loadClass(clazzName);
if (Addon.class.isAssignableFrom(clazz)) {
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/me/piitex/renjava/api/builders/ButtonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ public ButtonBuilder(String id, String text, Font font, Color color, double x, d
this.yScale = yScale;
}

/**
* Create a button with only text with a specific font.
*
* @param id Identifier for the button.
* @param text Text that will be displayed inside the button.
* @param font Font to be used for the text.
* @param color Color of the text.
* @param xScale X-Axis scale of the button.
* @param yScale Y-Axis scale of the button.
*/
public ButtonBuilder(String id, String text, Font font, Color color, double xScale, double yScale) {
this.id = id;
this.text = text;
this.font = font;
this.color = color;
this.xScale = xScale;
this.yScale = yScale;
}

/**
* Create a button with only an image.
*
Expand Down Expand Up @@ -200,6 +219,9 @@ public Button build() {
}
if (font != null) {
button.setFont(font);
} else {
// Set default font
button.setFont(RenJava.getInstance().getConfiguration().getUiFont().getFont());
}
if (color != null) {
button.setTextFill(color);
Expand All @@ -211,11 +233,6 @@ public Button build() {
button.setScaleX(xScale);
button.setScaleY(yScale);

FontLoader defaultFont = RenJava.getInstance().getConfiguration().getDefaultFont();
double size = defaultFont.getSize() * xScale;
defaultFont.setSize(size);
button.setFont(defaultFont.getFont());

button.setOnAction(actionEvent -> {
ButtonClickEvent event = new ButtonClickEvent(RenJava.getInstance().getPlayer().getCurrentScene(), button);
RenJava.callEvent(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.piitex.renjava.api.builders;

import javafx.scene.control.TextField;


public class InputFieldBuilder {
private final double x;
private final double y;
private final FontLoader fontLoader;

public InputFieldBuilder(double x, double y, FontLoader fontLoader) {
this.x = x;
this.y = y;
this.fontLoader = fontLoader;
}

public double getX() {
return x;
}

public double getY() {
return y;
}

public FontLoader getFontLoader() {
return fontLoader;
}

public TextField build() {
TextField textField = new TextField();
textField.setTranslateX(x);
textField.setTranslateY(y);
textField.setStyle("");
textField.setStyle("-fx-control-inner-background: transparent; -fx-background-color transparent;");
return textField;
}
}
18 changes: 13 additions & 5 deletions src/main/java/me/piitex/renjava/api/player/Player.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package me.piitex.renjava.api.player;

import javafx.scene.image.ImageView;

import me.piitex.renjava.api.APINote;
import me.piitex.renjava.api.builders.ImageLoader;
import me.piitex.renjava.api.saves.data.Data;
import me.piitex.renjava.api.saves.data.PersistentData;
import me.piitex.renjava.api.scenes.RenScene;
Expand All @@ -20,8 +19,9 @@ public class Player implements PersistentData {
private boolean rightClickMenu;
@Data private String currentScene;
@Data private String currentStory;
private ImageView lastDisplayedImage;
private ImageLoader lastDisplayedImage;

private boolean transitionPlaying = false;
private boolean uiToggled = true;

private boolean skipAutoScene = false;
Expand Down Expand Up @@ -93,11 +93,11 @@ public void setRightClickMenu(boolean rightClickMenu) {
this.rightClickMenu = rightClickMenu;
}

public ImageView getLastDisplayedImage() {
public ImageLoader getLastDisplayedImage() {
return lastDisplayedImage;
}

public void setLastDisplayedImage(ImageView lastDisplayedImage) {
public void setLastDisplayedImage(ImageLoader lastDisplayedImage) {
this.lastDisplayedImage = lastDisplayedImage;
}

Expand All @@ -117,6 +117,14 @@ public void setSkipAutoScene(boolean skipAutoScene) {
this.skipAutoScene = skipAutoScene;
}

public boolean isTransitionPlaying() {
return transitionPlaying;
}

public void setTransitionPlaying(boolean transitionPlaying) {
this.transitionPlaying = transitionPlaying;
}

public void updateScene(RenScene renScene) {
setCurrentScene(renScene.getId()); // Update the scene.
getViewedScenes().put(new AbstractMap.SimpleEntry<>(renScene.getStory(), renScene.getId()), renScene);
Expand Down
Loading

0 comments on commit b6eb943

Please sign in to comment.