public static void FirstParse(IList <Dsl.DslInfo> dslInfos) { for (int i = 0; i < dslInfos.Count; i++) { Dsl.DslInfo dslInfo = dslInfos[i]; FirstParse(dslInfo); } }
public static void FinalParse(Dsl.DslInfo dslInfo) { string id = dslInfo.GetId(); if (id == "command") { if (dslInfo.Functions.Count == 2) { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryCommandFactory factory = StoryCommandManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonCommands.CompositeCommand cmd = factory.Create() as StorySystem.CommonCommands.CompositeCommand; Dsl.FunctionData second = dslInfo.Second; cmd.InitialCommands.Clear(); for (int ix = 0; ix < second.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = second.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); cmd.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find command factory '{0}'", name); } } } else if (id == "value") { if (dslInfo.Functions.Count == 3) { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryValueFactory factory = StoryValueManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonValues.CompositeValue val = factory.Build() as StorySystem.CommonValues.CompositeValue; Dsl.FunctionData second = dslInfo.Second; Dsl.FunctionData third = dslInfo.Functions[2]; val.InitialCommands.Clear(); for (int ix = 0; ix < third.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = third.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); val.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find value factory '{0}'", name); } } } }
public static void FinalParse(params Dsl.DslFile[] dataFiles) { for (int ix = 0; ix < dataFiles.Length; ++ix) { Dsl.DslFile dataFile = dataFiles[ix]; for (int i = 0; i < dataFile.DslInfos.Count; i++) { Dsl.DslInfo dslInfo = dataFile.DslInfos[i]; FinalParse(dslInfo); } } }
static public int Clear(IntPtr l) { try { Dsl.DslInfo self = (Dsl.DslInfo)checkSelf(l); self.Clear(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int constructor(IntPtr l) { try { Dsl.DslInfo o; o = new Dsl.DslInfo(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int GetResourceName(IntPtr l) { try { Dsl.DslInfo self = (Dsl.DslInfo)checkSelf(l); var ret = self.GetResourceName(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int IsLoaded(IntPtr l) { try { Dsl.DslInfo self = (Dsl.DslInfo)checkSelf(l); var ret = self.IsLoaded(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int SetResourceName(IntPtr l) { try { Dsl.DslInfo self = (Dsl.DslInfo)checkSelf(l); System.String a1; checkType(l, 2, out a1); self.SetResourceName(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int SetLoaded(IntPtr l) { try { Dsl.DslInfo self = (Dsl.DslInfo)checkSelf(l); System.Boolean a1; checkType(l, 2, out a1); self.SetLoaded(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int CopyFrom(IntPtr l) { try { Dsl.DslInfo self = (Dsl.DslInfo)checkSelf(l); Dsl.DslInfo a1; checkType(l, 2, out a1); self.CopyFrom(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int ToScriptString(IntPtr l) { try { Dsl.DslInfo self = (Dsl.DslInfo)checkSelf(l); System.Boolean a1; checkType(l, 2, out a1); var ret = self.ToScriptString(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
private void Load(Dsl.DslInfo info) { Dsl.FunctionData func = info.First; string id = func.Call.GetParamId(0); List <Interpreter> list; if (!m_Procs.TryGetValue(id, out list)) { list = new List <Interpreter>(); m_Procs.Add(id, list); } foreach (Dsl.ISyntaxComponent comp in func.Statements) { Load(list, comp); } }
private void Load(Dsl.DslInfo info) { Dsl.FunctionData func = info.First; string id = func.Call.GetParamId(0); List <IExpression> list; if (!m_Procs.TryGetValue(id, out list)) { list = new List <IExpression>(); m_Procs.Add(id, list); } foreach (Dsl.ISyntaxComponent comp in func.Statements) { var exp = Load(comp); if (null != exp) { list.Add(exp); } } }
public static void FirstParse(Dsl.DslInfo dslInfo) { string id = dslInfo.GetId(); if (id == "command") { if (dslInfo.Functions.Count == 2) { StorySystem.CommonCommands.CompositeCommand cmd = new CommonCommands.CompositeCommand(); cmd.InitSharedData(); Dsl.FunctionData first = dslInfo.First; cmd.Name = first.Call.GetParamId(0); Dsl.FunctionData second = dslInfo.Second; for (int ix = 0; ix < second.Call.GetParamNum(); ++ix) { cmd.ArgNames.Add(second.Call.GetParamId(ix)); } //注册 StoryCommandManager.Instance.RegisterCommandFactory(cmd.Name, new CommonCommands.CompositeCommandFactory(cmd), true); } } else if (id == "value") { if (dslInfo.Functions.Count == 3) { StorySystem.CommonValues.CompositeValue val = new CommonValues.CompositeValue(); val.InitSharedData(); Dsl.FunctionData first = dslInfo.First; val.Name = first.Call.GetParamId(0); Dsl.FunctionData second = dslInfo.Second; for (int ix = 0; ix < second.Call.GetParamNum(); ++ix) { val.ArgNames.Add(second.Call.GetParamId(ix)); } Dsl.FunctionData third = dslInfo.Functions[2]; val.ReturnName = third.Call.GetParamId(0); //注册 StoryValueManager.Instance.RegisterValueFactory(val.Name, new CommonValues.CompositeValueFactory(val), true); } } }
public static void FinalParse(Dsl.DslInfo dslInfo) { string id = dslInfo.GetId(); if (id == "command") { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryCommandFactory factory = StoryCommandManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonCommands.CompositeCommand cmd = factory.Create() as StorySystem.CommonCommands.CompositeCommand; cmd.InitialCommands.Clear(); Dsl.FunctionData last = dslInfo.Last; var bodyId = last.GetId(); if (bodyId == "body" || bodyId != "opts") { for (int ix = 0; ix < last.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = last.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); cmd.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find command body '{0}'", name); } } else { LogSystem.Error("Can't find command factory '{0}'", name); } } else if (id == "value") { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryValueFactory factory = StoryValueManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonValues.CompositeValue val = factory.Build() as StorySystem.CommonValues.CompositeValue; val.InitialCommands.Clear(); Dsl.FunctionData last = dslInfo.Last; var bodyId = last.GetId(); if (bodyId == "body" || bodyId != "opts") { for (int ix = 0; ix < last.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = last.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); val.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find value body '{0}'", name); } } else { LogSystem.Error("Can't find value factory '{0}'", name); } } }
public static void FirstParse(Dsl.DslInfo dslInfo) { string id = dslInfo.GetId(); if (id == "command") { StorySystem.CommonCommands.CompositeCommand cmd = new CommonCommands.CompositeCommand(); cmd.InitSharedData(); Dsl.FunctionData first = dslInfo.First; cmd.Name = first.Call.GetParamId(0); for (int i = 1; i < dslInfo.GetFunctionNum(); ++i) { var funcData = dslInfo.GetFunction(i); var fid = funcData.GetId(); if (fid == "args") { for (int ix = 0; ix < funcData.Call.GetParamNum(); ++ix) { cmd.ArgNames.Add(funcData.Call.GetParamId(ix)); } } else if (fid == "opts") { for (int ix = 0; ix < funcData.GetStatementNum(); ++ix) { var fcomp = funcData.GetStatement(ix); var fcd = fcomp as Dsl.CallData; if (null != fcd) { cmd.OptArgs.Add(fcd.GetId(), fcd.GetParam(0)); } } } } //注册 StoryCommandManager.Instance.RegisterCommandFactory(cmd.Name, new CommonCommands.CompositeCommandFactory(cmd), true); } else if (id == "value") { StorySystem.CommonValues.CompositeValue val = new CommonValues.CompositeValue(); val.InitSharedData(); Dsl.FunctionData first = dslInfo.First; val.Name = first.Call.GetParamId(0); for (int i = 1; i < dslInfo.GetFunctionNum(); ++i) { var funcData = dslInfo.GetFunction(i); var fid = funcData.GetId(); if (fid == "args") { for (int ix = 0; ix < funcData.Call.GetParamNum(); ++ix) { val.ArgNames.Add(funcData.Call.GetParamId(ix)); } } else if (fid == "ret") { val.ReturnName = funcData.Call.GetParamId(0); } else if (fid == "opts") { for (int ix = 0; ix < funcData.GetStatementNum(); ++ix) { var fcomp = funcData.GetStatement(ix); var fcd = fcomp as Dsl.CallData; if (null != fcd) { val.OptArgs.Add(fcd.GetId(), fcd.GetParam(0)); } } } } //注册 StoryValueManager.Instance.RegisterValueFactory(val.Name, new CommonValues.CompositeValueFactory(val), true); } }
private void Load(Dsl.DslFile dataFile, int sceneId, string _namespace, string resourceName) { lock (m_Lock) { Dictionary <string, StoryInstance> existStoryInstances; if (!m_StoryInstancePool.TryGetValue(resourceName, out existStoryInstances)) { List <Dsl.DslInfo> cmdOrValList = new List <Dsl.DslInfo>(); existStoryInstances = new Dictionary <string, StoryInstance>(); m_StoryInstancePool.Add(resourceName, existStoryInstances); for (int i = 0; i < dataFile.DslInfos.Count; i++) { Dsl.DslInfo dslInfo = dataFile.DslInfos[i]; string id = dslInfo.GetId(); if (id == "story" || id == "script") { Dsl.FunctionData funcData = dslInfo.First; if (null != funcData) { Dsl.CallData callData = funcData.Call; if (null != callData && callData.HaveParam()) { StoryInstance instance = new StoryInstance(); if (!string.IsNullOrEmpty(_namespace)) { instance.Namespace = _namespace; } instance.Init(dslInfo); string storyId; if (string.IsNullOrEmpty(_namespace)) { storyId = instance.StoryId; } else { storyId = string.Format("{0}:{1}", _namespace, instance.StoryId); instance.StoryId = storyId; } if (!existStoryInstances.ContainsKey(storyId)) { existStoryInstances.Add(storyId, instance); } else { existStoryInstances[storyId] = instance; } LogSystem.Info("ParseStory {0} {1}", storyId, sceneId); } } } else if (id == "command" || id == "value") { cmdOrValList.Add(dslInfo); } else { LogSystem.Error("[LoadStory] Unknown story keyword '{0}'", id); } } CustomCommandValueParser.FirstParse(cmdOrValList); CustomCommandValueParser.FinalParse(cmdOrValList); } Dictionary <string, StoryInstance> storyInstances; if (!m_StoryInstances.TryGetValue(sceneId, out storyInstances)) { storyInstances = new Dictionary <string, StoryInstance>(existStoryInstances); m_StoryInstances.Add(sceneId, storyInstances); } else { foreach (var pair in existStoryInstances) { if (!storyInstances.ContainsKey(pair.Key)) { storyInstances.Add(pair.Key, pair.Value); } else { storyInstances[pair.Key] = pair.Value; } } } } }
public bool Init(Dsl.DslInfo config) { if (null == config || null == config.First) { return(false); } bool ret = false; Dsl.FunctionData story = config.First; if (story.GetId() == "story" || story.GetId() == "script") { ret = true; Dsl.CallData callData = story.Call; if (null != callData && callData.HaveParam()) { m_StoryId = callData.GetParamId(0); } for (int i = 0; i < story.Statements.Count; i++) { if (story.Statements[i].GetId() == "local") { Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData; if (null != sectionData) { for (int j = 0; j < sectionData.Statements.Count; j++) { Dsl.CallData defData = sectionData.Statements[j] as Dsl.CallData; if (null != defData && defData.HaveId() && defData.HaveParam()) { string id = defData.GetId(); if (id.StartsWith("@") && !id.StartsWith("@@")) { StoryValue val = new StoryValue(); val.InitFromDsl(defData.GetParam(0)); if (!m_PreInitedLocalVariables.ContainsKey(id)) { m_PreInitedLocalVariables.Add(id, val.Value); } else { m_PreInitedLocalVariables[id] = val.Value; } } } } } else { #if DEBUG string err = string.Format("Story {0} DSL, local must be a function ! line:{1} local:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false)); throw new Exception(err); #else LogSystem.Error("Story {0} DSL, local must be a function !", m_StoryId); #endif } } else if (story.Statements[i].GetId() == "onmessage" || story.Statements[i].GetId() == "onnamespacedmessage") { StoryMessageHandler handler = null; Dsl.StatementData msgData = story.Statements[i] as Dsl.StatementData; if (null != msgData) { handler = new StoryMessageHandler(); handler.Load(msgData); } else { Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData; if (null != sectionData) { handler = new StoryMessageHandler(); handler.Load(sectionData); } } if (null != handler) { string msgId; if (!string.IsNullOrEmpty(m_Namespace) && story.Statements[i].GetId() == "onnamespacedmessage") { msgId = string.Format("{0}:{1}", m_Namespace, handler.MessageId); handler.MessageId = msgId; } else { msgId = handler.MessageId; } if (!m_LoadedMessageHandlers.ContainsKey(msgId)) { m_LoadedMessageHandlers.Add(msgId, handler); m_MessageHandlers.Add(handler.Clone()); m_MessageQueues.Add(msgId, new Queue <MessageInfo>()); m_ConcurrentMessageQueues.Add(msgId, new Queue <MessageInfo>()); m_ConcurrentMessageHandlerPool.Add(msgId, new Queue <StoryMessageHandler>()); } else { #if DEBUG string err = string.Format("Story {0} DSL, onmessage or onnamespacedmessage {1} duplicate, discard it ! line:{2}", m_StoryId, msgId, story.Statements[i].GetLine()); throw new Exception(err); #else LogSystem.Error("Story {0} DSL, onmessage {1} duplicate, discard it !", m_StoryId, msgId); #endif } } else { #if DEBUG string err = string.Format("Story {0} DSL, onmessage must be a function or statement ! line:{1} onmessage:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false)); throw new Exception(err); #else LogSystem.Error("Story {0} DSL, onmessage must be a function !", m_StoryId); #endif } } else { #if DEBUG string err = string.Format("StoryInstance::Init, Story {0} unknown part {1}, line:{2} section:{3}", m_StoryId, story.Statements[i].GetId(), story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false)); throw new Exception(err); #else LogSystem.Error("StoryInstance::Init, Story {0} unknown part {1}", m_StoryId, story.Statements[i].GetId()); #endif } } } else { #if DEBUG string err = string.Format("StoryInstance::Init, isn't story DSL, line:{0} story:{1}", story.GetLine(), story.ToScriptString(false)); throw new Exception(err); #else LogSystem.Error("StoryInstance::Init, isn't story DSL"); #endif } LogSystem.Debug("StoryInstance.Init message handler num:{0} {1}", m_MessageHandlers.Count, ret); return(ret); }
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"); } } }
public static void FinalParse(Dsl.DslInfo dslInfo) { string id = dslInfo.GetId(); if (id == "command") { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryCommandFactory factory = StoryCommandManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonCommands.CompositeCommand cmd = factory.Create() as StorySystem.CommonCommands.CompositeCommand; cmd.InitialCommands.Clear(); Dsl.FunctionData bodyFunc = null; for (int i = 0; i < dslInfo.GetFunctionNum(); ++i) { var funcData = dslInfo.GetFunction(i); var fid = funcData.GetId(); if (funcData.HaveStatement() && fid != "opts") { bodyFunc = funcData; } } if (null != bodyFunc) { for (int ix = 0; ix < bodyFunc.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = bodyFunc.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); cmd.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find command {0}'s body", name); } } else { LogSystem.Error("Can't find command {0}'s factory", name); } } else if (id == "value") { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryValueFactory factory = StoryValueManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonValues.CompositeValue val = factory.Build() as StorySystem.CommonValues.CompositeValue; val.InitialCommands.Clear(); Dsl.FunctionData bodyFunc = null; for (int i = 0; i < dslInfo.GetFunctionNum(); ++i) { var funcData = dslInfo.GetFunction(i); var fid = funcData.GetId(); if (funcData.HaveStatement() && fid != "opts") { bodyFunc = funcData; } } if (null != bodyFunc) { for (int ix = 0; ix < bodyFunc.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = bodyFunc.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); val.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find value {0}'s body", name); } } else { LogSystem.Error("Can't find value {0}'s factory", name); } } }