Пример #1
0
        private bool LoadVelocity(ConfigSection section)
        {
            if (section == null)
            {
                return(false);
            }

            Dictionary <string, List <float> > keyValue = new Dictionary <string, List <float> >();

            for (int i = 0; i < section.ContentListCount; ++i)
            {
                string       key;
                List <float> values = new List <float>();
                if (section.GetKeyValue(i, out key, values))
                {
                    if (keyValue.ContainsKey(key))
                    {
                        keyValue[key] = values;
                    }
                    else
                    {
                        keyValue.Add(key, values);
                    }
                }
            }

            GetKeyValue(keyValue, "walk.fwd", out ForwardWalkSpeed);
            GetKeyValue(keyValue, "walk.back", out BackWalkSpeed);
            GetKeyValue(keyValue, "run.fwd", out ForwardRunSpeed);
            GetKeyValue(keyValue, "run.fwd", out BackRunSpeed);

            return(true);
        }
Пример #2
0
        private bool LoadSize(ConfigSection section)
        {
            if (section == null)
            {
                return(false);
            }

            Dictionary <string, List <float> > keyValue = new Dictionary <string, List <float> >();

            for (int i = 0; i < section.ContentListCount; ++i)
            {
                string       key;
                List <float> values = new List <float>();
                if (section.GetKeyValue(i, out key, values))
                {
                    if (keyValue.ContainsKey(key))
                    {
                        keyValue[key] = values;
                    }
                    else
                    {
                        keyValue.Add(key, values);
                    }
                }
            }

            GetKeyValue(keyValue, "xscale", out XScale);
            GetKeyValue(keyValue, "yscale", out YScale);
            GetKeyValue(keyValue, "ground.front", out GuardForwardNear);
            GetKeyValue(keyValue, "ground.back", out GuardBackNear);
            GetKeyValue(keyValue, "air.front", out AirForwardNear);
            GetKeyValue(keyValue, "air.back", out AirBackNear);

            return(true);
        }
Пример #3
0
        public bool LoadFromReader(ConfigReader reader)
        {
            Clear();
            if (reader == null)
            {
                return(false);
            }

            ConfigSection section = reader.GetSection("Remap");

            if (section != null)
            {
                m_Remap = new Cmd_Remap();
                if (!section.GetPropertysValues(m_Remap))
                {
                    m_Remap = null;
                }
            }

            section = reader.GetSection("Defaults");
            if (section != null)
            {
                for (int i = 0; i < section.ContentListCount; ++i)
                {
                    string key, value;
                    if (section.GetKeyValue(i, out key, out value))
                    {
                        if (string.Compare(key, "command.time", true) == 0)
                        {
                            m_Command__Time = int.Parse(value);
                        }
                        else if (string.Compare(key, "command.buffer.time", true) == 0)
                        {
                            m_Command__Buffer__Time = int.Parse(value);
                        }
                    }
                }
            }

            // 创建Command
            for (int i = 0; i < reader.SectionCount; ++i)
            {
                section = reader.GetSections(i);
                if (section == null)
                {
                    continue;
                }
                if (string.Compare(section.Tile, "Command", true) == 0)
                {
                    Cmd_Command cmd = null;
                    for (int j = 0; j < section.ContentListCount; ++j)
                    {
                        string key, value;
                        if (section.GetKeyValue(j, out key, out value))
                        {
                            if (string.Compare(key, "name", true) == 0)
                            {
                                if (cmd == null)
                                {
                                    cmd = new Cmd_Command();
                                }
                                cmd.name = value;
                            }
                            else if (string.Compare(key, "time", true) == 0)
                            {
                                if (cmd == null)
                                {
                                    cmd = new Cmd_Command();
                                }
                                cmd.time = int.Parse(value);
                            }
                            else if (string.Compare(key, "buffer.time", true) == 0)
                            {
                                if (cmd == null)
                                {
                                    cmd = new Cmd_Command();
                                }
                                cmd.buffer__time = int.Parse(value);
                            }
                            else if (string.Compare(key, "command", true) == 0)
                            {
                                if (cmd == null)
                                {
                                    cmd = new Cmd_Command();
                                }
                                cmd.keyCommands = ConfigSection.Split(value);
                            }
                        }
                    }
                    if (cmd != null && !string.IsNullOrEmpty(cmd.name))
                    {
                        AddCommand(cmd);
                    }
                }
                else if (section.Tile.StartsWith("State -1", StringComparison.CurrentCultureIgnoreCase))
                {
                    string[] names = ConfigSection.Split(section.Tile);
                    if (names == null || names.Length < 2)
                    {
                        continue;
                    }

                    string     aiName = names [1];
                    AI_Type    aiType = AI_Type.none;
                    AI_Command aiCmd  = null;

                    for (int j = 0; j < section.ContentListCount; ++j)
                    {
                        string key, value;
                        if (section.GetKeyValue(j, out key, out value))
                        {
                            if (string.Compare(key, "type", true) == 0)
                            {
                                if (string.Compare(value, "ChangeState", true) == 0)
                                {
                                    aiType = AI_Type.ChangeState;
                                    if (aiCmd == null)
                                    {
                                        aiCmd      = new AI_Command();
                                        aiCmd.type = aiType;
                                        aiCmd.name = aiName;
                                    }
                                }
                            }
                            else
                            {
                                if (aiCmd == null)
                                {
                                    continue;
                                }
                                if (string.Compare(key, "value", true) == 0)
                                {
                                    aiCmd.value = value;
                                }
                                else if (string.Compare(key, "triggerall", true) == 0)
                                {
                                    if (value.StartsWith("command", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        int idx = value.IndexOf("=");
                                        if (idx >= 0)
                                        {
                                            aiCmd.command = value.Substring(idx + 1, value.Length - idx - 1).Trim();
                                            if (!string.IsNullOrEmpty(aiCmd.command))
                                            {
                                                Cmd_Command cmdCmd = GetCommand(aiCmd.command);
                                                if (cmdCmd != null)
                                                {
                                                    cmdCmd.aiName = aiCmd.name;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }


                    if (aiCmd == null || aiCmd.type == AI_Type.none)
                    {
                        continue;
                    }
                    if (m_AICmdMap == null)
                    {
                        m_AICmdMap = new Dictionary <string, AI_Command> ();
                    }
                    m_AICmdMap [aiCmd.name] = aiCmd;
                }
            }

            return(true);
        }
Пример #4
0
        private bool ReadClsn(out Rect[] clsn2DArr, ConfigSection section, ref int aniStartIdx, string clsnName, string clsnKeyName)
        {
            clsn2DArr = null;
            if (string.IsNullOrEmpty(clsnName))
            {
                return(false);
            }
            string str = section.GetContent(aniStartIdx);

            if (string.IsNullOrEmpty(str))
            {
                clsn2DArr = null;
                return(false);
            }

            bool ret = false;

            if (str.StartsWith(clsnName))
            {
                string defClsStr = str.Substring(clsnName.Length).Trim();
                int    defClsCnt;
                if (!int.TryParse(defClsStr, out defClsCnt))
                {
                    clsn2DArr = null;
                    return(false);
                }
                if (defClsCnt > 0)
                {
                    clsn2DArr = new Rect[defClsCnt];
                    for (int i = aniStartIdx + 1; i <= aniStartIdx + defClsCnt; ++i)
                    {
                        string key;
                        string value;
                        if (section.GetKeyValue(i, out key, out value))
                        {
                            if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                            {
                                int idx = key.IndexOf(clsnKeyName, StringComparison.CurrentCultureIgnoreCase);
                                if (idx >= 0)
                                {
                                    key = key.Substring(idx + clsnKeyName.Length);
                                    int startIdx = key.IndexOf("[");
                                    int endIdx   = key.IndexOf("]");
                                    if (startIdx >= 0 && endIdx >= 0 && endIdx > startIdx + 1)
                                    {
                                        string idxStr = key.Substring(startIdx + 1, endIdx - startIdx - 1);
                                        if (!string.IsNullOrEmpty(idxStr))
                                        {
                                            idxStr = idxStr.Trim();
                                            if (!string.IsNullOrEmpty(idxStr))
                                            {
                                                int index = int.Parse(idxStr);
                                                if (index >= 0 && index < clsn2DArr.Length)
                                                {
                                                    string[] values = value.Split(ConfigSection._cContentArrSplit, StringSplitOptions.RemoveEmptyEntries);
                                                    if (values != null && values.Length > 0)
                                                    {
                                                        Rect r = new Rect();
                                                        if (values.Length >= 4)
                                                        {
                                                            string v    = values[0].Trim();
                                                            int    left = int.Parse(v);
                                                            v = values[1].Trim();
                                                            int top = int.Parse(v);
                                                            v = values[2].Trim();
                                                            int right = int.Parse(v);
                                                            v = values[3].Trim();
                                                            int bottom = int.Parse(v);
                                                            r.min = new Vector2(left, top);
                                                            r.max = new Vector2(right, bottom);
                                                        }
                                                        clsn2DArr[index] = r;
                                                        ret = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    aniStartIdx += defClsCnt + 1;
                }
            }

            if (!ret)
            {
                clsn2DArr = null;
            }

            return(ret);
        }
Пример #5
0
        public bool LoadConfigReader(ConfigSection section)
        {
            ResetVars();
            if (section == null)
            {
                return(false);
            }

            for (int i = 0; i < section.ContentListCount; ++i)
            {
                string key, value;
                if (section.GetKeyValue(i, out key, out value))
                {
                    if (string.Compare(key, "type", true) == 0)
                    {
                        if (string.Compare(value, "S", true) == 0)
                        {
                            m_Type = Cns_Type.S;
                        }
                        else if (string.Compare(value, "C", true) == 0)
                        {
                            m_Type = Cns_Type.C;
                        }
                        else if (string.Compare(value, "A", true) == 0)
                        {
                            m_Type = Cns_Type.A;
                        }
                        else if (string.Compare(value, "L", true) == 0)
                        {
                            m_Type = Cns_Type.L;
                        }
                        else
                        {
                            m_Type = Cns_Type.none;
                        }
                    }
                    else if (string.Compare(key, "movetype", true) == 0)
                    {
                        if (string.Compare(value, "A", true) == 0)
                        {
                            m_MoveType = Cns_MoveType.A;
                        }
                        else if (string.Compare(value, "I", true) == 0)
                        {
                            m_MoveType = Cns_MoveType.I;
                        }
                        else if (string.Compare(value, "H", true) == 0)
                        {
                            m_MoveType = Cns_MoveType.H;
                        }
                        else
                        {
                            m_MoveType = Cns_MoveType.none;
                        }
                    }
                    else if (string.Compare(key, "physics", true) == 0)
                    {
                        if (string.Compare(value, "S", true) == 0)
                        {
                            m_PhysicsType = Cns_PhysicsType.S;
                        }
                        else if (string.Compare(value, "C", true) == 0)
                        {
                            m_PhysicsType = Cns_PhysicsType.C;
                        }
                        else if (string.Compare(value, "A", true) == 0)
                        {
                            m_PhysicsType = Cns_PhysicsType.A;
                        }
                        else
                        {
                            m_PhysicsType = Cns_PhysicsType.none;
                        }
                    }
                    else if (string.Compare(key, "juggle", true) == 0)
                    {
                        m_Juggle = int.Parse(value);
                    }
                    else if (string.Compare(key, "velset", true) == 0)
                    {
                        string[] vs1 = ConfigSection.Split(value);
                        if (vs1 != null && vs1.Length >= 2)
                        {
                            m_Velset_x = float.Parse(vs1 [0]);
                            m_Velset_y = float.Parse(vs1 [1]);
                        }
                    }
                    else if (string.Compare(key, "ctrl", true) == 0)
                    {
                        m_Ctrl = int.Parse(value);
                    }
                    else if (string.Compare(key, "anim", true) == 0)
                    {
                        m_Anim = int.Parse(value);
                    }
                    else if (string.Compare(key, "facep2", true) == 0)
                    {
                        m_FaceP2 = int.Parse(value);
                    }
                }
            }

            return(true);
        }