コード例 #1
0
        public override bool ParseArgs(IScenarioContent content, ref TextArgs args, out string error)
        {
            // text position text0 text1 ...;
            if (content.length < 3)
            {
                error = GetLengthErrorString();
                return(false);
            }

            string position = content[1].ToLower();

            if (position != "top" && position != "bottom" && position != "global")
            {
                error = string.Format(
                    "{0} ParseArgs error: position must be one of [top, bottom, global].",
                    typeName,
                    content[1]);
                return(false);
            }
            args.position = position;

            TextInfoConfig config  = TextInfoConfig.Get <TextInfoConfig>();
            StringBuilder  builder = new StringBuilder();

            int index = 2;

            while (index < content.length)
            {
                string line;
                if (content[index].StartsWith("\""))
                {
                    if (!ScenarioUtility.ParseContentString(content, ref index, out line, out error))
                    {
                        return(false);
                    }
                }
                else
                {
                    // 可能是个变量
                    int id = -1;
                    if (!ParseOrGetVarValue(content[index], ref id, out error))
                    {
                        return(false);
                    }

                    TextInfo info = config[id];
                    if (info == null)
                    {
                        error = string.Format(
                            "{0} ParseArgs error: text id `{1}` was not found.",
                            typeName,
                            content[index]);
                        return(false);
                    }

                    line = info.text;
                    index++;
                }
                builder.AppendLine(line);
            }

            args.text = builder.ToString();

            /// 从游戏设置中读取
            /// 最常见的形式是类似J-AVG快进的形式
            args.async = true;

            error = null;
            return(true);
        }
コード例 #2
0
        public override bool ParseArgs(IScenarioContent content, ref MenuArgs args, out string error)
        {
            /// menu option
            ///     option0
            ///     option1
            ///     ...;
            if (content.length < 3)
            {
                error = GetLengthErrorString();
                return(false);
            }

            // 获取使用的变量
            if (!RegexUtility.IsMatchVariable(content[1]))
            {
                error = GetMatchVariableErrorString(content[1]);
                return(false);
            }
            args.menuName = content[1];

            TextInfoConfig config  = TextInfoConfig.Get <TextInfoConfig>();
            List <string>  options = new List <string>();
            int            index   = 2;

            while (index < content.length)
            {
                string line;
                if (content[index].StartsWith("\""))
                {
                    if (!ScenarioUtility.ParseContentString(content, ref index, out line, out error))
                    {
                        return(false);
                    }
                }
                else
                {
                    // 可能是个变量
                    int id = -1;
                    if (!ParseOrGetVarValue(content[index], ref id, out error))
                    {
                        return(false);
                    }

                    TextInfo info = config[id];
                    if (info == null)
                    {
                        error = string.Format(
                            "{0} ParseArgs error: text id `{1}` was not found.",
                            typeName,
                            content[index]);
                        return(false);
                    }

                    line = info.text;
                    index++;
                }
                options.Add(line);
            }
            args.options = options.ToArray();

            error = null;
            return(true);
        }