[adapters] 增加小游戏适配部分源码

This commit is contained in:
SmallMain
2024-10-16 17:12:08 +08:00
parent 887d4a96c9
commit 07bf3b7a96
345 changed files with 38447 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
function adaptSys (sys, env) {
if (!env) {
env = __globalAdapter.getSystemInfoSync();
}
var language = env.language || '';
var system = env.system || 'iOS';
var platform = env.platform || 'iOS';
sys.isNative = false;
sys.isBrowser = false;
sys.isMobile = true;
sys.language = language.substr(0, 2);
sys.languageCode = language.toLowerCase();
platform = platform.toLowerCase();
if (platform === "android") {
sys.os = sys.OS_ANDROID;
}
else if (platform === "ios") {
sys.os = sys.OS_IOS;
}
system = system.toLowerCase();
// Adaptation to Android P
if (system === 'android p') {
system = 'android p 9.0';
}
var version = /[\d\.]+/.exec(system);
sys.osVersion = version ? version[0] : system;
sys.osMainVersion = parseInt(sys.osVersion);
sys.browserType = null;
sys.browserVersion = null;
var w = env.windowWidth;
var h = env.windowHeight;
var ratio = env.pixelRatio || 1;
sys.windowPixelResolution = {
width: ratio * w,
height: ratio * h
};
sys.localStorage = window.localStorage;
var _supportWebGL = __globalAdapter.isSubContext ? false : true;;
var _supportWebp = false;
try {
var _canvas = document.createElement("canvas");
_supportWebp = _canvas.toDataURL('image/webp').startsWith('data:image/webp');
}
catch (err) { }
sys.capabilities = {
"canvas": true,
"opengl": !!_supportWebGL,
"webp": _supportWebp
};
sys.__audioSupport = {
ONLY_ONE: false,
WEB_AUDIO: false,
DELAY_CREATE_CTX: false,
format: ['.mp3']
};
}
module.exports = adaptSys;

View File

@@ -0,0 +1,25 @@
function adaptContainerStrategy (containerStrategyProto) {
containerStrategyProto._setupContainer = function (view, width, height) {
// Setup pixel ratio for retina display
var devicePixelRatio = view._devicePixelRatio = 1;
if (view.isRetinaEnabled()) {
devicePixelRatio = view._devicePixelRatio = Math.min(view._maxPixelRatio, window.devicePixelRatio || 1);
}
// size of sharedCanvas is readonly in subContext
if (__globalAdapter.isSubContext) {
return;
}
let locCanvas = cc.game.canvas;
// Setup canvas
width *= devicePixelRatio;
height *= devicePixelRatio;
// FIX: black screen on Baidu platform
// reset canvas size may call gl.clear(), especially when you call cc.director.loadScene()
if (locCanvas.width !== width || locCanvas.height !== height) {
locCanvas.width = width;
locCanvas.height = height;
}
};
}
module.exports = adaptContainerStrategy;

View File

@@ -0,0 +1,43 @@
function adaptView (viewProto) {
Object.assign(viewProto, {
_adjustViewportMeta () {
// minigame not support
},
setRealPixelResolution (width, height, resolutionPolicy) {
// Reset the resolution size and policy
this.setDesignResolutionSize(width, height, resolutionPolicy);
},
enableAutoFullScreen (enabled) {
cc.warn('cc.view.enableAutoFullScreen() is not supported on minigame platform.');
},
isAutoFullScreenEnabled () {
return false;
},
setCanvasSize () {
cc.warn('cc.view.setCanvasSize() is not supported on minigame platform.');
},
setFrameSize () {
cc.warn('frame size is readonly on minigame platform.');
},
_initFrameSize () {
let locFrameSize = this._frameSize;
if (__globalAdapter.isSubContext) {
let sharedCanvas = window.sharedCanvas || __globalAdapter.getSharedCanvas();
locFrameSize.width = sharedCanvas.width;
locFrameSize.height = sharedCanvas.height;
}
else {
locFrameSize.width = window.innerWidth;
locFrameSize.height = window.innerHeight;
}
},
});
}
module.exports = adaptView;

View File

@@ -0,0 +1,9 @@
const adapter = window.__globalAdapter;
Object.assign(adapter, {
adaptSys: require('./BaseSystemInfo'),
adaptView: require('./View'),
adaptContainerStrategy: require('./ContainerStrategy'),
});