Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Scaffolding/Content/ModEventTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Godot;
using MegaCrit.Sts2.Core.Events;
using MegaCrit.Sts2.Core.Localization;
using MegaCrit.Sts2.Core.Models;
using STS2RitsuLib.Scaffolding.Content.Patches;

Expand Down Expand Up @@ -94,6 +95,11 @@ protected string ModOptionKey(string pageName, string optionName)
return ModOptionKey("INITIAL", optionName);
}

/// <summary>
/// Gets the localized description for a page.
/// </summary>
protected LocString PageDescription(string pageName) => L10NLookup($"{Id.Entry}.pages.{pageName}.description");

/// <summary>
/// Creates a relic-grant option for a mutable relic resolved from <typeparamref name="T" />.
/// </summary>
Expand Down
27 changes: 24 additions & 3 deletions Utils/MaterialUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,35 @@ public static class MaterialUtils
private static NoiseTexture2D VanillaDoomBarNoiseTexture =>
_vanillaDoomBarNoiseTexture ??= CreateVanillaDoomBarNoiseTexture();

/// <summary>
/// Builds a <c>ShaderMaterial</c> using the game's HSV shader with the given RGB parameters.
/// </summary>
public static ShaderMaterial CreateRgbShaderMaterial(float r, float g, float b)
{
var max = Math.Max(r, Math.Max(g, b));
var min = Math.Min(r, Math.Min(g, b));
var delta = max - min;

float h = 0;
if (delta != 0)
{
if (max == r) h = (g - b) / delta + (g < b ? 6 : 0);
else if (max == g) h = (b - r) / delta + 2;
else h = (r - g) / delta + 4;
h /= 6;
}

var s = (max == 0) ? 0 : (delta / max);
var v = max;
return CreateHsvShaderMaterial(h, s, v);
}

/// <summary>
/// Builds a <c>ShaderMaterial</c> using the game's HSV shader with the given parameters.
/// </summary>
public static ShaderMaterial CreateHsvShaderMaterial(float h, float s, float v)
{
var shader = GameHsvShader;
if (shader == null)
throw new InvalidOperationException($"Failed to load HSV shader ({HsvShaderPath}).");
var shader = GameHsvShader ?? throw new InvalidOperationException($"Failed to load HSV shader ({HsvShaderPath}).");

var material = new ShaderMaterial
{
Expand Down