Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ShaderCodeManager.cs
浏览该文件的文档.
1using System.Text.RegularExpressions;
2using Engine;
3
4namespace Game {
5 public class ShaderCodeManager {
6 public static string GetFast(string fname) {
7 string shaderText = string.Empty;
8 string[] parameters = fname.Split('.');
9 if (parameters.Length > 1) {
10 shaderText = ModsManager.GetInPakOrStorageFile<string>(parameters[0], parameters[1]);
11 }
12 return shaderText;
13 }
14
15 public static string Get(string fname) {
16 string shaderText = string.Empty;
17 shaderText = GetIncludeText(shaderText, fname, false);
18 return shaderText;
19 }
20
21 public static string GetExternal(string fname) {
22 string shaderText = string.Empty;
23 shaderText = GetIncludeText(shaderText, fname, true);
24 return shaderText;
25 }
26
27 public static string GetIncludeText(string shaderText, string includefname, bool external) {
28 string includeText = string.Empty;
29 string shaderTextTemp;
30 try {
31 if (external) {
32 string path = ModsManager.IsAndroid ? RunPath.AndroidFilePath : "app:/";
33 Stream stream = Storage.OpenFile(Storage.CombinePaths(path, includefname), OpenFileMode.Read);
34 StreamReader streamReader = new(stream);
35 shaderTextTemp = streamReader.ReadToEnd();
36 }
37 else {
38 if (includefname.Contains(".txt")) {
39 includefname = includefname.Split('.')[0];
40 shaderTextTemp = ContentManager.Get<string>(includefname);
41 }
42 else {
43 shaderTextTemp = GetFast(includefname);
44 }
45 }
46 if (shaderTextTemp == string.Empty) {
47 return string.Empty;
48 }
49 shaderTextTemp = shaderTextTemp.Replace("\n", "$");
50 string[] lines = shaderTextTemp.Split(['$'], StringSplitOptions.RemoveEmptyEntries);
51 for (int l = 0; l < lines.Length; l++) {
52 lines[l] = lines[l].Trim();
53 if (lines[l].StartsWith("//")) {
54 string text = lines[l].Substring(2).TrimStart();
55 if (text.StartsWith('<')
56 && text.EndsWith("/>")) {
57 includeText += $"{lines[l]}\n";
58 continue;
59 }
60 }
61 string[] arline = lines[l].Replace("//", "$").Split('$');
62 if (arline.Length > 0) {
63 lines[l] = arline[0];
64 }
65 if (lines[l].StartsWith("#include")) {
66 Regex regex = new("\"[^\"]*\"");
67 string fname = regex.Match(lines[l]).Value.Replace("\"", "");
68 includeText += GetIncludeText(shaderText, fname, external);
69 }
70 else {
71 includeText += $"{lines[l]}\n";
72 }
73 }
74 shaderText += includeText;
75 }
76 catch {
77 // ignored
78 }
79 return shaderText;
80 }
81 }
82}
static string AndroidFilePath
static Stream OpenFile(string path, OpenFileMode openFileMode)
static string CombinePaths(params string[] paths)
static object Get(Type type, string name)
static string GetExternal(string fname)
static string Get(string fname)
static string GetIncludeText(string shaderText, string includefname, bool external)
static string GetFast(string fname)
static bool IsAndroid