mirror of
https://codeberg.org/vlw/monkeydo.git
synced 2025-09-13 15:53:40 +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()
|
||||
this.manifest = {
|
||||
header: null,
|
||||
body: null
|
||||
tasks: null
|
||||
};
|
||||
|
||||
if(!window.Worker) {
|
||||
|
@ -84,25 +83,17 @@ export default class Monkeydo extends MonkeyWorker {
|
|||
}
|
||||
|
||||
// Make sure the parsed JSON is a valid Monkeydo manifest
|
||||
if(!data.hasOwnProperty("header") || !data.hasOwnProperty("body")) {
|
||||
if(!data.hasOwnProperty("tasks")) {
|
||||
this.debug(data);
|
||||
throw new Error(errorPrefix + "Expected 'header' and 'body' properties in object");
|
||||
}
|
||||
|
||||
this.manifest.header = data.header;
|
||||
this.manifest.body = data.body;
|
||||
this.manifest.tasks = data.tasks;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Execute tasks from Monkeydo manifest
|
||||
async 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`);
|
||||
}
|
||||
|
||||
do() {
|
||||
// Hand over the loaded manifest to the MonkeyWorker task manager
|
||||
const monkey = this.giveManifest();
|
||||
this.play();
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
class Monkey {
|
||||
constructor(manifest) {
|
||||
const self = this;
|
||||
this.data = manifest.body;
|
||||
this.dataLength = this.data.length - 1;
|
||||
this.tasks = manifest.tasks;
|
||||
this.tasksLength = this.tasks.length - 1;
|
||||
|
||||
this.flags = {
|
||||
playing: 0,
|
||||
|
@ -62,7 +62,7 @@ class Monkey {
|
|||
// Schedule task for execution by index
|
||||
queueNext() {
|
||||
this.flags.playing = 1;
|
||||
const data = this.data[this.i];
|
||||
const data = this.tasks[this.i];
|
||||
const task = {
|
||||
wait: data[0],
|
||||
func: data[1],
|
||||
|
@ -73,7 +73,7 @@ class Monkey {
|
|||
this.queue.task = setTimeout(() => this.run(task),task.wait);
|
||||
|
||||
// We're out of tasks to schedule..
|
||||
if(this.i >= this.dataLength) {
|
||||
if(this.i >= this.tasksLength) {
|
||||
this.i = -1;
|
||||
// Exit if we're out of loops
|
||||
if(this.flags.loop === 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue