Skip to content

Commit

Permalink
fixed events import and changing device to null (#6758)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpal81xd authored Jun 27, 2024
1 parent 4cac923 commit 9f04bae
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/iframe/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function parseConfig(script) {
return config;
}

const DEVICE_TYPES = ['webgpu', 'webgl2'];
const DEVICE_TYPES = ['webgpu', 'webgl2', 'null'];
export let deviceType = 'webgl2';

/**
Expand Down
16 changes: 10 additions & 6 deletions examples/src/app/components/DeviceSelector.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
DEVICETYPE_WEBGL2,
DEVICETYPE_NULL
} from '../constants.mjs';
import '../events.js';

const deviceTypeNames = {
[DEVICETYPE_WEBGPU]: 'WebGPU',
[DEVICETYPE_WEBGL2]: 'WebGL 2',
[DEVICETYPE_NULL]: 'Null'
};

/** @typedef {import('../events.js').DeviceEvent} DeviceEvent */

/**
* @typedef {object} Props
* @property {Function} onSelect - On select handler.
Expand Down Expand Up @@ -87,8 +88,8 @@ class DeviceSelector extends TypedComponent {
/**
* If our preferred device was e.g. WebGPU, but our active device is suddenly e.g. WebGL 2,
* then we basically infer that WebGPU wasn't supported and mark it like that.
* @param {DEVICETYPE_WEBGPU | DEVICETYPE_WEBGL2} preferredDevice - The preferred device.
* @param {DEVICETYPE_WEBGPU | DEVICETYPE_WEBGL2} activeDevice - The active device reported from
* @param {DEVICETYPE_WEBGPU | DEVICETYPE_WEBGL2 | DEVICETYPE_NULL} preferredDevice - The preferred device.
* @param {DEVICETYPE_WEBGPU | DEVICETYPE_WEBGL2 | DEVICETYPE_NULL} activeDevice - The active device reported from
* the example iframe.
*/
setDisabledOptions(preferredDevice = DEVICETYPE_WEBGPU, activeDevice) {
Expand All @@ -105,8 +106,9 @@ class DeviceSelector extends TypedComponent {
};
this.mergeState({ fallbackOrder, disabledOptions, activeDevice });
} else {
const fallbackOrder = null;
const disabledOptions = null;
this.mergeState({ disabledOptions, activeDevice });
this.mergeState({ fallbackOrder, disabledOptions, activeDevice });
}
}

Expand All @@ -123,7 +125,8 @@ class DeviceSelector extends TypedComponent {
}

/**
* @param {string} value - Is graphics device active
* @param {DEVICETYPE_WEBGPU | DEVICETYPE_WEBGL2 | DEVICETYPE_NULL} value - Is graphics device
* active
*/
onSetActiveGraphicsDevice(value) {
if (!this.preferredGraphicsDevice) {
Expand All @@ -134,7 +137,8 @@ class DeviceSelector extends TypedComponent {
}

/**
* @param {string} value - The newly picked graphics device.
* @param {DEVICETYPE_WEBGPU | DEVICETYPE_WEBGL2 | DEVICETYPE_NULL} value - The newly picked
* graphics device.
*/
onSetPreferredGraphicsDevice(value) {
this.mergeState({ disabledOptions: null, activeDevice: value });
Expand Down
4 changes: 3 additions & 1 deletion examples/src/app/components/Example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { iframePath } from '../paths.mjs';
import { jsx, fragment } from '../jsx.mjs';
import { iframe } from '../iframe.mjs';
import { getOrientation } from '../utils.mjs';
import '../events.js';

/** @typedef {import('../events.js').StateEvent} StateEvent */
/** @typedef {import('../events.js').LoadingEvent} LoadingEvent */

/**
* @template {Record<string, string>} [FILES=Record<string, string>]
Expand Down
2 changes: 1 addition & 1 deletion examples/src/app/components/code-editor/CodeEditorBase.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { playcanvasTheme } from '../../monaco/theme.mjs';
import { jsRules } from '../../monaco/tokenizer-rules.mjs';
import * as languages from '../../monaco/languages/index.mjs';

import '../../events.js';
/** @typedef {import('../../events.js').StateEvent} StateEvent */

loader.config({ paths: { vs: './modules/monaco-editor/min/vs' } });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { jsx } from '../../jsx.mjs';
import { iframe } from '../../iframe.mjs';
import { removeRedundantSpaces } from '../../strings.mjs';

import '../../events.js';
/** @typedef {import('../../events.js').StateEvent} StateEvent */

loader.config({ paths: { vs: './modules/monaco-editor/min/vs' } });

Expand Down
2 changes: 0 additions & 2 deletions examples/src/app/components/code-editor/CodeEditorMobile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { CodeEditorBase } from './CodeEditorBase.mjs';

import { jsx } from '../../jsx.mjs';

import '../../events.js';

// eslint-disable-next-line jsdoc/require-property
/**
* @typedef {Record<string, any>} Props
Expand Down
6 changes: 5 additions & 1 deletion examples/src/app/events.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/** @typedef {import('./constants.mjs').DEVICETYPE_WEBGPU} DEVICETYPE_WEBGPU */
/** @typedef {import('./constants.mjs').DEVICETYPE_WEBGL2} DEVICETYPE_WEBGL2 */
/** @typedef {import('./constants.mjs').DEVICETYPE_NULL} DEVICETYPE_NULL */

/**
* @typedef {object} LoadingEventDetail
* @property {boolean} showDeviceSelector - Show device selector
Expand All @@ -16,7 +20,7 @@

/**
* @typedef {object} DeviceEventDetail
* @property {string} deviceType - The device type.
* @property {DEVICETYPE_WEBGPU | DEVICETYPE_WEBGL2 | DEVICETYPE_NULL} deviceType - The device type.
*
* @typedef {CustomEvent<DeviceEventDetail>} DeviceEvent
*/
Expand Down

0 comments on commit 9f04bae

Please sign in to comment.