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

Commit

Permalink
Fixes for #172.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed May 5, 2020
1 parent c9b097a commit 771faaf
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 12 deletions.
15 changes: 14 additions & 1 deletion Disks/PixelVisionOS/System/Tools/SpriteTool/saves.json
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
{"GameChip":{"savedData":{"editing": "undefined","sessionID": "202005041118313943","rootDirectory": "/Workspace/NewProjectB/","selectedSprite": "0","SpriteSize": "undefined","spriteSize": "1"}}}
{

"GameChip":
{
"savedData":{
"editing": "undefined",
"sessionID": "202005042130457172",
"rootDirectory": "/Workspace/NewProject/",
"selectedSprite": "0",
"SpriteSize": "undefined",
"spriteSize": "1"
}
}
}
6 changes: 3 additions & 3 deletions Disks/PixelVisionOS/System/Tools/TextEditorTool/saves.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"GameChip":
{
"savedData":{
"targetFile": "/Disks/PixelVisionOS/info.json",
"sessionID": "202005020908199470",
"targetFile": "/Workspace/SpaceRanger/info.json",
"sessionID": "202005042115013442",
"rootDirectory": "/Workspace/HelloWorld/",
"cursor": "1,1",
"cursor": "25,7",
"selectedSprite": "0",
"scroll": "1,1"
}
Expand Down
6 changes: 3 additions & 3 deletions Disks/PixelVisionOS/System/Tools/WorkspaceTool/saves.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"GameChip":
{
"savedData":{
"sessionID": "202005041152250834",
"lastPath": "/Workspace/NewProject/",
"selection": "0",
"scrollPos": "0",
"selection": "13",
"lastPath": "/Workspace/NewProjectB/"
"sessionID": "202005042130457172"
}
}
}
1 change: 1 addition & 0 deletions SDK/Engine/Chips/Graphics/ColorChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void Clear(string color = null)
if (color == null)
color = maskColor;

Console.WriteLine("Clear " + color);
var t = _colors.Length;
for (var i = 0; i < t; i++) UpdateColorAt(i, color);
}
Expand Down
107 changes: 102 additions & 5 deletions SDK/Runner/Parsers/SpriteImageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using PixelVision8.Engine.Chips;
Expand Down Expand Up @@ -86,19 +87,115 @@ public virtual void PrepareSprites()

protected virtual void CreateImage()
{
colorData = chips.GetChip(ColorMapParser.chipName, false) is ColorChip colorMapChip
? colorMapChip.colors
: chips.ColorChip.colors;

var colorChip = chips.GetChip(ColorMapParser.chipName, false) is ColorChip colorMapChip
? colorMapChip
: chips.ColorChip;

colorData = colorChip.colors;

var colorRefs = colorData.Select(c => ColorUtils.RgbToHex(c.R, c.G, c.B)).ToArray();

// Remove the colors that are not supported
Array.Resize(ref colorRefs, chips.ColorChip.totalUsedColors);

var imageColors = Parser.colorPalette.Select(c => ColorUtils.RgbToHex(c.R, c.G, c.B)).ToArray();

var colorMap = new string[colorRefs.Length];

var orphanColors = new List<string>();

var totalImageColors = imageColors.Length;
var totalColorRefs = colorRefs.Length;

for (int i = 0; i < totalImageColors; i++)
{

// var color = imageColors[i];
var color = imageColors[i];

if (color == colorChip.maskColor) continue;

var id = Array.IndexOf(colorRefs, color);

if (id > -1)
{
colorMap[id] = color;
}
else
{
orphanColors.Add(color);
}



//
// if (index > -1 && colorMap[index] == null)
// {
// colorMap[index] = color;
// }
// else
// {
// orphanColors.Add(color);
// }

}

var indexes = new List<int>();

// find open slots
for (int i = 0; i < colorMap.Length; i++)
{
if (colorMap[i] == null)
{
indexes.Add(i);
}
}

var totalOrphanColors = orphanColors.Count;

for (int i = 0; i < indexes.Count; i++)
{
if (i < totalOrphanColors)
{
colorMap[indexes[i]] = orphanColors[i];
}
}

// clean up the color map
for (int i = 0; i < colorMap.Length; i++)
{
if (colorMap[i] == null)
{
colorMap[i] = colorRefs[i];
}
}

// var indexes = new List<int>();
//
// // find open slots
// for (int i = 0; i < colorMap.Length; i++)
// {
// if (colorMap[i] == null)
// {
// indexes.Add(i);
// }
// }
//
// var totalOrphanColors = orphanColors.Count;
//
// for (int i = 0; i < index; i++)
// {
// if (i < totalOrphanColors)
// {
// colorMap[indexes[i]] = orphanColors[i];
// }
// }

// Convert all of the pixels into color ids
var pixelIDs = Parser.colorPixels.Select(c => Array.IndexOf(colorRefs, ColorUtils.RgbToHex(c.R, c.G, c.B))).ToArray();
var pixelIDs = Parser.colorPixels.Select(c => Array.IndexOf(colorMap, ColorUtils.RgbToHex(c.R, c.G, c.B))).ToArray();

image = new Image(Parser.width, Parser.height, colorRefs, pixelIDs, new Point(spriteWidth, spriteHeight));
image = new Image(Parser.width, Parser.height, colorMap, pixelIDs, new Point(spriteWidth, spriteHeight));

StepCompleted();
}
Expand Down

0 comments on commit 771faaf

Please sign in to comment.