MCPcopy Index your code
hub / github.com/EmulatorJS/EmulatorJS / buildButtonOptions

Method buildButtonOptions

data/src/emulator.js:1330–1404  ·  view source on GitHub ↗
(buttonUserOpts)

Source from the content-addressed store, hash-verified

1328 volume: "volumeSlider"
1329 };
1330 buildButtonOptions(buttonUserOpts) {
1331 let mergedButtonOptions = this.defaultButtonOptions;
1332
1333 // merge buttonUserOpts with mergedButtonOptions
1334 if (buttonUserOpts) {
1335 for (const key in buttonUserOpts) {
1336 let searchKey = key;
1337 // If the key is an alias, find the actual key in the default buttons
1338 if (this.defaultButtonAliases[key]) {
1339 // Use the alias to find the actual key
1340 // and update the searchKey to the actual key
1341 searchKey = this.defaultButtonAliases[key];
1342 }
1343
1344 // prevent the contextMenu button from being overridden
1345 if (searchKey === "contextMenu")
1346 continue;
1347
1348 // Check if the button exists in the default buttons, and update its properties
1349 if (!mergedButtonOptions[searchKey]) {
1350 console.warn(`Button "${searchKey}" is not a valid button.`);
1351 continue;
1352 }
1353
1354 // if the value is a boolean, set the visible property to the value
1355 if (typeof buttonUserOpts[searchKey] === "boolean") {
1356 mergedButtonOptions[searchKey].visible = buttonUserOpts[searchKey];
1357 } else if (typeof buttonUserOpts[searchKey] === "object") {
1358 // If the value is an object, merge it with the default button properties
1359
1360 if (this.defaultButtonOptions[searchKey]) {
1361 // copy properties from the button definition if they aren't null
1362 for (const prop in buttonUserOpts[searchKey]) {
1363 if (buttonUserOpts[searchKey][prop] !== null) {
1364 mergedButtonOptions[searchKey][prop] = buttonUserOpts[searchKey][prop];
1365 }
1366 }
1367 } else {
1368 // button was not in the default buttons list and is therefore a custom button
1369 // verify that the value has a displayName, icon, and callback property
1370 if (buttonUserOpts[searchKey].displayName && buttonUserOpts[searchKey].icon && buttonUserOpts[searchKey].callback) {
1371 mergedButtonOptions[searchKey] = {
1372 visible: true,
1373 displayName: buttonUserOpts[searchKey].displayName,
1374 icon: buttonUserOpts[searchKey].icon,
1375 callback: buttonUserOpts[searchKey].callback,
1376 custom: true
1377 };
1378 } else {
1379 console.warn(`Custom button "${searchKey}" is missing required properties`);
1380 }
1381 }
1382 }
1383
1384 // behaviour exceptions
1385 switch (searchKey) {
1386 case "playPause":
1387 mergedButtonOptions.play.visible = mergedButtonOptions.playPause.visible;

Callers 1

constructorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected