use of pl.asie.charset.module.tablet.format.api.ICommand in project Charset by CharsetMC.
the class AbstractTypesetter method write.
@Override
public void write(String text) throws TruthError {
if (Strings.isNullOrEmpty(text))
return;
final Tokenizer tokenizer = new Tokenizer(text);
while (tokenizer.nextToken()) {
final String token = tokenizer.getToken();
if (token.isEmpty())
continue;
switch(tokenizer.getType()) {
default:
throw new TruthError("Unknown tokentype: " + tokenizer.getToken());
case WORD:
write(new WordText(token));
break;
case PARAMETER:
write(token);
break;
case COMMAND:
final String cmdName = token.toLowerCase(Locale.ROOT);
ICommand cmd = TabletAPI.INSTANCE.getCommand(cmdName);
if (cmd == null) {
throw new TruthError("Unknown command: " + cmdName);
}
runCommand(cmd, tokenizer);
break;
}
}
}
use of pl.asie.charset.module.tablet.format.api.ICommand in project Charset by CharsetMC.
the class CharsetTablet method onInit.
@Mod.EventHandler
public void onInit(FMLInitializationEvent event) {
ICommand spaceCommand = ((typesetter, tokenizer) -> typesetter.write(new WordText(" ")));
TabletAPI.INSTANCE.registerRouter(new RouterIndex());
TabletAPI.INSTANCE.registerRouter(new RouterSearch());
TabletAPI.INSTANCE.registerRouter(new RouterModDocumentation("charset", "Book - Charset"));
TabletAPI.INSTANCE.addBook("Book of Charset", "mod://charset/index");
if (Loader.isModLoaded("simplelogic")) {
TabletAPI.INSTANCE.registerRouter(new RouterModDocumentation("simplelogic", "Book - SimpleLogic"));
TabletAPI.INSTANCE.addBook("The Rules of SimpleLogic", "mod://simplelogic/index");
}
TabletAPI.INSTANCE.registerCommand("\\", spaceCommand);
TabletAPI.INSTANCE.registerCommand("\\ ", spaceCommand);
TabletAPI.INSTANCE.registerCommand("\\nl", ((typesetter, tokenizer) -> typesetter.write(new WordNewline(1))));
TabletAPI.INSTANCE.registerCommand("\\p", ((typesetter, tokenizer) -> typesetter.write(new WordNewline(2))));
TabletAPI.INSTANCE.registerCommand("\\\\", (((typesetter, tokenizer) -> typesetter.write(new WordText("\\")))));
TabletAPI.INSTANCE.registerCommand("\\-", (((typesetter, tokenizer) -> {
String padS = tokenizer.getOptionalParameter();
typesetter.write(new WordBullet(padS != null ? Integer.parseInt(padS) : 0));
})));
TabletAPI.INSTANCE.registerCommand("\\scale", ((typesetter, tokenizer) -> {
String scaleS = tokenizer.getParameter("\\scale scaling amount");
String content = tokenizer.getParameter("\\scale content");
typesetter.pushStyle(new StyleScale(Float.parseFloat(scaleS)));
typesetter.write(content);
typesetter.popStyle(1);
}));
TabletAPI.INSTANCE.registerCommand("\\local", ((typesetter, tokenizer) -> typesetter.write(new WordTextLocalized(tokenizer.getParameter("text")))));
TabletAPI.INSTANCE.registerCommand("\\title", ((typesetter, tokenizer) -> {
typesetter.pushStyle(StyleFormat.ITALIC, StyleFormat.UNDERLINE, new StyleScale(2.0f));
typesetter.write(tokenizer.getParameter("text"));
typesetter.popStyle(3);
}));
TabletAPI.INSTANCE.registerCommand("\\header", ((typesetter, tokenizer) -> {
typesetter.pushStyle(StyleFormat.BOLD, StyleFormat.UNDERLINE);
typesetter.write(tokenizer.getParameter("text"));
typesetter.popStyle(2);
}));
TabletAPI.INSTANCE.registerCommand("\\b", ((typesetter, tokenizer) -> {
typesetter.pushStyle(StyleFormat.BOLD);
typesetter.write(tokenizer.getParameter("text"));
typesetter.popStyle();
}));
TabletAPI.INSTANCE.registerCommand("\\i", ((typesetter, tokenizer) -> {
typesetter.pushStyle(StyleFormat.ITALIC);
typesetter.write(tokenizer.getParameter("text"));
typesetter.popStyle();
}));
TabletAPI.INSTANCE.registerCommand("\\u", ((typesetter, tokenizer) -> {
typesetter.pushStyle(StyleFormat.UNDERLINE);
typesetter.write(tokenizer.getParameter("text"));
typesetter.popStyle();
}));
TabletAPI.INSTANCE.registerCommand("\\del", ((typesetter, tokenizer) -> {
typesetter.pushStyle(StyleFormat.STRIKETHROUGH);
typesetter.write(tokenizer.getParameter("text"));
typesetter.popStyle();
}));
TabletAPI.INSTANCE.registerCommand("\\checkmods", new CommandCheckMods());
TabletAPI.INSTANCE.registerCommand("\\img", new CommandImg());
TabletAPI.INSTANCE.registerCommand("\\item", new CommandItem());
TabletAPI.INSTANCE.registerCommand("\\url", new CommandURL());
TabletAPI.INSTANCE.registerCommand("\\urlmissing", new CommandURLMissing());
for (TextPrinterFormat format : TextPrinterFormat.values()) {
TabletAPI.INSTANCE.registerPrinterStyle(format, StyleFormat.class, new StylePrinterTextFormat(format));
}
TabletAPI.INSTANCE.registerPrinterText(TextPrinterFormat.HTML, WordText.class, (c, w) -> ((WordText) w).getText());
}
Aggregations