mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
4bbfac5a5a
Before, the naming of fields, variables, and parameters that took `DriveNumber` was very inconsistent. This changes them all to `driveNo`.
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { debug } from '../js/util';
|
|
import { jsonDecode } from '../js/formats/format_utils';
|
|
import {
|
|
createDisk,
|
|
createDiskFromJsonDisk,
|
|
} from '../js/formats/create_disk';
|
|
import {
|
|
FormatWorkerMessage,
|
|
DiskProcessedResponse,
|
|
DISK_PROCESSED,
|
|
PROCESS_BINARY,
|
|
PROCESS_JSON_DISK,
|
|
PROCESS_JSON,
|
|
FloppyDisk,
|
|
} from '../js/formats/types';
|
|
|
|
debug('Worker loaded');
|
|
|
|
addEventListener('message', (message: MessageEvent<FormatWorkerMessage>) => {
|
|
debug('Worker started', message.type);
|
|
const data = message.data;
|
|
const { driveNo } = data.payload;
|
|
let disk: FloppyDisk | null = null;
|
|
|
|
switch (data.type) {
|
|
case PROCESS_BINARY: {
|
|
const { fmt, options } = data.payload;
|
|
disk = createDisk(fmt, options);
|
|
}
|
|
break;
|
|
|
|
case PROCESS_JSON_DISK: {
|
|
const { jsonDisk } = data.payload;
|
|
disk = createDiskFromJsonDisk(jsonDisk);
|
|
}
|
|
break;
|
|
|
|
case PROCESS_JSON: {
|
|
const { json } = data.payload;
|
|
disk = jsonDecode(json);
|
|
}
|
|
break;
|
|
}
|
|
|
|
const response: DiskProcessedResponse = {
|
|
type: DISK_PROCESSED,
|
|
payload: {
|
|
driveNo,
|
|
disk
|
|
}
|
|
};
|
|
|
|
self.postMessage(response);
|
|
|
|
debug('Worker complete', message.type);
|
|
});
|