Example #1
0
        public bool LoadFromFile(string fileName)
        {
            Reset();
            string str = AppConfig.GetInstance().Loader.LoadText(fileName);

            if (str == null || string.IsNullOrEmpty(str))
            {
                return(false);
            }
            ConfigReader reader = new ConfigReader();

            reader.LoadString(str);

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

            if (section != null)
            {
                if (!LoadVelocity(section))
                {
                    return(false);
                }
            }

            section = reader.GetSection("Size");
            if (section != null)
            {
                if (!LoadSize(section))
                {
                    return(false);
                }
            }

            string dd  = "Statedef";
            string ddd = "State";

            for (int i = 0; i < reader.SectionCount; ++i)
            {
                section = reader.GetSections(i);
                if (section == null || string.IsNullOrEmpty(section.Tile))
                {
                    continue;
                }
                CNSStateDef parent = null;
                if (section.Tile.StartsWith(dd, StringComparison.CurrentCultureIgnoreCase))
                {
                    string name = section.Tile.Substring(dd.Length);
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    name = name.Trim();
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    CNSStateDef def = new CNSStateDef();
                    if (def.LoadConfigReader(section))
                    {
                        AddStateDef(name, def);
                        parent = def;
                    }
                    else
                    {
                        parent = null;
                        continue;
                    }
                }

                if (section.Tile.StartsWith(ddd, StringComparison.CurrentCultureIgnoreCase))
                {
                    if (parent == null)
                    {
                        continue;
                    }
                }
            }

            return(true);
        }
Example #2
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);
        }
Example #3
0
        public BeginAction(/*PlayerState state, */ ConfigSection section)
        {
            //this.State = state;
            if (section != null)
            {
                int    aniStartIdx     = 0;
                Rect[] clsn2DefaultArr = null;

                ReadClsn(out clsn2DefaultArr, section, ref aniStartIdx, _cClsn2Default, _cClsn2DKeyName);


                string str        = section.GetContent(aniStartIdx);
                Rect[] frameClsn2 = null;
                Rect[] frameClsn1 = null;
                if (!string.IsNullOrEmpty(str))
                {
                    List <string> arr         = new List <string>();
                    bool          isLoopStart = false;
                    int           i           = aniStartIdx;
                    while (i < section.ContentListCount)
                    {
                        arr.Clear();

                        string line = section.GetContent(i);
                        if (string.IsNullOrEmpty(line))
                        {
                            ++i;
                            continue;
                        }

                        if (line.StartsWith("Loopstart", StringComparison.CurrentCultureIgnoreCase))
                        {
                            isLoopStart = true;
                            ++i;
                            continue;
                        }

                        // 说明需要设置默认clsDefault
                        if (line.StartsWith(_cClsn2Default))
                        {
                            aniStartIdx = i;
                            if (ReadClsn(out clsn2DefaultArr, section, ref aniStartIdx, _cClsn2Default, _cClsn2DKeyName))
                            {
                                i = aniStartIdx;
                            }
                            else
                            {
                                ++i;
                            }
                            continue;
                        }

                        if (line.StartsWith(_cClsn2))
                        {
                            aniStartIdx = i;
                            if (ReadClsn(out frameClsn2, section, ref aniStartIdx, _cClsn2, _cClsn2DKeyName))
                            {
                                i = aniStartIdx;
                            }
                            else
                            {
                                ++i;
                            }
                            continue;
                        }

                        if (line.StartsWith(_cClsn1))
                        {
                            aniStartIdx = i;
                            if (ReadClsn(out frameClsn1, section, ref aniStartIdx, _cClsn1, _cClsn1DKeyName))
                            {
                                i = aniStartIdx;
                            }
                            else
                            {
                                ++i;
                            }
                            continue;
                        }

                        if (section.GetArray(i, arr))
                        {
                            if (arr.Count >= 5)
                            {
                                int        ImageGroup = GetIntFromStr(arr[0], -1);
                                int        ImageIndex = GetIntFromStr(arr[1], -1);
                                int        Tick       = int.Parse(arr[4].Trim());
                                bool       hasFlip    = arr.Count >= 6;
                                ActionFlip flipMode   = ActionFlip.afNone;
                                if (hasFlip)
                                {
                                    string flipStr = arr[5].Trim();
                                    if (string.Compare(flipStr, "H", true) == 0)
                                    {
                                        flipMode = ActionFlip.afH;
                                    }
                                    else if (string.Compare(flipStr, "V", true) == 0)
                                    {
                                        flipMode = ActionFlip.afV;
                                    }
                                    else if (string.Compare(flipStr, "HV", true) == 0 ||
                                             string.Compare(flipStr, "VH", true) == 0)
                                    {
                                        flipMode = ActionFlip.afHV;
                                    }
                                }

                                ActionFrame frame = new ActionFrame();
                                frame.Group = ImageGroup;
                                frame.Index = ImageIndex;
                                frame.Tick  = Tick;
                                frame.Flip  = flipMode;
                                if (aniStartIdx > 0 && clsn2DefaultArr != null)
                                {
                                    frame.defaultClsn2Arr = clsn2DefaultArr;
                                    clsn2DefaultArr       = null;
                                }
                                if (frameClsn2 != null)
                                {
                                    frame.localClsn2Arr = frameClsn2;
                                    frameClsn2          = null;
                                }
                                if (frameClsn1 != null)
                                {
                                    frame.localCls1Arr = frameClsn1;
                                    frameClsn1         = null;
                                }
                                if (isLoopStart)
                                {
                                    frame.IsLoopStart = isLoopStart;
                                    isLoopStart       = false;
                                }
                                ActionFrameList.Add(frame);
                            }
                        }
                        ++i;
                    }
                }
            }
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
0
 public void AttachKeyCommands(string keys)
 {
     keyCommands = ConfigSection.Split(keys);
 }