mirror of
https://codeberg.org/vlw/monkeydo.git
synced 2025-09-13 23:53:41 +02:00
Corrected manifest data references
This commit is contained in:
parent
17224b0a86
commit
f6e86a5892
2 changed files with 8 additions and 17 deletions
17
Monkeydo.mjs
17
Monkeydo.mjs
|
@ -19,8 +19,7 @@ export default class Monkeydo extends MonkeyWorker {
|
||||||
|
|
||||||
// Monkeydo manifest parsed with load()
|
// Monkeydo manifest parsed with load()
|
||||||
this.manifest = {
|
this.manifest = {
|
||||||
header: null,
|
tasks: null
|
||||||
body: null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!window.Worker) {
|
if(!window.Worker) {
|
||||||
|
@ -84,25 +83,17 @@ export default class Monkeydo extends MonkeyWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the parsed JSON is a valid Monkeydo manifest
|
// Make sure the parsed JSON is a valid Monkeydo manifest
|
||||||
if(!data.hasOwnProperty("header") || !data.hasOwnProperty("body")) {
|
if(!data.hasOwnProperty("tasks")) {
|
||||||
this.debug(data);
|
this.debug(data);
|
||||||
throw new Error(errorPrefix + "Expected 'header' and 'body' properties in object");
|
throw new Error(errorPrefix + "Expected 'header' and 'body' properties in object");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.manifest.header = data.header;
|
this.manifest.tasks = data.tasks;
|
||||||
this.manifest.body = data.body;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute tasks from Monkeydo manifest
|
// Execute tasks from Monkeydo manifest
|
||||||
async do() {
|
do() {
|
||||||
const errorPrefix = "DO_FAILED: ";
|
|
||||||
// Abort if the manifest object doesn't contain any header data
|
|
||||||
if(!this.manifest.header) {
|
|
||||||
this.debug(this.manifest.header);
|
|
||||||
throw new Error(errorPrefix + `Expected header object from contructed property`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hand over the loaded manifest to the MonkeyWorker task manager
|
// Hand over the loaded manifest to the MonkeyWorker task manager
|
||||||
const monkey = this.giveManifest();
|
const monkey = this.giveManifest();
|
||||||
this.play();
|
this.play();
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
class Monkey {
|
class Monkey {
|
||||||
constructor(manifest) {
|
constructor(manifest) {
|
||||||
const self = this;
|
const self = this;
|
||||||
this.data = manifest.body;
|
this.tasks = manifest.tasks;
|
||||||
this.dataLength = this.data.length - 1;
|
this.tasksLength = this.tasks.length - 1;
|
||||||
|
|
||||||
this.flags = {
|
this.flags = {
|
||||||
playing: 0,
|
playing: 0,
|
||||||
|
@ -62,7 +62,7 @@ class Monkey {
|
||||||
// Schedule task for execution by index
|
// Schedule task for execution by index
|
||||||
queueNext() {
|
queueNext() {
|
||||||
this.flags.playing = 1;
|
this.flags.playing = 1;
|
||||||
const data = this.data[this.i];
|
const data = this.tasks[this.i];
|
||||||
const task = {
|
const task = {
|
||||||
wait: data[0],
|
wait: data[0],
|
||||||
func: data[1],
|
func: data[1],
|
||||||
|
@ -73,7 +73,7 @@ class Monkey {
|
||||||
this.queue.task = setTimeout(() => this.run(task),task.wait);
|
this.queue.task = setTimeout(() => this.run(task),task.wait);
|
||||||
|
|
||||||
// We're out of tasks to schedule..
|
// We're out of tasks to schedule..
|
||||||
if(this.i >= this.dataLength) {
|
if(this.i >= this.tasksLength) {
|
||||||
this.i = -1;
|
this.i = -1;
|
||||||
// Exit if we're out of loops
|
// Exit if we're out of loops
|
||||||
if(this.flags.loop === 0) {
|
if(this.flags.loop === 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue