diff --git a/Content.Client/Overlays/StencilOverlay.cs b/Content.Client/Overlays/StencilOverlay.cs index 14a86e5854..46745a0e62 100644 --- a/Content.Client/Overlays/StencilOverlay.cs +++ b/Content.Client/Overlays/StencilOverlay.cs @@ -1,7 +1,7 @@ using System.Numerics; using Content.Client.Parallax; using Content.Client.Weather; -using Content.Shared._CP14.DayCycle; +using Content.Shared._CP14.DayCycle.Components; using Content.Shared._CP14.WorldEdge; using Content.Shared.Salvage; using Content.Shared.Weather; diff --git a/Content.Client/_CP14/Overlays/StencilOverlay.CloudShadows.cs b/Content.Client/_CP14/Overlays/StencilOverlay.CloudShadows.cs index 13950801d3..1d37e65443 100644 --- a/Content.Client/_CP14/Overlays/StencilOverlay.CloudShadows.cs +++ b/Content.Client/_CP14/Overlays/StencilOverlay.CloudShadows.cs @@ -1,5 +1,5 @@ using System.Numerics; -using Content.Shared._CP14.DayCycle; +using Content.Shared._CP14.DayCycle.Components; using Robust.Client.Graphics; using Robust.Shared.Utility; @@ -53,7 +53,7 @@ public sealed partial class StencilOverlay worldHandle.UseShader(_protoManager.Index("StencilMask").Instance()); worldHandle.DrawTextureRect(_blep!.Texture, worldBounds); var curTime = _timing.RealTime; - var sprite = _sprite.GetFrame(new SpriteSpecifier.Texture(new ResPath(cloudComp.ParallaxPath)), curTime); + var sprite = _sprite.GetFrame(new SpriteSpecifier.Texture(cloudComp.ParallaxPath), curTime); // Draw the rain worldHandle.UseShader(_protoManager.Index("StencilDraw").Instance()); diff --git a/Content.Server/_CP14/DayCycle/CP14CloudShadowsSystem.cs b/Content.Server/_CP14/DayCycle/CP14CloudShadowsSystem.cs index 2de54120ec..ac0b496eb4 100644 --- a/Content.Server/_CP14/DayCycle/CP14CloudShadowsSystem.cs +++ b/Content.Server/_CP14/DayCycle/CP14CloudShadowsSystem.cs @@ -1,10 +1,9 @@ -using System.Numerics; -using Content.Shared._CP14.DayCycle; +using Content.Shared._CP14.DayCycle.Components; using Robust.Shared.Random; namespace Content.Server._CP14.DayCycle; -public sealed partial class CP14CloudShadowsSystem : EntitySystem +public sealed class CP14CloudShadowsSystem : EntitySystem { [Dependency] private readonly IRobustRandom _random = default!; @@ -15,10 +14,8 @@ public sealed partial class CP14CloudShadowsSystem : EntitySystem SubscribeLocalEvent(OnMapInit); } - private void OnMapInit(Entity ent, ref MapInitEvent args) + private void OnMapInit(Entity entity, ref MapInitEvent args) { - ent.Comp.CloudSpeed = new Vector2( - _random.NextFloat(-ent.Comp.MaxSpeed, ent.Comp.MaxSpeed), - _random.NextFloat(-ent.Comp.MaxSpeed, ent.Comp.MaxSpeed)); + entity.Comp.CloudSpeed = _random.NextVector2(-entity.Comp.MaxSpeed, entity.Comp.MaxSpeed); } } diff --git a/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs b/Content.Server/_CP14/DayCycle/CP14DayCycleSystem.cs similarity index 69% rename from Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs rename to Content.Server/_CP14/DayCycle/CP14DayCycleSystem.cs index 423957219d..0f2df41ec1 100644 --- a/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs +++ b/Content.Server/_CP14/DayCycle/CP14DayCycleSystem.cs @@ -1,19 +1,22 @@ -using System.Diagnostics; +using Content.Shared._CP14.DayCycle; +using Content.Shared._CP14.DayCycle.Components; using Content.Shared.Maps; using Robust.Shared.Map; using Robust.Shared.Map.Components; +using Robust.Shared.Prototypes; using Robust.Shared.Timing; -namespace Content.Shared._CP14.DayCycle; +namespace Content.Server._CP14.DayCycle; -public sealed partial class CP14DayCycleSystem : EntitySystem +public sealed partial class CP14DayCycleSystem : CP14SharedDayCycleSystem { public const int MinTimeEntryCount = 2; private const float MaxTimeDiff = 0.05f; + private static readonly ProtoId DayPeriod = "Day"; + [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly SharedMapSystem _maps = default!; - [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; public override void Initialize() @@ -21,17 +24,8 @@ public sealed partial class CP14DayCycleSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnMapInitDayCycle); - SubscribeLocalEvent(OnDayStarted); - SubscribeLocalEvent(OnNightStarted); } - private void OnDayStarted(Entity dayCycle, ref DayCycleDayStartedEvent args) - { - } - - private void OnNightStarted(Entity dayCycle, ref DayCycleNightStartedEvent args) - { - } private void OnMapInitDayCycle(Entity dayCycle, ref MapInitEvent args) { @@ -88,22 +82,8 @@ public sealed partial class CP14DayCycleSystem : EntitySystem dayCycle.Comp.EntryStartTime = dayCycle.Comp.EntryEndTime; dayCycle.Comp.EntryEndTime += dayCycle.Comp.CurrentTimeEntry.Duration; - // TODO: Made with states,we might need an evening or something, and besides, it's too much hardcore - if (dayCycle.Comp.IsNight && !dayCycle.Comp.CurrentTimeEntry.IsNight) // Day started - { - dayCycle.Comp.IsNight = false; - - var ev = new DayCycleDayStartedEvent(dayCycle); - RaiseLocalEvent(dayCycle, ref ev, true); - } - - if (!dayCycle.Comp.IsNight && dayCycle.Comp.CurrentTimeEntry.IsNight) // Night started - { - dayCycle.Comp.IsNight = true; - - var ev = new DayCycleNightStartedEvent(dayCycle); - RaiseLocalEvent(dayCycle, ref ev, true); - } + var ev = new DayCycleChangedEvent(dayCycle.Comp.CurrentTimeEntry); + RaiseLocalEvent(dayCycle, ref ev, true); Dirty(dayCycle); } @@ -113,28 +93,22 @@ public sealed partial class CP14DayCycleSystem : EntitySystem /// /// An entity being tested to see if it is in daylight /// Checks if the tile covers the weather (the only "roof" factor at the moment) - /// daylight test result returned public bool TryDaylightThere(EntityUid target, bool checkRoof) { - if (!TryComp(target, out var xform)) - return false; - + var xform = Transform(target); if (!TryComp(xform.MapUid, out var dayCycle)) return false; - if (checkRoof) - { - if (!TryComp(xform.GridUid, out var mapGrid)) - return !dayCycle.IsNight; + if (!checkRoof || !TryComp(xform.GridUid, out var mapGrid)) + return dayCycle.CurrentPeriod == DayPeriod; - var tileRef = _maps.GetTileRef(xform.GridUid.Value, mapGrid, xform.Coordinates); - var tileDef = (ContentTileDefinition) _tileDefManager[tileRef.Tile.TypeId]; + var tileRef = _maps.GetTileRef(xform.GridUid.Value, mapGrid, xform.Coordinates); + var tileDef = (ContentTileDefinition) _tileDefManager[tileRef.Tile.TypeId]; - if (!tileDef.Weather) - return false; - } + if (!tileDef.Weather) + return false; - return !dayCycle.IsNight; + return dayCycle.CurrentPeriod == DayPeriod; } private void SetAmbientColor(Entity light, Color color) diff --git a/Content.Server/_CP14/DayCycle/CP14AddTimeEntryCommand.cs b/Content.Server/_CP14/DayCycle/Commands/CP14AddTimeEntryCommand.cs similarity index 79% rename from Content.Server/_CP14/DayCycle/CP14AddTimeEntryCommand.cs rename to Content.Server/_CP14/DayCycle/Commands/CP14AddTimeEntryCommand.cs index 1399101919..011b814f2d 100644 --- a/Content.Server/_CP14/DayCycle/CP14AddTimeEntryCommand.cs +++ b/Content.Server/_CP14/DayCycle/Commands/CP14AddTimeEntryCommand.cs @@ -1,9 +1,11 @@ using Content.Server.Administration; using Content.Shared._CP14.DayCycle; +using Content.Shared._CP14.DayCycle.Components; using Content.Shared.Administration; using Robust.Shared.Console; +using Robust.Shared.Prototypes; -namespace Content.Server._CP14.DayCycle; +namespace Content.Server._CP14.DayCycle.Commands; [AdminCommand(AdminFlags.VarEdit)] public sealed class CP14AddTimeEntryCommand : LocalizedCommands @@ -13,7 +15,7 @@ public sealed class CP14AddTimeEntryCommand : LocalizedCommands public override string Command => Name; public override string Description => "Allows you to add a new time entry to the map list"; - public override string Help => $"{Name} "; + public override string Help => $"{Name} "; public override void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -29,7 +31,9 @@ public sealed class CP14AddTimeEntryCommand : LocalizedCommands return; } - var entityManager = IoCManager.Resolve(); + var entityManager = IoCManager.Resolve(); + var prototypeManager = IoCManager.Resolve(); + var dayCycleSystem = entityManager.System(); var entity = entityManager.GetEntity(netEntity); @@ -51,9 +55,9 @@ public sealed class CP14AddTimeEntryCommand : LocalizedCommands return; } - if (!bool.TryParse(args[3], out var isNight)) + if (!prototypeManager.TryIndex(args[3], out var prototype)) { - shell.WriteError(Loc.GetString("parse-bool-fail", ("args", args[3]))); + shell.WriteError(Loc.GetString("parse-prototype-fail", ("args", args[3]))); return; } @@ -61,7 +65,7 @@ public sealed class CP14AddTimeEntryCommand : LocalizedCommands { Color = color, Duration = TimeSpan.FromSeconds(duration), - IsNight = isNight + Period = prototype.ID, }; dayCycleSystem.AddTimeEntry((entity, dayCycle), entry); @@ -72,7 +76,7 @@ public sealed class CP14AddTimeEntryCommand : LocalizedCommands return args.Length switch { 1 => CompletionResult.FromOptions(CompletionHelper.Components(args[0])), - 4 => CompletionResult.FromOptions(CompletionHelper.Booleans), + 4 => CompletionResult.FromOptions(CompletionHelper.PrototypeIDs()), _ => CompletionResult.Empty, }; } diff --git a/Content.Server/_CP14/DayCycle/CP14InitDayCycleCommand.cs b/Content.Server/_CP14/DayCycle/Commands/CP14InitDayCycleCommand.cs similarity index 93% rename from Content.Server/_CP14/DayCycle/CP14InitDayCycleCommand.cs rename to Content.Server/_CP14/DayCycle/Commands/CP14InitDayCycleCommand.cs index 796b1fe2fc..56de466d51 100644 --- a/Content.Server/_CP14/DayCycle/CP14InitDayCycleCommand.cs +++ b/Content.Server/_CP14/DayCycle/Commands/CP14InitDayCycleCommand.cs @@ -2,8 +2,9 @@ using Content.Server.Administration; using Content.Shared._CP14.DayCycle; using Content.Shared.Administration; using Robust.Shared.Console; +using CP14DayCycleComponent = Content.Shared._CP14.DayCycle.Components.CP14DayCycleComponent; -namespace Content.Server._CP14.DayCycle; +namespace Content.Server._CP14.DayCycle.Commands; [AdminCommand(AdminFlags.VarEdit)] public sealed class CP14InitDayCycleCommand : LocalizedCommands diff --git a/Content.Server/_CP14/DayCycle/CP14SetTimeEntryCommand.cs b/Content.Server/_CP14/DayCycle/Commands/CP14SetTimeEntryCommand.cs similarity index 95% rename from Content.Server/_CP14/DayCycle/CP14SetTimeEntryCommand.cs rename to Content.Server/_CP14/DayCycle/Commands/CP14SetTimeEntryCommand.cs index 7b4dba7fac..c7239901bb 100644 --- a/Content.Server/_CP14/DayCycle/CP14SetTimeEntryCommand.cs +++ b/Content.Server/_CP14/DayCycle/Commands/CP14SetTimeEntryCommand.cs @@ -2,8 +2,9 @@ using Content.Server.Administration; using Content.Shared._CP14.DayCycle; using Content.Shared.Administration; using Robust.Shared.Console; +using CP14DayCycleComponent = Content.Shared._CP14.DayCycle.Components.CP14DayCycleComponent; -namespace Content.Server._CP14.DayCycle; +namespace Content.Server._CP14.DayCycle.Commands; [AdminCommand(AdminFlags.VarEdit)] public sealed class CP14SetTimeEntryCommand : LocalizedCommands diff --git a/Content.Server/_CP14/Farming/CP14FarmingSystem.cs b/Content.Server/_CP14/Farming/CP14FarmingSystem.cs index 8eeaa3bd5e..3557280215 100644 --- a/Content.Server/_CP14/Farming/CP14FarmingSystem.cs +++ b/Content.Server/_CP14/Farming/CP14FarmingSystem.cs @@ -1,3 +1,4 @@ +using Content.Server._CP14.DayCycle; using Content.Server._CP14.Farming.Components; using Content.Server.Destructible; using Content.Server.DoAfter; diff --git a/Content.Shared/_CP14/DayCycle/CP14DayCyclePeriodPrototype.cs b/Content.Shared/_CP14/DayCycle/CP14DayCyclePeriodPrototype.cs new file mode 100644 index 0000000000..79823aacaf --- /dev/null +++ b/Content.Shared/_CP14/DayCycle/CP14DayCyclePeriodPrototype.cs @@ -0,0 +1,10 @@ +using Robust.Shared.Prototypes; + +namespace Content.Shared._CP14.DayCycle; + +[Prototype("CP14DayCyclePeriod")] +public sealed class CP14DayCyclePeriodPrototype : IPrototype +{ + [IdDataField] + public string ID { get; } = string.Empty; +} diff --git a/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs b/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs new file mode 100644 index 0000000000..90049abce1 --- /dev/null +++ b/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs @@ -0,0 +1,3 @@ +namespace Content.Shared._CP14.DayCycle; + +public abstract class CP14SharedDayCycleSystem : EntitySystem; diff --git a/Content.Shared/_CP14/DayCycle/CP14CloudShadowsComponent.cs b/Content.Shared/_CP14/DayCycle/Components/CP14CloudShadowsComponent.cs similarity index 62% rename from Content.Shared/_CP14/DayCycle/CP14CloudShadowsComponent.cs rename to Content.Shared/_CP14/DayCycle/Components/CP14CloudShadowsComponent.cs index 2ebfd7f568..30e6fad54a 100644 --- a/Content.Shared/_CP14/DayCycle/CP14CloudShadowsComponent.cs +++ b/Content.Shared/_CP14/DayCycle/Components/CP14CloudShadowsComponent.cs @@ -1,16 +1,17 @@ using System.Numerics; using Robust.Shared.GameStates; +using Robust.Shared.Utility; -namespace Content.Shared._CP14.DayCycle; +namespace Content.Shared._CP14.DayCycle.Components; /// -/// if added to the map, renders cloud shadows on the map +/// If added to the map, renders cloud shadows on the map /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class CP14CloudShadowsComponent : Component { [DataField, AutoNetworkedField] - public Vector2 CloudSpeed = new Vector2(0.5f, 0f); + public Vector2 CloudSpeed = new(0.5f, 0f); [DataField] public float MaxSpeed = 1.5f; @@ -22,5 +23,5 @@ public sealed partial class CP14CloudShadowsComponent : Component public float Scale = 2.5f; [DataField] - public string ParallaxPath = "/Textures/_CP14/Parallaxes/Shadows.png"; + public ResPath ParallaxPath = new("/Textures/_CP14/Parallaxes/Shadows.png"); } diff --git a/Content.Shared/_CP14/DayCycle/CP14DayCycleComponent.cs b/Content.Shared/_CP14/DayCycle/Components/CP14DayCycleComponent.cs similarity index 76% rename from Content.Shared/_CP14/DayCycle/CP14DayCycleComponent.cs rename to Content.Shared/_CP14/DayCycle/Components/CP14DayCycleComponent.cs index df7838667a..556259e16e 100644 --- a/Content.Shared/_CP14/DayCycle/CP14DayCycleComponent.cs +++ b/Content.Shared/_CP14/DayCycle/Components/CP14DayCycleComponent.cs @@ -1,13 +1,13 @@ using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -namespace Content.Shared._CP14.DayCycle; +namespace Content.Shared._CP14.DayCycle.Components; /// -/// Stores all the necessary data for the day and night cycle system to work +/// Stores all the necessary data for the day and night cycle system to work. /// - -[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(CP14DayCycleSystem))] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(CP14SharedDayCycleSystem))] public sealed partial class CP14DayCycleComponent : Component { [ViewVariables] @@ -25,12 +25,12 @@ public sealed partial class CP14DayCycleComponent : Component [ViewVariables] public Color EndColor => NextCurrentTimeEntry.Color; + [ViewVariables] + public ProtoId CurrentPeriod => CurrentTimeEntry.Period; + [DataField(required: true), ViewVariables, AutoNetworkedField] public List TimeEntries = new(); - [DataField, ViewVariables, AutoNetworkedField] - public bool IsNight; // TODO: Rewrite this shit - [DataField, ViewVariables, AutoNetworkedField] public int CurrentTimeEntryIndex; @@ -57,17 +57,11 @@ public readonly partial record struct DayCycleEntry() public TimeSpan Duration { get; init; } = TimeSpan.FromSeconds(60); [DataField] - public bool IsNight { get; init; } = false; + public ProtoId Period { get; init; } = "Day"; } /// -/// Event raised on map entity, wen night is started +/// Event raised on map entity, wen day cycle changed. /// [ByRefEvent] -public readonly record struct DayCycleNightStartedEvent(EntityUid Map); - -/// -/// Event raised on map entity, wen night is started -/// -[ByRefEvent] -public readonly record struct DayCycleDayStartedEvent(EntityUid Map); +public readonly record struct DayCycleChangedEvent(DayCycleEntry Entry); diff --git a/Content.Shared/_CP14/Random/Rules/IsDaylight.cs b/Content.Shared/_CP14/Random/Rules/IsDaylight.cs index e694bd255f..2f21338c83 100644 --- a/Content.Shared/_CP14/Random/Rules/IsDaylight.cs +++ b/Content.Shared/_CP14/Random/Rules/IsDaylight.cs @@ -1,4 +1,3 @@ -using Content.Shared._CP14.DayCycle; using Content.Shared.Random.Rules; namespace Content.Shared._CP14.Random.Rules; @@ -11,7 +10,9 @@ public sealed partial class IsDaylight : RulesRule public override bool Check(EntityManager entManager, EntityUid uid) { var transform = entManager.System(); - var dayCycle = entManager.System(); + + // Not shared yet, use raw component data from map + // var dayCycle = entManager.System(); //черт, нужны комиты из ветки фермерства return !Inverted; diff --git a/Resources/Maps/_CP14/alchemy_test.yml b/Resources/Maps/_CP14/alchemy_test.yml index 5924e8f4a2..05085f541a 100644 --- a/Resources/Maps/_CP14/alchemy_test.yml +++ b/Resources/Maps/_CP14/alchemy_test.yml @@ -47,18 +47,18 @@ entities: color: '#E0BA87FF' - duration: 80 color: '#BFEEFFFF' - - isNight: True - duration: 80 + - duration: 80 color: '#385163FF' - - isNight: True - duration: 80 + period: Night + - duration: 80 color: '#060D12FF' - - isNight: True - duration: 80 + period: Night + - duration: 80 color: '#000000FF' - - isNight: True - duration: 80 + period: Night + - duration: 80 color: '#000000FF' + period: Night - duration: 80 color: '#120906FF' - uid: 2 diff --git a/Resources/Maps/_CP14/battle_royale.yml b/Resources/Maps/_CP14/battle_royale.yml index d164f5e4e6..733b8c771a 100644 --- a/Resources/Maps/_CP14/battle_royale.yml +++ b/Resources/Maps/_CP14/battle_royale.yml @@ -42,16 +42,16 @@ entities: color: '#E0BA87FF' - duration: 80 color: '#BFEEFFFF' - - isNight: True + - period: Night duration: 80 color: '#385163FF' - - isNight: True + - period: Night duration: 80 color: '#060D12FF' - - isNight: True + - period: Night duration: 80 color: '#000000FF' - - isNight: True + - period: Night duration: 80 color: '#000000FF' - duration: 80 diff --git a/Resources/Maps/_CP14/dev_map.yml b/Resources/Maps/_CP14/dev_map.yml index a03fdfbe1d..4d2044a103 100644 --- a/Resources/Maps/_CP14/dev_map.yml +++ b/Resources/Maps/_CP14/dev_map.yml @@ -38,16 +38,16 @@ entities: color: '#E0BA87FF' - duration: 80 color: '#BFEEFFFF' - - isNight: True + - period: Night duration: 80 color: '#385163FF' - - isNight: True + - period: Night duration: 80 color: '#060D12FF' - - isNight: True + - period: Night duration: 80 color: '#000000FF' - - isNight: True + - period: Night duration: 80 color: '#000000FF' - duration: 80 diff --git a/Resources/Maps/_CP14/template.yml b/Resources/Maps/_CP14/template.yml index e5592855b4..0f49d44803 100644 --- a/Resources/Maps/_CP14/template.yml +++ b/Resources/Maps/_CP14/template.yml @@ -35,16 +35,16 @@ entities: color: '#E0BA87FF' - duration: 80 color: '#BFEEFFFF' - - isNight: True + - period: Night duration: 80 color: '#385163FF' - - isNight: True + - period: Night duration: 80 color: '#060D12FF' - - isNight: True + - period: Night duration: 80 color: '#000000FF' - - isNight: True + - period: Night duration: 80 color: '#000000FF' - duration: 80 diff --git a/Resources/Prototypes/_CP14/DayCycle/periods.yml b/Resources/Prototypes/_CP14/DayCycle/periods.yml new file mode 100644 index 0000000000..7881923e29 --- /dev/null +++ b/Resources/Prototypes/_CP14/DayCycle/periods.yml @@ -0,0 +1,11 @@ +- type: CP14DayCyclePeriod + id: Sunrise # HOLY SHIT! + +- type: CP14DayCyclePeriod + id: Day + +- type: CP14DayCyclePeriod + id: Night + +- type: CP14DayCyclePeriod + id: Evening