Automatic holiday sprites (#22929)
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Holiday;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -12,6 +13,7 @@ namespace Content.Server.Holiday
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private readonly List<HolidayPrototype> _currentHolidays = new();
|
||||
@@ -24,6 +26,7 @@ namespace Content.Server.Holiday
|
||||
_configManager.OnValueChanged(CCVars.HolidaysEnabled, OnHolidaysEnableChange, true);
|
||||
|
||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRunLevelChanged);
|
||||
SubscribeLocalEvent<HolidayVisualsComponent, ComponentInit>(OnVisualsInit);
|
||||
}
|
||||
|
||||
public void RefreshCurrentHolidays()
|
||||
@@ -102,6 +105,17 @@ namespace Content.Server.Holiday
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnVisualsInit(Entity<HolidayVisualsComponent> ent, ref ComponentInit args)
|
||||
{
|
||||
foreach (var (key, holidays) in ent.Comp.Holidays)
|
||||
{
|
||||
if (!holidays.Any(h => IsCurrentlyHoliday(h)))
|
||||
continue;
|
||||
_appearance.SetData(ent, HolidayVisuals.Holiday, key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
17
Content.Server/Holiday/HolidayVisualsComponent.cs
Normal file
17
Content.Server/Holiday/HolidayVisualsComponent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Holiday;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for an entity that enables unique visuals on specified holidays.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class HolidayVisualsComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// A dictionary relating a generic key to a list of holidays.
|
||||
/// If any of the holidays are being celebrated, that key will be set for holiday visuals.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Dictionary<string, List<ProtoId<HolidayPrototype>>> Holidays = new();
|
||||
}
|
||||
Reference in New Issue
Block a user