this repo has no description
1import { NodeManager } from "../Mangers/NodeManager";
2import { NodesByID } from "../Nodes/Nodes";
3import { Node } from "../structs/node";
4
5export let encodeNodeList = ( selectedNodes: Node[], mousePos: [ number, number ] ): string => {
6 let arr: any[] = [];
7
8 for(let node of selectedNodes){
9 arr.push({
10 type_id: node.typeId,
11 statics: node.statics,
12 x: node.x - mousePos[0],
13 y: node.y - mousePos[1]
14 })
15 }
16
17 return 'VRCMACRO' + btoa(JSON.stringify(arr));
18}
19
20export let decodeNodeList = async ( text: string, mousePos: [ number, number ] ): Promise<Node[] | null> => {
21 if(!text.startsWith("VRCMACRO"))return null;
22
23 let data = text.slice(8);
24 let json = JSON.parse(atob(data));
25
26 let nodes: Node[] = [];
27 for(let node of json){
28 let n = new Node(
29 [ node.x + mousePos[0] + 10, node.y + mousePos[1] + 10 ],
30 NodesByID[node.type_id],
31 await NodeManager.Instance.GetNewNodeId()
32 );
33
34 n.statics = node.statics;
35 await n.onStaticsUpdate(n);
36
37 nodes.push(n);
38 }
39
40 return nodes;
41}