Show local co-op icon in game card

This commit is contained in:
redphx
2025-01-02 21:39:27 +07:00
parent 9862f794cf
commit 90f89a0244
14 changed files with 287 additions and 14 deletions

View File

@@ -31,6 +31,12 @@ type ScriptEvents = {
data: any;
};
};
'list.localCoOp.updated': {
data: {
data: any;
};
};
};
type StreamEvents = {

View File

@@ -13,6 +13,7 @@ import { NativeMkbMode, TouchControllerMode } from "@/enums/pref-values";
import { Patcher, type PatchPage } from "@/modules/patcher/patcher";
import { BxEventBus } from "./bx-event-bus";
import { FeatureGates } from "./feature-gates";
import { LocalCoOpManager } from "./local-co-op-manager";
export enum SupportedInputType {
CONTROLLER = 'Controller',
@@ -230,4 +231,25 @@ export const BxExposed = {
BxLogger.info('beforePageLoad', page);
Patcher.patchPage(page);
} : () => {},
localCoOpManager: LocalCoOpManager.getInstance(),
reactCreateElement: function(...args: any[]) {},
createReactLocalCoOpIcon: isFullVersion() ? (): any => {
const reactCE = window.BX_EXPOSED.reactCreateElement;
// local-co-op.svg
return reactCE(
'svg',
{ xmlns: 'http://www.w3.org/2000/svg', width: '1em', height: '1em', viewBox: '0 0 32 32', 'fill-rule': 'evenodd', 'stroke-linecap': 'round', 'stroke-linejoin': 'round' },
reactCE(
'g',
null,
reactCE('path', { d: 'M24.272 11.165h-3.294l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564', fill: 'none', stroke: '#fff', 'stroke-width': '2' }),
reactCE('circle', { cx: '22.625', cy: '5.874', r: '.879' }),
reactCE('path', { d: 'M11.022 24.415H7.728l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564', fill: 'none', stroke: '#fff', 'stroke-width': '2' }),
reactCE('circle', { cx: '9.375', cy: '19.124', r: '.879' })
),
);
} : () => {},
};

View File

@@ -83,4 +83,24 @@ export class GhPagesUtils {
const customList = JSON.parse(window.localStorage.getItem(key) || '[]');
return customList;
}
static getLocalCoOpList() {
const supportedSchema = 1;
const key = StorageKey.LIST_LOCAL_CO_OP;
NATIVE_FETCH(GhPagesUtils.getUrl('local-co-op/ids.json'))
.then(response => response.json())
.then(json => {
if (json.$schemaVersion === supportedSchema) {
window.localStorage.setItem(key, JSON.stringify(json));
BxEventBus.Script.emit('list.localCoOp.updated', { data: json });
} else {
window.localStorage.removeItem(key);
BxEventBus.Script.emit('list.localCoOp.updated', { data: { data: {} } });
}
});
const customList = JSON.parse(window.localStorage.getItem(key) || '[]');
return customList;
}
}

View File

@@ -0,0 +1,21 @@
import { BxEventBus } from "./bx-event-bus";
import { GhPagesUtils } from "./gh-pages";
export class LocalCoOpManager {
private static instance: LocalCoOpManager;
public static getInstance = () => LocalCoOpManager.instance ?? (LocalCoOpManager.instance = new LocalCoOpManager());
private supportedIds: string[] = [];
constructor() {
BxEventBus.Script.once('list.localCoOp.updated', e => {
this.supportedIds = Object.keys(e.data.data);
console.log('supportedIds', this.supportedIds);
});
GhPagesUtils.getLocalCoOpList();
}
isSupported(productId: string) {
return this.supportedIds.includes(productId);
}
}

View File

@@ -436,7 +436,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
if (!setting.unsupported) {
(setting as any).multipleOptions = GhPagesUtils.getNativeMkbCustomList(true);
BxEventBus.Script.on('list.forcedNativeMkb.updated', payload => {
BxEventBus.Script.once('list.forcedNativeMkb.updated', payload => {
(setting as any).multipleOptions = payload.data.data;
});
}