Update file pickers to allow .smc

This commit is contained in:
Luke Hubmayer-Werner 2023-12-06 18:19:19 +10:30
parent 6c0c04fe21
commit 82a25de4ea
4 changed files with 38 additions and 37 deletions

View File

@ -1,10 +1,14 @@
var _snes_types = "application/vnd.nintendo.snes.rom,.sfc,.smc,.srm";
var _psx_types = "application/x-cd-image,application/x-iso9660-image,.bin,.iso";
var _gba_types = "application/x-gba-rom,.gba";
var _accepted_types = _snes_types+","+_psx_types+","+_gba_types;
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("accept", _accepted_types);
input.setAttribute("multiple", "");
input.click();
input.addEventListener('change', event => {

View File

@ -2,6 +2,25 @@ extends Node
const INDEX_FORMAT := Image.FORMAT_L8
const FOLDER_ICON := preload('res://theme/icons/file_folder.tres')
const ALLOWED_EXTS := PoolStringArray(['bin', 'iso', 'sfc', 'smc', 'srm', 'gba'])
const CD_EXTS := PoolStringArray(['bin', 'iso']) # If you have a weird disc image format, you can mount it yourself, leave me out of it
const EXT_ICONS := {
'bin': preload('res://theme/icons/file_binary.tres'),
'iso': preload('res://theme/icons/file_disc.tres'),
'sfc': preload('res://theme/icons/file_cart.tres'),
'smc': preload('res://theme/icons/file_cart.tres'),
'gba': preload('res://theme/icons/file_cart.tres'),
}
const TYPE_DESCS := {
'bin': 'Binary',
'iso': 'CD-ROM Image',
'sfc': 'SNES ROM',
'smc': 'SNES ROM',
'gba': 'GBA ROM',
'srm': 'SNES Savefile'
}
var time = 0.0
var time_mult = 1.0

View File

@ -3,22 +3,11 @@ extends PanelContainer
signal continue_pressed
const FOLDER_ICON := preload('res://theme/icons/file_folder.tres')
const ALLOWED_EXTS := PoolStringArray(['bin', 'iso', 'sfc', 'srm', 'gba'])
const CD_EXTS := PoolStringArray(['bin', 'iso']) # If you have a weird disc image format, you can mount it yourself, leave me out of it
var EXT_ICONS := { # Dicts can't be const
'bin': preload('res://theme/icons/file_binary.tres'),
'iso': preload('res://theme/icons/file_disc.tres'),
'sfc': preload('res://theme/icons/file_cart.tres'),
'gba': preload('res://theme/icons/file_cart.tres'),
}
var TYPE_DESCS := { # Dicts can't be const
'bin': 'Binary',
'iso': 'CD-ROM Image',
'sfc': 'SNES ROM',
'gba': 'GBA ROM',
'srm': 'SNES Savefile'
}
const FOLDER_ICON := globals.FOLDER_ICON
const ALLOWED_EXTS := globals.ALLOWED_EXTS
const CD_EXTS := globals.CD_EXTS
const EXT_ICONS := globals.EXT_ICONS
const TYPE_DESCS := globals.TYPE_DESCS
var cached_cd_bin_paths := {}
var dir := Directory.new()
@ -119,7 +108,7 @@ func load_file(entry: String):
var filename := dir.get_current_dir() + '/' + entry
var ext = entry.rsplit('.', true, 1)[1].to_lower()
match ext:
'sfc':
'sfc', 'smc':
RomLoader.load_snes_rom(filename)
func activate_entry(entry: String, _index: int = -1):
@ -179,7 +168,7 @@ func view_entry(entry: String, index: int = -1):
lbl_filesize_content.text = human_size
lbl_fileinfo_header.modulate = active_modulate_color if prodcode else inactive_modulate_color
lbl_fileinfo_content.text = prodcode
btn_ok.disabled = (ext != 'sfc') # Only allow opening snes roms for now
btn_ok.disabled = (ext != 'sfc' and ext != 'smc') # Only allow opening snes roms for now
func init_labels():
lbl_filename_header.modulate = inactive_modulate_color

View File

@ -3,22 +3,11 @@ extends PanelContainer
signal continue_pressed
const FOLDER_ICON := preload('res://theme/icons/file_folder.tres')
const ALLOWED_EXTS := PoolStringArray(['bin', 'iso', 'sfc', 'srm', 'gba'])
const CD_EXTS := PoolStringArray(['bin', 'iso']) # If you have a weird disc image format, you can mount it yourself, leave me out of it
var EXT_ICONS := { # Dicts can't be const
'bin': preload('res://theme/icons/file_binary.tres'),
'iso': preload('res://theme/icons/file_disc.tres'),
'sfc': preload('res://theme/icons/file_cart.tres'),
'gba': preload('res://theme/icons/file_cart.tres'),
}
var TYPE_DESCS := { # Dicts can't be const
'bin': 'Binary',
'iso': 'CD-ROM Image',
'sfc': 'SNES ROM',
'gba': 'GBA ROM',
'srm': 'SNES Savefile'
}
const FOLDER_ICON := globals.FOLDER_ICON
const ALLOWED_EXTS := globals.ALLOWED_EXTS
const CD_EXTS := globals.CD_EXTS
const EXT_ICONS := globals.EXT_ICONS
const TYPE_DESCS := globals.TYPE_DESCS
var uploaded_files := {} # filename: data
var uploaded_files_types := {} # filename: type
@ -78,7 +67,7 @@ func update_view():
func load_file(entry: String):
var ext = entry.rsplit('.', true, 1)[1].to_lower()
match ext:
'sfc':
'sfc', 'smc':
RomLoader.load_snes_rom_from_bytes(uploaded_files[entry])
func activate_entry(entry: String, _index: int = -1):
@ -119,7 +108,7 @@ func view_entry(entry: String, _index: int = -1):
lbl_filesize_content.text = human_size
lbl_fileinfo_header.modulate = active_modulate_color if prodcode else inactive_modulate_color
lbl_fileinfo_content.text = prodcode
btn_ok.disabled = (ext != 'sfc') # Only allow opening snes roms for now
btn_ok.disabled = (ext != 'sfc' and ext != 'smc') # Only allow opening snes roms for now
func init_labels():
lbl_filename_header.modulate = inactive_modulate_color