diff --git a/index.html b/index.html
index a8f0c0fd..7d40a147 100644
--- a/index.html
+++ b/index.html
@@ -34,8 +34,9 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
-
-
+
+
+
diff --git a/src/ide/project.ts b/src/ide/project.ts
index 81e64476..dd533469 100644
--- a/src/ide/project.ts
+++ b/src/ide/project.ts
@@ -11,7 +11,6 @@ export interface ProjectFilesystem {
export class WebPresetsFileSystem implements ProjectFilesystem {
preset_id : string;
constructor(platform_id: string) {
- // found on remote fetch?
this.preset_id = getBasePlatform(platform_id); // remove .suffix from preset name
}
async getRemoteFile(path: string): Promise {
@@ -20,6 +19,7 @@ export class WebPresetsFileSystem implements ProjectFilesystem {
});
}
async getFileData(path: string) : Promise {
+ // found on remote fetch?
var webpath = "presets/" + this.preset_id + "/" + path;
var data = await this.getRemoteFile(webpath);
if (data) console.log("read",webpath,data.length,'bytes');
@@ -44,23 +44,37 @@ export class NullFilesystem implements ProjectFilesystem {
}
-export class LocalForageFilesystem implements ProjectFilesystem {
+export class OverlayFilesystem implements ProjectFilesystem {
basefs: ProjectFilesystem;
- store: any;
- constructor(store: any, basefs: ProjectFilesystem) {
- this.store = store;
+ overlayfs: ProjectFilesystem;
+ constructor(basefs: ProjectFilesystem, overlayfs: ProjectFilesystem) {
this.basefs = basefs;
+ this.overlayfs = overlayfs;
}
async getFileData(path: string): Promise {
- var data = await this.store.getItem(path);
+ var data = await this.overlayfs.getFileData(path);
if (data == null) {
- data = await this.basefs.getFileData(path);
+ return this.basefs.getFileData(path);
+ } else {
+ return data;
}
- return data;
}
async setFileData(path: string, data: FileData): Promise {
- await this.store.setItem(path, data);
- await this.basefs.setFileData(path, data);
+ await this.overlayfs.setFileData(path, data);
+ return this.basefs.setFileData(path, data);
+ }
+}
+
+export class LocalForageFilesystem {
+ store: any;
+ constructor(store: any) {
+ this.store = store;
+ }
+ async getFileData(path: string): Promise {
+ return this.store.getItem(path);
+ }
+ async setFileData(path: string, data: FileData): Promise {
+ return this.store.setItem(path, data);
}
}
diff --git a/src/ide/services.ts b/src/ide/services.ts
index cc9d41b3..b3729f87 100644
--- a/src/ide/services.ts
+++ b/src/ide/services.ts
@@ -1,7 +1,7 @@
import { getFolderForPath, isProbablyBinary, stringToByteArray, byteArrayToString, byteArrayToUTF8 } from "../common/util";
import { FileData } from "../common/workertypes";
-import { CodeProject } from "./project";
+import { CodeProject, ProjectFilesystem } from "./project";
// in index.html
declare var exports;
@@ -370,3 +370,27 @@ export class GithubService {
}
}
+
+//
+
+export class FirebaseProjectFilesystem implements ProjectFilesystem {
+ ref;
+ constructor(user_id: string, store_id: string) {
+ var database = firebase.database();
+ this.ref = database.ref('users/' + user_id + "/" + store_id);
+ }
+ getChildForPath(path:string) {
+ var encodedPath = encodeURIComponent(path).replace('-','%2D').replace('.','%2E');
+ return this.ref.child(encodedPath);
+ }
+ async getFileData(path: string): Promise {
+ console.log(this.getChildForPath("test"));
+ var snapshot = await this.getChildForPath(path).get();
+ return snapshot.exists() ? snapshot.val().filedata : null;
+ }
+ async setFileData(path: string, data: FileData): Promise {
+ return this.getChildForPath(path).set({
+ filedata: data
+ });
+ }
+}
diff --git a/src/ide/ui.ts b/src/ide/ui.ts
index d62b0a9d..9f3b2994 100644
--- a/src/ide/ui.ts
+++ b/src/ide/ui.ts
@@ -3,7 +3,7 @@
import $ = require("jquery");
import * as bootstrap from "bootstrap";
-import { CodeProject, LocalForageFilesystem, ProjectFilesystem, WebPresetsFileSystem } from "./project";
+import { CodeProject, LocalForageFilesystem, OverlayFilesystem, ProjectFilesystem, WebPresetsFileSystem } from "./project";
import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError, FileData } from "../common/workertypes";
import { ProjectWindows } from "./windows";
import { Platform, Preset, DebugSymbols, DebugEvalCondition, isDebuggable, EmuState } from "../common/baseplatform";
@@ -13,7 +13,7 @@ import { createNewPersistentStore } from "./store";
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, stringToByteArray,
byteArrayToUTF8, isProbablyBinary, getWithBinary, getBasePlatform, getRootBasePlatform, hex } from "../common/util";
import { StateRecorderImpl } from "../common/recorder";
-import { GHSession, GithubService, getRepos, parseGithubURL } from "./services";
+import { GHSession, GithubService, getRepos, parseGithubURL, FirebaseProjectFilesystem } from "./services";
// external libs (TODO)
declare var Tour, GIF, saveAs, JSZip, Mousetrap, Split, firebase;
@@ -170,7 +170,11 @@ function unsetLastPreset() {
}
function initProject() {
- var filesystem = new LocalForageFilesystem(store, new WebPresetsFileSystem(platform_id));
+ var basefs : ProjectFilesystem = new WebPresetsFileSystem(platform_id);
+ //basefs = new FirebaseProjectFilesystem("TEST", "TEST");
+ var filesystem = new OverlayFilesystem(
+ basefs,
+ new LocalForageFilesystem(store));
current_project = new CodeProject(newWorker(), platform_id, platform, filesystem);
projectWindows = new ProjectWindows($("#workspace")[0] as HTMLElement, current_project);
if (isElectronWorkspace) {
diff --git a/test/cli/testgithub.js b/test/cli/testgithub.js
index 72e2d4fe..c2c07332 100644
--- a/test/cli/testgithub.js
+++ b/test/cli/testgithub.js
@@ -18,7 +18,7 @@ function newGH(store, platform_id) {
localStorage.clear();
// pzpinfo user
var pid = platform_id||test_platform_id;
- var fs = new prj.LocalForageFilesystem(store, new prj.NullFilesystem());
+ var fs = new prj.LocalForageFilesystem(store);
var project = new prj.CodeProject({}, pid, null, fs);
project.mainPath = 'local/main.asm';
project.updateFileInStore(project.mainPath, '\torg $0 ; test\n');
diff --git a/test/cli/teststore.js b/test/cli/teststore.js
index 5234a64a..bee7b74e 100644
--- a/test/cli/teststore.js
+++ b/test/cli/teststore.js
@@ -13,7 +13,9 @@ var prj = require("gen/ide/project.js");
var test_platform_id = "_TEST";
function newFilesystem(store, platform_id) {
- return new prj.LocalForageFilesystem(store, new prj.NullFilesystem());
+ return new prj.OverlayFilesystem(
+ new prj.NullFilesystem(),
+ new prj.LocalForageFilesystem(store));
}
describe('Store', function () {