Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Add metadata to guis
Browse files Browse the repository at this point in the history
  • Loading branch information
virustotalop committed Nov 16, 2020
1 parent fc66aa9 commit 277dcf4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class GuiToken implements Serializable {
private MacroParser macroParser;
private FunctionTree functions;
private List<String> loadMacros;
private Map<String, String> metadata;
public GuiToken(ConfigurationSection section)
{
this(section, new ArrayList<MacroToken>());
Expand Down Expand Up @@ -81,6 +82,9 @@ public GuiToken(ConfigurationSection section, List<MacroToken> macroTokens)
this.functions = new FunctionTree(guiFunctionsSection, this.macroParser);

this.loadMacros = section.getStringList("load-macros");

ConfigurationSection metadataSection = section.getConfigurationSection("metadata");
this.metadata = this.parseMetadata(metadataSection);
}

public String parseType(String type)
Expand Down Expand Up @@ -109,10 +113,23 @@ private void loadNpcs(ConfigurationSection section)
for(String key : npcSection.getKeys())
{
List<Integer> npcIds = npcSection.getIntegerList(key);
npcs.put(key, npcIds);
this.npcs.put(key, npcIds);
}
}

private Map<String, String> parseMetadata(ConfigurationSection section)
{
Map<String, String> metadata = new HashMap<>();
for(String key : section.getKeys())
{
String parsedKey = this.macroParser.parseStringMacros(key);
String value = section.getString(parsedKey);
value = this.macroParser.parseStringMacros(value);
metadata.put(parsedKey, value);
}

return metadata;
}

private void loadSlots(ConfigurationSection section)
{
Expand Down Expand Up @@ -190,4 +207,9 @@ public List<String> getLoadMacros()
{
return this.loadMacros;
}

public Map<String, String> getMetadata()
{
return this.metadata;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.clubobsidian.dynamicgui.parser.test.gui;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Map;

import org.junit.Test;

import com.clubobsidian.dynamicgui.parser.gui.GuiToken;
import com.clubobsidian.dynamicgui.parser.slot.SlotToken;
import com.clubobsidian.wrappy.Configuration;
import com.clubobsidian.wrappy.ConfigurationSection;

public class GuitMetadataTest {

@Test
public void testSlotMetadata()
{
File slotFolder = new File("test", "gui");
File metadataFile = new File(slotFolder, "metadata.yml");
Configuration config = Configuration.load(metadataFile);
GuiToken token = new GuiToken(config);
Map<String, String> metadata = token.getMetadata();
assertTrue(metadata.size() == 1);
assertTrue(metadata.get("some").equals("metadata"));
}
}
2 changes: 2 additions & 0 deletions test/gui/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
metadata:
some: "metadata"

0 comments on commit 277dcf4

Please sign in to comment.