a game about throwing hammers made for the github game off
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
extends Popuppable

const file = "user://graphics.settings"
const SaveLoad := preload("res://addons/remap/private/SaveLoadUtils.gd") # so what its private, im using gdscript

enum {FULLSCREEN, BORDERLESS_FS, WINDOWED}
const map := {
	FULLSCREEN: DisplayServer.WINDOW_MODE_FULLSCREEN,
	WINDOWED: DisplayServer.WINDOW_MODE_WINDOWED,
}
const default_settings_data := {
	window = WINDOWED,
	vsync = false,
}

@onready var vsync: CheckBox = $"%vsyncbutton"
@onready var window: CaretOptionButton = $"%windowbutton"

var ignore_set_settings := false
var has_loaded := false

var settings := default_settings_data

func save() -> void:
	SaveLoad.save(file, settings)

func _ready() -> void:
	var lod := SaveLoad.load_file(file)
	settings = lod if Util.dict_cmp(lod, default_settings_data) else default_settings_data # check if the keys and vaue types are correct
	has_loaded = true
	update_button_visuals()

func update_button_visuals():
	ignore_set_settings = true
	vsync.button_pressed = settings.vsync
	window.current_option = settings.window
	ignore_set_settings = false

func update_window():
	if settings.window == BORDERLESS_FS:
		DisplayServer.window_set_mode(map[FULLSCREEN])
		DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true)
	else:
		DisplayServer.window_set_mode(map[settings.window])

func update_vsync():
	var vsync_mode := DisplayServer.VSYNC_DISABLED if not settings.vsync else DisplayServer.VSYNC_ENABLED
	DisplayServer.window_set_vsync_mode(vsync_mode)

func _on_vsync_toggled(button_pressed: bool) -> void:
	if not has_loaded: return
	if not ignore_set_settings:
		settings.vsync = button_pressed
		save()
	update_vsync()

func _on_window_mode_changed(current_option: int) -> void:
	if not has_loaded: return
	if not ignore_set_settings:
		settings.window = current_option
		save()
	update_window()