Esempio n. 1
0
        public MapInfo LoadMapInfo(string dirPath)
        {
            MapInfo mi = new MapInfo();

            string mapXmlFile = Path.Combine(dirPath, "map.xml");

            if (!File.Exists(mapXmlFile))
            {
                return(null);
            }

            XmlDocument mapXml = new XmlDocument();

            try
            {
                mapXml.Load(mapXmlFile);
            }
            catch (Exception)
            {
                return(null);
            }

            XmlNode rootNode = mapXml.FirstChild;

            if (rootNode == null || rootNode.Name.ToLower() != "map")
            {
                return(null);
            }

            mi.DirectoryPath = dirPath;
            mi.Id            = Path.GetFileName(dirPath);
            mi.PitchType     = PitchType.Undefined;

            foreach (XmlNode node in rootNode)
            {
                switch (node.Name.ToLower())
                {
                    #region name
                case "name":
                {
                    mi.MapName = node.InnerText.Trim();
                }
                break;

                    #endregion
                    #region author
                case "author":
                {
                    mi.AuthorName = node.InnerText.Trim();
                }
                break;

                    #endregion
                    #region player
                case "player":
                {
                    foreach (XmlNode plNode in node)
                    {
                        switch (plNode.Name.ToLower())
                        {
                        case "vx":
                            int    vx  = 1;
                            string vxt = plNode.InnerText.Trim();
                            if (int.TryParse(vxt, out vx))
                            {
                                mi.PlayerVx = vx;
                            }
                            break;
                        }
                    }
                }
                break;

                    #endregion
                    #region color
                case "color":
                {
                    foreach (XmlNode coNode in node)
                    {
                        switch (coNode.Name.ToLower())
                        {
                        case "foreground":
                            mi.ForegroundColor = ImageUtil.GetColor(coNode.InnerText.Trim());
                            break;

                        case "background":
                            mi.BackgroundColor = ImageUtil.GetColor(coNode.InnerText.Trim());
                            break;

                        case "strong":
                            mi.StrongColor = ImageUtil.GetColor(coNode.InnerText.Trim());
                            break;
                        }
                    }
                }
                break;

                    #endregion
                    #region pitch
                case "pitch":
                {
                    #region PitchType
                    try
                    {
                        string pt = node.InnerText.Trim();
                        mi.PitchType = (PitchType)Enum.Parse(typeof(PitchType), pt, true);
                    }
                    catch (Exception) { mi.PitchType = PitchType.Undefined; }
                    #endregion

                    #region max/min
                    if (mi.PitchType == PitchType.Fixed)
                    {
                        double max = Config.Instance.MaxFreq;
                        double min = Config.Instance.MinFreq;
                        foreach (XmlAttribute attr in node.Attributes)
                        {
                            switch (attr.Name.ToLower())
                            {
                            case "max":
                                if (double.TryParse(attr.InnerText.Trim(), out max))
                                {
                                    mi.MaxPitch = max;
                                }
                                break;

                            case "min":
                                if (double.TryParse(attr.InnerText.Trim(), out min))
                                {
                                    mi.MinPitch = min;
                                }
                                break;
                            }
                        }
                    }
                    #endregion
                }
                break;

                    #endregion
                    #region chipdata
                case "chipdata":
                {
                    ChipDataInfo cdi = new ChipDataInfo();
                    #region default
                    cdi.ChipType    = MapChipType.Builtin;
                    cdi.FileName    = "";
                    cdi.BuiltinType = MapChipBuiltinType.Binary;
                    #endregion

                    #region size
                    int width = 16; int height = 16;
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        switch (attr.Name.ToLower())
                        {
                        case "width":
                            if (!int.TryParse(attr.InnerText.Trim(), out width))
                            {
                                width = 16;
                            }
                            break;

                        case "height":
                            if (!int.TryParse(attr.InnerText.Trim(), out height))
                            {
                                height = 16;
                            }
                            break;
                        }
                    }
                    cdi.Size = new Size(width, height);
                    #endregion

                    string name = null;
                    foreach (XmlNode cdiNode in node)
                    {
                        switch (cdiNode.Name.ToLower())
                        {
                            #region type
                        case "type":
                        {
                            try
                            {
                                string ct = cdiNode.InnerText.Trim();
                                cdi.ChipType = (MapChipType)Enum.Parse(typeof(MapChipType), ct, true);
                            }
                            catch (ArgumentException)
                            {
                                cdi.ChipType = MapChipType.None;
                            }
                        }
                        break;

                            #endregion
                            #region name
                        case "name":
                        {
                            name = cdiNode.InnerText.Trim();
                        }
                        break;

                            #endregion
                            #region chip
                        case "chip":
                        {
                            if (cdi.ChipInfos == null)
                            {
                                cdi.ChipInfos = new List <ChipInfo>();
                            }

                            ChipInfo ci = new ChipInfo();
                            ci.Color    = null;
                            ci.Hardness = cdi.ChipInfos.Count == 0 ? 0 : 1;

                            foreach (XmlNode ciNode in cdiNode)
                            {
                                switch (ciNode.Name.ToLower())
                                {
                                case "color":
                                {
                                    string ciColorStr = ciNode.InnerText.Trim();
                                    ci.Color = ImageUtil.GetColor(ciColorStr);
                                }
                                break;

                                case "hardness":
                                {
                                    string ciHardStr = ciNode.InnerText.Trim();
                                    if (!int.TryParse(ciHardStr, out ci.Hardness))
                                    {
                                        ci.Hardness = cdi.ChipInfos.Count == 0 ? 0 : 1;
                                    }
                                }
                                break;
                                }
                            }
                            cdi.ChipInfos.Add(ci);
                        }
                        break;
                            #endregion
                        }
                    }

                    #region name解釈
                    if (cdi.ChipType == MapChipType.Builtin)
                    {
                        try
                        {
                            if (string.IsNullOrEmpty(name))
                            {
                                cdi.BuiltinType = MapChipBuiltinType.Binary;
                            }
                            else
                            {
                                cdi.BuiltinType = (MapChipBuiltinType)Enum.Parse(typeof(MapChipBuiltinType), name, true);
                            }
                        }
                        catch (ArgumentException)
                        {
                            cdi.BuiltinType = MapChipBuiltinType.Binary;
                        }
                    }
                    else
                    {
                        cdi.FileName    = getFilePath(name);
                        cdi.BuiltinType = MapChipBuiltinType.None;
                    }
                    #endregion

                    mi.ChipDataInfo = cdi;
                }
                break;

                    #endregion
                    #region source
                case "source":
                    foreach (XmlNode soNode in node)
                    {
                        switch (soNode.Name.ToLower())
                        {
                            #region type
                        case "type":
                            try
                            {
                                string mt = soNode.InnerText.Trim();
                                mi.MapSourceType = (MapSourceType)Enum.Parse(typeof(MapSourceType), mt, true);
                            }
                            catch (ArgumentException)
                            {
                                mi.MapSourceType = MapSourceType.None;
                            }
                            break;

                            #endregion
                            #region name
                        case "name":
                            mi.MapSourceFileName = getFilePath(soNode.InnerText.Trim());
                            break;

                            #endregion
                            #region mapping
                        case "mapping":
                            mi.Mapping = soNode.InnerText.Trim();
                            break;
                            #endregion
                        }
                    }
                    break;

                    #endregion
                    #region bgm
                case "bgm":
                {
                    BgmInfo bi = new BgmInfo();
                    bi.Name = getFilePath(node.InnerText.Trim());
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        switch (attr.Name.ToLower())
                        {
                            #region volume
                        case "volume":
                        {
                            int vol = 50;
                            if (int.TryParse(attr.InnerText.Trim(), out vol))
                            {
                                vol = vol < 0 ? 0 : (vol > 100 ? 100 : vol);
                            }
                            bi.Volume = vol;
                        }
                        break;
                            #endregion
                        }
                    }
                    mi.BgmInfo = bi;
                }
                break;

                    #endregion
                default:
                    break;
                }
            }

            #region Pitchの記述が無い場合
            if (mi.PitchType == PitchType.Undefined)
            {
                if (mi.MapSourceType == MapSourceType.Music)
                {
                    mi.PitchType = PitchType.Fixed;
                }
                else
                {
                    mi.PitchType = PitchType.Variable;
                }
            }
            #endregion

            if (isValidMapInfo(mi))
            {
                return(mi);
            }
            return(null);
        }
