示例#1
0
        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);
            }
        }
        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);
                }
            }
        }