Color.TryFromHex returns a bool and outputs a color (#44581)

This commit is contained in:
sleepyyapril 2026-07-17 21:38:13 -03:00 • committed by GitHub
parent b57772c3ad
commit 2ab5af4052
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 7 deletions

View file

@ -28,8 +28,7 @@ namespace Content.Server.Administration.Commands
if (string.IsNullOrEmpty(colorArg))
return;
var color = Color.TryFromHex(colorArg);
if (!color.HasValue)
if (!Color.TryFromHex(colorArg, out var color))
{
shell.WriteError(Loc.GetString("shell-invalid-color-hex"));
return;
@ -37,10 +36,10 @@ namespace Content.Server.Administration.Commands
var userId = shell.Player.UserId;
// Save the DB
_dbManager.SaveAdminOOCColorAsync(userId, color.Value);
_dbManager.SaveAdminOOCColorAsync(userId, color);
// Update the cached preference
var prefs = _preferenceManager.GetPreferences(userId);
prefs.AdminOOCColor = color.Value;
prefs.AdminOOCColor = color;
}
}
}

View file

@ -56,14 +56,13 @@ namespace Content.Server.Sandbox.Commands
return;
}
var color = Color.TryFromHex(args[2]);
if (!color.HasValue)
if (!Color.TryFromHex(args[2], out var color))
{
shell.WriteError(Loc.GetString("shell-invalid-color-hex"));
return;
}
PaintNodes(nodeContainerComponent, nodeGroupId, color.Value);
PaintNodes(nodeContainerComponent, nodeGroupId, color);
}
private void PaintNodes(NodeContainerComponent nodeContainerComponent, NodeGroupID nodeGroupId, Color color)