File size: 2,766 Bytes
d548706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(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';
		}
	};
})();