mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-16 21:37:36 +08:00
Compare commits
55 Commits
typescript
...
dd81356d68
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd81356d68 | ||
|
|
9985071d61 | ||
|
|
c5f57dd3ef | ||
|
|
5b9b3a2592 | ||
|
|
c73bcdcdb5 | ||
|
|
6167e97406 | ||
|
|
0c6bda6fd4 | ||
|
|
58bb21b332 | ||
|
|
b4fdb99819 | ||
|
|
41988b1599 | ||
|
|
1d9a88125e | ||
|
|
dfa402707c | ||
|
|
15a1769b95 | ||
|
|
c356878e3f | ||
|
|
6403fec906 | ||
|
|
e40e6ba52b | ||
|
|
2173e2b421 | ||
|
|
3b68fb46a8 | ||
|
|
c0032fed76 | ||
|
|
e405a7245d | ||
|
|
3de0e74ef0 | ||
|
|
626b1eaafd | ||
|
|
365732a99c | ||
|
|
20e64e8511 | ||
|
|
d6f6513391 | ||
|
|
079fdb59c9 | ||
|
|
25bb1717df | ||
|
|
bbe92166f0 | ||
|
|
876b8ce47f | ||
|
|
a02877b9b9 | ||
|
|
4cdcae1493 | ||
|
|
5c26c95b5d | ||
|
|
007eec971b | ||
|
|
73176a8102 | ||
|
|
b9c2df5a3e | ||
|
|
4865f5fdab | ||
|
|
b1dc894f03 | ||
|
|
8d91a52e8c | ||
|
|
2352d866a6 | ||
|
|
a8d78483d5 | ||
|
|
404a2aed4f | ||
|
|
90d0cd7016 | ||
|
|
2b028e2800 | ||
|
|
5ea4d75a81 | ||
|
|
3f0185fca5 | ||
|
|
8b38173204 | ||
|
|
c03d0c8355 | ||
|
|
5d4f020a85 | ||
|
|
a763544b3b | ||
|
|
4885a988f9 | ||
|
|
4601c9dc48 | ||
|
|
19ef3bd10e | ||
|
|
2114abef5c | ||
|
|
c246c82bfe | ||
|
|
23ee628e28 |
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.vscode/extensions.json
vendored
Normal file → Executable file
0
.vscode/extensions.json
vendored
Normal file → Executable file
0
.vscode/launch.json
vendored
Normal file → Executable file
0
.vscode/launch.json
vendored
Normal file → Executable file
0
.vscode/settings.json
vendored
Normal file → Executable file
0
.vscode/settings.json
vendored
Normal file → Executable file
11
CONTRIBUTING.md
Normal file → Executable file
11
CONTRIBUTING.md
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
# Development Guide
|
||||
Getting started with the development of this application is very easy because it has a (arguably) well defined object-oriented architecture and separation of concerns.
|
||||
Getting started with the development of this application is very easy. It has a (arguably) well defined object-oriented architecture and separation of concerns.
|
||||
|
||||
Before starting, the gentle reader might want to make sure to be familiar with the [Lit](https://lit.dev/) library and its element [lifecycle](https://lit.dev/docs/components/lifecycle/). This library is used extensively throught the application to keep the HTML elements in sync with the data and avoid updating the DOM too often. The original author is aware that there are way more popular alternatives out there like React, Vue and Svelte, but the design of Lit fits very well into the original design of this application: vanilla JavaScript and object-oriented. This allowed the introduction of Lit with a relatively small amount of changes to the existing code, yes because the decision to use Lit was made at a later point in time. One important detail is that it does not make use of the shadow DOM (part of the Web Components), the real reason is that the development started without using Lit but it is still nice to be able to have a global CSS style (which wouldn't be possibile with a shadow root) so that restyling the library is just a matter of adding another CSS file and rewrite a few properties.
|
||||
Before starting, the gentle reader might want to make sure to be familiar with the [Lit](https://lit.dev/) library and its element [lifecycle](https://lit.dev/docs/components/lifecycle/). This library is used extensively throught the application to keep the HTML elements in sync with the data and avoid updating the DOM too often. The original author is aware that there are way more popular alternatives out there like React, Vue and Svelte, but the design of Lit fits very well into the original design of this application: vanilla JavaScript and object-oriented. This allowed the introduction of Lit with a relatively small amount of changes to the existing code because the decision to use Lit was made at a later point in time. One important detail is that it does not make use of the shadow DOM (part of the Web Components), the real reason is that the development started without using Lit but it is still nice to be able to have a global CSS style (which wouldn't be possibile with a shadow root) so that restyling the library is just a matter of adding another CSS file and rewrite a few properties.
|
||||
|
||||
The only other external library that is used here is [Parsernostrum](https://github.com/barsdeveloper/parsernostrum): a very small but capable text parsing library used to deserialize the text produced by the UE Blueprint Editor.
|
||||
|
||||
@@ -47,12 +47,7 @@ And refresh the HTML page possibly holding `Shift`.
|
||||
There are a few concepts that must be assimilated in order to understand the design. Those concepts are in general each mapped into a subfolder in `js/`.
|
||||
|
||||
### Entity
|
||||
An Entity is just a data holder object that does not really do anything by itself, it has a purely information storage related purpose. The top class at the hierarchy of entities is `IEntity`. This one is a bit more complicated in the sense that it does the initialization of the entity in its constructor according to the information contained in the object provided as an argument or from the attributes static field. This ended up being a somewhat wacky runtime type system. Each subclass can specify its attributes static member variable of type object where each entry is either a value (the default value the attribute will have), a function (called to generate such default value) or an object and in that case it will be of type `AttributeInformation` (please note that in case one wants to assign as default value a specific object, the solution is either to wrap it into a `AttributeInformation` object or to return it from a function).
|
||||
|
||||
### Grammar and Serializer
|
||||
In the `serialization/` folder the gentle reader will find all the classes responsible for transforming entities from and to text that the UE Blueprint Enditor can understand. One important class here is `Grammar` that contains similar formal grammar rules that use the [Parsernostrum library](https://github.com/barsdeveloper/parsernostrum) to create entities from Blueprint text. `Serializer` is at the top of the serializer classes hierarchy and it uses a factory design pattern to register serializers for the various entities types (check `js/serialization/initializeSerializerFactory.js`). It does both read and write of entities: to read it will use the Grammar after creating a language using a function from Parsernostrum, to write it will use methods from the class itself.
|
||||
|
||||
Grammar is usually the first place to look when pasting valid Blueprint code does fail. Most likely newer version of Unreal Engine did add some new data type that was not implemented yet (or this library never managed to handle it in the first place). In that case the approach should be trying to fix the existing grammar and entities to accept it, then implement the new entities and attributes.
|
||||
An Entity is just a data holder object that does not really do anything by itself, it has a purely information storage related purpose. The top class at the hierarchy of entities is `IEntity`. It is responsible for the initialization of the entity in its constructor according to the information contained in the object provided as an argument or from the attributes static field. This ended up being a somewhat wacky runtime type system. Each subclass can specify its attributes in the form of a static member variable of type vanilla object where each entry is a subclass of IEntity. The entities moreover are responsible for their serialization and deserialization: each class has a `serialize()` method and a `grammar` attribute to parse entities.
|
||||
|
||||
### Element
|
||||
Each element is just a custom HTML element type and its tag name is defined in the class file. The top level of the hierarchy is `IElement` and it inherits from `LitElement`. This class can be thought as an association between an entity and a template (and those are the arguments of the constructor). The top class `IElement` does propagate the lifecycle provided by `LitElement` to the template so that a template can hook into it.
|
||||
|
||||
26
README.md
Normal file → Executable file
26
README.md
Normal file → Executable file
@@ -1,22 +1,22 @@
|
||||
# UEBlueprint
|
||||
|
||||
A stand alone editor implementation of the UE's Blueprint visual language. (WIP)
|
||||
A stand alone implementation of the UE's Blueprint visual language editor
|
||||
|
||||
https://www.npmjs.com/package/ueblueprint
|
||||
|
||||
## Features:
|
||||
|
||||
- Intercommunicates with UE (can copy nodes both ways).
|
||||
- Can be used as a WEB library to visualize, interact and modify Blueprint graphs.
|
||||
- Can be used inside VS Code to operate directly on files from a UE project (in the future).
|
||||
- Can be used as a WEB library to visualize and interact with Blueprint graphs.
|
||||
- Graph shown is pixel-similar to how it appears in UE.
|
||||
- Graph behaves the same way as it does in UE (with the default settings).
|
||||
- All the information shown in he graph is just the one embedded in the serialized text (in VS Code it should be able to access assets also).
|
||||
- Modern object oriented, clean, JavaScript codebase.
|
||||
- All the information shown in he graph is just the one embedded in the serialized text.
|
||||
|
||||
## Demo:
|
||||
[Try it!](https://barsdeveloper.github.io/ueblueprint/)
|
||||
|
||||

|
||||
### [Try it!](https://barsdeveloper.github.io/ueblueprint/)
|
||||
|
||||
[](https://barsdeveloper.github.io/ueblueprint/)
|
||||
|
||||
## Getting started:
|
||||
|
||||
@@ -33,8 +33,9 @@ npx http-server
|
||||
### Use in a web page
|
||||
|
||||
You can check `index.html` for a working example, the main steps are the following:
|
||||
1. Include `dist/css/ueb-style.css` stylesheet in your page.
|
||||
2. Define eventual CSS variables.
|
||||
1. Make the `dist` directory available in your website by copying it or installing through npm `npm i ueblueprint`.
|
||||
2. Include `dist/css/ueb-style.min.css` stylesheet in your page.
|
||||
3. Define eventual CSS variables.
|
||||
```HTML
|
||||
<style>
|
||||
ueb-blueprint {
|
||||
@@ -42,13 +43,14 @@ You can check `index.html` for a working example, the main steps are the followi
|
||||
}
|
||||
</style>
|
||||
```
|
||||
3. Import the class Blueprint in JavaScript (this library uses modules).
|
||||
4. Import the class Blueprint in JavaScript (this library uses modules).
|
||||
```HTML
|
||||
<script type="module">
|
||||
import { Blueprint } from "./dist/ueblueprint.js"
|
||||
import { Blueprint } from "./dist/ueblueprint.min.js"
|
||||
</script>
|
||||
```
|
||||
4. Define your blueprint the by just writing the code inside a `ueb-blueprint`, inside a `template` element.
|
||||
5. Define your blueprint by writing the code inside a `template`, inside a `ueb-blueprint` element.
|
||||
It can have light background using the following CSS class: `<ueb-blueprint class="ueb-light-mode">`
|
||||
```HTML
|
||||
<ueb-blueprint>
|
||||
<template>
|
||||
|
||||
0
assets/fonts/roboto-bold.woff2
Normal file → Executable file
0
assets/fonts/roboto-bold.woff2
Normal file → Executable file
0
assets/fonts/roboto-condensed-bold.woff2
Normal file → Executable file
0
assets/fonts/roboto-condensed-bold.woff2
Normal file → Executable file
0
assets/fonts/roboto-light.woff2
Normal file → Executable file
0
assets/fonts/roboto-light.woff2
Normal file → Executable file
0
assets/fonts/roboto-regular.woff2
Normal file → Executable file
0
assets/fonts/roboto-regular.woff2
Normal file → Executable file
135
dist/css/ueb-style.css
vendored
Normal file → Executable file
135
dist/css/ueb-style.css
vendored
Normal file → Executable file
@@ -11,6 +11,9 @@
|
||||
ueb-blueprint {
|
||||
--ueb-scale: 1;
|
||||
--ueb-grid-actual-size: var(--ueb-grid-size);
|
||||
--ueb-grid-line-color: #353535;
|
||||
--ueb-grid-set-line-color: #161616;
|
||||
--ueb-grid-axis-line-color: #000;
|
||||
display: block;
|
||||
position: relative;
|
||||
font-family: Roboto, Noto, Oxygen, Ubuntu, "Open Sans", "Helvetica Neue", sans-serif;
|
||||
@@ -20,7 +23,8 @@ ueb-blueprint {
|
||||
}
|
||||
|
||||
ueb-blueprint svg {
|
||||
overflow: visible;
|
||||
overflow: visible !important;
|
||||
max-width: none !important;
|
||||
}
|
||||
|
||||
.ueb-viewport-header {
|
||||
@@ -33,6 +37,15 @@ ueb-blueprint svg {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.ueb-viewport-about {
|
||||
margin-top: -6px;
|
||||
padding: 0 8px;
|
||||
align-self: center;
|
||||
font-size: 20px;
|
||||
font-weight: bolder;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@keyframes ueb-zoom-animation {
|
||||
0% {
|
||||
color: #7f7f7f;
|
||||
@@ -42,7 +55,7 @@ ueb-blueprint svg {
|
||||
}
|
||||
}
|
||||
.ueb-zoom-changed .ueb-viewport-zoom {
|
||||
animation: 600ms ueb-zoom-animation;
|
||||
animation: 1500ms ueb-zoom-animation;
|
||||
}
|
||||
|
||||
.ueb-viewport-zoom {
|
||||
@@ -89,7 +102,6 @@ ueb-blueprint[data-scrolling=false] .ueb-grid {
|
||||
|
||||
ueb-blueprint.ueb-zoom--4 {
|
||||
--ueb-grid-actual-size: calc(var(--ueb-grid-size) * 2);
|
||||
--ueb-node-radius: 0 !important;
|
||||
}
|
||||
|
||||
ueb-blueprint.ueb-zoom--6 {
|
||||
@@ -144,6 +156,50 @@ ueb-selector > * {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ueb-info-dialog {
|
||||
border: 6px solid #202020;
|
||||
padding: 5px 30px;
|
||||
background: #121212;
|
||||
color: #f0f0f0;
|
||||
box-shadow: 0 2px 10px 0 #000;
|
||||
}
|
||||
.ueb-info-dialog a:link,
|
||||
.ueb-info-dialog a:visited,
|
||||
.ueb-info-dialog a:hover,
|
||||
.ueb-info-dialog a:active {
|
||||
outline: none;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
|
||||
.ueb-info-dialog::backdrop {
|
||||
background-color: rgba(0, 0, 0, 0.6274509804);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
/* Light mode */
|
||||
ueb-blueprint.ueb-light-mode {
|
||||
--ueb-grid-line-color: #ddd;
|
||||
--ueb-grid-set-line-color: #c0c0c0;
|
||||
--ueb-grid-axis-line-color: #a0a0a0;
|
||||
}
|
||||
|
||||
ueb-blueprint.ueb-light-mode .ueb-grid {
|
||||
background-color: #f6f6f6;
|
||||
}
|
||||
|
||||
ueb-blueprint.ueb-light-mode ueb-node.ueb-node-style-glass .ueb-node-wrapper {
|
||||
background-color: rgba(0, 0, 0, 0.5647058824);
|
||||
}
|
||||
|
||||
ueb-blueprint.ueb-light-mode ueb-link .ueb-link-path {
|
||||
filter: saturate(200%) brightness(0.6);
|
||||
}
|
||||
|
||||
ueb-blueprint.ueb-light-mode .ueb-viewport-header {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
color: #101010;
|
||||
}
|
||||
|
||||
ueb-node.ueb-node-style-minimal {
|
||||
box-shadow: none;
|
||||
}
|
||||
@@ -175,9 +231,7 @@ ueb-node.ueb-node-style-minimal[data-selected=true] .ueb-node-border {
|
||||
ueb-link {
|
||||
position: absolute;
|
||||
--ueb-link-color: rgb(var(--ueb-link-color-rgb));
|
||||
--ueb-from-input-coefficient: calc(2 * var(--ueb-from-input) - 1);
|
||||
/* when from-y > to-y */
|
||||
--ueb-y-reflected: clamp(0, var(--ueb-from-y) - var(--ueb-to-y) - 1, 1);
|
||||
display: block;
|
||||
margin-left: calc(var(--ueb-link-start) * -1px);
|
||||
min-width: calc(var(--ueb-link-min-width) * 1px);
|
||||
@@ -189,12 +243,11 @@ ueb-link {
|
||||
}
|
||||
|
||||
ueb-link > svg {
|
||||
--ueb-y-reflected-coefficient: calc(2 * var(--ueb-y-reflected) - 1);
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 1px;
|
||||
transform: scaleY(calc(var(--ueb-y-reflected-coefficient) * var(--ueb-from-input-coefficient)));
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
min-height: 1px !important;
|
||||
transform: scaleX(var(--ueb-link-scale-x)) scaleY(var(--ueb-link-scale-y));
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
@@ -221,10 +274,12 @@ ueb-link[data-dragging=true] .ueb-link-message {
|
||||
}
|
||||
|
||||
.ueb-link-message {
|
||||
--ueb-link-message-top: calc(50% * (var(--ueb-link-scale-y) + 1) + 22px);
|
||||
--ueb-link-message-left: calc(100% - var(--ueb-start-percentage) + 15px);
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: calc(100% * (1 - var(--ueb-y-reflected)) + 22px);
|
||||
left: calc((1 - var(--ueb-from-input)) * 100% + (var(--ueb-from-input-coefficient)) * var(--ueb-start-percentage) + 15px);
|
||||
top: var(--ueb-link-message-top);
|
||||
left: var(--ueb-link-message-left);
|
||||
border: 1px solid #000;
|
||||
border-radius: 2px;
|
||||
background: linear-gradient(to bottom, #2a2a2a 0, #151515 50%, #2a2a2a 100%);
|
||||
@@ -233,6 +288,11 @@ ueb-link[data-dragging=true] .ueb-link-message {
|
||||
z-index: 1000000;
|
||||
}
|
||||
|
||||
ueb-link[data-from-input=true] .ueb-link-message {
|
||||
--ueb-link-message-top: calc(-50% * (var(--ueb-link-scale-y) - 1) + 22px);
|
||||
--ueb-link-message-left: calc(var(--ueb-start-percentage) + 15px);
|
||||
}
|
||||
|
||||
.ueb-link-message-icon {
|
||||
display: inline-block;
|
||||
padding: 4px;
|
||||
@@ -266,10 +326,6 @@ ueb-node.ueb-node-style-comment {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ueb-zoom--2 ueb-node {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.ueb-node-border {
|
||||
margin: -3px;
|
||||
padding: 3px;
|
||||
@@ -309,6 +365,10 @@ ueb-node[data-selected=true] > .ueb-node-border {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ueb-zoom--2 .ueb-node-wrapper {
|
||||
background: rgb(14, 16, 10);
|
||||
}
|
||||
|
||||
ueb-node.ueb-node-style-operation .ueb-node-wrapper {
|
||||
grid-template-rows: min-content auto auto min-content min-content;
|
||||
grid-template-columns: 50% 0% 1fr;
|
||||
@@ -334,7 +394,6 @@ ueb-blueprint[data-scrolling=false][data-selecting=false] .ueb-draggable {
|
||||
}
|
||||
|
||||
.ueb-zoom--2 .ueb-node-wrapper {
|
||||
box-shadow: none;
|
||||
padding: 0;
|
||||
background: #101010;
|
||||
}
|
||||
@@ -371,10 +430,6 @@ ueb-node.ueb-node-style-event .ueb-node-top {
|
||||
background: linear-gradient(rgba(255, 255, 255, 0.1882352941) 1px, transparent 1px), linear-gradient(170deg, rgb(var(--ueb-node-color)) 0%, rgb(var(--ueb-node-color)) 50%, transparent 100%);
|
||||
}
|
||||
|
||||
.ueb-zoom--2 .ueb-node-top {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.ueb-zoom--2 .ueb-node-style-default .ueb-node-top {
|
||||
background: rgb(var(--ueb-node-color));
|
||||
}
|
||||
@@ -523,6 +578,10 @@ ueb-node.ueb-node-style-glass .ueb-node-wrapper {
|
||||
background-repeat: repeat, no-repeat;
|
||||
}
|
||||
|
||||
.ueb-zoom--2 ueb-node.ueb-node-style-glass .ueb-node-wrapper {
|
||||
background: #101010;
|
||||
}
|
||||
|
||||
ueb-node.ueb-node-style-glass .ueb-node-name {
|
||||
padding-right: 0;
|
||||
padding-left: 0;
|
||||
@@ -646,7 +705,7 @@ ueb-node.ueb-node-style-conversion .ueb-node-wrapper::after {
|
||||
grid-area: center;
|
||||
align-self: center;
|
||||
justify-self: center;
|
||||
margin: 10px;
|
||||
margin: 10px 10px 10px -6px;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
@@ -740,11 +799,6 @@ ueb-pin[data-connectable=false] .ueb-pin-icon {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.ueb-node-style-event ueb-pin[data-type=delegate] .ueb-pin-icon {
|
||||
width: 11px;
|
||||
height: 11px;
|
||||
}
|
||||
|
||||
.ueb-node-inputs .ueb-pin-icon {
|
||||
margin-right: 6px;
|
||||
}
|
||||
@@ -815,6 +869,23 @@ ueb-node[data-type="/Script/BlueprintGraph.K2Node_VariableSet"] ueb-pin[data-dir
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.ueb-pin-input[type=checkbox] {
|
||||
display: grid;
|
||||
place-content: center;
|
||||
appearance: none;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 1px solid #353535;
|
||||
background: #0f0f0f;
|
||||
}
|
||||
.ueb-pin-input[type=checkbox]:checked::before {
|
||||
content: "";
|
||||
height: 0.7em;
|
||||
width: 0.8em;
|
||||
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
|
||||
background: #0070e0;
|
||||
}
|
||||
|
||||
ueb-pin[data-linked=true] .ueb-pin-input,
|
||||
ueb-pin[data-linked=true] .ueb-pin-input-wrapper {
|
||||
display: none;
|
||||
@@ -865,7 +936,7 @@ ueb-pin[data-type="/Script/CoreUObject.LinearColor"] .ueb-pin-input {
|
||||
max-height: 16em;
|
||||
/* 97% is to get an effective font size of 12.6px from --ueb-font-size which is 13 px by default */
|
||||
font-size: 97%;
|
||||
white-space: nowrap;
|
||||
white-space: pre;
|
||||
background: none;
|
||||
color: inherit;
|
||||
overflow: auto;
|
||||
@@ -1280,4 +1351,12 @@ ueb-ui-slider {
|
||||
color: #c0c0c0;
|
||||
}
|
||||
|
||||
/* To improve a bit performance */
|
||||
.ueb-zoom--2 * {
|
||||
border: none !important;
|
||||
border-radius: 0 !important;
|
||||
box-shadow: none !important;
|
||||
text-shadow: none !important;
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=ueb-style.css.map */
|
||||
|
||||
2
dist/css/ueb-style.css.map
vendored
Normal file → Executable file
2
dist/css/ueb-style.css.map
vendored
Normal file → Executable file
File diff suppressed because one or more lines are too long
2
dist/css/ueb-style.min.css
vendored
Normal file → Executable file
2
dist/css/ueb-style.min.css
vendored
Normal file → Executable file
File diff suppressed because one or more lines are too long
2
dist/css/ueb-style.min.css.map
vendored
Normal file → Executable file
2
dist/css/ueb-style.min.css.map
vendored
Normal file → Executable file
File diff suppressed because one or more lines are too long
0
dist/font/roboto-bold.woff
vendored
Normal file → Executable file
0
dist/font/roboto-bold.woff
vendored
Normal file → Executable file
0
dist/font/roboto-bold.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-bold.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-condensed-bold.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-condensed-bold.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-condensed-regular.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-condensed-regular.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-light.woff
vendored
Normal file → Executable file
0
dist/font/roboto-light.woff
vendored
Normal file → Executable file
0
dist/font/roboto-light.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-light.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-regular.woff
vendored
Normal file → Executable file
0
dist/font/roboto-regular.woff
vendored
Normal file → Executable file
0
dist/font/roboto-regular.woff2
vendored
Normal file → Executable file
0
dist/font/roboto-regular.woff2
vendored
Normal file → Executable file
5127
dist/ueblueprint.js
vendored
5127
dist/ueblueprint.js
vendored
File diff suppressed because one or more lines are too long
12
dist/ueblueprint.min.js
vendored
Normal file → Executable file
12
dist/ueblueprint.min.js
vendored
Normal file → Executable file
File diff suppressed because one or more lines are too long
@@ -11,7 +11,6 @@
|
||||
padding: 0;
|
||||
--ueb-height: 100vh;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>UE Blueprint</title>
|
||||
<link rel="stylesheet" href="dist/css/ueb-style.css">
|
||||
<link rel="stylesheet" href="dist/css/ueb-style.min.css">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
|
||||
@@ -4,6 +4,8 @@ import IElement from "./element/IElement.js"
|
||||
import LinkElement from "./element/LinkElement.js"
|
||||
import NodeElement from "./element/NodeElement.js"
|
||||
import BlueprintEntity from "./entity/BlueprintEntity.js"
|
||||
import BooleanEntity from "./entity/BooleanEntity.js"
|
||||
import NiagaraClipboardContent from "./entity/objects/NiagaraClipboardContent.js"
|
||||
import BlueprintTemplate from "./template/BlueprintTemplate.js"
|
||||
|
||||
/** @extends {IElement<BlueprintEntity, BlueprintTemplate>} */
|
||||
@@ -14,19 +16,19 @@ export default class Blueprint extends IElement {
|
||||
type: Boolean,
|
||||
attribute: "data-selecting",
|
||||
reflect: true,
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
},
|
||||
scrolling: {
|
||||
type: Boolean,
|
||||
attribute: "data-scrolling",
|
||||
reflect: true,
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
},
|
||||
focused: {
|
||||
type: Boolean,
|
||||
attribute: "data-focused",
|
||||
reflect: true,
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
},
|
||||
zoom: {
|
||||
type: Number,
|
||||
@@ -296,29 +298,11 @@ export default class Blueprint extends IElement {
|
||||
return [x, y]
|
||||
}
|
||||
|
||||
getNodes(
|
||||
selected = false,
|
||||
[t, r, b, l] = [
|
||||
Number.MIN_SAFE_INTEGER,
|
||||
Number.MAX_SAFE_INTEGER,
|
||||
Number.MAX_SAFE_INTEGER,
|
||||
Number.MIN_SAFE_INTEGER,
|
||||
]
|
||||
) {
|
||||
getNodes(selected = false) {
|
||||
let result = this.nodes
|
||||
if (selected) {
|
||||
result = result.filter(n => n.selected)
|
||||
}
|
||||
if (
|
||||
t > Number.MIN_SAFE_INTEGER
|
||||
|| r < Number.MAX_SAFE_INTEGER
|
||||
|| b < Number.MAX_SAFE_INTEGER
|
||||
|| l > Number.MIN_SAFE_INTEGER
|
||||
) {
|
||||
result = result.filter(n => {
|
||||
return n.topBoundary() >= t && n.rightBoundary() <= r && n.bottomBoundary() <= b && n.leftBoundary() >= l
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -353,25 +337,25 @@ export default class Blueprint extends IElement {
|
||||
getLinks(a = null, b = null) {
|
||||
if ((a == null) != (b == null)) {
|
||||
const pin = a ?? b
|
||||
return this.links.filter(link => link.source == pin || link.destination == pin)
|
||||
return this.links.filter(link => link.origin == pin || link.target == pin)
|
||||
}
|
||||
if (a != null && b != null) {
|
||||
return this.links.filter(link =>
|
||||
link.source == a && link.destination == b
|
||||
|| link.source == b && link.destination == a
|
||||
link.origin == a && link.target == b
|
||||
|| link.origin == b && link.target == a
|
||||
)
|
||||
}
|
||||
return this.links
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PinElement} sourcePin
|
||||
* @param {PinElement} destinationPin
|
||||
* @param {PinElement} originPin
|
||||
* @param {PinElement} targetPin
|
||||
*/
|
||||
getLink(sourcePin, destinationPin, strictDirection = false) {
|
||||
getLink(originPin, targetPin, strictDirection = false) {
|
||||
return this.links.find(link =>
|
||||
link.source == sourcePin && link.destination == destinationPin
|
||||
|| !strictDirection && link.source == destinationPin && link.destination == sourcePin
|
||||
link.origin == originPin && link.target == targetPin
|
||||
|| !strictDirection && link.origin == targetPin && link.target == originPin
|
||||
)
|
||||
}
|
||||
|
||||
@@ -383,6 +367,22 @@ export default class Blueprint extends IElement {
|
||||
this.getNodes().forEach(node => Blueprint.nodeSelectToggleFunction(node, false))
|
||||
}
|
||||
|
||||
getSerializedText() {
|
||||
const nodes = this.blueprint.getNodes(true).map(n => n.entity)
|
||||
let exports = false
|
||||
let result = nodes
|
||||
.filter(n => {
|
||||
exports ||= n.exported
|
||||
return !n.exported
|
||||
})
|
||||
.reduce((acc, cur) => acc + cur.serialize(), "")
|
||||
if (exports) {
|
||||
const object = new NiagaraClipboardContent(this.blueprint.entity, nodes)
|
||||
result = object.serialize() + result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** @param {...IElement} graphElements */
|
||||
addGraphElement(...graphElements) {
|
||||
/** @param {CustomEvent} event */
|
||||
@@ -409,17 +409,22 @@ export default class Blueprint extends IElement {
|
||||
for (const element of graphElements) {
|
||||
element.blueprint = this
|
||||
if (element instanceof NodeElement && !this.nodes.includes(element)) {
|
||||
const name = element.entity.getObjectName()
|
||||
this.entity.updateNameIndex(name)
|
||||
if (element.getType() == Configuration.paths.niagaraClipboardContent) {
|
||||
this.entity = this.entity.mergeWith(element.entity)
|
||||
const additionalSerialization = atob(element.entity.ExportedNodes)
|
||||
this.template.getPasteInputObject().pasted(additionalSerialization)
|
||||
.forEach(node => node.entity._exported = true)
|
||||
const additionalSerialization = atob(element.entity.ExportedNodes?.toString() ?? "")
|
||||
if (additionalSerialization) {
|
||||
this.template.getPasteInputObject().pasted(additionalSerialization)
|
||||
.forEach(node => node.entity.exported = true)
|
||||
}
|
||||
continue
|
||||
}
|
||||
const name = element.entity.getObjectName()
|
||||
const homonym = this.entity.getHomonymObjectEntity(element.entity)
|
||||
if (homonym) {
|
||||
homonym.Name = this.entity.takeFreeName(name)
|
||||
const newName = this.entity.takeFreeName(name)
|
||||
// @ts-expect-error
|
||||
homonym.Name = new (homonym.Name.constructor)(newName)
|
||||
}
|
||||
this.nodes.push(element)
|
||||
this.entity.addObjectEntity(element.entity)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { css } from "lit"
|
||||
|
||||
export default class Configuration {
|
||||
static VERSION = "2.0.0"
|
||||
static nodeColors = {
|
||||
black: css`20, 20, 20`,
|
||||
blue: css`84, 122, 156`,
|
||||
@@ -23,7 +24,7 @@ export default class Configuration {
|
||||
static colorWindowName = "Color Picker"
|
||||
static defaultCommentHeight = 96
|
||||
static defaultCommentWidth = 400
|
||||
static distanceThreshold = 5 // px
|
||||
static distanceThreshold = 20 // px
|
||||
static dragEventName = "ueb-drag"
|
||||
static dragGeneralEventName = "ueb-drag-general"
|
||||
static edgeScrollThreshold = 50
|
||||
@@ -37,12 +38,9 @@ export default class Configuration {
|
||||
end: "blueprint-unfocus",
|
||||
}
|
||||
static fontSize = css`13px`
|
||||
static gridAxisLineColor = css`black`
|
||||
static gridExpandThreshold = 0.25 // remaining size factor threshold to cause an expansion event
|
||||
static gridLineColor = css`#353535`
|
||||
static gridLineWidth = 1 // px
|
||||
static gridSet = 8
|
||||
static gridSetLineColor = css`#161616`
|
||||
static gridShrinkThreshold = 4 // exceding size factor threshold to cause a shrink event
|
||||
static gridSize = 16 // px
|
||||
static hexColorRegex = /^\s*#(?<r>[0-9a-fA-F]{2})(?<g>[0-9a-fA-F]{2})(?<b>[0-9a-fA-F]{2})([0-9a-fA-F]{2})?|#(?<rs>[0-9a-fA-F])(?<gs>[0-9a-fA-F])(?<bs>[0-9a-fA-F])\s*$/
|
||||
@@ -79,9 +77,13 @@ export default class Configuration {
|
||||
* @param {Number} c1
|
||||
* @param {Number} c2
|
||||
*/
|
||||
static linkRightSVGPath = (start, c1, c2) => {
|
||||
let end = 100 - start
|
||||
return `M ${start} 0 C ${c1.toFixed(3)} 0, ${c2.toFixed(3)} 0, 50 50 S ${(end - c1 + start).toFixed(3)} 100, `
|
||||
static linkRightSVGPath = (start, c1, c2, arc = false) => {
|
||||
const end = 100 - start
|
||||
const mid = arc
|
||||
? 50 + (c2 - start)
|
||||
: 50
|
||||
const fin = arc ? end + c1 - start : end - c1 + start
|
||||
return `M ${start} 0 C ${c1.toFixed(2)} 0, ${c2.toFixed(2)} 0, ${mid.toFixed(2)} 50 S ${fin.toFixed(2)} 100, `
|
||||
+ `${end.toFixed(3)} 100`
|
||||
}
|
||||
static maxZoom = 7
|
||||
@@ -106,6 +108,7 @@ export default class Configuration {
|
||||
callArrayFunction: "/Script/BlueprintGraph.K2Node_CallArrayFunction",
|
||||
callDelegate: "/Script/BlueprintGraph.K2Node_CallDelegate",
|
||||
callFunction: "/Script/BlueprintGraph.K2Node_CallFunction",
|
||||
clearDelegate: "/Script/BlueprintGraph.K2Node_ClearDelegate",
|
||||
comment: "/Script/UnrealEd.EdGraphNode_Comment",
|
||||
commutativeAssociativeBinaryOperator: "/Script/BlueprintGraph.K2Node_CommutativeAssociativeBinaryOperator",
|
||||
componentBoundEvent: "/Script/BlueprintGraph.K2Node_ComponentBoundEvent",
|
||||
@@ -128,6 +131,7 @@ export default class Configuration {
|
||||
eTextureMipValueMode: "/Script/Engine.ETextureMipValueMode",
|
||||
eTraceTypeQuery: "/Script/Engine.ETraceTypeQuery",
|
||||
event: "/Script/BlueprintGraph.K2Node_Event",
|
||||
eWorldPositionIncludedOffsets: "/Script/Engine.EWorldPositionIncludedOffsets",
|
||||
executionSequence: "/Script/BlueprintGraph.K2Node_ExecutionSequence",
|
||||
flipflop: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:FlipFlop",
|
||||
forEachElementInEnum: "/Script/BlueprintGraph.K2Node_ForEachElementInEnum",
|
||||
@@ -166,20 +170,26 @@ export default class Configuration {
|
||||
materialExpressionLogarithm2: "/Script/Engine.MaterialExpressionLogarithm2",
|
||||
materialExpressionMaterialFunctionCall: "/Script/Engine.MaterialExpressionMaterialFunctionCall",
|
||||
materialExpressionSquareRoot: "/Script/Engine.MaterialExpressionSquareRoot",
|
||||
materialExpressionSubtract: "/Script/Engine.MaterialExpressionSubtract",
|
||||
materialExpressionTextureCoordinate: "/Script/Engine.MaterialExpressionTextureCoordinate",
|
||||
materialExpressionTextureSample: "/Script/Engine.MaterialExpressionTextureSample",
|
||||
materialExpressionWorldPosition: "/Script/Engine.MaterialExpressionWorldPosition",
|
||||
materialGraphNode: "/Script/UnrealEd.MaterialGraphNode",
|
||||
materialGraphNodeComment: "/Script/UnrealEd.MaterialGraphNode_Comment",
|
||||
metasoundEditorGraphExternalNode: "/Script/MetasoundEditor.MetasoundEditorGraphExternalNode",
|
||||
multiGate: "/Script/BlueprintGraph.K2Node_MultiGate",
|
||||
niagaraBool: "/Script/Niagara.NiagaraBool",
|
||||
niagaraClipboardContent: "/Script/NiagaraEditor.NiagaraClipboardContent",
|
||||
niagaraDataInterfaceCollisionQuery: "/Script/Niagara.NiagaraDataInterfaceCollisionQuery",
|
||||
niagaraDataInterfaceCurlNoise: "/Script/Niagara.NiagaraDataInterfaceCurlNoise",
|
||||
niagaraDataInterfaceVolumeTexture: "/Script/Niagara.NiagaraDataInterfaceVolumeTexture",
|
||||
niagaraFloat: "/Script/Niagara.NiagaraFloat",
|
||||
niagaraMatrix: "/Script/Niagara.NiagaraMatrix",
|
||||
niagaraInt32: "/Script/Niagara.NiagaraInt32",
|
||||
niagaraNodeConvert: "/Script/NiagaraEditor.NiagaraNodeConvert",
|
||||
niagaraNodeFunctionCall: "/Script/NiagaraEditor.NiagaraNodeFunctionCall",
|
||||
niagaraNodeInput: "/Script/NiagaraEditor.NiagaraNodeInput",
|
||||
niagaraNodeOp: "/Script/NiagaraEditor.NiagaraNodeOp",
|
||||
niagaraNumeric: "/Script/Niagara.NiagaraNumeric",
|
||||
niagaraParameterMap: "/Script/Niagara.NiagaraParameterMap",
|
||||
niagaraPosition: "/Script/Niagara.NiagaraPosition",
|
||||
pawn: "/Script/Engine.Pawn",
|
||||
pcgEditorGraphNode: "/Script/PCGEditor.PCGEditorGraphNode",
|
||||
@@ -189,6 +199,7 @@ export default class Configuration {
|
||||
pcgSubgraphSettings: "/Script/PCG.PCGSubgraphSettings",
|
||||
promotableOperator: "/Script/BlueprintGraph.K2Node_PromotableOperator",
|
||||
quat4f: "/Script/CoreUObject.Quat4f",
|
||||
removeDelegate: "/Script/BlueprintGraph.K2Node_RemoveDelegate",
|
||||
reverseForEachLoop: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:ReverseForEachLoop",
|
||||
rotator: "/Script/CoreUObject.Rotator",
|
||||
select: "/Script/BlueprintGraph.K2Node_Select",
|
||||
@@ -208,11 +219,12 @@ export default class Configuration {
|
||||
variableSet: "/Script/BlueprintGraph.K2Node_VariableSet",
|
||||
vector: "/Script/CoreUObject.Vector",
|
||||
vector2D: "/Script/CoreUObject.Vector2D",
|
||||
vector2f: "/Script/CoreUObject.Vector2f",
|
||||
vector3f: "/Script/CoreUObject.Vector3f",
|
||||
vector4f: "/Script/CoreUObject.Vector4f",
|
||||
whileLoop: "/Engine/EditorBlueprintResources/StandardMacros.StandardMacros:WhileLoop",
|
||||
}
|
||||
static pinInputWrapWidth = 143 // px
|
||||
static pinInputWrapWidth = 145 // px
|
||||
static removeEventName = "ueb-element-delete"
|
||||
static scale = {
|
||||
[-12]: 0.133333,
|
||||
@@ -237,7 +249,7 @@ export default class Configuration {
|
||||
7: 2,
|
||||
}
|
||||
static smoothScrollTime = 1000 // ms
|
||||
static stringEscapedCharacters = /["\\]/g
|
||||
static stringEscapedCharacters = /["\\]/g // Try to remove
|
||||
static subObjectAttributeNamePrefix = "#SubObject"
|
||||
/** @param {ObjectEntity} objectEntity */
|
||||
static subObjectAttributeNameFromEntity = (objectEntity, nameOnly = false) =>
|
||||
@@ -253,7 +265,7 @@ export default class Configuration {
|
||||
begin: "ueb-tracking-mouse-begin",
|
||||
end: "ueb-tracking-mouse-end",
|
||||
}
|
||||
static unescapedBackslash = /(?<=(?:[^\\]|^)(?:\\\\)*)\\(?!\\)/
|
||||
static unescapedBackslash = /(?<=(?:[^\\]|^)(?:\\\\)*)\\(?!\\)/ // Try to remove
|
||||
static windowApplyEventName = "ueb-window-apply"
|
||||
static windowApplyButtonText = "OK"
|
||||
static windowCancelEventName = "ueb-window-cancel"
|
||||
@@ -265,6 +277,7 @@ export default class Configuration {
|
||||
"KeepWorld",
|
||||
"SnapToTarget",
|
||||
],
|
||||
[this.paths.eDrawDebugTrace]: ["None", "ForOneFrame", "ForDuration", "Persistent"],
|
||||
[this.paths.eMaterialSamplerType]: [
|
||||
"Color",
|
||||
"Grayscale",
|
||||
@@ -291,6 +304,14 @@ export default class Configuration {
|
||||
["NewEnumerator3", "A"],
|
||||
],
|
||||
[this.paths.eSamplerSourceMode]: ["From texture asset", "Shared: Wrap", "Shared: Clamp", "Hidden"],
|
||||
[this.paths.eSearchCase]: ["CaseSensitive", "IgnoreCase"],
|
||||
[this.paths.eWorldPositionIncludedOffsets]: [
|
||||
"Absolute World Position (Including Material Shader Offsets)",
|
||||
"Absolute World Position (Excluding Material Shader Offsets)",
|
||||
"Camera Relative World Position (Including Material Shader Offsets)",
|
||||
"Camera Relative World Position (Excluding Material Shader Offsets)",
|
||||
],
|
||||
[this.paths.eSearchDir]: ["FromStart", "FromEnd"],
|
||||
[this.paths.eSpawnActorCollisionHandlingMethod]: [
|
||||
["Undefined", "Default"],
|
||||
["AlwaysSpawn", "Always Spawn, Ignore Collisions"],
|
||||
@@ -298,9 +319,6 @@ export default class Configuration {
|
||||
["AdjustIfPossibleButDontSpawnIfColliding", "Try To Adjust Location, Don't Spawn If Still Colliding"],
|
||||
["DontSpawnIfColliding", "Do Not Spawn"],
|
||||
],
|
||||
[this.paths.eSearchCase]: ["CaseSensitive", "IgnoreCase"],
|
||||
[this.paths.eSearchDir]: ["FromStart", "FromEnd"],
|
||||
[this.paths.eDrawDebugTrace]: ["None", "ForOneFrame", "ForDuration", "Persistent"],
|
||||
[this.paths.eTextureMipValueMode]: [
|
||||
"None (use computed mip level)",
|
||||
"MipLevel (absolute, 0 is full resolution)",
|
||||
|
||||
9
js/SVGIcon.js
Normal file → Executable file
9
js/SVGIcon.js
Normal file → Executable file
@@ -67,7 +67,7 @@ export default class SVGIcon {
|
||||
`
|
||||
|
||||
static delegate = html`
|
||||
<svg viewBox="-2 -2 32 32" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="11" height="11" viewBox="-2 -2 32 32" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect class="ueb-pin-tofill" fill="black" width="28" height="28" rx="4" stroke="currentColor" stroke-width="5" />
|
||||
</svg>
|
||||
`
|
||||
@@ -388,6 +388,13 @@ export default class SVGIcon {
|
||||
</svg>
|
||||
`
|
||||
|
||||
static staticPin = html`
|
||||
<svg width="16" height="12" viewBox="1 0 16 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path class="ueb-pin-tofill" d="M1 7C1 4 3 1 7 1C10 1 14 3 17 6C18 7 18 7 17 8C14 11 10 13 7 13C3 13 1 10 1 7Z" fill="none" stroke="currentColor" stroke-width="2" />
|
||||
<path class="ueb-pin-tostroke" d="M 9 4 V 3.5 H 5 V 7 H 9 V 10.5 H 5 V 10" stroke="currentColor" stroke-width="2" />
|
||||
</svg>
|
||||
`
|
||||
|
||||
static switch = html`
|
||||
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect x="3" y="2" width="6" height="2" fill="white" />
|
||||
|
||||
0
js/Shortcuts.js
Normal file → Executable file
0
js/Shortcuts.js
Normal file → Executable file
@@ -2,31 +2,6 @@ import Configuration from "./Configuration.js"
|
||||
|
||||
export default class Utility {
|
||||
|
||||
static booleanConverter = {
|
||||
fromAttribute: (value, type) => {
|
||||
value ? "true" : "false"
|
||||
},
|
||||
toAttribute: (value, type) => {
|
||||
if (value === true) {
|
||||
return "true"
|
||||
}
|
||||
if (value === false) {
|
||||
return "false"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {Number} x */
|
||||
static sigmoid(x, curvature = 1.7) {
|
||||
return 1 / (1 + (x / (1 - x) ** -curvature))
|
||||
}
|
||||
|
||||
/** @param {Number} x */
|
||||
static sigmoidPositive(x, curvature = 3.7, length = 1.1) {
|
||||
return 1 - Math.exp(-((x / length) ** curvature))
|
||||
}
|
||||
|
||||
/** @param {Number} value */
|
||||
static clamp(value, min = -Infinity, max = Infinity) {
|
||||
return Math.min(Math.max(value, min), max)
|
||||
@@ -52,23 +27,6 @@ export default class Utility {
|
||||
return num.toFixed(decimals)
|
||||
}
|
||||
|
||||
/** @param {String} value */
|
||||
static numberFromText(value = "") {
|
||||
value = value.toLowerCase()
|
||||
switch (value) {
|
||||
case "zero": return 0
|
||||
case "one": return 1
|
||||
case "two": return 2
|
||||
case "three": return 3
|
||||
case "four": return 4
|
||||
case "five": return 5
|
||||
case "six": return 6
|
||||
case "seven": return 7
|
||||
case "eight": return 8
|
||||
case "nine": return 9
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} num
|
||||
* @param {Number} decimals
|
||||
@@ -78,16 +36,6 @@ export default class Utility {
|
||||
return Math.round(num * power) / power
|
||||
}
|
||||
|
||||
/** @param {Number} num */
|
||||
static printNumber(num) {
|
||||
if (num == Number.POSITIVE_INFINITY) {
|
||||
return "inf"
|
||||
} else if (num == Number.NEGATIVE_INFINITY) {
|
||||
return "-inf"
|
||||
}
|
||||
return Utility.minDecimals(num)
|
||||
}
|
||||
|
||||
/** @param {Number} num */
|
||||
static printExponential(num) {
|
||||
if (num == Number.POSITIVE_INFINITY) {
|
||||
@@ -132,7 +80,7 @@ export default class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Attribute} entity
|
||||
* @param {IEntity} entity
|
||||
* @param {String} key
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
@@ -199,29 +147,31 @@ export default class Utility {
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Array<T>} a
|
||||
* @param {Array<T>} b
|
||||
* @param {T[]} reference
|
||||
* @param {T[]} additional
|
||||
* @param {(v: T) => void} adding - Process added element
|
||||
* @param {(l: T, r: T) => Boolean} predicate
|
||||
* @returns {T[]}
|
||||
*/
|
||||
static mergeArrays(a = [], b = [], predicate = (l, r) => l == r) {
|
||||
static mergeArrays(reference = [], additional = [], predicate = (l, r) => l == r, adding = v => { }) {
|
||||
let result = []
|
||||
a = [...a]
|
||||
b = [...b]
|
||||
reference = [...reference]
|
||||
additional = [...additional]
|
||||
restart:
|
||||
while (true) {
|
||||
for (let j = 0; j < b.length; ++j) {
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (predicate(a[i], b[j])) {
|
||||
for (let j = 0; j < additional.length; ++j) {
|
||||
for (let i = 0; i < reference.length; ++i) {
|
||||
if (predicate(reference[i], additional[j])) {
|
||||
// Found an element in common in the two arrays
|
||||
result.push(
|
||||
// Take and append all the elements skipped from a
|
||||
...a.splice(0, i),
|
||||
...reference.splice(0, i),
|
||||
// Take and append all the elements skippend from b
|
||||
...b.splice(0, j),
|
||||
...additional.splice(0, j).map(v => (adding(v), v)),
|
||||
// Take and append the element in common
|
||||
...a.splice(0, 1)
|
||||
...reference.splice(0, 1)
|
||||
)
|
||||
b.shift() // Remove the same element from b
|
||||
additional.shift() // Remove the same element from b
|
||||
continue restart
|
||||
}
|
||||
}
|
||||
@@ -229,7 +179,13 @@ export default class Utility {
|
||||
break restart
|
||||
}
|
||||
// Append remaining the elements in the arrays and make it unique
|
||||
return [...(new Set(result.concat(...a, ...b)))]
|
||||
result.push(...reference)
|
||||
result.push(
|
||||
...additional
|
||||
.filter(vb => !result.some(vr => predicate(vr, vb)))
|
||||
.map((v, k) => (adding(v), v))
|
||||
)
|
||||
return result
|
||||
}
|
||||
|
||||
/** @param {String} value */
|
||||
@@ -307,11 +263,6 @@ export default class Utility {
|
||||
return pathValue.match(regex)?.[1] ?? ""
|
||||
}
|
||||
|
||||
/** @param {LinearColorEntity} value */
|
||||
static printLinearColor(value) {
|
||||
return `${Math.round(value.R.valueOf() * 255)}, ${Math.round(value.G.valueOf() * 255)}, ${Math.round(value.B.valueOf() * 255)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
|
||||
0
js/action/RemoveAllNodes.js
Normal file → Executable file
0
js/action/RemoveAllNodes.js
Normal file → Executable file
25
js/decoding/nodeColor.js
Normal file → Executable file
25
js/decoding/nodeColor.js
Normal file → Executable file
@@ -8,19 +8,27 @@ export default function nodeColor(entity) {
|
||||
case Configuration.paths.materialExpressionConstant3Vector:
|
||||
case Configuration.paths.materialExpressionConstant4Vector:
|
||||
return Configuration.nodeColors.yellow
|
||||
case Configuration.paths.materialExpressionFunctionInput:
|
||||
case Configuration.paths.materialExpressionTextureCoordinate:
|
||||
case Configuration.paths.materialExpressionWorldPosition:
|
||||
case Configuration.paths.pcgEditorGraphNodeInput:
|
||||
case Configuration.paths.pcgEditorGraphNodeOutput:
|
||||
return Configuration.nodeColors.red
|
||||
case Configuration.paths.makeStruct:
|
||||
return Configuration.nodeColors.darkBlue
|
||||
case Configuration.paths.materialExpressionMaterialFunctionCall:
|
||||
return Configuration.nodeColors.blue
|
||||
case Configuration.paths.materialExpressionFunctionInput:
|
||||
return Configuration.nodeColors.red
|
||||
case Configuration.paths.materialExpressionTextureSample:
|
||||
return Configuration.nodeColors.darkTurquoise
|
||||
case Configuration.paths.materialExpressionTextureCoordinate:
|
||||
return Configuration.nodeColors.red
|
||||
case Configuration.paths.pcgEditorGraphNodeInput:
|
||||
case Configuration.paths.pcgEditorGraphNodeOutput:
|
||||
return Configuration.nodeColors.red
|
||||
case Configuration.paths.niagaraNodeInput:
|
||||
switch (entity["Usage"]?.toString()) {
|
||||
case "Attribute": return Configuration.nodeColors.intenseGreen
|
||||
case "Parameter": return Configuration.nodeColors.red
|
||||
case "RapidIterationParameter": return Configuration.nodeColors.black
|
||||
case "SystemConstant": return Configuration.nodeColors.gray
|
||||
case "TranslatorConstant": return Configuration.nodeColors.gray
|
||||
default: return Configuration.nodeColors.red
|
||||
}
|
||||
}
|
||||
switch (entity.getClass()) {
|
||||
case Configuration.paths.callFunction:
|
||||
@@ -77,5 +85,8 @@ export default function nodeColor(entity) {
|
||||
if (entity.bIsPureFunc?.valueOf()) {
|
||||
return Configuration.nodeColors.green
|
||||
}
|
||||
if (entity["Input"]?.["Name"]) {
|
||||
return Configuration.nodeColors.gray
|
||||
}
|
||||
return Configuration.nodeColors.blue
|
||||
}
|
||||
|
||||
2
js/decoding/nodeIcon.js
Normal file → Executable file
2
js/decoding/nodeIcon.js
Normal file → Executable file
@@ -11,9 +11,11 @@ export default function nodeIcon(entity) {
|
||||
case Configuration.paths.addDelegate:
|
||||
case Configuration.paths.asyncAction:
|
||||
case Configuration.paths.callDelegate:
|
||||
case Configuration.paths.clearDelegate:
|
||||
case Configuration.paths.createDelegate:
|
||||
case Configuration.paths.functionEntry:
|
||||
case Configuration.paths.functionResult:
|
||||
case Configuration.paths.removeDelegate:
|
||||
return SVGIcon.node
|
||||
case Configuration.paths.customEvent: return SVGIcon.event
|
||||
case Configuration.paths.doN: return SVGIcon.doN
|
||||
|
||||
27
js/decoding/nodeSubtitle.js
Executable file
27
js/decoding/nodeSubtitle.js
Executable file
@@ -0,0 +1,27 @@
|
||||
import Configuration from "../Configuration.js"
|
||||
import Utility from "../Utility.js"
|
||||
import pinTitle from "./pinTitle.js"
|
||||
|
||||
/**
|
||||
* @param {ObjectEntity} entity
|
||||
* @returns {String?}
|
||||
*/
|
||||
export default function nodeSubtitle(entity) {
|
||||
switch (entity.getType()) {
|
||||
case Configuration.paths.addDelegate:
|
||||
case Configuration.paths.clearDelegate:
|
||||
case Configuration.paths.callDelegate:
|
||||
case Configuration.paths.removeDelegate:
|
||||
return null
|
||||
}
|
||||
const targetPin = entity
|
||||
.getPinEntities()
|
||||
.find(pin => !pin.isHidden() && pin.PinName?.toString() === "self" && pinTitle(pin) === "Target")
|
||||
if (targetPin) {
|
||||
const target = entity.FunctionReference?.MemberParent?.getName()
|
||||
?? targetPin.PinType?.PinSubCategoryObject?.getName()
|
||||
?? "Untitled"
|
||||
return target.length > 0 ? `Target is ${Utility.formatStringName(target)}` : null
|
||||
}
|
||||
return null
|
||||
}
|
||||
112
js/decoding/nodeTemplate.js
Normal file → Executable file
112
js/decoding/nodeTemplate.js
Normal file → Executable file
@@ -9,22 +9,86 @@ import VariableAccessNodeTemplate from "../template/node/VariableAccessNodeTempl
|
||||
import VariableConversionNodeTemplate from "../template/node/VariableConversionNodeTemplate.js"
|
||||
import VariableOperationNodeTemplate from "../template/node/VariableOperationNodeTemplate.js"
|
||||
|
||||
const niagaraOperationNodes = [
|
||||
"Boolean::LogicEq",
|
||||
"Boolean::LogicNEq",
|
||||
"Integer::EnumNEq",
|
||||
"Integer::EnumEq",
|
||||
...[
|
||||
"Abs",
|
||||
"Add",
|
||||
"ArcCosine(Degrees)",
|
||||
"ArcCosine(Radians)",
|
||||
"ArcSine(Degrees)",
|
||||
"ArcSine(Radians)",
|
||||
"ArcTangent(Degrees)",
|
||||
"ArcTangent(Radians)",
|
||||
"Ceil",
|
||||
"CmpEQ",
|
||||
"CmpGE",
|
||||
"CmpGT",
|
||||
"CmpLE",
|
||||
"CmpLT",
|
||||
"CmpNEQ",
|
||||
"Cosine(Degrees)",
|
||||
"Cosine(Radians)",
|
||||
"DegreesToRadians",
|
||||
"Div",
|
||||
"Dot",
|
||||
"Exp",
|
||||
"Exp2",
|
||||
"Floor",
|
||||
"FMod",
|
||||
"Frac",
|
||||
"Length",
|
||||
"Lerp",
|
||||
"Log",
|
||||
"Log2",
|
||||
"Madd",
|
||||
"Max",
|
||||
"Min",
|
||||
"Mul",
|
||||
"Negate",
|
||||
"Normalize",
|
||||
"OneMinus",
|
||||
"PI",
|
||||
"RadiansToDegrees",
|
||||
"Rcp",
|
||||
"RcpFast",
|
||||
"Round",
|
||||
"RSqrt",
|
||||
"Sign",
|
||||
"Sine(Degrees)",
|
||||
"Sine(Radians)",
|
||||
"Sqrt",
|
||||
"Step",
|
||||
"Subtract",
|
||||
"Tangent(Degrees)",
|
||||
"Tangent(Radians)",
|
||||
"Trunc",
|
||||
"TWO_PI",
|
||||
].map(v => "Numeric::" + v),
|
||||
"Vector3::Cross",
|
||||
]
|
||||
|
||||
const paths = Configuration.paths
|
||||
|
||||
/**
|
||||
* @param {ObjectEntity} nodeEntity
|
||||
* @return {new () => NodeTemplate}
|
||||
*/
|
||||
export default function nodeTemplateClass(nodeEntity) {
|
||||
if (
|
||||
nodeEntity.getClass() === Configuration.paths.callFunction
|
||||
|| nodeEntity.getClass() === Configuration.paths.commutativeAssociativeBinaryOperator
|
||||
|| nodeEntity.getClass() === Configuration.paths.callArrayFunction
|
||||
nodeEntity.getClass() === paths.callFunction
|
||||
|| nodeEntity.getClass() === paths.commutativeAssociativeBinaryOperator
|
||||
|| nodeEntity.getClass() === paths.callArrayFunction
|
||||
) {
|
||||
const memberParent = nodeEntity.FunctionReference?.MemberParent?.path ?? ""
|
||||
const memberName = nodeEntity.FunctionReference?.MemberName?.valueOf()
|
||||
const memberName = nodeEntity.FunctionReference?.MemberName?.toString()
|
||||
if (
|
||||
memberName && (
|
||||
memberParent === Configuration.paths.kismetMathLibrary
|
||||
|| memberParent === Configuration.paths.kismetArrayLibrary
|
||||
memberParent === paths.kismetMathLibrary
|
||||
|| memberParent === paths.kismetArrayLibrary
|
||||
)) {
|
||||
if (memberName.startsWith("Conv_")) {
|
||||
return VariableConversionNodeTemplate
|
||||
@@ -77,45 +141,37 @@ export default function nodeTemplateClass(nodeEntity) {
|
||||
return VariableOperationNodeTemplate
|
||||
}
|
||||
}
|
||||
if (memberParent === Configuration.paths.blueprintSetLibrary) {
|
||||
if (memberParent === paths.blueprintSetLibrary) {
|
||||
return VariableOperationNodeTemplate
|
||||
}
|
||||
if (memberParent === Configuration.paths.blueprintMapLibrary) {
|
||||
if (memberParent === paths.blueprintMapLibrary) {
|
||||
return VariableOperationNodeTemplate
|
||||
}
|
||||
}
|
||||
switch (nodeEntity.getClass()) {
|
||||
case Configuration.paths.comment:
|
||||
case Configuration.paths.materialGraphNodeComment:
|
||||
case paths.comment:
|
||||
case paths.materialGraphNodeComment:
|
||||
return CommentNodeTemplate
|
||||
case Configuration.paths.createDelegate:
|
||||
case paths.createDelegate:
|
||||
return NodeTemplate
|
||||
case Configuration.paths.metasoundEditorGraphExternalNode:
|
||||
case paths.metasoundEditorGraphExternalNode:
|
||||
if (nodeEntity["ClassName"]?.["Name"] == "Add") {
|
||||
return MetasoundOperationTemplate
|
||||
}
|
||||
return MetasoundNodeTemplate
|
||||
case Configuration.paths.niagaraNodeOp:
|
||||
if (
|
||||
[
|
||||
"Boolean::LogicEq",
|
||||
"Boolean::LogicNEq",
|
||||
"Numeric::Abs",
|
||||
"Numeric::Add",
|
||||
"Numeric::Mul",
|
||||
].includes(nodeEntity.OpName?.valueOf())
|
||||
) {
|
||||
case paths.niagaraNodeOp:
|
||||
if (niagaraOperationNodes.includes(nodeEntity.OpName?.toString())) {
|
||||
return VariableOperationNodeTemplate
|
||||
}
|
||||
break
|
||||
case Configuration.paths.promotableOperator:
|
||||
case paths.promotableOperator:
|
||||
return VariableOperationNodeTemplate
|
||||
case Configuration.paths.knot:
|
||||
case paths.knot:
|
||||
return KnotNodeTemplate
|
||||
case Configuration.paths.literal:
|
||||
case Configuration.paths.self:
|
||||
case Configuration.paths.variableGet:
|
||||
case Configuration.paths.variableSet:
|
||||
case paths.literal:
|
||||
case paths.self:
|
||||
case paths.variableGet:
|
||||
case paths.variableSet:
|
||||
return VariableAccessNodeTemplate
|
||||
}
|
||||
if (nodeEntity.isEvent()) {
|
||||
|
||||
292
js/decoding/nodeTitle.js
Normal file → Executable file
292
js/decoding/nodeTitle.js
Normal file → Executable file
@@ -5,6 +5,7 @@ import LinearColorEntity from "../entity/LinearColorEntity.js"
|
||||
import MirroredEntity from "../entity/MirroredEntity.js"
|
||||
import VectorEntity from "../entity/VectorEntity.js"
|
||||
|
||||
const paths = Configuration.paths
|
||||
const sequencerScriptingNameRegex = /\/Script\/SequencerScripting\.MovieSceneScripting(.+)Channel/
|
||||
const keyNameValue = {
|
||||
"A_AccentGrave": "à",
|
||||
@@ -34,6 +35,83 @@ const keyNameValue = {
|
||||
"Subtract": "Num -",
|
||||
"Tilde": "`",
|
||||
}
|
||||
const niagaraNodeNames = {
|
||||
"Boolean::LogicAnd": "Logic AND",
|
||||
"Boolean::LogicEq": "==",
|
||||
"Boolean::LogicNEq": "!=",
|
||||
"Boolean::LogicNot": "Logic NOT",
|
||||
"Boolean::LogicOr": "Logic OR",
|
||||
"Integer::BitAnd": "Bitwise AND",
|
||||
"Integer::BitLShift": "Bitwise Left Shift",
|
||||
"Integer::BitNot": "Bitwise NOT",
|
||||
"Integer::BitOr": "Bitwise OR",
|
||||
"Integer::BitRShift": "Bitwise Right Shift",
|
||||
"Integer::BitXOr": "Bitwise XOR",
|
||||
"Integer::EnumEq": "==",
|
||||
"Integer::EnumNEq": "!=",
|
||||
"Matrix::MatrixMultiply": "Multiply (Matrix * Matrix)",
|
||||
"Matrix::MatrixVectorMultiply": "Multiply (Matrix * Vector4)",
|
||||
// Numeric::
|
||||
...Object.fromEntries(Object.entries({
|
||||
"Add": "+",
|
||||
"ArcCosine": "ArcCosine",
|
||||
"ArcCosine(Degrees)": "ArcCos(D)",
|
||||
"ArcCosine(Radians)": "ArcCos(R)",
|
||||
"ArcSine": "ArcSine",
|
||||
"ArcSine(Degrees)": "ArcSin(D)",
|
||||
"ArcSine(Radians)": "ArcSin(R)",
|
||||
"ArcTangent(Degrees)": "ArcTan(D)",
|
||||
"ArcTangent(Radians)": "ArcTan(R)",
|
||||
"CmpEQ": "==",
|
||||
"CmpGE": ">=",
|
||||
"CmpGT": ">",
|
||||
"CmpLE": "<=",
|
||||
"CmpLT": "<",
|
||||
"CmpNEQ": "!=",
|
||||
"Cosine(Degrees)": "Cos(D)",
|
||||
"Cosine(Radians)": "Cos(R)",
|
||||
"DegreesToRadians": "DegToRad",
|
||||
"DistancePos": "Distance",
|
||||
"Div": String.fromCharCode(0x00f7),
|
||||
"FMod": "%",
|
||||
"FModFast": "Modulo Fast",
|
||||
"Length": "Len",
|
||||
"Madd": `(A${String.fromCharCode(0x2a2f)}B)+C`,
|
||||
"Mul": String.fromCharCode(0x2a2f),
|
||||
"Negate": "-A",
|
||||
"OneMinus": "1-A",
|
||||
"PI": String.fromCharCode(0x03C0),
|
||||
"RadiansToDegrees": "RadToDeg",
|
||||
"Rand Float": "Random Float",
|
||||
"Rand Integer": "Random Integer",
|
||||
"Rand": "Random",
|
||||
"Rcp": "Reciprocal",
|
||||
"RSqrt": "Rcp Sqrt",
|
||||
"Sine(Degrees)": "Sin(D)",
|
||||
"Sine(Radians)": "Sin(R)",
|
||||
"Subtract": "-",
|
||||
"Tangent(Degrees)": "Tan(D)",
|
||||
"Tangent(Radians)": "Tan(R)",
|
||||
"TWO_PI": `2 ${String.fromCharCode(0x03C0)}`,
|
||||
}).map(([k, v]) => ["Numeric::" + k, v])),
|
||||
}
|
||||
|
||||
/** @param {String} value */
|
||||
function numberFromText(value = "") {
|
||||
value = value.toLowerCase()
|
||||
switch (value) {
|
||||
case "zero": return 0
|
||||
case "one": return 1
|
||||
case "two": return 2
|
||||
case "three": return 3
|
||||
case "four": return 4
|
||||
case "five": return 5
|
||||
case "six": return 6
|
||||
case "seven": return 7
|
||||
case "eight": return 8
|
||||
case "nine": return 9
|
||||
}
|
||||
}
|
||||
|
||||
function keyName(value) {
|
||||
/** @type {String} */
|
||||
@@ -41,114 +119,134 @@ function keyName(value) {
|
||||
if (result) {
|
||||
return result
|
||||
}
|
||||
result = Utility.numberFromText(value)?.toString()
|
||||
result = numberFromText(value)?.toString()
|
||||
if (result) {
|
||||
return result
|
||||
}
|
||||
const match = value.match(/NumPad([a-zA-Z]+)/)
|
||||
if (match) {
|
||||
result = Utility.numberFromText(match[1]).toString()
|
||||
result = numberFromText(match[1]).toString()
|
||||
if (result) {
|
||||
return "Num " + result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {ObjectEntity} entity */
|
||||
/**
|
||||
* @param {ObjectEntity} entity
|
||||
* @returns {String}
|
||||
*/
|
||||
export default function nodeTitle(entity) {
|
||||
let input
|
||||
let value
|
||||
switch (entity.getType()) {
|
||||
case Configuration.paths.asyncAction:
|
||||
case paths.addDelegate:
|
||||
value ??= "Bind Event to "
|
||||
case paths.clearDelegate:
|
||||
value ??= "Unbind all Events from "
|
||||
case paths.removeDelegate:
|
||||
value ??= "Unbind Event from "
|
||||
return value + Utility.formatStringName(
|
||||
entity.DelegateReference?.MemberName?.toString().replace(/Delegate$/, "") ?? "None"
|
||||
)
|
||||
case paths.asyncAction:
|
||||
if (entity.ProxyFactoryFunctionName) {
|
||||
return Utility.formatStringName(entity.ProxyFactoryFunctionName?.valueOf())
|
||||
return Utility.formatStringName(entity.ProxyFactoryFunctionName?.toString())
|
||||
}
|
||||
case Configuration.paths.actorBoundEvent:
|
||||
case Configuration.paths.componentBoundEvent:
|
||||
return `${Utility.formatStringName(entity.DelegatePropertyName?.valueOf())} (${entity.ComponentPropertyName?.valueOf() ?? "Unknown"})`
|
||||
case Configuration.paths.callDelegate:
|
||||
return `Call ${entity.DelegateReference?.MemberName?.valueOf() ?? "None"}`
|
||||
case Configuration.paths.createDelegate:
|
||||
case paths.actorBoundEvent:
|
||||
case paths.componentBoundEvent:
|
||||
return `${Utility.formatStringName(entity.DelegatePropertyName?.toString())} (${entity.ComponentPropertyName?.toString() ?? "Unknown"})`
|
||||
case paths.callDelegate:
|
||||
return `Call ${entity.DelegateReference?.MemberName?.toString() ?? "None"}`
|
||||
case paths.createDelegate:
|
||||
return "Create Event"
|
||||
case Configuration.paths.customEvent:
|
||||
case paths.customEvent:
|
||||
if (entity.CustomFunctionName) {
|
||||
return entity.CustomFunctionName?.valueOf()
|
||||
return entity.CustomFunctionName?.toString()
|
||||
}
|
||||
case Configuration.paths.dynamicCast:
|
||||
case paths.dynamicCast:
|
||||
if (!entity.TargetType) {
|
||||
return "Bad cast node" // Target type not found
|
||||
}
|
||||
return `Cast To ${entity.TargetType?.getName()}`
|
||||
case Configuration.paths.enumLiteral:
|
||||
case paths.enumLiteral:
|
||||
return `Literal enum ${entity.Enum?.getName()}`
|
||||
case Configuration.paths.event:
|
||||
return `Event ${(entity.EventReference?.MemberName?.valueOf() ?? "").replace(/^Receive/, "")}`
|
||||
case Configuration.paths.executionSequence:
|
||||
case paths.event:
|
||||
return `Event ${(entity.EventReference?.MemberName?.toString() ?? "").replace(/^Receive/, "")}`
|
||||
case paths.executionSequence:
|
||||
return "Sequence"
|
||||
case Configuration.paths.forEachElementInEnum:
|
||||
case paths.forEachElementInEnum:
|
||||
return `For Each ${entity.Enum?.getName()}`
|
||||
case Configuration.paths.forEachLoopWithBreak:
|
||||
case paths.forEachLoopWithBreak:
|
||||
return "For Each Loop with Break"
|
||||
case Configuration.paths.functionEntry:
|
||||
return entity.FunctionReference?.MemberName?.valueOf() === "UserConstructionScript"
|
||||
case paths.functionEntry:
|
||||
return entity.FunctionReference?.MemberName?.toString() === "UserConstructionScript"
|
||||
? "Construction Script"
|
||||
: entity.FunctionReference?.MemberName?.valueOf()
|
||||
case Configuration.paths.functionResult:
|
||||
: entity.FunctionReference?.MemberName?.toString()
|
||||
case paths.functionResult:
|
||||
return "Return Node"
|
||||
case Configuration.paths.ifThenElse:
|
||||
case paths.ifThenElse:
|
||||
return "Branch"
|
||||
case Configuration.paths.makeStruct:
|
||||
case paths.makeStruct:
|
||||
if (entity.StructType) {
|
||||
return `Make ${entity.StructType.getName()}`
|
||||
}
|
||||
case Configuration.paths.materialExpressionComponentMask: {
|
||||
case paths.materialExpressionComponentMask: {
|
||||
const materialObject = entity.getMaterialSubobject()
|
||||
return `Mask ( ${Configuration.rgba
|
||||
.filter(k => /** @type {MirroredEntity<typeof BooleanEntity>} */(materialObject[k]).getter().value === true)
|
||||
.map(v => v + " ")
|
||||
.join("")})`
|
||||
if (materialObject) {
|
||||
return `Mask ( ${Configuration.rgba
|
||||
.filter(k => /** @type {MirroredEntity<typeof BooleanEntity>} */(materialObject[k]).getter().value === true)
|
||||
.map(v => v + " ")
|
||||
.join("")})`
|
||||
}
|
||||
}
|
||||
case Configuration.paths.materialExpressionConstant:
|
||||
input ??= [entity.getCustomproperties().find(pinEntity => pinEntity.PinName.valueOf() == "Value")?.DefaultValue]
|
||||
case Configuration.paths.materialExpressionConstant2Vector:
|
||||
input ??= [
|
||||
entity.getCustomproperties().find(pinEntity => pinEntity.PinName?.valueOf() == "X")?.DefaultValue,
|
||||
entity.getCustomproperties().find(pinEntity => pinEntity.PinName?.valueOf() == "Y")?.DefaultValue,
|
||||
case paths.materialExpressionConstant:
|
||||
value ??= [entity.getCustomproperties().find(pinEntity => pinEntity.PinName.toString() == "Value")?.DefaultValue]
|
||||
case paths.materialExpressionConstant2Vector:
|
||||
value ??= [
|
||||
entity.getCustomproperties().find(pinEntity => pinEntity.PinName?.toString() == "X")?.DefaultValue,
|
||||
entity.getCustomproperties().find(pinEntity => pinEntity.PinName?.toString() == "Y")?.DefaultValue,
|
||||
]
|
||||
case Configuration.paths.materialExpressionConstant3Vector:
|
||||
case Configuration.paths.materialExpressionConstant4Vector:
|
||||
if (!input) {
|
||||
case paths.materialExpressionConstant3Vector:
|
||||
case paths.materialExpressionConstant4Vector:
|
||||
if (!value) {
|
||||
const vector = entity.getCustomproperties()
|
||||
.find(pinEntity => pinEntity.PinName?.valueOf() == "Constant")
|
||||
.find(pinEntity => pinEntity.PinName?.toString() == "Constant")
|
||||
?.DefaultValue
|
||||
input = vector instanceof VectorEntity ? [vector.X, vector.Y, vector.Z].map(v => v.valueOf())
|
||||
value = vector instanceof VectorEntity ? [vector.X, vector.Y, vector.Z].map(v => v.valueOf())
|
||||
: vector instanceof LinearColorEntity ? [vector.R, vector.G, vector.B, vector.A].map(v => v.valueOf())
|
||||
: /** @type {Number[]} */([])
|
||||
}
|
||||
if (input.length > 0) {
|
||||
return input.map(v => Utility.printExponential(v)).join(",")
|
||||
if (value?.length > 0) {
|
||||
return value.map(v => Utility.printExponential(v)).join(",")
|
||||
}
|
||||
value = undefined
|
||||
break
|
||||
case Configuration.paths.materialExpressionFunctionInput: {
|
||||
case paths.materialExpressionFunctionInput: {
|
||||
const materialObject = entity.getMaterialSubobject()
|
||||
const inputName = materialObject?.InputName ?? "In"
|
||||
const inputType = materialObject?.InputType?.value.match(/^.+?_(\w+)$/)?.[1] ?? "Vector3"
|
||||
return `Input ${inputName} (${inputType})`
|
||||
}
|
||||
case Configuration.paths.materialExpressionLogarithm:
|
||||
case paths.materialExpressionLogarithm:
|
||||
return "Ln"
|
||||
case Configuration.paths.materialExpressionLogarithm10:
|
||||
case paths.materialExpressionLogarithm10:
|
||||
return "Log10"
|
||||
case Configuration.paths.materialExpressionLogarithm2:
|
||||
case paths.materialExpressionLogarithm2:
|
||||
return "Log2"
|
||||
case Configuration.paths.materialExpressionMaterialFunctionCall:
|
||||
case paths.materialExpressionMaterialFunctionCall:
|
||||
const materialFunction = entity.getMaterialSubobject()?.MaterialFunction
|
||||
if (materialFunction) {
|
||||
return materialFunction.getName()
|
||||
}
|
||||
break
|
||||
case Configuration.paths.materialExpressionSquareRoot:
|
||||
case paths.materialExpressionSquareRoot:
|
||||
return "Sqrt"
|
||||
case Configuration.paths.metasoundEditorGraphExternalNode: {
|
||||
case paths.materialExpressionSubtract:
|
||||
const materialObject = entity.getMaterialSubobject()
|
||||
if (materialObject) {
|
||||
return `Subtract(${materialObject.ConstA ?? "1"},${materialObject.ConstB ?? "1"})`
|
||||
}
|
||||
case paths.metasoundEditorGraphExternalNode: {
|
||||
const name = entity["ClassName"]?.["Name"]
|
||||
if (name) {
|
||||
switch (name) {
|
||||
@@ -157,13 +255,21 @@ export default function nodeTitle(entity) {
|
||||
}
|
||||
}
|
||||
}
|
||||
case Configuration.paths.pcgEditorGraphNodeInput:
|
||||
case paths.niagaraNodeConvert:
|
||||
/** @type {String} */
|
||||
const targetType = (entity["AutowireMakeType"]?.["ClassStructOrEnum"] ?? "")
|
||||
.toString()
|
||||
.match(/(?:Niagara)?(\w+)['"]*$/)
|
||||
?.[1]
|
||||
?? ""
|
||||
return `Make ${targetType}`
|
||||
case paths.pcgEditorGraphNodeInput:
|
||||
return "Input"
|
||||
case Configuration.paths.pcgEditorGraphNodeOutput:
|
||||
case paths.pcgEditorGraphNodeOutput:
|
||||
return "Output"
|
||||
case Configuration.paths.spawnActorFromClass:
|
||||
case paths.spawnActorFromClass:
|
||||
let className = entity.getCustomproperties()
|
||||
.find(pinEntity => pinEntity.PinName.valueOf() == "ReturnValue")
|
||||
.find(pinEntity => pinEntity.PinName.toString() == "ReturnValue")
|
||||
?.PinType
|
||||
?.PinSubCategoryObject
|
||||
?.getName()
|
||||
@@ -171,15 +277,16 @@ export default function nodeTitle(entity) {
|
||||
className = null
|
||||
}
|
||||
return `SpawnActor ${Utility.formatStringName(className ?? "NONE")}`
|
||||
case Configuration.paths.switchEnum:
|
||||
case paths.switchEnum:
|
||||
return `Switch on ${entity.Enum?.getName() ?? "Enum"}`
|
||||
case Configuration.paths.switchInteger:
|
||||
case paths.switchInteger:
|
||||
return `Switch on Int`
|
||||
case Configuration.paths.variableGet:
|
||||
case paths.variableGet:
|
||||
return ""
|
||||
case Configuration.paths.variableSet:
|
||||
case paths.variableSet:
|
||||
return "SET"
|
||||
}
|
||||
const className = entity.getClass()
|
||||
let switchTarget = entity.switchTarget()
|
||||
if (switchTarget) {
|
||||
if (switchTarget[0] !== "E") {
|
||||
@@ -188,30 +295,31 @@ export default function nodeTitle(entity) {
|
||||
return `Switch on ${switchTarget}`
|
||||
}
|
||||
if (entity.isComment()) {
|
||||
return entity.NodeComment
|
||||
return entity.NodeComment.toString()
|
||||
}
|
||||
const keyNameSymbol = entity.getHIDAttribute()
|
||||
if (keyNameSymbol) {
|
||||
const name = keyNameSymbol.toString()
|
||||
let title = keyName(name) ?? Utility.formatStringName(name)
|
||||
if (entity.getClass() === Configuration.paths.inputDebugKey) {
|
||||
if (className === paths.inputDebugKey) {
|
||||
title = "Debug Key " + title
|
||||
} else if (entity.getClass() === Configuration.paths.getInputAxisKeyValue) {
|
||||
} else if (className === paths.getInputAxisKeyValue) {
|
||||
title = "Get " + title
|
||||
}
|
||||
return title
|
||||
}
|
||||
if (entity.getClass() === Configuration.paths.macro) {
|
||||
if (className === paths.macro) {
|
||||
return Utility.formatStringName(entity.MacroGraphReference?.getMacroName())
|
||||
}
|
||||
if (entity.isMaterial() && entity.getMaterialSubobject()) {
|
||||
let result = nodeTitle(entity.getMaterialSubobject())
|
||||
const materialSubobject = entity.getMaterialSubobject()
|
||||
if (materialSubobject) {
|
||||
let result = nodeTitle(materialSubobject)
|
||||
result = result.match(/Material Expression (.+)/)?.[1] ?? result
|
||||
return result
|
||||
}
|
||||
if (entity.isPcg() && entity.getPcgSubobject()) {
|
||||
let pcgSubobject = entity.getPcgSubobject()
|
||||
let result = pcgSubobject.NodeTitle ? pcgSubobject.NodeTitle : nodeTitle(pcgSubobject)
|
||||
let result = pcgSubobject.NodeTitle ? pcgSubobject.NodeTitle.toString() : nodeTitle(pcgSubobject)
|
||||
return result
|
||||
}
|
||||
const subgraphObject = entity.getSubgraphObject()
|
||||
@@ -220,7 +328,7 @@ export default function nodeTitle(entity) {
|
||||
}
|
||||
const settingsObject = entity.getSettingsObject()
|
||||
if (settingsObject) {
|
||||
if (settingsObject.ExportPath.type === Configuration.paths.pcgHiGenGridSizeSettings) {
|
||||
if (settingsObject.ExportPath?.valueOf()?.type === paths.pcgHiGenGridSizeSettings) {
|
||||
return `Grid Size: ${(
|
||||
settingsObject.HiGenGridSize?.toString().match(/\d+/)?.[0]?.concat("00")
|
||||
?? settingsObject.HiGenGridSize?.toString().match(/^\w+$/)?.[0]
|
||||
@@ -230,7 +338,7 @@ export default function nodeTitle(entity) {
|
||||
return Utility.formatStringName(settingsObject.BlueprintElementType.getName())
|
||||
}
|
||||
if (settingsObject.Operation) {
|
||||
const match = settingsObject.Name?.valueOf().match(/PCGMetadata(\w+)Settings_\d+/)
|
||||
const match = settingsObject.Name?.toString().match(/PCGMetadata(\w+)Settings_\d+/)
|
||||
if (match) {
|
||||
return Utility.formatStringName(match[1] + ": " + settingsObject.Operation)
|
||||
}
|
||||
@@ -240,9 +348,9 @@ export default function nodeTitle(entity) {
|
||||
return settingsSubgraphObject.Graph.getName()
|
||||
}
|
||||
}
|
||||
let memberName = entity.FunctionReference?.MemberName?.valueOf()
|
||||
let memberName = entity.FunctionReference?.MemberName?.toString()
|
||||
if (memberName) {
|
||||
const memberParent = entity.FunctionReference.MemberParent?.path?.valueOf() ?? ""
|
||||
const memberParent = entity.FunctionReference.MemberParent?.path ?? ""
|
||||
switch (memberName) {
|
||||
case "AddKey":
|
||||
let result = memberParent.match(sequencerScriptingNameRegex)
|
||||
@@ -262,10 +370,10 @@ export default function nodeTitle(entity) {
|
||||
)
|
||||
}
|
||||
switch (memberParent) {
|
||||
case Configuration.paths.blueprintGameplayTagLibrary:
|
||||
case Configuration.paths.kismetMathLibrary:
|
||||
case Configuration.paths.slateBlueprintLibrary:
|
||||
case Configuration.paths.timeManagementBlueprintLibrary:
|
||||
case paths.blueprintGameplayTagLibrary:
|
||||
case paths.kismetMathLibrary:
|
||||
case paths.slateBlueprintLibrary:
|
||||
case paths.timeManagementBlueprintLibrary:
|
||||
const leadingLetter = memberName.match(/[BF]([A-Z]\w+)/)
|
||||
if (leadingLetter) {
|
||||
// Some functions start with B or F (Like FCeil, FMax, BMin)
|
||||
@@ -349,7 +457,7 @@ export default function nodeTitle(entity) {
|
||||
return "^"
|
||||
}
|
||||
break
|
||||
case Configuration.paths.blueprintSetLibrary:
|
||||
case paths.blueprintSetLibrary:
|
||||
{
|
||||
const setOperationMatch = memberName.match(/Set_(\w+)/)
|
||||
if (setOperationMatch) {
|
||||
@@ -357,7 +465,7 @@ export default function nodeTitle(entity) {
|
||||
}
|
||||
}
|
||||
break
|
||||
case Configuration.paths.blueprintMapLibrary:
|
||||
case paths.blueprintMapLibrary:
|
||||
{
|
||||
const setOperationMatch = memberName.match(/Map_(\w+)/)
|
||||
if (setOperationMatch) {
|
||||
@@ -365,7 +473,7 @@ export default function nodeTitle(entity) {
|
||||
}
|
||||
}
|
||||
break
|
||||
case Configuration.paths.kismetArrayLibrary:
|
||||
case paths.kismetArrayLibrary:
|
||||
{
|
||||
const arrayOperationMath = memberName.match(/Array_(\w+)/)
|
||||
if (arrayOperationMath) {
|
||||
@@ -377,26 +485,24 @@ export default function nodeTitle(entity) {
|
||||
return Utility.formatStringName(memberName)
|
||||
}
|
||||
if (entity.OpName) {
|
||||
switch (entity.OpName.valueOf()) {
|
||||
case "Boolean::LogicAnd": return "Logic AND"
|
||||
case "Boolean::LogicEq": return "=="
|
||||
case "Boolean::LogicNEq": return "!="
|
||||
case "Boolean::LogicNot": return "Logic NOT"
|
||||
case "Boolean::LogicOr": return "Logic OR"
|
||||
case "Matrix::MatrixMultiply": return "Multiply (Matrix * Matrix)"
|
||||
case "Matrix::MatrixVectorMultiply": return "Multiply (Matrix * Vector4)"
|
||||
case "Numeric::Abs": return "Abs"
|
||||
case "Numeric::Add": return "+"
|
||||
case "Numeric::DistancePos": return "Distance"
|
||||
case "Numeric::Mul": return String.fromCharCode(0x2a2f)
|
||||
}
|
||||
return Utility.formatStringName(entity.OpName.valueOf()).replaceAll("::", " ")
|
||||
return niagaraNodeNames[entity.OpName.toString()]
|
||||
?? Utility.formatStringName(entity.OpName.toString().replaceAll(/(?:^\w+(?<!^Matrix))?::/g, " "))
|
||||
}
|
||||
if (entity.FunctionDisplayName) {
|
||||
return Utility.formatStringName(entity.FunctionDisplayName.valueOf())
|
||||
return Utility.formatStringName(entity.FunctionDisplayName.toString())
|
||||
}
|
||||
if (entity.ObjectRef) {
|
||||
return entity.ObjectRef.getName()
|
||||
}
|
||||
let prefix
|
||||
if (
|
||||
className.startsWith(prefix = "/Script/NiagaraEditor.NiagaraNodeParameter")
|
||||
|| className.startsWith(prefix = "/Script/NiagaraEditor.NiagaraNode")
|
||||
) {
|
||||
return entity["Input"]?.["Name"]?.toString() ?? Utility.formatStringName(className.substring(prefix.length))
|
||||
}
|
||||
if (entity.ParameterName) {
|
||||
return entity.ParameterName.toString()
|
||||
}
|
||||
return Utility.formatStringName(entity.getNameAndCounter()[0])
|
||||
}
|
||||
|
||||
22
js/decoding/nodeVariadic.js
Normal file → Executable file
22
js/decoding/nodeVariadic.js
Normal file → Executable file
@@ -7,7 +7,7 @@ import StringEntity from "../entity/StringEntity.js"
|
||||
|
||||
/** @param {PinEntity} pinEntity */
|
||||
const indexFromUpperCaseLetterName = pinEntity =>
|
||||
pinEntity.PinName?.valueOf().match(/^\s*([A-Z])\s*$/)?.[1]?.charCodeAt(0) - "A".charCodeAt(0)
|
||||
pinEntity.PinName?.toString().match(/^\s*([A-Z])\s*$/)?.[1]?.charCodeAt(0) - "A".charCodeAt(0)
|
||||
|
||||
/** @param {ObjectEntity} entity */
|
||||
export default function nodeVariadic(entity) {
|
||||
@@ -18,11 +18,12 @@ export default function nodeVariadic(entity) {
|
||||
/** @type {(newPinIndex: Number, minIndex: Number, maxIndex: Number, newPin: PinEntity) => String} */
|
||||
let pinNameFromIndex
|
||||
const type = entity.getType()
|
||||
let prefix
|
||||
let name
|
||||
switch (type) {
|
||||
case Configuration.paths.commutativeAssociativeBinaryOperator:
|
||||
case Configuration.paths.promotableOperator:
|
||||
name = entity.FunctionReference?.MemberName?.valueOf()
|
||||
name = entity.FunctionReference?.MemberName?.toString()
|
||||
switch (name) {
|
||||
default:
|
||||
if (
|
||||
@@ -59,11 +60,16 @@ export default function nodeVariadic(entity) {
|
||||
break
|
||||
}
|
||||
break
|
||||
case Configuration.paths.executionSequence:
|
||||
prefix ??= "Then"
|
||||
case Configuration.paths.multiGate:
|
||||
prefix ??= "Out"
|
||||
pinEntities ??= () => entity.getPinEntities().filter(pinEntity => pinEntity.isOutput())
|
||||
pinIndexFromEntity ??= pinEntity => Number(pinEntity.PinName?.valueOf().match(/^\s*Out[_\s]+(\d+)\s*$/i)?.[1])
|
||||
pinIndexFromEntity ??= pinEntity => Number(
|
||||
pinEntity.PinName?.toString().match(new RegExp(String.raw`^\s*${prefix}[_\s]+(\d+)\s*$`, "i"))?.[1]
|
||||
)
|
||||
pinNameFromIndex ??= (index, min = -1, max = -1, newPin) =>
|
||||
`Out ${index >= 0 ? index : min > 0 ? "Out 0" : max + 1}`
|
||||
`${prefix} ${index >= 0 ? index : min > 0 ? `${prefix} 0` : max + 1}`
|
||||
break
|
||||
// case Configuration.paths.niagaraNodeOp:
|
||||
// pinEntities ??= () => entity.getPinEntities().filter(pinEntity => pinEntity.isInput())
|
||||
@@ -77,7 +83,7 @@ export default function nodeVariadic(entity) {
|
||||
// break
|
||||
case Configuration.paths.switchInteger:
|
||||
pinEntities ??= () => entity.getPinEntities().filter(pinEntity => pinEntity.isOutput())
|
||||
pinIndexFromEntity ??= pinEntity => Number(pinEntity.PinName?.valueOf().match(/^\s*(\d+)\s*$/)?.[1])
|
||||
pinIndexFromEntity ??= pinEntity => Number(pinEntity.PinName?.toString().match(/^\s*(\d+)\s*$/)?.[1])
|
||||
pinNameFromIndex ??= (index, min = -1, max = -1, newPin) => (index < 0 ? max + 1 : index).toString()
|
||||
break
|
||||
case Configuration.paths.switchGameplayTag:
|
||||
@@ -92,7 +98,7 @@ export default function nodeVariadic(entity) {
|
||||
case Configuration.paths.switchName:
|
||||
case Configuration.paths.switchString:
|
||||
pinEntities ??= () => entity.getPinEntities().filter(pinEntity => pinEntity.isOutput())
|
||||
pinIndexFromEntity ??= pinEntity => Number(pinEntity.PinName.valueOf().match(/^\s*Case[_\s]+(\d+)\s*$/i)?.[1])
|
||||
pinIndexFromEntity ??= pinEntity => Number(pinEntity.PinName.toString().match(/^\s*Case[_\s]+(\d+)\s*$/i)?.[1])
|
||||
pinNameFromIndex ??= (index, min = -1, max = -1, newPin) => {
|
||||
const result = `Case_${index >= 0 ? index : min > 0 ? "0" : max + 1}`
|
||||
entity.PinNames ??= new ArrayEntity()
|
||||
@@ -144,6 +150,10 @@ export default function nodeVariadic(entity) {
|
||||
newPin.PinId = new GuidEntity()
|
||||
newPin.PinName = new StringEntity(pinNameFromIndex(index, min, max, newPin))
|
||||
newPin.PinToolTip = undefined
|
||||
if (newPin.DefaultValue) {
|
||||
// @ts-expect-error
|
||||
newPin.DefaultValue = new (newPin.DefaultValue.constructor)()
|
||||
}
|
||||
entity.getCustomproperties(true).push(newPin)
|
||||
return newPin
|
||||
}
|
||||
|
||||
58
js/decoding/pinColor.js
Normal file → Executable file
58
js/decoding/pinColor.js
Normal file → Executable file
@@ -2,24 +2,12 @@ import { css } from "lit"
|
||||
import Configuration from "../Configuration.js"
|
||||
|
||||
const colors = {
|
||||
[Configuration.paths.niagaraBool]: css`146, 0, 0`,
|
||||
[Configuration.paths.niagaraDataInterfaceVolumeTexture]: css`0, 168, 242`,
|
||||
[Configuration.paths.niagaraFloat]: css`160, 250, 68`,
|
||||
[Configuration.paths.niagaraMatrix]: css`0, 88, 200`,
|
||||
[Configuration.paths.niagaraNumeric]: css`0, 88, 200`,
|
||||
[Configuration.paths.niagaraPosition]: css`251, 146, 251`,
|
||||
[Configuration.paths.quat4f]: css`0, 88, 200`,
|
||||
[Configuration.paths.rotator]: css`157, 177, 251`,
|
||||
[Configuration.paths.transform]: css`227, 103, 0`,
|
||||
[Configuration.paths.vector]: css`251, 198, 34`,
|
||||
[Configuration.paths.vector3f]: css`250, 200, 36`,
|
||||
[Configuration.paths.vector4f]: css`0, 88, 200`,
|
||||
"Any": css`132, 132, 132`,
|
||||
"Any[]": css`132, 132, 132`,
|
||||
"audio": css`252, 148, 252`,
|
||||
"blue": css`0, 0, 255`,
|
||||
"bool": css`146, 0, 0`,
|
||||
"byte": css`0, 109, 99`,
|
||||
"byte": css`0, 110, 100`,
|
||||
"class": css`88, 0, 186`,
|
||||
"default": css`255, 255, 255`,
|
||||
"delegate": css`255, 56, 56`,
|
||||
@@ -27,16 +15,16 @@ const colors = {
|
||||
"exec": css`240, 240, 240`,
|
||||
"float": css`160, 252, 70`,
|
||||
"green": css`0, 255, 0`,
|
||||
"int": css`31, 224, 172`,
|
||||
"int": css`30, 224, 172`,
|
||||
"int32": css`30, 224, 172`,
|
||||
"int64": css`169, 223, 172`,
|
||||
"int64": css`170, 224, 172`,
|
||||
"interface": css`238, 252, 168`,
|
||||
"name": css`201, 128, 251`,
|
||||
"name": css`200, 128, 252`,
|
||||
"object": css`0, 168, 242`,
|
||||
"Param": css`255, 166, 39`,
|
||||
"Param[]": css`255, 166, 39`,
|
||||
"Point": css`63, 137, 255`,
|
||||
"Point[]": css`63, 137, 255`,
|
||||
"Param": css`255, 166, 40`,
|
||||
"Param[]": css`255, 166, 40`,
|
||||
"Point": css`64, 138, 255`,
|
||||
"Point[]": css`64, 137, 255`,
|
||||
"real": css`54, 208, 0`,
|
||||
"red": css`255, 0, 0`,
|
||||
"string": css`251, 0, 208`,
|
||||
@@ -48,21 +36,37 @@ const colors = {
|
||||
"Volume": css`230, 69, 188`,
|
||||
"Volume[]": css`230, 69, 188`,
|
||||
"wildcard": css`128, 120, 120`,
|
||||
[Configuration.paths.linearColor]: css`0, 88, 200`,
|
||||
[Configuration.paths.niagaraBool]: css`146, 0, 0`,
|
||||
[Configuration.paths.niagaraDataInterfaceCollisionQuery]: css`0, 168, 242`,
|
||||
[Configuration.paths.niagaraDataInterfaceCurlNoise]: css`0, 168, 242`,
|
||||
[Configuration.paths.niagaraDataInterfaceVolumeTexture]: css`0, 168, 242`,
|
||||
[Configuration.paths.niagaraFloat]: css`160, 250, 68`,
|
||||
[Configuration.paths.niagaraInt32]: css`30, 224, 172`,
|
||||
[Configuration.paths.niagaraPosition]: css`251, 146, 251`,
|
||||
[Configuration.paths.quat4f]: css`0, 88, 200`,
|
||||
[Configuration.paths.rotator]: css`157, 177, 251`,
|
||||
[Configuration.paths.transform]: css`227, 103, 0`,
|
||||
[Configuration.paths.vector]: css`251, 198, 34`,
|
||||
[Configuration.paths.vector2f]: css`0, 88, 200`,
|
||||
[Configuration.paths.vector3f]: css`250, 200, 36`,
|
||||
[Configuration.paths.vector4f]: css`0, 88, 200`,
|
||||
}
|
||||
|
||||
const pinColorMaterial = css`120, 120, 120`
|
||||
|
||||
/** @param {PinEntity} entity */
|
||||
/** @param {PinEntity<IEntity>} entity */
|
||||
export default function pinColor(entity) {
|
||||
if (entity.PinType.PinCategory?.valueOf() == "mask") {
|
||||
const result = colors[entity.PinType.PinSubCategory]
|
||||
if (entity.PinType.PinCategory?.toString() === "mask") {
|
||||
const result = colors[entity.PinType.PinSubCategory?.toString()]
|
||||
if (result) {
|
||||
return result
|
||||
}
|
||||
} else if (entity.PinType.PinCategory?.valueOf() == "optional") {
|
||||
} else if (entity.PinType.PinCategory?.toString() === "optional") {
|
||||
return pinColorMaterial
|
||||
}
|
||||
return colors[entity.getType()]
|
||||
?? colors[entity.PinType.PinCategory?.valueOf().toLowerCase()]
|
||||
?? colors["default"]
|
||||
const type = entity.getType()
|
||||
return colors[type]
|
||||
?? colors[entity.PinType.PinCategory?.toString().toLowerCase()]
|
||||
?? (type.startsWith("/Script/Niagara.") ? colors["struct"] : colors["default"])
|
||||
}
|
||||
|
||||
31
js/decoding/pinTemplate.js
Normal file → Executable file
31
js/decoding/pinTemplate.js
Normal file → Executable file
@@ -16,36 +16,41 @@ import Vector4DPinTemplate from "../template/pin/Vector4DPinTemplate.js"
|
||||
import VectorPinTemplate from "../template/pin/VectorPinTemplate.js"
|
||||
|
||||
const inputPinTemplates = {
|
||||
[Configuration.paths.linearColor]: LinearColorPinTemplate,
|
||||
[Configuration.paths.niagaraBool]: BoolPinTemplate,
|
||||
[Configuration.paths.niagaraPosition]: VectorPinTemplate,
|
||||
[Configuration.paths.rotator]: RotatorPinTemplate,
|
||||
[Configuration.paths.vector]: VectorPinTemplate,
|
||||
[Configuration.paths.vector2D]: Vector2DPinTemplate,
|
||||
[Configuration.paths.vector3f]: VectorPinTemplate,
|
||||
[Configuration.paths.vector4f]: Vector4DPinTemplate,
|
||||
"bool": BoolPinTemplate,
|
||||
"byte": IntPinTemplate,
|
||||
"enum": EnumPinTemplate,
|
||||
"float": RealPinTemplate,
|
||||
"int": IntPinTemplate,
|
||||
"int64": Int64PinTemplate,
|
||||
"MUTABLE_REFERENCE": ReferencePinTemplate,
|
||||
"name": NamePinTemplate,
|
||||
"rg": Vector2DPinTemplate,
|
||||
"real": RealPinTemplate,
|
||||
"rg": Vector2DPinTemplate,
|
||||
"string": StringPinTemplate,
|
||||
[Configuration.paths.linearColor]: LinearColorPinTemplate,
|
||||
[Configuration.paths.niagaraBool]: BoolPinTemplate,
|
||||
[Configuration.paths.niagaraFloat]: RealPinTemplate,
|
||||
[Configuration.paths.niagaraInt32]: IntPinTemplate,
|
||||
[Configuration.paths.niagaraPosition]: VectorPinTemplate,
|
||||
[Configuration.paths.rotator]: RotatorPinTemplate,
|
||||
[Configuration.paths.vector]: VectorPinTemplate,
|
||||
[Configuration.paths.vector2D]: Vector2DPinTemplate,
|
||||
[Configuration.paths.vector2f]: Vector2DPinTemplate,
|
||||
[Configuration.paths.vector3f]: VectorPinTemplate,
|
||||
[Configuration.paths.vector4f]: Vector4DPinTemplate,
|
||||
}
|
||||
|
||||
/** @param {PinEntity} entity */
|
||||
/** @param {PinEntity<IEntity>} entity */
|
||||
export default function pinTemplate(entity) {
|
||||
if (entity.PinType.ContainerType?.valueOf() === "Array") {
|
||||
if (entity.PinType.ContainerType?.toString() === "Array") {
|
||||
return PinTemplate
|
||||
}
|
||||
if (entity.PinType.bIsReference?.valueOf() && !entity.PinType.bIsConst?.valueOf()) {
|
||||
return inputPinTemplates["MUTABLE_REFERENCE"]
|
||||
}
|
||||
if (entity.getType() === "exec") {
|
||||
if (entity.isExecution()) {
|
||||
return ExecPinTemplate
|
||||
}
|
||||
return (entity.isInput() ? inputPinTemplates[entity.getType()] : PinTemplate) ?? PinTemplate
|
||||
const type = entity.getType()
|
||||
return (entity.isInput() ? inputPinTemplates[type] : PinTemplate) ?? PinTemplate
|
||||
}
|
||||
|
||||
11
js/decoding/pinTitle.js
Normal file → Executable file
11
js/decoding/pinTitle.js
Normal file → Executable file
@@ -1,19 +1,16 @@
|
||||
import Utility from "../Utility.js"
|
||||
|
||||
/** @param {PinEntity} entity */
|
||||
/** @param {PinEntity<IEntity>} entity */
|
||||
export default function pinTitle(entity) {
|
||||
let result = entity.PinFriendlyName
|
||||
? entity.PinFriendlyName.toString()
|
||||
: Utility.formatStringName(entity.PinName?.valueOf() ?? "")
|
||||
: Utility.formatStringName(entity.PinName?.toString() ?? "")
|
||||
let match
|
||||
if (
|
||||
entity.PinToolTip
|
||||
// Match up until the first \n excluded or last character
|
||||
&& (match = entity.PinToolTip?.valueOf().match(/\s*(.+?(?=\n)|.+\S)\s*/))
|
||||
) {
|
||||
if (match = entity.PinToolTip?.toString().match(/\s*(.+?(?=\n)|.+\S)\s*/)) {
|
||||
if (match[1].toLowerCase() === result.toLowerCase()) {
|
||||
return match[1] // In case they match, then keep the case of the PinToolTip
|
||||
}
|
||||
}
|
||||
result = result.replace(/^Module\./, "")
|
||||
return result
|
||||
}
|
||||
|
||||
0
js/element/ColorHandlerElement.js
Normal file → Executable file
0
js/element/ColorHandlerElement.js
Normal file → Executable file
0
js/element/ColorSliderElement.js
Normal file → Executable file
0
js/element/ColorSliderElement.js
Normal file → Executable file
0
js/element/DropdownElement.js
Normal file → Executable file
0
js/element/DropdownElement.js
Normal file → Executable file
4
js/element/ElementFactory.js
Normal file → Executable file
4
js/element/ElementFactory.js
Normal file → Executable file
@@ -1,11 +1,11 @@
|
||||
export default class ElementFactory {
|
||||
|
||||
/** @type {Map<String, AnyConstructor<IElement>>} */
|
||||
/** @type {Map<String, IElementConstructor>} */
|
||||
static #elementConstructors = new Map()
|
||||
|
||||
/**
|
||||
* @param {String} tagName
|
||||
* @param {AnyConstructor<IElement>} entityConstructor
|
||||
* @param {IElementConstructor} entityConstructor
|
||||
*/
|
||||
static registerElement(tagName, entityConstructor) {
|
||||
ElementFactory.#elementConstructors.set(tagName, entityConstructor)
|
||||
|
||||
0
js/element/IDraggableControlElement.js
Normal file → Executable file
0
js/element/IDraggableControlElement.js
Normal file → Executable file
0
js/element/IDraggableElement.js
Normal file → Executable file
0
js/element/IDraggableElement.js
Normal file → Executable file
0
js/element/IElement.js
Normal file → Executable file
0
js/element/IElement.js
Normal file → Executable file
36
js/element/IFromToPositionedElement.js
Normal file → Executable file
36
js/element/IFromToPositionedElement.js
Normal file → Executable file
@@ -9,19 +9,19 @@ export default class IFromToPositionedElement extends IElement {
|
||||
|
||||
static properties = {
|
||||
...super.properties,
|
||||
fromX: {
|
||||
originX: {
|
||||
type: Number,
|
||||
attribute: false,
|
||||
},
|
||||
fromY: {
|
||||
originY: {
|
||||
type: Number,
|
||||
attribute: false,
|
||||
},
|
||||
toX: {
|
||||
targetX: {
|
||||
type: Number,
|
||||
attribute: false,
|
||||
},
|
||||
toY: {
|
||||
targetY: {
|
||||
type: Number,
|
||||
attribute: false,
|
||||
},
|
||||
@@ -29,35 +29,35 @@ export default class IFromToPositionedElement extends IElement {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.fromX = 0
|
||||
this.fromY = 0
|
||||
this.toX = 0
|
||||
this.toY = 0
|
||||
this.originX = 0
|
||||
this.originY = 0
|
||||
this.targetX = 0
|
||||
this.targetY = 0
|
||||
}
|
||||
|
||||
/** @param {Coordinates} param0 */
|
||||
setBothLocations([x, y]) {
|
||||
this.fromX = x
|
||||
this.fromY = y
|
||||
this.toX = x
|
||||
this.toY = y
|
||||
this.originX = x
|
||||
this.originY = y
|
||||
this.targetX = x
|
||||
this.targetY = y
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
addSourceLocation(x, y) {
|
||||
this.fromX += x
|
||||
this.fromY += y
|
||||
addOriginLocation(x, y) {
|
||||
this.originX += x
|
||||
this.originY += y
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
addDestinationLocation(x, y) {
|
||||
this.toX += x
|
||||
this.toY += y
|
||||
addTargetLocation(x, y) {
|
||||
this.targetX += x
|
||||
this.targetY += y
|
||||
}
|
||||
}
|
||||
|
||||
4
js/element/ISelectableDraggableElement.js
Normal file → Executable file
4
js/element/ISelectableDraggableElement.js
Normal file → Executable file
@@ -1,5 +1,5 @@
|
||||
import Configuration from "../Configuration.js"
|
||||
import Utility from "../Utility.js"
|
||||
import BooleanEntity from "../entity/BooleanEntity.js"
|
||||
import IDraggableElement from "./IDraggableElement.js"
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ export default class ISelectableDraggableElement extends IDraggableElement {
|
||||
type: Boolean,
|
||||
attribute: "data-selected",
|
||||
reflect: true,
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
10
js/element/InputElement.js
Normal file → Executable file
10
js/element/InputElement.js
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
import IElement from "./IElement.js"
|
||||
import BooleanEntity from "../entity/BooleanEntity.js"
|
||||
import InputTemplate from "../template/pin/InputTemplate.js"
|
||||
import Utility from "../Utility.js"
|
||||
import IElement from "./IElement.js"
|
||||
|
||||
/** @extends {IElement<Object, InputTemplate>} */
|
||||
export default class InputElement extends IElement {
|
||||
@@ -10,19 +10,19 @@ export default class InputElement extends IElement {
|
||||
singleLine: {
|
||||
type: Boolean,
|
||||
attribute: "data-single-line",
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
reflect: true,
|
||||
},
|
||||
selectOnFocus: {
|
||||
type: Boolean,
|
||||
attribute: "data-select-focus",
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
reflect: true,
|
||||
},
|
||||
blurOnEnter: {
|
||||
type: Boolean,
|
||||
attribute: "data-blur-enter",
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
reflect: true,
|
||||
},
|
||||
}
|
||||
|
||||
224
js/element/LinkElement.js
Normal file → Executable file
224
js/element/LinkElement.js
Normal file → Executable file
@@ -1,9 +1,10 @@
|
||||
import { html, nothing } from "lit"
|
||||
import Configuration from "../Configuration.js"
|
||||
import IFromToPositionedElement from "./IFromToPositionedElement.js"
|
||||
import LinkTemplate from "../template/LinkTemplate.js"
|
||||
import SVGIcon from "../SVGIcon.js"
|
||||
import Utility from "../Utility.js"
|
||||
import BooleanEntity from "../entity/BooleanEntity.js"
|
||||
import LinkTemplate from "../template/LinkTemplate.js"
|
||||
import IFromToPositionedElement from "./IFromToPositionedElement.js"
|
||||
|
||||
/** @extends {IFromToPositionedElement<Object, LinkTemplate>} */
|
||||
export default class LinkElement extends IFromToPositionedElement {
|
||||
@@ -13,12 +14,34 @@ export default class LinkElement extends IFromToPositionedElement {
|
||||
dragging: {
|
||||
type: Boolean,
|
||||
attribute: "data-dragging",
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
reflect: true,
|
||||
},
|
||||
originNode: {
|
||||
type: String,
|
||||
attribute: "data-origin-node",
|
||||
reflect: true,
|
||||
},
|
||||
originPin: {
|
||||
type: String,
|
||||
attribute: "data-origin-pin",
|
||||
reflect: true,
|
||||
},
|
||||
targetNode: {
|
||||
type: String,
|
||||
attribute: "data-target-node",
|
||||
reflect: true,
|
||||
},
|
||||
targetPin: {
|
||||
type: String,
|
||||
attribute: "data-target-pin",
|
||||
reflect: true,
|
||||
},
|
||||
originatesFromInput: {
|
||||
type: Boolean,
|
||||
attribute: false,
|
||||
attribute: "data-from-input",
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
reflect: true,
|
||||
},
|
||||
svgPathD: {
|
||||
type: String,
|
||||
@@ -35,30 +58,35 @@ export default class LinkElement extends IFromToPositionedElement {
|
||||
}
|
||||
|
||||
/** @type {PinElement} */
|
||||
#source
|
||||
get source() {
|
||||
return this.#source
|
||||
#origin
|
||||
get origin() {
|
||||
return this.#origin
|
||||
}
|
||||
set source(pin) {
|
||||
set origin(pin) {
|
||||
this.#setPin(pin, false)
|
||||
}
|
||||
|
||||
/** @type {PinElement} */
|
||||
#destination
|
||||
get destination() {
|
||||
return this.#destination
|
||||
#target
|
||||
get target() {
|
||||
return this.#target
|
||||
}
|
||||
set destination(pin) {
|
||||
set target(pin) {
|
||||
this.#setPin(pin, true)
|
||||
}
|
||||
|
||||
#nodeDeleteHandler = () => this.remove()
|
||||
/** @param {UEBDragEvent} e */
|
||||
#nodeDragSourceHandler = e => this.addSourceLocation(...e.detail.value)
|
||||
#nodeDragOriginHandler = e => this.addOriginLocation(...e.detail.value)
|
||||
/** @param {UEBDragEvent} e */
|
||||
#nodeDragDestinatonHandler = e => this.addDestinationLocation(...e.detail.value)
|
||||
#nodeReflowSourceHandler = e => this.setSourceLocation()
|
||||
#nodeReflowDestinatonHandler = e => this.setDestinationLocation()
|
||||
#nodeDragTargetHandler = e => this.addTargetLocation(...e.detail.value)
|
||||
#nodeReflowOriginHandler = e => {
|
||||
if (this.origin.isKnot()) {
|
||||
this.originatesFromInput = this.origin.isInputVisually()
|
||||
}
|
||||
this.setOriginLocation()
|
||||
}
|
||||
#nodeReflowTargetHandler = e => this.setTargetLocation()
|
||||
|
||||
/** @type {TemplateResult | nothing} */
|
||||
linkMessageIcon = nothing
|
||||
@@ -71,6 +99,10 @@ export default class LinkElement extends IFromToPositionedElement {
|
||||
constructor() {
|
||||
super()
|
||||
this.dragging = false
|
||||
this.originNode = ""
|
||||
this.originPin = ""
|
||||
this.targetNode = ""
|
||||
this.targetPin = ""
|
||||
this.originatesFromInput = false
|
||||
this.startPercentage = 0
|
||||
this.svgPathD = ""
|
||||
@@ -78,44 +110,44 @@ export default class LinkElement extends IFromToPositionedElement {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PinElement} source
|
||||
* @param {PinElement?} destination
|
||||
* @param {PinElement} origin
|
||||
* @param {PinElement?} target
|
||||
*/
|
||||
static newObject(source, destination) {
|
||||
static newObject(origin, target) {
|
||||
const result = new LinkElement()
|
||||
result.initialize(source, destination)
|
||||
result.initialize(origin, target)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PinElement} source
|
||||
* @param {PinElement?} destination
|
||||
* @param {PinElement} origin
|
||||
* @param {PinElement?} target
|
||||
*/
|
||||
// @ts-expect-error
|
||||
initialize(source, destination) {
|
||||
initialize(origin, target) {
|
||||
super.initialize({}, new LinkTemplate())
|
||||
if (source) {
|
||||
this.source = source
|
||||
if (!destination) {
|
||||
this.toX = this.fromX
|
||||
this.toY = this.fromY
|
||||
if (origin) {
|
||||
this.origin = origin
|
||||
if (!target) {
|
||||
this.targetX = this.originX
|
||||
this.targetY = this.originY
|
||||
}
|
||||
}
|
||||
if (destination) {
|
||||
this.destination = destination
|
||||
if (!source) {
|
||||
this.fromX = this.toX
|
||||
this.fromY = this.toY
|
||||
if (target) {
|
||||
this.target = target
|
||||
if (!origin) {
|
||||
this.originX = this.targetX
|
||||
this.originY = this.targetY
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PinElement} pin
|
||||
* @param {Boolean} isDestinationPin
|
||||
* @param {Boolean} isTargetPin
|
||||
*/
|
||||
#setPin(pin, isDestinationPin) {
|
||||
const getCurrentPin = () => isDestinationPin ? this.destination : this.source
|
||||
#setPin(pin, isTargetPin) {
|
||||
const getCurrentPin = () => isTargetPin ? this.target : this.origin
|
||||
if (getCurrentPin() == pin) {
|
||||
return
|
||||
}
|
||||
@@ -124,115 +156,141 @@ export default class LinkElement extends IFromToPositionedElement {
|
||||
nodeElement.removeEventListener(Configuration.removeEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.removeEventListener(
|
||||
Configuration.nodeDragEventName,
|
||||
isDestinationPin ? this.#nodeDragDestinatonHandler : this.#nodeDragSourceHandler
|
||||
isTargetPin ? this.#nodeDragTargetHandler : this.#nodeDragOriginHandler
|
||||
)
|
||||
nodeElement.removeEventListener(
|
||||
Configuration.nodeReflowEventName,
|
||||
isDestinationPin ? this.#nodeReflowDestinatonHandler : this.#nodeReflowSourceHandler
|
||||
isTargetPin ? this.#nodeReflowTargetHandler : this.#nodeReflowOriginHandler
|
||||
)
|
||||
this.#unlinkPins()
|
||||
}
|
||||
isDestinationPin
|
||||
? this.#destination = pin
|
||||
: this.#source = pin
|
||||
if (isTargetPin) {
|
||||
this.#target = pin
|
||||
this.targetNode = pin?.nodeElement.nodeTitle
|
||||
this.targetPin = pin?.pinId.toString()
|
||||
} else {
|
||||
this.#origin = pin
|
||||
this.originNode = pin?.nodeElement.nodeTitle
|
||||
this.originPin = pin?.pinId.toString()
|
||||
}
|
||||
if (getCurrentPin()) {
|
||||
const nodeElement = getCurrentPin().getNodeElement()
|
||||
nodeElement.addEventListener(Configuration.removeEventName, this.#nodeDeleteHandler)
|
||||
nodeElement.addEventListener(
|
||||
Configuration.nodeDragEventName,
|
||||
isDestinationPin ? this.#nodeDragDestinatonHandler : this.#nodeDragSourceHandler
|
||||
isTargetPin ? this.#nodeDragTargetHandler : this.#nodeDragOriginHandler
|
||||
)
|
||||
nodeElement.addEventListener(
|
||||
Configuration.nodeReflowEventName,
|
||||
isDestinationPin ? this.#nodeReflowDestinatonHandler : this.#nodeReflowSourceHandler
|
||||
isTargetPin ? this.#nodeReflowTargetHandler : this.#nodeReflowOriginHandler
|
||||
)
|
||||
isDestinationPin
|
||||
? this.setDestinationLocation()
|
||||
: (this.setSourceLocation(), this.originatesFromInput = this.source.isInput())
|
||||
isTargetPin
|
||||
? this.setTargetLocation()
|
||||
: (this.setOriginLocation(), this.originatesFromInput = this.origin.isInputVisually())
|
||||
this.#linkPins()
|
||||
}
|
||||
}
|
||||
|
||||
#linkPins() {
|
||||
if (this.source && this.destination) {
|
||||
this.source.linkTo(this.destination)
|
||||
this.destination.linkTo(this.source)
|
||||
if (this.origin && this.target) {
|
||||
this.origin.linkTo(this.target)
|
||||
this.target.linkTo(this.origin)
|
||||
}
|
||||
}
|
||||
|
||||
#unlinkPins() {
|
||||
if (this.source && this.destination) {
|
||||
this.source.unlinkFrom(this.destination, false)
|
||||
this.destination.unlinkFrom(this.source, false)
|
||||
if (this.origin && this.target) {
|
||||
this.origin.unlinkFrom(this.target, false)
|
||||
this.target.unlinkFrom(this.origin, false)
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
super.cleanup()
|
||||
this.#unlinkPins()
|
||||
this.source = null
|
||||
this.destination = null
|
||||
this.origin = null
|
||||
this.target = null
|
||||
}
|
||||
|
||||
/** @param {Coordinates} location */
|
||||
setSourceLocation(location = null, canPostpone = true) {
|
||||
setOriginLocation(location = null, canPostpone = true) {
|
||||
if (location == null) {
|
||||
const self = this
|
||||
if (canPostpone && (!this.hasUpdated || !this.source.hasUpdated)) {
|
||||
Promise.all([this.updateComplete, this.source.updateComplete])
|
||||
.then(() => self.setSourceLocation(null, false))
|
||||
if (canPostpone && (!this.hasUpdated || !this.origin.hasUpdated)) {
|
||||
Promise.all([this.updateComplete, this.origin.updateComplete])
|
||||
.then(() => self.setOriginLocation(null, false))
|
||||
return
|
||||
}
|
||||
location = this.source.template.getLinkLocation()
|
||||
location = this.origin.template.getLinkLocation()
|
||||
}
|
||||
const [x, y] = location
|
||||
this.fromX = x
|
||||
this.fromY = y
|
||||
this.originX = x
|
||||
this.originY = y
|
||||
}
|
||||
|
||||
/** @param {Coordinates} location */
|
||||
setDestinationLocation(location = null, canPostpone = true) {
|
||||
setTargetLocation(location = null, canPostpone = true) {
|
||||
if (location == null) {
|
||||
const self = this
|
||||
if (canPostpone && (!this.hasUpdated || !this.destination.hasUpdated)) {
|
||||
Promise.all([this.updateComplete, this.destination.updateComplete])
|
||||
.then(() => self.setDestinationLocation(null, false))
|
||||
if (canPostpone && (!this.hasUpdated || !this.target.hasUpdated)) {
|
||||
Promise.all([this.updateComplete, this.target.updateComplete])
|
||||
.then(() => self.setTargetLocation(null, false))
|
||||
return
|
||||
}
|
||||
location = this.destination.template.getLinkLocation()
|
||||
location = this.target.template.getLinkLocation()
|
||||
}
|
||||
this.toX = location[0]
|
||||
this.toY = location[1]
|
||||
this.targetX = location[0]
|
||||
this.targetY = location[1]
|
||||
}
|
||||
|
||||
getInputPin() {
|
||||
if (this.source?.isInput()) {
|
||||
return this.source
|
||||
getInputPin(getSomething = false) {
|
||||
if (this.origin?.isInput()) {
|
||||
return this.origin
|
||||
}
|
||||
if (this.target?.isInput()) {
|
||||
return this.target
|
||||
}
|
||||
if (getSomething) {
|
||||
return this.origin ?? this.target
|
||||
}
|
||||
return this.destination
|
||||
}
|
||||
|
||||
/** @param {PinElement} pin */
|
||||
setInputPin(pin) {
|
||||
if (this.source?.isInput()) {
|
||||
this.source = pin
|
||||
if (this.origin?.isInput()) {
|
||||
this.origin = pin
|
||||
}
|
||||
this.destination = pin
|
||||
this.target = pin
|
||||
}
|
||||
|
||||
getOutputPin() {
|
||||
if (this.destination?.isOutput()) {
|
||||
return this.destination
|
||||
getOutputPin(getSomething = false) {
|
||||
if (this.origin?.isOutput()) {
|
||||
return this.origin
|
||||
}
|
||||
if (this.target?.isOutput()) {
|
||||
return this.target
|
||||
}
|
||||
if (getSomething) {
|
||||
return this.origin ?? this.target
|
||||
}
|
||||
return this.source
|
||||
}
|
||||
|
||||
/** @param {PinElement} pin */
|
||||
setOutputPin(pin) {
|
||||
if (this.destination?.isOutput()) {
|
||||
this.destination = pin
|
||||
if (this.target?.isOutput()) {
|
||||
this.target = pin
|
||||
}
|
||||
this.origin = pin
|
||||
}
|
||||
|
||||
/** @param {NodeElement} pin */
|
||||
getOtherPin(pin) {
|
||||
if (this.origin?.nodeElement === pin) {
|
||||
return this.target
|
||||
}
|
||||
if (this.target?.nodeElement === pin) {
|
||||
return this.origin
|
||||
}
|
||||
this.source = pin
|
||||
}
|
||||
|
||||
startDragging() {
|
||||
@@ -250,7 +308,7 @@ export default class LinkElement extends IFromToPositionedElement {
|
||||
|
||||
setMessageConvertType() {
|
||||
this.linkMessageIcon = SVGIcon.convert
|
||||
this.linkMessageText = html`Convert ${this.source.pinType} to ${this.destination.pinType}.`
|
||||
this.linkMessageText = html`Convert ${this.origin.pinType} to ${this.target.pinType}.`
|
||||
}
|
||||
|
||||
setMessageCorrect() {
|
||||
|
||||
31
js/element/NodeElement.js
Normal file → Executable file
31
js/element/NodeElement.js
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
import Configuration from "../Configuration.js"
|
||||
import Utility from "../Utility.js"
|
||||
import nodeTemplateClass from "../decoding/nodeTemplate.js"
|
||||
import nodeTitle from "../decoding/nodeTitle.js"
|
||||
import BooleanEntity from "../entity/BooleanEntity.js"
|
||||
import ObjectEntity from "../entity/ObjectEntity.js"
|
||||
import PinEntity from "../entity/PinEntity.js"
|
||||
import PinReferenceEntity from "../entity/PinReferenceEntity.js"
|
||||
@@ -41,7 +41,7 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
},
|
||||
pureFunction: {
|
||||
type: Boolean,
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
attribute: "data-pure-function",
|
||||
reflect: true,
|
||||
},
|
||||
@@ -99,14 +99,15 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
return result
|
||||
}
|
||||
|
||||
#redirectLinksAfterRename(name) {
|
||||
for (let sourcePinElement of this.getPinElements()) {
|
||||
for (let targetPinReference of sourcePinElement.getLinks()) {
|
||||
/** @param {String} name */
|
||||
#redirectLinksBeforeRename(name) {
|
||||
for (let originPinElement of this.getPinElements()) {
|
||||
for (let targetPinReference of originPinElement.getLinks()) {
|
||||
this.blueprint.getPin(targetPinReference).redirectLink(
|
||||
sourcePinElement,
|
||||
originPinElement,
|
||||
new PinReferenceEntity(
|
||||
name,
|
||||
sourcePinElement.entity.PinId,
|
||||
new SymbolEntity(name),
|
||||
originPinElement.entity.PinId,
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -130,11 +131,15 @@ export default class NodeElement extends ISelectableDraggableElement {
|
||||
} else {
|
||||
this.updateComplete.then(() => this.computeSizes())
|
||||
}
|
||||
entity.listenAttribute("Name", name => {
|
||||
this.nodeTitle = entity.Name
|
||||
this.nodeDisplayName = nodeTitle(entity)
|
||||
this.#redirectLinksAfterRename(name)
|
||||
})
|
||||
entity.listenAttribute(
|
||||
"Name",
|
||||
/** @param {InstanceType<typeof ObjectEntity.attributes.Name>} newName */
|
||||
newName => {
|
||||
this.#redirectLinksBeforeRename(newName?.toString())
|
||||
this.nodeTitle = newName?.toString()
|
||||
this.nodeDisplayName = nodeTitle(entity)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async getUpdateComplete() {
|
||||
|
||||
112
js/element/PinElement.js
Normal file → Executable file
112
js/element/PinElement.js
Normal file → Executable file
@@ -1,17 +1,17 @@
|
||||
import Utility from "../Utility.js"
|
||||
import Configuration from "../Configuration.js"
|
||||
import pinTemplate from "../decoding/pinTemplate.js"
|
||||
import ArrayEntity from "../entity/ArrayEntity.js"
|
||||
import BooleanEntity from "../entity/BooleanEntity.js"
|
||||
import GuidEntity from "../entity/GuidEntity.js"
|
||||
import LinearColorEntity from "../entity/LinearColorEntity.js"
|
||||
import PinEntity from "../entity/PinEntity.js"
|
||||
import PinReferenceEntity from "../entity/PinReferenceEntity.js"
|
||||
import StringEntity from "../entity/StringEntity.js"
|
||||
import SymbolEntity from "../entity/SymbolEntity.js"
|
||||
import PinTemplate from "../template/pin/PinTemplate.js"
|
||||
import ElementFactory from "./ElementFactory.js"
|
||||
import IElement from "./IElement.js"
|
||||
|
||||
/**
|
||||
* @template {TerminalAttribute} T
|
||||
* @template {IEntity} T
|
||||
* @extends {IElement<PinEntity<T>, PinTemplate>}
|
||||
*/
|
||||
export default class PinElement extends IElement {
|
||||
@@ -23,7 +23,7 @@ export default class PinElement extends IElement {
|
||||
fromAttribute: (value, type) => value
|
||||
? GuidEntity.grammar.parse(value)
|
||||
: null,
|
||||
toAttribute: (value, type) => /** @type {String} */(value?.toString()),
|
||||
toAttribute: (value, type) => value?.toString(),
|
||||
},
|
||||
attribute: "data-id",
|
||||
reflect: true,
|
||||
@@ -44,7 +44,7 @@ export default class PinElement extends IElement {
|
||||
fromAttribute: (value, type) => value
|
||||
? LinearColorEntity.getLinearColorFromAnyFormat().parse(value)
|
||||
: null,
|
||||
toAttribute: (value, type) => value ? Utility.printLinearColor(value) : null,
|
||||
toAttribute: (value, type) => value ? LinearColorEntity.printLinearColor(value) : null,
|
||||
},
|
||||
attribute: "data-color",
|
||||
reflect: true,
|
||||
@@ -55,7 +55,7 @@ export default class PinElement extends IElement {
|
||||
},
|
||||
isLinked: {
|
||||
type: Boolean,
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
attribute: "data-linked",
|
||||
reflect: true,
|
||||
},
|
||||
@@ -66,7 +66,7 @@ export default class PinElement extends IElement {
|
||||
},
|
||||
connectable: {
|
||||
type: Boolean,
|
||||
converter: Utility.booleanConverter,
|
||||
converter: BooleanEntity.booleanConverter,
|
||||
attribute: "data-connectable",
|
||||
reflect: true,
|
||||
}
|
||||
@@ -95,6 +95,7 @@ export default class PinElement extends IElement {
|
||||
this.isLinked = false
|
||||
this.connectable = !entity.bNotConnectable?.valueOf()
|
||||
super.initialize(entity, template)
|
||||
this.pinId = this.entity.PinId
|
||||
this.pinType = this.entity.getType()
|
||||
this.defaultValue = this.entity.getDefaultValue()
|
||||
this.color = PinElement.properties.color.converter.fromAttribute(this.getColor().toString())
|
||||
@@ -107,20 +108,15 @@ export default class PinElement extends IElement {
|
||||
}
|
||||
|
||||
createPinReference() {
|
||||
return new PinReferenceEntity({
|
||||
objectName: new StringEntity(this.nodeElement.getNodeName()),
|
||||
pinGuid: this.getPinId(),
|
||||
})
|
||||
return new PinReferenceEntity(new SymbolEntity(this.nodeElement.getNodeName()), this.getPinId())
|
||||
}
|
||||
|
||||
/** @return {GuidEntity} */
|
||||
getPinId() {
|
||||
return this.entity.PinId
|
||||
}
|
||||
|
||||
/** @returns {String} */
|
||||
getPinName() {
|
||||
return this.entity.PinName?.valueOf() ?? ""
|
||||
return this.entity.PinName?.toString() ?? ""
|
||||
}
|
||||
|
||||
getPinDisplayName() {
|
||||
@@ -132,16 +128,70 @@ export default class PinElement extends IElement {
|
||||
return this.entity.pinColor()
|
||||
}
|
||||
|
||||
isInput() {
|
||||
return this.entity.isInput()
|
||||
/** @param {PinElement} pin */
|
||||
#traverseKnots(pin) {
|
||||
while (pin?.isKnot()) {
|
||||
const pins = pin.nodeElement.getPinElements()
|
||||
pin = pin === pins[0] ? pins[1] : pins[0]
|
||||
pin = pin.isLinked ? this.blueprint.getPin(pin.getLinks()[0]) : null
|
||||
}
|
||||
return pin?.isKnot() ? undefined : pin
|
||||
}
|
||||
|
||||
isOutput() {
|
||||
return this.entity.isOutput()
|
||||
isInput(ignoreKnots = false) {
|
||||
/** @type {PinElement} */
|
||||
let result = this
|
||||
if (ignoreKnots) {
|
||||
return this.#traverseKnots(result)?.isInput()
|
||||
}
|
||||
return result.entity.isInput()
|
||||
}
|
||||
|
||||
getLinkLocation() {
|
||||
return this.template.getLinkLocation()
|
||||
/** @returns {boolean} True when the pin is the input part of a knot that can switch direction */
|
||||
isInputLoosely() {
|
||||
return this.isInput(false) && this.isInput(true) === undefined
|
||||
}
|
||||
|
||||
/** @returns {boolean} True when the pin is input and if it is a knot it appears input */
|
||||
isInputVisually() {
|
||||
const template = /** @type {KnotNodeTemplate} */(this.nodeElement.template)
|
||||
const isKnot = this.isKnot()
|
||||
return isKnot && this.isInput() != template.switchDirectionsVisually
|
||||
|| !isKnot && this.isInput()
|
||||
}
|
||||
|
||||
isOutput(ignoreKnots = false) {
|
||||
/** @type {PinElement} */
|
||||
let result = this
|
||||
if (ignoreKnots) {
|
||||
if (ignoreKnots) {
|
||||
return this.#traverseKnots(result)?.isOutput()
|
||||
}
|
||||
}
|
||||
return result.entity.isOutput()
|
||||
}
|
||||
|
||||
/** @returns {boolean} True when the pin is the output part of a knot that can switch direction */
|
||||
isOutputLoosely() {
|
||||
return this.isOutput(false) && this.isOutput(true) === undefined
|
||||
}
|
||||
|
||||
/** @returns {boolean} True when the pin is output and if it is a knot it appears output */
|
||||
isOutputVisually() {
|
||||
const template = /** @type {KnotNodeTemplate} */(this.nodeElement.template)
|
||||
const isKnot = this.isKnot()
|
||||
return isKnot && this.isOutput() != template.switchDirectionsVisually
|
||||
|| !isKnot && this.isOutput()
|
||||
}
|
||||
|
||||
|
||||
/** @returns {value is InstanceType<PinElement<>>} */
|
||||
isKnot() {
|
||||
return this.nodeElement?.getType() == Configuration.paths.knot
|
||||
}
|
||||
|
||||
getLinkLocation(oppositeDirection = false) {
|
||||
return this.template.getLinkLocation(oppositeDirection)
|
||||
}
|
||||
|
||||
getNodeElement() {
|
||||
@@ -167,7 +217,7 @@ export default class PinElement extends IElement {
|
||||
|
||||
/** @param {IElement[]} nodesWhitelist */
|
||||
sanitizeLinks(nodesWhitelist = []) {
|
||||
this.entity.LinkedTo = new ArrayEntity(
|
||||
this.entity.LinkedTo = new (PinEntity.attributes.LinkedTo)(
|
||||
this.entity.LinkedTo?.valueOf().filter(pinReference => {
|
||||
let pin = this.blueprint.getPin(pinReference)
|
||||
if (pin) {
|
||||
@@ -192,14 +242,16 @@ export default class PinElement extends IElement {
|
||||
const pinReference = this.createPinReference()
|
||||
if (
|
||||
this.isLinked
|
||||
&& this.isOutput()
|
||||
&& (this.pinType === "exec" || targetPinElement.pinType === "exec")
|
||||
&& !this.getLinks().some(ref => pinReference.equals(ref))) {
|
||||
&& (
|
||||
this.isInput(true)
|
||||
|| this.isOutput(true) && (this.entity.isExecution() || targetPinElement.entity.isExecution())
|
||||
)
|
||||
&& !this.getLinks().some(ref => pinReference.equals(ref))
|
||||
) {
|
||||
this.unlinkFromAll()
|
||||
}
|
||||
if (this.entity.linkTo(targetPinElement.getNodeElement().getNodeName(), targetPinElement.entity)) {
|
||||
this.isLinked = this.entity.isLinked()
|
||||
this.nodeElement?.template.linksChanged()
|
||||
if (this.entity.recomputesNodeTitleOnChange) {
|
||||
this.nodeElement?.computeNodeDisplayName()
|
||||
}
|
||||
@@ -210,7 +262,6 @@ export default class PinElement extends IElement {
|
||||
unlinkFrom(targetPinElement, removeLink = true) {
|
||||
if (this.entity.unlinkFrom(targetPinElement.getNodeElement().getNodeName(), targetPinElement.entity)) {
|
||||
this.isLinked = this.entity.isLinked()
|
||||
this.nodeElement?.template.linksChanged()
|
||||
if (removeLink) {
|
||||
this.blueprint.getLink(this, targetPinElement)?.remove() // Might be called after the link is removed
|
||||
}
|
||||
@@ -223,9 +274,6 @@ export default class PinElement extends IElement {
|
||||
unlinkFromAll() {
|
||||
const isLinked = this.getLinks().length
|
||||
this.getLinks().map(ref => this.blueprint.getPin(ref)).forEach(pin => this.unlinkFrom(pin))
|
||||
if (isLinked) {
|
||||
this.nodeElement?.template.linksChanged()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,10 +283,10 @@ export default class PinElement extends IElement {
|
||||
redirectLink(originalPinElement, newReference) {
|
||||
const index = this.getLinks().findIndex(pinReference =>
|
||||
pinReference.objectName.toString() == originalPinElement.getNodeElement().getNodeName()
|
||||
&& pinReference.pinGuid.valueOf() == originalPinElement.entity.PinId.valueOf()
|
||||
&& pinReference.pinGuid.toString() == originalPinElement.entity.PinId.toString()
|
||||
)
|
||||
if (index >= 0) {
|
||||
this.entity.LinkedTo[index] = newReference
|
||||
this.entity.LinkedTo.valueOf()[index] = newReference
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
12
js/element/SelectorElement.js
Normal file → Executable file
12
js/element/SelectorElement.js
Normal file → Executable file
@@ -37,16 +37,16 @@ export default class SelectorElement extends IFromToPositionedElement {
|
||||
/** @param {Coordinates} finalPosition */
|
||||
selectTo(finalPosition) {
|
||||
this.selectionModel.selectTo(finalPosition)
|
||||
this.toX = finalPosition[0]
|
||||
this.toY = finalPosition[1]
|
||||
this.targetX = finalPosition[0]
|
||||
this.targetY = finalPosition[1]
|
||||
}
|
||||
|
||||
endSelect() {
|
||||
this.blueprint.selecting = false
|
||||
this.selectionModel = null
|
||||
this.fromX = 0
|
||||
this.fromY = 0
|
||||
this.toX = 0
|
||||
this.toY = 0
|
||||
this.originX = 0
|
||||
this.originY = 0
|
||||
this.targetX = 0
|
||||
this.targetY = 0
|
||||
}
|
||||
}
|
||||
|
||||
0
js/element/WindowElement.js
Normal file → Executable file
0
js/element/WindowElement.js
Normal file → Executable file
0
js/element/defineElements.js
Normal file → Executable file
0
js/element/defineElements.js
Normal file → Executable file
7
js/entity/AlternativesEntity.js
Normal file → Executable file
7
js/entity/AlternativesEntity.js
Normal file → Executable file
@@ -1,6 +1,7 @@
|
||||
import P from "parsernostrum"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
/** @template {(typeof IEntity)[]} T */
|
||||
export default class AlternativesEntity extends IEntity {
|
||||
|
||||
/** @type {(typeof IEntity)[]} */
|
||||
@@ -9,14 +10,14 @@ export default class AlternativesEntity extends IEntity {
|
||||
static className() {
|
||||
let result = super.className()
|
||||
if (this.alternatives.length) {
|
||||
result += " (accepting: " + this.alternatives.map(v => v.className()).join(", ") + ")"
|
||||
result += ".accepting(" + this.alternatives.map(v => v.className()).join(", ") + ")"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
static createGrammar() {
|
||||
const grammars = this.alternatives.map(entity => entity.grammar)
|
||||
if (grammars.includes(this.unknownEntityGrammar)) {
|
||||
if (this.alternatives.length == 0 || grammars.includes(this.unknownEntityGrammar)) {
|
||||
return this.unknownEntityGrammar
|
||||
}
|
||||
return P.alt(...grammars)
|
||||
@@ -27,7 +28,7 @@ export default class AlternativesEntity extends IEntity {
|
||||
* @param {Types} types
|
||||
*/
|
||||
static accepting(...types) {
|
||||
const result = /** @type {typeof AlternativesEntity & { alternatives: Types }} */(
|
||||
const result = /** @type {typeof AlternativesEntity<Types> & { alternatives: Types }} */(
|
||||
this.asUniqueClass()
|
||||
)
|
||||
result.alternatives = types
|
||||
|
||||
84
js/entity/ArrayEntity.js
Normal file → Executable file
84
js/entity/ArrayEntity.js
Normal file → Executable file
@@ -2,26 +2,24 @@ import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
/** @template {IEntity} T */
|
||||
/** @template {typeof IEntity} T */
|
||||
export default class ArrayEntity extends IEntity {
|
||||
|
||||
/** @type {typeof IEntity} */
|
||||
static type
|
||||
static grammar = /** @type {P<ArrayEntity<IEntity>>} */(
|
||||
this.createGrammar()
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
get length() {
|
||||
return this.values.length
|
||||
}
|
||||
|
||||
/** @param {T[]} values */
|
||||
/** @param {(ExtractType<T>)[]} values */
|
||||
constructor(values = []) {
|
||||
super()
|
||||
this.values = values
|
||||
}
|
||||
|
||||
/** @returns {P<ArrayEntity<IEntity>>} */
|
||||
/** @returns {P<ArrayEntity<typeof IEntity>>} */
|
||||
static createGrammar(elementGrammar = this.type?.grammar ?? P.lazy(() => this.unknownEntityGrammar)) {
|
||||
return this.inlined
|
||||
? elementGrammar
|
||||
@@ -31,18 +29,31 @@ export default class ArrayEntity extends IEntity {
|
||||
P.reg(/\s*(,\s*)?\)/, 1),
|
||||
).map(([_0, values, trailing]) => {
|
||||
values = values instanceof Array ? values : []
|
||||
const result = new this(values)
|
||||
result.trailing = trailing !== undefined
|
||||
return result
|
||||
let Self = this
|
||||
if ((trailing !== undefined) !== Self.trailing) {
|
||||
Self = Self.flagTrailing(trailing !== undefined)
|
||||
}
|
||||
return new Self(values)
|
||||
}).label(`ArrayEntity of ${this.type?.className() ?? "unknown values"}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {T}
|
||||
*/
|
||||
static flagInlined(value = true) {
|
||||
const result = this.asUniqueClass()
|
||||
result.inlined = value
|
||||
result.grammar = /** @type {P<ArrayEntity>} */(result.createGrammar())
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @param {T} type
|
||||
*/
|
||||
static of(type) {
|
||||
const result = /** @type {typeof ArrayEntity<ExtractType<T>> & {type: T, grammar: P<ArrayEntity<ExtractType<T>>> }} */(
|
||||
const result = /** @type {{type: T, grammar: P<ArrayEntity<T>> } & typeof ArrayEntity<T>} */(
|
||||
this.asUniqueClass()
|
||||
)
|
||||
result.type = type
|
||||
@@ -50,6 +61,38 @@ export default class ArrayEntity extends IEntity {
|
||||
return result
|
||||
}
|
||||
|
||||
doSerialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof ArrayEntity<T>} */(this.constructor),
|
||||
printKey = Self.printKey,
|
||||
keySeparator = Self.keySeparator,
|
||||
attributeSeparator = Self.attributeSeparator,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
if (Self.inlined) {
|
||||
return super.serialize.bind(
|
||||
this.values,
|
||||
insideString,
|
||||
indentation,
|
||||
Self,
|
||||
printKey,
|
||||
keySeparator,
|
||||
attributeSeparator,
|
||||
wrap
|
||||
)()
|
||||
}
|
||||
let result = this.values.map(v => v?.serialize(insideString)).join(Self.attributeSeparator)
|
||||
if (this.trailing) {
|
||||
result += Self.attributeSeparator
|
||||
}
|
||||
return `(${result})`
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.values
|
||||
}
|
||||
|
||||
/** @param {IEntity} other */
|
||||
equals(other) {
|
||||
if (!(other instanceof ArrayEntity) || this.values.length !== other.values.length) {
|
||||
@@ -62,25 +105,4 @@ export default class ArrayEntity extends IEntity {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.values
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
if (Self.inlined) {
|
||||
return super.toString.bind(this.values, insideString, indentation, Self, printKey, wrap)()
|
||||
}
|
||||
let result = this.values.map(v => v?.toString(insideString)).join(Self.attributeSeparator)
|
||||
if (this.trailing) {
|
||||
result += Self.attributeSeparator
|
||||
}
|
||||
return `(${result})`
|
||||
}
|
||||
}
|
||||
|
||||
135
js/entity/BlueprintEntity.js
Normal file → Executable file
135
js/entity/BlueprintEntity.js
Normal file → Executable file
@@ -1,6 +1,7 @@
|
||||
import Configuration from "../Configuration.js"
|
||||
import Utility from "../Utility.js"
|
||||
import ObjectEntity from "./ObjectEntity.js"
|
||||
import ScriptVariableEntity from "./ScriptVariableEntity.js"
|
||||
|
||||
export default class BlueprintEntity extends ObjectEntity {
|
||||
|
||||
@@ -13,9 +14,21 @@ export default class BlueprintEntity extends ObjectEntity {
|
||||
return this.#objectEntities
|
||||
}
|
||||
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
ScriptVariables: super.attributes.ScriptVariables.asUniqueClass(true).withDefault(),
|
||||
}
|
||||
|
||||
constructor(...args) {
|
||||
super(...args)
|
||||
if (!this.Name) {
|
||||
this.Name = new (/** @type {typeof ObjectEntity} */(this.constructor).attributes.Name)("Blueprint")
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {ObjectEntity} entity */
|
||||
getHomonymObjectEntity(entity) {
|
||||
const name = entity.getObjectName(false)
|
||||
const name = entity.getObjectName()
|
||||
return this.#objectEntities.find(entity => entity.getObjectName() == name)
|
||||
}
|
||||
|
||||
@@ -27,6 +40,16 @@ export default class BlueprintEntity extends ObjectEntity {
|
||||
return Configuration.nodeTitle(name, counter)
|
||||
}
|
||||
|
||||
/** @param {String} name */
|
||||
updateNameIndex(name) {
|
||||
const match = name.match(/(.+)_(\d+)$/)
|
||||
if (match) {
|
||||
name = match[1]
|
||||
const index = Number(match[2])
|
||||
this.#objectEntitiesNameCounter.set(name, Math.max(index, this.#objectEntitiesNameCounter.get(name) ?? 0))
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {ObjectEntity} entity */
|
||||
addObjectEntity(entity) {
|
||||
if (!this.#objectEntities.includes(entity)) {
|
||||
@@ -54,35 +77,121 @@ export default class BlueprintEntity extends ObjectEntity {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ObjectReferenceEntity} variable
|
||||
* @param {IEntity} entity
|
||||
*/
|
||||
renameScriptVariable(variable, entity) {
|
||||
const name = variable.getName()
|
||||
const newName = this.takeFreeName(name)
|
||||
{
|
||||
[true, false].forEach(v => {
|
||||
/** @type {ObjectEntity} */
|
||||
let object = this[Configuration.subObjectAttributeNameFromReference(variable, v)]
|
||||
object.Name.value = newName
|
||||
object.Name = object.Name
|
||||
})
|
||||
}
|
||||
variable.path.replace(name, newName)
|
||||
return newName
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ScriptVariableEntity} scriptVariableEntity
|
||||
* @returns {String}
|
||||
*/
|
||||
variableName(scriptVariableEntity) {
|
||||
return this[Configuration.subObjectAttributeNameFromReference(scriptVariableEntity.ScriptVariable, true)]
|
||||
?.["Variable"]
|
||||
?.["Name"]
|
||||
?.toString()
|
||||
}
|
||||
|
||||
/** @param {String} variableName */
|
||||
variableIndex(variableName) {
|
||||
let i = 0
|
||||
for (const v of this.ScriptVariables?.valueOf()) {
|
||||
if (variableName == this.variableName(v)) {
|
||||
return i
|
||||
}
|
||||
++i
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {ObjectEntity} entity */
|
||||
mergeWith(entity) {
|
||||
if (!entity.ScriptVariables || entity.ScriptVariables.length === 0) {
|
||||
if ((entity.ScriptVariables?.length ?? 0) === 0) {
|
||||
// The entity does not add new variables
|
||||
return this
|
||||
}
|
||||
if (!this.ScriptVariables || this.ScriptVariables.length === 0) {
|
||||
this.ScriptVariables = entity.ScriptVariables
|
||||
}
|
||||
const variableObjectNames = this.ScriptVariables.valueOf().map(v => v.ScriptVariable.getName())
|
||||
let scriptVariables = Utility.mergeArrays(
|
||||
this.ScriptVariables.valueOf(),
|
||||
entity.ScriptVariables.valueOf(),
|
||||
(l, r) => l.OriginalChangeId.value == r.OriginalChangeId.value
|
||||
(l, r) => this.variableName(l) == this.variableName(r),
|
||||
added => {
|
||||
let name = added.ScriptVariable.getName()
|
||||
if (variableObjectNames.includes(name)) {
|
||||
name = this.renameScriptVariable(added.ScriptVariable, entity)
|
||||
}
|
||||
this.updateNameIndex(name)
|
||||
}
|
||||
)
|
||||
if (scriptVariables.length === this.ScriptVariables.length) {
|
||||
// The entity does not add new variables
|
||||
return this
|
||||
}
|
||||
scriptVariables.reverse()
|
||||
const blueprintEntity = /** @type {typeof BlueprintEntity} */(this.constructor)
|
||||
const entries = scriptVariables.concat(scriptVariables).map((v, i) => {
|
||||
const name = Configuration.subObjectAttributeNameFromReference(v.ScriptVariable, i >= scriptVariables.length)
|
||||
return [
|
||||
name,
|
||||
this[name] ?? entity[name]
|
||||
]
|
||||
const name = Configuration.subObjectAttributeNameFromReference(
|
||||
v.ScriptVariable,
|
||||
i >= scriptVariables.length // First take all the small objects then all name only
|
||||
)
|
||||
const object = this[name] ?? entity[name]
|
||||
return object ? [name, object] : null
|
||||
})
|
||||
.filter(v => v)
|
||||
entries.push(
|
||||
...Object.entries(this).filter(([k, v]) =>
|
||||
!k.startsWith(Configuration.subObjectAttributeNamePrefix)
|
||||
&& k !== "ExportedNodes"
|
||||
)
|
||||
),
|
||||
["ScriptVariables", new (blueprintEntity.attributes.ScriptVariables)(scriptVariables.reverse())]
|
||||
)
|
||||
return new BlueprintEntity(Object.fromEntries(entries))
|
||||
const result = new BlueprintEntity(Object.fromEntries(entries))
|
||||
result.mirrorNameInExportPaths(entity.Name?.toString())
|
||||
result.#objectEntitiesNameCounter = this.#objectEntitiesNameCounter
|
||||
result.#objectEntities = this.#objectEntities
|
||||
return result
|
||||
}
|
||||
|
||||
/** @param {ObjectEntity[]} entities */
|
||||
getVariablesAttributesReferringTo(...entities) {
|
||||
let pins = new Set(...entities.flatMap(entity => entity.getPinEntities()).map(pin => pin.PinName.toString()))
|
||||
let attributes = this.ScriptVariables
|
||||
.valueOf()
|
||||
.map(v => {
|
||||
const keySimple = Configuration.subObjectAttributeNameFromReference(v.ScriptVariable, false)
|
||||
const keyFull = Configuration.subObjectAttributeNameFromReference(v.ScriptVariable, true)
|
||||
return {
|
||||
simple: [keySimple, this[keySimple]],
|
||||
full: [keyFull, this[keyFull]],
|
||||
variable: v,
|
||||
}
|
||||
})
|
||||
.filter(v => pins.has(v.full?.["Variable"]?.["Name"]))
|
||||
.reduce(
|
||||
(acc, cur) => {
|
||||
acc.simple.push([cur.simple[0], cur.simple[1]])
|
||||
acc.full.push([cur.full[0], cur.full[1]])
|
||||
acc.ScriptVariables.push(cur.variable)
|
||||
return acc
|
||||
},
|
||||
({ simple: [], full: [], ScriptVariables: [] })
|
||||
)
|
||||
return {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,21 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class BooleanEntity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<BooleanEntity>} */(
|
||||
P.regArray(/(true)|(True)|(false)|(False)/)
|
||||
.map(v => {
|
||||
const result = (v[1] ?? v[2]) ? new this(true) : new this(false)
|
||||
result.uppercase = (v[2] ?? v[4]) !== undefined
|
||||
return result
|
||||
})
|
||||
.label("BooleanEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
static booleanConverter = {
|
||||
fromAttribute: (value, type) => {
|
||||
value ? "true" : "false"
|
||||
},
|
||||
toAttribute: (value, type) => {
|
||||
if (value === true) {
|
||||
return "true"
|
||||
}
|
||||
if (value === false) {
|
||||
return "false"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
#uppercase = true
|
||||
get uppercase() {
|
||||
@@ -21,22 +27,37 @@ export default class BooleanEntity extends IEntity {
|
||||
this.#uppercase = value
|
||||
}
|
||||
|
||||
/** @returns {P<BooleanEntity>} */
|
||||
static createGrammar() {
|
||||
return P.regArray(/(true)|(True)|(false)|(False)/)
|
||||
.map(v => {
|
||||
const result = (v[1] ?? v[2]) ? new this(true) : new this(false)
|
||||
result.uppercase = (v[2] ?? v[4]) !== undefined
|
||||
return result
|
||||
})
|
||||
.label("BooleanEntity")
|
||||
}
|
||||
|
||||
constructor(value = false) {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor),
|
||||
) {
|
||||
let result = this.value
|
||||
? this.#uppercase ? "True" : "true"
|
||||
: this.#uppercase ? "False" : "false"
|
||||
if (Self.serialized) {
|
||||
result = `"${result}"`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value
|
||||
? this.#uppercase
|
||||
? "True"
|
||||
: "true"
|
||||
: this.#uppercase
|
||||
? "False"
|
||||
: "false"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ import IntegerEntity from "./IntegerEntity.js"
|
||||
|
||||
export default class ByteEntity extends IntegerEntity {
|
||||
|
||||
static grammar = /** @type {P<ByteEntity>} */(
|
||||
P.numberByte.map(v => new this(v))
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
get value() {
|
||||
return super.value
|
||||
@@ -16,4 +14,10 @@ export default class ByteEntity extends IntegerEntity {
|
||||
super.value = value
|
||||
}
|
||||
}
|
||||
|
||||
/** @returns {P<ByteEntity>} */
|
||||
createGrammar() {
|
||||
// @ts-expect-error
|
||||
return P.numberByte.map(v => new this(v))
|
||||
}
|
||||
}
|
||||
|
||||
23
js/entity/ColorChannelEntity.js
Normal file → Executable file
23
js/entity/ColorChannelEntity.js
Normal file → Executable file
@@ -3,20 +3,35 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class ColorChannelEntity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<ColorChannelEntity>} */(
|
||||
P.number.map(v => new this(v))
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(value = 0) {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
/** @returns {P<ColorChannelEntity>} */
|
||||
static createGrammar() {
|
||||
return P.number.map(v => new this(v))
|
||||
}
|
||||
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor),
|
||||
) {
|
||||
let result = this.value.toFixed(6)
|
||||
if (Self.serialized) {
|
||||
result = `"${result}"`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toFixed(6)
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
11
js/entity/ComputedTypeEntity.js
Normal file → Executable file
11
js/entity/ComputedTypeEntity.js
Normal file → Executable file
@@ -1,11 +1,16 @@
|
||||
import IEntity from "./IEntity.js"
|
||||
import StringEntity from "./StringEntity.js"
|
||||
|
||||
export default class ComputedTypeEntity extends IEntity {
|
||||
|
||||
static grammar = undefined
|
||||
static grammar = this.createGrammar()
|
||||
/** @type {(entity: IEntity) => typeof IEntity} */
|
||||
static f
|
||||
|
||||
static createGrammar() {
|
||||
return StringEntity.grammar
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof ComputedTypeEntity.f} T
|
||||
* @param {T} producer
|
||||
@@ -17,7 +22,7 @@ export default class ComputedTypeEntity extends IEntity {
|
||||
}
|
||||
|
||||
/** @param {IEntity} entity */
|
||||
compute(entity) {
|
||||
return /** @type {typeof ComputedTypeEntity} */(this.Self()).f(entity)
|
||||
static compute(entity) {
|
||||
return this.f(entity)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import EnumEntity from "./EnumEntity.js"
|
||||
|
||||
export default class EnumDisplayValueEntity extends EnumEntity {
|
||||
|
||||
static grammar = /** @type {P<EnumDisplayValueEntity>} */(
|
||||
P.reg(Grammar.Regex.InsideString).map(v => new this(v))
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<EnumDisplayValueEntity>} */
|
||||
static createGrammar() {
|
||||
return P.reg(Grammar.Regex.InsideString).map(v => new this(v))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import SymbolEntity from "./SymbolEntity.js"
|
||||
|
||||
export default class EnumEntity extends SymbolEntity {
|
||||
|
||||
static grammar = /** @type {P<EnumEntity>} */(
|
||||
Grammar.symbol.map(v => new this(v))
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<EnumEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.symbol.map(v => new this(v))
|
||||
}
|
||||
}
|
||||
|
||||
53
js/entity/FormatTextEntity.js
Normal file → Executable file
53
js/entity/FormatTextEntity.js
Normal file → Executable file
@@ -8,8 +8,17 @@ export default class FormatTextEntity extends IEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static lookbehind = ["LOCGEN_FORMAT_NAMED", "LOCGEN_FORMAT_ORDERED"]
|
||||
static grammar = /** @type {P<FormatTextEntity>} */(
|
||||
P.lazy(() => P.seq(
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @param {(StringEntity | LocalizedTextEntity | InvariantTextEntity | FormatTextEntity)[]} values */
|
||||
constructor(values) {
|
||||
super()
|
||||
this.values = values
|
||||
}
|
||||
|
||||
/** @returns {P<FormatTextEntity>} */
|
||||
static createGrammar() {
|
||||
return P.lazy(() => P.seq(
|
||||
// Resulting regex: /(LOCGEN_FORMAT_NAMED|LOCGEN_FORMAT_ORDERED)\s*/
|
||||
P.reg(new RegExp(String.raw`(${this.lookbehind.join("|")})\s*\(\s*`), 1),
|
||||
P.alt(
|
||||
@@ -23,16 +32,26 @@ export default class FormatTextEntity extends IEntity {
|
||||
return result
|
||||
}))
|
||||
.label("FormatTextEntity")
|
||||
)
|
||||
|
||||
/** @param {(StringEntity | LocalizedTextEntity | InvariantTextEntity | FormatTextEntity)[]} values */
|
||||
constructor(values) {
|
||||
super()
|
||||
this.values = values
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
const pattern = this.values?.[0]?.valueOf() // The pattern is always the first element of the array
|
||||
doSerialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof FormatTextEntity} */(this.constructor),
|
||||
printKey = Self.printKey,
|
||||
keySeparator = Self.keySeparator,
|
||||
attributeSeparator = Self.attributeSeparator,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
const separator = Self.attributeSeparator
|
||||
return this.lookbehind + "("
|
||||
+ this.values.map(v => v.serialize(insideString)).join(separator)
|
||||
+ (Self.trailing ? separator : "")
|
||||
+ ")"
|
||||
}
|
||||
|
||||
toString() {
|
||||
const pattern = this.values?.[0]?.toString() // The pattern is always the first element of the array
|
||||
if (!pattern) {
|
||||
return ""
|
||||
}
|
||||
@@ -54,18 +73,4 @@ export default class FormatTextEntity extends IEntity {
|
||||
: ""
|
||||
return result
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
const separator = Self.attributeSeparator
|
||||
return this.lookbehind + "("
|
||||
+ this.values.map(v => v.toString(insideString)).join(separator)
|
||||
+ (Self.trailing ? separator : "")
|
||||
+ ")"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ export default class FunctionReferenceEntity extends IEntity {
|
||||
MemberName: StringEntity,
|
||||
MemberGuid: GuidEntity,
|
||||
}
|
||||
static grammar = /** @type {P<FunctionReferenceEntity>} */(
|
||||
Grammar.createEntityGrammar(this, Grammar.commaSeparation, false, 0)
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values) {
|
||||
super(values)
|
||||
@@ -23,4 +21,9 @@ export default class FunctionReferenceEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof FunctionReferenceEntity.attributes.MemberName>} */ this.MemberName
|
||||
/** @type {InstanceType<typeof FunctionReferenceEntity.attributes.MemberGuid>} */ this.MemberGuid
|
||||
}
|
||||
|
||||
/** @returns {P<FunctionReferenceEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this, Grammar.commaSeparation, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import P from "parsernostrum"
|
||||
|
||||
var crypto
|
||||
if (typeof window === "undefined") {
|
||||
// When used in nodejs, mainly for test purpose
|
||||
import("crypto").then(mod => crypto = mod.default).catch()
|
||||
} else {
|
||||
crypto = window.crypto
|
||||
@@ -10,9 +11,7 @@ if (typeof window === "undefined") {
|
||||
|
||||
export default class GuidEntity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<GuidEntity>} */(
|
||||
P.reg(/[0-9A-F]{32}/i).map(v => new this(v)).label("GuidEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
static generateGuid() {
|
||||
let values = new Uint32Array(4)
|
||||
@@ -29,8 +28,21 @@ export default class GuidEntity extends IEntity {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
/** @returns {P<GuidEntity>} */
|
||||
static createGrammar() {
|
||||
return P.reg(/[0-9A-F]{32}/i).map(v => new this(v)).label("GuidEntity")
|
||||
}
|
||||
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor),
|
||||
) {
|
||||
let result = this.value
|
||||
if (Self.serialized) {
|
||||
result = `"${result}"`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
||||
305
js/entity/IEntity.js
Normal file → Executable file
305
js/entity/IEntity.js
Normal file → Executable file
@@ -15,8 +15,7 @@ export default class IEntity {
|
||||
static keySeparator = "="
|
||||
/** @type {(k: String) => String} */
|
||||
static printKey = k => k
|
||||
/** @type {P<IEntity>} */
|
||||
static grammar = P.lazy(() => this.unknownEntity)
|
||||
static grammar = P.lazy(() => this.createGrammar())
|
||||
/** @type {P<IEntity>} */
|
||||
static unknownEntityGrammar
|
||||
static unknownEntity
|
||||
@@ -31,26 +30,11 @@ export default class IEntity {
|
||||
static serialized = false // Value is written and read as string
|
||||
static expected = false // Must be there
|
||||
static inlined = false // The key is a subobject or array and printed as inlined (A.B=123, A(0)=123)
|
||||
static quoted = false // Key is serialized with quotes
|
||||
/** @type {Boolean} */
|
||||
static quoted // Key is serialized with quotes
|
||||
static silent = false // Do not serialize if default
|
||||
static trailing = false // Add attribute separator after the last attribute when serializing
|
||||
|
||||
#trailing = this.Self().trailing
|
||||
get trailing() {
|
||||
return this.#trailing
|
||||
}
|
||||
set trailing(value) {
|
||||
this.#trailing = value
|
||||
}
|
||||
|
||||
#lookbehind = /** @type {String} */(this.Self().lookbehind)
|
||||
get lookbehind() {
|
||||
return this.#lookbehind.trim()
|
||||
}
|
||||
set lookbehind(value) {
|
||||
this.#lookbehind = value
|
||||
}
|
||||
|
||||
/** @type {String[]} */
|
||||
#keys
|
||||
get keys() {
|
||||
@@ -60,8 +44,50 @@ export default class IEntity {
|
||||
this.#keys = [... new Set(value)]
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
#lookbehind = /** @type {String} */(this.constructor.lookbehind)
|
||||
get lookbehind() {
|
||||
return this.#lookbehind.trim()
|
||||
}
|
||||
set lookbehind(value) {
|
||||
this.#lookbehind = value
|
||||
}
|
||||
|
||||
#ignored = /** @type {typeof IEntity} */(this.constructor).ignored
|
||||
get ignored() {
|
||||
return this.#ignored
|
||||
}
|
||||
set ignored(value) {
|
||||
this.#ignored = value
|
||||
}
|
||||
|
||||
#inlined = /** @type {typeof IEntity} */(this.constructor).inlined
|
||||
get inlined() {
|
||||
return this.#inlined
|
||||
}
|
||||
set inlined(value) {
|
||||
this.#inlined = value
|
||||
}
|
||||
|
||||
#quoted
|
||||
get quoted() {
|
||||
return this.#quoted ?? /** @type {typeof IEntity} */(this.constructor).quoted ?? false
|
||||
}
|
||||
set quoted(value) {
|
||||
this.#quoted = value
|
||||
}
|
||||
|
||||
/** @type {Boolean} */
|
||||
#trailing
|
||||
get trailing() {
|
||||
return this.#trailing ?? /** @type {typeof IEntity} */(this.constructor).trailing ?? false
|
||||
}
|
||||
set trailing(value) {
|
||||
this.#trailing = value
|
||||
}
|
||||
|
||||
constructor(values = {}) {
|
||||
const attributes = this.Self().attributes
|
||||
const attributes = /** @type {typeof IEntity} */(this.constructor).attributes
|
||||
const keys = Utility.mergeArrays(
|
||||
Object.keys(values),
|
||||
Object.entries(attributes).filter(([k, v]) => v.default !== undefined).map(([k, v]) => k)
|
||||
@@ -74,7 +100,16 @@ export default class IEntity {
|
||||
attributes[key] !== undefined ? attributes[key] : IEntity.unknownEntity
|
||||
)(values[key])
|
||||
}
|
||||
const computedEntity = /** @type {ComputedTypeEntityConstructor} */(attributes[key])
|
||||
this[key] = values[key]
|
||||
if (computedEntity?.compute) {
|
||||
/** @type {typeof IEntity} */
|
||||
const actualEntity = computedEntity.compute(this)
|
||||
const parsed = actualEntity.grammar.run(values[key].toString())
|
||||
if (parsed.status) {
|
||||
this[key] = parsed.value
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
const attribute = attributes[key]
|
||||
@@ -85,12 +120,24 @@ export default class IEntity {
|
||||
}
|
||||
}
|
||||
|
||||
static className() {
|
||||
/**
|
||||
* @protected
|
||||
* @returns {P<IEntity>}
|
||||
*/
|
||||
static createGrammar() {
|
||||
return this.unknownEntityGrammar
|
||||
}
|
||||
|
||||
static actualClass() {
|
||||
let self = this
|
||||
while (!self.name) {
|
||||
self = Object.getPrototypeOf(self)
|
||||
}
|
||||
return self.name
|
||||
return self
|
||||
}
|
||||
|
||||
static className() {
|
||||
return this.actualClass().name
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,12 +146,15 @@ export default class IEntity {
|
||||
* @this {T}
|
||||
* @returns {T}
|
||||
*/
|
||||
static asUniqueClass() {
|
||||
if (this.name.length) {
|
||||
static asUniqueClass(alwaysCreate = false) {
|
||||
let result = this
|
||||
if (this.name.length || alwaysCreate) {
|
||||
// @ts-expect-error
|
||||
return class extends this { }
|
||||
result = (() => class extends this { })() // Comes from a lambda otherwise the class will have name "result"
|
||||
result.grammar = result.createGrammar() // Reassign grammar to capture the correct this from subclass
|
||||
|
||||
}
|
||||
return this
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,8 +171,10 @@ export default class IEntity {
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {T}
|
||||
* @param {(type: T) => (InstanceType<T> | NullEntity)} value
|
||||
* @returns {T}
|
||||
*/
|
||||
static withDefault(value = /** @type {(type: T) => (InstanceType<T> | NullEntity)} */(type => new type())) {
|
||||
static withDefault(value = type => new type()) {
|
||||
const result = this.asUniqueClass()
|
||||
result.default = value
|
||||
return result
|
||||
@@ -138,6 +190,16 @@ export default class IEntity {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {T}
|
||||
*/
|
||||
static flagIgnored(value = true) {
|
||||
const result = this.asUniqueClass()
|
||||
result.ignored = value
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {T}
|
||||
@@ -180,22 +242,32 @@ export default class IEntity {
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {InstanceType<T>}
|
||||
* @this {T}
|
||||
*/
|
||||
Self() {
|
||||
return /** @type {T} */(this.constructor)
|
||||
static flagTrailing(value = true) {
|
||||
const result = this.asUniqueClass()
|
||||
result.trailing = value
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {String} string
|
||||
*/
|
||||
static asSerializedString(string) {
|
||||
return `"${string.replaceAll(/(?<=(?:[^\\]|^)(?:\\\\)*?)"/g, '\\"')}"`
|
||||
}
|
||||
|
||||
/** @param {String} key */
|
||||
showProperty(key) {
|
||||
/** @type {IEntity} */
|
||||
let value = this[key]
|
||||
const Self = this.Self()
|
||||
if (Self.silent && Self.default !== undefined) {
|
||||
if (Self["#default"] === undefined) {
|
||||
Self["#default"] = Self.default(Self)
|
||||
const valueType = /** @type {typeof IEntity} */(value.constructor)
|
||||
if (valueType.silent && valueType.default !== undefined) {
|
||||
if (valueType["#default"] === undefined) {
|
||||
valueType["#default"] = valueType.default(valueType)
|
||||
}
|
||||
const defaultValue = Self["#default"]
|
||||
const defaultValue = valueType["#default"]
|
||||
return !value.equals(defaultValue)
|
||||
}
|
||||
return true
|
||||
@@ -203,52 +275,130 @@ export default class IEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {String} attribute
|
||||
* @param {String} attributeName
|
||||
* @param {(v: any) => void} callback
|
||||
*/
|
||||
listenAttribute(attribute, callback) {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(this, attribute)
|
||||
listenAttribute(attributeName, callback) {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(this, attributeName)
|
||||
const setter = descriptor.set
|
||||
if (setter) {
|
||||
descriptor.set = v => {
|
||||
setter(v)
|
||||
callback(v)
|
||||
}
|
||||
Object.defineProperties(this, { [attribute]: descriptor })
|
||||
Object.defineProperties(this, { [attributeName]: descriptor })
|
||||
} else if (descriptor.value) {
|
||||
|
||||
Object.defineProperties(this, {
|
||||
["#" + attribute]: {
|
||||
["#" + attributeName]: {
|
||||
value: descriptor.value,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
},
|
||||
[attribute]: {
|
||||
[attributeName]: {
|
||||
enumerable: true,
|
||||
get() {
|
||||
return this["#" + attribute]
|
||||
return this["#" + attributeName]
|
||||
},
|
||||
set(v) {
|
||||
if (v != this["#" + attribute]) {
|
||||
callback(v)
|
||||
this["#" + attribute] = v
|
||||
}
|
||||
callback(v)
|
||||
this["#" + attributeName] = v
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {IEntity} other */
|
||||
/** @this {IEntity | Array} */
|
||||
doSerialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor),
|
||||
printKey = Self.printKey,
|
||||
keySeparator = Self.keySeparator,
|
||||
attributeSeparator = Self.attributeSeparator,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
const isSelfOverriden = Self !== this.constructor
|
||||
let result = ""
|
||||
let first = true
|
||||
const keys = this instanceof IEntity ? this.keys : Object.keys(this)
|
||||
for (const key of keys) {
|
||||
/** @type {IEntity} */
|
||||
const value = this[key]
|
||||
const valueType = /** @type {typeof IEntity} */(value?.constructor)
|
||||
if (value === undefined || this instanceof IEntity && !this.showProperty(key)) {
|
||||
continue
|
||||
}
|
||||
if (first) {
|
||||
first = false
|
||||
} else {
|
||||
result += attributeSeparator
|
||||
}
|
||||
let keyValue = this instanceof Array ? `(${key})` : key
|
||||
if (keyValue.length && (Self.attributes[key]?.quoted || value.quoted)) {
|
||||
keyValue = `"${keyValue}"`
|
||||
}
|
||||
if (value.inlined) {
|
||||
const inlinedPrintKey = valueType.className() === "ArrayEntity"
|
||||
? k => printKey(`${keyValue}${k}`)
|
||||
: k => printKey(`${keyValue}.${k}`)
|
||||
result += value.serialize(
|
||||
insideString,
|
||||
indentation,
|
||||
undefined,
|
||||
inlinedPrintKey,
|
||||
keySeparator,
|
||||
attributeSeparator,
|
||||
Self.notWrapped
|
||||
)
|
||||
continue
|
||||
}
|
||||
keyValue = printKey(keyValue)
|
||||
if (keyValue.length) {
|
||||
result += (attributeSeparator.includes("\n") ? indentation : "") + keyValue + keySeparator
|
||||
}
|
||||
let serialization = value?.serialize(insideString, indentation)
|
||||
result += serialization
|
||||
}
|
||||
if (this instanceof IEntity && (isSelfOverriden && Self.trailing || this.trailing) && result.length) {
|
||||
result += attributeSeparator
|
||||
}
|
||||
return wrap(/** @type {IEntity} */(this), result)
|
||||
}
|
||||
|
||||
/** @this {IEntity | Array} */
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor),
|
||||
printKey = Self.printKey,
|
||||
keySeparator = Self.keySeparator,
|
||||
attributeSeparator = Self.attributeSeparator,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
const isSelfOverriden = Self !== this.constructor
|
||||
let result = this instanceof Array
|
||||
? IEntity.prototype.doSerialize.bind(this)(insideString, indentation, Self, printKey, keySeparator, attributeSeparator, wrap)
|
||||
: this.doSerialize(insideString, indentation, Self, printKey, keySeparator, attributeSeparator, wrap)
|
||||
if (Self.serialized) {
|
||||
result = IEntity.asSerializedString(result)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
equals(other) {
|
||||
if (!(other instanceof IEntity)) {
|
||||
return false
|
||||
}
|
||||
const thisKeys = Object.keys(this)
|
||||
const otherKeys = Object.keys(other)
|
||||
const thisType = /** @type {typeof IEntity} */(this.constructor).actualClass()
|
||||
const otherType = /** @type {typeof IEntity} */(other.constructor).actualClass()
|
||||
if (
|
||||
thisKeys.length !== otherKeys.length
|
||||
|| this.lookbehind != other.lookbehind
|
||||
|| !(this instanceof other.constructor) && !(other instanceof this.constructor)
|
||||
|| !(other instanceof thisType) && !(this instanceof otherType)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
@@ -263,6 +413,15 @@ export default class IEntity {
|
||||
if (!a.equals(b)) {
|
||||
return false
|
||||
}
|
||||
} else if (a instanceof Array && b instanceof Array) {
|
||||
if (a.length !== b.length) {
|
||||
return false
|
||||
}
|
||||
for (let j = 0; j < a.length; ++j) {
|
||||
if (!(a[j] instanceof IEntity && a[j].equals(b[j])) && a[j] !== b[j]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (a !== b) {
|
||||
return false
|
||||
@@ -272,52 +431,8 @@ export default class IEntity {
|
||||
return true
|
||||
}
|
||||
|
||||
/** @this {IEntity | Array} */
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
let result = ""
|
||||
let first = true
|
||||
const keys = this instanceof IEntity ? this.keys : Object.keys(this)
|
||||
for (const key of keys) {
|
||||
/** @type {IEntity} */
|
||||
const value = this[key]
|
||||
let keyValue = this instanceof Array ? `(${key})` : key
|
||||
if (value === undefined || this instanceof IEntity && !this.showProperty(key)) {
|
||||
continue
|
||||
}
|
||||
if (first) {
|
||||
first = false
|
||||
} else {
|
||||
result += Self.attributeSeparator
|
||||
}
|
||||
if (value.Self?.().inlined) {
|
||||
const inlinedPrintKey = value.Self().className() === "ArrayEntity"
|
||||
? k => printKey(`${keyValue}${k}`)
|
||||
: k => printKey(`${keyValue}.${k}`)
|
||||
result += value.toString(insideString, indentation, Self, inlinedPrintKey, Self.notWrapped)
|
||||
continue
|
||||
}
|
||||
keyValue = printKey(keyValue)
|
||||
if (keyValue.length) {
|
||||
if (Self.quoted) {
|
||||
keyValue = `"${keyValue}"`
|
||||
}
|
||||
result += (Self.attributeSeparator.includes("\n") ? indentation : "") + keyValue + Self.keySeparator
|
||||
}
|
||||
let serialization = value?.toString(insideString, indentation)
|
||||
if (Self.serialized) {
|
||||
serialization = `"${serialization.replaceAll(/(?<=(?:[^\\]|^)(?:\\\\)*?)"/, '\\"')}"`
|
||||
}
|
||||
result += serialization
|
||||
}
|
||||
if (this instanceof IEntity && this.trailing && result.length) {
|
||||
result += Self.attributeSeparator
|
||||
}
|
||||
return wrap(/** @type {IEntity} */(this), result)
|
||||
/** @returns {IEntity | Boolean | Number | String | BigInt | (IEntity | Boolean | Number | String | BigInt)[]} */
|
||||
valueOf() {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,19 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class Integer64Entity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<Integer64Entity>} */(
|
||||
P.numberBigInteger.map(v => new this(v))
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @type {bigint} */
|
||||
#value
|
||||
/**
|
||||
* @protected
|
||||
* @type {bigint}
|
||||
*/
|
||||
_value
|
||||
get value() {
|
||||
return this.#value
|
||||
return this._value
|
||||
}
|
||||
set value(value) {
|
||||
if (value >= -(1n << 63n) && value < 1n << 63n) {
|
||||
this.#value = value
|
||||
this._value = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +25,28 @@ export default class Integer64Entity extends IEntity {
|
||||
this.value = BigInt(value)
|
||||
}
|
||||
|
||||
/** @returns {P<Integer64Entity>} */
|
||||
static createGrammar() {
|
||||
return P.numberBigInteger.map(v => new this(v))
|
||||
}
|
||||
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor),
|
||||
) {
|
||||
let result = this.value.toString()
|
||||
if (Self.serialized) {
|
||||
result = `"${result}"`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ import NumberEntity from "./NumberEntity.js"
|
||||
|
||||
export default class IntegerEntity extends NumberEntity {
|
||||
|
||||
static grammar = /** @type {P<IntegerEntity>} */(
|
||||
P.numberInteger.map(v => new this(v))
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
get value() {
|
||||
return super.value
|
||||
@@ -17,4 +15,9 @@ export default class IntegerEntity extends NumberEntity {
|
||||
super.value = value
|
||||
}
|
||||
}
|
||||
|
||||
/** @returns {P<IntegerEntity>} */
|
||||
static createGrammar() {
|
||||
return P.numberInteger.map(v => new this(v))
|
||||
}
|
||||
}
|
||||
|
||||
33
js/entity/InvariantTextEntity.js
Normal file → Executable file
33
js/entity/InvariantTextEntity.js
Normal file → Executable file
@@ -5,29 +5,36 @@ export default class InvariantTextEntity extends IEntity {
|
||||
|
||||
static lookbehind = "INVTEXT"
|
||||
|
||||
static grammar = /** @type {P<InvariantTextEntity>} */(
|
||||
P.alt(
|
||||
P.seq(
|
||||
P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
||||
P.doubleQuotedString,
|
||||
P.reg(/\s*\)/)
|
||||
).map(([_0, value, _2]) => Number(value)),
|
||||
P.reg(new RegExp(this.lookbehind)).map(() => 0) // InvariantTextEntity can not have arguments
|
||||
)
|
||||
.map(value => new this(value))
|
||||
.label("InvariantTextEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(value = "") {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
/** @returns {P<InvariantTextEntity>} */
|
||||
static createGrammar() {
|
||||
return P.alt(
|
||||
P.seq(
|
||||
P.reg(new RegExp(`${this.lookbehind}\\s*\\(`)),
|
||||
P.doubleQuotedString,
|
||||
P.reg(/\s*\)/)
|
||||
).map(([_0, value, _2]) => value),
|
||||
P.reg(new RegExp(this.lookbehind)).map(() => "") // InvariantTextEntity can have no arguments
|
||||
)
|
||||
.map(value => new this(value))
|
||||
.label("InvariantTextEntity")
|
||||
}
|
||||
|
||||
doSerialize() {
|
||||
return this.lookbehind + '("' + this.value + '")'
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.lookbehind + "(" + this.value + ")"
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
|
||||
15
js/entity/KeyBindingEntity.js
Normal file → Executable file
15
js/entity/KeyBindingEntity.js
Normal file → Executable file
@@ -16,12 +16,7 @@ export default class KeyBindingEntity extends IEntity {
|
||||
bCmd: BooleanEntity,
|
||||
Key: SymbolEntity,
|
||||
}
|
||||
static grammar = /** @type {P<KeyBindingEntity>} */(
|
||||
P.alt(
|
||||
SymbolEntity.grammar.map(identifier => new this({ Key: identifier })),
|
||||
Grammar.createEntityGrammar(this)
|
||||
)
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values) {
|
||||
super(values)
|
||||
@@ -32,4 +27,12 @@ export default class KeyBindingEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof KeyBindingEntity.attributes.bCmd>} */ this.bCmd
|
||||
/** @type {InstanceType<typeof KeyBindingEntity.attributes.Key>} */ this.Key
|
||||
}
|
||||
|
||||
/** @returs {P<KeyBindingEntity>} */
|
||||
static createGrammar() {
|
||||
return P.alt(
|
||||
SymbolEntity.grammar.map(identifier => new this({ Key: identifier })),
|
||||
Grammar.createEntityGrammar(this),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
24
js/entity/LinearColorEntity.js
Normal file → Executable file
24
js/entity/LinearColorEntity.js
Normal file → Executable file
@@ -14,9 +14,7 @@ export default class LinearColorEntity extends IEntity {
|
||||
B: ColorChannelEntity.withDefault(),
|
||||
A: ColorChannelEntity.withDefault(type => new type(1)),
|
||||
}
|
||||
static grammar = /** @type {P<LinearColorEntity>} */(
|
||||
Grammar.createEntityGrammar(this).label("LinearColorEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
#H = new ColorChannelEntity()
|
||||
get H() {
|
||||
@@ -59,6 +57,16 @@ export default class LinearColorEntity extends IEntity {
|
||||
this.#updateHSV()
|
||||
}
|
||||
|
||||
/** @returns {P<LinearColorEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this, Grammar.commaSeparation, 0.5).label("LinearColorEntity")
|
||||
}
|
||||
|
||||
/** @param {LinearColorEntity} value */
|
||||
static printLinearColor(value) {
|
||||
return `${Math.round(value.R.valueOf() * 255)}, ${Math.round(value.G.valueOf() * 255)}, ${Math.round(value.B.valueOf() * 255)}`
|
||||
}
|
||||
|
||||
/** @param {Number} x */
|
||||
static linearToSRGB(x) {
|
||||
if (x <= 0) {
|
||||
@@ -291,6 +299,11 @@ export default class LinearColorEntity extends IEntity {
|
||||
+ Math.round(this.A.value * 0xff)
|
||||
}
|
||||
|
||||
/** @returns {[Number, Number, Number, Number]} */
|
||||
toArray() {
|
||||
return [this.R.value, this.G.value, this.B.value, this.A.value]
|
||||
}
|
||||
|
||||
/** @param {Number} number */
|
||||
setFromRGBANumber(number) {
|
||||
this.A.value = (number & 0xff) / 0xff
|
||||
@@ -309,8 +322,7 @@ export default class LinearColorEntity extends IEntity {
|
||||
this.#updateHSV()
|
||||
}
|
||||
|
||||
/** @returns {[Number, Number, Number, Number]} */
|
||||
toArray() {
|
||||
return [this.R.value, this.G.value, this.B.value, this.A.value]
|
||||
toString() {
|
||||
return LinearColorEntity.printLinearColor(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import P from "parsernostrum"
|
||||
import Utility from "../Utility.js"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import StringEntity from "./StringEntity.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
import StringEntity from "./StringEntity.js"
|
||||
|
||||
export default class LocalizedTextEntity extends IEntity {
|
||||
|
||||
@@ -15,8 +15,18 @@ export default class LocalizedTextEntity extends IEntity {
|
||||
key: StringEntity.withDefault(),
|
||||
value: StringEntity.withDefault(),
|
||||
}
|
||||
static grammar = /** @type {P<LocalizedTextEntity>} */(
|
||||
P.regArray(new RegExp(
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.namespace>} */ this.namespace
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.key>} */ this.key
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.value>} */ this.value
|
||||
}
|
||||
|
||||
/** @returns {P<LocalizedTextEntity>} */
|
||||
static createGrammar() {
|
||||
return P.regArray(new RegExp(
|
||||
String.raw`${LocalizedTextEntity.lookbehind}\s*\(`
|
||||
+ String.raw`\s*"(?<namespace>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
+ String.raw`\s*"(?<key>${Grammar.Regex.InsideString.source})"\s*,`
|
||||
@@ -32,16 +42,9 @@ export default class LocalizedTextEntity extends IEntity {
|
||||
trailing: trailing !== undefined,
|
||||
})
|
||||
}).label("LocalizedTextEntity")
|
||||
)
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.namespace>} */ this.namespace
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.key>} */ this.key
|
||||
/** @type {InstanceType<typeof LocalizedTextEntity.attributes.value>} */ this.value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
toString() {
|
||||
return Utility.capitalFirstLetter(this.value.valueOf())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ export default class MacroGraphReferenceEntity extends IEntity {
|
||||
GraphBlueprint: ObjectReferenceEntity,
|
||||
GraphGuid: GuidEntity,
|
||||
}
|
||||
static grammar = /** @type {P<MacroGraphReferenceEntity>} */(
|
||||
Grammar.createEntityGrammar(this)
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values) {
|
||||
super(values)
|
||||
@@ -23,6 +21,11 @@ export default class MacroGraphReferenceEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof MacroGraphReferenceEntity.attributes.GraphGuid>} */ this.GraphGuid
|
||||
}
|
||||
|
||||
/** @returns {P<MacroGraphReferenceEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this)
|
||||
}
|
||||
|
||||
getMacroName() {
|
||||
const colonIndex = this.MacroGraph.path.search(":")
|
||||
return this.MacroGraph.path.substring(colonIndex + 1)
|
||||
|
||||
64
js/entity/MirroredEntity.js
Normal file → Executable file
64
js/entity/MirroredEntity.js
Normal file → Executable file
@@ -1,3 +1,4 @@
|
||||
import P from "parsernostrum"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
/** @template {typeof IEntity} T */
|
||||
@@ -9,38 +10,69 @@ export default class MirroredEntity extends IEntity {
|
||||
/** @param {() => InstanceType<T>} getter */
|
||||
constructor(getter = null) {
|
||||
super()
|
||||
const self = /** @type {typeof MirroredEntity<T>} */(this.constructor)
|
||||
getter ??= self.default !== undefined ? /** @type {MirroredEntity} */(self.default(self)).getter : getter
|
||||
this.getter = getter
|
||||
}
|
||||
|
||||
static createGrammar(elementGrammar = this.type?.grammar ?? P.lazy(() => this.unknownEntityGrammar)) {
|
||||
return this.type?.grammar.map(v => new this(() => v))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @this {T}
|
||||
* @param {(type: T) => (InstanceType<T> | NullEntity)} value
|
||||
* @returns {T}
|
||||
*/
|
||||
// @ts-expect-error
|
||||
static withDefault(value = type => new type(() => new (type.type)())) {
|
||||
// @ts-expect-error
|
||||
return super.withDefault(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof IEntity} T
|
||||
* @param {T} type
|
||||
* @returns {typeof MirroredEntity<T>}
|
||||
*/
|
||||
static of(type) {
|
||||
const result = this.asUniqueClass()
|
||||
const result = /** @type {{type: T, grammar: P<MirroredEntity<T>> } & typeof MirroredEntity<T>} */(
|
||||
this.asUniqueClass()
|
||||
)
|
||||
result.type = type
|
||||
result.grammar = result.getTargetType().grammar.map(v => new this())
|
||||
result.grammar = result.createGrammar()
|
||||
return result
|
||||
}
|
||||
|
||||
/** @returns {typeof IEntity} */
|
||||
static getTargetType() {
|
||||
const result = this.type
|
||||
if (result.prototype instanceof MirroredEntity) {
|
||||
return /** @type {typeof MirroredEntity} */(result).getTargetType()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
toString(
|
||||
doSerialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
Self = /** @type {typeof MirroredEntity<T>} */(this.constructor),
|
||||
printKey = Self.printKey,
|
||||
keySeparator = Self.keySeparator,
|
||||
attributeSeparator = Self.attributeSeparator,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
this.toString = this.getter.toString.bind(this.getter())
|
||||
return this.toString(insideString, indentation, Self, printKey, wrap)
|
||||
const value = this.getter()
|
||||
return value.serialize(insideString, indentation, Self.type, printKey, keySeparator, attributeSeparator, wrap)
|
||||
}
|
||||
|
||||
/** @param {IEntity} other */
|
||||
equals(other) {
|
||||
if (other instanceof MirroredEntity) {
|
||||
other = other.getter?.()
|
||||
}
|
||||
return this.getter?.().equals(other)
|
||||
}
|
||||
|
||||
/** @returns {InstanceType<T>} */
|
||||
valueOf(arg) {
|
||||
// @ts-expect-error
|
||||
return this.getter(arg).valueOf()
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.getter().toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ import IntegerEntity from "./IntegerEntity.js"
|
||||
|
||||
export default class NaturalNumberEntity extends IntegerEntity {
|
||||
|
||||
static grammar = /** @type {P<NaturalNumberEntity>} */(
|
||||
P.numberNatural.map(v => new this(v))
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
get value() {
|
||||
return super.value
|
||||
}
|
||||
set value(value) {
|
||||
value = Math.round(Utility.clamp(this.value, 0))
|
||||
value = Math.round(Utility.clamp(value, 0))
|
||||
super.value = value
|
||||
}
|
||||
|
||||
/** @returns {P<NaturalNumberEntity>} */
|
||||
static createGrammar() {
|
||||
return P.numberNatural.map(v => new this(v))
|
||||
}
|
||||
}
|
||||
|
||||
26
js/entity/NullEntity.js
Normal file → Executable file
26
js/entity/NullEntity.js
Normal file → Executable file
@@ -3,13 +3,25 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class NullEntity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<NullEntity>} */(
|
||||
// @ts-expect-error
|
||||
P.reg(new RegExp(String.raw`\(${P.whitespaceInlineOpt.getParser().regexp.source}\)`))
|
||||
.map(v => new this())
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
toString() {
|
||||
return "()"
|
||||
/** @returns {P<NullEntity>} */
|
||||
static createGrammar() {
|
||||
// @ts-expect-error
|
||||
return P.reg(new RegExp(String.raw`\(${P.whitespaceInlineOpt.getParser().regexp.source}\)`))
|
||||
.map(v => new this())
|
||||
.label("NullEntity")
|
||||
}
|
||||
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor)
|
||||
) {
|
||||
let result = "()"
|
||||
if (Self.serialized) {
|
||||
result = `"${result}"`
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
import Utility from "../Utility.js"
|
||||
|
||||
export default class NumberEntity extends IEntity {
|
||||
|
||||
static numberRegexSource = String.raw`${Grammar.numberRegexSource}(?<=(?:\.(\d*0+))?)`
|
||||
static grammar = /** @type {P<NumberEntity>} */(
|
||||
P.regArray(
|
||||
new RegExp(`(?<n>${this.numberRegexSource})|(?<posInf>\\+?inf)|(?<negInf>-inf)`)
|
||||
).map(({ 2: precision, groups: { n, posInf, negInf } }) => new this(
|
||||
n ? Number(n) : posInf ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY,
|
||||
precision?.length
|
||||
)
|
||||
).label("NumberEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
/** @type {Number} */
|
||||
static precision // Can override this.precision
|
||||
|
||||
#precision = 0
|
||||
#precision
|
||||
get precision() {
|
||||
return this.#precision
|
||||
return /** @type {typeof NumberEntity} */(this.constructor).precision ?? this.#precision
|
||||
}
|
||||
set precision(value) {
|
||||
this.#precision = value
|
||||
@@ -38,10 +33,63 @@ export default class NumberEntity extends IEntity {
|
||||
this._value = value
|
||||
}
|
||||
|
||||
constructor(value = 0, precision = 0) {
|
||||
constructor(value = 0, precision = null) {
|
||||
super()
|
||||
this.value = Number(value)
|
||||
this.#precision = Number(precision)
|
||||
if (precision !== null) {
|
||||
this.#precision = Number(precision)
|
||||
}
|
||||
}
|
||||
|
||||
/** @returns {P<NumberEntity>} */
|
||||
static createGrammar() {
|
||||
return P.regArray(
|
||||
new RegExp(`(?<n>${this.numberRegexSource})|(?<posInf>\\+?inf)|(?<negInf>-inf)`)
|
||||
).map(({ 2: precision, groups: { n, posInf, negInf } }) => new this(
|
||||
n ? Number(n) : posInf ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY,
|
||||
precision?.length
|
||||
)
|
||||
).label("NumberEntity")
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof NumberEntity} T
|
||||
* @this {T}
|
||||
* @returns {T}
|
||||
*/
|
||||
static withPrecision(value = 0) {
|
||||
const result = this.asUniqueClass()
|
||||
result.precision = value
|
||||
return result
|
||||
}
|
||||
|
||||
/** @param {Number} num */
|
||||
static printNumber(num) {
|
||||
if (num == Number.POSITIVE_INFINITY) {
|
||||
return "inf"
|
||||
} else if (num == Number.NEGATIVE_INFINITY) {
|
||||
return "-inf"
|
||||
}
|
||||
return Utility.minDecimals(num)
|
||||
}
|
||||
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof NumberEntity} */(this.constructor),
|
||||
) {
|
||||
if (this.value === Number.POSITIVE_INFINITY) {
|
||||
return "+inf"
|
||||
}
|
||||
if (this.value === Number.NEGATIVE_INFINITY) {
|
||||
return "-inf"
|
||||
}
|
||||
const precision = Self.precision ?? this.precision
|
||||
let result = precision !== undefined ? this.value.toFixed(precision) : this.value.toString()
|
||||
if (Self.serialized) {
|
||||
result = `"${result}"`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
@@ -49,12 +97,6 @@ export default class NumberEntity extends IEntity {
|
||||
}
|
||||
|
||||
toString() {
|
||||
if (this.value === Number.POSITIVE_INFINITY) {
|
||||
return "+inf"
|
||||
}
|
||||
if (this.value === Number.NEGATIVE_INFINITY) {
|
||||
return "-inf"
|
||||
}
|
||||
return this.#precision ? this.value.toFixed(this.#precision) : this.value.toString()
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import P from "parsernostrum"
|
||||
import Configuration from "../Configuration.js"
|
||||
import Utility from "../Utility.js"
|
||||
import nodeColor from "../decoding/nodeColor.js"
|
||||
import nodeIcon from "../decoding/nodeIcon.js"
|
||||
import nodeVariadic from "../decoding/nodeVariadic.js"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import Utility from "../Utility.js"
|
||||
import AlternativesEntity from "./AlternativesEntity.js"
|
||||
import ArrayEntity from "./ArrayEntity.js"
|
||||
import BooleanEntity from "./BooleanEntity.js"
|
||||
@@ -17,6 +17,7 @@ import MacroGraphReferenceEntity from "./MacroGraphReferenceEntity.js"
|
||||
import MirroredEntity from "./MirroredEntity.js"
|
||||
import NaturalNumberEntity from "./NaturalNumberEntity.js"
|
||||
import NullEntity from "./NullEntity.js"
|
||||
import NumberEntity from "./NumberEntity.js"
|
||||
import ObjectReferenceEntity from "./ObjectReferenceEntity.js"
|
||||
import PinEntity from "./PinEntity.js"
|
||||
import ScriptVariableEntity from "./ScriptVariableEntity.js"
|
||||
@@ -27,8 +28,6 @@ import VariableReferenceEntity from "./VariableReferenceEntity.js"
|
||||
|
||||
export default class ObjectEntity extends IEntity {
|
||||
|
||||
static trailing = true
|
||||
|
||||
#exported = false
|
||||
get exported() {
|
||||
return this.#exported
|
||||
@@ -37,15 +36,23 @@ export default class ObjectEntity extends IEntity {
|
||||
this.#exported = value
|
||||
}
|
||||
|
||||
static #nameRegex = /^(\w+?)(?:_(\d+))?$/
|
||||
/** @type {(k: String) => String} */
|
||||
static printKey = k => !k.startsWith(Configuration.subObjectAttributeNamePrefix) ? k : ""
|
||||
static attributeSeparator = "\n"
|
||||
static wrap = this.notWrapped
|
||||
static trailing = true
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
Class: ObjectReferenceEntity,
|
||||
Name: StringEntity,
|
||||
Archetype: ObjectReferenceEntity,
|
||||
ExportPath: ObjectReferenceEntity,
|
||||
ExportPath: MirroredEntity.of(ObjectReferenceEntity),
|
||||
ObjectRef: ObjectReferenceEntity,
|
||||
BlueprintElementType: ObjectReferenceEntity,
|
||||
BlueprintElementInstance: ObjectReferenceEntity,
|
||||
ConstA: MirroredEntity.of(NumberEntity),
|
||||
ConstB: MirroredEntity.of(NumberEntity),
|
||||
PinTags: ArrayEntity.of(NullEntity).flagInlined(),
|
||||
PinNames: ArrayEntity.of(StringEntity).flagInlined(),
|
||||
AxisKey: SymbolEntity,
|
||||
@@ -100,8 +107,11 @@ export default class ObjectEntity extends IEntity {
|
||||
SizeX: MirroredEntity.of(IntegerEntity),
|
||||
SizeY: MirroredEntity.of(IntegerEntity),
|
||||
Text: MirroredEntity.of(StringEntity),
|
||||
ParameterName: StringEntity,
|
||||
ExpressionGUID: GuidEntity,
|
||||
MaterialExpressionEditorX: MirroredEntity.of(IntegerEntity),
|
||||
MaterialExpressionEditorY: MirroredEntity.of(IntegerEntity),
|
||||
MaterialExpressionGuid: GuidEntity,
|
||||
NodeTitle: StringEntity,
|
||||
NodeTitleColor: LinearColorEntity,
|
||||
PositionX: MirroredEntity.of(IntegerEntity),
|
||||
@@ -129,12 +139,14 @@ export default class ObjectEntity extends IEntity {
|
||||
NodeGuid: GuidEntity,
|
||||
ErrorType: IntegerEntity,
|
||||
ErrorMsg: StringEntity,
|
||||
ScriptVariables: ArrayEntity.of(ScriptVariableEntity),
|
||||
ScriptVariables: ArrayEntity.flagInlined().of(ScriptVariableEntity),
|
||||
Node: MirroredEntity.of(ObjectReferenceEntity),
|
||||
ExportedNodes: StringEntity,
|
||||
CustomProperties: ArrayEntity.of(AlternativesEntity.accepting(PinEntity, UnknownPinEntity)).withDefault().flagSilent(),
|
||||
CustomProperties: ArrayEntity
|
||||
.of(AlternativesEntity.accepting(PinEntity, UnknownPinEntity))
|
||||
.withDefault()
|
||||
.flagSilent(),
|
||||
}
|
||||
static #nameRegex = /^(\w+?)(?:_(\d+))?$/
|
||||
static customPropertyGrammar = P.seq(
|
||||
P.reg(/CustomProperties\s+/),
|
||||
this.attributes.CustomProperties.type.grammar,
|
||||
@@ -148,55 +160,29 @@ export default class ObjectEntity extends IEntity {
|
||||
Grammar.symbolQuoted.map(v => [v, true]),
|
||||
Grammar.symbol.map(v => [v, false]),
|
||||
),
|
||||
P.reg(new RegExp(String.raw`\s*\(\s*(\d+)\s*\)\s*\=\s*`), 1).map(Number)
|
||||
)
|
||||
.chain(
|
||||
/** @param {[[keyof ObjectEntity.attributes, Boolean], Number]} param */
|
||||
([[symbol, quoted], index]) =>
|
||||
this.attributes[symbol].grammar.map(currentValue =>
|
||||
values => {
|
||||
if (values[symbol] === undefined) {
|
||||
let arrayEntity = ArrayEntity
|
||||
if (quoted != arrayEntity.quoted) {
|
||||
arrayEntity = arrayEntity.flagQuoted(quoted)
|
||||
}
|
||||
if (!arrayEntity.inlined) {
|
||||
arrayEntity = arrayEntity.flagInlined()
|
||||
}
|
||||
values[symbol] = new arrayEntity()
|
||||
P.reg(new RegExp(String.raw`\s*\(\s*(\d+)\s*\)\s*\=\s*`), 1).map(Number) // Number in parentheses then equal
|
||||
).chain(
|
||||
/** @param {[[keyof ObjectEntity.attributes, Boolean], Number]} param */
|
||||
([[symbol, quoted], index]) =>
|
||||
(this.attributes[symbol]?.grammar ?? IEntity.unknownEntityGrammar).map(currentValue =>
|
||||
values => {
|
||||
if (values[symbol] === undefined) {
|
||||
let arrayEntity = ArrayEntity
|
||||
if (quoted != arrayEntity.quoted) {
|
||||
arrayEntity = arrayEntity.flagQuoted(quoted)
|
||||
}
|
||||
/** @type {ArrayEntity} */
|
||||
const target = values[symbol]
|
||||
target.values[index] = currentValue
|
||||
if (!arrayEntity.inlined) {
|
||||
arrayEntity = arrayEntity.flagInlined()
|
||||
}
|
||||
values[symbol] = new arrayEntity()
|
||||
}
|
||||
)
|
||||
)
|
||||
static grammar = /** @type {P<ObjectEntity>} */(
|
||||
P.seq(
|
||||
P.reg(/Begin +Object/),
|
||||
P.seq(
|
||||
P.whitespace,
|
||||
P.alt(
|
||||
this.createSubObjectGrammar(),
|
||||
this.customPropertyGrammar,
|
||||
Grammar.createAttributeGrammar(this, P.reg(Grammar.Regex.MultipleWordsSymbols)),
|
||||
Grammar.createAttributeGrammar(this, Grammar.attributeNameQuoted, undefined, (obj, k, v) =>
|
||||
Utility.objectSet(obj, ["attributes", ...k, "quoted"], true)
|
||||
),
|
||||
this.inlinedArrayEntryGrammar,
|
||||
)
|
||||
/** @type {ArrayEntity} */
|
||||
const target = values[symbol]
|
||||
target.values[index] = currentValue
|
||||
}
|
||||
)
|
||||
.map(([_0, entry]) => entry)
|
||||
.many(),
|
||||
P.reg(/\s+End +Object/),
|
||||
)
|
||||
.map(([_0, attributes, _2]) => {
|
||||
const values = {}
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
return new this(values)
|
||||
})
|
||||
.label("ObjectEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
static grammarMultipleObjects = P.seq(
|
||||
P.whitespaceOpt,
|
||||
this.grammar,
|
||||
@@ -209,16 +195,6 @@ export default class ObjectEntity extends IEntity {
|
||||
P.whitespaceOpt
|
||||
).map(([_0, first, remaining, _4]) => [first, ...remaining])
|
||||
|
||||
static createSubObjectGrammar() {
|
||||
return P.lazy(() => this.grammar)
|
||||
.map(object =>
|
||||
values => values[Configuration.subObjectAttributeNameFromEntity(object)] = object
|
||||
)
|
||||
}
|
||||
|
||||
/** @type {String} */
|
||||
#class
|
||||
|
||||
constructor(values = {}) {
|
||||
if (("NodePosX" in values) !== ("NodePosY" in values)) {
|
||||
const entries = Object.entries(values)
|
||||
@@ -231,6 +207,7 @@ export default class ObjectEntity extends IEntity {
|
||||
super(values)
|
||||
|
||||
// Attributes
|
||||
/** @type {ArrayEntity<typeof PinEntity | typeof UnknownPinEntity>} */ this.CustomProperties
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.AddedPins>} */ this.AddedPins
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.AdvancedPinDisplay>} */ this.AdvancedPinDisplay
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.Archetype>} */ this.Archetype
|
||||
@@ -241,8 +218,9 @@ export default class ObjectEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.Class>} */ this.Class
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.CommentColor>} */ this.CommentColor
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.ComponentPropertyName>} */ this.ComponentPropertyName
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.ConstA>} */ this.ConstA
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.ConstB>} */ this.ConstB
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.CustomFunctionName>} */ this.CustomFunctionName
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.CustomProperties>} */ this.CustomProperties
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.DelegatePropertyName>} */ this.DelegatePropertyName
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.DelegateReference>} */ this.DelegateReference
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.EnabledState>} */ this.EnabledState
|
||||
@@ -281,9 +259,10 @@ export default class ObjectEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.Operation>} */ this.Operation
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.OpName>} */ this.OpName
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.OutputPins>} */ this.OutputPins
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.ParameterName>} */ this.ParameterName
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.PCGNode>} */ this.PCGNode
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.PinTags>} */ this.PinTags
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.PinNames>} */ this.PinNames
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.PinTags>} */ this.PinTags
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.PositionX>} */ this.PositionX
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.PositionY>} */ this.PositionY
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.ProxyFactoryFunctionName>} */ this.ProxyFactoryFunctionName
|
||||
@@ -299,8 +278,8 @@ export default class ObjectEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof ObjectEntity.attributes.VariableReference>} */ this.VariableReference
|
||||
|
||||
// Legacy nodes pins
|
||||
if (this["Pins"] instanceof Array) {
|
||||
this["Pins"].forEach(
|
||||
if (this["Pins"] instanceof ArrayEntity) {
|
||||
this["Pins"].valueOf().forEach(
|
||||
/** @param {ObjectReferenceEntity} objectReference */
|
||||
objectReference => {
|
||||
const pinObject = this[Configuration.subObjectAttributeNameFromReference(objectReference, true)]
|
||||
@@ -308,7 +287,7 @@ export default class ObjectEntity extends IEntity {
|
||||
const pinEntity = PinEntity.fromLegacyObject(pinObject)
|
||||
pinEntity.LinkedTo = new (PinEntity.attributes.LinkedTo)()
|
||||
this.getCustomproperties(true).push(pinEntity)
|
||||
Utility.objectSet(this, ["attributes", "CustomProperties", "ignored"], true)
|
||||
this.CustomProperties.ignored = true
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -323,16 +302,37 @@ export default class ObjectEntity extends IEntity {
|
||||
obj.MaterialExpressionEditorX && (obj.MaterialExpressionEditorX.getter = () => this.NodePosX)
|
||||
obj.MaterialExpressionEditorY && (obj.MaterialExpressionEditorY.getter = () => this.NodePosY)
|
||||
if (this.getType() === Configuration.paths.materialExpressionComponentMask) {
|
||||
// The following attributes are too generic therefore not assigned a MirroredEntity
|
||||
const rgbaPins = Configuration.rgba.map(pinName =>
|
||||
this.getPinEntities().find(pin => pin.PinName.toString() === pinName && (pin.recomputesNodeTitleOnChange = true))
|
||||
)
|
||||
const rgbaPins = Configuration.rgba.map(pinName => {
|
||||
const result = this.getPinEntities().find(pin => pin.PinName.toString() === pinName)
|
||||
result.recomputesNodeTitleOnChange = true
|
||||
return result
|
||||
})
|
||||
// Reorder keys so that the added ones stay first
|
||||
obj.keys = [...Configuration.rgba, ...obj.keys]
|
||||
const silentBool = MirroredEntity.of(BooleanEntity).withDefault().flagSilent()
|
||||
obj["R"] = new silentBool(() => rgbaPins[0].DefaultValue)
|
||||
obj["G"] = new silentBool(() => rgbaPins[1].DefaultValue)
|
||||
obj["B"] = new silentBool(() => rgbaPins[2].DefaultValue)
|
||||
obj["A"] = new silentBool(() => rgbaPins[3].DefaultValue)
|
||||
obj.keys = [...Configuration.rgba, ...super.keys.filter(k => !Configuration.rgba.includes(k))]
|
||||
} else if (this.getType() === Configuration.paths.materialExpressionSubtract) {
|
||||
const silentNumber = MirroredEntity
|
||||
.of(NumberEntity.withPrecision(6))
|
||||
.withDefault(() => new MirroredEntity(() => new NumberEntity(1)))
|
||||
.flagSilent()
|
||||
const pinA = this.getCustomproperties().find(pin => pin.PinName?.toString() === "A")
|
||||
const pinB = this.getCustomproperties().find(pin => pin.PinName?.toString() === "B")
|
||||
if (pinA || pinB) {
|
||||
// Reorder keys so that the added ones stay first
|
||||
obj.keys = ["ConstA", "ConstB", ...obj.keys]
|
||||
if (pinA) {
|
||||
pinA.recomputesNodeTitleOnChange = true
|
||||
obj.ConstA = new silentNumber(() => pinA.DefaultValue)
|
||||
}
|
||||
if (pinB) {
|
||||
pinB.recomputesNodeTitleOnChange = true
|
||||
obj.ConstB = new silentNumber(() => pinB.DefaultValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/** @type {ObjectEntity} */
|
||||
@@ -352,6 +352,7 @@ export default class ObjectEntity extends IEntity {
|
||||
obj.Node.getter = () => new ObjectReferenceEntity(
|
||||
this.PCGNode.type,
|
||||
`${this.Name}.${this.PCGNode.path}`,
|
||||
nodeRef.full,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -369,12 +370,92 @@ export default class ObjectEntity extends IEntity {
|
||||
? outputIndex++
|
||||
: i
|
||||
})
|
||||
this.mirrorNameInExportPaths()
|
||||
}
|
||||
|
||||
/** @returns {P<ObjectEntity>} */
|
||||
static createGrammar() {
|
||||
return P.seq(
|
||||
P.reg(/Begin +Object/),
|
||||
P.seq(
|
||||
P.whitespace,
|
||||
P.alt(
|
||||
this.createSubObjectGrammar(),
|
||||
this.customPropertyGrammar,
|
||||
Grammar.createAttributeGrammar(this, P.reg(Grammar.Regex.MultipleWordsSymbols)),
|
||||
Grammar.createAttributeGrammar(
|
||||
this,
|
||||
Grammar.attributeNameQuoted,
|
||||
undefined,
|
||||
(values, attributeKey, attributeValue) => {
|
||||
Utility.objectSet(values, [...attributeKey, "quoted"], true)
|
||||
},
|
||||
),
|
||||
this.inlinedArrayEntryGrammar,
|
||||
)
|
||||
)
|
||||
.map(([_0, entry]) => entry)
|
||||
.many(),
|
||||
P.reg(/\s+End +Object/),
|
||||
)
|
||||
.map(([_0, attributes, _2]) => {
|
||||
const values = {}
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
return new this(values)
|
||||
})
|
||||
.label("ObjectEntity")
|
||||
}
|
||||
|
||||
static createSubObjectGrammar() {
|
||||
return P.lazy(() => this.grammar)
|
||||
.map(object =>
|
||||
values => {
|
||||
object.trailing = false
|
||||
values[Configuration.subObjectAttributeNameFromEntity(object)] = object
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* Mirror then name part of the objects contained in this one in ExportPath
|
||||
*/
|
||||
mirrorNameInExportPaths(originalName = this.Name?.toString()) {
|
||||
if (!originalName) {
|
||||
return
|
||||
}
|
||||
const values = [this]
|
||||
for (let i = 0; i < values.length; ++i) {
|
||||
const value = values[i]
|
||||
if (value instanceof ObjectEntity) {
|
||||
values.push(...Object.values(value))
|
||||
if (!value.ExportPath?.valueOf().path.includes(originalName)) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
const mirroredEntity = /** @type {typeof ObjectEntity} */(value.constructor).attributes.ExportPath
|
||||
let originalExportPath = value.ExportPath
|
||||
value.ExportPath = new mirroredEntity(
|
||||
() => {
|
||||
const exportPath = originalExportPath.valueOf()
|
||||
return new (mirroredEntity.type)(
|
||||
exportPath.type,
|
||||
exportPath.path.replace(originalName, this.Name?.toString() ?? ""),
|
||||
exportPath.full
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {String} */
|
||||
#class
|
||||
getClass() {
|
||||
if (!this.#class) {
|
||||
this.#class = (this.Class?.path ? this.Class.path : this.Class?.type)
|
||||
?? (this.ExportPath?.path ? this.ExportPath.path : this.ExportPath?.type)
|
||||
?? this.ExportPath?.valueOf()?.type
|
||||
?? ""
|
||||
if (this.#class && !this.#class.startsWith("/")) {
|
||||
// Old path names did not start with /Script or /Engine, check tests/resources/LegacyNodes.js
|
||||
@@ -388,21 +469,21 @@ export default class ObjectEntity extends IEntity {
|
||||
}
|
||||
|
||||
getType() {
|
||||
let classValue = this.getClass()
|
||||
if (this.MacroGraphReference?.MacroGraph?.path) {
|
||||
return this.MacroGraphReference.MacroGraph.path
|
||||
const path = this.MacroGraphReference?.MacroGraph?.path
|
||||
if (path) {
|
||||
return path
|
||||
}
|
||||
if (this.MaterialExpression) {
|
||||
return this.MaterialExpression.type
|
||||
}
|
||||
return classValue
|
||||
return this.getClass()
|
||||
}
|
||||
|
||||
getObjectName(dropCounter = false) {
|
||||
if (dropCounter) {
|
||||
return this.getNameAndCounter()[0]
|
||||
}
|
||||
return this.Name.valueOf()
|
||||
return this.Name.toString()
|
||||
}
|
||||
|
||||
/** @returns {[String, Number]} */
|
||||
@@ -515,24 +596,10 @@ export default class ObjectEntity extends IEntity {
|
||||
}
|
||||
|
||||
isMaterial() {
|
||||
|
||||
return this.getClass() === Configuration.paths.materialGraphNode
|
||||
// return [
|
||||
// Configuration.paths.materialExpressionConstant,
|
||||
// Configuration.paths.materialExpressionConstant2Vector,
|
||||
// Configuration.paths.materialExpressionConstant3Vector,
|
||||
// Configuration.paths.materialExpressionConstant4Vector,
|
||||
// Configuration.paths.materialExpressionLogarithm,
|
||||
// Configuration.paths.materialExpressionLogarithm10,
|
||||
// Configuration.paths.materialExpressionLogarithm2,
|
||||
// Configuration.paths.materialExpressionMaterialFunctionCall,
|
||||
// Configuration.paths.materialExpressionSquareRoot,
|
||||
// Configuration.paths.materialExpressionTextureCoordinate,
|
||||
// Configuration.paths.materialExpressionTextureSample,
|
||||
// Configuration.paths.materialGraphNode,
|
||||
// Configuration.paths.materialGraphNodeComment,
|
||||
// ]
|
||||
// .includes(this.getClass())
|
||||
const classValue = this.getClass()
|
||||
return classValue.startsWith("/Script/Engine.MaterialExpression")
|
||||
|| classValue.startsWith("/Script/InterchangeImport.MaterialExpression")
|
||||
|| classValue.startsWith("/Script/UnrealEd.MaterialGraph")
|
||||
}
|
||||
|
||||
/** @return {ObjectEntity} */
|
||||
@@ -545,7 +612,7 @@ export default class ObjectEntity extends IEntity {
|
||||
|
||||
isPcg() {
|
||||
return this.getClass() === Configuration.paths.pcgEditorGraphNode
|
||||
|| this.getPcgSubobject()
|
||||
|| this.getPcgSubobject() != null
|
||||
}
|
||||
|
||||
isNiagara() {
|
||||
@@ -616,31 +683,62 @@ export default class ObjectEntity extends IEntity {
|
||||
return super.showProperty(key)
|
||||
}
|
||||
|
||||
toString(
|
||||
/** @param {typeof ObjectEntity} Self */
|
||||
doSerialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
Self = /** @type {typeof ObjectEntity} */(this.constructor),
|
||||
printKey = Self.printKey,
|
||||
keySeparator = Self.keySeparator,
|
||||
attributeSeparator = Self.attributeSeparator,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
const moreIndentation = indentation + Configuration.indentation
|
||||
const isSelfOverriden = Self !== this.constructor
|
||||
const deeperIndentation = indentation + Configuration.indentation
|
||||
const initial_trailing = this.trailing
|
||||
this.trailing = true
|
||||
const content = super.doSerialize(insideString, deeperIndentation, Self, printKey, keySeparator, attributeSeparator, wrap)
|
||||
this.trailing = initial_trailing
|
||||
let result = indentation + "Begin Object"
|
||||
+ (this.Class?.type || this.Class?.path ? ` Class=${this.Class.toString(insideString)}` : "")
|
||||
+ (this.Name ? ` Name=${this.Name.toString(insideString)}` : "")
|
||||
+ (this.Archetype ? ` Archetype=${this.Archetype.toString(insideString)}` : "")
|
||||
+ (this.ExportPath?.type || this.ExportPath?.path ? ` ExportPath=${this.ExportPath.toString(insideString)}` : "")
|
||||
+ "\n"
|
||||
+ super.toString(insideString, moreIndentation, Self, printKey, wrap)
|
||||
+ (!this.CustomProperties.Self().ignored
|
||||
? this.getCustomproperties().map(pin =>
|
||||
moreIndentation
|
||||
+ printKey("CustomProperties ")
|
||||
+ pin.toString(insideString)
|
||||
+ this.Self().attributeSeparator
|
||||
).join("")
|
||||
+ ((this.Class?.type || this.Class?.path)
|
||||
// && Self.attributes.Class.ignored !== true
|
||||
// && this.Class.ignored !== true
|
||||
? ` Class${keySeparator}${this.Class.serialize(insideString)}`
|
||||
: ""
|
||||
)
|
||||
+ (this.Name
|
||||
// && Self.attributes.Name.ignored !== true
|
||||
// && this.Name.ignored !== true
|
||||
? ` Name${keySeparator}${this.Name.serialize(insideString)}`
|
||||
: ""
|
||||
)
|
||||
+ (this.Archetype
|
||||
// && Self.attributes.Archetype.ignored !== true
|
||||
// && this.Archetype.ignored !== true
|
||||
? ` Archetype${keySeparator}${this.Archetype.serialize(insideString)}`
|
||||
: ""
|
||||
)
|
||||
+ ((this.ExportPath?.valueOf()?.type || this.ExportPath?.valueOf()?.path)
|
||||
// && Self.attributes.ExportPath.valueOf().ignored !== true
|
||||
// && this.ExportPath.valueOf().ignored !== true
|
||||
? ` ExportPath${keySeparator}${this.ExportPath.serialize(insideString)}`
|
||||
: ""
|
||||
)
|
||||
+ attributeSeparator
|
||||
+ content
|
||||
+ (Self.attributes.CustomProperties.ignored !== true && this.CustomProperties.ignored !== true
|
||||
? this.getCustomproperties()
|
||||
.map(pin =>
|
||||
deeperIndentation
|
||||
+ printKey("CustomProperties ")
|
||||
+ pin.serialize(insideString)
|
||||
+ attributeSeparator
|
||||
)
|
||||
.join("")
|
||||
: ""
|
||||
)
|
||||
+ indentation + "End Object"
|
||||
+ (isSelfOverriden && Self.trailing || this.trailing ? attributeSeparator : "")
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,37 +5,12 @@ import IEntity from "./IEntity.js"
|
||||
|
||||
export default class ObjectReferenceEntity extends IEntity {
|
||||
|
||||
static #quotedParser = P.regArray(new RegExp(
|
||||
`'"(${Grammar.Regex.InsideString.source})"'`
|
||||
+ "|"
|
||||
+ `'(${Grammar.Regex.InsideSingleQuotedString.source})'`
|
||||
)).map(([_0, a, b]) => a ?? b)
|
||||
static typeReference = P.reg(
|
||||
// @ts-expect-error
|
||||
new RegExp(Grammar.Regex.Path.source + "|" + Grammar.symbol.getParser().regexp.source)
|
||||
)
|
||||
static fullReferenceGrammar = P.regArray(
|
||||
new RegExp(
|
||||
// @ts-expect-error
|
||||
"(" + this.typeReference.getParser().regexp.source + ")"
|
||||
// @ts-expect-error
|
||||
+ "(?:" + this.#quotedParser.getParser().parser.regexp.source + ")"
|
||||
)
|
||||
).map(([full, type, ...path]) => new this(type, path.find(v => v), full))
|
||||
static fullReferenceSerializedGrammar = P.regArray(
|
||||
new RegExp(
|
||||
'"(' + Grammar.Regex.InsideString.source + "?)"
|
||||
+ "(?:'(" + Grammar.Regex.InsideSingleQuotedString.source + `?)')?"`
|
||||
)
|
||||
).map(([full, type, path]) => new this(type, path, full))
|
||||
static typeReferenceGrammar = this.typeReference.map(v => new this(v, "", v))
|
||||
static grammar = /** @type {P<ObjectReferenceEntity>} */(
|
||||
P.alt(
|
||||
this.fullReferenceSerializedGrammar,
|
||||
this.fullReferenceGrammar,
|
||||
this.typeReferenceGrammar,
|
||||
).label("ObjectReferenceEntity")
|
||||
)
|
||||
static fullReferenceGrammar = this.createFullReferenceGrammar()
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
#type
|
||||
get type() {
|
||||
@@ -50,33 +25,100 @@ export default class ObjectReferenceEntity extends IEntity {
|
||||
return this.#path
|
||||
}
|
||||
set path(value) {
|
||||
this.#name = ""
|
||||
this.#path = value
|
||||
}
|
||||
|
||||
#fullEscaped
|
||||
/** @type {String} */
|
||||
#full
|
||||
#serializer
|
||||
get full() {
|
||||
return this.#full
|
||||
return this.#serializer
|
||||
}
|
||||
set full(value) {
|
||||
this.#full = value
|
||||
this.#serializer = value
|
||||
}
|
||||
|
||||
#name = ""
|
||||
|
||||
constructor(type = "None", path = "", full = null) {
|
||||
/** @param {(t: String, p: String) => String} serializer */
|
||||
constructor(
|
||||
type = "None",
|
||||
path = "",
|
||||
serializer = type.includes("/") || path
|
||||
? (t, p) => `"${t + (p ? (`'${p}'`) : "")}"`
|
||||
: (t, p) => t) {
|
||||
super()
|
||||
this.#type = type
|
||||
this.#path = path
|
||||
this.#full = full ?? `"${this.type + (this.path ? (`'${this.path}'`) : "")}"`
|
||||
this.#serializer = serializer
|
||||
}
|
||||
|
||||
/** @returns {P<ObjectReferenceEntity>} */
|
||||
static createGrammar() {
|
||||
return P.alt(
|
||||
this.createFullReferenceSerializedGrammar(),
|
||||
this.createFullReferenceGrammar(),
|
||||
this.createTypeReferenceGrammar(),
|
||||
).label("ObjectReferenceEntity")
|
||||
}
|
||||
|
||||
/** @returns {P<ObjectReferenceEntity>} */
|
||||
static createFullReferenceGrammar() {
|
||||
return P.regArray(
|
||||
new RegExp(
|
||||
// @ts-expect-error
|
||||
"(" + this.typeReference.getParser().regexp.source + ")"
|
||||
+ "(?:"
|
||||
+ `'"(${Grammar.Regex.InsideString.source})"'`
|
||||
+ "|"
|
||||
+ `'(${Grammar.Regex.InsideSingleQuotedString.source})'`
|
||||
+ ")"
|
||||
)
|
||||
).map(([full, type, fullQuotedPath, simpleQuotedPath]) => {
|
||||
let fullQuoted = fullQuotedPath ? true : false
|
||||
let quotes = fullQuoted ? [`'"`, `"'`] : ["'", "'"]
|
||||
return new this(
|
||||
type,
|
||||
fullQuoted ? fullQuotedPath : simpleQuotedPath,
|
||||
(t, p) => t + quotes[0] + p + quotes[1]
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/** @returns {P<ObjectReferenceEntity>} */
|
||||
static createFullReferenceSerializedGrammar() {
|
||||
return P.regArray(
|
||||
new RegExp(
|
||||
'"(' + Grammar.Regex.InsideString.source + "?)"
|
||||
+ "(?:'(" + Grammar.Regex.InsideSingleQuotedString.source + `?)')?"`
|
||||
)
|
||||
).map(([_0, type, path]) => new this(type, path, (t, p) => `"${t}${p ? `'${p}'` : ""}"`))
|
||||
}
|
||||
|
||||
/** @returns {P<ObjectReferenceEntity>} */
|
||||
static createTypeReferenceGrammar() {
|
||||
return this.typeReference.map(v => new this(v, "", (t, p) => t))
|
||||
}
|
||||
|
||||
static createNoneInstance() {
|
||||
return new ObjectReferenceEntity("None")
|
||||
return new this("None")
|
||||
}
|
||||
|
||||
getName(dropCounter = false) {
|
||||
return Utility.getNameFromPath(this.path.replace(/_C$/, ""), dropCounter)
|
||||
if (!this.#name) {
|
||||
if (!dropCounter) {
|
||||
return this.#name = Utility.getNameFromPath(this.path.replace(/_C$/, ""), dropCounter)
|
||||
}
|
||||
return Utility.getNameFromPath(this.path.replace(/_C$/, ""), dropCounter)
|
||||
}
|
||||
return this.#name
|
||||
}
|
||||
|
||||
doSerialize(insideString = false) {
|
||||
let result = this.full(this.type, this.path)
|
||||
if (insideString) {
|
||||
result = Utility.escapeString(result, false)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** @param {IEntity} other */
|
||||
@@ -87,19 +129,7 @@ export default class ObjectReferenceEntity extends IEntity {
|
||||
return this.type == other.type && this.path == other.path
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
if (insideString) {
|
||||
if (this.#fullEscaped === undefined) {
|
||||
this.#fullEscaped = Utility.escapeString(this.#full, false)
|
||||
}
|
||||
return this.#fullEscaped
|
||||
}
|
||||
return this.full
|
||||
toString() {
|
||||
return this.full(this.type, this.path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import SimpleSerializationVector2DEntity from "./SimpleSerializationVector2DEnti
|
||||
import SimpleSerializationVector4DEntity from "./SimpleSerializationVector4DEntity.js"
|
||||
import SimpleSerializationVectorEntity from "./SimpleSerializationVectorEntity.js"
|
||||
import StringEntity from "./StringEntity.js"
|
||||
import SymbolEntity from "./SymbolEntity.js"
|
||||
import Vector2DEntity from "./Vector2DEntity.js"
|
||||
import Vector4DEntity from "./Vector4DEntity.js"
|
||||
import VectorEntity from "./VectorEntity.js"
|
||||
@@ -38,24 +39,29 @@ export default class PinEntity extends IEntity {
|
||||
|
||||
static lookbehind = "Pin"
|
||||
static #typeEntityMap = {
|
||||
[Configuration.paths.linearColor]: LinearColorEntity,
|
||||
[Configuration.paths.rotator]: RotatorEntity,
|
||||
[Configuration.paths.vector]: VectorEntity,
|
||||
[Configuration.paths.vector2D]: Vector2DEntity,
|
||||
[Configuration.paths.vector4f]: Vector4DEntity,
|
||||
"bool": BooleanEntity,
|
||||
"byte": ByteEntity,
|
||||
"enum": EnumEntity,
|
||||
"exec": StringEntity,
|
||||
"float": NumberEntity,
|
||||
"int": IntegerEntity,
|
||||
"int64": Integer64Entity,
|
||||
"name": StringEntity,
|
||||
"real": NumberEntity,
|
||||
"string": StringEntity,
|
||||
[Configuration.paths.linearColor]: LinearColorEntity,
|
||||
[Configuration.paths.niagaraBool]: BooleanEntity,
|
||||
[Configuration.paths.niagaraFloat]: NumberEntity,
|
||||
[Configuration.paths.niagaraPosition]: VectorEntity,
|
||||
[Configuration.paths.rotator]: RotatorEntity,
|
||||
[Configuration.paths.vector]: VectorEntity,
|
||||
[Configuration.paths.vector2D]: Vector2DEntity,
|
||||
[Configuration.paths.vector4f]: Vector4DEntity,
|
||||
}
|
||||
static #alternativeTypeEntityMap = {
|
||||
"enum": EnumDisplayValueEntity,
|
||||
"rg": RBSerializationVector2DEntity,
|
||||
[Configuration.paths.niagaraPosition]: SimpleSerializationVectorEntity.flagAllowShortSerialization(),
|
||||
[Configuration.paths.rotator]: SimpleSerializationRotatorEntity,
|
||||
[Configuration.paths.vector]: SimpleSerializationVectorEntity,
|
||||
[Configuration.paths.vector2D]: SimpleSerializationVector2DEntity,
|
||||
@@ -80,21 +86,19 @@ export default class PinEntity extends IEntity {
|
||||
DefaultValue:
|
||||
ComputedTypeEntity.from(
|
||||
/** @param {PinEntity} pinEntity */
|
||||
pinEntity => pinEntity.getEntityType(true) ?? StringEntity
|
||||
).flagSerialized(),
|
||||
pinEntity => pinEntity.getEntityType(true)?.flagSerialized() ?? StringEntity
|
||||
),
|
||||
AutogeneratedDefaultValue: StringEntity,
|
||||
DefaultObject: ObjectReferenceEntity,
|
||||
PersistentGuid: GuidEntity,
|
||||
bHidden: BooleanEntity.withDefault(),
|
||||
bNotConnectable: BooleanEntity.withDefault(),
|
||||
bDefaultValueIsReadOnly: BooleanEntity.withDefault(),
|
||||
bDefaultValueIsIgnored: BooleanEntity.withDefault(),
|
||||
bAdvancedView: BooleanEntity.withDefault(),
|
||||
bOrphanedPin: BooleanEntity.withDefault(),
|
||||
bHidden: BooleanEntity,
|
||||
bNotConnectable: BooleanEntity,
|
||||
bDefaultValueIsReadOnly: BooleanEntity,
|
||||
bDefaultValueIsIgnored: BooleanEntity,
|
||||
bAdvancedView: BooleanEntity,
|
||||
bOrphanedPin: BooleanEntity,
|
||||
}
|
||||
static grammar = /** @type {P<PinEntity>} */(
|
||||
Grammar.createEntityGrammar(this)
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
#recomputesNodeTitleOnChange = false
|
||||
set recomputesNodeTitleOnChange(value) {
|
||||
@@ -104,9 +108,26 @@ export default class PinEntity extends IEntity {
|
||||
return this.#recomputesNodeTitleOnChange
|
||||
}
|
||||
|
||||
#objectEntity
|
||||
/** @type {ObjectEntity} */
|
||||
#objectEntity = null
|
||||
get objectEntity() {
|
||||
return this.#objectEntity
|
||||
try {
|
||||
/*
|
||||
* Why inside a try block ?
|
||||
* It is because of this issue: https://stackoverflow.com/questions/61237153/access-private-method-in-an-overriden-method-called-from-the-base-class-construc
|
||||
* super(values) will call IEntity constructor while this instance is not yet fully constructed
|
||||
* IEntity will call computedEntity.compute(this) to initialize DefaultValue from this class
|
||||
* Which in turn calls pinEntity.getEntityType(true)
|
||||
* Which calls this.getType()
|
||||
* Which calls this.objectEntity?.isPcg()
|
||||
* Which would access #objectEntity through get objectEntity()
|
||||
* And this would violate the private access rule (because this class is not yet constructed)
|
||||
* If this issue in the future will be fixed in all the major browsers, please remove this try catch
|
||||
*/
|
||||
return this.#objectEntity
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
set objectEntity(value) {
|
||||
this.#objectEntity = value
|
||||
@@ -139,6 +160,12 @@ export default class PinEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof PinEntity.attributes.bDefaultValueIsIgnored>} */ this.bDefaultValueIsIgnored
|
||||
/** @type {InstanceType<typeof PinEntity.attributes.bAdvancedView>} */ this.bAdvancedView
|
||||
/** @type {InstanceType<typeof PinEntity.attributes.bOrphanedPin>} */ this.bOrphanedPin
|
||||
/** @type {ObjectEntity} */ this.objectEntity
|
||||
}
|
||||
|
||||
/** @returns {P<PinEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this)
|
||||
}
|
||||
|
||||
/** @param {ObjectEntity} objectEntity */
|
||||
@@ -146,9 +173,10 @@ export default class PinEntity extends IEntity {
|
||||
return new PinEntity(objectEntity)
|
||||
}
|
||||
|
||||
/** @returns {String} */
|
||||
getType() {
|
||||
const category = this.PinType.PinCategory?.valueOf().toLocaleLowerCase()
|
||||
if (category === "struct" || category === "class" || category === "object" || category === "type") {
|
||||
const category = this.PinType.PinCategory?.toString().toLocaleLowerCase()
|
||||
if (["struct", "class", "object", "type", "statictype"].includes(category)) {
|
||||
return this.PinType.PinSubCategoryObject?.path
|
||||
}
|
||||
if (this.isEnum()) {
|
||||
@@ -157,12 +185,12 @@ export default class PinEntity extends IEntity {
|
||||
if (this.objectEntity?.isPcg()) {
|
||||
const pcgSuboject = this.objectEntity.getPcgSubobject()
|
||||
const pinObjectReference = this.isInput()
|
||||
? pcgSuboject.InputPins?.[this.pinIndex]
|
||||
: pcgSuboject.OutputPins?.[this.pinIndex]
|
||||
? pcgSuboject.InputPins?.valueOf()[this.pinIndex]
|
||||
: pcgSuboject.OutputPins?.valueOf()[this.pinIndex]
|
||||
if (pinObjectReference) {
|
||||
/** @type {ObjectEntity} */
|
||||
const pinObject = pcgSuboject[Configuration.subObjectAttributeNameFromReference(pinObjectReference, true)]
|
||||
let allowedTypes = pinObject.Properties?.AllowedTypes?.valueOf() ?? ""
|
||||
let allowedTypes = pinObject.Properties?.AllowedTypes?.toString() ?? ""
|
||||
if (allowedTypes == "") {
|
||||
allowedTypes = this.PinType.PinCategory ?? ""
|
||||
if (allowedTypes == "") {
|
||||
@@ -181,7 +209,7 @@ export default class PinEntity extends IEntity {
|
||||
}
|
||||
}
|
||||
if (category === "optional") {
|
||||
const subCategory = this.PinType.PinSubCategory?.valueOf()
|
||||
const subCategory = this.PinType.PinSubCategory?.toString()
|
||||
switch (subCategory) {
|
||||
case "red":
|
||||
return "real"
|
||||
@@ -200,9 +228,9 @@ export default class PinEntity extends IEntity {
|
||||
|
||||
/** @returns {typeof IEntity} */
|
||||
getEntityType(alternative = false) {
|
||||
const typeString = this.getType()
|
||||
const entity = PinEntity.#typeEntityMap[typeString]
|
||||
const alternativeEntity = PinEntity.#alternativeTypeEntityMap[typeString]
|
||||
const type = this.getType()
|
||||
const entity = PinEntity.#typeEntityMap[type]
|
||||
const alternativeEntity = PinEntity.#alternativeTypeEntityMap[type]
|
||||
return alternative && alternativeEntity !== undefined
|
||||
? alternativeEntity
|
||||
: entity
|
||||
@@ -219,20 +247,21 @@ export default class PinEntity extends IEntity {
|
||||
|
||||
getDefaultValue(maybeCreate = false) {
|
||||
if (this.DefaultValue === undefined && maybeCreate) {
|
||||
this.DefaultValue = new (this.getEntityType(true))()
|
||||
this.DefaultValue = /** @type {T} */(new (this.getEntityType(true))())
|
||||
}
|
||||
return this.DefaultValue
|
||||
}
|
||||
|
||||
isEnum() {
|
||||
const type = this.PinType.PinSubCategoryObject.type
|
||||
const type = this.PinType.PinSubCategoryObject?.type
|
||||
return type === Configuration.paths.enum
|
||||
|| type === Configuration.paths.userDefinedEnum
|
||||
|| type.toLowerCase() === "enum"
|
||||
|| type?.toLowerCase() === "enum"
|
||||
}
|
||||
|
||||
isExecution() {
|
||||
return this.PinType.PinCategory.toString() === "exec"
|
||||
|| this.getType() === Configuration.paths.niagaraParameterMap
|
||||
}
|
||||
|
||||
isHidden() {
|
||||
@@ -240,15 +269,15 @@ export default class PinEntity extends IEntity {
|
||||
}
|
||||
|
||||
isInput() {
|
||||
return !this.isHidden() && this.Direction.valueOf() != "EGPD_Output"
|
||||
return !this.isHidden() && this.Direction?.toString() != "EGPD_Output"
|
||||
}
|
||||
|
||||
isOutput() {
|
||||
return !this.isHidden() && this.Direction.valueOf() == "EGPD_Output"
|
||||
return !this.isHidden() && this.Direction?.toString() == "EGPD_Output"
|
||||
}
|
||||
|
||||
isLinked() {
|
||||
return this.LinkedTo?.length > 0 ?? false
|
||||
return this.LinkedTo?.length > 0
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,10 +288,10 @@ export default class PinEntity extends IEntity {
|
||||
linkTo(targetObjectName, targetPinEntity) {
|
||||
const linkFound = this.LinkedTo.values?.some(pinReferenceEntity =>
|
||||
pinReferenceEntity.objectName.toString() == targetObjectName
|
||||
&& pinReferenceEntity.pinGuid.valueOf() == targetPinEntity.PinId.valueOf()
|
||||
&& pinReferenceEntity.pinGuid.toString() == targetPinEntity.PinId.toString()
|
||||
)
|
||||
if (!linkFound) {
|
||||
this.LinkedTo.values.push(new PinReferenceEntity(targetObjectName, targetPinEntity.PinId,))
|
||||
this.LinkedTo.values.push(new PinReferenceEntity(new SymbolEntity(targetObjectName), targetPinEntity.PinId))
|
||||
return true
|
||||
}
|
||||
return false // Already linked
|
||||
@@ -276,12 +305,12 @@ export default class PinEntity extends IEntity {
|
||||
unlinkFrom(targetObjectName, targetPinEntity) {
|
||||
const indexElement = this.LinkedTo.values?.findIndex(pinReferenceEntity => {
|
||||
return pinReferenceEntity.objectName.toString() == targetObjectName
|
||||
&& pinReferenceEntity.pinGuid.valueOf() == targetPinEntity.PinId.valueOf()
|
||||
&& pinReferenceEntity.pinGuid.toString() == targetPinEntity.PinId.toString()
|
||||
})
|
||||
if (indexElement >= 0) {
|
||||
this.LinkedTo.values.splice(indexElement, 1)
|
||||
if (this.LinkedTo.length === 0 && PinEntity.attributes.LinkedTo.default === undefined) {
|
||||
this.LinkedTo = undefined
|
||||
this.LinkedTo.values = []
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -289,7 +318,7 @@ export default class PinEntity extends IEntity {
|
||||
}
|
||||
|
||||
getSubCategory() {
|
||||
return this.PinType.PinSubCategoryObject.path
|
||||
return this.PinType.PinSubCategoryObject?.path
|
||||
}
|
||||
|
||||
pinColor() {
|
||||
|
||||
@@ -5,15 +5,7 @@ import SymbolEntity from "./SymbolEntity.js"
|
||||
|
||||
export default class PinReferenceEntity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<PinReferenceEntity>} */(
|
||||
P.seq(
|
||||
SymbolEntity.grammar,
|
||||
P.whitespace,
|
||||
GuidEntity.grammar
|
||||
)
|
||||
.map(([objectName, _1, pinGuid]) => new this(objectName, pinGuid))
|
||||
.label("PinReferenceEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/**
|
||||
* @param {SymbolEntity} objectName
|
||||
@@ -25,7 +17,18 @@ export default class PinReferenceEntity extends IEntity {
|
||||
this.pinGuid = pinGuid
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.objectName.toString() + " " + this.pinGuid.toString()
|
||||
/** @returns {P<PinReferenceEntity>} */
|
||||
static createGrammar() {
|
||||
return P.seq(
|
||||
SymbolEntity.grammar,
|
||||
P.whitespace,
|
||||
GuidEntity.grammar
|
||||
)
|
||||
.map(([objectName, _1, pinGuid]) => new this(objectName, pinGuid))
|
||||
.label("PinReferenceEntity")
|
||||
}
|
||||
|
||||
doSerialize() {
|
||||
return this.objectName.serialize() + " " + this.pinGuid.serialize()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,19 +12,17 @@ export default class PinTypeEntity extends IEntity {
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
PinCategory: StringEntity.withDefault(),
|
||||
PinSubCategory: StringEntity.withDefault(),
|
||||
PinSubCategoryObject: ObjectReferenceEntity.withDefault(),
|
||||
PinSubCategoryMemberReference: FunctionReferenceEntity.withDefault(),
|
||||
PinSubCategory: StringEntity,
|
||||
PinSubCategoryObject: ObjectReferenceEntity,
|
||||
PinSubCategoryMemberReference: FunctionReferenceEntity,
|
||||
ContainerType: SymbolEntity,
|
||||
bIsReference: BooleanEntity.withDefault(),
|
||||
bIsConst: BooleanEntity.withDefault(),
|
||||
bIsWeakPointer: BooleanEntity.withDefault(),
|
||||
bIsUObjectWrapper: BooleanEntity.withDefault(),
|
||||
bSerializeAsSinglePrecisionFloat: BooleanEntity.withDefault(),
|
||||
bIsReference: BooleanEntity,
|
||||
bIsConst: BooleanEntity,
|
||||
bIsWeakPointer: BooleanEntity,
|
||||
bIsUObjectWrapper: BooleanEntity,
|
||||
bSerializeAsSinglePrecisionFloat: BooleanEntity,
|
||||
}
|
||||
static grammar = /** @type {P<PinTypeEntity>} */(
|
||||
Grammar.createEntityGrammar(this).label("PinTypeEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
@@ -41,6 +39,11 @@ export default class PinTypeEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof PinTypeEntity.attributes.bSerializeAsSinglePrecisionFloat>} */ this.bSerializeAsSinglePrecisionFloat
|
||||
}
|
||||
|
||||
/** @returns {P<PinTypeEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this).label("PinTypeEntity")
|
||||
}
|
||||
|
||||
/** @param {PinTypeEntity} other */
|
||||
copyTypeFrom(other) {
|
||||
for (const key of this.keys) {
|
||||
|
||||
30
js/entity/RBSerializationVector2DEntity.js
Normal file → Executable file
30
js/entity/RBSerializationVector2DEntity.js
Normal file → Executable file
@@ -4,15 +4,23 @@ import Vector2DEntity from "./Vector2DEntity.js"
|
||||
|
||||
export default class RBSerializationVector2DEntity extends Vector2DEntity {
|
||||
|
||||
static grammar = /** @type {P<RBSerializationVector2DEntity>} */(P.alt(
|
||||
P.regArray(new RegExp(
|
||||
/X\s*=\s*/.source + "(?<x>" + Grammar.numberRegexSource + ")"
|
||||
+ "\\s+"
|
||||
+ /Y\s*=\s*/.source + "(?<y>" + Grammar.numberRegexSource + ")"
|
||||
)).map(({ groups: { x, y } }) => new this({
|
||||
X: Number(x),
|
||||
Y: Number(y),
|
||||
})),
|
||||
Vector2DEntity.grammar
|
||||
).label("RBSerializationVector2DEntity"))
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<RBSerializationVector2DEntity>} */
|
||||
static createGrammar() {
|
||||
return P.alt(
|
||||
P.regArray(new RegExp(
|
||||
/X\s*=\s*/.source + "(?<x>" + Grammar.numberRegexSource + ")"
|
||||
+ "\\s+"
|
||||
+ /Y\s*=\s*/.source + "(?<y>" + Grammar.numberRegexSource + ")"
|
||||
)).map(({ groups: { x, y } }) => new this({
|
||||
X: new (Vector2DEntity.attributes.X)(x),
|
||||
Y: new (Vector2DEntity.attributes.Y)(y),
|
||||
})),
|
||||
Vector2DEntity.grammar.map(v => new this({
|
||||
X: v.X,
|
||||
Y: v.Y,
|
||||
}))
|
||||
).label("RBSerializationVector2DEntity")
|
||||
}
|
||||
}
|
||||
|
||||
9
js/entity/RotatorEntity.js
Normal file → Executable file
9
js/entity/RotatorEntity.js
Normal file → Executable file
@@ -11,9 +11,7 @@ export default class RotatorEntity extends IEntity {
|
||||
P: NumberEntity.withDefault(),
|
||||
Y: NumberEntity.withDefault(),
|
||||
}
|
||||
static grammar = /** @type {P<RotatorEntity>} */(
|
||||
Grammar.createEntityGrammar(this, Grammar.commaSeparation, true).label("RotatorEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values) {
|
||||
super(values)
|
||||
@@ -22,6 +20,11 @@ export default class RotatorEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof RotatorEntity.attributes.Y>} */ this.Y
|
||||
}
|
||||
|
||||
/** @returns {P<RotatorEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this, Grammar.commaSeparation, 1).label("RotatorEntity")
|
||||
}
|
||||
|
||||
getRoll() {
|
||||
return this.R
|
||||
}
|
||||
|
||||
9
js/entity/ScriptVariableEntity.js
Normal file → Executable file
9
js/entity/ScriptVariableEntity.js
Normal file → Executable file
@@ -11,13 +11,16 @@ export default class ScriptVariableEntity extends IEntity {
|
||||
ScriptVariable: ObjectReferenceEntity,
|
||||
OriginalChangeId: GuidEntity,
|
||||
}
|
||||
static grammar = /** @type {P<ScriptVariableEntity>} */(
|
||||
Grammar.createEntityGrammar(this).label("ScriptVariableEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
/** @type {InstanceType<typeof ScriptVariableEntity.attributes.ScriptVariable>} */ this.ScriptVariable
|
||||
/** @type {InstanceType<typeof ScriptVariableEntity.attributes.OriginalChangeId>} */ this.OriginalChangeId
|
||||
}
|
||||
|
||||
/** @returns {P<ScriptVariableEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this).label("ScriptVariableEntity")
|
||||
}
|
||||
}
|
||||
|
||||
35
js/entity/SimpleSerializationRotatorEntity.js
Normal file → Executable file
35
js/entity/SimpleSerializationRotatorEntity.js
Normal file → Executable file
@@ -1,13 +1,15 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import RotatorEntity from "./RotatorEntity.js"
|
||||
import NumberEntity from "./NumberEntity.js"
|
||||
import RotatorEntity from "./RotatorEntity.js"
|
||||
|
||||
export default class SimpleSerializationRotatorEntity extends RotatorEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static grammar = /** @type {P<SimpleSerializationRotatorEntity>} */(
|
||||
P.alt(
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<SimpleSerializationRotatorEntity>} */
|
||||
static createGrammar() {
|
||||
return P.alt(
|
||||
P.regArray(new RegExp(
|
||||
`(${NumberEntity.numberRegexSource})`
|
||||
+ String.raw`\s*,\s*`
|
||||
@@ -15,9 +17,9 @@ export default class SimpleSerializationRotatorEntity extends RotatorEntity {
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
)).map(([_, p, pPrecision, y, yPrecision, r, rPrecision]) => new this({
|
||||
R: new NumberEntity(r, rPrecision?.length),
|
||||
P: new NumberEntity(p, pPrecision?.length),
|
||||
Y: new NumberEntity(y, yPrecision?.length),
|
||||
R: new (RotatorEntity.attributes.R)(r, rPrecision?.length),
|
||||
P: new (RotatorEntity.attributes.P)(p, pPrecision?.length),
|
||||
Y: new (RotatorEntity.attributes.Y)(y, yPrecision?.length),
|
||||
})),
|
||||
RotatorEntity.grammar.map(v => new this({
|
||||
R: v.R,
|
||||
@@ -25,17 +27,14 @@ export default class SimpleSerializationRotatorEntity extends RotatorEntity {
|
||||
Y: v.Y,
|
||||
}))
|
||||
).label("SimpleSerializationRotatorEntity")
|
||||
)
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
return this.P.toString() + Self.attributeSeparator
|
||||
+ this.Y.toString() + Self.attributeSeparator
|
||||
+ this.R.toString() + (this.trailing ? Self.attributeSeparator : "")
|
||||
doSerialize() {
|
||||
const attributeSeparator = /** @type {typeof SimpleSerializationRotatorEntity} */(
|
||||
this.constructor
|
||||
).attributeSeparator
|
||||
return this.P.serialize() + attributeSeparator
|
||||
+ this.Y.serialize() + attributeSeparator
|
||||
+ this.R.serialize() + (this.trailing ? attributeSeparator : "")
|
||||
}
|
||||
}
|
||||
|
||||
31
js/entity/SimpleSerializationVector2DEntity.js
Normal file → Executable file
31
js/entity/SimpleSerializationVector2DEntity.js
Normal file → Executable file
@@ -1,36 +1,35 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import Vector2DEntity from "./Vector2DEntity.js"
|
||||
import NumberEntity from "./NumberEntity.js"
|
||||
import Vector2DEntity from "./Vector2DEntity.js"
|
||||
|
||||
export default class SimpleSerializationVector2DEntity extends Vector2DEntity {
|
||||
|
||||
static attributeSeparator = ", "
|
||||
static grammar = /** @type {P<SimpleSerializationVector2DEntity>} */(
|
||||
P.alt(
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<SimpleSerializationVector2DEntity>} */
|
||||
static createGrammar() {
|
||||
return P.alt(
|
||||
P.regArray(new RegExp(
|
||||
`(${NumberEntity.numberRegexSource})`
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
)).map(([_, x, xPrecision, y, yPrecision]) => new this({
|
||||
X: new NumberEntity(x, xPrecision?.length),
|
||||
Y: new NumberEntity(y, yPrecision?.length),
|
||||
X: new (Vector2DEntity.attributes.X)(x, xPrecision?.length),
|
||||
Y: new (Vector2DEntity.attributes.Y)(y, yPrecision?.length),
|
||||
})),
|
||||
Vector2DEntity.grammar.map(v => new this({
|
||||
X: v.X,
|
||||
Y: v.Y,
|
||||
}))
|
||||
).label("SimpleSerializationVector2DEntity")
|
||||
)
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
return this.X.toString() + Self.attributeSeparator
|
||||
+ this.Y.toString() + (this.trailing ? Self.attributeSeparator : "")
|
||||
doSerialize() {
|
||||
const attributeSeparator = /** @type {typeof SimpleSerializationVector2DEntity} */(
|
||||
this.constructor
|
||||
).attributeSeparator
|
||||
return this.X.serialize() + attributeSeparator
|
||||
+ this.Y.serialize() + (this.trailing ? attributeSeparator : "")
|
||||
}
|
||||
}
|
||||
|
||||
11
js/entity/SimpleSerializationVector4DEntity.js
Normal file → Executable file
11
js/entity/SimpleSerializationVector4DEntity.js
Normal file → Executable file
@@ -4,8 +4,9 @@ import Vector4DEntity from "./Vector4DEntity.js"
|
||||
|
||||
export default class SimpleSerializationVector4DEntity extends Vector4DEntity {
|
||||
|
||||
static grammar = /** @type {P<SimpleSerializationVector4DEntity> } */(this.createGrammar())
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<SimpleSerializationVector4DEntity> } */
|
||||
static createGrammar() {
|
||||
const number = Grammar.numberRegexSource
|
||||
return P.alt(
|
||||
@@ -19,10 +20,10 @@ export default class SimpleSerializationVector4DEntity extends Vector4DEntity {
|
||||
+ `(${Grammar.numberRegexSource})`
|
||||
))
|
||||
.map(([_0, x, y, z, w]) => new this({
|
||||
X: Number(x),
|
||||
Y: Number(y),
|
||||
Z: Number(z),
|
||||
W: Number(w),
|
||||
X: new (Vector4DEntity.attributes.X)(x),
|
||||
Y: new (Vector4DEntity.attributes.Y)(y),
|
||||
Z: new (Vector4DEntity.attributes.Z)(z),
|
||||
W: new (Vector4DEntity.attributes.W)(w),
|
||||
})),
|
||||
Vector4DEntity.grammar
|
||||
)
|
||||
|
||||
53
js/entity/SimpleSerializationVectorEntity.js
Normal file → Executable file
53
js/entity/SimpleSerializationVectorEntity.js
Normal file → Executable file
@@ -1,24 +1,31 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import VectorEntity from "./VectorEntity.js"
|
||||
import NumberEntity from "./NumberEntity.js"
|
||||
import VectorEntity from "./VectorEntity.js"
|
||||
|
||||
export default class SimpleSerializationVectorEntity extends VectorEntity {
|
||||
|
||||
static allowShortSerialization = false
|
||||
static attributeSeparator = ", "
|
||||
static grammar = /** @type {P<SimpleSerializationVectorEntity>} */(
|
||||
P.alt(
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<SimpleSerializationVectorEntity>} */
|
||||
static createGrammar() {
|
||||
return P.alt(
|
||||
P.regArray(new RegExp(
|
||||
`(${NumberEntity.numberRegexSource})`
|
||||
// If allow simple serialization then it can parse only a single number ...
|
||||
+ (this.allowShortSerialization ? `(?:` : "")
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
+ String.raw`\s*,\s*`
|
||||
+ `(${NumberEntity.numberRegexSource})`
|
||||
// ... that will be assigned to X and the rest is optional and set to 0
|
||||
+ (this.allowShortSerialization ? `)?` : "")
|
||||
))
|
||||
.map(([_, x, xPrecision, y, yPrecision, z, zPrecision]) => new this({
|
||||
X: new NumberEntity(x, xPrecision?.length),
|
||||
Y: new NumberEntity(y, yPrecision?.length),
|
||||
Z: new NumberEntity(z, zPrecision?.length),
|
||||
X: new (VectorEntity.attributes.X)(x, xPrecision?.length),
|
||||
Y: new (VectorEntity.attributes.Y)(y, yPrecision?.length),
|
||||
Z: new (VectorEntity.attributes.Z)(z, zPrecision?.length),
|
||||
})),
|
||||
VectorEntity.grammar.map(v => new this({
|
||||
X: v.X,
|
||||
@@ -26,17 +33,27 @@ export default class SimpleSerializationVectorEntity extends VectorEntity {
|
||||
Z: v.Z,
|
||||
}))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
return this.X.toString() + Self.attributeSeparator
|
||||
+ this.Y.toString() + Self.attributeSeparator
|
||||
+ this.Z.toString() + (this.trailing ? Self.attributeSeparator : "")
|
||||
/**
|
||||
* @template {typeof SimpleSerializationVectorEntity} T
|
||||
* @this {T}
|
||||
*/
|
||||
static flagAllowShortSerialization(value = true) {
|
||||
const result = this.asUniqueClass()
|
||||
if (value !== result.allowShortSerialization) {
|
||||
result.allowShortSerialization = value
|
||||
result.grammar = result.createGrammar()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
doSerialize() {
|
||||
const attributeSeparator = /** @type {typeof SimpleSerializationVectorEntity} */(
|
||||
this.constructor
|
||||
).attributeSeparator
|
||||
return this.X.serialize() + attributeSeparator
|
||||
+ this.Y.serialize() + attributeSeparator
|
||||
+ this.Z.serialize() + (this.trailing ? attributeSeparator : "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,57 @@
|
||||
import P from "parsernostrum"
|
||||
import Utility from "../Utility.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
export default class StringEntity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<StringEntity>} */(
|
||||
P.doubleQuotedString
|
||||
.map(insideString => new this(Utility.unescapeString(insideString)))
|
||||
.label("StringEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
static escapedCharacters = /['"\\]/g
|
||||
static unescapedBackslash = /(?<=(?:[^\\]|^)(?:\\\\)*)\\(?!\\)/
|
||||
|
||||
/** @param {String} value */
|
||||
constructor(value = "") {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
/** @returns {P<StringEntity>} */
|
||||
static createGrammar() {
|
||||
return P.doubleQuotedString
|
||||
.map(insideString => new this(StringEntity.unescape(insideString)))
|
||||
.label("StringEntity")
|
||||
}
|
||||
|
||||
|
||||
/** @param {String} value */
|
||||
static escape(value, inline = true) {
|
||||
let result = value.replaceAll(new RegExp(`(${StringEntity.escapedCharacters.source})`, "g"), '\\$1')
|
||||
if (inline) {
|
||||
result = result
|
||||
.replaceAll("\n", "\\n") // Replace newline with \n
|
||||
.replaceAll("\t", "\\t") // Replace tab with \t
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** @param {String} value */
|
||||
static unescape(value) {
|
||||
return value
|
||||
.replaceAll(new RegExp(StringEntity.unescapedBackslash.source + "t", "g"), "\t") // Replace tab with \t
|
||||
.replaceAll(new RegExp(StringEntity.unescapedBackslash.source + "n", "g"), "\n") // Replace newline with \n
|
||||
.replaceAll(new RegExp(`\\\\(${StringEntity.escapedCharacters.source})`, "g"), "$1")
|
||||
}
|
||||
|
||||
doSerialize(insideString = false) {
|
||||
let result = `"${StringEntity.escape(this.value)}"`
|
||||
if (insideString) {
|
||||
result = StringEntity.escape(result, false)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = this.Self(),
|
||||
printKey = Self.printKey,
|
||||
wrap = Self.wrap,
|
||||
) {
|
||||
let result = `"${Utility.escapeString(this.value)}"`
|
||||
if (insideString) {
|
||||
result = Utility.escapeString(result, false)
|
||||
}
|
||||
return result
|
||||
toString() {
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
|
||||
21
js/entity/SymbolEntity.js
Normal file → Executable file
21
js/entity/SymbolEntity.js
Normal file → Executable file
@@ -8,17 +8,28 @@ export default class SymbolEntity extends IEntity {
|
||||
fromAttribute: (value, type) => new this(value),
|
||||
toAttribute: (value, type) => value.toString()
|
||||
}
|
||||
static grammar = /** @type {P<SymbolEntity>} */(
|
||||
Grammar.symbol.map(v => new this(v)).label("SymbolEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<SymbolEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.symbol.map(v => new this(v)).label("SymbolEntity")
|
||||
}
|
||||
|
||||
constructor(value = "") {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
serialize(
|
||||
insideString = false,
|
||||
indentation = "",
|
||||
Self = /** @type {typeof IEntity} */(this.constructor),
|
||||
) {
|
||||
let result = this.value
|
||||
if (Self.serialized) {
|
||||
result = `"${result}"`
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
||||
9
js/entity/TerminalTypeEntity.js
Normal file → Executable file
9
js/entity/TerminalTypeEntity.js
Normal file → Executable file
@@ -14,9 +14,7 @@ export default class TerminalTypeEntity extends IEntity {
|
||||
bTerminalIsWeakPointer: BooleanEntity,
|
||||
bTerminalIsUObjectWrapper: BooleanEntity,
|
||||
}
|
||||
static grammar = /** @type {P<TerminalTypeEntity>} */(
|
||||
Grammar.createEntityGrammar(this)
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values) {
|
||||
super(values)
|
||||
@@ -26,4 +24,9 @@ export default class TerminalTypeEntity extends IEntity {
|
||||
/** @type {Boolean} */ this.bTerminalIsWeakPointer
|
||||
/** @type {Boolean} */ this.bTerminalIsUObjectWrapper
|
||||
}
|
||||
|
||||
/** @returns {P<TerminalTypeEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this)
|
||||
}
|
||||
}
|
||||
|
||||
20
js/entity/UnknownKeysEntity.js
Normal file → Executable file
20
js/entity/UnknownKeysEntity.js
Normal file → Executable file
@@ -1,11 +1,23 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import GuidEntity from "./GuidEntity.js"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
export default class UnknownKeysEntity extends IEntity {
|
||||
|
||||
static grammar = /** @type {P<UnknownKeysEntity>} */(
|
||||
P.seq(
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
VariableGuid: GuidEntity,
|
||||
}
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
static {
|
||||
IEntity.unknownEntity = this
|
||||
}
|
||||
|
||||
/** @returns {P<UnknownKeysEntity>} */
|
||||
static createGrammar() {
|
||||
return P.seq(
|
||||
// Lookbehind
|
||||
P.reg(new RegExp(`(${Grammar.Regex.Path.source}|${Grammar.Regex.Symbol.source}\\s*)?\\(\\s*`), 1),
|
||||
P.seq(Grammar.attributeName, Grammar.equalSeparation).map(([attribute, equal]) => attribute)
|
||||
@@ -25,9 +37,5 @@ export default class UnknownKeysEntity extends IEntity {
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
return new this(values)
|
||||
}).label("UnknownKeysEntity")
|
||||
)
|
||||
|
||||
static {
|
||||
IEntity.unknownEntity = this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import P from "parsernostrum"
|
||||
import Grammar from "../serialization/Grammar.js"
|
||||
import GuidEntity from "./GuidEntity.js"
|
||||
import PinEntity from "./PinEntity.js"
|
||||
|
||||
export default class UnknownPinEntity extends PinEntity {
|
||||
|
||||
static grammar = /** @type {P<UnknownPinEntity>} */(
|
||||
P.seq(
|
||||
P.reg(new RegExp(`(${Grammar.Regex.Symbol.source})\\s*\\(\\s*`), 1),
|
||||
static attributes = {
|
||||
...super.attributes,
|
||||
PinId: GuidEntity
|
||||
}
|
||||
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
/** @returns {P<UnknownPinEntity>} */
|
||||
static createGrammar() {
|
||||
return P.seq(
|
||||
// Lookbehind
|
||||
P.reg(new RegExp(`(${Grammar.Regex.Symbol.source}\\s*)?\\(\\s*`), 1),
|
||||
Grammar.createAttributeGrammar(this).sepBy(Grammar.commaSeparation),
|
||||
P.reg(/\s*(?:,\s*)?\)/)
|
||||
).map(([lookbehind, attributes, _2]) => {
|
||||
@@ -18,5 +28,5 @@ export default class UnknownPinEntity extends PinEntity {
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
return new this(values)
|
||||
}).label("UnknownPinEntity")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@ export default class VariableReferenceEntity extends IEntity {
|
||||
MemberGuid: GuidEntity,
|
||||
bSelfContext: BooleanEntity,
|
||||
}
|
||||
static grammar = /** @type {P<VariableReferenceEntity>} */(
|
||||
Grammar.createEntityGrammar(this).label("VariableReferenceEntity")
|
||||
)
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
constructor(values) {
|
||||
super(values)
|
||||
@@ -25,4 +23,9 @@ export default class VariableReferenceEntity extends IEntity {
|
||||
/** @type {InstanceType<typeof VariableReferenceEntity.attributes.MemberGuid>} */ this.MemberGuid
|
||||
/** @type {InstanceType<typeof VariableReferenceEntity.attributes.bSelfContext>} */ this.bSelfContext
|
||||
}
|
||||
|
||||
/** @returns {P<VariableReferenceEntity>} */
|
||||
static createGrammar() {
|
||||
return Grammar.createEntityGrammar(this).label("VariableReferenceEntity")
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user