-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from tommai78101/feature/trigger-human-readable
Feature/trigger human readable
- Loading branch information
Showing
25 changed files
with
514 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
% | ||
|
||
|
Oops, something went wrong.