add url parameter for saving to the local file system &mock-save

This commit is contained in:
Lee-Orr
2024-03-21 18:15:44 -04:00
parent 10759af963
commit 7f12634780
3 changed files with 70 additions and 73 deletions
+30 -6
View File
@@ -39,6 +39,7 @@ import "./anim-editor.element";
import "./help.element";
import "./app.element.scss";
import { mock_save_load } from "./util";
@customElement("app-root")
@provide({
@@ -72,13 +73,36 @@ export class AppElement extends LitElement {
async onSceneSaved({ detail: scene }: SceneSavedEvent): Promise<void> {
try {
const file = new File([scene], "scene.scn.ron", { type: "text/ron" });
const token = await this.api.createScene(file);
if (mock_save_load()) {
let handle = await window.showSaveFilePicker({
suggestedName: "scene",
types: [{
description: "Scene Files",
accept: {
"text/ron": [".scn.ron"]
}
}]
});
let writable = await handle.createWritable();
await writable.write(file);
await writable.close();
let token = handle.name;
this.dispatchEvent(new CustomEvent("scene-uploaded", {
detail: token,
bubbles: true,
composed: true,
}));
this.dispatchEvent(new CustomEvent("scene-uploaded", {
detail: token,
bubbles: true,
composed: true,
}));
} else {
const token = await this.api.createScene(file);
this.dispatchEvent(new CustomEvent("scene-uploaded", {
detail: token,
bubbles: true,
composed: true,
}));
}
}
catch (err) {
console.error(err);
+4
View File
@@ -3,3 +3,7 @@ export function isDevEnvironment(): boolean {
|| window.location.hostname === "127.0.0.1"
|| window.location.hostname.includes("deploy-preview");
}
export function mock_save_load(): boolean {
return window.location.search.includes("mock-saves");
}