예제 #1
0
        public IStoryCommandFactory FindFactory(StoryCommandGroupDefine group, string type)
        {
            IStoryCommandFactory factory = null;

            lock (m_Lock) {
                int ix = (int)group;
                if (ix >= 0 && ix < c_MaxCommandGroupNum)
                {
                    Dictionary <string, IStoryCommandFactory> factories = m_GroupedCommandFactories[ix];
                    factories.TryGetValue(type, out factory);
                }
            }
            return(factory);
        }
    /// <summary>
    /// 创建一个命令
    /// </summary>
    /// <param name="commandConfig"></param>
    /// <returns></returns>
    public IStoryCommand CreateCommand(ScriptableData.ISyntaxComponent commandConfig)
    {
        IStoryCommand        command = null;
        string               type    = commandConfig.GetId();
        IStoryCommandFactory factory = GetFactory(type);

        if (factory != null)
        {
            command = factory.Create(commandConfig);
        }
        else
        {
            m_log.Error("创建命令失败,命令类型:" + type);
        }
        return(command);
    }
 public void RegisterCommandFactory(string type, IStoryCommandFactory factory, bool replace)
 {
     lock (m_Lock) {
         if (!m_StoryCommandFactories.ContainsKey(type))
         {
             m_StoryCommandFactories.Add(type, factory);
         }
         else if (replace)
         {
             m_StoryCommandFactories[type] = factory;
         }
         else
         {
             //error
         }
     }
 }
 public void RegisterCommandFactory(StoryCommandGroupDefine group, string type, IStoryCommandFactory factory, bool replace)
 {
     lock (m_Lock) {
         int ix = (int)group;
         if (ix >= 0 && ix < c_MaxCommandGroupNum)
         {
             Dictionary <string, IStoryCommandFactory> factories = m_GroupedCommandFactories[ix];
             if (!factories.ContainsKey(type))
             {
                 factories.Add(type, factory);
             }
             else if (replace)
             {
                 factories[type] = factory;
             }
             else
             {
                 //error
             }
         }
     }
 }
        public static void FinalParse(Dsl.ISyntaxComponent dslInfo)
        {
            string id = dslInfo.GetId();

            if (id == "command")
            {
                string name      = string.Empty;
                var    first     = dslInfo as Dsl.FunctionData;
                var    statement = dslInfo as Dsl.StatementData;
                if (null != first)
                {
                    name = first.Call.GetParamId(0);
                }
                else
                {
                    if (null != statement)
                    {
                        first = statement.First;
                        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;
                    if (null != statement)
                    {
                        for (int i = 0; i < statement.GetFunctionNum(); ++i)
                        {
                            var funcData = statement.GetFunction(i);
                            var fid      = funcData.GetId();
                            if (funcData.HaveStatement() && fid != "opts")
                            {
                                bodyFunc = funcData;
                            }
                        }
                    }
                    else
                    {
                        bodyFunc = first;
                    }
                    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")
            {
                string name      = string.Empty;
                var    first     = dslInfo as Dsl.FunctionData;
                var    statement = dslInfo as Dsl.StatementData;
                if (null != first)
                {
                    name = first.Call.GetParamId(0);
                }
                else
                {
                    if (null != statement)
                    {
                        first = statement.First;
                        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;
                    if (null != statement)
                    {
                        for (int i = 0; i < statement.GetFunctionNum(); ++i)
                        {
                            var funcData = statement.GetFunction(i);
                            var fid      = funcData.GetId();
                            if (funcData.HaveStatement() && fid != "opts")
                            {
                                bodyFunc = funcData;
                            }
                        }
                    }
                    else
                    {
                        bodyFunc = first;
                    }
                    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);
                }
            }
        }
        public IStoryCommand CreateCommand(Dsl.ISyntaxComponent commandConfig)
        {
            Dsl.CallData callData = commandConfig as Dsl.CallData;
            if (null != callData)
            {
                if (callData.IsHighOrder)
                {
                    Dsl.CallData innerCall = callData.Call;
                    if (innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD ||
                        innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_BRACKET ||
                        innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE ||
                        innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET ||
                        innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS)
                    {
                        if (callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS)
                        {
                            //obj.member(a,b,...) or obj[member](a,b,...) or obj.(member)(a,b,...) or obj.[member](a,b,...) or obj.{member}(a,b,...) -> execinstance(obj,member,a,b,...)
                            Dsl.CallData newCall = new Dsl.CallData();
                            newCall.Name = new Dsl.ValueData("dotnetexec", Dsl.ValueData.ID_TOKEN);
                            newCall.SetParamClass((int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS);
                            if (innerCall.IsHighOrder)
                            {
                                newCall.Params.Add(innerCall.Call);
                                newCall.Params.Add(innerCall.GetParam(0));
                                for (int i = 0; i < callData.GetParamNum(); ++i)
                                {
                                    Dsl.ISyntaxComponent p = callData.Params[i];
                                    newCall.Params.Add(p);
                                }
                            }
                            else
                            {
                                newCall.Params.Add(innerCall.Name);
                                newCall.Params.Add(innerCall.GetParam(0));
                                for (int i = 0; i < callData.GetParamNum(); ++i)
                                {
                                    Dsl.ISyntaxComponent p = callData.Params[i];
                                    newCall.Params.Add(p);
                                }
                            }
                            return(CreateCommand(newCall));
                        }
                    }
                }
                else if ((callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_OPERATOR ||
                          callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_BRACKET ||
                          callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE ||
                          callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET ||
                          callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS) &&
                         callData.GetId() == "=")
                {
                    Dsl.CallData innerCall = callData.GetParam(0) as Dsl.CallData;
                    if (null != innerCall)
                    {
                        //obj.property = val  or obj[property] = val or obj.(property) = val or obj.[property] = val or obj.{property} = val -> setinstance(obj,property,val)
                        Dsl.CallData newCall = new Dsl.CallData();
                        newCall.Name = new Dsl.ValueData("dotnetset", Dsl.ValueData.ID_TOKEN);
                        newCall.SetParamClass((int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS);
                        if (innerCall.IsHighOrder)
                        {
                            newCall.Params.Add(innerCall.Call);
                            newCall.Params.Add(innerCall.GetParam(0));
                            newCall.Params.Add(callData.GetParam(1));
                        }
                        else
                        {
                            newCall.Params.Add(innerCall.Name);
                            newCall.Params.Add(innerCall.GetParam(0));
                            newCall.Params.Add(callData.GetParam(1));
                        }
                        return(CreateCommand(newCall));
                    }
                }
            }
            IStoryCommand command = null;
            string        type    = commandConfig.GetId();

            if (commandConfig.GetIdType() == Dsl.ValueData.ID_TOKEN)
            {
                IStoryCommandFactory factory = GetFactory(type);
                if (null != factory)
                {
                    try {
                        command = factory.Create();
                        if (!command.Init(commandConfig))
                        {
                            GameFramework.LogSystem.Error("[LoadStory] command:{0}[{1}] line:{2} failed.", type, commandConfig.ToScriptString(false), commandConfig.GetLine());
                        }
                    } catch (Exception ex) {
                        GameFramework.LogSystem.Error("[LoadStory] command:{0}[{1}] line:{2} failed.", type, commandConfig.ToScriptString(false), commandConfig.GetLine());
                        throw ex;
                    }
                }
                else
                {
#if DEBUG
                    string err = string.Format("[LoadStory] CreateCommand failed, line:{0} command:{1}[{2}]", commandConfig.GetLine(), type, commandConfig.ToScriptString(false));
                    GameFramework.LogSystem.Error("{0}", err);
                    throw new Exception(err);
#else
                    GameFramework.LogSystem.Error("[LoadStory] CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine());
#endif
                }
                if (null != command)
                {
                    //GameFramework.LogSystem.Debug("[LoadStory] CreateCommand, type:{0} command:{1}", type, command.GetType().Name);
                }
                else
                {
#if DEBUG
                    string err = string.Format("[LoadStory] CreateCommand failed, line:{0} command:{1}[{2}]", commandConfig.GetLine(), type, commandConfig.ToScriptString(false));
                    GameFramework.LogSystem.Error("{0}", err);
                    throw new Exception(err);
#else
                    GameFramework.LogSystem.Error("[LoadStory] CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine());
#endif
                }
            }
            return(command);
        }
 public void RegisterCommandFactory(StoryCommandGroupDefine group, string type, IStoryCommandFactory factory)
 {
     RegisterCommandFactory(group, type, factory, false);
 }
 public void RegisterCommandFactory(string type, IStoryCommandFactory factory)
 {
     RegisterCommandFactory(type, factory, false);
 }
예제 #9
0
        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 void RegisterCommandFactory(StoryCommandGroupDefine group, string type, IStoryCommandFactory factory, bool replace)
 {
     lock (m_Lock) {
         int ix = (int)group;
         if (ix >= 0 && ix < c_MaxCommandGroupNum) {
             Dictionary<string, IStoryCommandFactory> factories = m_GroupedCommandFactories[ix];
             if (!factories.ContainsKey(type)) {
                 factories.Add(type, factory);
             } else if (replace) {
                 factories[type] = factory;
             } else {
                 //error
             }
         }
     }
 }
 public void RegisterCommandFactory(StoryCommandGroupDefine group, string type, IStoryCommandFactory factory)
 {
     RegisterCommandFactory(group, type, factory, false);
 }
 public void RegisterCommandFactory(string type, IStoryCommandFactory factory, bool replace)
 {
     lock (m_Lock) {
         if (!m_StoryCommandFactories.ContainsKey(type)) {
             m_StoryCommandFactories.Add(type, factory);
         } else if (replace) {
             m_StoryCommandFactories[type] = factory;
         } else {
             //error
         }
     }
 }
 public void RegisterCommandFactory(string type, IStoryCommandFactory factory)
 {
     RegisterCommandFactory(type, factory, false);
 }
예제 #14
0
        public IStoryCommand CreateCommand(Dsl.ISyntaxComponent commandConfig)
        {
            IStoryCommand command = null;

            lock (m_Lock) {
                Dsl.StatementData statementData = commandConfig as Dsl.StatementData;
                if (null != statementData)
                {
                    Dsl.FunctionData func;
                    if (DslSyntaxTransformer.TryTransformCommandLineLikeSyntax(statementData, out func))
                    {
                        commandConfig = func;
                    }
                }
                Dsl.FunctionData callData = commandConfig as Dsl.FunctionData;
                if (null != callData)
                {
                    if (callData.IsHighOrder)
                    {
                        Dsl.FunctionData innerCall = callData.LowerOrderFunction;
                        if (innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD ||
                            innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET ||
                            innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE ||
                            innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET ||
                            innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS)
                        {
                            if (callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS)
                            {
                                //obj.member(a,b,...) or obj[member](a,b,...) or obj.(member)(a,b,...) or obj.[member](a,b,...) or obj.{member}(a,b,...) -> execinstance(obj,member,a,b,...)
                                Dsl.FunctionData newCall = new Dsl.FunctionData();
                                if (innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD)
                                {
                                    newCall.Name = new Dsl.ValueData("dotnetexec", Dsl.ValueData.ID_TOKEN);
                                }
                                else
                                {
                                    newCall.Name = new Dsl.ValueData("collectionexec", Dsl.ValueData.ID_TOKEN);
                                }
                                newCall.SetParamClass((int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS);
                                if (innerCall.IsHighOrder)
                                {
                                    newCall.Params.Add(innerCall.LowerOrderFunction);
                                    newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass()));
                                    for (int i = 0; i < callData.GetParamNum(); ++i)
                                    {
                                        Dsl.ISyntaxComponent p = callData.Params[i];
                                        newCall.Params.Add(p);
                                    }
                                }
                                else
                                {
                                    newCall.Params.Add(innerCall.Name);
                                    newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass()));
                                    for (int i = 0; i < callData.GetParamNum(); ++i)
                                    {
                                        Dsl.ISyntaxComponent p = callData.Params[i];
                                        newCall.Params.Add(p);
                                    }
                                }
                                return(CreateCommand(newCall));
                            }
                        }
                    }
                    else if (callData.GetId() == "=")
                    {
                        Dsl.FunctionData innerCall = callData.GetParam(0) as Dsl.FunctionData;
                        if (null != innerCall && (innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD ||
                                                  innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET ||
                                                  innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE ||
                                                  innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET ||
                                                  innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS))
                        {
                            //obj.property = val  or obj[property] = val or obj.(property) = val or obj.[property] = val or obj.{property} = val -> setinstance(obj,property,val)
                            Dsl.FunctionData newCall = new Dsl.FunctionData();
                            if (innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD)
                            {
                                newCall.Name = new Dsl.ValueData("dotnetset", Dsl.ValueData.ID_TOKEN);
                            }
                            else
                            {
                                newCall.Name = new Dsl.ValueData("collectionset", Dsl.ValueData.ID_TOKEN);
                            }
                            newCall.SetParamClass((int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS);
                            if (innerCall.IsHighOrder)
                            {
                                newCall.Params.Add(innerCall.LowerOrderFunction);
                                newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass()));
                                newCall.Params.Add(callData.GetParam(1));
                            }
                            else
                            {
                                newCall.Params.Add(innerCall.Name);
                                newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass()));
                                newCall.Params.Add(callData.GetParam(1));
                            }
                            return(CreateCommand(newCall));
                        }
                    }
                }
                string type = commandConfig.GetId();
                if (commandConfig.GetIdType() == Dsl.ValueData.ID_TOKEN && type != "true" && type != "false")
                {
                    IStoryCommandFactory factory = GetFactory(type);
                    if (null != factory)
                    {
                        try {
                            command = factory.Create();
                            if (!command.Init(commandConfig))
                            {
                                GameFramework.LogSystem.Error("[LoadStory] command:{0}[{1}] line:{2} failed.", type, commandConfig.ToScriptString(false), commandConfig.GetLine());
                            }
                        }
                        catch (Exception ex) {
                            var msg = string.Format("[LoadStory] command:{0}[{1}] line:{2} failed.", type, commandConfig.ToScriptString(false), commandConfig.GetLine());
                            throw new Exception(msg, ex);
                        }
                    }
                    else
                    {
#if DEBUG
                        string err = string.Format("[LoadStory] CreateCommand failed, line:{0} command:{1}[{2}]", commandConfig.GetLine(), type, commandConfig.ToScriptString(false));
                        GameFramework.LogSystem.Error("{0}", err);
                        throw new Exception(err);
#else
                        GameFramework.LogSystem.Error("[LoadStory] CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine());
#endif
                    }
                    if (null != command)
                    {
                        //GameFramework.LogSystem.Debug("[LoadStory] CreateCommand, type:{0} command:{1}", type, command.GetType().Name);
                    }
                    else
                    {
#if DEBUG
                        string err = string.Format("[LoadStory] CreateCommand failed, line:{0} command:{1}[{2}]", commandConfig.GetLine(), type, commandConfig.ToScriptString(false));
                        GameFramework.LogSystem.Error("{0}", err);
                        throw new Exception(err);
#else
                        GameFramework.LogSystem.Error("[LoadStory] CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine());
#endif
                    }
                }
            }
            return(command);
        }