Skip to content

Commit 68bd3b6

Browse files
committed
fix: normalize url when playing scene inline in editor
1 parent 4ed7e9c commit 68bd3b6

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

editor/src/project/run.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export async function startProjectDevProcess(editor: Editor) {
2525

2626
isBusy = true;
2727

28+
editor.layout.selectTab("console");
29+
2830
const log = await editor.layout.console.progress("Starting the game / application...");
2931

3032
await checkPackageManagerAvailable(editor.state.packageManager!);

editor/src/tools/scene/play/override.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ const savedHtmlElementListeners: {
5050
listener: EventListenerOrEventListenerObject;
5151
}[] = [];
5252

53+
function normalizeUrl(url: string) {
54+
if (url.startsWith("scene/")) {
55+
url = url.substring("scene/".length);
56+
}
57+
58+
if (url.startsWith("/scene/")) {
59+
url = url.substring("/scene/".length);
60+
}
61+
62+
return url;
63+
}
64+
5365
/**
5466
* To play scene inline in the editor, we need to override some methods.
5567
* This function restores all the orignal methods for all object that have been overridden.
@@ -135,6 +147,7 @@ export function applyOverrides(editor: Editor) {
135147
// Fetch
136148
window.fetch = async (input: string | URL | Request, init?: RequestInit) => {
137149
if (!isAbsolute(input.toString())) {
150+
input = normalizeUrl(input.toString());
138151
input = join(publicDir, input.toString());
139152
}
140153

@@ -171,6 +184,7 @@ export function applyOverrides(editor: Editor) {
171184
// WebRequest
172185
WebRequest.prototype.open = function (method: string, url: string) {
173186
if (url && !isAbsolute(url)) {
187+
url = normalizeUrl(url);
174188
url = join(publicDir, url);
175189
}
176190

@@ -184,6 +198,11 @@ export function applyOverrides(editor: Editor) {
184198

185199
// Engine
186200
Engine.prototype.createTexture = (url: string, ...args: any[]) => {
201+
if (!isAbsolute(url) && !url.startsWith("data:")) {
202+
url = normalizeUrl(url);
203+
url = join(publicScene, url);
204+
}
205+
187206
const temporaryTextureIndex = url?.indexOf(".bjseditor") ?? -1;
188207

189208
if (temporaryTextureIndex !== -1) {

0 commit comments

Comments
 (0)