[Web] Allow dropping files onto the window to load them.
This commit is contained in:
parent
a7fc07c726
commit
9ad16eaece
|
@ -145,6 +145,24 @@ func _upload_file(filename: String, file_type: String, data): # data is Javascr
|
||||||
print('uploaded "%s" with filesize %d bytes'%[filename, len(data)])
|
print('uploaded "%s" with filesize %d bytes'%[filename, len(data)])
|
||||||
update_view()
|
update_view()
|
||||||
|
|
||||||
|
func _files_dropped(filenames: PoolStringArray, screen_idx: int) -> void:
|
||||||
|
print('Files Dropped signal: screen=%d, files='%screen_idx, filenames)
|
||||||
|
for filename in filenames:
|
||||||
|
var ext: String = filename.rsplit('.', true, 1)[1]
|
||||||
|
if ext in ALLOWED_EXTS:
|
||||||
|
var file := File.new()
|
||||||
|
match file.open(filename, File.READ):
|
||||||
|
OK:
|
||||||
|
var rom_size := file.get_len()
|
||||||
|
var data := file.get_buffer(rom_size)
|
||||||
|
uploaded_files[filename] = data
|
||||||
|
uploaded_files_types[filename] = ext
|
||||||
|
print('uploaded "%s" with filesize %d bytes'%[filename, len(data)])
|
||||||
|
update_view()
|
||||||
|
load_file(filename)
|
||||||
|
var error:
|
||||||
|
print_debug('Error %d loading filename:'%error, filename)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if OS.get_name() != 'HTML5' or !OS.has_feature('JavaScript'):
|
if OS.get_name() != 'HTML5' or !OS.has_feature('JavaScript'):
|
||||||
return
|
return
|
||||||
|
@ -155,6 +173,7 @@ func _ready() -> void:
|
||||||
RomLoader.connect('rom_loaded', self, '_on_rom_loaded')
|
RomLoader.connect('rom_loaded', self, '_on_rom_loaded')
|
||||||
RomLoader.connect('loading_stage_updated', self, '_on_loading_stage_updated')
|
RomLoader.connect('loading_stage_updated', self, '_on_loading_stage_updated')
|
||||||
HTML5.connect('uploaded_file', self, '_upload_file')
|
HTML5.connect('uploaded_file', self, '_upload_file')
|
||||||
|
get_tree().connect('files_dropped', self, '_files_dropped')
|
||||||
|
|
||||||
func _set_mode(new_mode) -> void:
|
func _set_mode(new_mode) -> void:
|
||||||
match new_mode:
|
match new_mode:
|
||||||
|
|
Loading…
Reference in New Issue