feat: use wx.createUserInfoButton to get weixin's avarta

This commit is contained in:
jakciehan
2026-05-14 22:41:32 +08:00
parent c4bd390478
commit 9359139186
13 changed files with 1181 additions and 184 deletions
+53
View File
@@ -31,6 +31,7 @@ const ContentSecurityManager = require('./js/managers/ContentSecurityManager');
const BuffManager = require('./js/managers/BuffManager');
const SkinManager = require('./js/managers/SkinManager');
const PlayerProfile = require('./js/managers/PlayerProfile');
const PrivacyPopup = require('./js/ui/PrivacyPopup');
const EventBus = require('./js/base/EventBus');
const {
SCREEN_WIDTH,
@@ -81,6 +82,7 @@ const contentSecurityManager = new ContentSecurityManager();
const buffManager = new BuffManager();
const skinManager = new SkinManager();
const playerProfile = new PlayerProfile();
const privacyPopup = new PrivacyPopup();
GameGlobal.adManager = adManager;
GameGlobal.shareManager = shareManager;
GameGlobal.currencyManager = currencyManager;
@@ -90,6 +92,7 @@ GameGlobal.contentSecurityManager = contentSecurityManager;
GameGlobal.buffManager = buffManager;
GameGlobal.skinManager = skinManager;
GameGlobal.playerProfile = playerProfile;
GameGlobal.privacyPopup = privacyPopup;
// ============================================================
// Game State
@@ -101,15 +104,60 @@ let lastTimestamp = 0;
// Touch Event Forwarding
// ============================================================
wx.onTouchStart((e) => {
// Privacy popup consumes all touches while active
if (privacyPopup.active) {
privacyPopup.handleTouch('touchstart', e);
return;
}
sceneManager.handleTouch('touchstart', e);
});
wx.onTouchMove((e) => {
if (privacyPopup.active) return;
sceneManager.handleTouch('touchmove', e);
});
wx.onTouchEnd((e) => {
if (privacyPopup.active) {
privacyPopup.handleTouch('touchend', e);
return;
}
sceneManager.handleTouch('touchend', e);
});
// ============================================================
// WeChat Privacy Authorization (required since base library 2.32.3)
// ============================================================
if (typeof wx !== 'undefined' && typeof wx.onNeedPrivacyAuthorization === 'function') {
// Once the user has explicitly agreed to privacy, we auto-resolve any
// subsequent onNeedPrivacyAuthorization callbacks without showing the
// popup again. This prevents showing duplicate popups.
let _privacyAgreed = false;
wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
console.log('[game.js] onNeedPrivacyAuthorization triggered, eventInfo:', eventInfo, ', alreadyAgreed:', _privacyAgreed);
// If the user already agreed, auto-resolve without showing the popup.
if (_privacyAgreed) {
console.log('[game.js] Auto-resolving privacy (already agreed)');
resolve({ event: 'agree' });
return;
}
// Show the privacy popup for the first-time authorization.
// When the user taps "Agree" or "Decline", the popup calls resolve().
const wrappedResolve = (result) => {
console.log('[game.js] Privacy resolved with:', JSON.stringify(result));
resolve(result);
// Remember that the user agreed — future triggers auto-resolve.
if (result && result.event === 'agree') {
_privacyAgreed = true;
}
};
privacyPopup.show(wrappedResolve, eventInfo);
});
}
// ============================================================
// Lifecycle: pause / resume on background switch
// ============================================================
@@ -255,6 +303,11 @@ function gameLoop(timestamp) {
// Update & render current scene
sceneManager.update(dt);
sceneManager.render(ctx);
// Privacy popup renders on top of everything
if (privacyPopup.active) {
privacyPopup.render(ctx);
}
}
// ============================================================