diff --git a/js/defs.js b/js/defs.js index da7f095..1159af4 100644 --- a/js/defs.js +++ b/js/defs.js @@ -4,6 +4,7 @@ export const DIRECTIONS = { north: { movement: [0, -1], bit: 0x01, + index: 0, action: 'up', left: 'west', right: 'east', @@ -12,6 +13,7 @@ export const DIRECTIONS = { south: { movement: [0, 1], bit: 0x04, + index: 2, action: 'down', left: 'east', right: 'west', @@ -20,6 +22,7 @@ export const DIRECTIONS = { west: { movement: [-1, 0], bit: 0x08, + index: 3, action: 'left', left: 'south', right: 'north', @@ -28,6 +31,7 @@ export const DIRECTIONS = { east: { movement: [1, 0], bit: 0x02, + index: 1, action: 'right', left: 'north', right: 'south', diff --git a/js/format-c2g.js b/js/format-c2g.js index 6faf993..ef2ef36 100644 --- a/js/format-c2g.js +++ b/js/format-c2g.js @@ -462,7 +462,34 @@ const TILE_ENCODING = { } }, encode(tile) { - // FIXME implement + let direction_offset = DIRECTIONS[tile.direction].index; + if (tile.gate_type === 'not') { + return 0 + direction_offset; + } + else if (tile.gate_type === 'and') { + return 4 + direction_offset; + } + else if (tile.gate_type === 'or') { + return 8 + direction_offset; + } + else if (tile.gate_type === 'xor') { + return 12 + direction_offset; + } + else if (tile.gate_type === 'latch-cw') { + return 16 + direction_offset; + } + else if (tile.gate_type === 'nand') { + return 20 + direction_offset; + } + else if (tile.gate_type === 'counter') { + return 30 + tile.memory; + } + else if (tile.gate_type === 'latch-ccw') { + return 64 + direction_offset; + } + else { + return 0xff; + } }, }, }, @@ -612,8 +639,11 @@ const TILE_ENCODING = { tile.arrows = arrows; }, encode(tile) { - // TODO - return 0; + let bits = 0; + for (let direction of tile.arrows) { + bits |= DIRECTIONS[direction].bit; + } + return bits; }, }, ], diff --git a/js/main-editor.js b/js/main-editor.js index 6537805..91fda1f 100644 --- a/js/main-editor.js +++ b/js/main-editor.js @@ -1007,6 +1007,7 @@ const EDITOR_PALETTE = [{ // - wires, wire tunnels probably a dedicated tool, placing tunnels like a tile makes no sense // - canopy normal tile; layering problem // - thin walls special rotate logic, like force floors; layering problem + // - light switches // TODO should tiles that respond to wiring and/or gray buttons be highlighted, highlightable? }, { title: "Logic", @@ -1045,7 +1046,7 @@ const SPECIAL_PALETTE_ENTRIES = { 'logic_gate/nand': { name: 'logic_gate', direction: 'north', gate_type: 'nand' }, 'logic_gate/latch-cw': { name: 'logic_gate', direction: 'north', gate_type: 'latch-cw' }, 'logic_gate/latch-ccw': { name: 'logic_gate', direction: 'north', gate_type: 'latch-ccw' }, - 'logic_gate/counter': { name: 'logic_gate', direction: 'north', gate_type: 'counter' }, + 'logic_gate/counter': { name: 'logic_gate', direction: 'north', gate_type: 'counter', memory: 0 }, }; const _RAILROAD_ROTATED_LEFT = [3, 0, 1, 2, 5, 4]; const _RAILROAD_ROTATED_RIGHT = [1, 2, 3, 0, 5, 4];