Skip to content

Commit

Permalink
Edited the configuration syntax to be easier
Browse files Browse the repository at this point in the history
  • Loading branch information
zessirb committed Jun 27, 2018
1 parent f917cad commit 7f4438d
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 195 deletions.
169 changes: 68 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,115 +16,82 @@ into the mods folder on your server.

## Configuration
The dialogs need to be configured first, like the following example.
* The **id** is used to reference a dialog from an other one or from a command call
* The **id** number is used to reference a dialog from an other one or from a command call
* The **trigger** defines a list of villager names that will trigger the dialog when the player right click them
* The optional **objective** field is used to map custom objectives that act as variables being edited as a result of some dialog action
* The optional **items** field is a string matching an item name (or its id if itemizer is present) and the amount required.
* The **pages** contains the one or many pages a dialog contains
* The **text** is the one going to be displayed to the player on this page
* The **text** is the one going to be displayed to the player on this page.
* The **buttons** is a list of clickable text buttons that are going to trigger some event
* The **text** is what will be displayed and clickable
* The **color** defines the color of the button
* The array **actions** list the actions the button will execute
* The **name** must match one of the available actions, being : [OPEN_DIALOG|TELEPORT|GIVE_ITEM|REMOVE_ITEM|SET_OBJECTIVE]
* The **arg** depends on the action
* The array **actions** list the actions the button will execute. Must match one of the available actions, being : [OPEN_DIALOG|TELEPORT|GIVE_ITEM|REMOVE_ITEM|SET_OBJECTIVE]
```
dialogs = [
{
id = 1,
trigger = ["Steve the villager"],
objective: "steve_asking_wood==0",
pages = [
{
text: "Hello ! Would you kindly bring me some wood please ?",
buttons: [
{
text : "> I will bring you wood !",
color: "BLACK",
actions : [
{
name: "SET_OBJECTIVE",
arg: "steve_asking_wood=1"
}
]
}
]
}
]
},
{
id = 2,
trigger = ["Steve the villager"],
objective : "steve_asking_wood==1",
items: "minecraft:log 5",
pages = [
{
text : "This wood looks beautiful on you !",
buttons: [
{
text : "Here, take my wood",
color: "BLUE",
actions : [
{
name: "SET_OBJECTIVE",
arg: "steve_asking_wood=2"
},
{
name: "REMOVE_ITEM",
arg: "minecraft:log 5"
},
{
name: "START_KILL_COUNT",
arg:"Zombie"
}
]
}
]
}
]
},
{
id = 3,
trigger = ["Steve the villager"],
objective : "steve_asking_wood==2",
killcount: "Zombie>=5",
pages = [
{
text : "I'm grateful for the wood, but I'd also like you to kill some zombies.",
buttons: [
{
text : "> I killed some zombies !",
color: "RED",
actions : [
{
name: "SET_OBJECTIVE",
arg: "steve_asking_wood=3"
}
]
}
]
}
]
},
{
id = 4,
trigger = ["Steve the villager"],
objective : "steve_asking_wood==2",
pages = [
{
text : "I'm grateful for the wood, but I'd also like you to kill 5 zombies.",
buttons: [
{
text : "> Alright then",
color: "BLACK"
}
]
}
]
}
]
1 = {
trigger: ["Steve the villager"]
objective: "steve_asking_wood==0"
pages: [
{
text: "Hello ! Would you kindly bring me some wood please ?"
buttons: [
{
text : "&0> I will bring you wood !"
actions : ["SET_OBJECTIVE steve_asking_wood=1"]
}
]
}
]
}
2 = {
trigger: ["Steve the villager"]
objective : "steve_asking_wood==1"
items: "minecraft:log 5"
pages: [
{
text : "This wood looks beautiful on you !"
buttons: [
{
text : "&2Here, take my wood"
actions : ["SET_OBJECTIVE steve_asking_wood=2", "REMOVE_ITEM minecraft:log 5", "START_KILL_COUNT Zombie"]
}
]
}
]
}
3 = {
trigger: ["Steve the villager"]
objective : "steve_asking_wood==2"
killcount: "Zombie>=5"
pages: [
{
text : "I'm grateful for the wood, but I'd also like you to kill some zombies.",
buttons: [
{
text : "&4> I killed some &6zombies &4!",
actions : ["SET_OBJECTIVE steve_asking_wood=3"]
}
]
}
]
}
4 = {
trigger: ["Steve the villager"]
objective: "steve_asking_wood==2"
pages: [
{
text: "I'm grateful for the wood, but I'd also like you to kill 5 zombies."
buttons: [
{
text: "> Alright then"
}
]
}
]
}
```
Here is the list of the available button actions and there arguments :
Here is the list of the available button actions and there arguments (separated with spaces) :
- **OPEN_DIALOG** : Open the dialog with the given *id* (given as argument)
- **EXECUTE_COMMAND** : Execute the *command* given as argument
- **GIVE_ITEM** : Give an item to the player. Fill with an item name or itemizer id, followed by a space and the amount you want to give
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/ylinor/storyteller/BookGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ private Text generateButton(ButtonBean buttonBean, List<String> npcNames) {
textBuilder.append(coloredContent);
textBuilder.append(Text.of("\n"));
// Deprecated color system
Optional<TextColor> textColor = game.getRegistry().getType(TextColor.class,buttonBean.getColor().toUpperCase());
if (textColor.isPresent()) {
textBuilder.color(textColor.get());
if (buttonBean.getColor() != null) {
Optional<TextColor> textColor = game.getRegistry().getType(TextColor.class,buttonBean.getColor().toUpperCase());
if (textColor.isPresent()) {
textBuilder.color(textColor.get());
}
}
// Iterate button actions
List<ActionBean> actions = buttonBean.getActions();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ylinor/storyteller/Storyteller.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static BookGenerator getBookGenerator(){
public void onServerStart(GameInitializationEvent event) {
instance = this;
try {
getLogger().info("Dialogues configuration loaded." +loadConfig()+ "Dialogs loaded");
getLogger().info("Dialogs configuration loaded. " +loadConfig()+ " dialogs loaded");
} catch (ObjectMappingException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Singleton
Expand All @@ -50,9 +51,20 @@ public int readDialogsConfiguration(List<CommentedConfigurationNode> configurati
TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(DialogBean.class), new DialogSerializer());

for (CommentedConfigurationNode configNode : configurationNodes) {
dialogList.addAll(configNode.getNode("dialogs").getList(TypeToken.of(DialogBean.class)));
for (Map.Entry<Object, ?> configEntry : configNode.getChildrenMap().entrySet()) {
String configEntryKey = (String) configEntry.getKey();
CommentedConfigurationNode configEntryNode = (CommentedConfigurationNode)configEntry.getValue();
// Legacy configuration where "dialogs" is the root node
if (configEntryKey.equals("dialogs")) {
dialogList.addAll(configEntryNode.getList(TypeToken.of(DialogBean.class)));
} else {
// Current configuration mode where dialogs are by key-values
DialogBean dialog = configEntryNode.getValue(TypeToken.of(DialogBean.class));
dialog.setId(Integer.parseInt(configEntryKey));
dialogList.add(dialog);
}
}
}
// Storyteller.getLogger().error("Error while reading configuration 'storyteller' : " + e.getMessage());

return dialogList.size();
}
Expand Down Expand Up @@ -88,8 +100,8 @@ public List<CommentedConfigurationNode> loadConfiguration(String configName) {
configNode = configLoader.load(options);
commentedNodes.add(configNode);
} catch (IOException e) {
Storyteller.getLogger().error("Error while loading configuration '" + p + "' : " + e.getMessage());
}
Storyteller.getLogger().error("Error while loading configuration '" + p + "' : " + e.getMessage());
}
}


Expand Down
Loading

0 comments on commit 7f4438d

Please sign in to comment.