From 64f5d15a84c6bd47cf7d033448d003efb9450eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20C=C3=B3rvus?= Date: Mon, 16 Nov 2020 03:51:47 +0300 Subject: [PATCH] fixes & updates --- scripts/blocks/terminal.js | 58 +++++++++++++---------- sprites/blocks/terminal-display-icon.png | Bin 258 -> 220 bytes 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/scripts/blocks/terminal.js b/scripts/blocks/terminal.js index ea8fd38..0d39da1 100644 --- a/scripts/blocks/terminal.js +++ b/scripts/blocks/terminal.js @@ -13,85 +13,93 @@ const Terminal = extendContent(Block, "terminal", { const terminalBase = Core.atlas.find(this.name); const terminalDisplay = Core.atlas.find(this.name + "-display-icon"); return [terminalBase, terminalDisplay]; - }, + } }); Terminal.buildType = prov(() => { const TerminalBuild = extend(Building, { + // Initialization + created() { + this.setText(""); + this.setError(false); + + this.super$created(); + }, + // Draw block draw() { - Draw.rect(Terminal.region, tile.drawx(), tile.drawy()); - this.drawLayer(); + Draw.rect(Terminal.region, this.tile.drawx(), this.tile.drawy()); + this.drawDisplay(); }, - + // Draw block display - drawLayer() { - + drawDisplay() { + // If error draw red display instead blue Draw.color(this.getError() ? Color.valueOf("E55454") : Color.valueOf("88A4FF")); - - Draw.rect(Terminal.displayRegion, tile.drawx(), tile.drawy()); - + + Draw.rect(Terminal.displayRegion, this.tile.drawx(), this.tile.drawy()); + // Caret flash if (Mathf.sin(Time.time(), 10, 1) > 0) { - Draw.rect(Terminal.caretRegion, tile.drawx(), tile.drawy()); + Draw.rect(Terminal.caretRegion, this.tile.drawx(), this.tile.drawy()); } Draw.reset(); }, - + // Called when player clicks on block buildConfiguration(table) { - + // Add buttons table.button(Icon.pencil, () => { if (Vars.mobile) { - + // Mobile and desktop version have different dialogs const input = new Input.TextInput(); input.text = this.getText(); input.multiline = true; input.accepted = cons(text => this.setText(text)); - + Core.input.getTextInput(input); } else { // Create dialog const dialog = new BaseDialog(Core.bundle.get("block." + Terminal.name + ".terminal-caption")); dialog.setFillParent(false); - + // Add text area to dialog const textArea = new TextArea(this.getText()); dialog.cont.add(textArea).size(380, 160); - + // Add "ok" button to dialog dialog.buttons.button("@ok", run(() => { this.setText(textArea.getText()); dialog.hide(); })); - + // Show it dialog.show(); } this.deselect(); }).size(40); - + table.button(Icon.terminal, () => { try { - + // If there is no text in block return undefined - // In other case put output to entity._result + // In other case put output to this._result this.setResult(this.getText() ? eval.bind(Vars.mods.getScripts(), this.getText())() : undefined); - + // Log with [I] mark - Log.info("[#ffea4a]" + this.localizedName + ": [] " + this.getResult()); + Log.info("[#ffea4a]" + Terminal.localizedName + " [[" + this.tile.x + "," + this.tile.y + "]: [] " + this.getResult()); this.setError(false); - + } catch (err) { // If error appear print it instead crash the game - + // Log with [E] mark - Log.err("[#ff5a54]" + this.localizedName + ": []" + err); + Log.err("[#ff5a54]" + Terminal.localizedName + " [[" + this.tile.x + "," + this.tile.y + "]: []" + err); this.setError(true); } }).size(40); diff --git a/sprites/blocks/terminal-display-icon.png b/sprites/blocks/terminal-display-icon.png index 9ef6aa7ed3e940c487cad82b3c45ba9561904fb2..41bd59cbc7c3d4c8cb1cd39ef3a02836c3b2aaf5 100644 GIT binary patch delta 169 zcmV;a09OBk0^9+RBnkm@Qb$4nuFf3kks%v@zyJUazyWI3i3tDz0C7n~K~z{rWBmXB zKf^!*CMZ2%VAKJl4j6U7r~^hFK#~IvO#byBgrQuj0FoTwkjushqN(W!lB0myjvy-y zP}31ZD-pr~%;&I>pahWIBEn`ldQ_0&Fp@%mnm&ht(Kg|z14bP%>VQ!PjC2PuFaQ7) X3dk$X(`gA}00000NkvXXu0mjfb*@0w delta 209 zcmcb^*u*qJWul=({Xqr>zJrWACT727U|^6aag8Vm&QB{TPb^AhC`ioAE78kKEm1Jh zGte{p)02E3sHVZw#W5tp{pdMEE(S#&*1-4mZto`@O-h{D$t8X4k?G_|%UzFzO88=h z#(Td@Jp0FfZ0aj@gLffzjUQdyuL?`}$J8#!syVR3>2dzz+kD4-%s$92|IOtlj1~HC ZVYhQ;I_h4Nv>NCb22WQ%mvv4FO#sedNyPvF