Updated day cycle (#171)
* Updated day cycle * Fixed DayCycleComponent attributes * Added new commands, as well as synchronization * Update cave-arena.yml * Update alchemy_test.yml --------- Co-authored-by: Ed <edwardxperia2000@gmail.com> Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>
This commit is contained in:
79
Content.Server/_CP14/DayCycle/CP14AddTimeEntryCommand.cs
Normal file
79
Content.Server/_CP14/DayCycle/CP14AddTimeEntryCommand.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared._CP14.DayCycle;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server._CP14.DayCycle;
|
||||
|
||||
[AdminCommand(AdminFlags.VarEdit)]
|
||||
public sealed class CP14AddTimeEntryCommand : LocalizedCommands
|
||||
{
|
||||
private const string Name = "add_time_entry";
|
||||
private const int ArgumentCount = 4;
|
||||
|
||||
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} <mapUid> <color> <duration> <isNight>";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != ArgumentCount)
|
||||
{
|
||||
shell.WriteError($"{Loc.GetString("shell-wrong-arguments-number")}\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NetEntity.TryParse(args[0], out var netEntity))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<EntityManager>();
|
||||
var dayCycleSystem = entityManager.System<CP14DayCycleSystem>();
|
||||
var entity = entityManager.GetEntity(netEntity);
|
||||
|
||||
if (!entityManager.TryGetComponent<CP14DayCycleComponent>(entity, out var dayCycle))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", entity), ("componentName", nameof(CP14DayCycleComponent))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Color.TryParse(args[1], out var color))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("parse-color-fail", ("args", args[1])));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!float.TryParse(args[2], out var duration))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("parse-float-fail", ("args", args[2])));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bool.TryParse(args[3], out var isNight))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("parse-bool-fail", ("args", args[3])));
|
||||
return;
|
||||
}
|
||||
|
||||
var entry = new DayCycleEntry
|
||||
{
|
||||
Color = color,
|
||||
Duration = TimeSpan.FromSeconds(duration),
|
||||
IsNight = isNight
|
||||
};
|
||||
|
||||
dayCycleSystem.AddTimeEntry((entity, dayCycle), entry);
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
return args.Length switch
|
||||
{
|
||||
1 => CompletionResult.FromOptions(CompletionHelper.Components<CP14DayCycleComponent>(args[0])),
|
||||
4 => CompletionResult.FromOptions(CompletionHelper.Booleans),
|
||||
_ => CompletionResult.Empty,
|
||||
};
|
||||
}
|
||||
}
|
||||
60
Content.Server/_CP14/DayCycle/CP14InitDayCycleCommand.cs
Normal file
60
Content.Server/_CP14/DayCycle/CP14InitDayCycleCommand.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared._CP14.DayCycle;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server._CP14.DayCycle;
|
||||
|
||||
[AdminCommand(AdminFlags.VarEdit)]
|
||||
public sealed class CP14InitDayCycleCommand : LocalizedCommands
|
||||
{
|
||||
private const string Name = "init_day_cycle";
|
||||
private const int ArgumentCount = 1;
|
||||
|
||||
public override string Command => Name;
|
||||
public override string Description =>
|
||||
"Re-initializes the day and night system, but reset the current time entry stage";
|
||||
public override string Help => $"{Name} <mapUid>";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != ArgumentCount)
|
||||
{
|
||||
shell.WriteError($"{Loc.GetString("shell-wrong-arguments-number")}\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NetEntity.TryParse(args[0], out var netEntity))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<EntityManager>();
|
||||
var dayCycleSystem = entityManager.System<CP14DayCycleSystem>();
|
||||
var entity = entityManager.GetEntity(netEntity);
|
||||
|
||||
if (!entityManager.TryGetComponent<CP14DayCycleComponent>(entity, out var dayCycle))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", entity), ("componentName", nameof(CP14DayCycleComponent))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dayCycle.TimeEntries.Count < CP14DayCycleSystem.MinTimeEntryCount)
|
||||
{
|
||||
shell.WriteError($"Attempting to init a daily cycle with the number of time entries less than {CP14DayCycleSystem.MinTimeEntryCount}");
|
||||
return;
|
||||
}
|
||||
|
||||
dayCycleSystem.Init((entity, dayCycle));
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
return args.Length switch
|
||||
{
|
||||
1 => CompletionResult.FromOptions(CompletionHelper.Components<CP14DayCycleComponent>(args[0])),
|
||||
_ => CompletionResult.Empty,
|
||||
};
|
||||
}
|
||||
}
|
||||
81
Content.Server/_CP14/DayCycle/CP14SetTimeEntryCommand.cs
Normal file
81
Content.Server/_CP14/DayCycle/CP14SetTimeEntryCommand.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared._CP14.DayCycle;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server._CP14.DayCycle;
|
||||
|
||||
[AdminCommand(AdminFlags.VarEdit)]
|
||||
public sealed class CP14SetTimeEntryCommand : LocalizedCommands
|
||||
{
|
||||
private const string Name = "set_time_entry";
|
||||
private const int ArgumentCount = 2;
|
||||
|
||||
public override string Command => Name;
|
||||
public override string Description => "Sets a new entry at the specified index";
|
||||
public override string Help => $"{Name} <mapUid> <timeEntry>";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != ArgumentCount)
|
||||
{
|
||||
shell.WriteError($"{Loc.GetString("shell-wrong-arguments-number")}\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NetEntity.TryParse(args[0], out var netEntity))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<EntityManager>();
|
||||
var dayCycleSystem = entityManager.System<CP14DayCycleSystem>();
|
||||
var entity = entityManager.GetEntity(netEntity);
|
||||
|
||||
if (!entityManager.TryGetComponent<CP14DayCycleComponent>(entity, out var dayCycle))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-entity-with-uid-lacks-component", ("uid", entity), ("componentName", nameof(CP14DayCycleComponent))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[1], out var timeEntry))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("parse-int-fail", ("args", args[1])));
|
||||
return;
|
||||
}
|
||||
|
||||
dayCycleSystem.SetTimeEntry((entity, dayCycle), timeEntry);
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<EntityManager>();
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 1:
|
||||
return CompletionResult.FromOptions(CompletionHelper.Components<CP14DayCycleComponent>(args[0], entityManager));
|
||||
|
||||
case 2:
|
||||
if (!NetEntity.TryParse(args[0], out var mapUid))
|
||||
return CompletionResult.Empty;
|
||||
|
||||
if (!entityManager.TryGetComponent<CP14DayCycleComponent>(entityManager.GetEntity(mapUid), out var component))
|
||||
return CompletionResult.Empty;
|
||||
|
||||
if (component.TimeEntries.Count - 1 < 0)
|
||||
return CompletionResult.Empty;
|
||||
|
||||
var indices = new string[component.TimeEntries.Count - 1];
|
||||
for (var i = 0; i < indices.Length; i++)
|
||||
{
|
||||
indices[i] = i.ToString();
|
||||
}
|
||||
|
||||
return CompletionResult.FromOptions(indices);
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user