Skip to content

Commit

Permalink
Clarify by renaming Priority to CancelPriority
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickcreamer committed Mar 1, 2020
1 parent 92be10f commit 4236bdd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 6 additions & 6 deletions Hemlock/StatusInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public int Value {
}
}
/// <summary>
/// Priority is important only during cancellation. When a status is cancelled, its StatusInstances are removed
/// one at a time, in order of priority - lowest first.
/// When a status is cancelled, its StatusInstances are removed one at a time, in order of priority - lowest first.
/// This can be useful to ensure a specific ordering for value changes during cancellation.
/// </summary>
public int Priority { get; set; }
public int CancelPriority { get; set; }
/// <summary>
/// Test whether this StatusInstance's status is a valid value for the type of the "status" argument.
/// If so, load its value into "status" and return true.
Expand Down Expand Up @@ -101,7 +101,7 @@ public StatusInstance<TObject> Clone(int? value = null, int? priority = null, In
public StatusInstance(TBaseStatus status, int value = 1, int priority = 0, InstanceType type = InstanceType.Feed, int? overrideSetIndex = null) {
Status = status;
internalValue = value;
Priority = priority;
CancelPriority = priority;
InstanceType = type;
this.overrideSetIndex = overrideSetIndex;
}
Expand All @@ -110,8 +110,8 @@ protected StatusInstance(StatusInstance<TObject> copyFrom, int? value = null, in
Status = copyFrom.Status;
if(value == null) internalValue = copyFrom.internalValue;
else internalValue = value.Value;
if(priority == null) Priority = copyFrom.Priority;
else Priority = priority.Value;
if(priority == null) CancelPriority = copyFrom.CancelPriority;
else CancelPriority = priority.Value;
if(type == null) InstanceType = copyFrom.InstanceType;
else InstanceType = type.Value;
if(overrideSetIndex == null) this.overrideSetIndex = copyFrom.overrideSetIndex;
Expand Down
4 changes: 2 additions & 2 deletions Hemlock/StatusTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void SerializeStatusInstances(InstanceType type, System.IO.BinaryWriter
writer.Write(instance.Status);
writer.Write((int)instance.InstanceType);
writer.Write(instance.Value);
writer.Write(instance.Priority);
writer.Write(instance.CancelPriority);
if(instance.OverrideSetIndex == null){
writer.Write(false);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ public bool RemoveStatusInstance(StatusInstance<TObject> instance) {
/// (This will return the value of this status to zero, unless other statuses are feeding this one.)
/// </summary>
public void Cancel(TBaseStatus status) {
foreach(var instance in statusInstances[InstanceType.Feed][status].OrderBy(x => x.Priority)) {
foreach(var instance in statusInstances[InstanceType.Feed][status].OrderBy(x => x.CancelPriority)) {
RemoveStatusInstance(instance);
}
foreach(TBaseStatus extendingStatus in rules.statusesThatExtend[status]) Cancel(extendingStatus);
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ For example, you might want to prevent Burning for any creature that is currentl
This is useful for prevention conditions, because (unlike suppression and cancellation) prevention only matters at the exact moment when a status instance is added.


### Cancel priority
Normally, when a status is canceled, all the StatusInstances for that status are removed in insertion order, with the value being recalculated as each is removed.

Occasionally, it might be useful to have more control over the order in which instances are removed, especially for a boolean status, and especially if each instance prints a different message (through use of the override set feature).

You can set the CancelPriority property on a StatusInstance to control this behavior: StatusInstances will be removed in order of CancelPriority, lowest to highest (while preserving insertion order for instances with the same priority).


## How does the parser work?

Expand Down

0 comments on commit 4236bdd

Please sign in to comment.