diff options
author | alyx <alyx@aleteoryx.me> | 2022-06-08 22:02:16 +0000 |
---|---|---|
committer | Aleteoryx <alyx@aleteoryx.me> | 2022-06-08 22:02:16 +0000 |
commit | 0490ebfefc2fb9383f8ff3a3302af2842e928377 (patch) | |
tree | 1807580dda9a4d833327741ac601e931d5fc6434 /lib | |
parent | d286258f7c05b1a98f9a9aea388690a85246fd87 (diff) | |
download | RRCUtils-0490ebfefc2fb9383f8ff3a3302af2842e928377.tar.gz RRCUtils-0490ebfefc2fb9383f8ff3a3302af2842e928377.tar.bz2 RRCUtils-0490ebfefc2fb9383f8ff3a3302af2842e928377.zip |
moved types.js to chips2.js, added a basic copy of the old logic, written with the new type parser
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chips2.js (renamed from lib/types.js) | 90 |
1 files changed, 86 insertions, 4 deletions
diff --git a/lib/types.js b/lib/chips2.js index 3fbb1c9..2c4c786 100644 --- a/lib/types.js +++ b/lib/chips2.js @@ -49,7 +49,7 @@ function Type(TypeName,Params=[]) { workspace += c; } if (workspace) types.push(workspace); - this.template = types.map(t => t.trim()).map(t => Params.includes(t) ? Type.any : new Type(t, Params)); + this.template = types.map(t => t.trim()).map(t => new Type(t, Params)); } //Template else if (/^[^<]+<.+>$/.test(TypeName)) { @@ -79,7 +79,7 @@ function Type(TypeName,Params=[]) { workspace += c; } if (workspace) types.push(workspace); - this.template = types.map(t => t.trim()).map(t => Params.includes(t) ? Type.any : new Type(t, Params)); + this.template = types.map(t => t.trim()).map(t => new Type(t, Params)); Type.all[this.typename] = () => new Type(TypeName, Array.from(Params)); } //Standard Type, or Template Param @@ -96,7 +96,7 @@ function Type(TypeName,Params=[]) { } } -Type.prototype.toString = function() { +Type.prototype.toString = function(info=false) { switch (this.mode) { case "tuple": return `(${this.template.join(',')})`; @@ -108,7 +108,7 @@ Type.prototype.toString = function() { case "standard": return this.typename; case "param": - return this.template.toString(); + return info ? `${this.typename}: ${this.template}` : this.template.toString(); } } @@ -321,4 +321,86 @@ function Chip(Entry) { input.append(...cur.Inputs.map(genPort).flat()); output.append(...cur.Outputs.map(genPort).flat()); +} + + +//chips.js reimplemented with the above + +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(tn, TypeParams, to) { + if (tn != "exec") { + const t = Object.entries({...TypeParams, ...to}).reduce((t,i) => t.resolve(...i), new Type(tn, Object.keys(TypeParams))); + return {typeclass: t.getClasses(), type: t.toString()}; + } else { + return {typeclass: ['exec'], type: 'exec'}; + } +} + +//keeping this the same for now +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', ''); + port.innerHTML = inp.Name + " "; + typeclass.map(port.classList.add.bind(port.classList)); + + 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', ''); + port.innerHTML = out.Name + " "; + typeclass.map(port.classList.add.bind(port.classList)); + + const tooltip = newEl('div', 'type'); + tooltip.innerText = type; + + output.append(port, tooltip); + } + + return root; + } + +} + +function ListAllTypes(Nodes) { + return Object.keys(Type.all); }
\ No newline at end of file |