dayCycle prototipization (#694)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Content.Shared._CP14.DayCycle;
|
||||
using Content.Shared._CP14.DayCycle.Components;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -13,6 +14,7 @@ public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem
|
||||
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -23,10 +25,12 @@ public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem
|
||||
|
||||
private void OnMapInitDayCycle(Entity<CP14DayCycleComponent> dayCycle, ref MapInitEvent args)
|
||||
{
|
||||
dayCycle.Comp.IndexedCycle = _proto.Index(dayCycle.Comp.CycleProto);
|
||||
|
||||
Init(dayCycle);
|
||||
|
||||
if (dayCycle.Comp.StartWithRandomEntry && dayCycle.Comp.TimeEntries.Count > 1)
|
||||
SetTimeEntry(dayCycle, _random.Next(dayCycle.Comp.TimeEntries.Count));
|
||||
if (dayCycle.Comp.StartWithRandomEntry && dayCycle.Comp.IndexedCycle.TimeEntries.Count > 1)
|
||||
SetTimeEntry(dayCycle, _random.Next(dayCycle.Comp.IndexedCycle.TimeEntries.Count));
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -38,7 +42,10 @@ public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem
|
||||
{
|
||||
var entity = new Entity<CP14DayCycleComponent, MapLightComponent>(uid, dayCycle, mapLight);
|
||||
|
||||
if (dayCycle.TimeEntries.Count < MinTimeEntryCount)
|
||||
if (dayCycle.IndexedCycle is null)
|
||||
continue;
|
||||
|
||||
if (dayCycle.IndexedCycle.TimeEntries.Count < MinTimeEntryCount)
|
||||
continue;
|
||||
|
||||
SetAmbientColor((entity, entity), GetCurrentColor(entity, _timing.CurTime.TotalSeconds));
|
||||
@@ -52,32 +59,41 @@ public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem
|
||||
|
||||
public void Init(Entity<CP14DayCycleComponent> dayCycle)
|
||||
{
|
||||
if (dayCycle.Comp.TimeEntries.Count < MinTimeEntryCount)
|
||||
if (dayCycle.Comp.IndexedCycle is null)
|
||||
return;
|
||||
|
||||
if (dayCycle.Comp.IndexedCycle.TimeEntries.Count < MinTimeEntryCount)
|
||||
{
|
||||
Log.Warning($"Attempting to init a daily cycle with the number of time entries less than {MinTimeEntryCount}");
|
||||
Log.Warning($"Attempting to init a day/night cycle with the number of time entries less than {MinTimeEntryCount}");
|
||||
return;
|
||||
}
|
||||
|
||||
dayCycle.Comp.CurrentTimeEntryIndex = 0;
|
||||
dayCycle.Comp.EntryStartTime = _timing.CurTime;
|
||||
dayCycle.Comp.EntryEndTime = _timing.CurTime + dayCycle.Comp.CurrentTimeEntry.Duration;
|
||||
dayCycle.Comp.EntryEndTime = _timing.CurTime + dayCycle.Comp.CurrentTimeEntry!.Value.Duration;
|
||||
|
||||
Dirty(dayCycle);
|
||||
}
|
||||
|
||||
public void AddTimeEntry(Entity<CP14DayCycleComponent> dayCycle, DayCycleEntry entry)
|
||||
{
|
||||
dayCycle.Comp.TimeEntries.Add(entry);
|
||||
if (dayCycle.Comp.IndexedCycle is null)
|
||||
return;
|
||||
|
||||
dayCycle.Comp.IndexedCycle.TimeEntries.Add(entry);
|
||||
Dirty(dayCycle);
|
||||
}
|
||||
|
||||
public void SetTimeEntry(Entity<CP14DayCycleComponent> dayCycle, int nextEntry)
|
||||
{
|
||||
nextEntry = Math.Clamp(nextEntry, 0, dayCycle.Comp.TimeEntries.Count - 1);
|
||||
if (dayCycle.Comp.IndexedCycle is null)
|
||||
return;
|
||||
|
||||
nextEntry = Math.Clamp(nextEntry, 0, dayCycle.Comp.IndexedCycle.TimeEntries.Count - 1);
|
||||
|
||||
dayCycle.Comp.CurrentTimeEntryIndex = nextEntry;
|
||||
dayCycle.Comp.EntryStartTime = dayCycle.Comp.EntryEndTime;
|
||||
dayCycle.Comp.EntryEndTime += dayCycle.Comp.CurrentTimeEntry.Duration;
|
||||
dayCycle.Comp.EntryEndTime += dayCycle.Comp.CurrentTimeEntry!.Value.Duration;
|
||||
|
||||
var ev = new DayCycleChangedEvent(dayCycle.Comp.CurrentTimeEntry);
|
||||
RaiseLocalEvent(dayCycle, ref ev, true);
|
||||
@@ -97,7 +113,7 @@ public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem
|
||||
private Color GetCurrentColor(Entity<CP14DayCycleComponent> dayCycle, double totalSeconds)
|
||||
{
|
||||
var timeScale = GetTimeScale(dayCycle, totalSeconds);
|
||||
return Color.InterpolateBetween(dayCycle.Comp.StartColor, dayCycle.Comp.EndColor, timeScale);
|
||||
return Color.InterpolateBetween(dayCycle.Comp.StartColor ?? Color.Black, dayCycle.Comp.EndColor ?? Color.Black, timeScale);
|
||||
}
|
||||
|
||||
private float GetTimeScale(Entity<CP14DayCycleComponent> dayCycle, double totalSeconds)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared._CP14.DayCycle;
|
||||
using Content.Shared._CP14.DayCycle.Components;
|
||||
using Content.Shared._CP14.DayCycle.Prototypes;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -41,7 +41,10 @@ public sealed class CP14InitDayCycleCommand : LocalizedCommands
|
||||
return;
|
||||
}
|
||||
|
||||
if (dayCycle.TimeEntries.Count < CP14DayCycleSystem.MinTimeEntryCount)
|
||||
if (dayCycle.IndexedCycle is null)
|
||||
return;
|
||||
|
||||
if (dayCycle.IndexedCycle.TimeEntries.Count < CP14DayCycleSystem.MinTimeEntryCount)
|
||||
{
|
||||
shell.WriteError($"Attempting to init a daily cycle with the number of time entries less than {CP14DayCycleSystem.MinTimeEntryCount}");
|
||||
return;
|
||||
|
||||
@@ -64,10 +64,13 @@ public sealed class CP14SetTimeEntryCommand : LocalizedCommands
|
||||
if (!entityManager.TryGetComponent<CP14DayCycleComponent>(entityManager.GetEntity(mapUid), out var component))
|
||||
return CompletionResult.Empty;
|
||||
|
||||
if (component.TimeEntries.Count - 1 < 0)
|
||||
if (component.IndexedCycle is null)
|
||||
return CompletionResult.Empty;
|
||||
|
||||
var indices = new string[component.TimeEntries.Count - 1];
|
||||
if (component.IndexedCycle.TimeEntries.Count - 1 < 0)
|
||||
return CompletionResult.Empty;
|
||||
|
||||
var indices = new string[component.IndexedCycle.TimeEntries.Count - 1];
|
||||
for (var i = 0; i < indices.Length; i++)
|
||||
{
|
||||
indices[i] = i.ToString();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared._CP14.DayCycle.Components;
|
||||
using Content.Shared._CP14.DayCycle.Prototypes;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared._CP14.DayCycle.Prototypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -7,37 +8,47 @@ namespace Content.Shared._CP14.DayCycle.Components;
|
||||
/// <summary>
|
||||
/// Stores all the necessary data for the day and night cycle system to work.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(CP14SharedDayCycleSystem))]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause, Access(typeof(CP14SharedDayCycleSystem))]
|
||||
public sealed partial class CP14DayCycleComponent : Component
|
||||
{
|
||||
[ViewVariables]
|
||||
public int NextTimeEntryIndex => CurrentTimeEntryIndex + 1 >= TimeEntries.Count ? 0 : CurrentTimeEntryIndex + 1;
|
||||
public int NextTimeEntryIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IndexedCycle is null)
|
||||
return 0;
|
||||
return CurrentTimeEntryIndex + 1 >= IndexedCycle.TimeEntries.Count ? 0 : CurrentTimeEntryIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public DayCycleEntry CurrentTimeEntry => TimeEntries[CurrentTimeEntryIndex];
|
||||
public DayCycleEntry? CurrentTimeEntry => IndexedCycle?.TimeEntries[CurrentTimeEntryIndex];
|
||||
|
||||
[ViewVariables]
|
||||
public DayCycleEntry NextCurrentTimeEntry => TimeEntries[NextTimeEntryIndex];
|
||||
public DayCycleEntry? NextCurrentTimeEntry => IndexedCycle?.TimeEntries[NextTimeEntryIndex];
|
||||
|
||||
[ViewVariables]
|
||||
public Color StartColor => CurrentTimeEntry.Color;
|
||||
public Color? StartColor => CurrentTimeEntry?.Color;
|
||||
|
||||
[ViewVariables]
|
||||
public Color EndColor => NextCurrentTimeEntry.Color;
|
||||
public Color? EndColor => NextCurrentTimeEntry?.Color;
|
||||
|
||||
[ViewVariables]
|
||||
public ProtoId<CP14DayCyclePeriodPrototype> CurrentPeriod => CurrentTimeEntry.Period;
|
||||
public ProtoId<CP14DayCyclePeriodPrototype>? CurrentPeriod => CurrentTimeEntry?.Period;
|
||||
|
||||
[DataField(required: true), ViewVariables, AutoNetworkedField]
|
||||
public List<DayCycleEntry> TimeEntries = new();
|
||||
public CP14DayCyclePrototype? IndexedCycle;
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
public ProtoId<CP14DayCyclePrototype> CycleProto = "Default";
|
||||
|
||||
[DataField, ViewVariables, AutoNetworkedField]
|
||||
public int CurrentTimeEntryIndex;
|
||||
|
||||
[DataField, ViewVariables, AutoNetworkedField]
|
||||
[DataField, ViewVariables, AutoNetworkedField, AutoPausedField]
|
||||
public TimeSpan EntryStartTime;
|
||||
|
||||
[DataField, ViewVariables, AutoNetworkedField]
|
||||
[DataField, ViewVariables, AutoNetworkedField, AutoPausedField]
|
||||
public TimeSpan EntryEndTime;
|
||||
|
||||
[DataField]
|
||||
@@ -73,4 +84,4 @@ public readonly partial record struct DayCycleEntry()
|
||||
/// Event raised on map entity, wen day cycle changed.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct DayCycleChangedEvent(DayCycleEntry Entry);
|
||||
public readonly record struct DayCycleChangedEvent(DayCycleEntry? Entry);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._CP14.DayCycle;
|
||||
namespace Content.Shared._CP14.DayCycle.Prototypes;
|
||||
|
||||
[Prototype("CP14DayCyclePeriod")]
|
||||
public sealed class CP14DayCyclePeriodPrototype : IPrototype
|
||||
@@ -0,0 +1,14 @@
|
||||
using Content.Shared._CP14.DayCycle.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._CP14.DayCycle.Prototypes;
|
||||
|
||||
[Prototype("CP14DayCycle")]
|
||||
public sealed class CP14DayCyclePrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; } = string.Empty;
|
||||
|
||||
[DataField(required: true), ViewVariables]
|
||||
public List<DayCycleEntry> TimeEntries = new();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared._CP14.DayCycle;
|
||||
using Content.Shared._CP14.DayCycle.Components;
|
||||
using Content.Shared._CP14.DayCycle.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._CP14.MagicRitual.Requirements;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared._CP14.DayCycle;
|
||||
using Content.Shared._CP14.DayCycle.Components;
|
||||
using Content.Shared._CP14.DayCycle.Prototypes;
|
||||
using Content.Shared.Random.Rules;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -17,6 +18,9 @@ public sealed partial class CP14TimePeriod : RulesRule
|
||||
var transform = entManager.System<SharedTransformSystem>();
|
||||
|
||||
var map = transform.GetMap(uid);
|
||||
return entManager.TryGetComponent<CP14DayCycleComponent>(map, out var dayCycle) && Periods.Contains(dayCycle.CurrentPeriod);
|
||||
if (!entManager.TryGetComponent<CP14DayCycleComponent>(map, out var dayCycle))
|
||||
return false;
|
||||
|
||||
return dayCycle.CurrentPeriod is not null && Periods.Contains(dayCycle.CurrentPeriod.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,27 +69,6 @@ entities:
|
||||
- 0
|
||||
- 0
|
||||
- type: CP14DayCycle
|
||||
timeEntries:
|
||||
- duration: 80
|
||||
color: '#754A4AFF'
|
||||
- duration: 80
|
||||
color: '#E0BA87FF'
|
||||
- duration: 80
|
||||
color: '#BFEEFFFF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#385163FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#060D12FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- duration: 80
|
||||
color: '#120906FF'
|
||||
- type: CP14WeatherController
|
||||
entries:
|
||||
- visuals: CP14Snow
|
||||
|
||||
@@ -36,27 +36,6 @@ entities:
|
||||
- visuals: CP14Storm
|
||||
- visuals: CP14Mist
|
||||
- type: CP14DayCycle
|
||||
timeEntries:
|
||||
- duration: 80
|
||||
color: '#754A4AFF'
|
||||
- duration: 80
|
||||
color: '#E0BA87FF'
|
||||
- duration: 80
|
||||
color: '#BFEEFFFF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#385163FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#060D12FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- duration: 80
|
||||
color: '#120906FF'
|
||||
- type: Broadphase
|
||||
- type: OccluderTree
|
||||
- type: MapGrid
|
||||
|
||||
@@ -47,27 +47,6 @@ entities:
|
||||
- 0
|
||||
- 0
|
||||
- type: CP14DayCycle
|
||||
timeEntries:
|
||||
- duration: 80
|
||||
color: '#754A4AFF'
|
||||
- duration: 80
|
||||
color: '#E0BA87FF'
|
||||
- duration: 80
|
||||
color: '#BFEEFFFF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#385163FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#060D12FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- duration: 80
|
||||
color: '#120906FF'
|
||||
- type: Gravity
|
||||
gravityShakeSound: !type:SoundPathSpecifier
|
||||
path: /Audio/Effects/alert.ogg
|
||||
|
||||
@@ -53,27 +53,6 @@ entities:
|
||||
- visuals: CP14Storm
|
||||
- visuals: CP14Mist
|
||||
- type: CP14DayCycle
|
||||
timeEntries:
|
||||
- duration: 80
|
||||
color: '#754A4AFF'
|
||||
- duration: 80
|
||||
color: '#E0BA87FF'
|
||||
- duration: 80
|
||||
color: '#BFEEFFFF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#385163FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#060D12FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- duration: 80
|
||||
color: '#120906FF'
|
||||
- type: Broadphase
|
||||
- type: OccluderTree
|
||||
- type: MapGrid
|
||||
|
||||
@@ -28,27 +28,6 @@ entities:
|
||||
range: 10
|
||||
- type: MapLight
|
||||
- type: CP14DayCycle
|
||||
timeEntries:
|
||||
- duration: 80
|
||||
color: '#754A4AFF'
|
||||
- duration: 80
|
||||
color: '#E0BA87FF'
|
||||
- duration: 80
|
||||
color: '#BFEEFFFF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#385163FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#060D12FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#000000FF'
|
||||
- duration: 80
|
||||
color: '#120906FF'
|
||||
- type: Gravity
|
||||
gravityShakeSound: !type:SoundPathSpecifier
|
||||
path: /Audio/Effects/alert.ogg
|
||||
|
||||
@@ -13,3 +13,24 @@
|
||||
- type: CP14DayCyclePeriod
|
||||
id: Evening
|
||||
name: cp14-daycycle-evening
|
||||
|
||||
- type: CP14DayCycle #
|
||||
id: Default
|
||||
timeEntries:
|
||||
- duration: 145
|
||||
color: '#754A4A' #Dawn
|
||||
- duration: 145
|
||||
color: '#E0BA87' #
|
||||
- duration: 145
|
||||
color: '#BFEEFF' #Day
|
||||
- period: Night
|
||||
duration: 145
|
||||
color: '#385163' #Evening
|
||||
- period: Night
|
||||
duration: 80
|
||||
color: '#060D12' #Night
|
||||
- period: Night
|
||||
duration: 160
|
||||
color: '#000000' #BLACK NIGHT
|
||||
- duration: 80
|
||||
color: '#120906' #Night
|
||||
@@ -11,6 +11,17 @@
|
||||
- type: MapLight
|
||||
ambientLightColor: "#000000"
|
||||
|
||||
- type: cp14DemiplaneModifier
|
||||
id: MapLightCycleDefault
|
||||
tiers:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
categories:
|
||||
MapLight: 1
|
||||
components:
|
||||
- type: CP14DayCycle
|
||||
|
||||
- type: cp14DemiplaneModifier
|
||||
id: MapLightDarkRed
|
||||
tiers:
|
||||
|
||||
Reference in New Issue
Block a user