Skip to content

Commit

Permalink
Rename console_civ_scientist.mdl animations
Browse files Browse the repository at this point in the history
malortie/custom-hl-viewmodels#21
  • Loading branch information
SamVanheer committed May 26, 2022
1 parent dc8a54f commit 59154e7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static MapUpgradeBuilder AddOpposingForceUpgrades(this MapUpgradeBuilder
public static MapUpgradeBuilder AddBlueShiftUpgrades(this MapUpgradeBuilder builder)
{
builder.AddAction(new BaYard4aSlavesUpgrade());
builder.AddAction(new RenameConsoleCivAnimationsUpgrade());
return builder;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using HalfLife.UnifiedSdk.Utilities.Entities;
using HalfLife.UnifiedSdk.Utilities.Tools.UpgradeTool;
using System.Collections.Immutable;

namespace HalfLife.UnifiedSdk.MapUpgrader.Upgrades
{
/// <summary>
/// Renames certain animations referenced by <c>scripted_sequence</c>s targeting entities using <c>models/console_civ_scientist.mdl</c>.
/// </summary>
internal sealed class RenameConsoleCivAnimationsUpgrade : IMapUpgradeAction
{
private const string ScriptedSequenceTargetKey = "m_iszEntity";
private const string ScriptedSequenceIdleKey = "m_iszIdle";
private const string ScriptedSequencePlayKey = "m_iszPlay";

private static readonly ImmutableList<string> KeysToCheck = ImmutableList.Create(ScriptedSequenceIdleKey, ScriptedSequencePlayKey);

private static readonly ImmutableDictionary<string, string> AnimationRemap = new Dictionary<string, string>
{
{ "idle1", "console_idle1" },
{ "work", "console_work" },
{ "shocked", "console_shocked" },
{ "sneeze", "console_sneeze" }
}.ToImmutableDictionary();

public void Apply(MapUpgradeContext context)
{
foreach (var script in context.Map.Entities
.OfClass("scripted_sequence")
.Where(e => e.ContainsKey(ScriptedSequenceTargetKey)))
{
var target = context.Map.Entities
.WhereTargetName(script.GetString(ScriptedSequenceTargetKey))
.FirstOrDefault();

if (target is null)
{
continue;
}

if (target.GetModel() != "models/console_civ_scientist.mdl")
{
continue;
}

foreach (var key in KeysToCheck)
{
if (script.GetStringOrNull(key) is { } animation
&& AnimationRemap.TryGetValue(animation, out var replacement))
{
script.SetString(key, replacement);
}
}
}
}
}
}

0 comments on commit 59154e7

Please sign in to comment.