Compare commits

...

5 Commits

Author SHA1 Message Date
bb980d2cad Bump version to 3.1.5 2024-02-09 18:07:40 +07:00
102c796c69 Set USE_DEV_TOUCH_LAYOUT to "false" 2024-02-09 18:07:04 +07:00
2f7218d165 Update translations 2024-02-09 18:04:06 +07:00
b07318e07f Add BX_EXPOSED.test_touch_control() for layout testing 2024-02-09 17:57:25 +07:00
70a8fc9866 Test new structure of custom touch layout 2024-02-09 17:46:05 +07:00
2 changed files with 53 additions and 34 deletions

View File

@ -1,5 +1,5 @@
// ==UserScript==
// @name Better xCloud
// @namespace https://github.com/redphx
// @version 3.1.4
// @version 3.1.5
// ==/UserScript==

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Better xCloud
// @namespace https://github.com/redphx
// @version 3.1.4
// @version 3.1.5
// @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx
// @license MIT
@ -14,7 +14,7 @@
// ==/UserScript==
'use strict';
const SCRIPT_VERSION = '3.1.4';
const SCRIPT_VERSION = '3.1.5';
const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
const ENABLE_XCLOUD_LOGGER = false;
@ -1335,6 +1335,7 @@ const Translations = {
"tr-TR": "Bu özellik çevrimiçi oyunlarda sizi hile yapıyormuşsunuz gibi gösterebilir",
"uk-UA": "Використання цієї функції під час гри онлайн може розглядатися як шахрайство",
"vi-VN": "Sử dụng chức năng này khi chơi trực tuyến có thể bị xem là gian lận",
"zh-CN": "游玩在线游戏时,使用此功能可能被视为作弊。",
},
"mouse-and-keyboard": {
"de-DE": "Maus & Tastatur",
@ -2479,8 +2480,10 @@ const Translations = {
"ja-JP": "タッチコントロールレイアウト",
"pt-BR": "Layout do controle por toque",
"ru-RU": "Расположение сенсорных кнопок",
"tr-TR": "Dokunmatik kontrol şeması",
"uk-UA": "Розташування сенсорного керування",
"vi-VN": "Bố cục điều khiển cảm ứng",
"zh-CN": "触摸控制布局",
},
"touch-controller": {
"de-DE": "Touch-Controller",
@ -3498,53 +3501,51 @@ class TouchController {
}, 10);
}
static getCustomLayouts(xboxTitleId) {
const dispatchLayouts = data => {
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
data: data,
});
};
static #dispatchLayouts(data) {
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
data: data,
});
};
static getCustomLayouts(xboxTitleId, retries) {
xboxTitleId = '' + xboxTitleId;
if (xboxTitleId in TouchController.#customLayouts) {
dispatchLayouts(TouchController.#customLayouts[xboxTitleId]);
TouchController.#dispatchLayouts(TouchController.#customLayouts[xboxTitleId]);
return;
}
let url = 'https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/touch-layouts/';
if (USE_DEV_TOUCH_LAYOUT) {
url += `dev/${xboxTitleId}.json`;
} else {
url += `${xboxTitleId}.json`;
retries = retries || 1;
if (retries > 2) {
TouchController.#customLayouts[xboxTitleId] = null;
// Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => TouchController.#dispatchLayouts(null), 1000);
return;
}
const baseUrl = `https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/touch-layouts${USE_DEV_TOUCH_LAYOUT ? '/dev' : ''}`;
const url = `${baseUrl}/${xboxTitleId}.json`;
// Get layout info
NATIVE_FETCH(url)
.then(resp => resp.json())
.then(json => {
// Normalize data
const schema_version = json.schema_version || 1;
let layout;
try {
if (schema_version === 1) {
json.layouts = {
default: {
name: 'Default',
content: json.layout,
},
};
json.default_layout = 'default';
delete json.layout;
}
} catch (e) {}
const layouts = {};
json.layouts.forEach(async file => {
const layoutUrl = `${baseUrl}/layouts/${file}.json`;
const json = await (await NATIVE_FETCH(layoutUrl)).json();
Object.assign(layouts, json.layouts);
});
json.layouts = layouts;
TouchController.#customLayouts[xboxTitleId] = json;
// Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => dispatchLayouts(json), 1000);
setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
})
.catch(() => {
TouchController.#customLayouts[xboxTitleId] = null;
// Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => dispatchLayouts(null), 1000);
// Retry
TouchController.getCustomLayouts(xboxTitleId, retries + 1);
});
}
@ -3588,6 +3589,24 @@ class TouchController {
}
static setup() {
// Function for testing touch control
window.BX_EXPOSED.test_touch_control = content => {
const { touch_layout_manager } = window.BX_EXPOSED;
touch_layout_manager && touch_layout_manager.changeLayoutForScope({
type: 'showLayout',
scope: '' + GAME_XBOX_TITLE_ID,
subscope: 'base',
layout: {
id: 'System.Standard',
displayName: 'Custom',
layoutFile: {
content: content,
},
},
});
};
const $fragment = document.createDocumentFragment();
const $style = document.createElement('style');
$fragment.appendChild($style);