h5prod / matchn /anan.tool.js
anan66's picture
reload-matchn-game
d1e95fb verified
(function() {
window.godotFilePath = null;
window.urlParameter = window.location.search;
window.uploadFile = function() {
var input = document.createElement('input');
input.type = 'file';
input.onchange = function(event) {
var file = event.target.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function(e) {
var fileContent = e.target.result; // 读取到的文件内容(Base64 编码)
window.godotFilePath = fileContent;
if (typeof window.fileUploaded === 'function') {
window.fileUploaded(fileContent); // 调用外部定义的事件触发函数
}
};
reader.readAsDataURL(file); // 读取文件内容为 Data URL
}
};
input.click();
};
window.gdjs = {
godotFilePath: null
};
// 虚拟键盘
window.showVirtualKeyboard = function() {
var inputField = document.createElement('input');
inputField.type = 'text';
inputField.style.position = 'absolute';
inputField.style.top = '-1000px';
document.body.appendChild(inputField);
setTimeout(function() {
inputField.focus();
}, 100); // 尝试调整延迟时间
inputField.onblur = function() {
document.body.removeChild(inputField);
};
inputField.addEventListener('input', function() {
var value = inputField.value;
if (typeof window.godotUserInput === 'function') {
window.godotUserInput(value); // 修正了传参的语法
}
});
};
window.closeVirtualKeyboard = function() {
document.activeElement.blur();
};
//屏幕翻转
window.setOrientation = function(orientation) {
console.log("2222")
console.log(orientation)
if (orientation === "landscape") {
screen.orientation.lock(orientation).catch(function(error) {
console.log("Orientation lock failed: " + error);
});
} else if (orientation === "portrait") {
screen.lockOrientation(orientation).catch(function(error) {
console.log("Orientation lock failed: " + error);
});
}
console.log(document.body)
};
window.setWindowSize = function(width, height) {
var canvas = document.getElementById('canvas');
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
};
window.setScreenStretch = function(mode, aspect, width, height) {
var canvas = document.getElementById('canvas');
if (mode === 'viewport') {
canvas.style.objectFit = 'contain'; // 等同于 Godot 的 STRETCH_MODE_VIEWPORT
}
if (aspect === 'keep') {
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
}
};
})();