public static void Save(Map map, string file) { List <string> lines = new List <string>(); int w = map.W; int h = map.H; lines.Add("" + w); lines.Add("" + h); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { MapCell cell = map.GetCell(x, y); List <string> tokens = new List <string>(); tokens.Add("" + (int)cell.Kind); tokens.Add(cell.SurfacePicture.Name); tokens.Add(cell.TilePicture.Name); // 新しい項目をここへ追加... lines.Add(string.Join("\t", tokens).TrimEnd()); } } foreach (KeyValuePair <string, string> pair in map.GetProperties()) { lines.Add(pair.Key + "=" + pair.Value); } DDResource.Save(file, Encoding.UTF8.GetBytes(FileTools.LinesToText(lines.ToArray()))); }
private static void DrawToScreen(DDSubScreen screen, Map map, D2Point mapCamera) { int cam_l = (int)mapCamera.X; int cam_t = (int)mapCamera.Y; int cam_r = cam_l + DDConsts.Screen_W; int cam_b = cam_t + DDConsts.Screen_H; int l = cam_l / GameConsts.TILE_W; int t = cam_t / GameConsts.TILE_H; int r = cam_r / GameConsts.TILE_W; int b = cam_b / GameConsts.TILE_H; using (screen.Section()) { DX.ClearDrawScreen(); { Map bk_map = Game.I.Map; D2Point bk_camera = DDGround.Camera; I2Point bk_iCamera = DDGround.ICamera; // Hack { Game.I.Map = map; DDGround.Camera = new D2Point(cam_l, cam_t); DDGround.ICamera = new I2Point(cam_l, cam_t); } WallCreator.Create(map.WallName).Draw(); // restore { Game.I.Map = bk_map; DDGround.Camera = bk_camera; DDGround.ICamera = bk_iCamera; } } DDGround.EL.Clear(); for (int x = l; x <= r; x++) { for (int y = t; y <= b; y++) { double cell_x = x * GameConsts.TILE_W + GameConsts.TILE_W / 2; double cell_y = y * GameConsts.TILE_H + GameConsts.TILE_H / 2; map.GetCell(x, y).Tile.Draw(cell_x - cam_l, cell_y - cam_t, x, y); } } DDGround.EL.ExecuteAllTask(); // 前面に表示するタイルのため } }
public static string LastLoadedFile = null; // null == 未読み込み public static Map Load(string file) { LastLoadedFile = file; string[] lines = FileTools.TextToLines(Encoding.UTF8.GetString(DDResource.Load(file))); int c = 0; int w = int.Parse(lines[c++]); int h = int.Parse(lines[c++]); Map map = new Map(w, h); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (lines.Length <= c) { goto endLoad; } MapCell cell = map.GetCell(x, y); var tokens = new BluffList <string>(lines[c++].Split('\t')).FreeRange(""); // 項目が増えても良いように -> FreeRange("") int d = 0; cell.Kind = (MapCell.Kind_e) int.Parse(tokens[d++]); cell.SurfacePicture = MapTileManager.GetTile(tokens[d++]); cell.TilePicture = MapTileManager.GetTile(tokens[d++]); // 新しい項目をここへ追加... } } while (c < lines.Length) { // memo: Save()時にプロパティ部分も上書きされるので注意してね。 var tokens = lines[c++].Split("=".ToArray(), 2); string name = tokens[0]; string value = tokens[1]; map.AddProperty(name, value); } endLoad: return(map); }