public void PokeDTileSetRequest(Client player, IEnumerable <string> tileSetNames) { var tileSets = new List <TileSetResponse>(); var images = new List <ImageResponse>(); foreach (var tileSetName in tileSetNames) { tileSets.Add(new TileSetResponse() { Name = tileSetName, TileSetData = TileSets.GetFileAsync($"{tileSetName}.tsx").Result.ReadAllTextAsync().Result }); var image = new ImageResponse { Name = tileSetName }; using (var fileStream = TileSets.GetFileAsync($"{tileSetName}.png").Result.OpenAsync(FileAccess.Read).Result) image.ImageData = fileStream.ReadFully(); images.Add(image); } player.SendPacket(new TileSetResponsePacket() { TileSets = tileSets.ToArray(), Images = images.ToArray() }); }
public TileSet(ContentManager content, TileSets tileSet) { string path = "Textures/TileSet/" + tileSet.ToString(); LoadTextures(content, path); nullTex = content.Load <Texture2D>("Example"); }
#pragma warning restore 649 #endregion #region Methods public void BeforeSave() { foreach (var xTileSetVM in TileSets.Cast <XAbstractTileSetVM>().Union(TerrainSets)) { foreach (var vm in xTileSetVM.Children) { vm.BeforeSave(); } } }
// Read all tile sets from ROM. private void ReadTileSets(Rom rom) { int addresPC = TileSet.TileSetsAddresPC; TileSets.Clear(); for (int n = 0; n < TileSet.Count; n++) { TileSets.Add(new TileSet()); TileSets [n].ReadFromROM(rom, addresPC); addresPC += TileSet.DefaultSize; } }
public void loadTMXFile(string path, bool bind) { XmlDocument xml = new XmlDocument(); xml.LoadXml(File.ReadAllText(path)); XmlNode mapNode = xml["map"]; //get basic info int mapWidth = int.Parse(mapNode.Attributes["width"].InnerText); int mapHeight = int.Parse(mapNode.Attributes["height"].InnerText); int tileWidth = int.Parse(mapNode.Attributes["tilewidth"].InnerText); int tileHeight = int.Parse(mapNode.Attributes["tileheight"].InnerText); //load world (assumes same sized tiles throughout layers) foreach (XmlNode subNode in mapNode) { if (subNode.Name.EqualsIgnoreCase("tileset")) { string imageAtlasFile = subNode["image"].Attributes["source"].InnerText; string imageAtlasPath = Path.Combine(Path.GetDirectoryName(path), imageAtlasFile); int startIndex = int.Parse(subNode.Attributes["firstgid"].InnerText); TileSets.Add(TileSet <Tile> .fromImageAtlas(imageAtlasPath, startIndex, tileWidth, tileHeight)); rebuildTileLut(); //(future proofing) do now incase layers ever need to inspect the tiles } else if (subNode.Name.EqualsIgnoreCase("layer")) { string layerFormat = subNode["data"].Attributes["encoding"].InnerText; if (layerFormat.EqualsIgnoreCase("csv")) { //get all numbers from the csv [LIKE A BOSS] //int[] indicies = subNode["data"].InnerText.Split(',').Select(n => int.Parse(n.Trim())).ToArray(); int[] indicies = subNode["data"].InnerText.ParseAllIntegers(); Panes.Add(new TiledPane(mapWidth, mapHeight, indicies, this)); } else { WDAppLog.logError(ErrorLevel.Error, "Unsuported layer format", path); } } else if (subNode.Name.EqualsIgnoreCase("objectgroup")) { } else if (subNode.Name.EqualsIgnoreCase("imagelayer")) { string imageFile = subNode["image"].Attributes["source"].InnerText.Trim(); string imagePath = Path.Combine(Path.GetDirectoryName(path), imageFile); Bitmap b = new Bitmap(imagePath); Panes.Add(new ImagePane(b)); } } }
public TileSets(TileSets _tileSet) { blockOffset = _tileSet.blockOffset; floorOffset = _tileSet.floorOffset; tileI = _tileSet.tileI; tileC = _tileSet.tileC; tileCi = _tileSet.tileCi; tileB = _tileSet.tileB; tileF = _tileSet.tileF; yRotationOffset = new float[_tileSet.yRotationOffset.Length]; for (int f = 0; f < _tileSet.yRotationOffset.Length; f++) { yRotationOffset[f] = _tileSet.yRotationOffset[f]; } }
public XElement ToXml() { return(new XElement("map", new object[12] { new XAttribute("version", Version), new XAttribute("orientation", Orientation), new XAttribute("renderorder", RenderOrder), new XAttribute("width", Width), new XAttribute("height", Height), new XAttribute("tilewidth", TileWidth), new XAttribute("tileheight", TileHeight), new XAttribute("nextobjectid", NextObjectId), XmlUtils.If(Properties.Any(), new XElement("properties", Properties.Select(prop => prop.ToXml()))), TileSets.Select(tileSet => tileSet.ToXml()), Layers.Select(layer => layer.ToXml()), ObjectGroups.Select(objectGroup => objectGroup.ToXml()) })); }
public void Close() { if (!ProjectLoaded) { return; } Rooms.Clear(); DoorSets.Clear(); Doors.Clear(); ScrollSets.Clear(); PlmSets.Clear(); ScrollPlmDatas.Clear(); Backgrounds.Clear(); Fxs.Clear(); SaveStations.Clear(); LevelDatas.Clear(); EnemySets.Clear(); EnemyGfxs.Clear(); ScrollAsms.Clear(); DoorAsms.Clear(); SetupAsms.Clear(); MainAsms.Clear(); TileSets.Clear(); TileTables.Clear(); TileSheets.Clear(); Palettes.Clear(); AreaMaps.Clear(); PlmTypes.Clear(); EnemyTypes.Clear(); CurrentRom = null; ProjectPath = String.Empty; RomFileName = String.Empty; ProjectFileName = String.Empty; RoomTiles.Clear(); MapTiles.Clear(); BackgroundImage = null; ChangesMade = false; ProjectLoaded = false; ProjectClosed?.Invoke(this, null); }
public Texture2D ToTexture2D() { const int cellSize = 8; const int tileSize = cellSize * cellSize; var tex = TextureHelpers.CreateTexture2D(Map.Width * cellSize, Map.Height * cellSize); var pal = Util.ConvertGBAPalette(Palette); var fullTileSet = TileSets.SelectMany(x => x).ToArray(); for (int y = 0; y < Map.Height; y++) { for (int x = 0; x < Map.Width; x++) { var tile = Map.MapData[y * Map.Width + x]; tex.FillInTile(fullTileSet, tile.TileMapY * tileSize, pal, Util.TileEncoding.Linear_8bpp, cellSize, true, x * cellSize, y * cellSize, tile.HorizontalFlip, tile.VerticalFlip); } } tex.Apply(); return(tex); }
//======================================================================================== // Object management - tools. private void DeleteData(Data data) { if (data is IReferenceable refdata) { refdata.DetachAllReferences(); } switch (data) { case Room d: Rooms.Remove(d); break; case DoorSet d: DoorSets.Remove(d); break; case Door d: Doors.Remove(d); break; case ScrollSet d: ScrollSets.Remove(d); break; case PlmSet d: PlmSets.Remove(d); break; case ScrollPlmData d: ScrollPlmDatas.Remove(d); break; case Background d: Backgrounds.Remove(d); break; case Fx d: Fxs.Remove(d); break; case SaveStation d: SaveStations.Remove(d); break; case LevelData d: LevelDatas.Remove(d); break; case EnemySet d: EnemySets.Remove(d); break; case EnemyGfx d: EnemyGfxs.Remove(d); break; case ScrollAsm d: ScrollAsms.Remove(d); break; case Asm d: DoorAsms.Remove(d); SetupAsms.Remove(d); MainAsms.Remove(d); break; case TileSet d: TileSets.Remove(d); break; case TileTable d: TileTables.Remove(d); break; case TileSheet d: TileSheets.Remove(d); break; case Palette d: Palettes.Remove(d); break; case AreaMap d: AreaMaps.Remove(d); break; default: break; } ChangesMade = true; }
private static async Task Main(string[] args) { Stopwatch stopwatch = Stopwatch.StartNew(); try { Parser.Default.ParseArguments <Options>(args).WithParsed(ParseConsoleOptions) .WithNotParsed(_ => IsParsingErrors = true); } catch (Exception exception) { // Catch some uncaught parsing errors Helpers.ErrorHelper.PrintException(exception); return; } if (IsParsingErrors) { Helpers.ErrorHelper.PrintError(Strings.ParsingError); return; } // Create progress-reporter IProgress <double> consoleProgress = IsProgress ? new Progress <double>(ProgressReporter) : null; Action <string> printTimeAction = IsTime ? new Action <string>(System.Console.WriteLine) : null; // Create temp directory object TempDirectoryPath = Path.Combine(TempDirectoryPath, DateTime.Now.ToString(DateTimePatterns.LongWithMs, CultureInfo.InvariantCulture)); // Run tiling asynchroniously try { // Check for errors if (!await CheckHelper.CheckInputFileAsync(InputFilePath, TargetCoordinateSystem).ConfigureAwait(false)) { string tempFilePath = Path.Combine(TempDirectoryPath, GdalWorker.TempFileName); await GdalWorker.ConvertGeoTiffToTargetSystemAsync(InputFilePath, tempFilePath, TargetCoordinateSystem, consoleProgress).ConfigureAwait(false); InputFilePath = tempFilePath; } await using Raster image = new(InputFilePath, TargetCoordinateSystem, MemCache); // Generate tiles await image.WriteTilesToDirectoryAsync(OutputDirectoryPath, MinZ, MaxZ, TmsCompatible, TileSize, TileExtension, TargetInterpolation, BandsCount, TileCacheCount, ThreadsCount, consoleProgress, printTimeAction) .ConfigureAwait(false); // Generate tilemapresource if needed if (IsTmr) { IEnumerable <TileSet> tileSets = TileSets.GenerateTileSetCollection(MinZ, MaxZ, TileSize, TargetCoordinateSystem); TileMap tileMap = new(image.MinCoordinate, image.MaxCoordinate, TileSize, TileExtension, tileSets, TargetCoordinateSystem); string xmlPath = $"{OutputDirectoryPath}/{TmrName}"; await using FileStream fs = File.OpenWrite(xmlPath); tileMap.Serialize(fs); } } catch (Exception exception) { Helpers.ErrorHelper.PrintException(exception); return; } System.Console.WriteLine(Strings.Done, Environment.NewLine, stopwatch.Elapsed.Days, stopwatch.Elapsed.Hours, stopwatch.Elapsed.Minutes, stopwatch.Elapsed.Seconds, stopwatch.Elapsed.Milliseconds); }