public void LoadSkill(int id, string file) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); #if DEBUG try { if (dataFile.Load(file, LogSystem.Log)) { Load(id, dataFile); } else { LogSystem.Error("LoadSkill file:{0} failed", file); } } catch (Exception ex) { LogSystem.Error("LoadSkill file:{0} Exception:{1}\n{2}", file, ex.Message, ex.StackTrace); } #else try { dataFile.LoadBinaryFile(file, GlobalVariables.Instance.DecodeTable); Load(id, dataFile); } catch { } #endif } }
public static Dsl.DslFile LoadStory(string file) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); #if DEBUG try { if (dataFile.Load(file, LogSystem.Log)) { return(dataFile); } else { LogSystem.Error("LoadStory file:{0} failed", file); } } catch (Exception ex) { LogSystem.Error("LoadStory file:{0} Exception:{1}\n{2}", file, ex.Message, ex.StackTrace); } #else try { dataFile.LoadBinaryFile(file, GlobalVariables.Instance.DecodeTable); return(dataFile); } catch { } #endif } return(null); }
public void LoadStory(string file, int sceneId, string _namespace) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); #if DEBUG try { if (dataFile.Load(file, LogSystem.Log)) { Load(dataFile, sceneId, _namespace, file); } else { LogSystem.Error("LoadStory file:{0} scene:{1} failed", file, sceneId); } } catch (Exception ex) { LogSystem.Error("LoadStory file:{0} scene:{1} Exception:{2}\n{3}", file, sceneId, ex.Message, ex.StackTrace); } #else try { dataFile.LoadBinaryFile(file, GlobalVariables.Instance.DecodeTable); Load(dataFile, sceneId, _namespace, file); } catch { } #endif } }
private static bool ExecuteUpdate(string dslFile) { try { if (!File.Exists(dslFile)) { return(false); } bool ret = false; string txt = File.ReadAllText(dslFile); Dsl.DslFile file = new Dsl.DslFile(); if (file.Load(dslFile, (string msg) => { Debug.LogError(msg); })) { s_Calculator = new DslExpression.DslCalculator(); s_Calculator.Init(); s_Calculator.SetGlobalVariable("@@processkey", s_ProcessKey); s_Calculator.SetGlobalVariable("@@haskey", s_HasKey); s_Calculator.SetGlobalVariable("global", DslExpression.CalculatorValue.FromObject(GlobalVariables.Instance)); s_Calculator.Register("verifycacheserver", new DslExpression.ExpressionFactoryHelper <VerifyCacheServerExp>()); foreach (var info in file.DslInfos) { s_Calculator.LoadDsl(info); } object retObj = s_Calculator.Calc("main"); if (null != retObj) { ret = (bool)System.Convert.ChangeType(retObj, typeof(bool)); } } return(ret); } catch { return(false); } }
private void SelectDsl() { string path = EditorUtility.OpenFilePanel("请选择要执行的dsl文件", string.Empty, "dsl"); if (!string.IsNullOrEmpty(path) && File.Exists(path)) { Dsl.DslFile file = new Dsl.DslFile(); if (file.Load(path, (string msg) => { Debug.Log(msg); })) { m_DslFile = file; m_Samplers.Clear(); foreach (var info in m_DslFile.DslInfos) { var dslInfo = info as Dsl.StatementData; if (null == dslInfo) { continue; } var func = dslInfo.First; foreach (var comp in func.Params) { var callData = comp as Dsl.FunctionData; string id = callData.GetId(); if (id == "sampler") { string key = callData.GetParamId(0); string val = callData.GetParamId(1); if (File.Exists(val)) { m_Samplers[key] = val; } else { m_Samplers[key] = string.Empty; } } else if (id == "cache") { string key = callData.GetParamId(0); int w = int.Parse(callData.GetParamId(1)); int h = int.Parse(callData.GetParamId(2)); m_Caches.Add(key, new Size(w, h)); } else if (id == "list") { m_ListFile = callData.GetParamId(0); } } } } else { m_DslFile = null; m_Samplers.Clear(); } } }
internal static void Import(string path, GameObject root) { Dsl.DslFile file = new Dsl.DslFile(); if (file.Load(path, (string msg) => { Debug.Log(msg); })) { foreach (var info in file.DslInfos) { ReadObject(info.First, root.transform); } } }
public void Load(string dslFile) { Dsl.DslFile file = new Dsl.DslFile(); string path = HomePath.GetAbsolutePath(dslFile); if (file.Load(path, LogSystem.Log)) { foreach (Dsl.DslInfo info in file.DslInfos) { Load(info); } } }
public void Load(string dslFile) { Dsl.DslFile file = new Dsl.DslFile(); string path = dslFile; if (file.Load(path, (string s) => { Console.WriteLine(s); })) { foreach (Dsl.DslInfo info in file.DslInfos) { Load(info); } } }
internal static void Generate(string csprojPath, string outPath, string ext) { if (string.IsNullOrEmpty(outPath)) { outPath = Path.Combine(csprojPath, "dsl"); } else if (!Path.IsPathRooted(outPath)) { outPath = Path.Combine(csprojPath, outPath); } s_ExePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; s_SrcPath = Path.Combine(csprojPath, "dsl"); s_LogPath = Path.Combine(csprojPath, "log"); s_OutPath = outPath; s_Ext = ext; if (!Directory.Exists(s_OutPath)) { Directory.CreateDirectory(s_OutPath); } var files = Directory.GetFiles(s_SrcPath, "*.dsl", SearchOption.TopDirectoryOnly); foreach (string file in files) { try { string fileName = Path.GetFileNameWithoutExtension(file); Dsl.DslFile dslFile = new Dsl.DslFile(); dslFile.Load(file, s => Log(file, s)); GenerateJs(dslFile, Path.Combine(s_OutPath, Path.ChangeExtension(fileName.Replace("cs2dsl__", "cs2js__"), s_Ext))); } catch (Exception ex) { string id = string.Empty; int line = 0; if (null != s_CurSyntax) { id = s_CurSyntax.GetId(); if (null == id) { id = string.Empty; } line = s_CurSyntax.GetLine(); } Log(file, string.Format("[{0}:{1}]:exception:{2}\n{3}", id, line, ex.Message, ex.StackTrace)); File.WriteAllText(Path.Combine(s_LogPath, "Generator.log"), s_LogBuilder.ToString()); System.Environment.Exit(-1); } } File.WriteAllText(Path.Combine(s_LogPath, "Generator.log"), s_LogBuilder.ToString()); System.Environment.Exit(0); }
public static Dsl.DslFile LoadStory(string file) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); var bytes = new byte[Dsl.DslFile.c_BinaryIdentity.Length]; using (var fs = File.OpenRead(file)) { fs.Read(bytes, 0, bytes.Length); fs.Close(); } var id = System.Text.Encoding.ASCII.GetString(bytes); if (id == Dsl.DslFile.c_BinaryIdentity) { try { dataFile.LoadBinaryFile(file, StoryConfigManager.ReuseKeyBuffer, StoryConfigManager.ReuseIdBuffer); return(dataFile); } catch (Exception ex) { var sb = new System.Text.StringBuilder(); sb.AppendFormat("[LoadStory] LoadStory file:{0} Exception:{1}\n{2}", file, ex.Message, ex.StackTrace); sb.AppendLine(); Helper.LogInnerException(ex, sb); LogSystem.Error("{0}", sb.ToString()); } } else { try { if (dataFile.Load(file, LogSystem.Log)) { return(dataFile); } else { LogSystem.Error("LoadStory file:{0} failed", file); } } catch (Exception ex) { var sb = new System.Text.StringBuilder(); sb.AppendFormat("[LoadStory] LoadStory file:{0} Exception:{1}\n{2}", file, ex.Message, ex.StackTrace); sb.AppendLine(); Helper.LogInnerException(ex, sb); LogSystem.Error("{0}", sb.ToString()); } } } return(null); }
public void LoadStory(string file, int sceneId, string _namespace) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); var bytes = new byte[Dsl.DslFile.c_BinaryIdentity.Length]; using (var fs = File.OpenRead(file)) { fs.Read(bytes, 0, bytes.Length); fs.Close(); } var id = System.Text.Encoding.ASCII.GetString(bytes); if (id == Dsl.DslFile.c_BinaryIdentity) { try { dataFile.LoadBinaryFile(file); Load(dataFile, sceneId, _namespace, file); } catch (Exception ex) { var sb = new System.Text.StringBuilder(); sb.AppendFormat("[LoadStory] LoadStory file:{0} scene:{1} Exception:{2}\n{3}", file, sceneId, ex.Message, ex.StackTrace); sb.AppendLine(); Helper.LogInnerException(ex, sb); LogSystem.Error("{0}", sb.ToString()); } } else { try { if (dataFile.Load(file, LogSystem.Log)) { Load(dataFile, sceneId, _namespace, file); } else { LogSystem.Error("[LoadStory] LoadStory file:{0} scene:{1} failed", file, sceneId); } } catch (Exception ex) { var sb = new System.Text.StringBuilder(); sb.AppendFormat("[LoadStory] LoadStory file:{0} scene:{1} Exception:{2}\n{3}", file, sceneId, ex.Message, ex.StackTrace); sb.AppendLine(); Helper.LogInnerException(ex, sb); LogSystem.Error("{0}", sb.ToString()); } } } }
static public int Load(IntPtr l) { try { Dsl.DslFile self = (Dsl.DslFile)checkSelf(l); System.String a1; checkType(l, 2, out a1); Dsl.DslLogDelegation a2; LuaDelegation.checkDelegate(l, 3, out a2); var ret = self.Load(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
public void LoadStory(string file, int sceneId, string _namespace) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); var bytes = new byte[Dsl.DslFile.c_BinaryIdentity.Length]; using (var fs = File.OpenRead(file)) { fs.Read(bytes, 0, bytes.Length); fs.Close(); } var id = System.Text.Encoding.ASCII.GetString(bytes); if (id == Dsl.DslFile.c_BinaryIdentity) { try { dataFile.LoadBinaryFile(file); Load(dataFile, sceneId, _namespace, file); } catch (Exception ex) { while (null != ex.InnerException) { ex = ex.InnerException; } LogSystem.Error("[LoadStory] LoadStoryText text:{0} scene:{1} Exception:{2}\n{3}", file, sceneId, ex.Message, ex.StackTrace); } } else { try { if (dataFile.Load(file, LogSystem.Log)) { Load(dataFile, sceneId, _namespace, file); } else { LogSystem.Error("[LoadStory] LoadStory file:{0} scene:{1} failed", file, sceneId); } } catch (Exception ex) { while (null != ex.InnerException) { ex = ex.InnerException; } LogSystem.Error("[LoadStory] LoadStoryText text:{0} scene:{1} Exception:{2}\n{3}", file, sceneId, ex.Message, ex.StackTrace); } } } }
public static Dsl.DslFile LoadStory(string file) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); var bytes = new byte[Dsl.DslFile.c_BinaryIdentity.Length]; using (var fs = File.OpenRead(file)) { fs.Read(bytes, 0, bytes.Length); fs.Close(); } var id = System.Text.Encoding.ASCII.GetString(bytes); if (id == Dsl.DslFile.c_BinaryIdentity) { try { dataFile.LoadBinaryFile(file); return(dataFile); } catch { } } else { try { if (dataFile.Load(file, LogSystem.Log)) { return(dataFile); } else { LogSystem.Error("LoadStory file:{0} failed", file); } } catch (Exception ex) { LogSystem.Error("LoadStory file:{0} Exception:{1}\n{2}", file, ex.Message, ex.StackTrace); } } } return(null); }
internal void Init(CSharpCompilation compilation, string cfgPath) { m_Compilation = compilation; m_AssemblySymbol = compilation.Assembly; INamespaceSymbol nssym = m_AssemblySymbol.GlobalNamespace; BuildInheritTypeTreeRecursively(nssym); InitRecursively(nssym); Dsl.DslFile dslFile = new Dsl.DslFile(); if (dslFile.Load(Path.Combine(cfgPath, "rewriter.dsl"), (msg) => { Console.WriteLine(msg); })) { foreach (var info in dslFile.DslInfos) { var fid = info.GetId(); if (fid != "config") { continue; } var func = info as Dsl.FunctionData; if (null == func) { continue; } var call = func.Call; var cid = call.GetParamId(0); if (cid == "LegalGenericTypeList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "type") { var v1 = cd.GetParamId(0); if (!m_LegalGenericTypes.Contains(v1)) { m_LegalGenericTypes.Add(v1); } } } } } else if (cid == "LegalGenericMethodList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "method") { var v1 = cd.GetParamId(0); var v2 = cd.GetParamId(1); var v = string.Format("{0}.{1}", v1, v2); if (!m_LegalGenericMethods.Contains(v)) { m_LegalGenericMethods.Add(v); } } } } } else if (cid == "LegalParameterGenericTypeList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "type") { var v1 = cd.GetParamId(0); if (!m_LegalParameterGenericTypes.Contains(v1)) { m_LegalParameterGenericTypes.Add(v1); } } } } } else if (cid == "LegalExtensionList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "type") { var v1 = cd.GetParamId(0); if (!m_LegalExtensions.Contains(v1)) { m_LegalExtensions.Add(v1); } } } } } else if (cid == "LegalConvertionList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "convertion") { var v1 = cd.GetParamId(0); var v2 = cd.GetParamId(1); HashSet <string> targets; if (!m_LegalConvertions.TryGetValue(v1, out targets)) { targets = new HashSet <string>(); m_LegalConvertions.Add(v1, targets); } if (!targets.Contains(v2)) { targets.Add(v2); } } } } } else if (cid == "IllegalTypeList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "type") { var v1 = cd.GetParamId(0); if (!m_IllegalTypes.Contains(v1)) { m_IllegalTypes.Add(v1); } } } } } else if (cid == "IllegalMethodList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "method") { var v1 = cd.GetParamId(0); var v2 = cd.GetParamId(1); var v = string.Format("{0}.{1}", v1, v2); if (!m_IllegalMethods.Contains(v)) { m_IllegalMethods.Add(v); } } } } } else if (cid == "IllegalPropertyList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "property") { var v1 = cd.GetParamId(0); var v2 = cd.GetParamId(1); var v = string.Format("{0}.{1}", v1, v2); if (!m_IllegalProperties.Contains(v)) { m_IllegalProperties.Add(v); } } } } } else if (cid == "IllegalFieldList") { foreach (var comp in func.Statements) { var cd = comp as Dsl.CallData; if (null != cd) { var mid = cd.GetId(); if (mid == "field") { var v1 = cd.GetParamId(0); var v2 = cd.GetParamId(1); var v = string.Format("{0}.{1}", v1, v2); if (!m_IllegalFields.Contains(v)) { m_IllegalFields.Add(v); } } } } } } } }
internal static void Generate(string csprojPath, string outPath, string ext, bool parallel) { if (string.IsNullOrEmpty(outPath)) { outPath = Path.Combine(csprojPath, "lua"); } else if (!Path.IsPathRooted(outPath)) { outPath = Path.Combine(csprojPath, outPath); } s_ExePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; s_SrcPath = Path.Combine(csprojPath, "dsl"); s_LogPath = Path.Combine(csprojPath, "log"); s_OutPath = outPath; s_Ext = ext; ReadConfig(); if (!Directory.Exists(s_OutPath)) { Directory.CreateDirectory(s_OutPath); } File.Copy(Path.Combine(s_ExePath, "lualib/syslib.lua"), Path.Combine(s_OutPath, "cs2lua__syslib." + s_Ext), true); var files = Directory.GetFiles(s_SrcPath, "*.dsl", SearchOption.TopDirectoryOnly); Action <string> handler = (file) => { try { string fileName = Path.GetFileNameWithoutExtension(file); Dsl.DslFile dslFile = new Dsl.DslFile(); dslFile.Load(file, s => Log(file, s)); GenerateLua(dslFile, Path.Combine(s_OutPath, Path.ChangeExtension(fileName.Replace("cs2dsl__", "cs2lua__"), s_Ext)), fileName); } catch (Exception ex) { string id = string.Empty; int line = 0; if (null != s_CurSyntax) { id = s_CurSyntax.GetId(); if (null == id) { id = string.Empty; } line = s_CurSyntax.GetLine(); } Log(file, string.Format("[{0}:{1}]:exception:{2}\n{3}", id, line, ex.Message, ex.StackTrace)); File.WriteAllText(Path.Combine(s_LogPath, "Generator.log"), s_LogBuilder.ToString()); throw ex; } }; if (parallel) { Parallel.ForEach(files, handler); } else { foreach (var file in files) { handler(file); } } foreach (var pair in s_FileMergeInfos) { var info = pair.Value; StringBuilder sb = new StringBuilder(); sb.AppendLine(info.CodeBuilder.ToString()); foreach (string req in info.RequireList) { sb.AppendFormatLine("{0}require \"{1}\";", GetIndentString(0), req); } foreach (string className in info.DefinedClasses) { sb.AppendFormatLine("{0}settempmetatable({1});", GetIndentString(0), className); } if (!string.IsNullOrEmpty(info.EntryClass)) { sb.AppendFormatLine("{0}defineentry({1});", GetIndentString(0), info.EntryClass); } File.WriteAllText(Path.Combine(s_OutPath, Path.ChangeExtension(info.MergedFileName, s_Ext)), sb.ToString()); } File.WriteAllText(Path.Combine(s_LogPath, "Generator.log"), s_LogBuilder.ToString()); string specialLib = Path.Combine(s_OutPath, "lualib_special.txt"); using (var sw = new StreamWriter(specialLib, false)) { foreach (var pair in s_FunctionsFromDslHook) { sw.Write(pair.Value); sw.WriteLine(); } sw.Close(); } }
public static Dsl.DslFile LoadStory(string file) { if (!string.IsNullOrEmpty(file)) { Dsl.DslFile dataFile = new Dsl.DslFile(); #if DEBUG try { if (dataFile.Load(file, LogSystem.Log)) { return dataFile; } else { LogSystem.Error("LoadStory file:{0} failed", file); } } catch (Exception ex) { LogSystem.Error("LoadStory file:{0} Exception:{1}\n{2}", file, ex.Message, ex.StackTrace); } #else try { dataFile.LoadBinaryFile(file, GlobalVariables.Instance.DecodeTable); return dataFile; } catch { } #endif } return null; }
public static void Import(string path, string name, ModelImporter importer) { Dsl.DslFile file = new Dsl.DslFile(); if (file.Load(path, (string msg) => { Debug.Log(msg); })) { Dsl.DslInfo dslInfo = null; if (file.DslInfos.Count == 1) { dslInfo = file.DslInfos[0]; } else { foreach (var info in file.DslInfos) { if (info.GetId() == "model") { var callData = info.First.Call; if (callData.GetId() == name) { dslInfo = info; break; } } } } if (null != dslInfo) { if (dslInfo.GetId() == "model") { List <ModelImporterClipAnimation> list = new List <ModelImporterClipAnimation>(); Dsl.FunctionData funcData = dslInfo.First; foreach (Dsl.ISyntaxComponent clipInfo in funcData.Statements) { var fd = clipInfo as Dsl.FunctionData; if (null != fd) { var cd = fd.Call; string id = cd.GetId(); if (id == "setting") { foreach (var settingInfo in fd.Statements) { var setting = settingInfo as Dsl.CallData; if (null != setting) { string key = setting.GetId(); if (key == "import_animation") { importer.importAnimation = bool.Parse(setting.GetParamId(0)); } else if (key == "resample_curves") { importer.resampleCurves = bool.Parse(setting.GetParamId(0)); } else if (key == "animation_compression") { importer.animationCompression = GameFramework.Converter.ConvertStrToEnum <UnityEditor.ModelImporterAnimationCompression>(setting.GetParamId(0)); } else if (key == "rotation_error") { importer.animationRotationError = float.Parse(setting.GetParamId(0)); } else if (key == "position_error") { importer.animationPositionError = float.Parse(setting.GetParamId(0)); } else if (key == "scale_error") { importer.animationScaleError = float.Parse(setting.GetParamId(0)); } } } } else if (id == "clip_animation") { ModelImporterClipAnimation clip = new ModelImporterClipAnimation(); clip.name = cd.GetParamId(0); foreach (var settingInfo in fd.Statements) { var setting = settingInfo as Dsl.CallData; if (null != setting) { string key = setting.GetId(); if (key == "take_name") { clip.takeName = setting.GetParamId(0); } else if (key == "first_frame") { clip.firstFrame = float.Parse(setting.GetParamId(0)); } else if (key == "last_frame") { clip.lastFrame = float.Parse(setting.GetParamId(0)); } else if (key == "loop_time") { clip.loopTime = bool.Parse(setting.GetParamId(0)); } else if (key == "loop_pose") { clip.loopPose = bool.Parse(setting.GetParamId(0)); } else if (key == "cycle_offset") { clip.cycleOffset = float.Parse(setting.GetParamId(0)); } else if (key == "additive_reference_pose") { clip.hasAdditiveReferencePose = bool.Parse(setting.GetParamId(0)); } else if (key == "additive_reference_pose_frame") { clip.additiveReferencePoseFrame = float.Parse(setting.GetParamId(0)); } } } list.Add(clip); } } } importer.clipAnimations = list.ToArray(); importer.SaveAndReimport(); } } else { EditorUtility.DisplayDialog("提示", "找不到对应名字的数据,如果需要不同名导入,导入数据里只能包含一个model", "ok"); } } }