use of buildcraft.lib.expression.FunctionContext in project BuildCraft by BuildCraft.
the class GuiGate method preLoad.
protected void preLoad(BuildCraftJsonGui json) {
GateLogic gate = container.gate;
TypedKeyMap<String, Object> properties = json.properties;
FunctionContext context = json.context;
properties.put("statement.container", gate);
context.putConstantBoolean("gate.two_columns", gate.isSplitInTwo());
context.putConstantLong("gate.slots", gate.variant.numSlots);
context.putConstantLong("gate.triggers.args", gate.variant.numTriggerArgs);
context.putConstantLong("gate.actions.args", gate.variant.numActionArgs);
context.put_b("gate.two_columns", () -> gate.isOn);
context.putConstant("gate.material", String.class, gate.variant.material.tag);
context.putConstant("gate.modifier", String.class, gate.variant.modifier.tag);
context.putConstant("gate.logic", String.class, gate.variant.logic.tag);
context.putConstant("gate.variant", String.class, gate.variant.getLocalizedName());
properties.put("gate.triggers.possible", container.possibleTriggersContext);
properties.put("gate.actions.possible", container.possibleActionsContext);
context.put_l_b("gate.is_connected", (i) -> {
if (i < 0 || i >= gate.connections.length) {
return false;
}
return gate.connections[(int) i];
}).setNeverInline();
context.put_l_b("gate.trigger.is_on", (i) -> {
if (i < 0 || i >= gate.triggerOn.length) {
return false;
}
return gate.triggerOn[(int) i];
}).setNeverInline();
context.put_l_b("gate.set.is_on", (i) -> {
if (i < 0 || i >= gate.triggerOn.length) {
return false;
}
return gate.actionOn[(int) i];
}).setNeverInline();
context.put_l_b("gate.action.is_on", (i) -> {
if (i < 0 || i >= gate.actionOn.length) {
return false;
}
return gate.actionOn[(int) i] && gate.statements[(int) i].action.get() != null;
}).setNeverInline();
for (int s = 0; s < gate.variant.numSlots; s++) {
final int i = s;
String tName = "gate.trigger/" + i;
String aName = "gate.action/" + i;
properties.put(tName, gate.statements[i].trigger);
properties.put(aName, gate.statements[i].action);
properties.put(tName, container.possibleTriggersContext);
properties.put(aName, container.possibleActionsContext);
}
for (int c = 0; c < gate.connections.length; c++) {
final int connection = c;
String name = "gate.connection/" + c;
properties.put(name, gate.connections[c]);
properties.put(name, IButtonBehaviour.TOGGLE);
properties.put(name, (IButtonClickEventListener) (b, k) -> {
container.setConnected(connection, b.isButtonActive());
});
}
}
use of buildcraft.lib.expression.FunctionContext in project BuildCraft by BuildCraft.
the class ElementTypeDrawnStack method deserialize0.
@Override
protected IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
Item item = JsonUtils.getItem(json.json, "id");
int meta = resolveEquationInt(json, "meta", ctx);
ItemStack stack = new ItemStack(item, 1, meta);
ISimpleDrawable icon = new GuiStack(stack);
IGuiArea area = IGuiArea.create(pos, 16, 16);
return new GuiElementDrawable(gui, area, icon, foreground, visible);
}
use of buildcraft.lib.expression.FunctionContext in project BuildCraft by BuildCraft.
the class ElementTypeLedger method deserialize0.
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
inheritProperty(json, "color", "colour");
String side = json.properties.get("side");
String title = json.properties.get("title");
int colour = resolveEquationInt(json, "colour", ctx);
boolean positive = "right".equalsIgnoreCase(side);
Ledger_Neptune ledger = new Ledger_Neptune(gui, colour, positive);
ledger.setTitle(title);
addChildren(gui, ledger.positionLedgerIconStart, info, json, "closed", ledger.getClosedElements()::add);
ledger.calculateMaxSize();
ResourceLocation def = gui.jsonGuiDefinition;
def = new ResourceLocation(def.getResourceDomain(), def.getResourcePath().replace(".json", ""));
ledger.setOpenProperty(GuiConfigManager.getOrAddBoolean(def, json.name + ".is_open", false));
return ledger;
}
use of buildcraft.lib.expression.FunctionContext 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;
}
use of buildcraft.lib.expression.FunctionContext in project BuildCraft by BuildCraft.
the class ElementTypeText method deserialize0.
// pos: the position of the text
// text: The text to be drawn. Will be localised first, and used as a fallback
// expression: A replacement for text -- uses an expression rather than as a literal.
// colour: Default colour to be drawn
// centered: If true then the text will be centered around pos
@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
FunctionContext ctx = createContext(json);
IGuiPosition pos = resolvePosition(json, "pos", parent, ctx);
INodeObject<String> text;
String prop;
if ((prop = json.properties.get("text")) != null) {
String localized = LocaleUtil.localize(prop);
text = new NodeConstantObject<>(String.class, localized);
} else if ((prop = json.properties.get("expression")) != null) {
try {
text = GenericExpressionCompiler.compileExpressionString(prop, ctx);
} catch (InvalidExpressionException e) {
throw new JsonSyntaxException("Invalid expression for '" + json.name + "'", e);
}
} else {
throw new JsonSyntaxException("Require either 'text' or 'expression'!");
}
int colour;
if (json.properties.containsKey("colour")) {
colour = resolveEquationInt(json, "colour", ctx);
} else {
colour = resolveEquationInt(json, "color", ctx);
}
GuiElementText element = new GuiElementText(gui, pos, text, colour);
element.setCentered("true".equals(json.properties.get("centered")));
element.setDropShadow("true".equals(json.properties.get("shadow")));
element.setForeground("true".equals(json.properties.get("foreground")));
return element;
}
Aggregations