aboutsummaryrefslogtreecommitdiffstats
path: root/chips.js
diff options
context:
space:
mode:
authoralyx <>2022-02-04 14:02:20 +0000
committeralyxisdysphoric <alyx@aleteoryx.me>2022-02-04 14:02:20 +0000
commit40c8a4cb97f185f2b18c0e78f96a895b1b3fe06d (patch)
tree2135a25ef2890331935e5be2728ef34a3d7bd834 /chips.js
downloadRRCUtils-40c8a4cb97f185f2b18c0e78f96a895b1b3fe06d.tar.gz
RRCUtils-40c8a4cb97f185f2b18c0e78f96a895b1b3fe06d.tar.bz2
RRCUtils-40c8a4cb97f185f2b18c0e78f96a895b1b3fe06d.zip
Initial commit
Diffstat (limited to 'chips.js')
-rw-r--r--chips.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/chips.js b/chips.js
new file mode 100644
index 0000000..686dce0
--- /dev/null
+++ b/chips.js
@@ -0,0 +1,93 @@
+let root = document.documentElement;
+
+if (window.location.pathname != '/grapher/')
+ root.addEventListener("mousemove", e => {
+ root.style.setProperty('--mouse-x', e.clientX + "px");
+ root.style.setProperty('--mouse-y', e.clientY + "px");
+ });
+
+
+const portColors = {
+ float: '#186adc',
+ int: '#0f6522',
+ exec: '#f55b18',
+ string: '#794284',
+ bool: '#ea2e50',
+ any: '#f6eee8',
+ special: '#f4c61e'
+}
+const typeRegex = /(?:^|(?<=<))(?:int|float|bool|string|exec)(?:$|(?=>))/;
+const unionRegex = /^T\d*$|(?<=List<)T\d*(?=>)/;
+
+function computeType(Type, TypeParams, to) {
+ let t = Type;
+ if (to) for (const o of Object.keys(to)) t = t.replace(o, to[o]);
+ let tc = "special"
+ if (typeRegex.test(t)) {
+ tc = t;
+ } else if (unionRegex.test(t)) {
+ let tn = t.match(unionRegex)[0];
+ let ut = TypeParams[tn];
+ t = t.replace(unionRegex, `${tn}: ${ut}`)
+
+ tc = "any";
+ }
+ return {typeclass: tc, type: t};
+}
+
+function generateChipHTML(NodeDescs, typeoverride = undefined) {
+ for (let cur of NodeDescs) {
+ let ins = cur.Inputs;
+ let outs = cur.Outputs;
+
+ const root = newEl('div', 'chip');
+ const header = newEl('div', 'chipheader');
+ header.innerText = cur.Name;
+ const input = newEl('div', 'input');
+ const output = newEl('div', 'output');
+ root.append(header, input, output);
+
+ for (const inp of ins) {
+ //work out the type
+ let {typeclass, type} = computeType(inp.ReadonlyType, cur.ReadonlyTypeParams, typeoverride);
+
+ const port = newEl('div', typeclass);
+ port.innerHTML = inp.Name + "&nbsp;";
+ if (type.includes("List")) port.classList.add("list");
+
+ const tooltip = newEl('div', 'type');
+ tooltip.innerText = type;
+
+ input.append(port, tooltip);
+ }
+
+ for (const out of outs) {
+ //work out the type
+ let {typeclass, type} = computeType(out.ReadonlyType, cur.ReadonlyTypeParams, typeoverride);
+
+ const port = newEl('div', typeclass);
+ port.innerHTML = out.Name + "&nbsp;";
+ if (type.includes("List")) port.classList.add("list");
+
+ const tooltip = newEl('div', 'type');
+ tooltip.innerText = type;
+
+ output.append(port, tooltip);
+ }
+ return root;
+ }
+}
+
+function ListAllTypes(Nodes) {
+ let m = new Set();
+ for (const n of Object.values(Nodes)) {
+ for (const desc of n.NodeDescs) {
+ for (const td of Object.values(desc.ReadonlyTypeParams))
+ if (/^[A-Za-z0-9 ]+$/.test(td)) m.add(td);
+ for (const port of [...desc.Inputs, ...desc.Outputs])
+ if (/^[A-Za-z0-9 ]+$/.test(port.ReadonlyType) && !/^[A-Za-z]\d*$/.test(port.ReadonlyType)) m.add(port.ReadonlyType);
+ }
+ }
+ m.delete('any');
+ return Array.from(m);
+} \ No newline at end of file