forked from hantabaru1014/ResoniteScreenshotExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTreeUtils.cs
More file actions
50 lines (47 loc) · 1.49 KB
/
DataTreeUtils.cs
File metadata and controls
50 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Elements.Core;
using FrooxEngine;
using Newtonsoft.Json;
using System.IO;
using HarmonyLib;
namespace ResoniteScreenshotExtensions;
public static class DataTreeUtils
{
public static void LoadComponent(IComponent component, SavedGraph graph)
{
var dict = graph.Root;
var control = new LoadControl(component.Slot.World, new ReferenceTranslator(), default, null);
control.TryLoadVersion(dict);
var flags = dict.TryGetDictionary("FeatureFlags");
if (flags != null)
{
control.LoadFeatureFlags(flags);
}
control.InitializeLoaders();
var typeList = dict.TryGetList("Types");
var typeVersions = dict.TryGetDictionary("TypeVersions");
if (typeVersions != null)
{
control.LoadTypeData(typeList, typeVersions);
}
var data = dict.TryGetNode("Component");
if (data != null)
{
component.Load(data, control);
}
AccessTools.Method(typeof(LoadControl), "FinishLoad").Invoke(control, null);
}
public static SavedGraph? ToSavedGraph(string json)
{
var sr = new StringReader(json);
var reader = new JsonTextReader(sr);
var node = (DataTreeNode)AccessTools.Method(typeof(DataTreeConverter), "Read").Invoke(null, new object[] { reader });
if (node != null)
{
return new SavedGraph((DataTreeDictionary)node);
}
else
{
return null;
}
}
}