Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Cleaning up canvas and image classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Mar 21, 2020
1 parent cbb41e8 commit b794b2a
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 567 deletions.
20 changes: 0 additions & 20 deletions Runners/LuaRunner/Content/bios.json

This file was deleted.

7 changes: 3 additions & 4 deletions Runners/PixelVision8/Content/bios.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"BaseDir": "PixelVision8",

"Resolution": "512x480",
"BootTool": "/PixelVisionOS/System/Tools/BootTool/",
"LoadTool": "/PixelVisionOS/System/Tools/LoadTool/",
"ErrorTool": "/PixelVisionOS/System/Tools/ErrorTool/",
"AutoRun": "/PixelVisionOS/System/OSInstaller/",
"BootTool": "/PixelVisionOS/Tools/BootTool/",
"LoadTool": "/PixelVisionOS/Tools/LoadTool/",
"ErrorTool": "/PixelVisionOS/Tools/ErrorTool/",

"SystemName": "Pixel Vision 8",
"SystemVersion": "v0.9.8",
Expand Down
271 changes: 85 additions & 186 deletions Runners/PixelVision8/Runner/Editors/GameEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,43 +273,6 @@ public void ResetValidation()
_invalid = false;
}


//
//// [MoonSharpHidden]
//// private ArchiveFlags BuildArchiveFlags(ArchiveFlags[] flags)
//// {
//// // Since Lua doesn't know how to handle bit flags, we need to do the conversion on the C# side of things
//// var archiveFlags = ArchiveFlags.All;
////
//// for (int i = 0; i < flags.Length; i++)
//// {
//// if (flags[i] != ArchiveFlags.All)
//// archiveFlags |= flags[i];
//// }
////
//// return archiveFlags;
//// }
//

//
// // TODO this is not part of the GameChip API?
//// public Vector RealTilemapSize()
//// {
//// return new Vector(gameChip.realWidth, gameChip.realHeight);
//// }
//
// public void AddScript(string name, string code)
// {
// var gameChip = this.gameChip as LuaGameChip;
//
// if (gameChip != null)
// {
// gameChip.AddScript(name, code);
// }
//
// }
//

//
/// <summary>
/// Allows you to save the current game you are editing. Pass in SaveFlags to define which files should be exported.
Expand Down Expand Up @@ -384,30 +347,6 @@ public bool GameSpecsLocked(bool? isLocked = null)
return gameChip.lockSpecs;
}

// /// <summary>
// ///
// /// </summary>
// /// <returns></returns>
// public bool ValidateSize()
// {
//// var size = workspace.CalculateProjectSize() / 1024;
////
// // TODO need to figure out a better way to validate the project size
// return true; //size <= GameMaxSize();
// }
//
// /// <summary>
// ///
// /// </summary>
// /// <param name="safeDelete"></param>
// /// <returns></returns>
// public string Archive(bool safeDelete = true)
// {
// var newFileName = workspace.ArchiveCurrentGame(safeDelete);
//
// return newFileName;
// }
//
/// <summary>
/// Change the name of the game.
/// </summary>
Expand Down Expand Up @@ -674,11 +613,6 @@ public int[] SongPatterns(int id, int[] patterns = null)
return musicChip.songs[id].patterns;
}

// public int TotalSongs()
// {
// return musicChip.totalSongs;
// }

/// <summary>
/// Get the pattern at a position in the song or change it.
/// </summary>
Expand Down Expand Up @@ -961,13 +895,6 @@ public bool DebugColor(bool? flag = null)
return colorChip.debugMode;
}

// public string FlagColor(int id)
// {
// var flagColors = ((ColorChip) targetGame.GetChip(FlagColorParser.flagColorChipName, false)).hexColors;
//
// return flagColors[id];
// }

/// <summary>
/// Change the color mode of the game to edit specific color spaces in the Color Chip.
/// </summary>
Expand Down Expand Up @@ -1055,9 +982,6 @@ public void OptimizeSprites()
spriteChip.UpdateSpriteAt(i, tmpPixelData);
}

// Console.WriteLine("Optimized sprites " + i + " to " + TotalDisks);

// spriteChip.texture = tmpSpriteChip.texture;
}

