From 953a7dacad6c093270794433d65dd63108c72dae Mon Sep 17 00:00:00 2001
From: Landon & Emma <80786423+LandonAndEmma@users.noreply.github.com>
Date: Wed, 10 Apr 2024 19:33:11 -0400
Subject: [PATCH] Update code.js
---
code.js | 102 ++++++++++++++++++++++----------------------------------
1 file changed, 40 insertions(+), 62 deletions(-)
diff --git a/code.js b/code.js
index 44425dd..4b8401a 100644
--- a/code.js
+++ b/code.js
@@ -53,18 +53,7 @@ const ARM_OFFSETS = {
};
function openFile() {
- const fileInput = document.createElement('input');
- fileInput.type = 'file';
- fileInput.accept = '.bin';
- fileInput.addEventListener('change', async (event) => {
- const file = event.target.files[0];
- if (file) {
- ARM9_BIN_PATH = file.name;
- const fileContent = await readBinaryFile(file);
- ARM_VALUES = Array.from(fileContent);
- refreshListbox();
- }
- });
+ const fileInput = document.getElementById('fileInput');
fileInput.click();
}
@@ -99,42 +88,6 @@ async function saveFile() {
}
}
-function openRepository() {
- const repositoryUrl = 'https://github.com/LandonAndEmma/MKDS-ARM9-Music-Editor';
- window.open(repositoryUrl, '_blank');
-}
-
-function openPopup() {
- const selectedTrack = listbox.options[listbox.selectedIndex].text;
- const offset = ARM_OFFSETS[selectedTrack];
-
- const popupWindow = window.open('', 'Change SEQ Value', 'width=300,height=180');
- popupWindow.document.write(`
-
-
- Change SEQ Value
-
-
-
-
-
-
-
- `);
-
- popupWindow.changeSeqValue = function() {
- const newSeqValue = parseInt(popupWindow.document.getElementById('seqValue').value);
- if (!isNaN(newSeqValue) && newSeqValue >= 0 && newSeqValue <= 75) {
- ARM_VALUES[offset] = newSeqValue;
- refreshListbox();
- popupWindow.close();
- alert(`SEQ value for ${selectedTrack} changed to ${newSeqValue}`);
- } else {
- alert('Invalid SEQ value. Value must be between 0 and 75.');
- }
- };
-}
-
async function saveFileAs() {
try {
const uint8Array = new Uint8Array(ARM_VALUES);
@@ -176,29 +129,54 @@ function openHelp() {
3. After making changes, go to File > Save to save the modified file.\n\n
Original Code: Ermelber, Yami, MkDasher\n
Fixed and made into a Python GUI app by Landon & Emma`;
-
alert(helpMessage);
}
+function openRepository() {
+ const repositoryUrl = 'https://github.com/LandonAndEmma/MKDS-ARM9-Music-Editor';
+ window.open(repositoryUrl, '_blank');
+}
+
function onListboxSelect() {
- const selectedTrack = listbox.options[listbox.selectedIndex].text;
+ const selectedTrack = trackList.options[trackList.selectedIndex].text;
if (selectedTrack) {
openPopup();
}
}
-window.addEventListener('DOMContentLoaded', (event) => {
- // Add event listeners and initialize the app
- const fileInput = document.getElementById('fileInput');
- fileInput.addEventListener('change', async (event) => {
- const file = event.target.files[0];
- if (file) {
- ARM9_BIN_PATH = file.name;
- const fileContent = await readBinaryFile(file);
- ARM_VALUES = Array.from(fileContent);
+function refreshListbox() {
+ const trackList = document.getElementById('trackList');
+ trackList.innerHTML = '';
+ for (const [track, offset] of Object.entries(ARM_OFFSETS)) {
+ const option = document.createElement('option');
+ option.text = track;
+ trackList.add(option);
+ }
+}
+
+async function openPopup() {
+ const selectedTrack = trackList.options[trackList.selectedIndex].text;
+ const offset = ARM_OFFSETS[selectedTrack];
+
+ const newSeqValue = prompt(`Enter new SEQ value for ${selectedTrack}:`, ARM_VALUES[offset]);
+ if (newSeqValue !== null) {
+ const intValue = parseInt(newSeqValue);
+ if (!isNaN(intValue) && intValue >= 0 && intValue <= 75) {
+ ARM_VALUES[offset] = intValue;
refreshListbox();
+ alert(`SEQ value for ${selectedTrack} changed to ${intValue}`);
+ } else {
+ alert('Invalid SEQ value. Value must be between 0 and 75.');
}
- });
+ }
+}
- // Add other event listeners
-});
\ No newline at end of file
+document.getElementById('fileInput').addEventListener('change', async (event) => {
+ const file = event.target.files[0];
+ if (file) {
+ ARM9_BIN_PATH = file.name;
+ const fileContent = await readBinaryFile(file);
+ ARM_VALUES = Array.from(fileContent);
+ refreshListbox();
+ }
+});