diff options
75 files changed, 228 insertions, 1140 deletions
@@ -1,4 +1,4 @@ -const Pico = require('./core/pico') +const Pico = require('./desktop/core/pico') const Terminal = require('./cli/terminal') const pico = new Pico(40, 20) diff --git a/core/lib.js b/desktop/core/lib.js index 485fd0f..485fd0f 100644 --- a/core/lib.js +++ b/desktop/core/lib.js diff --git a/core/lib/_base.js b/desktop/core/lib/_base.js index d60743d..d60743d 100644 --- a/core/lib/_base.js +++ b/desktop/core/lib/_base.js diff --git a/core/lib/_move.js b/desktop/core/lib/_move.js index 9219216..9219216 100644 --- a/core/lib/_move.js +++ b/desktop/core/lib/_move.js diff --git a/core/lib/_null.js b/desktop/core/lib/_null.js index d305a41..d305a41 100644 --- a/core/lib/_null.js +++ b/desktop/core/lib/_null.js diff --git a/core/lib/_port.js b/desktop/core/lib/_port.js index ac8a202..ac8a202 100644 --- a/core/lib/_port.js +++ b/desktop/core/lib/_port.js diff --git a/core/lib/_wiref.js b/desktop/core/lib/_wiref.js index 75c767d..75c767d 100644 --- a/core/lib/_wiref.js +++ b/desktop/core/lib/_wiref.js diff --git a/core/lib/_wireh.js b/desktop/core/lib/_wireh.js index ca77e65..ca77e65 100644 --- a/core/lib/_wireh.js +++ b/desktop/core/lib/_wireh.js diff --git a/core/lib/_wiren.js b/desktop/core/lib/_wiren.js index e54dc70..e54dc70 100644 --- a/core/lib/_wiren.js +++ b/desktop/core/lib/_wiren.js diff --git a/core/lib/_wirev.js b/desktop/core/lib/_wirev.js index a1e279a..a1e279a 100644 --- a/core/lib/_wirev.js +++ b/desktop/core/lib/_wirev.js diff --git a/core/lib/a.js b/desktop/core/lib/a.js index eabea47..eabea47 100644 --- a/core/lib/a.js +++ b/desktop/core/lib/a.js diff --git a/core/lib/b.js b/desktop/core/lib/b.js index 0102c0a..0102c0a 100644 --- a/core/lib/b.js +++ b/desktop/core/lib/b.js diff --git a/core/lib/c.js b/desktop/core/lib/c.js index 33a50f1..33a50f1 100644 --- a/core/lib/c.js +++ b/desktop/core/lib/c.js diff --git a/core/lib/d.js b/desktop/core/lib/d.js index 136fe27..136fe27 100644 --- a/core/lib/d.js +++ b/desktop/core/lib/d.js diff --git a/core/lib/e.js b/desktop/core/lib/e.js index 2c56984..2c56984 100644 --- a/core/lib/e.js +++ b/desktop/core/lib/e.js diff --git a/core/lib/f.js b/desktop/core/lib/f.js index e6c3db2..e6c3db2 100644 --- a/core/lib/f.js +++ b/desktop/core/lib/f.js diff --git a/core/lib/g.js b/desktop/core/lib/g.js index 0fafb32..66acdc9 100644 --- a/core/lib/g.js +++ b/desktop/core/lib/g.js @@ -7,7 +7,7 @@ function FnG (pico, x, y) { this.name = 'generator' this.glyph = 'g' - this.info = 'Generates a s on bang.' + this.info = 'Generates a direction fn from bang.' this.ports = [{ x: 0, y: 1, output: true }, { x: 0, y: 0, bang: true }] diff --git a/core/lib/h.js b/desktop/core/lib/h.js index 1bb39bf..1bb39bf 100644 --- a/core/lib/h.js +++ b/desktop/core/lib/h.js diff --git a/core/lib/i.js b/desktop/core/lib/i.js index 0c0df9e..0c0df9e 100644 --- a/core/lib/i.js +++ b/desktop/core/lib/i.js diff --git a/core/lib/j.js b/desktop/core/lib/j.js index fa5f09d..fa5f09d 100644 --- a/core/lib/j.js +++ b/desktop/core/lib/j.js diff --git a/core/lib/k.js b/desktop/core/lib/k.js index d18bc86..d18bc86 100644 --- a/core/lib/k.js +++ b/desktop/core/lib/k.js diff --git a/core/lib/l.js b/desktop/core/lib/l.js index 28dff23..28dff23 100644 --- a/core/lib/l.js +++ b/desktop/core/lib/l.js diff --git a/core/lib/m.js b/desktop/core/lib/m.js index a5b92f8..a5b92f8 100644 --- a/core/lib/m.js +++ b/desktop/core/lib/m.js diff --git a/core/lib/n.js b/desktop/core/lib/n.js index 78dfb1c..78dfb1c 100644 --- a/core/lib/n.js +++ b/desktop/core/lib/n.js diff --git a/core/lib/o.js b/desktop/core/lib/o.js index f6425cd..f6425cd 100644 --- a/core/lib/o.js +++ b/desktop/core/lib/o.js diff --git a/core/lib/p.js b/desktop/core/lib/p.js index 9ccd846..9ccd846 100644 --- a/core/lib/p.js +++ b/desktop/core/lib/p.js diff --git a/core/lib/q.js b/desktop/core/lib/q.js index e8eedeb..e8eedeb 100644 --- a/core/lib/q.js +++ b/desktop/core/lib/q.js diff --git a/core/lib/r.js b/desktop/core/lib/r.js index 891c8b9..891c8b9 100644 --- a/core/lib/r.js +++ b/desktop/core/lib/r.js diff --git a/core/lib/s.js b/desktop/core/lib/s.js index 32190d5..32190d5 100644 --- a/core/lib/s.js +++ b/desktop/core/lib/s.js diff --git a/core/lib/t.js b/desktop/core/lib/t.js index 2437c7c..2437c7c 100644 --- a/core/lib/t.js +++ b/desktop/core/lib/t.js diff --git a/core/lib/u.js b/desktop/core/lib/u.js index f5551b1..f5551b1 100644 --- a/core/lib/u.js +++ b/desktop/core/lib/u.js diff --git a/core/lib/v.js b/desktop/core/lib/v.js index 4ce9c74..4ce9c74 100644 --- a/core/lib/v.js +++ b/desktop/core/lib/v.js diff --git a/core/lib/w.js b/desktop/core/lib/w.js index 06df04e..06df04e 100644 --- a/core/lib/w.js +++ b/desktop/core/lib/w.js diff --git a/core/lib/x.js b/desktop/core/lib/x.js index e248fb5..e248fb5 100644 --- a/core/lib/x.js +++ b/desktop/core/lib/x.js diff --git a/core/lib/y.js b/desktop/core/lib/y.js index b55b2d8..b55b2d8 100644 --- a/core/lib/y.js +++ b/desktop/core/lib/y.js diff --git a/core/lib/z.js b/desktop/core/lib/z.js index 7b73068..7b73068 100644 --- a/core/lib/z.js +++ b/desktop/core/lib/z.js diff --git a/core/pico.js b/desktop/core/pico.js index 9e334f5..9e334f5 100644 --- a/core/pico.js +++ b/desktop/core/pico.js diff --git a/desktop/main.js b/desktop/main.js index 9a5fe42..c82d36b 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -22,7 +22,7 @@ app.on('ready', () => { }) app.win.loadURL(`file://${__dirname}/sources/index.html`) - // app.inspect() + app.inspect() app.win.on('closed', () => { win = null diff --git a/desktop/sources/index.html b/desktop/sources/index.html index 824c257..78d8e67 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -3,40 +3,9 @@ <script type="text/javascript" src="scripts/lib/controller.js"></script> <script type="text/javascript" src="scripts/lib/theme.js"></script> - <script type="text/javascript" src="scripts/pico.js"></script> - <script type="text/javascript" src="scripts/program.js"></script> - <script type="text/javascript" src="scripts/grid.js"></script> <script type="text/javascript" src="scripts/keyboard.js"></script> <script type="text/javascript" src="scripts/events.js"></script> - <script type="text/javascript" src="scripts/programs/default.js"></script> - <script type="text/javascript" src="scripts/programs/a.js"></script> - <script type="text/javascript" src="scripts/programs/b.js"></script> - <script type="text/javascript" src="scripts/programs/c.js"></script> - <script type="text/javascript" src="scripts/programs/d.js"></script> - <script type="text/javascript" src="scripts/programs/e.js"></script> - <script type="text/javascript" src="scripts/programs/f.js"></script> - <script type="text/javascript" src="scripts/programs/g.js"></script> - <script type="text/javascript" src="scripts/programs/h.js"></script> - <script type="text/javascript" src="scripts/programs/i.js"></script> - <script type="text/javascript" src="scripts/programs/j.js"></script> - <script type="text/javascript" src="scripts/programs/k.js"></script> - <script type="text/javascript" src="scripts/programs/l.js"></script> - <script type="text/javascript" src="scripts/programs/m.js"></script> - <script type="text/javascript" src="scripts/programs/n.js"></script> - <script type="text/javascript" src="scripts/programs/o.js"></script> - <script type="text/javascript" src="scripts/programs/p.js"></script> - <script type="text/javascript" src="scripts/programs/q.js"></script> - <script type="text/javascript" src="scripts/programs/r.js"></script> - <script type="text/javascript" src="scripts/programs/s.js"></script> - <script type="text/javascript" src="scripts/programs/t.js"></script> - <script type="text/javascript" src="scripts/programs/u.js"></script> - <script type="text/javascript" src="scripts/programs/w.js"></script> - <script type="text/javascript" src="scripts/programs/x.js"></script> - <script type="text/javascript" src="scripts/programs/v.js"></script> - <script type="text/javascript" src="scripts/programs/y.js"></script> - <script type="text/javascript" src="scripts/programs/z.js"></script> - <link rel="stylesheet" type="text/css" href="links/reset.css"/> <link rel="stylesheet" type="text/css" href="links/fonts.css"/> <link rel="stylesheet" type="text/css" href="links/main.css"/> @@ -50,31 +19,34 @@ const fs = require('fs') const app_path = app.getAppPath() - const pico = new Pico() - pico.controller = new Controller() - pico.install() - pico.start() - - pico.controller.add("default","*","About",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Donsol'); },"CmdOrCtrl+,") - pico.controller.add("default","*","Fullscreen",() => { app.toggle_fullscreen(); },"CmdOrCtrl+Enter") - pico.controller.add("default","*","Hide",() => { app.toggle_visible(); },"CmdOrCtrl+H") - pico.controller.add("default","*","Inspect",() => { app.inspect(); },"CmdOrCtrl+.") - pico.controller.add("default","*","Reset",() => { pico.reset(); },"CmdOrCtrl+Backspace") - pico.controller.add("default","*","Quit",() => { app.exit(); },"CmdOrCtrl+Q") - - pico.controller.add("default","File","New",() => { pico.new(); },"CmdOrCtrl+N") - pico.controller.add("default","File","Save",() => { pico.save(); },"CmdOrCtrl+S") - pico.controller.add("default","File","Open",() => { pico.open(); },"CmdOrCtrl+O") - - pico.controller.add("default","Program","Play/Pause",() => { pico.pause(); },"CmdOrCtrl+P") - pico.controller.add("default","Program","Run",() => { pico.run(true); },"Enter") - - pico.controller.add("default","Theme","Noir",() => { pico.theme.noir(); },"CmdOrCtrl+Shift+1") - pico.controller.add("default","Theme","Pale",() => { pico.theme.pale(); },"CmdOrCtrl+Shift+2") - pico.controller.add("default","Theme","Invert",() => { pico.theme.invert(); },"CmdOrCtrl+Shift+I") - pico.controller.add("default","Theme","Install",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes'); }) - - pico.controller.commit() + const Pico = require('../core/pico') + const Terminal = require('./scripts/terminal') + const pico = new Pico(10, 10) + const terminal = new Terminal(pico) + + terminal.install(document.body) + + terminal.controller.add("default","*","About",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Donsol'); },"CmdOrCtrl+,") + terminal.controller.add("default","*","Fullscreen",() => { app.toggle_fullscreen(); },"CmdOrCtrl+Enter") + terminal.controller.add("default","*","Hide",() => { app.toggle_visible(); },"CmdOrCtrl+H") + terminal.controller.add("default","*","Inspect",() => { app.inspect(); },"CmdOrCtrl+.") + terminal.controller.add("default","*","Reset",() => { pico.reset(); },"CmdOrCtrl+Backspace") + terminal.controller.add("default","*","Quit",() => { app.exit(); },"CmdOrCtrl+Q") + + terminal.controller.add("default","File","New",() => { pico.new(); },"CmdOrCtrl+N") + terminal.controller.add("default","File","Save",() => { pico.save(); },"CmdOrCtrl+S") + terminal.controller.add("default","File","Open",() => { pico.open(); },"CmdOrCtrl+O") + + terminal.controller.add("default","Program","Play/Pause",() => { pico.pause(); },"CmdOrCtrl+P") + terminal.controller.add("default","Program","Run",() => { pico.run(true); },"Enter") + + terminal.controller.add("default","Theme","Noir",() => { pico.theme.noir(); },"CmdOrCtrl+Shift+1") + terminal.controller.add("default","Theme","Pale",() => { pico.theme.pale(); },"CmdOrCtrl+Shift+2") + terminal.controller.add("default","Theme","Invert",() => { pico.theme.invert(); },"CmdOrCtrl+Shift+I") + terminal.controller.add("default","Theme","Install",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes'); }) + + terminal.controller.commit() + terminal.start() const keyboard = new Keyboard() document.onkeydown = function(event){ keyboard.listen_onkeydown(event); } diff --git a/desktop/sources/scripts/grid.js b/desktop/sources/scripts/grid.js deleted file mode 100644 index 30e028a..0000000 --- a/desktop/sources/scripts/grid.js +++ /dev/null @@ -1,135 +0,0 @@ -'use strict' - -function Grid () { - this.el = document.createElement('canvas') - - this.tile = { w: 15, h: 20 } - - this.cursor = { - x: 0, - y: 0, - move: function (x, y) { - this.x += x - this.y -= y - this.x = clamp(this.x, 0, pico.program.w - 1) - this.y = clamp(this.y, 0, pico.program.h - 1) - pico.grid.update() - }, - insert: function (k) { - const key = k.trim() == '' ? '.' : k.toLowerCase() - if (pico.program.glyphs.indexOf(key) < 0) { console.log(`Illegal rune:${key}`); return } - pico.program.add(this.x, this.y, key) - }, - inspect: function () { - return pico.program.glyph_at(this.x, this.y) - } - } - - this.install = function (host) { - this.size = { width: this.tile.w * pico.program.size.h, height: this.tile.h * pico.program.size.v, ratio: 0.75 } - this.el.width = this.size.width - this.el.height = this.size.height + this.tile.h - this.el.style.width = (this.size.width * this.size.ratio) + 'px' - this.el.style.height = (this.size.height * this.size.ratio) + 'px' - - host.appendChild(this.el) - } - - this.update = function () { - this.clear() - this.draw_program() - this.draw_output() - } - - this.draw_program = function () { - const ports = this.find_ports() - - let y = 0 - while (y < pico.program.h) { - let x = 0 - while (x < pico.program.w) { - const styles = { - is_cursor: pico.grid.is_cursor(x, y), - is_port: ports[`${x}:${y}`] - } - this.draw_sprite(x, y, pico.program.glyph_at(x, y), styles) - x += 1 - } - y += 1 - } - } - - this.draw_output = function () { - const s = pico.program.r.replace(/\./g, ' ').trim() - - let x = 0 - while (x < s.length) { - const c = s.substr(x, 1) - this.draw_sprite(x, pico.program.size.v - 1, c) - x += 1 - } - } - - this.is_cursor = function (x, y) { - return this.cursor.x == x && this.cursor.y == y - } - - this.find_ports = function () { - const h = {} - - for (const id in pico.program.progs) { - const g = pico.program.progs[id] - if (pico.program.is_locked(g.x, g.y)) { continue } - for (const id in g.ports) { - const port = g.ports[id] - h[`${g.x + port.x}:${g.y + port.y}`] = port.output ? 2 : port.bang ? 1 : 3 - } - } - - return h - } - - this.context = function () { - return this.el.getContext('2d') - } - - this.clear = function () { - const ctx = this.context() - - ctx.clearRect(0, 0, this.size.width, this.size.height) - } - - this.draw_sprite = function (x, y, g, styles = { is_cursor: false, is_port: false }) { - const ctx = this.context() - - ctx.textBaseline = 'bottom' - ctx.textAlign = 'center' - ctx.font = `${this.tile.h * 0.75}px input_mono_regular` - - if (styles.is_cursor) { - ctx.fillStyle = pico.theme.active.b_inv - ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) - ctx.fillStyle = pico.theme.active.f_inv - } else if (styles.is_port) { - if (styles.is_port == 2) { - ctx.fillStyle = pico.theme.active.b_high - ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) - ctx.fillStyle = pico.theme.active.f_low - } else if (styles.is_port == 1) { - ctx.fillStyle = pico.theme.active.b_med - ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) - ctx.fillStyle = pico.theme.active.f_low - } else if (styles.is_port == 3) { - ctx.fillStyle = pico.theme.active.b_low - ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) - ctx.fillStyle = pico.theme.active.f_high - } - } else { - ctx.fillStyle = 'white' - } - - ctx.fillText(styles.is_cursor && g == '.' ? (!pico.is_paused ? '@' : '~') : g.toUpperCase(), (x + 1) * this.tile.w, (y + 1) * this.tile.h) - } - - function clamp (v, min, max) { return v < min ? min : v > max ? max : v } -} diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js index 660bc24..61618d0 100644 --- a/desktop/sources/scripts/keyboard.js +++ b/desktop/sources/scripts/keyboard.js @@ -7,13 +7,13 @@ function Keyboard () { this.listen_onkeydown = function (event) { // Reset if ((event.metaKey || event.ctrlKey) && event.key == 'Backspace') { - pico.reset() + terminal.reset() event.preventDefault() return } // Pause if ((event.metaKey || event.ctrlKey) && event.key == 'p') { - pico.pause() + terminal.pause() event.preventDefault() return } @@ -26,32 +26,32 @@ function Keyboard () { if (event.keyCode == 37) { keyboard.key_arrow_left(); return } if (event.keyCode == 39) { keyboard.key_arrow_right(); return } - if (event.key == 'Backspace') { pico.grid.cursor.insert('.'); return } - if (event.key == 'Space') { pico.grid.cursor.insert('.'); event.preventDefault(); return } - if (event.key == 'Escape') { logo.remove(); pico.program.clear(); return } + if (event.key == 'Backspace') { terminal.cursor.insert('.'); return } + if (event.key == 'Space') { terminal.cursor.insert('.'); event.preventDefault(); return } + if (event.key == 'Escape') { logo.remove(); terminal.clear(); return } if (event.key.length == 1) { - pico.grid.cursor.insert(event.key) + terminal.cursor.insert(event.key) if (event.shiftKey) { - pico.grid.cursor.move(1, 0) + terminal.cursor.move(1, 0) } - pico.grid.update() + terminal.update() } } this.key_arrow_up = function () { - pico.grid.cursor.move(0, 1) + terminal.cursor.move(0, 1) } this.key_arrow_down = function () { - pico.grid.cursor.move(0, -1) + terminal.cursor.move(0, -1) } this.key_arrow_left = function () { - pico.grid.cursor.move(-1, 0) + terminal.cursor.move(-1, 0) } this.key_arrow_right = function () { - pico.grid.cursor.move(1, 0) + terminal.cursor.move(1, 0) } } diff --git a/desktop/sources/scripts/pico.js b/desktop/sources/scripts/pico.js deleted file mode 100644 index e835468..0000000 --- a/desktop/sources/scripts/pico.js +++ /dev/null @@ -1,82 +0,0 @@ -'use strict' - -function Pico () { - this.el = document.createElement('app') - - this.theme = new Theme({ - background: '#111111', - f_high: '#ffffff', - f_med: '#333333', - f_low: '#000000', - f_inv: '#000000', - b_high: '#ffb545', - b_med: '#72dec2', - b_low: '#444444', - b_inv: '#ffffff' - }) - - this.controller = null - this.program = new Program(39, 29) - this.grid = new Grid() - - this.f = 0 - this.is_paused = false - - this.install = function (host = document.body) { - this.theme.install(host) - this.grid.install(this.el) - host.appendChild(this.el) - this.program.reset() - } - - this.start = function () { - this.theme.start() - setInterval(() => { this.run() }, 200) - } - - this.new = function () { - this.program.reset() - this.grid.update() - } - - this.reset = function () { - this.theme.reset() - this.new() - } - - this.save = function () { - dialog.showSaveDialog({ title: 'Save to .pico', filters: [{ name: 'Pico Format', extensions: ['pico'] }] }, (fileName) => { - if (fileName === undefined) { return } - fileName = fileName.substr(-5, 5) != '.pico' ? fileName + '.pico' : fileName - fs.writeFileSync(fileName, pico.program.output()) - }) - } - - this.open = function () { - const filepath = dialog.showOpenDialog({ filters: [{ name: 'Pico Files', extensions: ['pico'] }], properties: ['openFile'] }) - if (!filepath) { console.log('Nothing to load'); return } - fs.readFile(filepath[0], 'utf-8', (err, data) => { - if (err) { alert('An error ocurred reading the file :' + err.message); return } - pico.load(data) - }) - } - - this.load = function (txt) { - pico.program.reset() - pico.program.s = txt.replace(/\n/g, '').replace(/[^0-9a-z]/gi, '.') - pico.grid.update() - } - - this.run = function (force = false) { - if (this.is_paused && !force) { return } - - this.program.run() - this.grid.update() - this.f += 1 - } - - this.pause = function () { - this.is_paused = !this.is_paused - this.grid.update() - } -} diff --git a/desktop/sources/scripts/program.js b/desktop/sources/scripts/program.js deleted file mode 100644 index 4951b74..0000000 --- a/desktop/sources/scripts/program.js +++ /dev/null @@ -1,125 +0,0 @@ -'use strict' - -function Program (w, h) { - this.size = { h: 40, v: 30 } - this.w = w - this.h = h - this.s = '' - this.r = '' // Record - - this.locks = [] - this.progs = [] - this.glyphs = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '.'] - - this.reset = function () { - this.r = '' - this.s = '' - let y = 0 - while (y < this.h) { - let x = 0 - while (x < this.w) { - this.s += '.' - x += 1 - } - y += 1 - } - } - - this.add = function (x, y, glyph) { - if (x < 0 || x > pico.program.w - 1 || y < 0 || y > pico.program.h - 1 || !glyph) { return } - - const index = this.index_at(x, y) - - this.s = this.s.substr(0, index) + glyph + this.s.substr(index + glyph.length) - } - - this.remove = function (x, y) { - this.add(x, y, '.') - } - - this.run = function () { - this.unlock() - this.progs = [] - - // Find Programs - let y = 0 - while (y < this.h) { - let x = 0 - while (x < this.w) { - const g = this.glyph_at(x, y) - if (this.is_prog(g)) { - this.progs.push(new window[`program_${g.toUpperCase()}`](x, y)) - } - x += 1 - } - y += 1 - } - - // Operate - for (const id in this.progs) { - const p = this.progs[id] - if (this.is_locked(p.x, p.y)) { continue } - p.run() - } - - this.record() - - this.s = this.s.substr(0, this.w * this.h) - } - - this.clear = function () { - this.r = '' - } - - this.is_prog = function (g) { - return this.glyphs.indexOf(g) >= 9 && this.glyphs.indexOf(g) <= 35 && window[`program_${g.toUpperCase()}`] - } - - this.glyph_at = function (x, y, req = null) { - return this.s.charAt(this.index_at(x, y)) - } - - this.glyph_like_at = function (x, y, target) { - return this.s.charAt(this.index_at(x, y)) == target ? true : null - } - - this.index_at = function (x, y) { - return x + (this.w * y) - } - - // Locks - - this.is_locked = function (x, y) { - return this.locks.indexOf(`${x}:${y}`) > -1 - } - - this.unlock = function () { - this.locks = [] - } - - this.lock = function (x, y) { - this.locks.push(`${x}:${y}`) - } - - // Tools - - this.output = function () { - const origin = this.s.replace(/[^0-9a-z]/gi, '.') - const lines = origin.match(/.{1,39}/g) - return lines.reduce((acc, val) => { - return `${acc}${val}\n` - }, '') - } - - this.record = function () { - const g = this.s.substr(-1, 1) - const last_g = this.r.substr(-1, 1) - if (g == '.' && last_g == '.') { return } - this.r += g - - // Trim - if (this.r.length >= pico.program.size.h) { - this.r = this.r.substr(-pico.program.size.h + 1, pico.program.size.h) - } - } -} diff --git a/desktop/sources/scripts/programs/a.js b/desktop/sources/scripts/programs/a.js deleted file mode 100644 index 74023d0..0000000 --- a/desktop/sources/scripts/programs/a.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -function program_A (x, y) { - Program_Default.call(this, x, y) - - this.name = 'add' - this.glyph = 'a' - this.ports = [{ x: -1, y: 0 }, { x: 1, y: 0 }, { x: 0, y: 1, output: true }] - - this.operation = function () { - if (!this.left() || !this.right()) { - pico.program.remove(this.x, this.y + 1) - return - } - - const left = !this.left() ? '0' : this.left().glyph - const right = !this.right() ? '0' : this.right().glyph - - const index = (this.convert(left) + this.convert(right)) % pico.program.glyphs.length - const output = pico.program.glyphs[index] - - pico.program.add(this.x, this.y + 1, output) - } - - this.convert = function (glyph) { - return pico.program.glyphs.indexOf(glyph) - } -} diff --git a/desktop/sources/scripts/programs/b.js b/desktop/sources/scripts/programs/b.js deleted file mode 100644 index fa3a26f..0000000 --- a/desktop/sources/scripts/programs/b.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -function program_B (x, y) { - Program_Default.call(this, x, y) - - this.name = 'bang' - this.glyph = 'b' - - this.operation = function () { - this.remove() - } -} diff --git a/desktop/sources/scripts/programs/c.js b/desktop/sources/scripts/programs/c.js deleted file mode 100644 index 94eb728..0000000 --- a/desktop/sources/scripts/programs/c.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict' - -function program_C (x, y) { - Program_Default.call(this, x, y) - - this.name = 'clone' - this.glyph = 'c' - this.ports = [{ x: 0, y: 0, bang: true }, { x: 1, y: 0, output: true }, { x: -1, y: 0 }] - - this.operation = function () { - if (this.bang() && this.left()) { - pico.program.add(this.x + 1, this.y, this.left().glyph) - } - } -} diff --git a/desktop/sources/scripts/programs/d.js b/desktop/sources/scripts/programs/d.js deleted file mode 100644 index f70d152..0000000 --- a/desktop/sources/scripts/programs/d.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -function program_D (x, y) { - Program_Default.call(this, x, y) - - this.name = 'down' - this.glyph = 'd' - - this.operation = function () { - if (this.is_free(0, 1) != true) { this.replace('b'); this.lock(); return } - this.move(0, 1) - } -} diff --git a/desktop/sources/scripts/programs/default.js b/desktop/sources/scripts/programs/default.js deleted file mode 100644 index ab0ec43..0000000 --- a/desktop/sources/scripts/programs/default.js +++ /dev/null @@ -1,103 +0,0 @@ -'use strict' - -function Program_Default (x, y) { - this.name = '<missing name>' - this.x = x - this.y = y - this.glyph = '.' - this.ports = [] - - this.id = function () { - return this.x + (this.y * pico.program.h) - } - - this.run = function () { - this.operation() - } - - this.operation = function () { - - } - - this.remove = function () { - this.replace('.') - } - - this.replace = function (g) { - this.lock() - pico.program.add(this.x, this.y, g) - } - - this.lock = function () { - pico.program.lock(this.x, this.y) - } - - this.move = function (x, y, g) { - pico.program.lock(this.x + x, this.y + y) - pico.program.remove(this.x, this.y) - pico.program.add((this.x + x) % pico.program.w, (this.y + y) % pico.program.h, this.glyph) - } - - this.is_free = function (x, y) { - if (this.x + x >= pico.program.w) { return false } - if (this.x + x <= -1) { return false } - if (this.y + y >= pico.program.h) { return false } - if (this.y + y <= -1) { return false } - - const target = pico.program.glyph_at(this.x + x, this.y + y) - return target == '.' || target == 'b' ? true : target - } - - this.neighbor_by = function (x, y) { - return pico.program.glyph_at(this.x + x, this.y + y) != '.' ? { x: this.x + x, y: this.y + y, glyph: pico.program.glyph_at(this.x + x, this.y + y) } : null - } - - this.neighbors = function (g) { - return [this.up(g), this.right(g), this.down(g), this.left(g)].filter(function (e) { return e }) - } - - this.free_neighbors = function () { - const a = [] - if (pico.program.glyph_at(this.x + 1, this.y) == '.') { a.push({ x: this.x + 1, y: this.y }) } - if (pico.program.glyph_at(this.x - 1, this.y) == '.') { a.push({ x: this.x - 1, y: this.y }) } - if (pico.program.glyph_at(this.x, this.y + 1) == '.') { a.push({ x: this.x, y: this.y + 1 }) } - if (pico.program.glyph_at(this.x, this.y - 1) == '.') { a.push({ x: this.x, y: this.y - 1 }) } - return a - } - - this.bang = function () { - const ns = this.neighbors('b') - for (const id in ns) { - const n = ns[id] - if (pico.program.glyph_at(n.x, n.y - 1) != 'h') { - return { x: n.x, y: n.y } - } - } - return false - } - - this.left = function (target = null) { - const g = pico.program.glyph_at(this.x - 1, this.y) - - return g != '.' && (g == target || !target) ? { x: this.x - 1, y: this.y, glyph: g } : null - } - - this.right = function (target) { - const g = pico.program.glyph_at(this.x + 1, this.y) - return g != '.' && (g == target || !target) ? { x: this.x + 1, y: this.y, glyph: g } : null - } - - this.up = function (target) { - const g = pico.program.glyph_at(this.x, this.y - 1) - return g != '.' && (g == target || !target) ? { x: this.x, y: this.y - 1, glyph: g } : null - } - - this.down = function (target) { - const g = pico.program.glyph_at(this.x, this.y + 1) - return g != '.' && (g == target || !target) ? { x: this.x, y: this.y + 1, glyph: g } : null - } - - this.docs = function () { - return `${this.name}` - } -} diff --git a/desktop/sources/scripts/programs/e.js b/desktop/sources/scripts/programs/e.js deleted file mode 100644 index 19e3c23..0000000 --- a/desktop/sources/scripts/programs/e.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict' - -function program_E (x, y) { - Program_Default.call(this, x, y) - - this.name = 'explode' - this.glyph = 'e' - - this.ports = [{ x: 0, y: 0, bang: true }] - - this.operation = function () { - const b = this.bang() - - if (!b) { return } - - this.remove() - pico.program.lock(b.x, b.y) - - const ns = this.free_neighbors() - for (const id in ns) { - const n = ns[id] - pico.program.add(n.x, n.y, 'b') - } - } -} diff --git a/desktop/sources/scripts/programs/f.js b/desktop/sources/scripts/programs/f.js deleted file mode 100644 index f50eb0f..0000000 --- a/desktop/sources/scripts/programs/f.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict' - -function program_F (x, y) { - Program_Default.call(this, x, y) - - this.name = 'if' - this.glyph = 'f' - this.ports = [{ x: -1, y: 0 }, { x: 1, y: 0 }, { x: 0, y: 1, output: true }] - - this.operation = function () { - if (!this.left() || !this.right()) { return } - - if (this.left(this.right().glyph)) { - pico.program.add(this.x, this.y + 1, '1') - } else { - pico.program.add(this.x, this.y + 1, '0') - } - } -} diff --git a/desktop/sources/scripts/programs/g.js b/desktop/sources/scripts/programs/g.js deleted file mode 100644 index 2358537..0000000 --- a/desktop/sources/scripts/programs/g.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -function program_G (x, y) { - Program_Default.call(this, x, y) - - this.name = 'generator' - this.glyph = 'g' - - this.ports = [{ x: 0, y: 1, output: true }, { x: 0, y: 0, bang: true }] - - this.operation = function () { - if (!this.bang()) { return } - - pico.program.add(this.x, this.y + 1, 'd') - } -} diff --git a/desktop/sources/scripts/programs/h.js b/desktop/sources/scripts/programs/h.js deleted file mode 100644 index f1b3db8..0000000 --- a/desktop/sources/scripts/programs/h.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict' - -function program_H (x, y) { - Program_Default.call(this, x, y) - - this.name = 'halt' - this.glyph = 'h' - - this.ports = [{ x: 0, y: 1, output: true }] - - this.operation = function () { - pico.program.lock(this.x, this.y + 1) - } -} diff --git a/desktop/sources/scripts/programs/i.js b/desktop/sources/scripts/programs/i.js deleted file mode 100644 index 1890f2b..0000000 --- a/desktop/sources/scripts/programs/i.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict' - -function program_I (x, y) { - Program_Default.call(this, x, y) - - this.name = 'increment' - this.glyph = 'i' - this.ports = [{ x: 0, y: 0, bang: true }, { x: 0, y: 1, output: true }] - - this.operation = function () { - if (!this.bang()) { return } - if (!this.down()) { return } - - const n = this.down() - pico.program.add(this.x, this.y + 1, this.inc(n.glyph)) - } - - this.inc = function (letter) { - if (parseInt(letter) == 9) { return '0' } - if (parseInt(letter) == 0) { return '1' } - if (parseInt(letter) > 0) { return parseInt(letter) + 1 + '' } - - const index = pico.program.glyphs.indexOf(letter) - - if (index < 0) { return } - - return pico.program.glyphs[(index + 1) % pico.program.glyphs.length] - } -} diff --git a/desktop/sources/scripts/programs/j.js b/desktop/sources/scripts/programs/j.js deleted file mode 100644 index dcbe79d..0000000 --- a/desktop/sources/scripts/programs/j.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict' - -function program_J (x, y) { - Program_Default.call(this, x, y) - - this.name = 'jump' - this.glyph = 'j' - - this.ports = [{ x: -1, y: 0 }, { x: 1, y: 0, output: true }, { x: 0, y: 0, bang: true }] - - this.operation = function () { - if (!this.bang()) { return } - - if (this.left()) { - pico.program.add(this.x + 1, this.y, this.left().glyph) - pico.program.remove(this.x - 1, this.y) - pico.program.lock(this.x - 1, this.y) - pico.program.lock(this.x + 1, this.y) - } else if (this.right()) { - pico.program.add(this.x - 1, this.y, this.right().glyph) - pico.program.remove(this.x + 1, this.y) - pico.program.lock(this.x - 1, this.y) - pico.program.lock(this.x + 1, this.y) - } - } -} diff --git a/desktop/sources/scripts/programs/k.js b/desktop/sources/scripts/programs/k.js deleted file mode 100644 index 914f974..0000000 --- a/desktop/sources/scripts/programs/k.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict' - -function program_K (x, y) { - Program_Default.call(this, x, y) - - this.name = 'kill' - this.glyph = 'k' - this.ports = [{ x: 0, y: 0, bang: true }, { x: 0, y: 1 }, { x: 0, y: -1 }, { x: 1, y: 0 }, { x: -1, y: 0 }] - - this.operation = function () { - if (this.bang()) { - pico.program.remove(this.x - 1, this.y) - pico.program.remove(this.x + 1, this.y) - pico.program.remove(this.x, this.y + 1) - pico.program.remove(this.x, this.y - 1) - - pico.program.lock(this.x, this.y + 1) - pico.program.lock(this.x, this.y - 1) - pico.program.lock(this.x + 1, this.y) - pico.program.lock(this.x - 1, this.y) - } - } -} diff --git a/desktop/sources/scripts/programs/l.js b/desktop/sources/scripts/programs/l.js deleted file mode 100644 index 16c4dc6..0000000 --- a/desktop/sources/scripts/programs/l.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -function program_L (x, y) { - Program_Default.call(this, x, y) - - this.name = 'left' - this.glyph = 'l' - - this.operation = function () { - if (this.is_free(-1, 0) != true) { this.replace('b'); this.lock(); return } - this.move(-1, 0) - } -} diff --git a/desktop/sources/scripts/programs/m.js b/desktop/sources/scripts/programs/m.js deleted file mode 100644 index c1a2ce4..0000000 --- a/desktop/sources/scripts/programs/m.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict' - -function program_M (x, y) { - Program_Default.call(this, x, y) - - this.name = 'modulo' - this.glyph = 'm' - this.ports = [{ x: -1, y: 0 }, { x: 1, y: 0 }, { x: 0, y: 1, output: true }] - - this.operation = function () { - if (!this.left() || !this.right()) { return } - - const val = pico.program.glyphs.indexOf(this.left().glyph) - const mod = pico.program.glyphs.indexOf(this.right().glyph) - - if (mod == 0) { return } - - pico.program.add(this.x, this.y + 1, `${parseInt(val) % parseInt(mod)}`) - } -} diff --git a/desktop/sources/scripts/programs/n.js b/desktop/sources/scripts/programs/n.js deleted file mode 100644 index 17ab15a..0000000 --- a/desktop/sources/scripts/programs/n.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -function program_N (x, y) { - Program_Default.call(this, x, y) - - this.name = 'turn' - this.glyph = 'n' - this.ports = [{ x: 0, y: 1, output: true }] - - this.operation = function () { - pico.program.add(this.x, this.y + 1, (pico.f % 10) + '') - } -} diff --git a/desktop/sources/scripts/programs/o.js b/desktop/sources/scripts/programs/o.js deleted file mode 100644 index f723693..0000000 --- a/desktop/sources/scripts/programs/o.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -function program_O (x, y) { - Program_Default.call(this, x, y) - - this.name = 'odd' - this.glyph = 'o' - this.ports = [{ x: 0, y: 0, bang: true }, { x: 0, y: -1 }] - - this.operation = function () { - if (!this.bang()) { return } - - this.replace('q') - this.lock() - } -} diff --git a/desktop/sources/scripts/programs/p.js b/desktop/sources/scripts/programs/p.js deleted file mode 100644 index fa4d8df..0000000 --- a/desktop/sources/scripts/programs/p.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -function program_P (x, y) { - Program_Default.call(this, x, y) - - this.name = 'push' - this.glyph = 'p' - this.ports = [{ x: 0, y: 0, bang: true }] - - this.operation = function () { - const origin = this.bang() - - if (!origin) { return } - - const direction = { x: this.x - origin.x, y: this.y - origin.y } - const pushed = this.neighbor_by(direction.x, direction.y) - - this.move(direction.x, direction.y) - - if (pushed) { - pico.program.add(this.x + (direction.x * 2), this.y + (direction.y * 2), pushed.glyph) - } - } - - this.n_offset = function (pos) { - return { x: this.x - pos.x, y: this.y - pos.y } - } -} diff --git a/desktop/sources/scripts/programs/q.js b/desktop/sources/scripts/programs/q.js deleted file mode 100644 index 5863fde..0000000 --- a/desktop/sources/scripts/programs/q.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict' - -function program_Q (x, y) { - Program_Default.call(this, x, y) - - this.name = 'even' - this.glyph = 'q' - this.ports = [{ x: 0, y: 0, bang: true }, { x: 0, y: 1, output: true }] - - this.operation = function () { - if (!this.bang()) { return } - - this.replace('o') - this.lock() - pico.program.add(this.x, this.y + 1, 'b') - pico.program.lock(this.x, this.y + 1) - } -} diff --git a/desktop/sources/scripts/programs/r.js b/desktop/sources/scripts/programs/r.js deleted file mode 100644 index a732552..0000000 --- a/desktop/sources/scripts/programs/r.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -function program_R (x, y) { - Program_Default.call(this, x, y) - - this.name = 'right' - this.glyph = 'r' - - this.operation = function () { - if (this.is_free(1, 0) != true) { this.replace('b'); this.lock(); return } - this.move(1, 0) - } -} diff --git a/desktop/sources/scripts/programs/s.js b/desktop/sources/scripts/programs/s.js deleted file mode 100644 index e77511b..0000000 --- a/desktop/sources/scripts/programs/s.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' - -function program_S (x, y) { - Program_Default.call(this, x, y) - - this.name = 'shift' - this.glyph = 's' - this.ports = [{ x: 0, y: 1 }, { x: 0, y: -1 }, { x: 1, y: 0 }, { x: -1, y: 0 }] - - this.operation = function () { - if (this.up() && this.up().glyph != 'u') { - pico.program.add(this.x, this.y - 1, 'u') - pico.program.lock(this.x, this.y - 1) - } - if (this.down() && this.down().glyph != 'd') { - pico.program.add(this.x, this.y + 1, 'd') - pico.program.lock(this.x, this.y + 1) - } - if (this.left() && this.left().glyph != 'l') { - pico.program.add(this.x - 1, this.y, 'l') - pico.program.lock(this.x - 1, this.y) - } - if (this.right() && this.right().glyph != 'r') { - pico.program.add(this.x + 1, this.y, 'r') - pico.program.lock(this.x + 1, this.y) - } - } -} diff --git a/desktop/sources/scripts/programs/t.js b/desktop/sources/scripts/programs/t.js deleted file mode 100644 index d2c4bd2..0000000 --- a/desktop/sources/scripts/programs/t.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict' - -function program_T (x, y) { - Program_Default.call(this, x, y) - - this.name = 'trigger' - this.glyph = 't' - this.ports = [{ x: -1, y: 0 }, { x: 0, y: 1, output: true }] - - this.operation = function () { - if (this.left('1') || this.left('r') || this.left('l') || this.left('u') || this.left('d') || this.left('b') || this.left('z')) { - this.fire() - } - } - - this.fire = function () { - pico.program.add(this.x, this.y + 1, 'b') - pico.program.lock(this.x, this.y + 1) - } -} diff --git a/desktop/sources/scripts/programs/u.js b/desktop/sources/scripts/programs/u.js deleted file mode 100644 index 26f1158..0000000 --- a/desktop/sources/scripts/programs/u.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -function program_U (x, y) { - Program_Default.call(this, x, y) - - this.name = 'up' - this.glyph = 'u' - - this.operation = function () { - if (this.is_free(0, -1) != true) { this.replace('b'); this.lock(); return } - this.move(0, -1) - } -} diff --git a/desktop/sources/scripts/programs/v.js b/desktop/sources/scripts/programs/v.js deleted file mode 100644 index 35b9d71..0000000 --- a/desktop/sources/scripts/programs/v.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -function program_V (x, y) { - Program_Default.call(this, x, y) - - this.name = 'value' - this.glyph = 'v' - this.ports = [{ x: -1, y: 0 }, { x: -2, y: 0 }, { x: -3, y: 0 }, { x: -4, y: 0 }, { x: -5, y: 0 }] - - this.operation = function () { - const val = (pico.program.glyph_at(this.x - 1, this.y) != '.' ? 1 : 0) + (pico.program.glyph_at(this.x - 2, this.y) != '.' ? 1 : 0) + (pico.program.glyph_at(this.x - 3, this.y) != '.' ? 1 : 0) + (pico.program.glyph_at(this.x - 4, this.y) != '.' ? 1 : 0) + (pico.program.glyph_at(this.x - 5, this.y) != '.' ? 1 : 0) - - pico.program.add(this.x + 1, this.y, val + '') - pico.program.lock(this.x + 1, this.y) - } -} diff --git a/desktop/sources/scripts/programs/w.js b/desktop/sources/scripts/programs/w.js deleted file mode 100644 index 767a3c0..0000000 --- a/desktop/sources/scripts/programs/w.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict' - -function program_W (x, y) { - Program_Default.call(this, x, y) - - this.name = 'warp' - this.glyph = 'w' - this.ports = [{ x: 0, y: -1 }, { x: 0, y: 1, output: true }, { x: 0, y: 0, bang: true }] - - this.operation = function () { - const input = this.up() - const active = this.bang() || this.neighbors('1').length > 0 - - if (input && active) { - const warp = this.find_warp(this) - if (!warp) { return } - pico.program.add(warp.x, warp.y + 1, input.glyph) - pico.program.remove(this.x, this.y - 1) - pico.program.lock(warp.x, warp.y + 1) - } - } - - this.find_warps = function (origin) { - const a = [] - let y = 0 - while (y < pico.program.h) { - let x = 0 - while (x < pico.program.w) { - if (pico.program.glyph_at(x, y) == 'w') { - a.push({ x: x, y: y }) - } - x += 1 - } - y += 1 - } - return a - } - - this.find_warp = function (origin) { - const warps = this.find_warps(origin) - - if (warps.length < 2) { return } - - let warp_id = -1 - for (const id in warps) { - const warp = warps[id] - if (warp.x == this.x && warp.y == this.y) { - warp_id = id - } - } - return warps[(warp_id + 1) % warps.length] - } -} diff --git a/desktop/sources/scripts/programs/x.js b/desktop/sources/scripts/programs/x.js deleted file mode 100644 index f084ef5..0000000 --- a/desktop/sources/scripts/programs/x.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict' - -function program_X (x, y) { - Program_Default.call(this, x, y) - - this.name = 'split' - this.glyph = 'x' - this.ports = [{ x: -1, y: 0 }, { x: 0, y: 1, output: true }, { x: 1, y: 0, output: true }] - - this.operation = function () { - if (this.left('0')) { - this.fire(1, 0) - } - if (this.left('1')) { - this.fire(0, 1) - } - } - - this.fire = function (x, y) { - pico.program.add(this.x + x, this.y + y, 'b') - pico.program.lock(this.x + x, this.y + y) - } -} diff --git a/desktop/sources/scripts/programs/y.js b/desktop/sources/scripts/programs/y.js deleted file mode 100644 index 7ede47d..0000000 --- a/desktop/sources/scripts/programs/y.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict' - -function program_Y (x, y) { - Program_Default.call(this, x, y) - - this.name = 'automata' - this.glyph = 'y' - this.ports = [{ x: -1, y: 0, input: true }, { x: 1, y: 0, input: true }, { x: 0, y: 1, output: true }] - - this.operation = function () { - if (!this.left() && !this.right()) { - pico.program.add(this.x, this.y + 1, '1') - } else if ((this.left() && !this.right()) || (this.right() && !this.left())) { - pico.program.add(this.x, this.y + 1, '0') - } else if ((this.left() && !this.right()) || (this.right() && !this.left())) { - pico.program.add(this.x, this.y + 1, '0') - } else if (is_num(this.left().glyph) == is_num(this.right().glyph)) { - pico.program.add(this.x, this.y + 1, '1') - } else { - pico.program.add(this.x, this.y + 1, '0') - } - } - - function is_num (c) { - return pico.program.glyphs.indexOf(c) < 10 - } -} diff --git a/desktop/sources/scripts/programs/z.js b/desktop/sources/scripts/programs/z.js deleted file mode 100644 index 230e973..0000000 --- a/desktop/sources/scripts/programs/z.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict' - -function program_Z (x, y) { - Program_Default.call(this, x, y) - - this.name = 'creep' - this.glyph = 'z' - - this.operation = function () { - const positions = [{ x: 1, y: 0 }, { x: 0, y: 1 }, { x: -1, y: 0 }, { x: 0, y: -1 }] - const position = positions[pico.f % 4] - - if (this.is_free(position.x, position.y) == true) { - this.move(position.x, position.y) - } - } -} diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js new file mode 100644 index 0000000..cd8f981 --- /dev/null +++ b/desktop/sources/scripts/terminal.js @@ -0,0 +1,180 @@ +'use strict' + +function Terminal (pico) { + this.pico = pico + this.el = document.createElement('canvas') + this.controller = new Controller(); + this.theme = new Theme(this.theme = new Theme({ background: '#111111', f_high: '#ffffff', f_med: '#333333', f_low: '#000000', f_inv: '#000000', b_high: '#ffb545', b_med: '#72dec2', b_low: '#444444', b_inv: '#ffffff'})); + this.is_paused = false + this.tile = { w: 15, h: 20 } + + this.cursor = { + x: 0, + y: 0, + move: function (x, y) { + this.x = clamp(this.x + x, 0, pico.w - 1) + this.y = clamp(this.y - y, 0, pico.h - 1) + terminal.update() + }, + insert: function (g) { + pico.add(this.x, this.y, g) + }, + erase: function (g) { + pico.remove(this.x, this.y) + }, + inspect: function () { + const g = pico.glyphAt(this.x, this.y) + return pico.docs[g] ? pico.docs[g] : '>' + } + } + + this.install = function (host) { + this.size = { width: this.tile.w * pico.w, height: this.tile.h * pico.h, ratio: 0.75 } + this.el.width = this.size.width + this.el.height = this.size.height + this.tile.h + this.el.style.width = (this.size.width * this.size.ratio) + 'px' + this.el.style.height = (this.size.height * this.size.ratio) + 'px' + + host.appendChild(this.el) + } + + this.start = function() + { + this.pico.terminal = this + this.pico.start() + + this.update() + setInterval(() => { this.run() }, 200) + } + + this.run = function () { + if (this.is_paused) { return } + + this.pico.run() + this.update() + } + + this.pause = function () { + this.is_paused = !this.is_paused + this.log(this.is_paused ? "Paused" : "Unpaused") + } + + this.load = function (path) { + const terminal = this + var fs = require('fs') + fs.readFile(path, 'utf8', function (err, data) { + if (err) throw err + const w = data.split('\n')[0].length + const h = data.split('\n').length + terminal.log(`Loaded: ${path} ${w}x${h}`) + pico.load(w, h, data) + terminal._grid.width = w + terminal.update() + }) + } + + this.log = function (msg) { + console.log(msg) + this.update() + } + + this.update = function () { + this.clear() + this.draw_program() + this.draw_output() + } + + this.draw_program = function () { + const ports = this.find_ports() + const terminal = this + + let y = 0 + while (y < pico.h) { + let x = 0 + while (x < pico.w) { + const styles = { + is_cursor: terminal.is_cursor(x, y), + is_port: ports[`${x}:${y}`] + } + this.draw_sprite(x, y, pico.glyphAt(x, y), styles) + x += 1 + } + y += 1 + } + } + + this.draw_output = function () { + const s = pico.r.replace(/\./g, ' ').trim() + + let x = 0 + while (x < s.length) { + const c = s.substr(x, 1) + this.draw_sprite(x, pico.size.v - 1, c) + x += 1 + } + } + + this.is_cursor = function (x, y) { + return this.cursor.x == x && this.cursor.y == y + } + + this.find_ports = function () { + const h = {} + + // for (const id in pico.program.progs) { + // const g = pico.program.progs[id] + // if (pico.program.is_locked(g.x, g.y)) { continue } + // for (const id in g.ports) { + // const port = g.ports[id] + // h[`${g.x + port.x}:${g.y + port.y}`] = port.output ? 2 : port.bang ? 1 : 3 + // } + // } + + return h + } + + this.context = function () { + return this.el.getContext('2d') + } + + this.clear = function () { + const ctx = this.context() + + ctx.clearRect(0, 0, this.size.width, this.size.height) + } + + this.draw_sprite = function (x, y, g, styles = { is_cursor: false, is_port: false }) { + const ctx = this.context() + + ctx.textBaseline = 'bottom' + ctx.textAlign = 'center' + ctx.font = `${this.tile.h * 0.75}px input_mono_regular` + + if (styles.is_cursor) { + ctx.fillStyle = "#f00" + ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) + ctx.fillStyle = "#fff" + } else if (styles.is_port) { + if (styles.is_port == 2) { + ctx.fillStyle = "#0ff" + ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) + ctx.fillStyle = "#0ff" + } else if (styles.is_port == 1) { + ctx.fillStyle = "#0ff" + ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) + ctx.fillStyle = "#0ff" + } else if (styles.is_port == 3) { + ctx.fillStyle = "#0ff" + ctx.fillRect((x + 0.5) * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h) + ctx.fillStyle = "#0ff" + } + } else { + ctx.fillStyle = 'white' + } + ctx.fillText(styles.is_cursor && g == '.' ? (!pico.is_paused ? '@' : '~') : g.toUpperCase(), (x + 1) * this.tile.w, (y + 1) * this.tile.h) + } + + function clamp (v, min, max) { return v < min ? min : v > max ? max : v } +} + +module.exports = Terminal diff --git a/examples/raygun.pico b/examples/raygun.pico index 6f61fd0..71e2fac 100644 --- a/examples/raygun.pico +++ b/examples/raygun.pico @@ -1,14 +1,14 @@ ............................................................. ............................................................. +............................1................................ ............................................................. ............................................................. -..........|.|.|.|.|.|.|.|.|.|.|.|.|.|.|...................... -............................................................. -...............r......................t...................... -............................................................. -............................................................. +............................r................................ +...............r.............1............................... +............................r................................ ............................................................. ............................................................. +............................1................................ ............................................................. ............................................................. ............................................................. diff --git a/examples/issue1.pico b/examples/test_wires.pico index 12cc4f4..12cc4f4 100644 --- a/examples/issue1.pico +++ b/examples/test_wires.pico diff --git a/index.html b/index.html deleted file mode 100644 index 614f799..0000000 --- a/index.html +++ /dev/null @@ -1,57 +0,0 @@ -<html> - <head> - <script type="text/javascript" src="desktop/sources/scripts/lib/theme.js"></script> - - <script type="text/javascript" src="desktop/sources/scripts/pico.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/program.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/grid.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/keyboard.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/events.js"></script> - - <script type="text/javascript" src="desktop/sources/scripts/programs/default.js"></script> - - <script type="text/javascript" src="desktop/sources/scripts/programs/a.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/b.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/c.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/d.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/e.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/f.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/g.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/h.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/i.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/j.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/k.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/l.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/m.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/n.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/o.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/p.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/q.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/r.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/s.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/t.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/u.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/w.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/x.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/v.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/y.js"></script> - <script type="text/javascript" src="desktop/sources/scripts/programs/z.js"></script> - - <link rel="stylesheet" type="text/css" href="desktop/sources/links/reset.css"/> - <link rel="stylesheet" type="text/css" href="desktop/sources/links/fonts.css"/> - <link rel="stylesheet" type="text/css" href="desktop/sources/links/main.css"/> - <link rel="stylesheet" type="text/css" href="desktop/sources/links/theme.css"/> - - <title>Pico</title> - </head> - <body> - <script> - const pico = new Pico() - pico.install() - pico.start() - - const keyboard = new Keyboard() - document.onkeydown = function(event){ keyboard.listen_onkeydown(event); } - </script> - </body> -</html> diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 3f4f0c8..0000000 --- a/npm-debug.log +++ /dev/null @@ -1,24 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/local/bin/node', -1 verbose cli '/usr/local/bin/npm', -1 verbose cli 'run', -1 verbose cli 'upgrade', -1 verbose cli '-save' ] -2 info using [email protected] -3 info using [email protected] -4 verbose stack Error: ENOENT: no such file or directory, open '/Users/VillaMoirai/Github/HundredRabbits/Pico/package.json' -4 verbose stack at Error (native) -5 verbose cwd /Users/VillaMoirai/Github/HundredRabbits/Pico -6 error Darwin 16.7.0 -7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "upgrade" "-save" -8 error node v6.11.4 -9 error npm v3.10.10 -10 error path /Users/VillaMoirai/Github/HundredRabbits/Pico/package.json -11 error code ENOENT -12 error errno -2 -13 error syscall open -14 error enoent ENOENT: no such file or directory, open '/Users/VillaMoirai/Github/HundredRabbits/Pico/package.json' -15 error enoent ENOENT: no such file or directory, open '/Users/VillaMoirai/Github/HundredRabbits/Pico/package.json' -15 error enoent This is most likely not a problem with npm itself -15 error enoent and is related to npm not being able to find a file. -16 verbose exit [ -2, true ] |