Exemple #1
0
        public void LoadString(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return;
            }
            ConfigReader reader = new ConfigReader();

            reader.LoadString(str);
            var section = reader.GetSection("Files");

            if (section == null)
            {
                return;
            }
            mPlayerFiles = new PlayerFiles();
            if (!section.GetPropertysValues(mPlayerFiles))
            {
                mPlayerFiles = null;
            }

            section     = reader.GetSection("Info");
            mPlayerInfo = new PlayerInfo();
            if (section != null)
            {
                if (!section.GetPropertysValues(mPlayerInfo))
                {
                    mPlayerInfo = null;
                }
                else
                {
                    for (int i = 0; i < section.ContentListCount; ++i)
                    {
                        string key, value;
                        if (section.GetKeyValue(i, out key, out value))
                        {
                            if (string.Compare(key, "localcoord", true) == 0)
                            {
                                string[] vals = ConfigSection.Split(value);
                                if (vals != null && vals.Length >= 2)
                                {
                                    mPlayerInfo.designWidth  = int.Parse(vals[0]);
                                    mPlayerInfo.designHeight = int.Parse(vals[1]);
                                }
                            }
                            else if (string.Compare(key, "pal.defaults", true) == 0)
                            {
                                if (mPlayerFiles.HasPal)
                                {
                                    continue;
                                }
                                string[] vals = ConfigSection.Split(value);
                                if (vals != null && vals.Length > 0)
                                {
                                    if (vals.Length >= 1)
                                    {
                                        mPlayerFiles.pal1 = vals[0];
                                    }
                                    if (vals.Length >= 2)
                                    {
                                        mPlayerFiles.pal2 = vals[1];
                                    }
                                    if (vals.Length >= 3)
                                    {
                                        mPlayerFiles.pal3 = vals[2];
                                    }
                                    if (vals.Length >= 4)
                                    {
                                        mPlayerFiles.pal4 = vals[3];
                                    }
                                    if (vals.Length >= 5)
                                    {
                                        mPlayerFiles.pal5 = vals[4];
                                    }
                                    if (vals.Length >= 6)
                                    {
                                        mPlayerFiles.pal6 = vals[5];
                                    }
                                    if (vals.Length >= 7)
                                    {
                                        mPlayerFiles.pal7 = vals[6];
                                    }
                                    if (vals.Length >= 8)
                                    {
                                        mPlayerFiles.pal8 = vals[7];
                                    }
                                    if (vals.Length >= 9)
                                    {
                                        mPlayerFiles.pal9 = vals[8];
                                    }
                                    if (vals.Length >= 10)
                                    {
                                        mPlayerFiles.pal10 = vals[9];
                                    }
                                    if (vals.Length >= 11)
                                    {
                                        mPlayerFiles.pal11 = vals[10];
                                    }
                                    if (vals.Length >= 12)
                                    {
                                        mPlayerFiles.pal12 = vals[11];
                                    }

                                    mPlayerFiles.IsDefaultPal = true;
                                }
                            }
                        }
                    }
                }
            }
            section = reader.GetSection("Palette Keymap");
            mKeyMap = new PalletKeyMap();
            if (section != null)
            {
                if (!section.GetPropertysValues(mKeyMap))
                {
                    mKeyMap = null;
                }
            }
        }
Exemple #2
0
        public bool LoadFromReader(ConfigReader reader)
        {
            if (reader == null)
            {
                return(false);
            }

            for (int i = 0; i < reader.SectionCount; ++i)
            {
                var section = reader.GetSections(i);
                if (section == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(section.Tile))
                {
                    continue;
                }
                if (!section.Tile.StartsWith(_cBG, System.StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                string       name       = section.Tile.Substring(_cBG.Length).Trim();
                BgStaticInfo staticInfo = null;
                BgAniInfo    aniInfo    = null;
                BgType       bgType     = BgType.none;
                for (int j = 0; j < section.ContentListCount; ++j)
                {
                    string key, value;
                    if (!section.GetKeyValue(j, out key, out value))
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
                    {
                        continue;
                    }
                    if (key.StartsWith("type", System.StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (string.Compare(value, "normal", true) == 0)
                        {
                            bgType            = BgType.normal;
                            staticInfo        = new BgStaticInfo();
                            staticInfo.name   = name;
                            staticInfo.bgType = bgType;
                            if (m_BgList == null)
                            {
                                m_BgList = new List <IBg>();
                            }
                            m_BgList.Add(staticInfo);
                            continue;
                        }
                        else if (string.Compare(value, "anim", true) == 0)
                        {
                            bgType         = BgType.anim;
                            aniInfo        = new BgAniInfo();
                            aniInfo.name   = name;
                            aniInfo.bgType = bgType;
                            if (m_BgList == null)
                            {
                                m_BgList = new List <IBg>();
                            }
                            m_BgList.Add(aniInfo);
                            continue;
                        }
                    }

                    if (bgType == BgType.none)
                    {
                        continue;
                    }

                    if (bgType == BgType.normal)
                    {
                        string[] arr = null;
                        if (string.Compare(key, "spriteno", true) == 0)
                        {
                            arr = value.Split(ConfigSection._cContentArrSplit, System.StringSplitOptions.RemoveEmptyEntries);
                            if (arr != null && arr.Length >= 2)
                            {
                                staticInfo.srpiteno_Group = int.Parse(arr[0]);
                                staticInfo.spriteno_Image = int.Parse(arr[1]);
                            }
                        }
                        else if (string.Compare(key, "layerno", true) == 0)
                        {
                            staticInfo.layerno = int.Parse(value);
                        }
                        else if (string.Compare(key, "start", true) == 0)
                        {
                            arr = value.Split(ConfigSection._cContentArrSplit, System.StringSplitOptions.RemoveEmptyEntries);
                            if (arr != null && arr.Length >= 2)
                            {
                                staticInfo.start_x = int.Parse(arr[0]);
                                staticInfo.start_y = int.Parse(arr[1]);
                            }
                        }
                        else if (string.Compare(key, "delta", true) == 0)
                        {
                            arr = value.Split(ConfigSection._cContentArrSplit, System.StringSplitOptions.RemoveEmptyEntries);
                            if (arr != null && arr.Length >= 2)
                            {
                                float x1 = float.Parse(arr[0]);
                                float y1 = float.Parse(arr[1]);
                                staticInfo.delta = new Vector2(x1, y1);
                            }
                        }
                        else if (string.Compare(key, "trans", true) == 0)
                        {
                            if (string.Compare(value, "none", true) == 0)
                            {
                                staticInfo.transType = TransType.none;
                            }
                        }
                        else if (string.Compare(key, "mask", true) == 0)
                        {
                            int i1 = int.Parse(value);
                            staticInfo.mask = (MaskType)i1;
                        }
                    }
                    else if (bgType == BgType.anim)
                    {
                        string[] arr = null;
                        if (string.Compare(key, "actionno", true) == 0)
                        {
                            aniInfo.actionno = int.Parse(value);
                        }
                        else if (string.Compare(key, "layerno", true) == 0)
                        {
                            aniInfo.layerno = int.Parse(value);
                        }
                        else if (string.Compare(key, "start", true) == 0)
                        {
                            arr = value.Split(ConfigSection._cContentArrSplit, System.StringSplitOptions.RemoveEmptyEntries);
                            if (arr != null && arr.Length >= 2)
                            {
                                aniInfo.start_x = int.Parse(arr[0]);
                                aniInfo.start_y = int.Parse(arr[1]);
                            }
                        }
                        else if (string.Compare(key, "delta", true) == 0)
                        {
                            arr = value.Split(ConfigSection._cContentArrSplit, System.StringSplitOptions.RemoveEmptyEntries);
                            if (arr != null && arr.Length >= 2)
                            {
                                float x1 = float.Parse(arr[0]);
                                float y1 = float.Parse(arr[1]);
                                aniInfo.delta = new Vector2(x1, y1);
                            }
                        }
                        else if (string.Compare(key, "trans", true) == 0)
                        {
                            if (string.Compare(value, "none", true) == 0)
                            {
                                aniInfo.transType = TransType.none;
                            }
                        }
                        else if (string.Compare(key, "mask", true) == 0)
                        {
                            int i1 = int.Parse(value);
                            aniInfo.mask = (MaskType)i1;
                        }
                    }
                }
            }

            // 排序
            SortBg();
            return(true);
        }
Exemple #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);
        }
Exemple #4
0
        private bool LoadFromStr(string str)
        {
            Clear();
            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            ConfigReader reader = new ConfigReader();

            reader.LoadString(str);

            // 1
            var section = reader.GetSection("Info");

            if (section != null)
            {
                m_Info = new StageInfo();
                if (!section.GetPropertysValues(m_Info))
                {
                    Clear();
                    return(false);
                }
            }
            else
            {
                Clear();
                return(false);
            }

            // 2
            section = reader.GetSection("Camera");
            if (section == null)
            {
                Clear();
                return(false);
            }
            m_Cam = new StageCamera();
            if (!section.GetPropertysValues(m_Cam))
            {
                Clear();
                return(false);
            }

            // 3
            section = reader.GetSection("PlayerInfo");
            if (section == null)
            {
                Clear();
                return(false);
            }
            m_Players = new StagePlayerInfo();
            if (!section.GetPropertysValues(m_Players))
            {
                Clear();
                return(false);
            }

            // 4
            section = reader.GetSection("Scaling");
            if (section != null)
            {
                m_Scaling = new StageScaling();
                if (!section.GetPropertysValues(m_Scaling))
                {
                    Clear();
                    return(false);
                }
            }
            else
            {
                m_Scaling = new StageScaling();
            }

            // 5
            m_AirConfig = new AirConfig(reader);
            if (!m_AirConfig.IsVaild)
            {
                Clear();
                return(false);
            }

            // 6
            section = reader.GetSection("BGdef");
            if (section == null)
            {
                Clear();
                return(false);
            }
            m_BgDef = new BgDef();
            if (!section.GetPropertysValues(m_BgDef))
            {
                Clear();
                return(false);
            }

            // 7.
            m_BgCfg = new BgConfig();
            if (!m_BgCfg.LoadFromReader(reader))
            {
                Clear();
                return(false);
            }

            return(IsVaild);
        }
Exemple #5
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);
        }
Exemple #6
0
 public AirConfig(ConfigReader reader)
 {
     mIsVaild = LoadFromReader(reader);
 }