private void BuildBanks() { SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Building banks", OutputMessageType.Information); ProjectModel projectModel = ModelManager.Get <ProjectModel>(); string outputPath = Path.GetFullPath(projectModel.Build.OutputFilePath); List <FileModelVO> bankModelVOs = ProjectFiles.GetModels <BankModel>(); const int cellSizeInBytes = 128; // 16 bytes each cell foreach (FileModelVO vo in bankModelVOs) { BankModel bank = vo.Model as BankModel; int cellsCount = 0; switch (bank.BankSize) { case BankSize.Size4Kb: cellsCount = 16 * 16; break; case BankSize.Size2Kb: cellsCount = 16 * 8; break; case BankSize.Size1Kb: cellsCount = 16 * 4; break; } Dictionary <string, WriteableBitmap> bitmapCache = new Dictionary <string, WriteableBitmap>(); BitArray outputBits = new BitArray(cellSizeInBytes * cellsCount); outputBits.SetAll(false); int currentIndex = 0; WriteableBitmap bitmap = BanksUtils.CreateImage(bank, ref bitmapCache, false); using (bitmap.GetBitmapContext()) { WriteIntoBitArray(bank, bitmap, ref outputBits, ref currentIndex); } for (int i = 0; i < cellSizeInBytes * cellsCount;) { Reverse(ref outputBits, i, 8); i += 8; } byte[] bytes = new byte[outputBits.Length / 8]; outputBits.CopyTo(bytes, 0); string fullPath = Path.Combine(outputPath, vo.Name.ToLower() + ".bin"); File.WriteAllBytes(fullPath, bytes); } SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Finishing building banks", OutputMessageType.Information); }
private void BuildBackgrounds() { SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Building background", OutputMessageType.Information); ProjectModel projectModel = ModelManager.Get <ProjectModel>(); List <FileModelVO> models = ProjectFiles.GetModels <MapModel>(); foreach (FileModelVO item in models) { MapModel model = item.Model as MapModel; string fullPath = Path.Combine(Path.GetFullPath(projectModel.Build.OutputFilePath), item.Name + ".s"); using (StreamWriter outputFile = new StreamWriter(fullPath)) { outputFile.WriteLine("; This file is autogenerated!"); outputFile.Write(Environment.NewLine); outputFile.WriteLine($"nt_{item.Name}:"); List <byte> serializedMap = new List <byte>(); SerializeNametable(model, ref serializedMap); if (projectModel.Build.UseRLEOnMaps) { RLE.Compress(serializedMap, out List <byte> compressedData); serializedMap = compressedData; } FormatBytes(serializedMap, outputFile, 32); serializedMap.Clear(); if (model.ExportAttributeTable) { outputFile.WriteLine($"att_{item.Name}:"); SerializeAttributes(model, ref serializedMap); if (projectModel.Build.UseRLEOnMaps) { RLE.Compress(serializedMap, out List <byte> compressedData); serializedMap = compressedData; } FormatBytes(serializedMap, outputFile, 8); } PrintMetaData(model, item, outputFile); } } SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Finishing building background", OutputMessageType.Information); }
private void BuildPalettes() { SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Building palettes", OutputMessageType.Information); ProjectModel projectModel = ModelManager.Get <ProjectModel>(); string fullPath = Path.Combine(Path.GetFullPath(projectModel.Build.OutputFilePath), "palettes.s"); using (StreamWriter outputFile = new StreamWriter(fullPath)) { List <FileModelVO> paletteModelVOs = ProjectFiles.GetModels <PaletteModel>(); outputFile.WriteLine("; This file is autogenerated!"); SortedDictionary <string, StringWriter> pals = new SortedDictionary <string, StringWriter>(); foreach (FileModelVO vo in paletteModelVOs) { PaletteModel model = vo.Model as PaletteModel; string name = "palette_" + vo.Name.Replace(' ', '_').ToLower(); Color color0 = Util.GetColorFromInt(model.Color0); Color color1 = Util.GetColorFromInt(model.Color1); Color color2 = Util.GetColorFromInt(model.Color2); Color color3 = Util.GetColorFromInt(model.Color3); StringWriter stringWriter = new StringWriter(); stringWriter.Write($" .byte "); stringWriter.Write($"${Util.ColorToColorHex(color0)},"); stringWriter.Write($"${Util.ColorToColorHex(color1)},"); stringWriter.Write($"${Util.ColorToColorHex(color2)},"); stringWriter.Write($"${Util.ColorToColorHex(color3)}"); pals.Add(name, stringWriter); } foreach (var item in pals) { outputFile.WriteLine(""); outputFile.WriteLine($"{item.Key}:"); outputFile.Write(item.Value.ToString()); outputFile.Write(Environment.NewLine); } } SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Finished building palettes", OutputMessageType.Information); }
public override void Execute(object parameter) { object[] values = (object[])parameter; Point croppedPoint = (Point)values[1]; int selectedTileSet = (int)values[2]; BankModel model = (BankModel)values[3]; if (model.GetEmptyTileIndex(out int index)) { FileModelVO[] tileSets = ProjectFiles.GetModels <TileSetModel>().ToArray(); model.PTTiles[index].GUID = Guid.NewGuid().ToString(); model.PTTiles[index].TileSetID = tileSets[selectedTileSet].Model.GUID; model.PTTiles[index].Point = croppedPoint; model.PTTiles[index].Group = index; SignalManager.Get <BankImageUpdatedSignal>().Dispatch(); } }
private void BuildTilesDefinitions() { SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Building tiles definitions", OutputMessageType.Information); List <FileModelVO> bankModelVOs = ProjectFiles.GetModels <BankModel>(); foreach (FileModelVO bankVO in bankModelVOs) { BankModel bank = bankVO.Model as BankModel; if (bank.BankUseType != BankUseType.Background) { continue; } BuildTilesDefinition(bankVO.Name, bank); } SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Finishing building tiles definitions", OutputMessageType.Information); }
private void BuildMetaSprites() { SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Building meta sprites", OutputMessageType.Information); ProjectModel projectModel = ModelManager.Get <ProjectModel>(); List <FileModelVO> models = ProjectFiles.GetModels <CharacterModel>(); foreach (FileModelVO item in models) { CharacterModel model = item.Model as CharacterModel; string fullPath = Path.Combine(Path.GetFullPath(projectModel.Build.OutputFilePath), item.Name + ".s"); using (StreamWriter outputFile = new StreamWriter(fullPath)) { WriteMetaSpriteHeader(outputFile); WriteMetaSprites(outputFile, model, item.Name); } } SignalManager.Get <WriteBuildOutputSignal>().Dispatch("Finishing building meta sprites", OutputMessageType.Information); }
public static WriteableBitmap CreateImage(BankModel bankModel, ref Dictionary <string, WriteableBitmap> bitmapCache, bool sendSignals = true) { FileModelVO[] tileSets = ProjectFiles.GetModels <TileSetModel>().ToArray(); WriteableBitmap bankBitmap = BitmapFactory.New(128, 128); int index = 0; foreach (PTTileModel tile in bankModel.PTTiles) { if (string.IsNullOrEmpty(tile.GUID) || string.IsNullOrEmpty(tile.TileSetID)) { continue; } if (!bitmapCache.TryGetValue(tile.TileSetID, out WriteableBitmap sourceBitmap)) { TileSetModel model = ProjectFiles.GetModel <TileSetModel>(tile.TileSetID); if (model == null) { continue; } ProjectModel projectModel = ModelManager.Get <ProjectModel>(); string path = Path.Combine(projectModel.ProjectPath, model.ImagePath); BitmapImage bmImage = new BitmapImage(); bmImage.BeginInit(); bmImage.CacheOption = BitmapCacheOption.OnLoad; bmImage.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); bmImage.EndInit(); bmImage.Freeze(); sourceBitmap = BitmapFactory.ConvertToPbgra32Format(bmImage); bitmapCache.Add(tile.TileSetID, sourceBitmap); if (sendSignals) { // Add the link object foreach (FileModelVO tileset in tileSets) { if (tileset.Model.GUID == tile.TileSetID) { SignalManager.Get <AddNewTileSetLinkSignal>().Dispatch(new BankLinkVO() { Caption = tileset.Name, Id = tile.TileSetID }); break; } } } } WriteableBitmap cropped = sourceBitmap.Crop((int)tile.Point.X, (int)tile.Point.Y, 8, 8); int destX = index % 16 * 8; int destY = index / 16 * 8; Util.CopyBitmapImageToWriteableBitmap(ref bankBitmap, destX, destY, cropped); index++; } return(bankBitmap); }