fix boss tank cross brick
This commit is contained in:
@@ -177,9 +177,10 @@ wx.onShow((res) => {
|
||||
|
||||
// Check for teamId from invite card (3v3 mode) or roomId from invite card (1v1 mode)
|
||||
const teamId = _extractTeamId(res && res.query);
|
||||
const teamMode = _extractTeamMode(res && res.query);
|
||||
const roomId = _extractRoomId(res && res.query);
|
||||
if (teamId) {
|
||||
_handleInviteTeamId(teamId);
|
||||
_handleInviteTeamId(teamId, teamMode);
|
||||
} else if (roomId) {
|
||||
_handleInviteRoomId(roomId);
|
||||
} else {
|
||||
@@ -187,10 +188,11 @@ wx.onShow((res) => {
|
||||
try {
|
||||
const launchOptions = wx.getLaunchOptionsSync();
|
||||
const fallbackTeamId = _extractTeamId(launchOptions && launchOptions.query);
|
||||
const fallbackTeamMode = _extractTeamMode(launchOptions && launchOptions.query);
|
||||
const fallbackRoomId = _extractRoomId(launchOptions && launchOptions.query);
|
||||
if (fallbackTeamId) {
|
||||
console.log(`[game.js] onShow query empty, but found teamId in launchOptions: ${fallbackTeamId}`);
|
||||
_handleInviteTeamId(fallbackTeamId);
|
||||
_handleInviteTeamId(fallbackTeamId, fallbackTeamMode);
|
||||
} else if (fallbackRoomId) {
|
||||
console.log(`[game.js] onShow query empty, but found roomId in launchOptions: ${fallbackRoomId}`);
|
||||
_handleInviteRoomId(fallbackRoomId);
|
||||
@@ -242,6 +244,36 @@ function _extractTeamId(query) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract mode parameter from query (e.g. mode=2v2 or mode=3v3).
|
||||
* Used to route team invites to the correct room scene.
|
||||
* @param {object|string|undefined} query
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function _extractTeamMode(query) {
|
||||
if (!query) return null;
|
||||
|
||||
if (typeof query === 'object' && query.mode) {
|
||||
return query.mode;
|
||||
}
|
||||
|
||||
if (typeof query === 'string') {
|
||||
const match = query.match(/mode=([^&]+)/);
|
||||
if (match) return match[1];
|
||||
}
|
||||
|
||||
if (typeof query === 'object') {
|
||||
const keys = Object.keys(query);
|
||||
for (const key of keys) {
|
||||
const combined = key + (query[key] ? '=' + query[key] : '');
|
||||
const match = combined.match(/mode=([^&]+)/);
|
||||
if (match) return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract roomId from query parameter (1v1 invite card).
|
||||
* Similar to _extractTeamId, but looks for roomId key.
|
||||
@@ -309,10 +341,11 @@ function _handleInviteRoomId(roomId) {
|
||||
|
||||
/**
|
||||
* Handle teamId from invite card (shared between onShow and cold launch).
|
||||
* Navigates to TeamRoomScene if possible, otherwise stores as pending.
|
||||
* Routes to Team2v2RoomScene or TeamRoomScene based on mode parameter.
|
||||
* @param {string} teamId
|
||||
* @param {string|null} mode - '2v2' or '3v3' (default: '3v3')
|
||||
*/
|
||||
function _handleInviteTeamId(teamId) {
|
||||
function _handleInviteTeamId(teamId, mode) {
|
||||
if (!teamId) return;
|
||||
|
||||
// Avoid duplicate processing if already pending the same teamId
|
||||
@@ -321,21 +354,29 @@ function _handleInviteTeamId(teamId) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`[game.js] Received teamId from invite: ${teamId}, currentScene: ${sceneManager._currentName}`);
|
||||
const is2v2 = mode === '2v2';
|
||||
const targetScene = is2v2 ? SCENE.TEAM_2V2_ROOM : SCENE.TEAM_ROOM;
|
||||
const sceneName = is2v2 ? 'Team2v2RoomScene' : 'TeamRoomScene';
|
||||
|
||||
// If already past loading, navigate directly to team room
|
||||
console.log(`[game.js] Received teamId from invite: ${teamId}, mode: ${mode || '3v3'}, targetScene: ${targetScene}, currentScene: ${sceneManager._currentName}`);
|
||||
|
||||
// If already past loading, navigate directly to the team room
|
||||
if (sceneManager._currentScene && sceneManager._currentName !== SCENE.LOADING) {
|
||||
console.log(`[game.js] Navigating directly to TeamRoomScene with teamId: ${teamId}`);
|
||||
if (!sceneManager._scenes.has(SCENE.TEAM_ROOM)) {
|
||||
const TeamRoomScene = require('./js/scenes/TeamRoomScene');
|
||||
sceneManager.register(SCENE.TEAM_ROOM, TeamRoomScene);
|
||||
console.log(`[game.js] Navigating directly to ${sceneName} with teamId: ${teamId}`);
|
||||
if (!sceneManager._scenes.has(targetScene)) {
|
||||
const SceneModule = is2v2
|
||||
? require('./js/scenes/Team2v2RoomScene')
|
||||
: require('./js/scenes/TeamRoomScene');
|
||||
sceneManager.register(targetScene, SceneModule);
|
||||
}
|
||||
sceneManager.switchTo(SCENE.TEAM_ROOM, { teamId });
|
||||
sceneManager.switchTo(targetScene, { teamId });
|
||||
GameGlobal._pendingTeamId = null;
|
||||
GameGlobal._pendingTeamMode = null;
|
||||
} else {
|
||||
// Still loading — store pending teamId for auto-navigation after load
|
||||
console.log(`[game.js] Still loading, storing pendingTeamId: ${teamId}`);
|
||||
console.log(`[game.js] Still loading, storing pendingTeamId: ${teamId}, mode: ${mode || '3v3'}`);
|
||||
GameGlobal._pendingTeamId = teamId;
|
||||
GameGlobal._pendingTeamMode = mode || null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,9 +385,10 @@ try {
|
||||
const launchOptions = wx.getLaunchOptionsSync();
|
||||
console.log(`[game.js] Cold launch options: scene=${launchOptions.scene}, query=${JSON.stringify(launchOptions.query)}, referrerInfo=${JSON.stringify(launchOptions.referrerInfo)}`);
|
||||
const launchTeamId = _extractTeamId(launchOptions && launchOptions.query);
|
||||
const launchTeamMode = _extractTeamMode(launchOptions && launchOptions.query);
|
||||
const launchRoomId = _extractRoomId(launchOptions && launchOptions.query);
|
||||
if (launchTeamId) {
|
||||
_handleInviteTeamId(launchTeamId);
|
||||
_handleInviteTeamId(launchTeamId, launchTeamMode);
|
||||
} else if (launchRoomId) {
|
||||
_handleInviteRoomId(launchRoomId);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user