From 31c4b9cf4b17150735aad8697bb4be5278f7da72 Mon Sep 17 00:00:00 2001 From: Ck Algos Date: Fri, 14 Oct 2022 09:55:06 +0200 Subject: [PATCH] fix sbcs --- app/function-overrides/sbchome-override.js | 105 +++++++++++++-------- app/function-overrides/sbcview-override.js | 14 +-- app/utils/commonUtil.js | 7 ++ tampermonkey-header.js | 2 +- 4 files changed, 79 insertions(+), 49 deletions(-) diff --git a/app/function-overrides/sbchome-override.js b/app/function-overrides/sbchome-override.js index 8cd4272..eb84adc 100644 --- a/app/function-overrides/sbchome-override.js +++ b/app/function-overrides/sbchome-override.js @@ -1,14 +1,29 @@ +import { fetchSolvableSbcs } from "../services/datasource/marketAlert"; import { getSquadPlayerIds, getSquadPlayerLookup } from "../services/club"; import { getAllChallanges } from "../services/datasource/futbin"; -import { fetchSolvableSbcs } from "../services/datasource/marketAlert"; import { t } from "../services/translate"; -import { downloadCsv, hideLoader, showLoader } from "../utils/commonUtil"; -import { getCardQuality } from "../utils/futItemUtil"; +import { + getCurrentViewController, + hideLoader, + showLoader, +} from "../utils/commonUtil"; import { sendUINotification } from "../utils/notificationUtil"; import { showPopUp } from "./popup-override"; export const sbcHomeOverride = () => { const populateTiles = UTSBCHubView.prototype.populateTiles; + const challengeRender = UTSBCChallengeTileView.prototype.render; + + UTSBCChallengeTileView.prototype.render = function (...args) { + const result = challengeRender.call(this, ...args); + const challange = this._data; + if (challange.fromSolve) { + this.__subTitle.textContent = `Av. Players (${ + challange.playersAvailable + }) - ${challange.percentageCompleted.toFixed(2)}% completed`; + } + return result; + }; UTSBCHubView.prototype.populateTiles = function (set, challange) { const result = populateTiles.call(this, set, challange); @@ -64,7 +79,7 @@ export const sbcHomeOverride = () => { continue; } let requiredPlayers = 0; - const playersNames = []; + let playersAvailable = 0; for (const playerId of sbc.players) { if (!playerId) { continue; @@ -74,53 +89,67 @@ export const sbcHomeOverride = () => { if (!playerDetail) { continue; } - playersNames.push( - `${playerDetail._staticData.name} (${ - playerDetail.rating - } ${getCardQuality(playerDetail)})` - ); + playersAvailable++; } - const percentageCompleted = ( - (playersNames.length / requiredPlayers) * - 100 - ).toFixed(2); + const percentageCompleted = (playersAvailable / requiredPlayers) * 100; sbcResult.push({ + id: sbc._id, sbcName, requiredPlayers, percentageCompleted, - playersNames, + playersAvailable, }); } + const currentNavigationController = getCurrentViewController() + .getCurrentController() + .getNavigationController(); - downloadSolutionsAsSbc(sbcResult); + const challengesViewController = new UTSBCChallengesViewController(); + challengesViewController.initWithSBCSet( + generateSbcSet( + sbcResult.sort( + (a, b) => b.percentageCompleted - a.percentageCompleted + ) + ) + ), + currentNavigationController.pushViewController( + challengesViewController, + true + ); } catch (err) { sendUINotification(t("errSolvableSbcs"), UINotificationType.NEGATIVE); } hideLoader(); }; - const downloadSolutionsAsSbc = (sbcResult) => { - const club = services.User.getUser().getSelectedPersona().getCurrentClub(); - - const headers = - "Challenge,Players Required, Players Available, Percentage Completed, Player1, Player2, Player3, Player4, Player5, Player6, Player7, Player8, Player9, Player10, PLayer11"; - let csvContent = ""; - csvContent += headers + "\r\n"; - for (const { - sbcName, - percentageCompleted, - playersNames, - requiredPlayers, - } of sbcResult.sort( - (a, b) => b.percentageCompleted - a.percentageCompleted - )) { - let rowRecord = sbcName + ","; - rowRecord += requiredPlayers + ","; - rowRecord += playersNames.length + ","; - rowRecord += percentageCompleted + ","; - rowRecord += playersNames.join(","); - csvContent += rowRecord + "\r\n"; - } - downloadCsv(csvContent, `${club.name}_Sbc_Solutions`); + const generateSbcSet = (sbcResult) => { + return { + id: -1, + name: "Sbcs", + challengesCount: 1, + challengesCompletedCount: 1, + endTime: 1666112400, + challenges: new EAHashTable(), + awards: [], + notExpirable: true, + repeatabilityMode: SBCRepeatabilityMode.UNLIMITED, + getRepeatsRemaining: () => 0, + getRefreshTimeRemaining: () => 0, + getTimeRemaining: () => 0, + getChallenges: () => { + return sbcResult.map( + ({ id, sbcName, playersAvailable, percentageCompleted }) => ({ + id, + name: `${sbcName}`, + playersAvailable, + percentageCompleted, + fromSolve: true, + isCompleted: () => true, + isInProgress: () => false, + hasNotStarted: () => false, + }) + ); + }, + }; }; }; diff --git a/app/function-overrides/sbcview-override.js b/app/function-overrides/sbcview-override.js index 8376b99..1c76067 100644 --- a/app/function-overrides/sbcview-override.js +++ b/app/function-overrides/sbcview-override.js @@ -5,6 +5,7 @@ import { showLoader, formatDataSource, wait, + getCurrentViewController, } from "../utils/commonUtil"; import { getAllSBCSForChallenge, @@ -155,19 +156,12 @@ const fetchAndAppendMarketAlertSbcs = async (challengeId) => { const getControllerInstance = () => { if (isPhone()) { - const childViews = getAppMain() - .getRootViewController() - .getPresentedViewController() - .getCurrentViewController()._childViewControllers; + const childViews = getCurrentViewController()._childViewControllers; return childViews[childViews.length - 2]; } - return getAppMain() - .getRootViewController() - .getPresentedViewController() - .getCurrentViewController() - .getCurrentController()._leftController; + return getCurrentViewController().getCurrentController()._leftController; }; const buyPlayersPopUp = () => { @@ -359,7 +353,7 @@ const fillSquad = async (squadId) => { } positionPlayers( - futBinSquadPlayersInfo.map((currItem) => currItem.definitionId), + futBinSquadPlayersInfo.map((currItem) => currItem && currItem.definitionId), squadPlayersLookup ); }; diff --git a/app/utils/commonUtil.js b/app/utils/commonUtil.js index bb91a63..bc986bc 100644 --- a/app/utils/commonUtil.js +++ b/app/utils/commonUtil.js @@ -47,6 +47,13 @@ export const wait = async (seconds = 1) => { ); }; +export const getCurrentViewController = () => { + return getAppMain() + .getRootViewController() + .getPresentedViewController() + .getCurrentViewController(); +}; + export const getRandWaitTime = (range) => { if (range) { const [start, end] = range.split("-").map((a) => parseInt(a)); diff --git a/tampermonkey-header.js b/tampermonkey-header.js index 7353574..10e0ece 100644 --- a/tampermonkey-header.js +++ b/tampermonkey-header.js @@ -2,7 +2,7 @@ module.exports = { headers: { name: "FUT Trade Enhancer", namespace: "http://tampermonkey.net/", - version: "1.4.2", + version: "1.4.3", description: "FUT Trade Enhancer", author: "CK Algos", match: [