From 8ea51b62a827d912e5927b1658d9f5ddb3e1f8f4 Mon Sep 17 00:00:00 2001 From: mborik128 Date: Wed, 30 Nov 2022 21:21:32 +0100 Subject: [PATCH 1/6] Implement E-Tracker module format #17 --- src/compiler/index.ts | 15 +- src/tracker/controls.ts | 17 +- src/tracker/file.import.ts | 440 +++++++++++++++++++++++++++++++++++++ src/tracker/file.system.ts | 13 +- src/tracker/file.ts | 92 ++------ src/tracker/gui.ts | 5 +- src/tracker/index.ts | 8 +- templates/menu.html | 4 +- webpack.config.js | 3 +- 9 files changed, 504 insertions(+), 93 deletions(-) create mode 100644 src/tracker/file.import.ts diff --git a/src/compiler/index.ts b/src/compiler/index.ts index 84696cf..61a379e 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -286,15 +286,18 @@ export default class Compiler extends CompilerRender implements CompilerOptions 'data-dismiss': 'modal' }).text('\xd7'); - keys.inDialog = true; + dialog.on('shown.bs.modal', () => { + keys.inDialog = true; + }).on('hidden.bs.modal', () => { + $(dialog).off().find('.modal-body').empty(); + keys.inDialog = false; + }); + dialog.modal('show') .find('.modal-body') .html('
\n
') - .prepend(button) - .on('hidden.bs.modal', () => { - keys.inDialog = false; - $(this).find('.modal-body').empty(); - }); + .scrollTop(0) + .prepend(button); } private composeSongData(): void { diff --git a/src/tracker/controls.ts b/src/tracker/controls.ts index c2f1cf5..27e78ac 100644 --- a/src/tracker/controls.ts +++ b/src/tracker/controls.ts @@ -311,18 +311,27 @@ Tracker.prototype.onCmdFileSave = function(as) { } }; //--------------------------------------------------------------------------------------- -Tracker.prototype.onCmdFileImport = function(demosong) { +Tracker.prototype.onCmdFileImport = function(type) { const keys = this.globalKeyState; if (this.modePlay || keys.lastPlayMode) { return; } let fnToCall: () => void; - if (demosong) { - fnToCall = this.file.importDemosong.bind(this.file, demosong, `demosongs/${demosong}.json`); + if (type === 'ETrk') { + fnToCall = () => { + this.file.importETracker(); + }; + } + else if (type) { + fnToCall = () => { + this.file.importDemosong(type, `demosongs/${type}.json`); + }; } else { - fnToCall = this.file.importFile.bind(this.file); + fnToCall = () => { + this.file.importFile(); + }; } if (this.file.modified) { diff --git a/src/tracker/file.import.ts b/src/tracker/file.import.ts new file mode 100644 index 0000000..0b8fb76 --- /dev/null +++ b/src/tracker/file.import.ts @@ -0,0 +1,440 @@ +/** + * SAA1099Tracker: File base class with all imports of various file formats. + * Copyright (c) 2022 Martin Borik + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS + * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +//--------------------------------------------------------------------------------------- + +import { devLog } from '../commons/dev'; +import Pattern from '../player/Pattern'; +import Position from '../player/Position'; +import constants from './constants'; +import { STMFile, STMFileFormat } from './file'; +import { binarytype } from './file.system'; + + +export class File extends STMFile { + private _messageLogger: string = ''; + private _log(str: string, error: boolean = false) { + this._messageLogger += `${error ? 'ERROR: ' : ''}${str}\n`; + $('#documodal .modal-body > pre').text(`\n${this._messageLogger}`); + } + + private _openOutputLog() { + this._messageLogger = ''; + + const keys = this._parent.globalKeyState; + + const dialog = $('#documodal'); + const button = $('