public void init(Map m) { currMap = m; currVsp = m.vsp; vspc.SetActiveVsp(currVsp); vspc.SetControllerMode(VSPController.ControllerMode.SelectorDual); // n_start.Maximum = m.vsp.tileCount-1; // n_end.Maximum = m.vsp.tileCount-1; foreach(VspAnimation va in currVsp.Animations) { anims.Add( va.Clone() ); } foreach(VspAnimation va in anims) { ListViewItem lvi = new ListViewItem( new string[] { va.ID.ToString(), va.Name } ); lvi.Tag = va; lv_anims.Items.Add(lvi); } DisableEditor(); }
static Map ReadMapJson(FileInfo fi) { Map map = new Map(); var root = JObject.Parse(File.ReadAllText(fi.FullName)); int version = (int)root["version"]; //basic map properties map.MusicFileName = (string)root["MusicFileName"]; map.FormalName = (string)root["FormalName"]; map.AutoExecEvent = (string)root["AutoExecEvent"]; map.PlayerStartX = (int)root["PlayerStartX"]; map.PlayerStartY = (int)root["PlayerStartY"]; //some basic collections map.Notes = JsonConvert.DeserializeObject<List<Map.Note>>((string)root["Notes"]); map.Zones = JsonConvert.DeserializeObject<List<MapZone>>((string)root["Zones"]); //entities are maybe tricky... but not yet! map.Entities = JsonConvert.DeserializeObject<List<MapEntity>>((string)root["Entities"]); //regular map layers foreach (var jml in root["Layers"]) { var ml = JsonConvert.DeserializeObject<MapLayer>((string)jml); if (ml.type == LayerType.Special_Retrace) { ml = JsonConvert.DeserializeObject<MapLayerSpecial>((string)jml); ml.parentmap = map; } map.Layers.Add(ml); } //other map data layers map.ObsLayer = JsonConvert.DeserializeObject<MapLayer>((string)root["ObsLayer"]); map.ObsLayer.parentmap = map; map.ZoneLayer = JsonConvert.DeserializeObject<MapLayer>((string)root["ZoneLayer"]); map.ZoneLayer.parentmap = map; map.EntLayer = JsonConvert.DeserializeObject<MapLayer>((string)root["EntLayer"]); map.EntLayer.parentmap = map; map.RenderString = "1,2"; return map; }
static void WriteMapJson(FileInfo fi, Map map) { var root = new JObject(); root["version"] = 1; //basic map properties root["MusicFileName"] = map.MusicFileName; root["FormalName"] = map.FormalName; root["AutoExecEvent"] = map.AutoExecEvent; root["PlayerStartX"] = map.PlayerStartX; root["PlayerStartY"] = map.PlayerStartY; //shitty properties root["VSPName"] = Helper.GetRelativePath(map.FileOnDisk.Directory.FullName, map.vsp.FileOnDisk.FullName); //some basic collections root["Notes"] = JsonConvert.SerializeObject(map.Notes); root["Zones"] = JsonConvert.SerializeObject(map.Zones); //entities are maybe tricky... but not yet! root["Entities"] = JsonConvert.SerializeObject(map.Entities); root["Layers"] = new JArray(); Func<MapLayer,string> serializeLayer = (MapLayer layer) => { return JsonConvert.SerializeObject(layer); }; root["ObsLayer"] = serializeLayer(map.ObsLayer); root["ZoneLayer"] = serializeLayer(map.ZoneLayer); root["EntLayer"] = serializeLayer(map.EntLayer); foreach (var ml in map.Layers) { root["Layers"].AsArray().Add(serializeLayer(ml)); } File.WriteAllText((fi.FullName + ".json.txt"), root.ToString()); }
public void LoadMap(string fname) { mMap = Map.LoadMap(fname); if (mMap == null) return; mru.touch(fname); Global.ActiveMap = mMap; Global.ActiveVsp = mMap.vsp; vspController.SetActiveVsp(mMap.vsp); vspc_obs.SetActiveVsp(mMap.vsp); update_zone_list(); update_ent_list(); if (Global.VspViewer != null) { Global.VspViewer.CalculateScrollValues(); } if (Global.mapViewer != null) { Global.mapViewer.CalculateScrollValues(); } lpInit(mMap); Global.FrameCalc.generate(mMap.vsp.Animations); Global.ForceRedraws(); statusBar.Panels[0].Text = "Loaded " + fname; if (mMap.vsp.ObstructionTiles.Count == 0) { if (MessageBox.Show("No obstruction tiles were loaded from the VSP file. Do you wish MapEd to create the most common basic obstruction tiles for you?", "Help", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) mMap.vsp.AddBasicObstructionTiles(); } }
private void SaveMap(Map m, bool ForcePrompt) { string mapname; string vspname; Vsp24 vsp = m.vsp; if (ForcePrompt || m.FileOnDisk == null) { // get location of map if (m.FileOnDisk != null) saveFileDialog.FileName = m.FileOnDisk.FullName; else saveFileDialog.FileName = "untitled.map"; if (saveFileDialog.ShowDialog() != DialogResult.OK) return; mapname = saveFileDialog.FileName; FileInfo fimap = new FileInfo(mapname); DirectoryInfo dimap = fimap.Directory; string dm = dimap.FullName; bool done = false; while (!done) { if (vsp.FileOnDisk != null) saveVspDialog.FileName = vsp.FileOnDisk.FullName; else saveVspDialog.FileName = Path.Combine(dimap.FullName, Path.GetFileNameWithoutExtension(fimap.Name)) + ".vsp"; saveVspDialog.ShowDialog(); vspname = saveVspDialog.FileName; if (CheckVSPLoc(dm, vspname)) { // got a valid vsp filename // write vsp. vsp.Write(vspname); // write map m.WriteMap(mapname); mru.touch(mapname); statusBar.Panels[0].Text = "Saved " + Global.ActiveMap.FileOnDisk.FullName; done = true; } else { DialogResult dr = MessageBox.Show("The VSP must be located in the same directory, or a sub-directory of that directory, as the map file. Please choose such a location.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (dr == DialogResult.Cancel) done = true; } } } else { // write vsp vsp.Write(); // write map m.WriteMap(); statusBar.Panels[0].Text = "Saved " + Global.ActiveMap.FileOnDisk.FullName; } }
public void init(Map map) { ArrayList ents = map.Entities; this.map = map; foreach(MapEntity me in ents) entCopy.Add(me.Clone()); foreach(MapEntity me in entCopy) { ListViewItem lvi = new ListViewItem( new string[] { me.ID.ToString(), me.Description + "; "+me.ChrName } ); lvi.Tag = me; lv_ents.Items.Add(lvi); } }
void resize(Map map) { //fixup each layer foreach (var layer in map.Layers) { var od = layer.Data; if (od == null) continue; var ow = layer.Width; var oh = layer.Height; var nw = newWidth; var nh = newHeight; var nd = new short[nw * nh]; layer.Data = nd; layer._Width = nw; layer._Height = nh; int dx = 0, dy = 0; int sx, sy = -above; for (int y = 0; y < nh; y++, sy++, dy++) { sx = -left; dx = 0; for (int x = 0; x < nw; x++, sx++, dx++) { if (sx < 0) continue; if (sy < 0) continue; short tile = 0; if (sx < ow && sy < oh) tile = od[sy * ow + sx]; nd[dy * nw + dx] = tile; } } } //fixup each note foreach (var note in map.Notes) { note.x += left * Global.TILE_SIZE; note.y += above * Global.TILE_SIZE; } //fixup each entity foreach (var ent in map.Entities) { ent.TileX += left; ent.TileY += above; } }
public static unsafe int WriteMap_Archaic(FileInfo fi, Map map) { byte[] map3_signature = new byte[] { (byte)'V', (byte)'3', (byte)'M', (byte)'A', (byte)'P', (byte)0 }; if (map == null) return -1; string vspname = Helper.GetRelativePath(map.FileOnDisk.Directory.FullName, map.vsp.FileOnDisk.FullName); if (vspname == null) throw new Exception("Unable to resolve VSP path."); //fi = new FileInfo(fi.Name); if (fi.Exists) fi.Delete(); FileStream fs = fi.OpenWrite(); MemoryStream ms_outbuf = new MemoryStream(); BinaryWriter bw_o = new BinaryWriter(ms_outbuf); MemoryStream ms_outbuf2 = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms_outbuf2); bw_o.Write(map3_signature); bw_o.Write(Global.VERSIONINFO.MAPVERSION); //---- bw.Write(map.Notes.Count); foreach (var note in map.Notes) { bw.Write(note.x); bw.Write(note.y); byte[] n = System.Text.Encoding.ASCII.GetBytes(note.note); bw.Write(n.Length); bw.Write(n); } bw.Write(Helper.StringToPaddedByteArray(map.FormalName, 256)); bw.Write(Helper.StringToPaddedByteArray(vspname, 256)); bw.Write(Helper.StringToPaddedByteArray(map.MusicFileName, 256)); bw.Write(Helper.StringToPaddedByteArray(map.RenderString, 256)); bw.Write(Helper.StringToPaddedByteArray(map.AutoExecEvent, 256)); bw.Write((short)map.PlayerStartX); bw.Write((short)map.PlayerStartY); int special_count = 0; foreach (MapLayer ml in map.Layers) if (ml.type != LayerType.Tile) special_count++; bw.Write(map.Layers.Count - special_count); foreach (MapLayer ml in map.Layers) { if (ml.type != LayerType.Tile) continue; bw.Write(Helper.StringToPaddedByteArray(ml.name, 256)); bw.Write(ml.parallaxInfo.MultipleX); bw.Write(ml.parallaxInfo.MultipleY); bw.Write((short)ml.Width); bw.Write((short)ml.Height); bw.Write((byte)ml.Translucency); fixed (short* ptr = ml.Data) { byte[] zdata = ZLIB.Encode((byte*)ptr, ml.Data.Length * 2); bw.Write(ml.Data.Length * 2); bw.Write(zdata.Length); bw.Write(zdata); } } MapLayer zl = map.ZoneLayer, ol = map.ObsLayer; byte[] obsdata = new byte[ol.Data.Length]; for (int j = 0; j < ol.Data.Length; j++) obsdata[j] = (byte)ol.Data[j]; fixed (byte* ptr = obsdata) { byte[] zdata = ZLIB.Encode(ptr, obsdata.Length); bw.Write(obsdata.Length); bw.Write(zdata.Length); bw.Write(zdata); } fixed (short* ptr = zl.Data) { byte[] zdata = ZLIB.Encode((byte*)ptr, zl.Data.Length * 2); bw.Write(zl.Data.Length * 2); bw.Write(zdata.Length); bw.Write(zdata); } bw.Write(map.Zones.Count); foreach (MapZone mz in map.Zones) { bw.Write(Helper.StringToPaddedByteArray(mz.Name, 256)); bw.Write(Helper.StringToPaddedByteArray(mz.PlayerScript, 256)); // bw.Write(Helper.StringToPaddedByteArray(mz.EntityScript,256)); bw.Write((byte)mz.Rate); bw.Write((byte)mz.Delay); bw.Write((byte)mz.Flags); } bw.Write(map.Entities.Count); foreach (MapEntity me in map.Entities) { bw.Write((short)me.TileX); bw.Write((short)me.TileY); bw.Write((byte)me.Facing); bw.Write((byte)me.ObeyObstruction); bw.Write((byte)me.IsObstruction); bw.Write((byte)me.AutoFace); bw.Write((short)me.Speed); bw.Write((byte)me.ActivationMode); bw.Write((byte)me.MoveType); bw.Write((short)me.WanderRectangle.x0); bw.Write((short)me.WanderRectangle.y0); bw.Write((short)me.WanderRectangle.x1); bw.Write((short)me.WanderRectangle.y1); bw.Write((short)me.WanderDelay); bw.Write((int)0);//expand bw.Write(Helper.StringToPaddedByteArray(me.MoveScript, 256)); bw.Write(Helper.StringToPaddedByteArray(me.ChrName, 256)); bw.Write(Helper.StringToPaddedByteArray(me.Description, 256)); bw.Write(Helper.StringToPaddedByteArray(me.onActivate, 256)); } bw_o.Flush(); int content_ofs = (int)bw_o.BaseStream.Position + 4; bw_o.Write(content_ofs + (int)ms_outbuf2.Length); bw.Close(); bw_o.Close(); bw = new BinaryWriter(fs); bw.Write(ms_outbuf.ToArray()); bw.Write(ms_outbuf2.ToArray()); //write number of compiled vc functions bw.Write((int)0); bw.Close(); return 0; }
public Map tileCopyRange(int x0, int y0, int w, int h) { Map m = new Map(); foreach (MapLayer ml in Layers) { MapLayer ml2 = ml.copyRange(x0, y0, w, h); ml2.parentmap = m; m.AddLayer(ml2); } return m; }
public Map CreateMap() { Map m = new Map(); int l_count = (int)n_layers.Value; int l_w = (int)n_w.Value; int l_h = (int)n_h.Value; bool bNewvsp = rb_new.Checked; for(int i=0;i<l_count;i++) { MapLayer ml = new MapLayer(m); ml.size(l_w,l_h); ml.name = "Layer " + i; ml.type = LayerType.Tile; ml.parallaxInfo = new ParallaxInfo(); m.Layers.Add(ml); } MapLayer zl = new MapLayer(m); zl.type = LayerType.Zone; zl.name = "Zones"; zl.size(l_w,l_h); m.ZoneLayer=zl; MapLayer ol = new MapLayer(m); ol.type = LayerType.Obs; ol.name = "Obstructions"; ol.size(l_w,l_h); m.ObsLayer = ol; MapLayer el = new MapLayer(m); el.type = LayerType.Entity; el.name = "Entities"; MapLayerSpecial rl = new MapLayerSpecial(m); rl.type=LayerType.Special_Retrace; m.Layers.Add(rl); m.Layers.Add(el); m.Layers.Add(ol); m.Layers.Add(zl); m.EntLayer = el; if(bNewvsp) { Vsp24 v = new Vsp24(); //v.AddTiles(100); v.Tiles.AddRange(v.GetTiles(100)); m.vsp = v; } else { Vsp24 v = InputOutput.ReadVsp(t_vspfile.Text); if(v==null) { Errors.Error("Warning", "An error occured when attempting to load the vsp file. A blank VSP has been created."); v = new Vsp24(); v.Tiles.Add(v.GetTiles(100)); m.vsp = v; } else m.vsp = v; } MapZone mz = new MapZone(); mz.ID = 0; mz.Name = "NULL_ZONE"; m.Zones.Add(mz); m.Init(); m.RenderString = ""; return m; }
public static Map ReadMap2(FileInfo fi) { FileStream fs = fi.OpenRead(); BinaryReader br = new BinaryReader(fs); byte[] Buffer = br.ReadBytes((int)fi.Length); br.Close(); Map map = new Map(); map.FileOnDisk = fi; MemoryStream ms = new MemoryStream(Buffer); br = new BinaryReader(ms); if (Buffer[0] != 77 || Buffer[1] != 65 || Buffer[2] != 80 || Buffer[3] != 249 || Buffer[4] != 53 || Buffer[5] != 0) { Errors.Error("InputOutput", "File is not a VERGE2 Map"); return null; } // 6 bytes signature // 4 bytes unknown?? // --- // advance 10 bytes br.ReadBytes(10); // 60 bytes VSP FileName FileInfo vspfile = new FileInfo(Helper.BytesToString(br.ReadBytes(60))); if (!vspfile.Exists) { // TODO: give the option to create a vsp in this case Errors.Error("InputOutput", "VSP was not found. New VSP created."); map.vsp = new Vsp24(); } else { map.vsp = ReadVsp(vspfile.FullName); } // 60 bytes music filename map.MusicFileName = Helper.BytesToString(br.ReadBytes(60)); // 20 bytes render string string dontcare = Helper.BytesToString(br.ReadBytes(20)); // 4 bytes, start position map.PlayerStartX = (int)br.ReadInt16(); map.PlayerStartY = (int)br.ReadInt16(); // 51 bytes, unknown br.ReadBytes(51); // 1 byte, number of layers int layerCount = (int)br.ReadByte(); for (int i = 0; i < layerCount; i++) { // 12 bytes per layer discriptor MapLayer ml = new MapLayer(map); ml.type = LayerType.Tile; ml.name = "Layer " + i.ToString(); int mx, dx, my, dy; mx = (int)br.ReadByte(); dx = (int)br.ReadByte(); my = (int)br.ReadByte(); dy = (int)br.ReadByte(); double dmx, dmy; dmx = 1.0 * mx / dx; dmy = 1.0 * my / dy; ml.parallaxInfo.MultipleX = dmx; ml.parallaxInfo.MultipleY = dmy; /* ml.parallaxInfo.MultiplyX = (int)br.ReadByte(); ml.parallaxInfo.DivideX = (int)br.ReadByte(); ml.parallaxInfo.MultiplyY = (int)br.ReadByte(); ml.parallaxInfo.DivideY = (int)br.ReadByte(); */ int w = (int)br.ReadInt16(); int h = (int)br.ReadInt16(); ml.size(w, h); ml.Translucency = (int)br.ReadByte(); ml.HLine = (int)br.ReadByte(); // padding br.ReadInt16(); map.Layers.Add(ml); } for (int i = 0; i < layerCount; i++) { int rleLength = br.ReadInt32(); ushort[] layerdata = InputOutput.DecompressData16(Helper.BytesToWords(br.ReadBytes(rleLength))); MapLayer ml = (MapLayer)map.Layers[i]; ml.Data = new short[ml.Width * ml.Height]; for (int j = 0; j < ml.Width * ml.Height; j++) ml.Data[j] = (short)layerdata[j]; } int obsDataLength = br.ReadInt32(); byte[] obsdata = InputOutput.DecompressData8(br.ReadBytes(obsDataLength)); map.ObsLayer = new MapLayer(map); map.ObsLayer.type = LayerType.Obs; map.ObsLayer.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height); map.ObsLayer.name = "Obstructions"; map.ObsLayer.Data = new short[map.ObsLayer.Width * map.ObsLayer.Height]; for (int i = 0; i < map.ObsLayer.Width * map.ObsLayer.Height; i++) map.ObsLayer.Data[i] = obsdata[i]; int zoneDataLength = br.ReadInt32(); byte[] zonedata = InputOutput.DecompressData8(br.ReadBytes(zoneDataLength)); map.ZoneLayer = new MapLayer(map); map.ZoneLayer.type = LayerType.Zone; map.ZoneLayer.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height); map.ZoneLayer.name = "Zones"; map.ZoneLayer.Data = new short[map.ZoneLayer.Width * map.ZoneLayer.Height]; for (int i = 0; i < map.ZoneLayer.Width * map.ZoneLayer.Height; i++) map.ZoneLayer.Data[i] = zonedata[i]; MapLayer el = new MapLayer(map); el.type = LayerType.Entity; el.name = "Entities"; map.Layers.Add(el); map.EntLayer = el; MapLayerSpecial rl = new MapLayerSpecial(map); rl.type = LayerType.Special_Retrace; map.Layers.Add(rl); map.Layers.Add(map.ObsLayer); map.Layers.Add(map.ZoneLayer); int zoneCount = br.ReadInt32(); // 50 bytes per zone for (int i = 0; i < zoneCount; i++) { MapZone mz = new MapZone(); mz.ID = i; mz.Name = Helper.CharsToString(br.ReadChars(40)); //Errors.Error(mz.Name); mz.PlayerScript = ""; br.ReadInt16(); mz.Rate = (int)br.ReadInt16(); mz.Delay = (int)br.ReadInt16(); mz.Flags = (int)br.ReadInt16(); mz.EntityScript = ""; br.ReadInt16(); map.Zones.Add(mz); } if (zoneCount == 0) { MapZone mz = new MapZone(); mz.ID = 0; mz.Name = "NULL_ZONE"; map.Zones.Add(mz); } int chrCount = (int)br.ReadByte(); ArrayList al_chrs = new ArrayList(); for (int i = 0; i < chrCount; i++) { MapChr mc = new MapChr(); try { mc.Name = Helper.BytesToFileString(br.ReadBytes(60)); } catch (Exception e) { mc.Name = ""; /// there's no error log in maped3 yet. I'll discuss this with the boys. For now, ANNOYING MESSAGE BOX! /// -gru Errors.Error("I/O", "Bad filename for MapChr(" + i + "): " + e.Message + "\nDefaulting to empty string for file name."); } mc.ID = i; if (mc.Name.Length > 0) { FileInfo mcfi = new FileInfo(mc.Name); if (ReadCHR(mcfi, mc) == 0) mc.bImageAvailable = true; } al_chrs.Add(mc); } int entCount = (int)br.ReadByte(); //Errors.Error(entCount.ToString() + ", "+br.BaseStream.Position.ToString()); for (int i = 0; i < entCount; i++) { MapEntity me = new MapEntity(); me.TileX = (int)br.ReadInt32(); me.TileY = (int)br.ReadInt32(); int xx = (int)br.ReadInt16(); int xy = (int)br.ReadInt16(); //Errors.Error(""+ me.TileX+","+me.TileY+":"+xx+","+xy); // ignore //br.ReadBytes(4); me.Facing = (int)br.ReadByte(); if (me.Facing == 0) me.Facing = 2; me.Moving = (int)br.ReadByte(); // ignore br.ReadByte(); me.BottomLineFrame = (int)br.ReadByte(); me.SpecialFrameSet = (int)br.ReadByte(); int cidx = (int)br.ReadByte(); // assign chr // dont do this //me.Chr = ((MapChr)al_chrs[cidx]).Clone(); me.ChrName = string.Copy(((MapChr)al_chrs[cidx]).Name); me.Reset = (int)br.ReadByte(); me.ObeyObstruction = (int)br.ReadByte(); me.IsObstruction = (int)br.ReadByte(); me.Speed = (int)br.ReadByte(); switch (me.Speed) { case 1: me.Speed = 25; break; case 2: me.Speed = 33; break; case 3: me.Speed = 50; break; case 4: me.Speed = 100; break; case 5: me.Speed = 200; break; case 6: me.Speed = 300; break; case 7: me.Speed = 400; break; } // ignore br.ReadBytes(10); // entspeedcnt(1), anim frame delay(1), anim script(4), move script(4) //32 me.AutoFace = (int)br.ReadByte(); me.ActivationMode = (int)br.ReadByte(); me.MoveType = (int)br.ReadByte(); if (me.MoveType > 1) me.MoveType--; me.__movescript = (int)br.ReadByte(); // ignore br.ReadBytes(2); // subtile move ctr, mode flag me.WanderSteps = (int)br.ReadInt16(); me.WanderDelay = (int)br.ReadInt16(); // ignore br.ReadBytes(4); // step ctr, delay ctr me.ID = i; br.ReadBytes(2); // WTF IS THIS!! for (int j = 0; j < 6; j++) { me.UserData[j] = br.ReadInt16(); } me.WanderRectangle.x0 = me.UserData[1]; me.WanderRectangle.y0 = me.UserData[2]; me.WanderRectangle.x1 = me.UserData[4]; me.WanderRectangle.y1 = me.UserData[5]; // ignore br.ReadBytes(20); // a lot of shiznit me.Description = Helper.BytesToString(br.ReadBytes(20)); //Errors.Error(me.Description); //br.ReadBytes(2); // WTF IS THIS!! me.ID = i; map.Entities.Add(me); } int movescriptCount = (int)br.ReadByte(); int movescriptBuffersize = (int)br.ReadInt32(); ArrayList al_scripts = new ArrayList(); // ignore br.ReadBytes(4 * movescriptCount); string script = ""; while (movescriptBuffersize > 0) { char c = br.ReadChar(); if (c == (char)0) { al_scripts.Add(string.Copy(script)); script = ""; } else script += c; movescriptBuffersize--; } // add all the scripts to their respective entities and trash the movescript array foreach (MapEntity me in map.Entities) { me.MoveScript = (string)al_scripts[me.__movescript]; } br.Close(); string rs2 = ""; foreach (char c in dontcare) { if (rs2.Length != 0) rs2 += ","; rs2 += c; } map.RenderString = rs2; return map; }
public void Setup(Map map) { if (true)//map.RenderString.Length==0) { foreach (MapLayer ml in map.Layers) { LayerState ls = new LayerState(); ls.bRender = true; ls.mlayer = ml; Layers.Add(ls); } } }
public void update(Map m) { map = m; }
public void SetRenderString(Map m, string v) { map = m; string[] comms = v.Split(','); ArrayList layers = new ArrayList(); foreach (MapLayer ml in m.Layers) { if (ml.type == LayerType.Tile) layers.Add(ml); } Layers.Clear(); foreach (string s in comms) { if (s.Length == 0) continue; if (char.IsDigit(s[0])) // layer { Layers.Add(layers[int.Parse(s) - 1]); } else if (s.ToLower() == "e") { Layers.Add(m.EntLayer); } else if (s.ToLower() == "r") { // locate R layer foreach (MapLayer ml in m.Layers) { if (ml.type == LayerType.Special_Retrace) { Layers.Add(ml); break; } } } } foreach (MapLayer ml in m.Layers) { if (ml is MapLayerSpecial || ml.type == LayerType.Tile || ml.type == LayerType.Entity) if (!Layers.Contains(ml)) Layers.Add(ml); } Layers.Add(m.ObsLayer); Layers.Add(m.ZoneLayer); }
public MapLayerSpecial(Map p) : base(p) { }
public MapLayer(Map parent) { parentmap = parent; }
public void lpInit(Map map) { foreach (LPanel lw in lwLayers) { lw.Dispose(); } lwLayers.Clear(); for (int i = 0; i < map.RenderManager.Layers.Count; i++) { MapLayer ml = (MapLayer)map.RenderManager.Layers[i]; lpAddLayer(ml, true, Global.IsBaseLayer(ml), i); } // if(Global.lpSelection==null) // ((LPanel)lwLayers[0]).SelectForWrite(); l_rstring.Text = Global.ActiveMap.RenderManager.ToRenderString(); ui_update(); }
public void lpUpdate(Map map, MapLayer select) { foreach (LPanel lw in lwLayers) { lw.Dispose(); } lwLayers.Clear(); for (int i = 0; i < map.RenderManager.Layers.Count; i++) { MapLayer ml = (MapLayer)map.RenderManager.Layers[i]; lpAddLayer(ml, true, (ml == select), i); } l_rstring.Text = Global.ActiveMap.RenderManager.ToRenderString(); ui_update(); }
protected override void OnMouseUp(MouseEventArgs e) { Capture = false; trackingMouse = false; if (trackingDrag) { trackingDrag = false; int _x0 = dragStart.X; int _y0 = (dragStart.Y); int _x1 = (dragEnd.X); int _y1 = (dragEnd.Y); int x0 = Math.Min(_x0, _x1); int x1 = Math.Max(_x0, _x1); int y0 = Math.Min(_y0, _y1); int y1 = Math.Max(_y0, _y1); Map m = new Map(); MapLayer ml = new MapLayer(m); ml.resize(x1 - x0 + 1, y1 - y0 + 1); for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { //((scrollOffset / Global.TILE_SIZE) + (my / Global.TILE_SIZE)) * TilesWide + (mx / Global.TILE_SIZE); int tile = y * TilesWide + x + (scrollOffset / Global.TILE_SIZE * TilesWide); ml.setTile(x - x0, y - y0, tile); } } m.AddLayer(ml); m.IsBrush = true; m.vsp = vsp; Global.clipboard = m; } }
public static unsafe Map ReadMap3(FileInfo fi) { byte[] m3s = new byte[] { (byte)'V', (byte)'3', (byte)'M', (byte)'A', (byte)'P', (byte)0 }; FileStream fs = fi.OpenRead(); BinaryReader br = new BinaryReader(fs); Map map = new Map(); map.FileOnDisk = fi; // Directory.SetCurrentDirectory(map.FileOnDisk.Directory.FullName); byte[] sig = br.ReadBytes(m3s.Length); for (int i = 0; i < m3s.Length; i++) if (sig[i] != m3s[i]) return null; int version = br.ReadInt32(); int vcofs = br.ReadInt32(); if (version >= 3) { int numNotes = br.ReadInt32(); for (int i = 0; i < numNotes; i++) { Map.Note note = new Map.Note(); note.x = br.ReadInt32(); note.y = br.ReadInt32(); int strlen = br.ReadInt32(); byte[] bytes = br.ReadBytes(strlen); note.note = System.Text.Encoding.ASCII.GetString(bytes); map.Notes.Add(note); } } byte[] formal = br.ReadBytes(256); byte[] vspname = br.ReadBytes(256); byte[] musicname = br.ReadBytes(256); byte[] renderstring = br.ReadBytes(256); byte[] aexec = br.ReadBytes(256); string vspf = Helper.BytesToString(vspname); FileInfo vspfile; try { vspfile = new FileInfo(vspf); } catch (ArgumentException) { throw new Exception("VSP file is inaccessible. Requested file was '" + vspf + "'"); } if (!vspfile.Exists) { System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("Unable to load requested VSP file. Create a blank vsp?", "Load Error", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Information); if (dr == System.Windows.Forms.DialogResult.OK) map.vsp = new Vsp24(); else if (dr == System.Windows.Forms.DialogResult.Cancel) return null; else return null; } else { map.vsp = ReadVsp(vspfile.FullName); } map.FormalName = Helper.BytesToString(formal); map.MusicFileName = Helper.BytesToString(musicname); //map.RenderString = Helper.BytesToString(renderstring); string rs = Helper.BytesToString(renderstring); map.AutoExecEvent = Helper.BytesToString(aexec); map.PlayerStartX = br.ReadInt16(); map.PlayerStartY = br.ReadInt16(); int layercount = br.ReadInt32(); for (int i = 0; i < layercount; i++) { MapLayer ml = new MapLayer(map); ml.name = Helper.BytesToString(br.ReadBytes(256)); ml.type = LayerType.Tile; ml.parallaxInfo = new ParallaxInfo(); ml.parallaxInfo.MultipleX = br.ReadDouble(); ml.parallaxInfo.MultipleY = br.ReadDouble(); int w = br.ReadInt16(); int h = br.ReadInt16(); ml.size(w, h); ml.Translucency = br.ReadByte(); int len = br.ReadInt32(); int zlen = br.ReadInt32(); ml.Data = ZLIB.DecodeShorts(br.ReadBytes(zlen), len); map.Layers.Add(ml); } MapLayer ol = new MapLayer(map); ol.type = LayerType.Obs; ol.name = "Obstructions"; ol.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height); int ol_lenn = br.ReadInt32(); int ol_len = br.ReadInt32(); byte[] obsdata = ZLIB.Decode(br.ReadBytes(ol_len), ol_lenn); //patch up total garbage obstruction data for (int i = 0; i < obsdata.Length; i++) { ol.Data[i] = obsdata[i]; #if ASTRAL if (ol.Data[i] >= 16) //NUM_OBS ol.Data[i] = 15; #endif } map.ObsLayer = ol; int zl_lenn = br.ReadInt32(); int zl_len = br.ReadInt32(); MapLayer zl = new MapLayer(map); zl.type = LayerType.Zone; zl.name = "Zones"; zl.size(((MapLayer)map.Layers[0]).Width, ((MapLayer)map.Layers[0]).Height); zl.Data = ZLIB.DecodeShorts(br.ReadBytes(zl_len), zl_lenn); map.ZoneLayer = zl; MapLayer el = new MapLayer(map); el.type = LayerType.Entity; el.name = "Entities"; map.EntLayer = el; map.Layers.Add(el); MapLayerSpecial rl = new MapLayerSpecial(map); rl.type = LayerType.Special_Retrace; map.Layers.Add(rl); map.Layers.Add(ol); map.Layers.Add(zl); int zonecount = br.ReadInt32(); for (int i = 0; i < zonecount; i++) { MapZone mz = new MapZone(); byte[] zname = br.ReadBytes(256); byte[] pscript = br.ReadBytes(256); // byte[] escript = br.ReadBytes(256); mz.Name = Helper.BytesToString(zname); mz.PlayerScript = Helper.BytesToString(pscript); // mz.EntityScript = Helper.BytesToString(escript); mz.Rate = br.ReadByte(); mz.Delay = br.ReadByte(); mz.Flags = br.ReadByte(); mz.ID = i; map.Zones.Add(mz); } if (zonecount == 0) { MapZone mz = new MapZone(); mz.ID = 0; mz.Name = "NULL_ZONE"; map.Zones.Add(mz); } int entcount = br.ReadInt32(); for (int i = 0; i < entcount; i++) { MapEntity me = new MapEntity(); me.TileX = br.ReadInt16(); me.TileY = br.ReadInt16(); me.Facing = br.ReadByte(); me.ObeyObstruction = br.ReadByte(); me.IsObstruction = br.ReadByte(); me.AutoFace = br.ReadByte(); me.Speed = br.ReadInt16(); me.ActivationMode = br.ReadByte(); me.MoveType = br.ReadByte(); me.WanderRectangle.x0 = br.ReadInt16(); me.WanderRectangle.y0 = br.ReadInt16(); me.WanderRectangle.x1 = br.ReadInt16(); me.WanderRectangle.y1 = br.ReadInt16(); me.WanderDelay = br.ReadInt16(); int expand = br.ReadInt32(); me.MoveScript = Helper.BytesToString(br.ReadBytes(256)); me.ChrName = Helper.BytesToString(br.ReadBytes(256)); me.Description = Helper.BytesToString(br.ReadBytes(256)); me.onActivate = Helper.BytesToString(br.ReadBytes(256)); map.Entities.Add(me); me.ID = map.Entities.Count-1; } br.Close(); string rs2 = ""; if (version == 1) { foreach (char c in rs) { if (rs2.Length != 0) rs2 += ","; rs2 += c; } map.RenderString = rs2; } else map.RenderString = rs; return map; }
public Map tileCopy() { Map m = new Map(); foreach (MapLayer ml in Layers) { MapLayer ml2 = ml.copy(); ml2.parentmap = m; m.AddLayer(ml2); } return m; }
public static int WriteMap(FileInfo fi, Map map) { //WriteMapJson(fi, map); //return 0; return WriteMap_Archaic(fi, map); }
public void init(Map m, List<MapZone> zones) { map = m; zoneLayerCopy = m.ZoneLayer.copy(); foreach (MapZone mz in zones) { zoneCopy.Add(mz.Clone()); } foreach (MapZone mz in zoneCopy) { ListViewItem lvi = new ListViewItem(new string[] { mz.ID.ToString(), mz.Name }); lvi.Tag = mz; lv_zones.Items.Add(lvi); } }