public static WorldMap ReadMap(StreamReader inStream) { WorldMap map = new WorldMap(); map.IntForLoad(); BasicObjectParser parser = null; while (!inStream.EndOfStream) { string line = inStream.ReadLine().Trim(); if (line == string.Empty || line[0] == '#') { continue; } string cmd_norm = GetFirstWord(line); string cmd = cmd_norm.ToUpperInvariant(); if (parser == null) { parser = ParserFactory.Create(cmd); parser.Init(cmd_norm, GetRestOfWords(TrimTrainingComments(line))); } else { if (cmd == "END") { parser.Finish(); map.AddObject(parser.Object); parser = null; } else { parser.AddCodeLine(cmd, TrimTrainingComments(line)); } } } if (parser != null) // should not happen, but don't loose data { parser.Finish(); map.AddObject(parser.Object); parser = null; } map.FinishLoad(); return(map); }
public static WorldMap BuildBZW() { WorldMap map = new WorldMap(); BZWWorld root = GameObject.FindObjectOfType <BZWWorld>(); if (root == null) { return(null); } if (root.Name == string.Empty) { map.WorldInfo.Name = "Untitled BZW"; } map.WorldInfo = root.ToBZWObject() as BZFlag.Map.Elements.World; for (int i = 0; i < root.gameObject.transform.childCount; i++) { var child = root.transform.GetChild(i); BZWBasicObject opt = child.GetComponent <BZWBasicObject>(); if (opt != null) { map.AddObject(opt.ToBZWObject()); } } return(map); }
public WorldMap Unpack() { BufferOffset = 0; WorldMap map = new WorldMap(); int len = ReadUInt16(); ushort code = ReadUInt16(); if (code != Constants.WorldCodeHeader) { return(null); } int Version = ReadUInt16(); if (Version != MapVersion) { return(null); } UInt32 uncompressedSize = ReadUInt32(); UInt32 compressedSize = ReadUInt32(); UInt16 zlibFlags = ReadUInt16(); // deflate doesnt need these try { MemoryStream ms = new MemoryStream(Buffer, BufferOffset, (int)compressedSize); DeflateStream dfs = new DeflateStream(ms, CompressionMode.Decompress); byte[] uncompressedData = new byte[uncompressedSize]; dfs.Read(uncompressedData, 0, (int)uncompressedSize); dfs.Close(); ms.Close(); Buffer = uncompressedData; BufferOffset = 0; // start parsin that sweet sweet world data map.AddObjects(UnpackDynamicColors()); map.AddObjects(UnpackTextureMatricies()); map.AddObjects(UnpackMaterials()); map.AddObjects(UnpackPhysicsDrivers()); map.AddObjects(UnpackTransforms()); map.AddObjects(UnpackObstacles()); map.AddObjects(UnpackLinks()); map.AddObject(UnpackWaterLevel()); map.AddObjects(UnpackWorldWeapons()); map.AddObjects(UnpackZones()); } catch (Exception /*ex*/) { } map.CacheRuntimeObjects(); return(map); }
private void ProcessBrushEvent(MouseButtons button) { if (_brush == BrushMode.Draw) { if (tabControl.SelectedTab == tabPageTiles) { var selectedIndexRect = GetPalletSelectedIndexRectangle(); foreach (var dy in Enumerable.Range(0, selectedIndexRect.Height + 1)) { var y = _canvasMouseY + dy; if (y < 0 || y >= _map.Y) { continue; } foreach (var dx in Enumerable.Range(0, selectedIndexRect.Width + 1)) { var x = _canvasMouseX + dx; if (x < 0 || x >= _map.X) { continue; } if (button == MouseButtons.Left) { _map.Tiles[y, x] = (selectedIndexRect.Top + dy) * _map.Pallet.XCount + (selectedIndexRect.Left + dx); } else if (button == MouseButtons.Right) { _map.Tiles[y, x] = -1; } } } } else if (tabControl.SelectedTab == tabPageObjects) { var currentIndexPos = GetCurrentCanvasIndexPosition(); if (button == MouseButtons.Left) { if (_objectBrush != null) { _map.AddObject(currentIndexPos, _objectBrush); } } else if (button == MouseButtons.Right) { _map.RemoveObject(currentIndexPos); } } } var currentIndex = GetCurrentCanvasIndexPosition(); if (currentIndex.X >= 0 && currentIndex.Y >= 0) { if (_brush == BrushMode.Obstacle) { if (button == MouseButtons.Left) { if (!_map.Obstacles.Contains(currentIndex)) { _map.Obstacles.Add(currentIndex); } } else { _map.Obstacles.Remove(currentIndex); } } } _isDirty = true; UpdateEditorTitle(); panelCanvas.Invalidate(); }