Allow setting the rawvalue of unlocked permission objects

This commit is contained in:
RogueException
2015-10-06 15:29:46 -03:00
parent 976789240b
commit 6f9e876252
4 changed files with 18 additions and 4 deletions

View File

@@ -260,7 +260,7 @@ namespace Discord.API
public class RoleInfo public class RoleInfo
{ {
[JsonProperty("permissions")] [JsonProperty("permissions")]
public int Permissions; public uint Permissions;
[JsonProperty("name")] [JsonProperty("name")]
public string Name; public string Name;
[JsonProperty("id")] [JsonProperty("id")]

View File

@@ -186,7 +186,7 @@ namespace Discord
if (permissions.RawValue != newPermissions) if (permissions.RawValue != newPermissions)
{ {
permissions.RawValue = newPermissions; permissions.SetRawValue(newPermissions);
channel._areMembersStale = true; channel._areMembersStale = true;
} }
} }

View File

@@ -44,7 +44,16 @@ namespace Discord
{ {
private bool _isLocked; private bool _isLocked;
protected uint _rawValue; protected uint _rawValue;
public uint RawValue { get { return _rawValue; } internal set { _rawValue = value; } } //Internal set bypasses isLocked for API changes. public uint RawValue
{
get { return _rawValue; }
set
{
if (_isLocked)
throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy.");
_rawValue = value;
}
}
protected PackedPermissions(bool isLocked, uint rawValue) { _isLocked = isLocked; _rawValue = rawValue; } protected PackedPermissions(bool isLocked, uint rawValue) { _isLocked = isLocked; _rawValue = rawValue; }
@@ -92,6 +101,11 @@ namespace Discord
//6 Unused //6 Unused
internal void SetRawValue(uint rawValue)
{
//Bypasses isLocked for API changes.
_rawValue = rawValue;
}
protected bool GetBit(int pos) => ((_rawValue >> (pos - 1)) & 1U) == 1; protected bool GetBit(int pos) => ((_rawValue >> (pos - 1)) & 1U) == 1;
protected void SetBit(int pos, bool value) protected void SetBit(int pos, bool value)
{ {

View File

@@ -41,7 +41,7 @@ namespace Discord
internal void Update(API.RoleInfo model) internal void Update(API.RoleInfo model)
{ {
Name = model.Name; Name = model.Name;
Permissions.RawValue = (uint)model.Permissions; Permissions.SetRawValue(model.Permissions);
foreach (var member in Members) foreach (var member in Members)
member.UpdatePermissions(); member.UpdatePermissions();