RacesOfValheim/JotunnModStub/EyePositionConfig.cs
kanym 8b2b5180ed feat(eyes): per-race eye position sliders in Configuration Manager
One 'Eyes Position - <race>' section each for the Alfar, Aswid, Dvergar and
Sverm, with a female and a male set: forward, height, separation and size,
plus rotation X/Y/Z for the Alfar and Aswid. All are deltas on the computed
placement (0 and size 1 change nothing), read live, and left local by
ConfigSync because they only change how this client draws faces.
2026-10-27 15:21:19 +01:00

98 lines
5 KiB
C#

using System.Collections.Generic;
using BepInEx.Configuration;
namespace RacesOfValheim
{
/// <summary>
/// Hand placement for every race that hangs eyes on the face: one "Eyes Position - race"
/// section each, with a female and a male set, because the two bodies put their painted eyes
/// in different places (PlayerFace). Every value is a delta on the placement the race's own
/// code computes, so all zeros (and size 1) is the shipped look.
///
/// Local, never synced (ConfigSync): it only changes how this client draws faces.
/// </summary>
public static class EyePositionConfig
{
public const string SectionPrefix = "Eyes Position - ";
/// <summary>One body's sliders for one race.</summary>
public sealed class Tuning
{
public ConfigEntry<float> Forward;
public ConfigEntry<float> Height;
public ConfigEntry<float> Separation;
public ConfigEntry<float> Size;
// Only bound for races whose eyes are not spheres; null elsewhere.
public ConfigEntry<float> RotationX;
public ConfigEntry<float> RotationY;
public ConfigEntry<float> RotationZ;
public float RotX => RotationX != null ? RotationX.Value : 0f;
public float RotY => RotationY != null ? RotationY.Value : 0f;
public float RotZ => RotationZ != null ? RotationZ.Value : 0f;
}
// [race] -> { male, female }
private static readonly Dictionary<string, Tuning[]> tunings = new Dictionary<string, Tuning[]>();
public static void Bind(ConfigFile config)
{
BindRace(config, AlfarConfig.RaceId, true);
BindRace(config, "Aswid", true);
BindRace(config, DvergarConfig.RaceId, false);
BindRace(config, SvermConfig.RaceId, false);
}
/// <summary>The sliders for the body this player is wearing right now.</summary>
public static Tuning For(string race, Player player)
{
if (!tunings.TryGetValue(race, out Tuning[] pair)) return null;
return pair[PlayerFace.IsFemale(player) ? 1 : 0];
}
private static void BindRace(ConfigFile config, string race, bool rotation)
{
string section = SectionPrefix + race;
tunings[race] = new[]
{
BindBody(config, section, "Male", rotation, 100),
BindBody(config, section, "Female", rotation, 200),
};
}
private static Tuning BindBody(ConfigFile config, string section, string body, bool rotation, int order)
{
// Female first in the list: Order sorts high to low.
Tuning t = new Tuning();
t.Forward = config.Bind(section, body + " Forward", 0f,
new ConfigDescription($"{body} characters: moves both eyes out of (+) or into (-) the face, in metres.",
new AcceptableValueRange<float>(-0.05f, 0.05f), new ConfigurationManagerAttributes { Order = order + 9 }));
t.Height = config.Bind(section, body + " Height", 0f,
new ConfigDescription($"{body} characters: moves both eyes up (+) or down (-), in metres.",
new AcceptableValueRange<float>(-0.05f, 0.05f), new ConfigurationManagerAttributes { Order = order + 8 }));
t.Separation = config.Bind(section, body + " Separation", 0f,
new ConfigDescription($"{body} characters: pushes the eyes apart (+) or together (-), in metres. Each eye moves by this much.",
new AcceptableValueRange<float>(-0.03f, 0.03f), new ConfigurationManagerAttributes { Order = order + 7 }));
t.Size = config.Bind(section, body + " Size", 1f,
new ConfigDescription($"{body} characters: scales both eyes. 1 is the default size.",
new AcceptableValueRange<float>(0.2f, 3f), new ConfigurationManagerAttributes { Order = order + 6 }));
if (rotation)
{
t.RotationX = config.Bind(section, body + " Rotation X", 0f,
new ConfigDescription($"{body} characters: tilts both eyes up or down, in degrees.",
new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 5 }));
t.RotationY = config.Bind(section, body + " Rotation Y", 0f,
new ConfigDescription($"{body} characters: turns the eyes toward the temples (+) or the nose (-), in degrees. Mirrored between the two eyes.",
new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 4 }));
t.RotationZ = config.Bind(section, body + " Rotation Z", 0f,
new ConfigDescription($"{body} characters: raises (+) or lowers (-) the outer corners, in degrees. Mirrored between the two eyes.",
new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 3 }));
}
return t;
}
}
}