name(arg1,arg2,...);
这里的Name、ArgNames与InitialCommands为同一command定义的各个调用共享。 由于解析时需要处理交叉引用,先克隆后Load。 这里的自定义命令支持挂起-恢复执行或递归(性能较低,仅处理小规模问题),但 二者不能同时使用。 注意:所有依赖InitialCommands等共享数据的其它成员,初始化需要写成lazy的样式,不要在Clone与Load里初始化,因为 此时共享数据可能还不完整!
Inheritance: AbstractStoryCommand
コード例 #1
0
 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);
         }
     }
 }
コード例 #2
0
 public override IStoryCommand Clone()
 {
     CompositeCommand cmd = new CompositeCommand();
     cmd.m_LoadedArgs = m_LoadedArgs;
     cmd.m_Name = m_Name;
     cmd.m_ArgNames=m_ArgNames;
     cmd.m_InitialCommands=m_InitialCommands;
     cmd.IsCompositeCommand = true;
     if (null == cmd.m_LeadCommand) {
         cmd.m_LeadCommand = new CompositeCommandHelper(cmd);
     }
     return cmd;
 }
コード例 #3
0
        public override IStoryCommand Clone()
        {
            CompositeCommand cmd = new CompositeCommand();

            cmd.m_LoadedArgs       = m_LoadedArgs;
            cmd.m_Name             = m_Name;
            cmd.m_ArgNames         = m_ArgNames;
            cmd.m_InitialCommands  = m_InitialCommands;
            cmd.IsCompositeCommand = true;
            if (null == cmd.m_LeadCommand)
            {
                cmd.m_LeadCommand = new CompositeCommandHelper(cmd);
            }
            return(cmd);
        }
コード例 #4
0
        protected override IStoryCommand CloneCommand()
        {
            CompositeCommand cmd = new CompositeCommand();

            cmd.m_LoadedArgs      = m_LoadedArgs;
            cmd.m_LoadedOptArgs   = m_LoadedOptArgs;
            cmd.m_Name            = m_Name;
            cmd.m_ArgNames        = m_ArgNames;
            cmd.m_OptArgs         = m_OptArgs;
            cmd.m_InitialCommands = m_InitialCommands;
            if (null == cmd.m_PrologueCommand)
            {
                cmd.m_PrologueCommand = new CompositePrologueCommandHelper(cmd);
            }
            if (null == cmd.m_EpilogueCommand)
            {
                cmd.m_EpilogueCommand = new CompositeEpilogueCommandHelper(cmd);
            }
            return(cmd);
        }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
0
        public static void FirstParse(Dsl.ISyntaxComponent dslInfo)
        {
            string id = dslInfo.GetId();

            if (id == "command")
            {
                StorySystem.CommonCommands.CompositeCommand cmd = new CommonCommands.CompositeCommand();
                cmd.InitSharedData();
                var first = dslInfo as Dsl.FunctionData;
                if (null != first)
                {
                    cmd.Name = first.Call.GetParamId(0);
                }
                else
                {
                    var statement = dslInfo as Dsl.StatementData;
                    if (null != statement)
                    {
                        first    = statement.First;
                        cmd.Name = first.Call.GetParamId(0);
                        for (int i = 1; i < statement.GetFunctionNum(); ++i)
                        {
                            var funcData = statement.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));
                                    }
                                }
                            }
                            else if (fid == "body")
                            {
                            }
                            else
                            {
                                LogSystem.Error("Command {0} unknown part '{1}'", cmd.Name, fid);
                            }
                        }
                    }
                }
                //注册
                StoryCommandManager.Instance.RegisterCommandFactory(cmd.Name, new CommonCommands.CompositeCommandFactory(cmd), true);
            }
            else if (id == "value")
            {
                StorySystem.CommonValues.CompositeValue val = new CommonValues.CompositeValue();
                val.InitSharedData();
                var first = dslInfo as Dsl.FunctionData;
                if (null != first)
                {
                    val.Name = first.Call.GetParamId(0);
                }
                else
                {
                    var statement = dslInfo as Dsl.StatementData;
                    if (null != statement)
                    {
                        first    = statement.First;
                        val.Name = first.Call.GetParamId(0);
                        for (int i = 1; i < statement.GetFunctionNum(); ++i)
                        {
                            var funcData = statement.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));
                                    }
                                }
                            }
                            else if (fid == "body")
                            {
                            }
                            else
                            {
                                LogSystem.Error("Value {0} unknown part '{1}'", val.Name, fid);
                            }
                        }
                    }
                }
                //注册
                StoryValueManager.Instance.RegisterValueFactory(val.Name, new CommonValues.CompositeValueFactory(val), true);
            }
        }
コード例 #7
0
 public CompositeEpilogueCommandHelper(CompositeCommand cmd)
 {
     m_Cmd = cmd;
 }
コード例 #8
0
 internal CompositeCommandFactory(CompositeCommand cmd)
 {
     m_Cmd = cmd;
 }
コード例 #9
0
 public CompositeCommandHelper(CompositeCommand cmd)
 {
     m_Cmd = cmd;
 }
コード例 #10
0
 internal CompositeCommandFactory(CompositeCommand cmd)
 {
     m_Cmd = cmd;
 }