From 272cfd9a3f15cb5b9c00eba138b35ced7c3df215 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Sat, 25 Feb 2023 04:44:56 -0600 Subject: [PATCH] Simple queueing script (needs finished) --- scripts/shared/queue.js | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 scripts/shared/queue.js diff --git a/scripts/shared/queue.js b/scripts/shared/queue.js new file mode 100644 index 00000000..f63b5b1e --- /dev/null +++ b/scripts/shared/queue.js @@ -0,0 +1,44 @@ +// =========================================================================== +// Vortrex's Roleplay Resource +// https://github.com/VortrexFTW/v-roleplay +// =========================================================================== +// FILE: queue.js +// DESC: Provides simple queue functions +// TYPE: Shared (JavaScript) +// =========================================================================== + +class QueueData { + constructor(func, duration) { + this.duration = duration; + this.func = func; + this.nextUp = null; + + if (this.nextUp != null) { + if (duration <= 0) { + this.nextUp.func(); + } else { + delayedFunction(this.nextUp.func, this.duration); + } + } + } + + next(func, duration) { + this.nextUp = createQueue(func, duration); + } +} + +// =========================================================================== + +function createQueue(func, duration) { + return new QueueData(func, duration); +} + +// =========================================================================== + +function delayedFunction(func, duration) { + setTimeout(function () { + func(); + }, duration); +} + +// =========================================================================== \ No newline at end of file