Skip to content

Commit

Permalink
add test simx
Browse files Browse the repository at this point in the history
  • Loading branch information
eanders-ms committed Sep 28, 2024
1 parent 3205319 commit 4a45400
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ declare namespace pxt {
// don't recycle the iframe between runs
permanent?: boolean;
}>;
// This is for testing new simulator extensions before adding them to targetconfig.json.
// DO NOT SHIP SIMULATOR EXTENSIONS HERE. Add them to targetconfig.json/approvedRepoLib instead.
testSimulatorExtensions?: pxt.Map<SimulatorExtensionConfig>;
}

interface TargetCompileService {
Expand Down
4 changes: 3 additions & 1 deletion pxtsim/simdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ namespace pxsim {
simx.url = new URL(simx.index, simx.devUrl).toString();
} else {
const simUrl = this.getSimUrl();
// Ensure we preserve upload target path (/app/<sha>---simulator)
const simPath = simUrl.pathname.replace(/---?.*/, "");
// Construct the path. The "-" element delineates the extension key from the resource name.
const simxPath = ["simx", key, "-", simx.index].join("/");
const simxPath = [simPath, "simx", key, "-", simx.index].join("/");
simx.url = new URL(simxPath, simUrl.origin).toString();
}

Expand Down
10 changes: 10 additions & 0 deletions webapp/src/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export async function initAsync(root: HTMLElement, cfg: SimulatorConfig) {
permanent: true, // default to true
...e.v
});
// Add in test simulator extensions
Object.entries(pxt.appTarget?.simulator?.testSimulatorExtensions || {})
.map(([k, v]) => ({ k: k, v: v as pxt.SimulatorExtensionConfig }))
.filter(e => !!e.v)
.forEach(e => simulatorExtensions[e.k] = {
index: "index.html", // default to index.html
aspectRatio: pxt.appTarget.simulator.aspectRatio || 1.22, // fallback to 1.22
permanent: true, // default to true
...e.v
});

let options: pxsim.SimulatorDriverOptions = {
restart: () => cfg.restartSimulator(),
Expand Down

0 comments on commit 4a45400

Please sign in to comment.