28 lines
969 B
JavaScript
28 lines
969 B
JavaScript
var _FilePicker = {};
|
|
var _FilePickerData = {};
|
|
_FilePicker.upload = function(gd_callback) {
|
|
// canceled = true;
|
|
var input = document.createElement('INPUT');
|
|
input.setAttribute("type", "file");
|
|
input.setAttribute("accept", ".sfc,.srm,.gba,.bin,.iso");
|
|
input.setAttribute("multiple", "");
|
|
input.click();
|
|
input.addEventListener('change', event => {
|
|
for (const file of event.target.files) {
|
|
var reader = new FileReader();
|
|
// this.filename = file.name;
|
|
// this.file_type = file.type;
|
|
reader.readAsArrayBuffer(file);
|
|
reader.onloadend = (evt) => {
|
|
if (evt.target.readyState == FileReader.DONE) {
|
|
// Godot's JavaScriptObject API is very very poorly documented.
|
|
// It might be possible to unwrap JavaScriptObject<ArrayBuffer> to PoolByteArray
|
|
// without a bytewise for loop, but I can't work it out by trial and error.
|
|
_FilePickerData[file.name] = evt.target.result;
|
|
gd_callback(file.name, file.type);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|