Skip to content

Commit

Permalink
Merge pull request #42 from tommai78101/feature/trigger-human-readable
Browse files Browse the repository at this point in the history
Feature/trigger human readable
  • Loading branch information
tommai78101 authored Aug 14, 2021
2 parents 920ff94 + cc565be commit dd13e07
Show file tree
Hide file tree
Showing 25 changed files with 514 additions and 254 deletions.
84 changes: 84 additions & 0 deletions common/src/main/java/enums/ItemCategories.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package enums;

public enum ItemCategories {
// @formatter:off
POTIONS(0x00, "POTIONS", "Potions"),
KEYITEMS(0x01, "KEYITEMS", "KeyItems"),
POKEBALLS(0x02, "POKEBALLS", "Pokéballs"),
TM_HM(0x03, "TM HM", "TMs_HMs"),
ALL(0x04, "ALL", "Unsorted");
// @formatter:on

private byte categoryByte;
private int id;
private String keyString;
private String chunkName;

private ItemCategories(int value, String chunkName, String key) {
this.id = value;
this.categoryByte = (byte) value;
this.keyString = key;
this.chunkName = chunkName;
}

/**
* Obtains a Category enum value that matches the given ID number.
*
* <p>
* If there is no Category that comes after the last element, it will give the first element, and
* wraps from there.
* </p>
*
* @param value
* The ID number of the category that is to be obtained.
*
* @return The category that matches the given ID number.
*/
public static ItemCategories getWrapped(int value) {
ItemCategories[] categories = ItemCategories.values();
if (value < 0)
value = (categories.length - 1);
if (value > categories.length - 1)
value = 0;
for (ItemCategories c : categories) {
if (c.id == value)
return categories[value];
}
return categories[0];
}

public int getID() {
return this.id;
}

public byte getByte() {
return this.categoryByte;
}

public String getKey() {
return this.keyString;
}

public boolean chunkEquals(String value) {
return this.chunkName.equals(value);
}

/**
* Returns the correct Category enum value. Otherwise, returns null if no Category matches the
* value.
*
* @param value
* @return
*/
public static ItemCategories convert(byte value) {
if (value == POTIONS.getByte())
return POTIONS;
if (value == KEYITEMS.getByte())
return KEYITEMS;
if (value == POKEBALLS.getByte())
return POKEBALLS;
if (value == TM_HM.getByte())
return TM_HM;
return null;
}
}
105 changes: 105 additions & 0 deletions common/src/main/java/enums/ItemTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package enums;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public enum ItemTags {
Type("%", "TYPE", "Item type"),
Name("#", "NAME", "Name of the item"),
Description("@", "DESCRIPTION", "Item description"),
Category("^", "CATEGORY", "Item category"),
Delimiter(";", "END", "End of the item information"),

// Item options
SetCommand("$", "DESCRIPTION", "Item description"),
UseCommand("!", "CATEGORY", "Item category"),
TossCommand("&", "END", "End of the item information");

private final String symbol;
private final String uppercaseSymbolName;
private final String lowercaseSymbolName;
private final String description;

private ItemTags(String sym, String alternate, String description) {
this.symbol = sym;
this.uppercaseSymbolName = alternate.toUpperCase();
this.lowercaseSymbolName = alternate.toLowerCase();
this.description = description;
}

/**
* Checks if the line starts with either the symbol representation, or the tag name.
*
* @param line
* @return True if either the symbol or the tag name matches. False, if otherwise.
*/
public boolean beginsAt(String line) {
if (line == null || line.isEmpty() || line.isBlank())
return false;
if (this.startsWithUpperCase(line) || line.startsWith(this.symbol))
return true;
String upper = line.toUpperCase().trim();
String lower = line.toLowerCase().trim();
if (upper.startsWith(this.uppercaseSymbolName) || lower.startsWith(this.lowercaseSymbolName))
return true;
return line.regionMatches(true, 0, this.name(), 0, this.name().length());
}

/**
* Replaces the first occurrence of the tag name with the equivalent symbol representation.
* <p>
* Otherwise, if the line already has the symbol representation, then it does nothing.
*
* @param line
* @return The replaced line.
*/
public String replace(String line) {
if (line.startsWith(this.symbol))
return line;
return line.replaceFirst(Pattern.quote(this.name()), Matcher.quoteReplacement(this.symbol));
}

public boolean startsWithUpperCase(String line) {
String[] tokens = line.toUpperCase().split(":=");
if (tokens.length > 0) {
String uppercase = tokens[0];
return (uppercase.trim().equals(this.uppercaseSymbolName));
}
return false;
}

/**
* Removes the script tag or script symbol from the given line, and returns the result.
*
* @param line
* The line that contains the script tag or symbol.
* @return The resulting string value after the script tag or symbol has been removed.
*/
public String removeItemTag(String line) {
if (line.startsWith(this.symbol))
return line.substring(this.symbol.length());
else if (line.toUpperCase().startsWith(this.uppercaseSymbolName) || line.toLowerCase().startsWith(this.lowercaseSymbolName)) {
// We ignore anything that comes before the script tag. We're not doing anything complicated here.
int endOfIndex = line.indexOf(this.uppercaseSymbolName) + this.uppercaseSymbolName.length();
return line.substring(endOfIndex).trim();
}
// Cannot remove any script tags or symbols.
return line;
}

public String getDescription() {
return this.description;
}

public String getPrettyDescription() {
return this.description + ".";
}

public String getSymbolName() {
return this.uppercaseSymbolName;
}

public String getLowercaseSymbolName() {
return this.lowercaseSymbolName;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package constants;
package enums;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -10,11 +10,12 @@
*
* @author tlee
*/
public enum ScriptTag {
ScriptName("@", "NAME", "Script Name"),
Comment("/", "COMMENT", "Comment"),
public enum ScriptTags {
ScriptName("@", "NAME", "Script name"),
Checksum("&", "CHKSUM", "Script checksum"),
Comment("/", "REM", "Comment"),
BeginScript("$", "BEGIN", "Script begins"),
PathData("^", "PATH", "Scripted Path Data"),
PathData("^", "PATH", "Scripted path data"),
EndScript("%", "END", "Script ends"),
Speech("#", "SPEAK", "A speech dialogue"),
Question("?", "ASK", "A question dialogue"),
Expand All @@ -27,12 +28,14 @@ public enum ScriptTag {
Condition("~", "CONDITION", "Conditions that are to be met to complete the script");

private final String symbol;
private final String fullSymbol;
private final String uppercaseSymbolName;
private final String lowercaseSymbolName;
private final String description;

private ScriptTag(String sym, String alternate, String description) {
private ScriptTags(String sym, String alternate, String description) {
this.symbol = sym;
this.fullSymbol = alternate;
this.uppercaseSymbolName = alternate.toUpperCase();
this.lowercaseSymbolName = alternate.toLowerCase();
this.description = description;
}

Expand All @@ -45,9 +48,11 @@ private ScriptTag(String sym, String alternate, String description) {
public boolean beginsAt(String line) {
if (line == null || line.isEmpty() || line.isBlank())
return false;
if (this.startsWithUpperCase(line))
if (this.startsWithUpperCase(line) || line.startsWith(this.symbol))
return true;
if (line.startsWith(this.symbol))
String upper = line.toUpperCase().trim();
String lower = line.toLowerCase().trim();
if (upper.startsWith(this.uppercaseSymbolName) || lower.startsWith(this.lowercaseSymbolName))
return true;
return line.regionMatches(true, 0, this.name(), 0, this.name().length());
}
Expand All @@ -70,11 +75,30 @@ public boolean startsWithUpperCase(String line) {
String[] tokens = line.toUpperCase().split(":=");
if (tokens.length > 0) {
String uppercase = tokens[0];
return (uppercase.trim().equals(this.fullSymbol));
return (uppercase.trim().equals(this.uppercaseSymbolName));
}
return false;
}

/**
* Removes the script tag or script symbol from the given line, and returns the result.
*
* @param line
* The line that contains the script tag or symbol.
* @return The resulting string value after the script tag or symbol has been removed.
*/
public String removeScriptTag(String line) {
if (line.startsWith(this.symbol))
return line.substring(this.symbol.length());
else if (line.toUpperCase().startsWith(this.uppercaseSymbolName) || line.toLowerCase().startsWith(this.lowercaseSymbolName)) {
// We ignore anything that comes before the script tag. We're not doing anything complicated here.
int endOfIndex = line.indexOf(this.uppercaseSymbolName) + this.uppercaseSymbolName.length();
return line.substring(endOfIndex).trim();
}
// Cannot remove any script tags or symbols.
return line;
}

public String getDescription() {
return this.description;
}
Expand All @@ -84,6 +108,10 @@ public String getPrettyDescription() {
}

public String getSymbolName() {
return this.fullSymbol;
return this.uppercaseSymbolName;
}

public String getLowercaseSymbolName() {
return this.lowercaseSymbolName;
}
}
Binary file modified common/src/main/resources/art/area/test/testArea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion common/src/main/resources/art/script/scripts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $0


/ Turn around after seeing things.
BeginScript 1
$1
@Avoiding_Event
#Something is not right around here.
#I should probably move away from this place.
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/resources/art/script/test.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
&eb7280781bb89cfb
$1
@Avoiding_Event
/ Turn around after seeing things.
#Something is not right around here.
#I should probably move away from this place.
^L2R0
%


Loading

0 comments on commit dd13e07

Please sign in to comment.