Skip to content

Commit

Permalink
Changed the way colors decompress
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaimi committed Jun 12, 2024
1 parent 33073e7 commit f134cd1
Showing 1 changed file with 70 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ public string ToCompressedString(string seperator = "\n")
theString.Append(';');
}
}
theString.Append(seperator);
theString.Append('<');
}
theString.Append(seperator);
}

if (Dna != null)
Expand Down Expand Up @@ -386,7 +387,7 @@ public static AvatarDefinition FromCompressedStringV2(string compressed,char sep
AvatarDefinition adf = new AvatarDefinition();
splitter[0] = seperator;
string[] SplitLines = compressed.Split(splitter);
List<SharedColorDef> Colors = new List<SharedColorDef>();
// List<SharedColorDef> Colors = new List<SharedColorDef>();

for (int i = 0; i < SplitLines.Length; i++)
{
Expand All @@ -409,57 +410,7 @@ public static AvatarDefinition FromCompressedStringV2(string compressed,char sep
break;
case 'C':
// Unpack Colors
splitter[0] = '>';
string[] SharedColor = s.Substring(2).Trim().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
if (SharedColor.Length > 1)
{
SharedColorDef scd = new SharedColorDef();
List<string> ShaderParms = new List<string>();
splitter[0] = ',';
string[] maincol = SharedColor[0].Split(splitter, StringSplitOptions.RemoveEmptyEntries);
if (maincol.Length > 1)
{
scd.name = maincol[0];
scd.count = Convert.ToInt32(maincol[1]);

splitter[0] = ';';
string[] ColorDefs = SharedColor[1].Split(splitter, StringSplitOptions.RemoveEmptyEntries);
List<ColorDef> theColors = new List<ColorDef>();
if (ColorDefs != null)
{
if (ColorDefs.Length > 0)
{
for (int i1 = 0; i1 < ColorDefs.Length; i1++)
{
if (String.IsNullOrEmpty(ColorDefs[i1]))
continue;
if (ColorDefs[i1][0] == 'P')
{
ShaderParms.Add(Base64Decode(ColorDefs[i1].Substring(2)));
continue;
}
string c = ColorDefs[i1];
splitter[0] = ',';
string[] vals = c.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
if (vals.Length == 2)
{
ColorDef cdef = new ColorDef(Convert.ToInt32(vals[0]), Convert.ToUInt32(vals[1], 16), 0);
theColors.Add(cdef);
}
else if (vals.Length == 3)
{
ColorDef cdef = new ColorDef(Convert.ToInt32(vals[0]), Convert.ToUInt32(vals[1], 16), Convert.ToUInt32(vals[2], 16));
theColors.Add(cdef);
}
}
}

}
scd.channels = theColors.ToArray();
scd.shaderParms = ShaderParms.ToArray();
Colors.Add(scd);
}
}
adf.Colors = UnpackColors(s);
break;
case 'D':
// Unpack DNA
Expand All @@ -485,10 +436,75 @@ public static AvatarDefinition FromCompressedStringV2(string compressed,char sep
}
}

adf.Colors = Colors.ToArray();
//adf.Colors = Colors.ToArray();
return adf;
}

private static SharedColorDef[] UnpackColors(string s)
{
List<SharedColorDef> colors = new List<SharedColorDef>();

string[] encodedColors = s.Split(new char[] { '<' }, StringSplitOptions.RemoveEmptyEntries);


return colors.ToArray();
}

private static void UnpackAColor(char[] splitter, List<SharedColorDef> Colors, string s)
{
splitter[0] = '>';
string[] SharedColor = s.Substring(2).Trim().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
if (SharedColor.Length > 1)
{
SharedColorDef scd = new SharedColorDef();
List<string> ShaderParms = new List<string>();
splitter[0] = ',';
string[] maincol = SharedColor[0].Split(splitter, StringSplitOptions.RemoveEmptyEntries);
if (maincol.Length > 1)
{
scd.name = maincol[0];
scd.count = Convert.ToInt32(maincol[1]);

splitter[0] = ';';
string[] ColorDefs = SharedColor[1].Split(splitter, StringSplitOptions.RemoveEmptyEntries);
List<ColorDef> theColors = new List<ColorDef>();
if (ColorDefs != null)
{
if (ColorDefs.Length > 0)
{
for (int i1 = 0; i1 < ColorDefs.Length; i1++)
{
if (String.IsNullOrEmpty(ColorDefs[i1]))
continue;
if (ColorDefs[i1][0] == 'P')
{
ShaderParms.Add(Base64Decode(ColorDefs[i1].Substring(2)));
continue;
}
string c = ColorDefs[i1];
splitter[0] = ',';
string[] vals = c.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
if (vals.Length == 2)
{
ColorDef cdef = new ColorDef(Convert.ToInt32(vals[0]), Convert.ToUInt32(vals[1], 16), 0);
theColors.Add(cdef);
}
else if (vals.Length == 3)
{
ColorDef cdef = new ColorDef(Convert.ToInt32(vals[0]), Convert.ToUInt32(vals[1], 16), Convert.ToUInt32(vals[2], 16));
theColors.Add(cdef);
}
}
}

}
scd.channels = theColors.ToArray();
scd.shaderParms = ShaderParms.ToArray();
Colors.Add(scd);
}
}
}

// Ascii version of the string. Not as good as binary formatter,
// but 1/2 the size of a string.
public byte[] ToASCIIString()
Expand Down

0 comments on commit f134cd1

Please sign in to comment.