-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.js
More file actions
99 lines (85 loc) · 3.34 KB
/
ui.js
File metadata and controls
99 lines (85 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// const Y = require('js-yaml')
const R = require('ramda')
const m = require('mithril')
const Opstack = require('./machine.js')
const {robot, r_set, r_switch} = require('./robot.js')
const controller = require('./controller.js')
var start = undefined;
function step(timestamp) {
if (!start) start = timestamp;
var progress = timestamp - start;
// if (progress < 2000) {
let r = robot()
r.x = Math.max(0, r.x + r.m0)
r.y = Math.max(0, r.y + r.m1)
robot(r)
controller()
window.requestAnimationFrame(step);
// }
}
const prop = (label, val) => m('p', [m('span',`${label}: `), m('b', val)])
const btn = (label, fn) => m('button', {onclick: fn}, label)
var UI = {
oninit: (vnode) => {
// if loaded initially, update the stream (before first drawing)
// if (vnode.attrs.state && robot() !== vnode.attrs.diag) {
// numbers(vnode.attrs.diag)
// }
// update the route when the contents are changed
robot.map(s => m.route.set('/:state', {state: JSON.stringify(s)}))
},
oncreate: () => {
window.requestAnimationFrame(step)
},
view: (vnode) => {
// let isBetter = array().length < (2 * graph().length)
let s = robot()
let sw = x => x ? m('span.switch.on', 'on') : m('span.switch.off', 'off')
let M = x => x === 0 ? m('span.motor.off', 'off') : (x < 0 ? m('span.motor.left', '«««') : m('span.motor.right', '»»»'))
return m('.ui', [
m('div',[
m('div.manual', [
btn('left', () => r_switch('m0', -1,0)),
btn('right', () => r_switch('m0', 1,0)),
btn('up', () => r_switch('m1', -1,0)),
btn('down', () => r_switch('m1', 1,0))
]),
m('div.controller', [
btn('s1', () => controller({stack:1})),
btn('s2', () => controller({stack:2})),
btn('s3', () => controller({stack:3})),
btn('s4', () => controller({stack:4})),
btn('s5', () => controller({stack:5})),
btn('first', () => controller({first:true})),
btn('top', () => controller({top:true})),
btn('stackMax', () => controller({stackMax:true})),
btn('suck', () => controller({suck:true})),
btn('no sucky', () => controller({nosucky:true})),
]),
m('p', [
prop('y', s.y),
prop('x', s.x),
]),
m('hr'),
prop('commands ', [
prop('cmd', s.cmd),
m('pre',R.join('\n', R.map(JSON.stringify.bind(JSON), s.queue || [])))
]),
m('hr'),
m('p', [
prop('m0', s.m0),
prop('m1', s.m1),
prop('suck', sw(s.suck)),
prop('sw0', sw(s.sw0)),
prop('sw1 ', sw(s.sw1)),
prop('stacks ', R.join('_', R.map(R.prop('h'), s.stacks))),
])
]),
m('.opstack', [
m('h4', 'Operator Stack'),
m(Opstack, {robot: robot()})
]),
])
}
}
module.exports = UI