Skip to content

Commit

Permalink
[demon] begin work on CC Standard API
Browse files Browse the repository at this point in the history
  • Loading branch information
GlitchyPSIX committed Dec 20, 2022
1 parent 1ca7872 commit 28b0b09
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 7 deletions.
4 changes: 2 additions & 2 deletions M64MM.Utils/Appearance/ColorPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void CommitColorsToRam(long baseOffset) {
byte[] colors_L = {LightColor.R, LightColor.G, LightColor.B, 0x0};
byte[] colors_D = {DarkColor.R, DarkColor.G, DarkColor.B, 0x0};

if (colors_L.Aggregate((x, y) => (byte)(x + y)) == 0) colors_L[3] = 0xFF;
if (colors_D.Aggregate((x, y) => (byte)(x + y)) == 0) colors_D[3] = 0xFF;
if (colors_L.Sum(x => (int)x) == 0) colors_L[3] = 0xFF;
if (colors_D.Sum(x => (int)x) == 0) colors_D[3] = 0xFF;


WriteBytes(baseOffset + Offset86, SwapEndian(colors_L, 4));
Expand Down
46 changes: 46 additions & 0 deletions M64MM.Utils/Appearance/ColorStandardNaming.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace M64MM.Utils {
public enum CCStandardPart {
PANTS,
HAT,
GLOVES,
SHOES,
SKIN,
HAIR,
SHIRT,
SHIRT_SHOULDER,
SHIRT_ARM,
OVERALLS_TOP,
OVERALLS_BOTTOM,
LEGS_TOP,
LEGS_BOTTOM,
CUSTOM1,
CUSTOM2,
CUSTOM3,
CUSTOM4,
CUSTOM5,
CUSTOM6,
CUSTOM7,
CUSTOM8,
LEGACY_CHARA_TINT, // X3S and others
LEVEL_TINT1,
LEVEL_TINT2, // Anything beyond is futureproofing
LEVEL_TINT3,
LEVEL_TINT4
}

public static class CCStandardHelpers {
public static readonly CCStandardPart[] SparkStandard = new CCStandardPart[] {
CCStandardPart.SHIRT, CCStandardPart.SHIRT_ARM, CCStandardPart.SHIRT_SHOULDER,
CCStandardPart.OVERALLS_BOTTOM, CCStandardPart.LEGS_TOP, CCStandardPart.LEGS_BOTTOM,
CCStandardPart.CUSTOM1, CCStandardPart.CUSTOM2, CCStandardPart.CUSTOM3, CCStandardPart.CUSTOM4,
CCStandardPart.CUSTOM5, CCStandardPart.CUSTOM6, CCStandardPart.CUSTOM7, CCStandardPart.CUSTOM8
};

public static readonly CCStandardPart[] ColorcodeableStandard = new CCStandardPart[] {
CCStandardPart.SHIRT, CCStandardPart.SHIRT_ARM, CCStandardPart.SHIRT_SHOULDER,
CCStandardPart.OVERALLS_BOTTOM, CCStandardPart.LEGS_TOP, CCStandardPart.LEGS_BOTTOM,
CCStandardPart.CUSTOM1, CCStandardPart.CUSTOM2, CCStandardPart.CUSTOM3, CCStandardPart.CUSTOM4,
CCStandardPart.CUSTOM5, CCStandardPart.CUSTOM6, CCStandardPart.CUSTOM7, CCStandardPart.CUSTOM8
};
}
}
67 changes: 67 additions & 0 deletions M64MM.Utils/Appearance/Lightset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace M64MM.Utils {
public class Lightset {
private Dictionary<string, ColorPart> _parts;
private Dictionary<CCStandardPart, string> _partMapping;

public bool SparkCompatible {
get
{
return _partMapping.Keys.Any(x => CCStandardHelpers.SparkStandard.Contains(x));
}
}

public bool NormalColorcodeCompatible
{
get
{
return _partMapping.Keys.Any(x => CCStandardHelpers.ColorcodeableStandard.Contains(x));
}
}

/// <summary>
/// Sets a ColorPart to a given ID. If the ID exists, it's overwritten. If the ColorPart is already assigned, the previous entry is erased.
/// </summary>
/// <param name="id">An ID to get the part by</param>
/// <param name="part">The CC part to set</param>
public void SetPart(string id, ColorPart part) {
if (_parts.ContainsKey(id)) {
_parts[id] = part;
}
else {
if (_parts.Values.Contains(part)) {
_parts.Remove(_parts.FirstOrDefault(x => x.Value == part).Key);
}
_parts.Add(id, part);
}
}

public void SetPartMapping(CCStandardPart source, string id) {
if (!_parts.ContainsKey(id)) {
throw new ArgumentException($"This Lightset has no part with ID \"{id}\".");
}

if (_partMapping.ContainsKey(source)) {
_partMapping[source] = id;
}
else {
_partMapping.Add(source, id);
}
}

public ColorPart GetPartById(string id)
{
if (!_parts.ContainsKey(id)) return null;

return _parts[id];
}

public ColorPart GetPart(CCStandardPart stdPart) {
return GetPartById(_partMapping[stdPart]);
}

}
}
2 changes: 1 addition & 1 deletion M64MM.Utils/Appearance/Looks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public enum ModelHeaderType {
}
};

public enum ShadowParts {
public enum ShadowAxis {
X,
Y,
Z
Expand Down
1 change: 1 addition & 0 deletions M64MM.Utils/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static class Core
public static SettingsGroup coreSettingsGroup;
static bool _cameraFrozen = false;
static bool _cameraSoftFrozen = false;
public static Lightset CurrentLightset { get; set; }

public static bool TurboUpdateEnabled
{
Expand Down
2 changes: 2 additions & 0 deletions M64MM.Utils/M64MM.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<Compile Include="Appearance\ColorCodeGS.cs" />
<Compile Include="Appearance\ColorSpace.cs" />
<Compile Include="Appearance\ColorPart.cs" />
<Compile Include="Appearance\ColorStandardNaming.cs" />
<Compile Include="Appearance\Lightset.cs" />
<Compile Include="EmuFoundEventArgs.cs" />
<Compile Include="Extensions\MathExtensions.cs" />
<Compile Include="Updater\GitHubRelease.cs" />
Expand Down
8 changes: 4 additions & 4 deletions M64MM2/AppearanceForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ public void ExecuteRandomCC() {

void UpdateTrackbar(object sender, EventArgs e) {
TrackBar changedBar = ((TrackBar)sender);
ShadowParts part = ShadowParts.X;
ShadowAxis part = ShadowAxis.X;
switch (changedBar.Name) {
case "tbLeftRight":
part = ShadowParts.X;
part = ShadowAxis.X;
break;
case "tbBottomTop":
part = ShadowParts.Y;
part = ShadowAxis.Y;
break;
case "tbBackFront":
part = ShadowParts.Z;
part = ShadowAxis.Z;
break;
}

Expand Down

0 comments on commit 28b0b09

Please sign in to comment.