2023-07-28 15:57:21 +09:30
|
|
|
extends Node
|
|
|
|
|
2023-08-02 20:18:29 +09:30
|
|
|
var base_resolution: Vector2 = Vector2(ProjectSettings.get_setting('display/window/size/width'), ProjectSettings.get_setting('display/window/size/height')) # Vector2(640, 360)
|
2023-08-02 19:48:45 +09:30
|
|
|
var shrink_timer := Timer.new()
|
|
|
|
|
2023-07-31 23:33:05 +09:30
|
|
|
static func load_json(filename: String) -> Dictionary:
|
2023-07-28 15:57:21 +09:30
|
|
|
var file := File.new()
|
|
|
|
var error := file.open(filename, File.READ)
|
|
|
|
if error == OK:
|
|
|
|
var result = JSON.parse(file.get_as_text())
|
|
|
|
if result.error == OK:
|
|
|
|
return result.result
|
|
|
|
else:
|
|
|
|
print_debug(result.error_string)
|
|
|
|
print_debug(result.error_line)
|
|
|
|
return {}
|
2023-07-31 23:33:05 +09:30
|
|
|
|
|
|
|
static func load_tsv(filename: String, delimiter: String = '\t') -> Dictionary:
|
|
|
|
var file := File.new()
|
|
|
|
var error := file.open(filename, File.READ)
|
|
|
|
if error == OK:
|
|
|
|
var headers := file.get_csv_line(delimiter)
|
|
|
|
var n := headers.size()
|
|
|
|
var output = {}
|
|
|
|
while file.get_position() < file.get_len():
|
|
|
|
var line := file.get_csv_line(delimiter)
|
|
|
|
var entry := {}
|
|
|
|
for i in range(1, n):
|
|
|
|
if line.size() > i:
|
|
|
|
var token := line[i]
|
|
|
|
entry[headers[i]] = token
|
|
|
|
if token.begins_with('0x'):
|
|
|
|
var hex := token.hex_to_int()
|
|
|
|
if hex > 0:
|
|
|
|
entry[headers[i]] = hex
|
|
|
|
output[line[0]] = entry
|
|
|
|
return output
|
|
|
|
print_debug(error)
|
|
|
|
return {}
|
|
|
|
|
|
|
|
var SNES_PSX_addresses := load_tsv('res://data/SNES_PSX_addresses.tsv')
|
2023-08-02 19:48:45 +09:30
|
|
|
|
|
|
|
func shrink_to_integer():
|
|
|
|
var size := OS.get_window_size()
|
|
|
|
var scale_vec := size / base_resolution
|
|
|
|
var scale_f := max(min(scale_vec.x, scale_vec.y), 1)
|
|
|
|
var scale := int(scale_f)
|
2023-08-02 20:18:29 +09:30
|
|
|
var new_window_size := base_resolution*scale
|
|
|
|
if OS.get_window_size() != new_window_size: # avoid retriggering this event forever
|
|
|
|
OS.set_window_size(new_window_size)
|
|
|
|
print('resized to scale %d %s' % [scale, new_window_size])
|
2023-08-02 19:48:45 +09:30
|
|
|
|
|
|
|
func update_window_scale():
|
|
|
|
if OS.window_size < base_resolution*2:
|
|
|
|
OS.window_size = base_resolution*2
|
|
|
|
var size := OS.get_window_size()
|
|
|
|
var scale_vec := size / base_resolution
|
|
|
|
var scale_f := max(min(scale_vec.x, scale_vec.y), 1)
|
|
|
|
var scale := int(scale_f)
|
|
|
|
if ProjectSettings.get_setting('display/window/size/snap_to_integer'):
|
|
|
|
# OS.window_size = base_resolution*scale
|
|
|
|
shrink_timer.paused = false
|
|
|
|
shrink_timer.start(1)
|
|
|
|
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_DISABLED, SceneTree.STRETCH_ASPECT_KEEP, base_resolution*scale, scale)
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
shrink_timer.connect('timeout', self, 'shrink_to_integer')
|
2023-08-02 20:18:29 +09:30
|
|
|
shrink_timer.one_shot = true
|
2023-08-02 19:48:45 +09:30
|
|
|
add_child(shrink_timer)
|
|
|
|
get_tree().connect('screen_resized', self, 'update_window_scale')
|
|
|
|
OS.set_min_window_size(base_resolution*2)
|