Implement Diode

Emits power only when receiving power. (Effectively, this delays power by one frame.)

Also I made it so circuit blocks clone properly
This commit is contained in:
Timothy Stiles 2021-02-14 19:54:53 +11:00
parent 931f3c19c7
commit 11747f0d6e
4 changed files with 25 additions and 3 deletions

View File

@ -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;
}

View File

@ -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' },

View File

@ -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 {

View File

@ -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