Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
terryzfeng committed Apr 22, 2024
1 parent c9093fb commit c050cbf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,28 @@ export async function startChuck() {
.loadFile(
"https://raw.githubusercontent.com/tae1han/ChucKTonal/main/src/ezchord.ck"
)
.then(() => {
.then(() => {
theChuck.runFile("ezchord.ck");
});
await theChuck
.loadFile(
"https://raw.githubusercontent.com/tae1han/ChucKTonal/main/src/ezscore.ck"
)
.then(() => {
.then(() => {
theChuck.runFile("ezscore.ck");
});
await theChuck
.loadFile(
"https://raw.githubusercontent.com/tae1han/ChucKTonal/main/src/ezscale.ck"
)
.then(() => {
.then(() => {
theChuck.runFile("ezscale.ck");
});
await theChuck
.loadFile(
"https://raw.githubusercontent.com/tae1han/ChucKTonal/main/src/scoreplayer.ck"
)
.then(() => {
.then(() => {
theChuck.runFile("scoreplayer.ck");
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/export/exportSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export const MIXER_JS = `// MIXER CODE for GUI (if there are global variables)
mixer.append(div);
input.addEventListener('input', e => theChuck?.setFloat(variable, +e.target.value));
});`;
});`;
38 changes: 28 additions & 10 deletions src/services/export/exportWebchuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,27 @@ async function exportWebchuck(
// Add in PRELOAD_FILES
// get all projectFiles excluding the current active file
const currentFile = ProjectSystem.activeFile;
const projectFilesToPreload = ProjectSystem.getProjectFiles().filter(file => file !== currentFile);
const preloadFileString = projectFilesToPreload.map(file => {
return { "serverFilename": `./${file.getFilename()}`, "virtualFilename": file.getFilename() }
const projectFilesToPreload = ProjectSystem.getProjectFiles().filter(
(file) => file !== currentFile
);
const preloadFileString = projectFilesToPreload.map((file) => {
return {
serverFilename: `./${file.getFilename()}`,
virtualFilename: file.getFilename(),
};
});
wc_html = docFindReplace(wc_html, "{{{ PRELOAD_FILES }}}", JSON.stringify(preloadFileString));
wc_html = docFindReplace(
wc_html,
"{{{ PRELOAD_FILES }}}",
JSON.stringify(preloadFileString)
);

// If exporting a single HTML or a HTML with auxillary files
if (projectFilesToPreload.length === 0) {
exportSingleWCFile(wc_html);
} else {
exportProjectWCFiles(wc_html, projectFilesToPreload);
}

}

/**
Expand Down Expand Up @@ -145,12 +153,22 @@ function exportProjectWCFiles(wc_html: Document, projectFiles: any) {
}

/**
* Helper function to find and replace in a HTML Document file
*
* Helper function to find and replace in a HTML Document file
*
*/
function docFindReplace(doc: Document, find: string, replace: string): Document {
doc.documentElement.innerHTML = doc.documentElement.outerHTML.replace(find, replace);
return new DOMParser().parseFromString(doc.documentElement.outerHTML, "text/html");
function docFindReplace(
doc: Document,
find: string,
replace: string
): Document {
doc.documentElement.innerHTML = doc.documentElement.outerHTML.replace(
find,
replace
);
return new DOMParser().parseFromString(
doc.documentElement.outerHTML,
"text/html"
);
}

// --------------------------------------
Expand Down

0 comments on commit c050cbf

Please sign in to comment.