Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
GLOBals and some bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
AyIong committed Apr 10, 2024
1 parent 774ed19 commit f51f6e7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions code/_helpers/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ var/global/list/string_slot_flags = list(
"holster" = SLOT_HOLSTER
)

var/global/list/hotkey_keybinding_list_by_key = list()
var/global/list/keybindings_by_name = list()
GLOBAL_LIST_EMPTY(hotkey_keybinding_list_by_key)
GLOBAL_LIST_EMPTY(keybindings_by_name)

/// This is a mapping from JS keys to Byond - ref: https://keycode.info/
var/global/list/_kbMap = list(
GLOBAL_LIST_INIT(keybindings_map, list(
"UP" = "North",
"RIGHT" = "East",
"DOWN" = "South",
Expand All @@ -107,10 +107,10 @@ var/global/list/_kbMap = list(
"SUBTRACT" = "Subtract",
"DECIMAL" = "Decimal",
"CLEAR" = "Center"
)
))

/// Without alt, shift, ctrl and etc because its not necessary
var/global/list/_kbMap_reverse = list(
GLOBAL_LIST_INIT(keybindings_map_reverse, list(
"North" = "Up",
"East" = "Right",
"South" = "Down",
Expand All @@ -119,7 +119,7 @@ var/global/list/_kbMap_reverse = list(
"Northeast" = "PageUp",
"Southwest" = "End",
"Southeast" = "PageDown",
)
))

//////////////////////////
/////Initial Building/////
Expand Down Expand Up @@ -228,10 +228,10 @@ var/global/list/_kbMap_reverse = list(
if(!initial(keybinding.name))
continue
var/datum/keybinding/instance = new keybinding
global.keybindings_by_name[instance.name] = instance
GLOB.keybindings_by_name[instance.name] = instance
if(length(instance.hotkey_keys))
for(var/bound_key in instance.hotkey_keys)
global.hotkey_keybinding_list_by_key[bound_key] += list(instance.name)
GLOB.hotkey_keybinding_list_by_key[bound_key] += list(instance.name)

return TRUE

Expand Down
2 changes: 1 addition & 1 deletion code/datums/keybindings/client.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name = "screenshot"
full_name = "Screenshot"
description = "Take a screenshot"
hotkey_keys = list("F10")
hotkey_keys = list()

/datum/keybinding/client/screenshot/down(client/user)
winset(user, null, "command=.screenshot [!user.keys_held[SHIFT_CLICK] ? "auto" : ""]")
Expand Down
2 changes: 1 addition & 1 deletion code/datums/keybindings/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
name = "pixel_shift"
full_name = "Pixel Shift"
description = "Hold to pixel shift with movement keys"
hotkey_keys = list("V")
hotkey_keys = list("B")

/datum/keybinding/living/pixel_shift/down(client/user)
if(!(SEND_SIGNAL(user.mob, COMSIG_KB_MOB_PIXEL_SHIFT_DOWN) & COMSIG_KB_ACTIVATED))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

var/list/kb_categories = list()
// Group keybinds by category
for (var/name in global.keybindings_by_name)
var/datum/keybinding/kb = global.keybindings_by_name[name]
for (var/name in GLOB.keybindings_by_name)
var/datum/keybinding/kb = GLOB.keybindings_by_name[name]
kb_categories[kb.category] += list(kb)

. += "<center>"
Expand All @@ -56,11 +56,11 @@
. += "</tr>"
else
var/bound_key = user_binds[kb.name][1]
var/normal_name = _kbMap_reverse[bound_key] ? _kbMap_reverse[bound_key] : bound_key
var/normal_name = GLOB.keybindings_map_reverse[bound_key] ? GLOB.keybindings_map[bound_key] : bound_key
. += "<tr><td width='40%'>[kb.full_name]</td><td width='15%'><a class='fluid' href ='?src=\ref[src];preference=keybindings_capture;keybinding=[kb.name];old_key=[bound_key]'>[pretty_keybinding_name(normal_name)]</a></td>"
for(var/bound_key_index in 2 to length(user_binds[kb.name]))
bound_key = user_binds[kb.name][bound_key_index]
normal_name = _kbMap_reverse[bound_key] ? _kbMap_reverse[bound_key] : bound_key
normal_name = GLOB.keybindings_map_reverse[bound_key] ? GLOB.keybindings_map_reverse[bound_key] : bound_key
. += "<td width='15%'><a class='fluid' href ='?src=\ref[src];preference=keybindings_capture;keybinding=[kb.name];old_key=[bound_key]'>[pretty_keybinding_name(normal_name)]</a></td>"
if(length(user_binds[kb.name]) < MAX_KEYS_PER_KEYBIND)
. += "<td width='15%'><a class='fluid' href ='?src=\ref[src];preference=keybindings_capture;keybinding=[kb.name]'>None</a></td>"
Expand All @@ -81,7 +81,7 @@
/datum/category_item/player_setup_item/controls/keybindings/OnTopic(href, list/href_list, mob/user)
switch(href_list["preference"])
if("keybindings_capture")
var/datum/keybinding/kb = global.keybindings_by_name[href_list["keybinding"]]
var/datum/keybinding/kb = GLOB.keybindings_by_name[href_list["keybinding"]]
var/old_key = href_list["old_key"]
capture_keybinding(user, kb, old_key)
return TOPIC_REFRESH
Expand Down Expand Up @@ -115,8 +115,8 @@
close_browser(user, "window=capturekeypress")
return TOPIC_REFRESH

if(global._kbMap[new_key])
new_key = global._kbMap[new_key]
if(GLOB.keybindings_map[new_key])
new_key = GLOB.keybindings_map[new_key]

var/full_key
switch(new_key)
Expand All @@ -142,7 +142,7 @@
return TOPIC_REFRESH

if("keybindings_reset")
pref.key_bindings = deepCopyList(global.hotkey_keybinding_list_by_key)
pref.key_bindings = deepCopyList(GLOB.hotkey_keybinding_list_by_key)
user.client.set_macros()
return TOPIC_REFRESH

Expand All @@ -157,7 +157,7 @@
if(!length(pref.key_bindings[old_key]))
pref.key_bindings -= old_key

var/datum/keybinding/kb = global.keybindings_by_name[kb_name]
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
for(var/key in kb.hotkey_keys)
pref.key_bindings[key] += list(kb_name)
pref.key_bindings[key] = sortTim(pref.key_bindings[key], GLOBAL_PROC_REF(cmp_text_asc))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/proc/sanitize_keybindings(value)
var/list/base_bindings = sanitize_islist(value,list())
for(var/key in base_bindings)
base_bindings[key] = base_bindings[key] & global.keybindings_by_name
base_bindings[key] = base_bindings[key] & GLOB.keybindings_by_name
if(!length(base_bindings[key]))
base_bindings -= key
return base_bindings
Expand Down
8 changes: 4 additions & 4 deletions code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
..()

/datum/preferences/proc/setup()
key_bindings = deepCopyList(global.hotkey_keybinding_list_by_key)
key_bindings = deepCopyList(GLOB.hotkey_keybinding_list_by_key)
if(!length(GLOB.skills))
GET_SINGLETON(/singleton/hierarchy/skill)
player_setup = new(src)
Expand Down Expand Up @@ -501,15 +501,15 @@
// When loading from savefile key_binding can be null
// This happens when player had savefile created before new kb system, but hotkeys was not saved
if(!length(key_bindings))
key_bindings = deepCopyList(global.hotkey_keybinding_list_by_key) // give them default keybinds too
key_bindings = deepCopyList(GLOB.hotkey_keybinding_list_by_key) // give them default keybinds too

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 global.keybindings_by_name)
var/datum/keybinding/kb = global.keybindings_by_name[name]
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
Expand Down
10 changes: 5 additions & 5 deletions code/modules/input/input.dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
var/keycount = 0
for(var/kb_name in prefs.key_bindings[full_key])
keycount++
var/datum/keybinding/kb = global.keybindings_by_name[kb_name]
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
if(kb.can_use(src) && kb.down(src) && keycount >= MAX_COMMANDS_PER_KEY)
break

Expand Down Expand Up @@ -107,7 +107,7 @@
// We don't do full key for release, because for mod keys you
// can hold different keys and releasing any should be handled by the key binding specifically
for (var/kb_name in prefs.key_bindings[_key])
var/datum/keybinding/kb = global.keybindings_by_name[kb_name]
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
if(kb.can_use(src) && kb.up(src))
break
holder?.key_up(_key, src)
Expand Down Expand Up @@ -140,11 +140,11 @@
update_special_keybinds()

/client/proc/reset_macros(skip_alert = FALSE)
var/ans
var/answer
if(!skip_alert)
ans = alert(src, "Change your keyboard language to ENG", "Reset macros")
answer = tgui_alert(src, "Change your keyboard language to ENG", "Reset macros")

if(skip_alert || ans)
if(skip_alert || answer)
set_macros()
to_chat(src, SPAN_NOTICE("Keybindings were fixed.")) // not yet but set_macros works fast enough

Expand Down

0 comments on commit f51f6e7

Please sign in to comment.