aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2022-06-08 22:02:16 +0000
committerAleteoryx <alyx@aleteoryx.me>2022-06-08 22:02:16 +0000
commit0490ebfefc2fb9383f8ff3a3302af2842e928377 (patch)
tree1807580dda9a4d833327741ac601e931d5fc6434
parentd286258f7c05b1a98f9a9aea388690a85246fd87 (diff)
downloadRRCUtils-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
-rw-r--r--grapher/index.html2
-rw-r--r--index.html8
-rw-r--r--lib/chips2.js (renamed from lib/types.js)90
-rw-r--r--searcher/index.html2
-rw-r--r--types.html3
5 files changed, 94 insertions, 11 deletions
diff --git a/grapher/index.html b/grapher/index.html
index b81b31b..23144e6 100644
--- a/grapher/index.html
+++ b/grapher/index.html
@@ -16,7 +16,7 @@
<script crossorigin src="/lib/util.js"></script>
<script crossorigin src="/lib/types.js"></script>
- <script crossorigin src="/lib/chips.js"></script>
+ <script crossorigin src="/lib/chips2.js"></script>
<script crossorigin src="script.js"></script>
<noscript><style> #searcher, #graph, #canvas { display: none } </style></noscript>
</head>
diff --git a/index.html b/index.html
index 9cac405..a7d4cac 100644
--- a/index.html
+++ b/index.html
@@ -49,11 +49,12 @@
<span style="color:khaki;">Frosty</span>;</code></h1>
<hr>
<ul>
- <li>Continued work on type inference logic.</li>
+ <li>Continued work on type intersection logic.</li>
<ul>
<li><q>as well as plenty of methods for computing intersections between them.</q></li>
<li>But actually now! The <code><span style="color:khaki;">intersect</span>(<span style="color:crimson;">T1</span>,<span style="color:crimson;">T2</span>)</code> function generates the intersection between 2 types.</li>
<li>Support exists for things as dense as nested unions, even.</li>
+ <li>The grapher and the searcher have had their underlying parsers rebuilt on the new code.</li>
<li><b>As Always:</b></li>
<ul>
<li>You can view it at <a href="/types.html">types.html</a>, by opening the DevTools console or reading the table.</li>
@@ -74,7 +75,7 @@
<h1>June 3, 2022 - The Three Clicks Edition</h1>
<hr>
<ul>
- <li>Continued work on type inference logic.</li>
+ <li>Continued work on type intersection logic.</li>
<ul>
<li>There is now something that can parse in R2C types,
as well as plenty of methods for computing intersections between them.</li>
@@ -97,7 +98,7 @@
<li>Added Changelog.</li>
<li>Added a credits section.</li>
</ul>
- <li>Continued work on type inference logic.</li>
+ <li>Continued work on type intersection logic.</li>
<ul>
<li>You can view it at <a href="/types.html">types.html</a>, by opening the DevTools console.</li>
<li>The actual logic is contained in <code>/lib/types.js</code>.</li>
@@ -120,5 +121,6 @@
<li><a href="https://useiconic.com/open" target="_blank">Open Iconic - Various Icons</a></li>
<li><a href="https://fusejs.io" target="_blank">fuse.js - Searching through the JSON</a></li>
</ul>
+ <p>The term "R2C"(Rec Room Circuits) was coined by Demented on the <a href="https://discord.gg/recroom">RR Discord</a>.</p>
</body>
</html> \ No newline at end of file
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 + "&nbsp;";
+ 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 + "&nbsp;";
+ 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
diff --git a/searcher/index.html b/searcher/index.html
index eb4937d..83abf53 100644
--- a/searcher/index.html
+++ b/searcher/index.html
@@ -12,7 +12,7 @@
<link crossorigin href="/lib/chips.css" rel="stylesheet" type="text/css" />
<link crossorigin href="/lib/util.js" rel="preload" as="script"/>
- <link crossorigin href="/lib/chips.js" rel="preload" as="script"/>
+ <link crossorigin href="/lib/chips2.js" rel="preload" as="script"/>
<link crossorigin href="script.js" rel="preload" as="script"/>
<link crossorigin href="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.min.js" rel="preload" as="script"/>
<link crossorigin href="/lib/chips.css" rel="preload" as="style"/>
diff --git a/types.html b/types.html
index 3f9d74a..81da334 100644
--- a/types.html
+++ b/types.html
@@ -6,8 +6,7 @@
<title>Document</title>
<script src="/lib/util.js"></script>
- <script src="/lib/types.js"></script>
- <script src="/lib/chips.js"></script>
+ <script src="/lib/chips2.js"></script>
<link href="/lib/chips.css" rel="stylesheet"></link>
<style>