新排行榜加周竞赛功能升级

This commit is contained in:
keke
2026-10-28 11:09:00 +08:00
parent e6e359d9d3
commit 5e509ca4a5
341 changed files with 59686 additions and 21 deletions
@@ -10,6 +10,12 @@ export default class ServerEnvironment {
static current(): ServerTarget {
if (this.active !== null) return this.active;
// Browser previews default to test and remember explicit choices across reloads.
if (typeof wx === "undefined" && cc.sys.isBrowser) {
this.switchAllowed = true;
this.active = this.readChoice() || "test";
return this.active;
}
try {
const version = typeof wx !== "undefined" && wx.getAccountInfoSync?.().miniProgram?.envVersion;
this.switchAllowed = version === "develop" || version === "trial";
@@ -24,7 +30,7 @@ export default class ServerEnvironment {
}
static next(): ServerTarget {
return this.canSwitch() ? this.readChoice() || "test" : "production";
return this.canSwitch() ? this.readChoice() || "test" : this.current();
}
static saveNext(target: ServerTarget): void {
@@ -45,8 +51,8 @@ export default class ServerEnvironment {
}
static storageKey(key: string): string {
// Device preferences and the existing standalone web preview retain their keys.
if (key === "music" || typeof wx === "undefined") return key;
// Share device preferences; isolate gameplay storage on every platform.
if (key === "music") return key;
// Unscoped legacy data remains on disk as a backup, never uploaded to an unknown server.
return "matchmaster:server:v1:" + this.current() + ":" + key;
}
+25 -7
View File
@@ -11,13 +11,31 @@ export default class ServerSwitch {
static inProgress = false;
private static confirming = false;
private static isBrowser(): boolean { return typeof wx === "undefined" && cc.sys.isBrowser; }
private static modal(options: any): void {
if (!this.isBrowser()) { wx.showModal(options); return; }
try {
const confirm = options.showCancel === false
? (window.alert(options.title + "\n" + options.content), true)
: window.confirm(options.title + "\n" + options.content);
if (options.success) options.success({ confirm });
} finally { if (options.complete) options.complete(); }
}
private static showLoading(title: string): void {
if (!this.isBrowser()) wx.showLoading({ title, mask: true });
}
private static restart(failed: () => void): void {
if (!this.isBrowser()) { MiniGameSdk.API.reboot(undefined, failed); return; }
try { window.location.reload(); } catch (_) { failed(); }
}
static choose(target: ServerTarget, refresh: () => void): void {
if (!ServerEnvironment.canSwitch() || this.inProgress || this.confirming || ClientUpdate.blocked
|| cc.director.getScene()?.name !== "HomeScene") return;
if (target === ServerEnvironment.current() && target === ServerEnvironment.next()) return;
const cancelPending = target === ServerEnvironment.current();
this.confirming = true;
wx.showModal({
this.modal({
title: cancelPending ? "取消服务器切换" : "切换服务器",
content: cancelPending ? "取消待生效的切换,继续使用当前服务器?"
: `将切换到${target === "test" ? "测试服" : "正式服"}并重启游戏,是否继续?`,
@@ -26,7 +44,7 @@ export default class ServerSwitch {
if (!result.confirm) return;
if (cancelPending) {
try { ServerEnvironment.saveNext(target); refresh(); }
catch (_) { MiniGameSdk.API.showToast("服务器选择保存失败,请重试"); }
catch (_) { this.modal({ title: "保存失败", content: "服务器选择保存失败,请重试", showCancel: false }); }
} else {
this.perform(target, refresh);
}
@@ -43,7 +61,7 @@ export default class ServerSwitch {
let restartTimer: any = null;
scene.pauseSystemEvents(true);
try {
wx.showLoading({ title: "正在保存进度", mask: true });
this.showLoading("正在保存进度");
DailyTaskProgressTracker.stopOnline();
DailyTaskProgressTracker.flushNow();
await Utils.prepareServerSwitch();
@@ -51,25 +69,25 @@ export default class ServerSwitch {
ServerEnvironment.saveNext(target);
saved = true;
refresh();
wx.showLoading({ title: "正在重启", mask: true });
this.showLoading("正在重启");
// A real restart destroys this process. If it stays alive, keep the old session usable.
await new Promise<void>((_, reject) => {
const failed = () => reject(new Error("自动重启失败"));
restartTimer = setTimeout(failed, 8000);
MiniGameSdk.API.reboot(undefined, failed);
this.restart(failed);
});
} catch (error) {
clearTimeout(restartTimer);
Utils.cancelServerSwitch();
this.inProgress = false;
if (ClientUpdate.blocked) { ClientUpdate.onShow(); return; }
wx.hideLoading();
if (!this.isBrowser()) wx.hideLoading();
if (cc.isValid(scene)) scene.resumeSystemEvents(true);
cc.game.resume();
cc.audioEngine.resumeAll();
DailyTaskProgressTracker.startOnline();
refresh();
wx.showModal({
this.modal({
title: saved ? "请重启游戏" : "暂未切换",
content: saved ? "选择已保存,完整重启后生效。当前仍连接原服务器,请重试重启或退出后重新进入。"
: (error?.message || "存档保存失败,请稍后重试"),
+6 -1
View File
@@ -1,3 +1,4 @@
import WeeklyCache from '../../../ranking_v2_entry/WeeklyCache';
import { MiniGameSdk } from "../../Sdk/MiniGameSdk";
import { normalizePass, mergePassInfo, legacyPassInfo, legacyExperience, passTier, PASS_PERIOD } from '../Config/BattlePassModel';
import { settlementRewards, settlementClaimFlags } from '../Config/BattlePassSettlementModel';
@@ -104,7 +105,7 @@ export default class Utils {
const save = !entryRequest && (action === "save" || action === "save_reward");
// These no-action endpoints were checked against their server implementations.
const readOnly = action === "read" || action === "info" || [
"getRank", "getSRank", "getAddressRank", "getAddressRankOther", "getAddressRankSelf",
"getRank", "getSRank", "getWeeklyCompetitionRank", "getAddressRank", "getAddressRankOther", "getAddressRankSelf",
"getUserInfoByID", "getShareLv", "getHeadInfo", "getFilm", "activityConfig/list",
].indexOf(path) >= 0;
const mayWrite = !entryRequest && !readOnly;
@@ -918,7 +919,9 @@ export default class Utils {
const saveLevel = goldMiner
? (body, callback) => Utils.POSTJSON('userLevel', { ...body, isWuXian: goldMiner.mode === 'endless' ? 'true' : undefined, goldMiner }, callback)
: (body, callback) => Utils.POST('userLevel', body, callback);
const weeklyScope = WeeklyCache.scope(Utils.serverUrl(), cc.fx.GameConfig.GM_INFO.uid);
saveLevel(setData, res => {
if (res.code === 1) WeeklyCache.invalidate(weeklyScope);
const activityResult = res && res.data && res.data.goldMiner;
console.log('[GoldMiner通关] userLevel 返回', JSON.stringify({
eventId: goldMiner && goldMiner.eventId,
@@ -2089,7 +2092,9 @@ export default class Utils {
endLevelNum: parseInt(data2),
}
console.log("设置无尽关卡等级:", setData);
const weeklyScope = WeeklyCache.scope(Utils.serverUrl(), cc.fx.GameConfig.GM_INFO.uid);
Utils.POST("setUserLevel", setData, res => {
if (res.code === 1) WeeklyCache.invalidate(weeklyScope);
if (res.code === 1) {
let endLevelNum = res.data.endLevelNum;
if (parseInt(data2) < Number(endLevelNum))
+6
View File
@@ -5,6 +5,7 @@
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
import RankingEntry from "../ranking_v2_entry/RankingEntry";
import Utils from "./module/Pay/Utils";
import LoadingCatAnimation from "./LoadingCatAnimation";
import NumberToImage from "./NumberToImage";
@@ -43,6 +44,11 @@ export default class ranking extends cc.Component {
init(event?: cc.Event, customEventData?: string) {
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
if (RankingEntry.enabled) {
this.node.active = false;
RankingEntry.open(this.node.parent, customEventData || "btnRank", customEventData !== undefined ? "click" : "auto");
return;
}
this.node.getChildByName("bg").active = false;
this.node.getChildByName("bg2").active = true;
this.node.getChildByName("word_rank").getChildByName("selfNode").getChildByName("bg").active = false;