Esempio n. 2
0
        public MapInfo LoadMapInfo(string dirPath)
        {
            MapInfo mi = new MapInfo();

            string mapXmlFile = Path.Combine(dirPath, "map.xml");
            if (!File.Exists(mapXmlFile)) return null;

            XmlDocument mapXml = new XmlDocument();
            try
            {
                mapXml.Load(mapXmlFile);
            }
            catch (Exception)
            {
                return null;
            }

            XmlNode rootNode = mapXml.FirstChild;
            if (rootNode == null || rootNode.Name.ToLower() != "map") return null;

            mi.DirectoryPath = dirPath;
            mi.Id = Path.GetFileName(dirPath);
            mi.PitchType = PitchType.Undefined;

            foreach (XmlNode node in rootNode)
            {
                switch (node.Name.ToLower())
                {
                    #region name
                    case "name":
                        {
                            mi.MapName = node.InnerText.Trim();
                        }
                        break;
                    #endregion
                    #region author
                    case "author":
                        {
                            mi.AuthorName = node.InnerText.Trim();
                        }
                        break;
                    #endregion
                    #region player
                    case "player":
                        {
                            foreach (XmlNode plNode in node)
                            {
                                switch (plNode.Name.ToLower())
                                {
                                    case "vx":
                                        int vx = 1;
                                        string vxt = plNode.InnerText.Trim();
                                        if (int.TryParse(vxt, out vx)) mi.PlayerVx = vx;
                                        break;
                                }
                            }
                        }
                        break;
                    #endregion
                    #region color
                    case "color":
                        {
                            foreach (XmlNode coNode in node)
                            {
                                switch (coNode.Name.ToLower())
                                {
                                    case "foreground":
                                        mi.ForegroundColor = ImageUtil.GetColor(coNode.InnerText.Trim());
                                        break;
                                    case "background":
                                        mi.BackgroundColor = ImageUtil.GetColor(coNode.InnerText.Trim());
                                        break;
                                    case "strong":
                                        mi.StrongColor = ImageUtil.GetColor(coNode.InnerText.Trim());
                                        break;
                                }
                            }
                        }
                        break;
                    #endregion
                    #region pitch
                    case "pitch":
                        {
                            #region PitchType
                            try
                            {
                                string pt = node.InnerText.Trim();
                                mi.PitchType = (PitchType)Enum.Parse(typeof(PitchType), pt, true);
                            }
                            catch (Exception) { mi.PitchType = PitchType.Undefined; }
                            #endregion

                            #region max/min
                            if (mi.PitchType == PitchType.Fixed)
                            {
                                double max = Config.Instance.MaxFreq;
                                double min = Config.Instance.MinFreq;
                                foreach (XmlAttribute attr in node.Attributes)
                                {
                                    switch (attr.Name.ToLower())
                                    {
                                        case "max":
                                            if (double.TryParse(attr.InnerText.Trim(), out max)) mi.MaxPitch = max;
                                            break;
                                        case "min":
                                            if (double.TryParse(attr.InnerText.Trim(), out min)) mi.MinPitch = min;
                                            break;
                                    }
                                }
                            }
                            #endregion
                        }
                        break;
                    #endregion
                    #region chipdata
                    case "chipdata":
                        {
                            ChipDataInfo cdi = new ChipDataInfo();
                            #region default
                            cdi.ChipType = MapChipType.Builtin;
                            cdi.FileName = "";
                            cdi.BuiltinType = MapChipBuiltinType.Binary;
                            #endregion

                            #region size
                            int width = 16; int height = 16;
                            foreach (XmlAttribute attr in node.Attributes)
                            {
                                switch (attr.Name.ToLower())
                                {
                                    case "width":
                                        if (!int.TryParse(attr.InnerText.Trim(), out width)) width = 16;
                                        break;
                                    case "height":
                                        if (!int.TryParse(attr.InnerText.Trim(), out height)) height = 16;
                                        break;
                                }
                            }
                            cdi.Size = new Size(width, height);
                            #endregion

                            string name = null;
                            foreach (XmlNode cdiNode in node)
                            {
                                switch (cdiNode.Name.ToLower())
                                {
                                    #region type
                                    case "type":
                                        {
                                            try
                                            {
                                                string ct = cdiNode.InnerText.Trim();
                                                cdi.ChipType = (MapChipType)Enum.Parse(typeof(MapChipType), ct, true);
                                            }
                                            catch (ArgumentException)
                                            {
                                                cdi.ChipType = MapChipType.None;
                                            }
                                        }
                                        break;
                                    #endregion
                                    #region name
                                    case "name":
                                        {
                                            name = cdiNode.InnerText.Trim();
                                        }
                                        break;
                                    #endregion
                                    #region chip
                                    case "chip":
                                        {
                                            if (cdi.ChipInfos == null) cdi.ChipInfos = new List<ChipInfo>();

                                            ChipInfo ci = new ChipInfo();
                                            ci.Color = null;
                                            ci.Hardness = cdi.ChipInfos.Count == 0 ? 0 : 1;

                                            foreach (XmlNode ciNode in cdiNode)
                                            {
                                                switch (ciNode.Name.ToLower())
                                                {
                                                    case "color":
                                                        {
                                                            string ciColorStr = ciNode.InnerText.Trim();
                                                            ci.Color = ImageUtil.GetColor(ciColorStr);
                                                        }
                                                        break;
                                                    case "hardness":
                                                        {
                                                            string ciHardStr = ciNode.InnerText.Trim();
                                                            if (!int.TryParse(ciHardStr, out ci.Hardness)) ci.Hardness = cdi.ChipInfos.Count == 0 ? 0 : 1;
                                                        }
                                                        break;
                                                }
                                            }
                                            cdi.ChipInfos.Add(ci);
                                        }
                                        break;
                                    #endregion
                                }
                            }

                            #region name解釈
                            if (cdi.ChipType == MapChipType.Builtin)
                            {
                                try
                                {
                                    if (string.IsNullOrEmpty(name)) cdi.BuiltinType = MapChipBuiltinType.Binary;
                                    else cdi.BuiltinType = (MapChipBuiltinType)Enum.Parse(typeof(MapChipBuiltinType), name, true);
                                }
                                catch (ArgumentException)
                                {
                                    cdi.BuiltinType = MapChipBuiltinType.Binary;
                                }
                            }
                            else
                            {
                                cdi.FileName = getFilePath(name);
                                cdi.BuiltinType = MapChipBuiltinType.None;
                            }
                            #endregion

                            mi.ChipDataInfo = cdi;
                        }
                        break;
                    #endregion
                    #region source
                    case "source":
                        foreach (XmlNode soNode in node)
                        {
                            switch (soNode.Name.ToLower())
                            {
                                #region type
                                case "type":
                                    try
                                    {
                                        string mt = soNode.InnerText.Trim();
                                        mi.MapSourceType = (MapSourceType)Enum.Parse(typeof(MapSourceType), mt, true);
                                    }
                                    catch (ArgumentException)
                                    {
                                        mi.MapSourceType = MapSourceType.None;
                                    }
                                    break;
                                #endregion
                                #region name
                                case "name":
                                    mi.MapSourceFileName = getFilePath(soNode.InnerText.Trim());
                                    break;
                                #endregion
                                #region mapping
                                case "mapping":
                                    mi.Mapping = soNode.InnerText.Trim();
                                    break;
                                #endregion
                            }
                        }
                        break;
                    #endregion
                    #region bgm
                    case "bgm":
                        {
                            BgmInfo bi = new BgmInfo();
                            bi.Name = getFilePath(node.InnerText.Trim());
                            foreach (XmlAttribute attr in node.Attributes)
                            {
                                switch (attr.Name.ToLower())
                                {
                                    #region volume
                                    case "volume":
                                        {
                                            int vol = 50;
                                            if (int.TryParse(attr.InnerText.Trim(), out vol))
                                            {
                                                vol = vol < 0 ? 0 : (vol > 100 ? 100 : vol);
                                            }
                                            bi.Volume = vol;
                                        }
                                        break;
                                    #endregion
                                }
                            }
                            mi.BgmInfo = bi;
                        }
                        break;
                    #endregion
                    default:
                        break;
                }
            }

            #region Pitchの記述が無い場合
            if (mi.PitchType == PitchType.Undefined)
            {
                if (mi.MapSourceType == MapSourceType.Music) mi.PitchType = PitchType.Fixed;
                else mi.PitchType = PitchType.Variable;
            }
            #endregion

            if (isValidMapInfo(mi)) return mi;
            return null;
        }