chore: Started implementing dialog
This commit is contained in:
9
src/main/java/cz/jzitnik/events/QuestionAnswerEvent.java
Normal file
9
src/main/java/cz/jzitnik/events/QuestionAnswerEvent.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package cz.jzitnik.events;
|
||||
|
||||
import cz.jzitnik.utils.events.Event;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class QuestionAnswerEvent implements Event {
|
||||
private int questionIndex;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cz.jzitnik.events.handlers;
|
||||
|
||||
import cz.jzitnik.annotations.EventHandler;
|
||||
import cz.jzitnik.annotations.injectors.InjectDependency;
|
||||
import cz.jzitnik.annotations.injectors.InjectState;
|
||||
import cz.jzitnik.events.QuestionAnswerEvent;
|
||||
import cz.jzitnik.game.GameState;
|
||||
import cz.jzitnik.game.dialog.Dialog;
|
||||
import cz.jzitnik.game.dialog.OnEnd;
|
||||
import cz.jzitnik.utils.DependencyManager;
|
||||
import cz.jzitnik.utils.events.AbstractEventHandler;
|
||||
import cz.jzitnik.utils.events.EventManager;
|
||||
|
||||
@EventHandler(QuestionAnswerEvent.class)
|
||||
public class QuestionAnswerEventHandler extends AbstractEventHandler<QuestionAnswerEvent> {
|
||||
public QuestionAnswerEventHandler(DependencyManager dm) {
|
||||
super(dm);
|
||||
}
|
||||
|
||||
@InjectState
|
||||
private GameState gameState;
|
||||
|
||||
@InjectDependency
|
||||
private EventManager eventManager;
|
||||
|
||||
@Override
|
||||
public void handle(QuestionAnswerEvent event) {
|
||||
OnEnd dialogOnEnd = gameState.getCurrentDialog().getOnEnd();
|
||||
|
||||
if (dialogOnEnd instanceof OnEnd.AskQuestion dialog) {
|
||||
OnEnd.AskQuestion.Answer answer = dialog.getAnswers()[event.getQuestionIndex()];
|
||||
Dialog switchTo = answer.dialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package cz.jzitnik.game;
|
||||
|
||||
import cz.jzitnik.annotations.State;
|
||||
import cz.jzitnik.game.dialog.Dialog;
|
||||
import cz.jzitnik.game.objects.Interactable;
|
||||
import cz.jzitnik.screens.Screen;
|
||||
import cz.jzitnik.utils.DependencyManager;
|
||||
@@ -25,6 +26,10 @@ public class GameState {
|
||||
@Setter
|
||||
private Interactable interacting;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Dialog currentDialog;
|
||||
|
||||
@Getter
|
||||
private Screen screen;
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ public class Player {
|
||||
private PlayerRotation playerRotation = PlayerRotation.FRONT;
|
||||
@Setter
|
||||
private GameItem selectedItem;
|
||||
@Setter
|
||||
private int health = MAX_HEALTH;
|
||||
private int stamina = MAX_STAMINA;
|
||||
private boolean swinging = false;
|
||||
|
||||
18
src/main/java/cz/jzitnik/game/dialog/Dialog.java
Normal file
18
src/main/java/cz/jzitnik/game/dialog/Dialog.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package cz.jzitnik.game.dialog;
|
||||
|
||||
import cz.jzitnik.utils.events.Event;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class Dialog implements Event {
|
||||
/**
|
||||
* Characters per second
|
||||
*/
|
||||
private int typingSpeed = 10;
|
||||
private final String text;
|
||||
private final OnEnd onEnd;
|
||||
}
|
||||
25
src/main/java/cz/jzitnik/game/dialog/OnEnd.java
Normal file
25
src/main/java/cz/jzitnik/game/dialog/OnEnd.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package cz.jzitnik.game.dialog;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public interface OnEnd {
|
||||
record Continue(Dialog nextDialog) implements OnEnd {
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
class AskQuestion implements OnEnd {
|
||||
private final String question;
|
||||
private final Answer[] answers;
|
||||
/**
|
||||
* Characters per second
|
||||
*/
|
||||
private int typingSpeed = 10;
|
||||
|
||||
public record Answer(String answer, Dialog dialog) {
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/main/java/cz/jzitnik/game/mobs/DialogMob.java
Normal file
27
src/main/java/cz/jzitnik/game/mobs/DialogMob.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package cz.jzitnik.game.mobs;
|
||||
|
||||
import cz.jzitnik.game.dialog.Dialog;
|
||||
import cz.jzitnik.game.utils.RoomCords;
|
||||
import cz.jzitnik.utils.DependencyManager;
|
||||
import cz.jzitnik.utils.roomtasks.RoomTask;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public abstract class DialogMob extends Mob {
|
||||
private final Dialog dialog;
|
||||
|
||||
public DialogMob(BufferedImage texture, RoomTask[] tasks, RoomCords cords, Dialog dialog) {
|
||||
super(texture, tasks, cords);
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
public DialogMob(BufferedImage texture, RoomTask task, RoomCords cords, Dialog dialog) {
|
||||
super(texture, task, cords);
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(DependencyManager dm) {
|
||||
|
||||
}
|
||||
}
|
||||
30
src/main/java/cz/jzitnik/game/setup/enemies/Pepa.java
Normal file
30
src/main/java/cz/jzitnik/game/setup/enemies/Pepa.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package cz.jzitnik.game.setup.enemies;
|
||||
|
||||
import cz.jzitnik.game.dialog.Dialog;
|
||||
import cz.jzitnik.game.dialog.OnEnd;
|
||||
import cz.jzitnik.game.mobs.DialogMob;
|
||||
import cz.jzitnik.game.utils.RoomCords;
|
||||
import cz.jzitnik.utils.roomtasks.RoomTask;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Pepa extends DialogMob {
|
||||
public Pepa(BufferedImage texture, RoomTask[] tasks, RoomCords cords) {
|
||||
super(texture, tasks, cords,
|
||||
new Dialog(
|
||||
"Never gonna give you up",
|
||||
new OnEnd.Continue(new Dialog(
|
||||
"Never gonna let you down",
|
||||
new OnEnd.Continue(new Dialog(
|
||||
"Never gonna run around", new OnEnd.AskQuestion(
|
||||
"How it continues?",
|
||||
new OnEnd.AskQuestion.Answer[]{
|
||||
new OnEnd.AskQuestion.Answer("And desert you", new Dialog("You are god damn right!", new OnEnd.Continue(null))),
|
||||
new OnEnd.AskQuestion.Answer("You are a dessert", new Dialog("WRONG!", new OnEnd.Continue(null)))
|
||||
}
|
||||
)))
|
||||
))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user