Search in sources :

Example 1 with TruthError

use of pl.asie.charset.module.tablet.format.api.TruthError 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;
        }
    }
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) ICommand(pl.asie.charset.module.tablet.format.api.ICommand) WordText(pl.asie.charset.module.tablet.format.words.WordText)

Example 2 with TruthError

use of pl.asie.charset.module.tablet.format.api.TruthError in project Charset by CharsetMC.

the class CommandImg method call.

@Override
public void call(ITypesetter out, ITokenizer tokenizer) throws TruthError {
    String imgName = tokenizer.getParameter("domain:path/to/image.png");
    String scaleOrWidth = tokenizer.getOptionalParameter();
    String heightS = tokenizer.getOptionalParameter();
    ResourceLocation rl = new ResourceLocation(imgName);
    try {
        Minecraft mc = Minecraft.getMinecraft();
        IResource r = mc.getResourceManager().getResource(rl);
        if (r == null) {
            throw new TruthError("Not found: " + imgName);
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw new TruthError(e.getMessage());
    }
    WordImage img;
    if (heightS != null) {
        int width = Integer.parseInt(scaleOrWidth);
        int height = Integer.parseInt(heightS);
        img = new WordImage(rl, width, height);
    } else {
        img = new WordImage(rl);
        if (scaleOrWidth != null) {
            img.scale(Double.parseDouble(scaleOrWidth));
        }
    }
    if (out.hasFixedWidth()) {
        img.fitToPage(out.getWidth(), Integer.MAX_VALUE);
    }
    out.write(img);
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) ResourceLocation(net.minecraft.util.ResourceLocation) WordImage(pl.asie.charset.module.tablet.format.words.WordImage) Minecraft(net.minecraft.client.Minecraft) IResource(net.minecraft.client.resources.IResource)

Example 3 with TruthError

use of pl.asie.charset.module.tablet.format.api.TruthError in project Charset by CharsetMC.

the class CommandURL method call.

@Override
public void call(ITypesetter typesetter, ITokenizer tokenizer) throws TruthError {
    String uriLink = tokenizer.getParameter("\\url missing parameter: uriLink");
    String content = tokenizer.getParameter("\\url missing parameter: content");
    try {
        typesetter.write(new WordURL(content, new URI(uriLink)));
    } catch (Exception e) {
        e.printStackTrace();
        throw new TruthError(e.getMessage());
    }
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) WordURL(pl.asie.charset.module.tablet.format.words.WordURL) URI(java.net.URI)

Example 4 with TruthError

use of pl.asie.charset.module.tablet.format.api.TruthError in project Charset by CharsetMC.

the class CommandURLMissing method call.

@Override
public void call(ITypesetter typesetter, ITokenizer tokenizer) throws TruthError {
    String content = tokenizer.getParameter("\\urlmissing missing parameter: content");
    try {
        typesetter.pushStyle(new StyleColor(0xFFCC3333), StyleFormat.ITALIC, StyleFormat.UNDERLINE);
        typesetter.write(new WordText(content));
        typesetter.popStyle(3);
    } catch (Exception e) {
        e.printStackTrace();
        throw new TruthError(e.getMessage());
    }
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) StyleColor(pl.asie.charset.module.tablet.format.words.StyleColor) WordText(pl.asie.charset.module.tablet.format.words.WordText)

Aggregations

TruthError (pl.asie.charset.module.tablet.format.api.TruthError)4 WordText (pl.asie.charset.module.tablet.format.words.WordText)2 URI (java.net.URI)1 Minecraft (net.minecraft.client.Minecraft)1 IResource (net.minecraft.client.resources.IResource)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ICommand (pl.asie.charset.module.tablet.format.api.ICommand)1 StyleColor (pl.asie.charset.module.tablet.format.words.StyleColor)1 WordImage (pl.asie.charset.module.tablet.format.words.WordImage)1 WordURL (pl.asie.charset.module.tablet.format.words.WordURL)1