/// <summary>
Expand All @@ -1074,91 +998,91 @@ public int SpritesInRam()
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public bool LoadImage(string path)
{
// Convert to a system path
var filePath = WorkspacePath.Parse(path);

// If the file doesn't exist, return false.
if (!workspace.Exists(filePath)) return false;

byte[] imageBytes = null;

try
{
// Read bytes from image file
using (var memoryStream = new MemoryStream())
{
workspace.OpenFile(filePath, FileAccess.Read).CopyTo(memoryStream);

imageBytes = memoryStream.ToArray();
}
}
catch
{
runner.DisplayWarning("Unable to read image file.");
}

try
{
// var saveFlags = BuildSaveFlags(new[] { SaveFlags.Colors, SaveFlags.Tilemap });

// var files = new Dictionary<string, byte[]>
// {
// {"colors.png", imageBytes},
// {"tilemap.png", imageBytes}
// };

// We only need a few chips to make this work
string[] chips =
{
typeof(ColorChip).FullName,
typeof(SpriteChip).FullName,
typeof(TilemapChip).FullName,
typeof(DisplayChip).FullName,
typeof(GameChip).FullName
};


targetGame = new PixelVisionEngine(serviceManager, chips)
{
ColorChip = {unique = true},
SpriteChip = {unique = true, colorsPerSprite = 16, pages = 8},
TilemapChip = {autoImport = true}
};

targetGame.ColorChip.Clear();

// var tmpParser = new PNGReader(imageBytes);
var pngReader = new PNGReader(imageBytes, targetGame.ColorChip.maskColor);

// Resize the tilemap
targetGame.TilemapChip.Resize(pngReader.width / 8, pngReader.height / 8);

var loadService = runner.loadService;

loadService.Reset();

loadService.targetEngine = targetGame;

loadService.AddParser(new ColorParser(pngReader, targetGame.ColorChip));
loadService.AddParser(new TilemapParser(pngReader, targetGame));

loadService.LoadAll();

}
catch
{
// Console.WriteLine("Game Editor Load Error:\n"+e.Message);

return false;
}


Reset();

return true;
}
// public bool LoadImage(string path)
// {
// // Convert to a system path
// var filePath = WorkspacePath.Parse(path);
//
// // If the file doesn't exist, return false.
// if (!workspace.Exists(filePath)) return false;
//
// byte[] imageBytes = null;
//
// try
// {
// // Read bytes from image file
// using (var memoryStream = new MemoryStream())
// {
// workspace.OpenFile(filePath, FileAccess.Read).CopyTo(memoryStream);
//
// imageBytes = memoryStream.ToArray();
// }
// }
// catch
// {
// runner.DisplayWarning("Unable to read image file.");
// }
//
// try
// {
// // var saveFlags = BuildSaveFlags(new[] { SaveFlags.Colors, SaveFlags.Tilemap });
//
// // var files = new Dictionary<string, byte[]>
// // {
// // {"colors.png", imageBytes},
// // {"tilemap.png", imageBytes}
// // };
//
// // We only need a few chips to make this work
// string[] chips =
// {
// typeof(ColorChip).FullName,
// typeof(SpriteChip).FullName,
// typeof(TilemapChip).FullName,
// typeof(DisplayChip).FullName,
// typeof(GameChip).FullName
// };
//
//
// targetGame = new PixelVisionEngine(serviceManager, chips)
// {
// ColorChip = {unique = true},
// SpriteChip = {unique = true, colorsPerSprite = 16, pages = 8},
// TilemapChip = {autoImport = true}
// };
//
// targetGame.ColorChip.Clear();
//
// // var tmpParser = new PNGReader(imageBytes);
// var pngReader = new PNGReader(imageBytes, targetGame.ColorChip.maskColor);
//
// // Resize the tilemap
// targetGame.TilemapChip.Resize(pngReader.width / 8, pngReader.height / 8);
//
// var loadService = runner.loadService;
//
// loadService.Reset();
//
// loadService.targetEngine = targetGame;
//
// loadService.AddParser(new ColorParser(pngReader, targetGame.ColorChip));
// loadService.AddParser(new TilemapParser(pngReader, targetGame));
//
// loadService.LoadAll();
//
// }
// catch
// {
// // Console.WriteLine("Game Editor Load Error:\n"+e.Message);
//
// return false;
// }
//
//
// Reset();
//
// return true;
// }

/// <summary>
/// Load a font from a path in the Workspace
Expand Down Expand Up @@ -1346,20 +1270,6 @@ public int ChannelType(int id, int? typeID = null)

#region Colors

/// <summary>
/// Get or change the TotalDisks number of colors per page
/// </summary>
/// <param name="TotalDisks"></param>
/// <returns></returns>
// public int ColorPages(int? TotalDisks = null)
// {
// // TODO this is deprecated and the API needs to be updated
//
// if (TotalDisks.HasValue) activeColorChip.TotalDisks = TotalDisks.Value * 64;
//
// return MathUtil.CeilToInt(activeColorChip.TotalDisks / 64);
// }

/// <summary>
/// Convert sprites in memory to palette colors, clamping the TotalDisks colors in each sprite to 16
/// </summary>
Expand Down Expand Up @@ -1558,17 +1468,6 @@ public void StopSound(int channel = 0)
throw new NotImplementedException();
}

// public void DrawTile(int id, int c, int r, DrawMode drawMode = DrawMode.Tile, int colorOffset = 0)
// {
// gameChip.DrawTile(id, c, r, drawMode, colorOffset);
// }
//
// public void DrawTiles(int[] ids, int c, int r, int width, DrawMode drawMode = DrawMode.Tile,
// int colorOffset = 0)
// {
// gameChip.DrawTiles(ids, c, r, width, drawMode, colorOffset);
// }

/// <summary>
/// Get or change the TotalDisks number of sounds
/// </summary>
Expand Down

0 comments on commit b794b2a

Please sign in to comment.