From 6855fb9fa876df098ad79baae3783d09fb49ee1d Mon Sep 17 00:00:00 2001 From: Couls Date: Tue, 29 Sep 2020 12:21:13 -0400 Subject: [PATCH] newly added keybinds no longer need savefile updates (#54050) Keybinds check if there are any new keybinds when loading preferences now If there's a conflict it doesn't bind the key to anything --- code/modules/client/preferences_savefile.dm | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index 4492826d7cd..9ede9e6df21 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -90,6 +90,44 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car /datum/preferences/proc/update_character(current_version, savefile/S) return +/// checks through keybindings for outdated unbound keys and updates them +/datum/preferences/proc/check_keybindings() + if(!parent) + return + var/list/user_binds = list() + for (var/key in key_bindings) + for(var/kb_name in key_bindings[key]) + user_binds[kb_name] += list(key) + var/list/notadded = list() + for (var/name in GLOB.keybindings_by_name) + var/datum/keybinding/kb = GLOB.keybindings_by_name[name] + if(length(user_binds[kb.name])) + continue // key is unbound and or bound to something + var/addedbind = FALSE + if(hotkeys) + for(var/hotkeytobind in kb.classic_keys) + if(!length(key_bindings[hotkeytobind])) + LAZYADD(key_bindings[hotkeytobind], kb.name) + addedbind = TRUE + else + for(var/classickeytobind in kb.classic_keys) + if(!length(key_bindings[classickeytobind])) + LAZYADD(key_bindings[classickeytobind], kb.name) + addedbind = TRUE + if(!addedbind) + notadded += kb + if(length(notadded)) + to_chat(parent, "KEYBINDING CONFLICT!!!\n \ + There are new keybindings that have defaults bound to keys you already set, They will default to Unbound. You can bind them in Setup Character or Game Preferences\n \ + Or you can click here to go straight to the keybindings page") + for(var/item in notadded) + var/datum/keybinding/conflicted = item + to_chat(parent, "[conflicted.category]: [conflicted.full_name] needs updating") + LAZYADD(key_bindings["Unbound"], conflicted.name) // set it to unbound to prevent this from opening up again in the future + + + + /datum/preferences/proc/load_path(ckey,filename="preferences.sav") if(!ckey) return @@ -158,6 +196,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car // Custom hotkeys READ_FILE(S["key_bindings"], key_bindings) + check_keybindings() // hearted READ_FILE(S["hearted_until"], hearted_until) if(hearted_until > world.realtime)