Skip to content

Instantly share code, notes, and snippets.

@eelstork
Created August 29, 2019 08:55
Show Gist options
  • Save eelstork/0e8b68cd8b645ee221ca3c15c24e9442 to your computer and use it in GitHub Desktop.
Save eelstork/0e8b68cd8b645ee221ca3c15c24e9442 to your computer and use it in GitHub Desktop.
Demonstrates implementing an Active Logic Decorator
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