Search in sources :

Example 11 with INodeDouble

use of buildcraft.lib.expression.api.IExpressionNode.INodeDouble in project BuildCraft by BuildCraft.

the class NodeConditionalDouble method inline.

@Override
public INodeDouble inline() {
    INodeBoolean c = condition.inline();
    INodeDouble t = ifTrue.inline();
    INodeDouble f = ifFalse.inline();
    if (c instanceof NodeConstantBoolean && t instanceof NodeConstantDouble && f instanceof NodeConstantDouble) {
        return new NodeConstantDouble(((NodeConstantBoolean) c).value ? ((NodeConstantDouble) t).value : ((NodeConstantDouble) f).value);
    } else if (c != condition || t != ifTrue || f != ifFalse) {
        return new NodeConditionalDouble(c, t, f);
    } else {
        return this;
    }
}
Also used : INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble) NodeConstantBoolean(buildcraft.lib.expression.node.value.NodeConstantBoolean) NodeConstantDouble(buildcraft.lib.expression.node.value.NodeConstantDouble)

Example 12 with INodeDouble

use of buildcraft.lib.expression.api.IExpressionNode.INodeDouble in project BuildCraft by BuildCraft.

the class ElementTypeSprite method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    inheritProperty(json, "source.pos[0]", "source.area[0]");
    inheritProperty(json, "source.pos[1]", "source.area[1]");
    inheritProperty(json, "source.size[0]", "source.area[2]");
    inheritProperty(json, "source.size[1]", "source.area[3]");
    inheritProperty(json, "area", "source.area");
    inheritProperty(json, "area[0]", "source.area[0]");
    inheritProperty(json, "area[1]", "source.area[1]");
    inheritProperty(json, "area[2]", "source.area[2]");
    inheritProperty(json, "area[3]", "source.area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    IGuiArea srcArea = resolveArea(json, "source.area", PositionAbsolute.ORIGIN, ctx);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
    // TODO: Allow the source sprite to be changing as well!
    SrcTexture tex = resolveTexture(info, json, "source");
    String origin = tex.origin;
    int texSize = tex.texSize;
    if (// 
    !json.properties.containsKey("source.area[2]") && // 
    !json.properties.containsKey("source.area[3]") && !json.properties.containsKey("source.area")) {
        srcArea = new GuiRectangle(texSize, texSize);
    }
    ISprite sprite = gui.properties.get(origin, ISprite.class);
    if (sprite == null) {
        ResourceLocation loc = SpriteUtil.transformLocation(new ResourceLocation(origin));
        sprite = new SpriteRaw(loc, 0, 0, 1, 1);
    }
    if (srcArea instanceof GuiRectangle) {
        double u = srcArea.getX();
        double v = srcArea.getY();
        double uSize = srcArea.getWidth();
        double vSize = srcArea.getHeight();
        sprite = GuiUtil.subRelative(sprite, u, v, uSize, vSize, texSize);
    } else {
        final IGuiArea a = srcArea;
        INodeDouble u = () -> a.getX() / texSize;
        INodeDouble v = () -> a.getY() / texSize;
        INodeDouble uSize = () -> a.getEndX() / texSize;
        INodeDouble vSize = () -> a.getEndY() / texSize;
        sprite = new SubSpriteChanging(sprite, u, v, uSize, vSize);
    }
    ISimpleDrawable icon = new GuiSpriteScaled(sprite, area.offsetToOrigin());
    GuiElementDrawable element = new GuiElementDrawable(gui, area, icon, foreground, visible);
    return element;
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ISprite(buildcraft.api.core.render.ISprite) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) SubSpriteChanging(buildcraft.lib.client.sprite.SubSpriteChanging) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble) ResourceLocation(net.minecraft.util.ResourceLocation) GuiSpriteScaled(buildcraft.lib.gui.GuiSpriteScaled) SpriteRaw(buildcraft.lib.client.sprite.SpriteRaw)

Aggregations

INodeDouble (buildcraft.lib.expression.api.IExpressionNode.INodeDouble)12 InvalidExpressionException (buildcraft.lib.expression.api.InvalidExpressionException)6 FunctionContext (buildcraft.lib.expression.FunctionContext)5 IExpressionNode (buildcraft.lib.expression.api.IExpressionNode)4 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)4 INodeLong (buildcraft.lib.expression.api.IExpressionNode.INodeLong)4 NodeStack (buildcraft.lib.expression.NodeStack)3 INodeObject (buildcraft.lib.expression.api.IExpressionNode.INodeObject)3 INodeFunc (buildcraft.lib.expression.api.INodeFunc)3 INodeStack (buildcraft.lib.expression.api.INodeStack)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 NodeConstantDouble (buildcraft.lib.expression.node.value.NodeConstantDouble)2 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)2 ISprite (buildcraft.api.core.render.ISprite)1 SpriteRaw (buildcraft.lib.client.sprite.SpriteRaw)1 SubSpriteChanging (buildcraft.lib.client.sprite.SubSpriteChanging)1 INodeFuncDouble (buildcraft.lib.expression.api.INodeFunc.INodeFuncDouble)1 INodeFuncLong (buildcraft.lib.expression.api.INodeFunc.INodeFuncLong)1 INodeFuncObject (buildcraft.lib.expression.api.INodeFunc.INodeFuncObject)1 IVariableNode (buildcraft.lib.expression.api.IVariableNode)1