Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVar CharacterRequirement #1322

Merged
merged 16 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Content.Shared/Customization/Systems/CharacterRequirements.Misc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Content.Shared.Customization.Systems;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;

namespace Content.Shared.Customization.Systems;

/// <summary>
/// Requires the server to have a specific CVar value.
/// </summary>
[UsedImplicitly, Serializable, NetSerializable,]
public sealed partial class CVarRequirement : CharacterRequirement
{
[DataField("cvar", required: true)]
sleepyyapril marked this conversation as resolved.
Show resolved Hide resolved
public string CVar;

[DataField("requiredValue", required: true)]
sleepyyapril marked this conversation as resolved.
Show resolved Hide resolved
public string RequiredValue;

public override bool IsValid(
JobPrototype job,
HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes,
bool whitelisted,
IPrototype prototype,
IEntityManager entityManager,
IPrototypeManager prototypeManager,
IConfigurationManager configManager,
out string? reason,
int depth = 0
)
{
if (!configManager.IsCVarRegistered(CVar))
{
reason = null;
return true;
}

const string color = "lightblue";
var cvar = configManager.GetCVar(CVar);
var isValid = cvar.ToString()! == RequiredValue;

reason = Loc.GetString(
"character-cvar-requirement",
("inverted", Inverted),
("color", color),
("cvar", CVar),
("value", RequiredValue));

return isValid;
}
}
Loading
Loading