aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-10-19 16:05:38 +1200
committerDevine Lu Linvega <[email protected]>2018-10-19 16:05:38 +1200
commitc7c28dcf38564f4fe880b21788a4910a68676b77 (patch)
tree8091178620b4f071004e5aa6675a8262351f7eee
parentd72636dd8a3dd7c175f2212b9db042b7e627a768 (diff)
downloadOrca-c7c28dcf38564f4fe880b21788a4910a68676b77.tar.gz
Orca-c7c28dcf38564f4fe880b21788a4910a68676b77.zip
Added save
-rw-r--r--desktop/core/pico.js14
-rw-r--r--desktop/sources/scripts/cursor.js4
-rw-r--r--desktop/sources/scripts/terminal.js36
-rw-r--r--examples/junctions.pico23
-rw-r--r--examples/loop.pico19
-rw-r--r--examples/raygun.pico20
-rw-r--r--examples/sequencer.pico18
-rw-r--r--examples/test_wires.pico21
-rw-r--r--examples/wires.pico20
9 files changed, 44 insertions, 131 deletions
diff --git a/desktop/core/pico.js b/desktop/core/pico.js
index cfbffdd..adcae1b 100644
--- a/desktop/core/pico.js
+++ b/desktop/core/pico.js
@@ -199,10 +199,18 @@ function Pico (w, h) {
// Tools
- this.output = function () {
+ this.lines = function () {
const origin = this.s.replace(/[^0-9a-z]/gi, '.')
- const lines = origin.match(/.{1,39}/g)
- return lines.reduce((acc, val) => {
+ const a = []
+ for (let y = 0; y < this.h; y++) {
+ const from = y * this.w
+ const to = this.w
+ a.push(origin.substr(from, to))
+ }
+ return a
+ }
+ this.output = function () {
+ return this.lines().reduce((acc, val) => {
return `${acc}${val}\n`
}, '')
}
diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js
index 0bc5d1e..fd3f1aa 100644
--- a/desktop/sources/scripts/cursor.js
+++ b/desktop/sources/scripts/cursor.js
@@ -54,6 +54,10 @@ function Cursor (terminal) {
}
this.erase = function (g) {
+ if (this.w === 1 && this.h === 1 && pico.glyphAt(this.x, this.y) === '.') {
+ this.move(-1, 0)
+ return
+ }
this.terminal.log(`Erase ${this._position()}`)
this.terminal.pico.removeBlock(this.x, this.y, this.w, this.h)
}
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index 5182b98..8d95207 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -58,6 +58,21 @@ function Terminal (pico) {
this.log(this.isPaused ? 'Paused' : 'Unpaused')
}
+ this.open = function () {
+ console.log('Open[TODO]')
+ let paths = dialog.showOpenDialog(app.win, { properties: ['openFile'] })
+ if (!paths) { console.log('Nothing to load') }
+ }
+
+ this.save = function () {
+ dialog.showSaveDialog((fileName) => {
+ if (fileName === undefined) { return }
+ fs.writeFile(fileName + '.pico', `${pico}`, (err) => {
+ if (err) { alert('An error ocurred updating the file' + err.message); console.log(err) }
+ })
+ })
+ }
+
this.load = function (path) {
const terminal = this
var fs = require('fs')
@@ -72,6 +87,8 @@ function Terminal (pico) {
})
}
+ //
+
this.log = function (msg) {
this.debug = msg
}
@@ -99,7 +116,8 @@ function Terminal (pico) {
const styles = {
isSelection: terminal.isSelection(x, y),
isCursor: terminal.isCursor(x, y),
- is_port: ports[`${x}:${y}`]
+ isPort: ports[`${x}:${y}`],
+ isLocked: pico.isLocked(x, y)
}
this.draw_sprite(x, y, pico.glyphAt(x, y), styles)
x += 1
@@ -174,7 +192,7 @@ function Terminal (pico) {
ctx.clearRect(0, 0, this.size.width, this.size.height)
}
- this.draw_sprite = function (x, y, g, styles = { isCursor: false, isSelection: false, is_port: false }) {
+ this.draw_sprite = function (x, y, g, styles = { isCursor: false, isSelection: false, isPort: false }) {
const ctx = this.context()
ctx.textBaseline = 'bottom'
@@ -185,16 +203,20 @@ function Terminal (pico) {
ctx.fillStyle = this.theme.active.b_inv
ctx.fillRect(x * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h)
ctx.fillStyle = this.theme.active.f_inv
- } else if (styles.is_port) {
- if (styles.is_port === 2) {
+ } else if (styles.isLocked) {
+ ctx.fillStyle = this.theme.active.background
+ ctx.fillRect(x * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h)
+ ctx.fillStyle = this.theme.active.f_low
+ } else if (styles.isPort) {
+ if (styles.isPort === 2) {
ctx.fillStyle = this.theme.active.b_high
ctx.fillRect(x * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h)
ctx.fillStyle = this.theme.active.f_low
- } else if (styles.is_port === 1) {
+ } else if (styles.isPort === 1) {
ctx.fillStyle = this.theme.active.b_med
ctx.fillRect(x * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h)
ctx.fillStyle = this.theme.active.f_med
- } else if (styles.is_port === 3) {
+ } else if (styles.isPort === 3) {
ctx.fillStyle = this.theme.active.b_low
ctx.fillRect(x * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h)
ctx.fillStyle = this.theme.active.f_high
@@ -202,7 +224,7 @@ function Terminal (pico) {
} else {
ctx.fillStyle = 'white'
}
- ctx.fillText(styles.isCursor && g === '.' ? (!pico.isPaused ? '@' : '~') : g, (x + 0.5) * this.tile.w, (y + 1) * this.tile.h)
+ ctx.fillText(styles.isCursor && g === '.' ? (!this.isPaused ? '@' : '~') : g, (x + 0.5) * this.tile.w, (y + 1) * this.tile.h)
}
this.reset = function () {
diff --git a/examples/junctions.pico b/examples/junctions.pico
deleted file mode 100644
index d66a91c..0000000
--- a/examples/junctions.pico
+++ /dev/null
@@ -1,23 +0,0 @@
-....................................................................
-.................................s..................................
-....................................................................
-.................................*..................................
-.................................|..................................
-.................................|..................................
-...................*-------------*-------------*....................
-...................|...........................|....................
-...................|...........................|....................
-...............*---*---*...................*---*---*................
-...............|.......|...................|.......|................
-...............|.......|...................|.......|................
-............*--*--*.*--*--*.............*--*--*.*--*--*.............
-............|.....|.|.....|.............|.....|.|.....|.............
-............|.....|.|.....|.............|.....|.|.....|.............
-.........*--*--*..|.|..*--*--*.......*--*--*..|.|..*--*--*..........
-.........|.....|..|.|..|.....|.......|.....|..|.|..|.....|..........
-.........|.....|..|.|..|.....|.......|.....|..|.|..|.....|..........
-......*--*--*..*..|.|..*..*--*--*.*--*--*..*..|.|..*..*--*--*.......
-......|.....|..|..|.|..|..|.....|.|.....|..|..|.|..|..|.....|.......
-......|.....|..|..|.|..|..|.....|.|.....|..|..|.|..|..|.....|.......
-......*.....*..*..*.*..*..*.....*.*.....*..*..*.*..*..*.....*.......
-.................................................................... \ No newline at end of file
diff --git a/examples/loop.pico b/examples/loop.pico
deleted file mode 100644
index 1da01ab..0000000
--- a/examples/loop.pico
+++ /dev/null
@@ -1,19 +0,0 @@
-..................................................
-..................................................
-..................................................
-..................................................
-..................................................
-................s......+------+...................
-.......................|......|...................
-.......................|......|...................
-.......................|......|...................
-................+------+------+....w..............
-................|......|..........................
-................|......|..........................
-................|......|..........................
-................+------+..........................
-..................................................
-..................................................
-..................................................
-..................................................
-.................................................. \ No newline at end of file
diff --git a/examples/raygun.pico b/examples/raygun.pico
deleted file mode 100644
index 71e2fac..0000000
--- a/examples/raygun.pico
+++ /dev/null
@@ -1,20 +0,0 @@
-.............................................................
-.............................................................
-............................1................................
-.............................................................
-.............................................................
-............................r................................
-...............r.............1...............................
-............................r................................
-.............................................................
-.............................................................
-............................1................................
-.............................................................
-.............................................................
-.............................................................
-.............................................................
-.............................................................
-.............................................................
-.............................................................
-.............................................................
-............................................................. \ No newline at end of file
diff --git a/examples/sequencer.pico b/examples/sequencer.pico
deleted file mode 100644
index eb4422c..0000000
--- a/examples/sequencer.pico
+++ /dev/null
@@ -1,18 +0,0 @@
-...........................................................
-.:BPM120...................................................
-...........................................................
-.:VOL075.........h.........................................
-................hb|...|...|...|...|........................
-..h.....h.......4lc.c.:SNR.................................
-..b.....b........h.........................................
-..i4....i4......hb|...|...|...|...|........................
-...f0....f0.....glc...c.c.c.......:SYN.....................
-....t.....t................................................
-...........r......0...|...|...|...|........................
-....i4..........8l0.c.0...:KCK.............................
-.....t.....................................................
-......r...........0...|...|...|...|........................
-................8l0....c..:PAD.............................
-...........................................................
-...........................................................
-........................................................... \ No newline at end of file
diff --git a/examples/test_wires.pico b/examples/test_wires.pico
deleted file mode 100644
index 12cc4f4..0000000
--- a/examples/test_wires.pico
+++ /dev/null
@@ -1,21 +0,0 @@
-..................................................................
-..................................................................
-...................e..*--+----*....*----+--*..w...................
-.........................|....|....|....|.........................
-.........................|....|....|....|.........................
-.........................*----*....*----*.........................
-...............................d..d...............................
-...................e..*--*----*....*----*--*..w...................
-.........................|....|....|....|.........................
-.........................|....|....|....|.........................
-.........................*----*....*----*.........................
-...............................d..d...............................
-.........................*----*....*----*.........................
-.........................|....|t...|....|t........................
-.........................|....|....|....|.........................
-.........................*----*g..g*----*.........................
-..................................................................
-..............................n....n..............................
-..................................................................
-..................................................................
-.................................................................. \ No newline at end of file
diff --git a/examples/wires.pico b/examples/wires.pico
deleted file mode 100644
index 0e0bb43..0000000
--- a/examples/wires.pico
+++ /dev/null
@@ -1,20 +0,0 @@
-.......................................................
-............s.......s........s.......s.................
-.......................................................
-............*--*.*--*.*--*.w.*--*.*--*.*--*.w..........
-............|..|.|..|.|..|...|..|.|..|.|..|............
-............|..|.|..|.|..|...|..|.|..|.|..|............
-............*--*.*--*.*--*...*--*.*--*.*--*............
-.......................................................
-..........e.*--*.*--*.*--*.e.*--*.*--*.*--*............
-............|..|.|..|.|..|...|..|.|..|.|..|............
-............|..|.|..|.|..|...|..|.|..|.|..|............
-............*--*.*--*.*--*.w.*--*.*--*.*--*.w..........
-.......................................................
-............*--*.*--*.*--*.e.*--*.*--*.*--*............
-............|..|.|..|.|..|...|..|.|..|.|..|............
-............|..|.|..|.|..|...|..|.|..|.|..|............
-..........e.*--*.*--*.*--*...*--*.*--*.*--*............
-.......................................................
-.................n.......n........n.......n............
-....................................................... \ No newline at end of file