Skip to content

Commit

Permalink
Merge pull request #58 from xFranco99/feature/conversation-courtesy-p…
Browse files Browse the repository at this point in the history
…hrases

ADD - added courtesy phrases to silent npc
  • Loading branch information
hdescottes authored Mar 18, 2024
2 parents 3f39d56 + 2db9e19 commit 3dbea4e
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 4 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/com/gdx/game/common/Constats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gdx.game.common;

public class Constats {

public static final String FOE = "FOE";

public static final String COURTESY_PHRASES_PATH = "conversations/conversation_courtesy.json";

}
15 changes: 15 additions & 0 deletions core/src/main/java/com/gdx/game/dialog/ConversationGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,19 @@ public String toString() {
return outputString.toString();
}

public Hashtable<String, Conversation> getConversations() {
return conversations;
}

public Hashtable<String, ArrayList<ConversationChoice>> getAssociatedChoices() {
return associatedChoices;
}

public void setAssociatedChoices(Hashtable<String, ArrayList<ConversationChoice>> associatedChoices) {
this.associatedChoices = associatedChoices;
}

public void setCurrentConversationID(String currentConversationID) {
this.currentConversationID = currentConversationID;
}
}
21 changes: 19 additions & 2 deletions core/src/main/java/com/gdx/game/dialog/ConversationUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Random;

import static com.gdx.game.common.Constats.COURTESY_PHRASES_PATH;
import static com.gdx.game.common.Constats.FOE;

public class ConversationUI extends Window {
private static final Logger LOGGER = LoggerFactory.getLogger(ConversationUI.class);
Expand All @@ -30,6 +34,8 @@ public class ConversationUI extends Window {

private Json json;

private Random random = new Random();

public ConversationUI() {
super("dialog", ResourceManager.skin);

Expand Down Expand Up @@ -98,15 +104,26 @@ public void loadConversation(EntityConfig entityConfig) {

clearDialog();

if (fullFilenamePath.isEmpty() || !Gdx.files.internal(fullFilenamePath).exists()) {
LOGGER.debug("Conversation file does not exist!");
if(FOE.equalsIgnoreCase(entityConfig.getEntityStatus())){
LOGGER.debug("The NPC is an Enemy");
return;
}

if (fullFilenamePath.isEmpty() || !Gdx.files.internal(fullFilenamePath).exists()) {
fullFilenamePath = COURTESY_PHRASES_PATH;
}

currentEntityID = entityConfig.getEntityID();
this.getTitleLabel().setText(entityConfig.getEntityID());

ConversationGraph graph = json.fromJson(ConversationGraph.class, Gdx.files.internal(fullFilenamePath));

// if the npc has nothing to say, use a random courtesy phrases
if(graph.getCurrentConversationID() == null){
int randomNumber = random.nextInt(graph.getConversations().size()) + 1;
graph.setCurrentConversationID(String.valueOf(randomNumber));
}

setConversationGraph(graph);
}

Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/com/gdx/game/screen/MenuScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ private void handleOptionButton() {
optionButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent even, float x, float y) {
setScreenWithTransition((BaseScreen) gdxGame.getScreen(), new OptionScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager), new ArrayList<>());
setScreenWithTransition(
(BaseScreen) gdxGame.getScreen(),
new OptionScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager),
new ArrayList<>()
);
}
});
}
Expand All @@ -90,7 +94,11 @@ private void handleNewButton() {
newButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent even, float x, float y) {
setScreenWithTransition((BaseScreen) gdxGame.getScreen(), new MenuNewGameScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager), new ArrayList<>());
setScreenWithTransition(
(BaseScreen) gdxGame.getScreen(),
new MenuNewGameScreen(gdxGame, (BaseScreen) gdxGame.getScreen(), resourceManager),
new ArrayList<>()
);
}
});
}
Expand Down
84 changes: 84 additions & 0 deletions core/src/main/resources/conversations/conversation_courtesy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
conversations: {
1: {
id: 1
dialog: Hi.
}
2: {
id: 2
dialog: What a beautiful day!
}
3: {
id: 3,
dialog: Greetings stranger.
}
4: {
id: 4,
dialog: Well met traveler!
}
5: {
id: 5,
dialog: May the winds guide you on your journey
}
6: {
id: 6
dialog: See you later traveler!
}
}
associatedChoices: {
1: [
{
class: com.gdx.game.dialog.ConversationChoice
sourceId: 1
destinationId: 7
choicePhrase: "Bye."
conversationCommandEvent: EXIT_CONVERSATION
}
],
2: [
{
class: com.gdx.game.dialog.ConversationChoice
sourceId: 1
destinationId: 7
choicePhrase: "Bye."
conversationCommandEvent: EXIT_CONVERSATION
}
],
3: [
{
class: com.gdx.game.dialog.ConversationChoice
sourceId: 1
destinationId: 7
choicePhrase: "Bye."
conversationCommandEvent: EXIT_CONVERSATION
}
],
4: [
{
class: com.gdx.game.dialog.ConversationChoice
sourceId: 1
destinationId: 7
choicePhrase: "Bye."
conversationCommandEvent: EXIT_CONVERSATION
}
],
5: [
{
class: com.gdx.game.dialog.ConversationChoice
sourceId: 1
destinationId: 7
choicePhrase: "Bye."
conversationCommandEvent: EXIT_CONVERSATION
}
],
6: [
{
class: com.gdx.game.dialog.ConversationChoice
sourceId: 1
destinationId: 7
choicePhrase: "Bye."
conversationCommandEvent: EXIT_CONVERSATION
}
]
}
}

0 comments on commit 3dbea4e

Please sign in to comment.