Skip to content

Commit

Permalink
fix: various minor issues (#115)
Browse files Browse the repository at this point in the history
* fix: cancel timer when close button pressed

* fix: change opponent tag for boxer in location 4

* chore: disable new game screen after game end

* fix: move calls to callback to the main FX thread

* feat: add icon

* docs: update

* refact: move assets to package

* chore: final fixes
  • Loading branch information
kkafar committed Jun 12, 2022
1 parent df28510 commit 04676f5
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 18 deletions.
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'checkstyle'
}
group 'io.rpg'
version '1.0'
version '1.0.0'

repositories {
mavenCentral()
Expand Down Expand Up @@ -81,13 +81,20 @@ run {
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']

jpackage {
icon = 'src/main/resources/io/rpg/app.png'
appVersion = "1.0.0"
}

launcher {
name = 'app'
name = 'RPG-IO'
jvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.scene=io.rpg']
}
forceMerge('log4j-api')
}


jlinkZip {
group = 'distribution'
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"condition": {
"tag": "whatever",
"type": "defeat-opponent",
"opponent-tag": "zombie-2"
"opponent-tag": "zombie-4"
}
},
"onRightClick": {
Expand Down
3 changes: 2 additions & 1 deletion docs/resources.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Resources

* Default popup backgrounds and buttons: [Wood button vector created by upklyak - www.freepik.com](https://www.freepik.com/vectors/wood-button>)
* Coin: [Money sign vector created by rawpixel.com - www.freepik.com]("https://www.freepik.com/vectors/money-sign">)
* Coin: [Money sign vector created by rawpixel.com - www.freepik.com]("https://www.freepik.com/vectors/money-sign">)
* Characters: [by segel](https://opengameart.org/users/segel) (not all :D)
9 changes: 8 additions & 1 deletion src/main/java/io/rpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import com.kkafara.rt.Result;
import io.rpg.wrapper.WrapperController;
import java.io.IOException;
import javafx.application.Application;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;

import java.io.IOException;

/**
* Entry point of the app.
*/
Expand All @@ -20,6 +22,11 @@ public class Main extends Application {
public void start(Stage stage) throws IOException {
Configurator.setRootLevel(Level.WARN);
String path = getParameters().getNamed().get("config");

stage.setTitle("RPG-IO");

stage.getIcons().add(new Image((Main.class.getResource("app.png").toString())));

if (path == null) {
WrapperController wrapperController = WrapperController.load();
wrapperController.show(stage);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/rpg/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ else if (tagToLocationViewMap.size() != tagToLocationModelMap.size())

@Override
public void onKeyboardEvent(KeyboardEvent event) {
// TODO: implement event handling
logger.trace("Controller notified on key pressed from " + event.source());
//TODO: call Player::set...Pressed depending on keyCode and whether the key was pressed or released

KeyEvent payload = event.payload();

if (payload.getEventType() == KeyEvent.KEY_PRESSED) {
switch (payload.getCode()) {
case E ->
popupController.openInventoryPopup(playerController.getPlayer().getInventory(), getWindowCenterX(), getWindowCenterY(), playerController.getPlayer());
case E -> {
stopPlayer();
popupController.openInventoryPopup(playerController.getPlayer().getInventory(), getWindowCenterX(), getWindowCenterY(), playerController.getPlayer());
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/rpg/model/actions/ActionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ public void acceptQuizResult(GameObject opponent, boolean correct, int pointsCou
} else {
controller.getPopupController().hidePopup();
}
opponent.setOnLeftClickAction(Action.VOID);
} else {
controller.getPopupController().hidePopup();
logger.info("Wrong answer provided");
}

// TODO: better action disabling
opponent.setOnLeftClickAction(Action.VOID);
}

public void onAction(GameEndAction action) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/io/rpg/view/popups/BattleReflexPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public BattleReflexPopup(int pointsPerSecond, BiConsumer<Boolean, Integer> callb

timer.schedule(new TimerTask() {
public void run() {
Platform.runLater(() -> timerTick());
timerTick();
}
}, 1000, 1000);
button.setOnAction((event) -> {
Expand All @@ -154,8 +154,8 @@ public String generateRandomSequence(int length) {
private void timerTick() {
timeToCountDown--;
if (timeToCountDown < 0) {
timer.cancel();
lose();
timer.cancel();
return;
}
timerDots[timeToCountDown].setImage(new Image(PathUtils.resolvePathToJFXFormat(
Expand All @@ -164,15 +164,18 @@ private void timerTick() {
}

public void win() {
callback.accept(true, timeToCountDown * pointsPerSecond);
Platform.runLater(() -> callback.accept(true, timeToCountDown * pointsPerSecond));
timer.cancel();
}

public void lose() {
callback.accept(false, 0);
Platform.runLater(() -> callback.accept(false, 0));
}

public void setCloseButtonActionListener(EventHandler<ActionEvent> value) {
button.setOnAction(value);
button.setOnAction(event -> {
timer.cancel();
value.handle(event);
});
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/rpg/wrapper/WrapperController.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void onLoadClick() {
loadGame(path).ifOk(
g -> {
game = g;
game.setOnEnd(() -> show(stage));
// game.setOnEnd(() -> show(stage));
}
);
}
Expand Down
Binary file added src/main/resources/io/rpg/app.icns
Binary file not shown.
Binary file added src/main/resources/io/rpg/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04676f5

Please sign in to comment.