mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-17 05:37:46 +00:00
perf: 减少导入,提升性能
This commit is contained in:
parent
d6f6365146
commit
dcaa31ac1d
2 changed files with 22 additions and 48 deletions
|
|
@ -1,12 +1,25 @@
|
|||
import _ from 'lodash';
|
||||
import settings from '../lib/settings.js';
|
||||
import { rulePrefix } from '../lib/common.js';
|
||||
import { Deadly } from '../model/deadly.js';
|
||||
import { ZZZChallenge } from '../model/abyss.js';
|
||||
import { ZZZPlugin } from '../lib/plugin.js';
|
||||
|
||||
const USER_CONFIGS_KEY = 'ZZZ:REMIND:USER_CONFIGS';
|
||||
|
||||
// 计算到指定等级为止的S评级数量
|
||||
function getSRankCountUpTo(allFloorDetail, maxLevel) {
|
||||
const sSet = new Set(
|
||||
allFloorDetail.filter(f => f.rating === 'S').map(f => f.layer_index)
|
||||
);
|
||||
const minLevel = Math.min(...allFloorDetail.map(f => f.layer_index));
|
||||
let sRankCount = 0;
|
||||
for (let level = 1; level <= maxLevel; level++) {
|
||||
if (sSet.has(level) || level < minLevel) {
|
||||
sRankCount++;
|
||||
}
|
||||
}
|
||||
return sRankCount;
|
||||
}
|
||||
|
||||
export class Remind extends ZZZPlugin {
|
||||
constructor() {
|
||||
super({
|
||||
|
|
@ -241,11 +254,10 @@ export class Remind extends ZZZPlugin {
|
|||
if (!abyssRawData || !abyssRawData.has_data) {
|
||||
messages.push('式舆防卫战S评级: 0/7');
|
||||
} else {
|
||||
const abyssData = new ZZZChallenge(abyssRawData);
|
||||
const userThreshold = userConfig.abyssCheckLevel || 7;
|
||||
if (showAll || !abyssData.areAllSUpTo(userThreshold)) {
|
||||
const sCount = abyssData.getSRankCountUpTo(7);
|
||||
const status = abyssData.areAllSUpTo(userThreshold) ? ' ✓' : '';
|
||||
const sCount = getSRankCountUpTo(abyssRawData.all_floor_detail, 7);
|
||||
const status = sCount >= userThreshold ? ' ✓' : '';
|
||||
if (showAll || sCount < userThreshold) {
|
||||
messages.push(`式舆防卫战S评级: ${sCount}/7${status}`);
|
||||
}
|
||||
}
|
||||
|
|
@ -260,10 +272,10 @@ export class Remind extends ZZZPlugin {
|
|||
if (!deadlyRawData || !deadlyRawData.has_data) {
|
||||
messages.push('危局强袭战星星: 0/9');
|
||||
} else {
|
||||
const deadlyData = new Deadly(deadlyRawData);
|
||||
if (showAll || deadlyData.total_star < userConfig.deadlyStars) {
|
||||
const status = deadlyData.total_star >= userConfig.deadlyStars ? ' ✓' : '';
|
||||
messages.push(`危局强袭战星星: ${deadlyData.total_star}/9${status}`);
|
||||
const totalStar = deadlyRawData.total_star || 0;
|
||||
if (showAll || totalStar < userConfig.deadlyStars) {
|
||||
const status = totalStar >= userConfig.deadlyStars ? ' ✓' : '';
|
||||
messages.push(`危局强袭战星星: ${totalStar}/9${status}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -369,42 +369,4 @@ export class ZZZChallenge {
|
|||
'0'
|
||||
)}`;
|
||||
}
|
||||
getSRankCountUpTo(maxLevel) {
|
||||
let s_rank_count = 0;
|
||||
const min_level = Math.min(
|
||||
...this.all_floor_detail.map(f => f.layer_index)
|
||||
);
|
||||
for (let level = 1; level <= maxLevel; level++) {
|
||||
const floor = this.all_floor_detail.find(f => f.layer_index === level);
|
||||
if (floor) {
|
||||
if (floor.rating === 'S') {
|
||||
s_rank_count++;
|
||||
}
|
||||
} else {
|
||||
if (level < min_level) {
|
||||
s_rank_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s_rank_count;
|
||||
}
|
||||
|
||||
areAllSUpTo(maxLevel) {
|
||||
const min_level = Math.min(
|
||||
...this.all_floor_detail.map(f => f.layer_index)
|
||||
);
|
||||
for (let level = 1; level <= maxLevel; level++) {
|
||||
const floor = this.all_floor_detail.find(f => f.layer_index === level);
|
||||
if (floor) {
|
||||
if (floor.rating !== 'S') {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (level >= min_level) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue