Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ProceduralValue.cs
浏览该文件的文档.
1using System;
2using System.Text.RegularExpressions;
4
5namespace TemplatesDatabase {
6 public struct ProceduralValue {
7 static Regex m_regEx = new("\\%([A-Za-z0-9_\\-\\.\\/\\^]+)\\%", RegexOptions.Compiled);
8
9 public string Procedure;
10
11 public object Parse(DatabaseObject context) {
12 Match match = m_regEx.Match(Procedure);
13 if (match.Success
14 && match.Length == Procedure.Length) {
15 string value = match.Groups[1].Value;
16 DatabaseObject databaseObject = ResolveReference(context, value);
17 if (databaseObject != null) {
18 if (databaseObject.Type.SupportsValue) {
19 return databaseObject.Value;
20 }
21 return databaseObject.Name;
22 }
23 return $"%'{value}' not found%";
24 }
25 return m_regEx.Replace(
27 delegate(Match m) {
28 string value2 = m.Groups[1].Value;
29 DatabaseObject databaseObject2 = ResolveReference(context, value2);
30 return databaseObject2 != null
31 ? databaseObject2.Type.SupportsValue ? HumanReadableConverter.ConvertToString(databaseObject2.Value) : databaseObject2.Name
32 : $"%'{value2}' not found%";
33 }
34 );
35 }
36
37 public static DatabaseObject ResolveReference(DatabaseObject context, string reference) {
38 if (reference.Length == 36
39 && reference[8] == '-'
40 && reference[13] == '-'
41 && reference[18] == '-'
42 && reference[23] == '-') {
43 Guid guid = new(reference);
44 return context.Database.FindDatabaseObject(guid, null, false);
45 }
46 if (reference.Contains("/")
47 || reference.Contains(".")
48 || reference.Contains("^")) {
49 string[] array = reference.Split(['/'], StringSplitOptions.RemoveEmptyEntries);
50 int num = 0;
51 while (context != null
52 && num < array.Length) {
53 string text = array[num];
54 if (!(text == ".")) {
55 if (text == "..") {
56 context = context.NestingParent;
57 }
58 else if (text.StartsWith("...")) {
59 string text2 = text.Substring(3);
60 if (string.IsNullOrEmpty(text2)) {
61 context = context.NestingRoot;
62 }
63 else {
64 while (context != null
65 && context.Type.Name != text2) {
66 context = context.NestingParent;
67 }
68 }
69 }
70 else if (text == "^^") {
71 context = context.EffectiveInheritanceParent;
72 }
73 else {
74 if (!text.StartsWith("^^^")) {
75 return context.FindEffectiveNestedChild(text, null, true, false);
76 }
77 string text3 = text.Substring(3);
78 if (string.IsNullOrEmpty(text3)) {
79 context = context.EffectiveInheritanceRoot;
80 }
81 else {
82 while (context != null
83 && context.Type.Name != text3) {
84 context = context.EffectiveInheritanceParent;
85 }
86 }
87 }
88 }
89 num++;
90 }
91 return context;
92 }
93 while (context != null) {
94 DatabaseObject databaseObject = context.FindEffectiveNestedChild(reference, null, true, false);
95 if (databaseObject != null) {
96 return databaseObject;
97 }
98 context = context.NestingParent;
99 }
100 return null;
101 }
102 }
103}
DatabaseObject FindDatabaseObject(Guid guid, DatabaseObjectType type, bool throwIfNotFound)
DatabaseObject FindEffectiveNestedChild(string name, DatabaseObjectType type, bool directChildrenOnly, bool throwIfNotFound)
static DatabaseObject ResolveReference(DatabaseObject context, string reference)
object Parse(DatabaseObject context)