From 8c2d1771f84dc58b397017440c74e4c5e7d52a62 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 30 Sep 2020 00:42:13 +0200 Subject: [PATCH] [MIRROR] newly added keybinds no longer need savefile updates (#1056) * 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 * newly added keybinds no longer need savefile updates Co-authored-by: Couls --- 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 431ce3b8ee2..4893a106c3f 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -92,6 +92,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 @@ -160,6 +198,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)