public static ImageMapChipData LoadChipData(MapInfo info) { ImageMapChipData c = new ImageMapChipData(); string path = System.IO.Path.Combine(info.DirectoryPath, info.ChipDataInfo.FileName); c._chipSurfaces = ResourceManager.LoadSurfacesFromFile(path, info.ChipDataInfo.Size); c._avgColors = new Dictionary <uint, Color>(); c._hardness = new int[c._chipSurfaces.Count]; uint chip = 0; foreach (Surface s in c._chipSurfaces) { c._avgColors.Add(chip, ImageUtil.GetAvgColor(s)); if (info.ChipDataInfo == null || chip > info.ChipDataInfo.ChipInfos.Count - 1) { c._hardness[chip] = chip == 0 ? 0 : 1; } else { c._hardness[chip] = info.ChipDataInfo.ChipInfos[(int)chip].Hardness; } chip++; } c._chipWidth = info.ChipDataInfo.Size.Width; c._chipHeight = info.ChipDataInfo.Size.Height; c._backChip = 0; c._wallChip = 1; return(c); }
public static ImageMapChipData LoadChipData(MapInfo info) { ImageMapChipData c = new ImageMapChipData(); string path = System.IO.Path.Combine(info.DirectoryPath, info.ChipDataInfo.FileName); c._chipSurfaces = ResourceManager.LoadSurfacesFromFile(path, info.ChipDataInfo.Size); c._avgColors = new Dictionary<uint, Color>(); c._hardness = new int[c._chipSurfaces.Count]; uint chip = 0; foreach (Surface s in c._chipSurfaces) { c._avgColors.Add(chip, ImageUtil.GetAvgColor(s)); if (info.ChipDataInfo == null || chip > info.ChipDataInfo.ChipInfos.Count - 1) { c._hardness[chip] = chip == 0 ? 0 : 1; } else { c._hardness[chip] = info.ChipDataInfo.ChipInfos[(int)chip].Hardness; } chip++; } c._chipWidth = info.ChipDataInfo.Size.Width; c._chipHeight = info.ChipDataInfo.Size.Height; c._backChip = 0; c._wallChip = 1; return c; }
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); } }