Example #1
0
        private Map loadUserMap(MapInfo info)
        {
            Map         map      = null;
            MapChipData chipData = null;

            try
            {
                switch (info.ChipDataInfo.ChipType)
                {
                case MapChipType.Builtin:
                {
                    switch (info.ChipDataInfo.BuiltinType)
                    {
                    case MapChipBuiltinType.Binary:
                        chipData     = BinaryChipData.LoadChipData(info);
                        map          = new BinaryMap();
                        map.ChipData = chipData;
                        break;

                    case MapChipBuiltinType.Colors:
                        chipData     = ColorChipData.LoadChipData(info);
                        map          = new ColorsMap();
                        map.ChipData = chipData;
                        break;
                    }
                }
                break;

                case MapChipType.Image:
                {
                    chipData     = ImageMapChipData.LoadChipData(info);
                    map          = new Map();
                    map.ChipData = chipData;
                }
                break;
                }


                switch (info.MapSourceType)
                {
                case MapSourceType.Text:
                {
                    string   srcPath = Path.Combine(info.DirectoryPath, info.MapSourceFileName);
                    string   mapping = info.Mapping;
                    string[] lines   = File.ReadAllLines(srcPath, Encoding.UTF8);
                    map.LoadMapText(lines, mapping);
                }
                break;

                case MapSourceType.Image:
                {
                    string srcPath     = Path.Combine(info.DirectoryPath, info.MapSourceFileName);
                    string mappingPath = Path.Combine(info.DirectoryPath, info.Mapping);
                    using (Bitmap srcBmp = (Bitmap)Bitmap.FromFile(srcPath))
                    {
                        if (!string.IsNullOrEmpty(info.Mapping) && File.Exists(mappingPath))
                        {
                            using (Bitmap mappingBmp = (Bitmap)Bitmap.FromFile(mappingPath))
                            {
                                map.LoadMapImage(srcBmp, mappingBmp);
                            }
                        }
                        else
                        {
                            map.LoadMapImage(srcBmp, null);
                        }
                    }
                }
                break;

                case MapSourceType.Music:
                {
                    string srcPath = Path.Combine(info.DirectoryPath, info.MapSourceFileName);

                    Music music = Music.LoadMusic(srcPath);
                    info.MaxPitch = music.MaxPitch;
                    info.MinPitch = music.MinPitch;
                    using (Bitmap srcBmp = music.GetMap(SdlDotNet.Core.Events.TargetFps, info.PlayerVx,
                                                        info.ChipDataInfo.Size.Width, info.ChipDataInfo.Size.Height,
                                                        !(info.ChipDataInfo.ChipType == MapChipType.Builtin &&
                                                          info.ChipDataInfo.BuiltinType == MapChipBuiltinType.Binary)))
                    {
                        if (srcBmp != null)
                        {
                            string dirPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                            dirPath = Path.Combine(dirPath, Properties.Resources.Dirname_Config);
                            string fpath = Path.Combine(dirPath, Properties.Resources.Filename_MusicLogImage);
                            srcBmp.Save(fpath);
                            fpath = Path.Combine(dirPath, Properties.Resources.Filename_MusicLogText);
                            using (StreamWriter writer = new StreamWriter(fpath, false, Encoding.UTF8))
                            {
                                writer.WriteLine("max pitch: {0}", info.MaxPitch);
                                writer.WriteLine("min pitch: {0}", info.MinPitch);
                            }

                            using (Bitmap mappingBmp = Music.GetMappingBmp())
                            {
                                map.LoadMapImage(srcBmp, mappingBmp);
                            }
                        }
                    }
                }
                break;
                }

                if (info.BgmInfo != null && !string.IsNullOrEmpty(info.BgmInfo.Name))
                {
                    string bgmPath = Path.Combine(info.DirectoryPath, info.BgmInfo.Name);
                    map.Bgm       = new SdlDotNet.Audio.Music(bgmPath);
                    map.BgmVolume = info.BgmInfo.Volume;
                }

                map.MapInfo = info;
                return(map);
            }
            catch (Exception ex)
            {
                throw new MapLoadException(string.Format("{0}: {1}", Properties.Resources.Str_MapLoadError, info.Id), ex);
            }
        }
Example #2
0
        private Map loadUserMap(MapInfo info)
        {
            Map map = null;
            MapChipData chipData = null;

            try
            {
                switch (info.ChipDataInfo.ChipType)
                {
                    case MapChipType.Builtin:
                        {
                            switch (info.ChipDataInfo.BuiltinType)
                            {
                                case MapChipBuiltinType.Binary:
                                    chipData = BinaryChipData.LoadChipData(info);
                                    map = new BinaryMap();
                                    map.ChipData = chipData;
                                    break;
                                case MapChipBuiltinType.Colors:
                                    chipData = ColorChipData.LoadChipData(info);
                                    map = new ColorsMap();
                                    map.ChipData = chipData;
                                    break;
                            }
                        }
                        break;
                    case MapChipType.Image:
                        {
                            chipData = ImageMapChipData.LoadChipData(info);
                            map = new Map();
                            map.ChipData = chipData;
                        }
                        break;
                }


                switch (info.MapSourceType)
                {
                    case MapSourceType.Text:
                        {
                            string srcPath = Path.Combine(info.DirectoryPath, info.MapSourceFileName);
                            string mapping = info.Mapping;
                            string[] lines = File.ReadAllLines(srcPath, Encoding.UTF8);
                            map.LoadMapText(lines, mapping);
                        }
                        break;
                    case MapSourceType.Image:
                        {
                            string srcPath = Path.Combine(info.DirectoryPath, info.MapSourceFileName);
                            string mappingPath = Path.Combine(info.DirectoryPath, info.Mapping);
                            using (Bitmap srcBmp = (Bitmap)Bitmap.FromFile(srcPath))
                            {
                                if (!string.IsNullOrEmpty(info.Mapping) && File.Exists(mappingPath))
                                {
                                    using (Bitmap mappingBmp = (Bitmap)Bitmap.FromFile(mappingPath))
                                    {
                                        map.LoadMapImage(srcBmp, mappingBmp);
                                    }
                                }
                                else
                                {
                                    map.LoadMapImage(srcBmp, null);
                                }
                            }
                        }
                        break;
                    case MapSourceType.Music:
                        {
                            string srcPath = Path.Combine(info.DirectoryPath, info.MapSourceFileName);

                            Music music = Music.LoadMusic(srcPath);
                            info.MaxPitch = music.MaxPitch;
                            info.MinPitch = music.MinPitch;
                            using (Bitmap srcBmp = music.GetMap(SdlDotNet.Core.Events.TargetFps, info.PlayerVx,
                                info.ChipDataInfo.Size.Width, info.ChipDataInfo.Size.Height,
                                !(info.ChipDataInfo.ChipType == MapChipType.Builtin && 
                                    info.ChipDataInfo.BuiltinType == MapChipBuiltinType.Binary)))
                            {
                                if (srcBmp != null)
                                {
                                    string dirPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                                    dirPath = Path.Combine(dirPath, Properties.Resources.Dirname_Config);
                                    string fpath = Path.Combine(dirPath, Properties.Resources.Filename_MusicLogImage);
                                    srcBmp.Save(fpath);
                                    fpath = Path.Combine(dirPath, Properties.Resources.Filename_MusicLogText);
                                    using (StreamWriter writer = new StreamWriter(fpath, false, Encoding.UTF8))
                                    {
                                        writer.WriteLine("max pitch: {0}", info.MaxPitch);
                                        writer.WriteLine("min pitch: {0}", info.MinPitch);
                                    }

                                    using (Bitmap mappingBmp = Music.GetMappingBmp())
                                    {
                                        map.LoadMapImage(srcBmp, mappingBmp);
                                    }
                                }
                            }
                        }
                        break;
                }

                if (info.BgmInfo != null && !string.IsNullOrEmpty(info.BgmInfo.Name))
                {
                    string bgmPath = Path.Combine(info.DirectoryPath, info.BgmInfo.Name);
                    map.Bgm = new SdlDotNet.Audio.Music(bgmPath);
                    map.BgmVolume = info.BgmInfo.Volume;
                }

                map.MapInfo = info;
                return map;
            }
            catch (Exception ex)
            {
                throw new MapLoadException(string.Format("{0}: {1}", Properties.Resources.Str_MapLoadError, info.Id), ex);
            }
        }