From 11747f0d6ea9c39ab4a0b2c15bd1869f333d2bbc Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Sun, 14 Feb 2021 19:54:53 +1100 Subject: [PATCH] Implement Diode Emits power only when receiving power. (Effectively, this delays power by one frame.) Also I made it so circuit blocks clone properly --- js/format-c2g.js | 7 +++++-- js/main-editor.js | 6 ++++++ js/tileset.js | 8 +++++++- js/tiletypes.js | 7 +++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/js/format-c2g.js b/js/format-c2g.js index 5789189..e03d9a2 100644 --- a/js/format-c2g.js +++ b/js/format-c2g.js @@ -530,8 +530,8 @@ const TILE_ENCODING = { else { tile.direction = DIRECTION_ORDER[modifier & 0x03]; let type = modifier >> 2; - if (type < 6) { - tile.gate_type = ['not', 'and', 'or', 'xor', 'latch-cw', 'nand'][type]; + if (type < 7) { + tile.gate_type = ['not', 'and', 'or', 'xor', 'latch-cw', 'nand', 'diode'][type]; } else if (type === 16) { tile.gate_type = 'latch-ccw'; @@ -561,6 +561,9 @@ const TILE_ENCODING = { else if (tile.gate_type === 'nand') { return 20 + direction_offset; } + else if (tile.gate_type === 'diode') { + return 24 + direction_offset; + } else if (tile.gate_type === 'counter') { return 30 + tile.memory; } diff --git a/js/main-editor.js b/js/main-editor.js index 8a9bcc9..e527d58 100644 --- a/js/main-editor.js +++ b/js/main-editor.js @@ -1611,6 +1611,7 @@ const EDITOR_PALETTE = [{ 'score_5x', 'spikes', 'boulder', + 'logic_gate/diode', ], }]; @@ -2107,6 +2108,10 @@ const EDITOR_TILE_DESCRIPTIONS = { name: "NOT gate", desc: "Emits power only when not receiving power.", }, + 'logic_gate/diode': { + name: "Diode", + desc: "Emits power only when receiving power. (Effectively, this delays power by one frame.)", + }, 'logic_gate/and': { name: "AND gate", desc: "Emits power while both inputs are receiving power.", @@ -2252,6 +2257,7 @@ const SPECIAL_PALETTE_ENTRIES = { 'railroad/curve': { name: 'railroad', tracks: 1 << 0, track_switch: null, entered_direction: 'north' }, 'railroad/switch': { name: 'railroad', tracks: 0, track_switch: 0, entered_direction: 'north' }, 'logic_gate/not': { name: 'logic_gate', direction: 'north', gate_type: 'not' }, + 'logic_gate/diode': { name: 'logic_gate', direction: 'north', gate_type: 'diode' }, 'logic_gate/and': { name: 'logic_gate', direction: 'north', gate_type: 'and' }, 'logic_gate/or': { name: 'logic_gate', direction: 'north', gate_type: 'or' }, 'logic_gate/xor': { name: 'logic_gate', direction: 'north', gate_type: 'xor' }, diff --git a/js/tileset.js b/js/tileset.js index b5331ec..4ed4477 100644 --- a/js/tileset.js +++ b/js/tileset.js @@ -548,6 +548,12 @@ export const CC2_TILESET_LAYOUT = { south: [2, 25], west: [3, 25], }, + diode: { + north: [0, 41], + east: [1, 41], + south: [2, 41], + west: [3, 41], + }, and: { north: [4, 25], east: [5, 25], @@ -1507,7 +1513,7 @@ export class Tileset { if (tile && tile.cell) { // What goes on top varies a bit... let r = this.layout['#wire-width'] / 2; - if (tile.gate_type === 'not' || tile.gate_type === 'counter') { + if (tile.gate_type === 'not' || tile.gate_type === 'counter' || tile.gate_type === 'diode') { this._draw_fourway_tile_power(tile, 0x0f, packet); } else { diff --git a/js/tiletypes.js b/js/tiletypes.js index 8b3059f..d502451 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -2250,6 +2250,7 @@ const TILE_TYPES = { // gate_type: not, and, or, xor, nand, latch-cw, latch-ccw, counter, bogus _gate_types: { not: ['out0', null, 'in0', null], + diode: ['out0', null, 'in0', null], and: ['out0', 'in0', null, 'in1'], or: ['out0', 'in0', null, 'in1'], xor: ['out0', 'in0', null, 'in1'], @@ -2304,6 +2305,9 @@ const TILE_TYPES = { if (me.gate_type === 'not') { output0 = ! input0; } + else if (me.gate_type === 'diode') { + output0 = input0; + } else if (me.gate_type === 'and') { output0 = input0 && input1; } @@ -2409,6 +2413,9 @@ const TILE_TYPES = { is_block: true, can_reverse_on_railroad: true, movement_speed: 4, + on_clone(me, original) { + me.wire_directions = original.wire_directions; + } }, // Time alteration