Skip to content

Commit

Permalink
Add gui types
Browse files Browse the repository at this point in the history
  • Loading branch information
virustotalop committed Feb 22, 2021
1 parent 3fd4e5b commit 130c946
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class GuiToken implements Serializable {
private static final long serialVersionUID = -1815626830683338944L;

private static final int MAX_SLOT_SIZE = 100; //Temporary fix


private String type;
private String title;
private String content;
private List<String> alias;
Expand All @@ -62,6 +63,7 @@ public GuiToken(ConfigurationSection section, List<MacroToken> macroTokens) {
copyMacroTokens.add(new MacroToken(macrosSection));

this.macroParser = new MacroParser(copyMacroTokens);
this.type = this.macroParser.parseStringMacros(this.getString(section, "type", "simple"));
this.title = this.macroParser.parseStringMacros(section.getString("title"));
this.content = this.macroParser.parseStringMacros(section.getString("content"));
this.alias = this.macroParser.parseListMacros(section.getStringList("alias"));
Expand All @@ -76,7 +78,15 @@ public GuiToken(ConfigurationSection section, List<MacroToken> macroTokens) {
ConfigurationSection metadataSection = section.getConfigurationSection("metadata");
this.metadata = this.parseMetadata(metadataSection);
}


private String getString(ConfigurationSection section, String key, String defaultValue) {
String value = section.getString(key);
if(value == null) {
value = defaultValue;
}
return value;
}

private void loadNpcs(ConfigurationSection section) {
this.npcs = new HashMap<>();
ConfigurationSection npcSection = section.getConfigurationSection("npcs");
Expand Down Expand Up @@ -109,6 +119,10 @@ private Map<String, String> parseMetadata(ConfigurationSection section) {
return metadata;
}

public String getType() {
return this.type;
}

public String getTitle() {
return this.title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ public static void loadToken() {
Configuration config = Configuration.load(file);
token = new GuiToken(config);
}


@Test
public void testType() {
String title = token.getType();
assertEquals(title, "modal");
}

@Test
public void testTitle() {
String title = token.getTitle();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.clubobsidian.dynamicform.parser.test.gui;

import com.clubobsidian.dynamicform.parser.gui.GuiToken;
import com.clubobsidian.wrappy.Configuration;
import org.junit.Test;

import java.io.File;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TypeDoesNotExistTest {

@Test
public void testDoesNotExist() {
File slotFolder = new File("test", "gui");
File file = new File(slotFolder, "alias.yml");
Configuration config = Configuration.load(file);
GuiToken token = new GuiToken(config);
String type = token.getType();
assertEquals(type, "simple");
}
}
1 change: 1 addition & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
title: "test gui title"
content: "foobar"
type: "modal"
rows: 1
mode: "set"
close: true
Expand Down

0 comments on commit 130c946

Please sign in to comment.