2025-01-05 19:08:35 +03:00
|
|
|
using Content.Shared._CP14.DayCycle.Prototypes;
|
2024-06-05 00:54:49 +10:00
|
|
|
using Robust.Shared.GameStates;
|
2024-08-10 08:12:13 +10:00
|
|
|
using Robust.Shared.Prototypes;
|
2024-06-05 00:54:49 +10:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
2024-08-10 08:12:13 +10:00
|
|
|
namespace Content.Shared._CP14.DayCycle.Components;
|
2024-06-05 00:54:49 +10:00
|
|
|
|
|
|
|
|
/// <summary>
|
2024-08-10 08:12:13 +10:00
|
|
|
/// Stores all the necessary data for the day and night cycle system to work.
|
2024-06-05 00:54:49 +10:00
|
|
|
/// </summary>
|
2025-01-05 19:08:35 +03:00
|
|
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause, Access(typeof(CP14SharedDayCycleSystem))]
|
2024-06-05 00:54:49 +10:00
|
|
|
public sealed partial class CP14DayCycleComponent : Component
|
|
|
|
|
{
|
|
|
|
|
[ViewVariables]
|
2025-01-05 19:08:35 +03:00
|
|
|
public int NextTimeEntryIndex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (IndexedCycle is null)
|
|
|
|
|
return 0;
|
|
|
|
|
return CurrentTimeEntryIndex + 1 >= IndexedCycle.TimeEntries.Count ? 0 : CurrentTimeEntryIndex + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-05 00:54:49 +10:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2025-01-05 19:08:35 +03:00
|
|
|
public DayCycleEntry? CurrentTimeEntry => IndexedCycle?.TimeEntries[CurrentTimeEntryIndex];
|
2024-06-05 00:54:49 +10:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2025-01-05 19:08:35 +03:00
|
|
|
public DayCycleEntry? NextCurrentTimeEntry => IndexedCycle?.TimeEntries[NextTimeEntryIndex];
|
2024-06-05 00:54:49 +10:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2025-01-05 19:08:35 +03:00
|
|
|
public Color? StartColor => CurrentTimeEntry?.Color;
|
2024-06-05 00:54:49 +10:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2025-01-05 19:08:35 +03:00
|
|
|
public Color? EndColor => NextCurrentTimeEntry?.Color;
|
2024-06-05 00:54:49 +10:00
|
|
|
|
2024-08-10 08:12:13 +10:00
|
|
|
[ViewVariables]
|
2025-01-05 19:08:35 +03:00
|
|
|
public ProtoId<CP14DayCyclePeriodPrototype>? CurrentPeriod => CurrentTimeEntry?.Period;
|
|
|
|
|
|
|
|
|
|
public CP14DayCyclePrototype? IndexedCycle;
|
2024-08-10 08:12:13 +10:00
|
|
|
|
2025-01-05 19:08:35 +03:00
|
|
|
[DataField, AutoNetworkedField]
|
|
|
|
|
public ProtoId<CP14DayCyclePrototype> CycleProto = "Default";
|
2024-06-05 00:54:49 +10:00
|
|
|
|
|
|
|
|
[DataField, ViewVariables, AutoNetworkedField]
|
|
|
|
|
public int CurrentTimeEntryIndex;
|
|
|
|
|
|
2025-01-05 19:08:35 +03:00
|
|
|
[DataField, ViewVariables, AutoNetworkedField, AutoPausedField]
|
2024-06-05 00:54:49 +10:00
|
|
|
public TimeSpan EntryStartTime;
|
|
|
|
|
|
2025-01-05 19:08:35 +03:00
|
|
|
[DataField, ViewVariables, AutoNetworkedField, AutoPausedField]
|
2024-06-05 00:54:49 +10:00
|
|
|
public TimeSpan EntryEndTime;
|
2024-09-01 17:22:16 +05:00
|
|
|
|
|
|
|
|
[DataField]
|
|
|
|
|
public bool StartWithRandomEntry = true;
|
2024-06-05 00:54:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DataDefinition, NetSerializable, Serializable]
|
|
|
|
|
public readonly partial record struct DayCycleEntry()
|
|
|
|
|
{
|
2024-10-31 19:13:44 +03:00
|
|
|
public DayCycleEntry(Color _color, TimeSpan _duration, string _period) : this()
|
|
|
|
|
{
|
|
|
|
|
Color = _color;
|
|
|
|
|
Duration = _duration;
|
|
|
|
|
Period = _period;
|
|
|
|
|
}
|
2024-06-05 00:54:49 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// The color of the world's lights at the beginning of this time of day
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField]
|
|
|
|
|
public Color Color { get; init; } = Color.White;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Duration of color shift to the next time of day
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField]
|
|
|
|
|
public TimeSpan Duration { get; init; } = TimeSpan.FromSeconds(60);
|
|
|
|
|
|
|
|
|
|
[DataField]
|
2024-08-10 08:12:13 +10:00
|
|
|
public ProtoId<CP14DayCyclePeriodPrototype> Period { get; init; } = "Day";
|
2024-06-05 00:54:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-08-10 08:12:13 +10:00
|
|
|
/// Event raised on map entity, wen day cycle changed.
|
2024-06-05 00:54:49 +10:00
|
|
|
/// </summary>
|
|
|
|
|
[ByRefEvent]
|
2025-01-05 19:08:35 +03:00
|
|
|
public readonly record struct DayCycleChangedEvent(DayCycleEntry? Entry);
|