diff --git a/README.md b/README.md index 87564ea3120ea8c5bef93a3e66aab8ce458584fe..64533444f3e077f8581c5b72a80d54324ebd0aef 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ change title of index.html ... ## Making this Useable -To dev... should be able to reload a hunk. Delete, undo es6 impement, call again, load in old links if possible. +To dev... should be able to reload a hunk. Delete, undo es6 impement, call again, load in old links if possible. ## Program 'Recipes' @@ -357,8 +357,7 @@ At the moment, the UI really hobbles along. There are a few big bugs and problem ## Known Bugs - - adding link from the DOM doesn't work when id's don't have one underscore in them... (is this still true?) - - an error while adding a link prevents a program (or hunk) from being sent to the view ... addHunk and addLink errors should be carefully handled + - of 2019 July 10: reloading a native hunk with document events attached: or deleting in general: document event handles are not removed, and are reachable by document, so will hang out. ## Bug Foreshadowing diff --git a/hunks/interface/arrowpad.js b/hunks/interface/arrowpad.js new file mode 100644 index 0000000000000000000000000000000000000000..d2a9b0ff33feb6df34a29967915854509bda16fa --- /dev/null +++ b/hunks/interface/arrowpad.js @@ -0,0 +1,140 @@ +/* + +arrowpad pressure, for maching jogging (probably) + +*/ + +import { + Hunkify, + Input, + Output, + State +} from '../hunks.js' + +function Arrowpad() { + Hunkify(this) + + let pairs = [{ + name: 'left', + code: 37, + down: false, + output: new Output('boolean', 'left', this) + }, { + name: 'right', + code: 39, + down: false, + output: new Output('boolean', 'right', this) + }, { + name: 'up', + code: 38, + down: false, + output: new Output('boolean', 'up', this) + }, { + name: 'down', + code: 40, + down: false, + output: new Output('boolean', 'down', this) + }, { + name: 'pgup', + code: 33, + down: false, + output: new Output('boolean', 'pgup', this) + }, { + name: 'right', + code: 34, + down: false, + output: new Output('boolean', 'pgdown', this) + } + ] + + for(let pair of pairs){ + this.outputs.push(pair.output) + } + + // as is tradition, + this.dom = {} + + this.init = () => { + // manager calls this once + // it is loaded and state is updated (from program) + console.log('HELLO KEYDOWN') + this.dom = $('<div>').get(0) + //this.dom = document.createElement('div') + } + + let activeStatus = false; + let activeColor = '#d981eb' + let idleColor = '#82aef5' + + let removeKeyBindings = () => { + document.removeEventListener('keydown', keyListen) + document.removeEventListener('keyup', keyListen) + // no sticky keys! + clearAllKeys() + } + + let setKeyBindings = () => { + document.addEventListener('keydown', keyDownListen) + document.addEventListener('keyup', keyUpListen) + } + + let keyDownListen = (evt) => { + let key = pairs.find((cand) => { + return cand.code === evt.keyCode + }) + if(key) { + key.down = true + } + } + + let keyUpListen = (evt) => { + let key = pairs.find((cand) => { + return cand.code === evt.keyCode + }) + if(key) { + key.down = false + } + } + + let clearAllKeys = () => { + for(let key of pairs){ + key.down = false; + } + } + + this.onload = () => { + let domain = $('<div>').get(0) + let msg = $('<div>').text('~ click in to activate ~').get(0) + $(msg).css('padding-top', '35px') + $(domain).append(msg) + $(domain).css('background-color', idleColor) + $(domain).width(400).height(400) + $(domain).css('text-align', 'center') + $(domain).css('font-size', '18px') + $(domain).css('color', 'white') + $(this.dom).append(domain) + this.dom.addEventListener('click', (evt) => { + if (activeStatus) { + activeStatus = false + $(msg).text('~ click in to activate ~') + $(domain).css('background-color', idleColor) + removeKeyBindings() + } else { + activeStatus = true + $(msg).text('~ push push push ~') + $(domain).css('background-color', activeColor) + setKeyBindings() + } + }) + } + + this.loop = () => { + for(let key of pairs){ + if(!(key.output.io) && key.down){ + key.output.put(true) + } + } + } +} + +export default Arrowpad