class ScriptEvent {
	var action:Void->Void;

	public var totalDelay:Float;
	public var time:Float = 0;
	public var repeat:Int;

	public var ready:Bool = false;
	public var remove:Bool = false;

	public function new(action:Void->Void, delay:Float = 0, repeat:Int = 1) {
		this.action = action;
		totalDelay = delay;
		this.repeat = repeat;
	}

	public static function s(?delay:Float = 0, ?repeat:Int = 1, ?action:Void->Void) {
		return new ScriptEvent(action, delay, repeat);
	}

	public function go() {
		if (action != null)
			action();
		ready = false;
	}

	public function update(dt:Float) {
		if (time >= totalDelay) {
			ready = true;

			if (--repeat == 0) {
				remove = true;
			} else {
				time -= totalDelay;
			}
		} else {
			time += dt;
		}
	}
}
