Created
August 29, 2019 08:55
-
-
Save eelstork/0e8b68cd8b645ee221ca3c15c24e9442 to your computer and use it in GitHub Desktop.
Demonstrates implementing an Active Logic Decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Active.Core; | |
using static Active.Core.status; | |
using Tag = System.Runtime.CompilerServices.CallerLineNumberAttribute; | |
[Serializable] public class Cooldown : Conditional { | |
public float duration = 1f; | |
float stamp = System.Single.MinValue; | |
public CustomCooldown() {} | |
public CustomCooldown(float duration) => this.duration = duration; | |
public Gate? this[float s] | |
=> (time >= stamp + s) ? done() | |
: fail(log && $"[{s + stamp - time:0.0}]"); | |
override public void OnStatus(status s){ | |
if(!s.running) stamp = time; | |
} | |
override public action Reset(){ | |
stamp = 0; | |
return @void(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment