Skip to content

Commit 4e5e95d

Browse files
authored
Merge pull request #33 from sabarjp/refactoring
- clarified variables names and ui calls - added autoitem feature to slot items into bar - finally moved key binds into settings.xml
2 parents 204a3f2 + b14a84e commit 4e5e95d

File tree

11 files changed

+1164
-942
lines changed

11 files changed

+1164
-942
lines changed

data/default_keybinds.lua

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
-- DEFAULT BINDINGS
2+
-- SEE: https://docs.windower.net/commands/keymapping/
3+
---------------------------------------------------------
4+
-- 'EQ' is a special binding for '=' since its not valid XML
5+
-- '#' is a special binding for pure numbers, so it parses correctly
6+
---------------------------------------------------------
7+
-- DO NOT EDIT THIS FILE, CHANGE IN SETTINGS.XML INSTEAD
8+
-- DO NOT EDIT THIS FILE, CHANGE IN SETTINGS.XML INSTEAD
9+
-- DO NOT EDIT THIS FILE, CHANGE IN SETTINGS.XML INSTEAD
10+
---------------------------------------------------------
11+
12+
keybinds = {}
13+
keybinds.R1 = {}
14+
keybinds.R1.C01 = '#1' -- Hotbar Row #1 Col #1
15+
keybinds.R1.C02 = '#2' -- Hotbar Row #1 Col #2
16+
keybinds.R1.C03 = '#3' -- Hotbar Row #1 Col #3
17+
keybinds.R1.C04 = '#4' -- Hotbar Row #1 Col #4
18+
keybinds.R1.C05 = '#5' -- Hotbar Row #1 Col #5
19+
keybinds.R1.C06 = '#6' -- Hotbar Row #1 Col #6
20+
keybinds.R1.C07 = '#7' -- Hotbar Row #1 Col #7
21+
keybinds.R1.C08 = '#8' -- Hotbar Row #1 Col #8
22+
keybinds.R1.C09 = '#9' -- Hotbar Row #1 Col #9
23+
keybinds.R1.C10 = '#0' -- Hotbar Row #1 Col #10
24+
keybinds.R1.C11 = '`' -- Hotbar Row #1 Col #11
25+
keybinds.R1.C12 = 'EQ' -- Hotbar Row #1 Col #12
26+
keybinds.R2 = {}
27+
keybinds.R2.C01 = 'ALT + 1' -- Hotbar Row #2 Col #1
28+
keybinds.R2.C02 = 'ALT + 2' -- Hotbar Row #2 Col #2
29+
keybinds.R2.C03 = 'ALT + 3' -- Hotbar Row #2 Col #3
30+
keybinds.R2.C04 = 'ALT + 4' -- Hotbar Row #2 Col #4
31+
keybinds.R2.C05 = 'ALT + 5' -- Hotbar Row #2 Col #5
32+
keybinds.R2.C06 = 'ALT + 6' -- Hotbar Row #2 Col #6
33+
keybinds.R2.C07 = 'ALT + 7' -- Hotbar Row #2 Col #7
34+
keybinds.R2.C08 = 'ALT + 8' -- Hotbar Row #2 Col #8
35+
keybinds.R2.C09 = 'ALT + 9' -- Hotbar Row #2 Col #9
36+
keybinds.R2.C10 = 'ALT + 0' -- Hotbar Row #2 Col #10
37+
keybinds.R2.C11 = 'ALT + -' -- Hotbar Row #2 Col #11
38+
keybinds.R2.C12 = 'ALT + EQ' -- Hotbar Row #2 Col #12
39+
keybinds.R3 = {}
40+
keybinds.R3.C01 = 'CTRL + 1' -- Hotbar Row #3 Col #1
41+
keybinds.R3.C02 = 'CTRL + 2' -- Hotbar Row #3 Col #2
42+
keybinds.R3.C03 = 'CTRL + 3' -- Hotbar Row #3 Col #3
43+
keybinds.R3.C04 = 'CTRL + 4' -- Hotbar Row #3 Col #4
44+
keybinds.R3.C05 = 'CTRL + 5' -- Hotbar Row #3 Col #5
45+
keybinds.R3.C06 = 'CTRL + 6' -- Hotbar Row #3 Col #6
46+
keybinds.R3.C07 = 'CTRL + 7' -- Hotbar Row #3 Col #7
47+
keybinds.R3.C08 = 'CTRL + 8' -- Hotbar Row #3 Col #8
48+
keybinds.R3.C09 = 'CTRL + 9' -- Hotbar Row #3 Col #9
49+
keybinds.R3.C10 = 'CTRL + 0' -- Hotbar Row #3 Col #10
50+
keybinds.R3.C11 = 'CTRL + -' -- Hotbar Row #3 Col #11
51+
keybinds.R3.C12 = 'CTRL + EQ' -- Hotbar Row #3 Col #12
52+
keybinds.R4 = {}
53+
keybinds.R4.C01 = 'Shift + 1' -- Hotbar Row #4 Col #1
54+
keybinds.R4.C02 = 'Shift + 2' -- Hotbar Row #4 Col #2
55+
keybinds.R4.C03 = 'Shift + 3' -- Hotbar Row #4 Col #3
56+
keybinds.R4.C04 = 'Shift + 4' -- Hotbar Row #4 Col #4
57+
keybinds.R4.C05 = 'Shift + 5' -- Hotbar Row #4 Col #5
58+
keybinds.R4.C06 = 'Shift + 6' -- Hotbar Row #4 Col #6
59+
keybinds.R4.C07 = 'Shift + 7' -- Hotbar Row #4 Col #7
60+
keybinds.R4.C08 = 'Shift + 8' -- Hotbar Row #4 Col #8
61+
keybinds.R4.C09 = 'Shift + 9' -- Hotbar Row #4 Col #9
62+
keybinds.R4.C10 = 'Shift + 0' -- Hotbar Row #4 Col #10
63+
keybinds.R4.C11 = 'Shift + -' -- Hotbar Row #4 Col #11
64+
keybinds.R4.C12 = 'Shift + EQ' -- Hotbar Row #4 Col #12
65+
keybinds.R5 = {}
66+
keybinds.R5.C01 = 'Shift + q' -- Hotbar Row #5 Col #1
67+
keybinds.R5.C02 = 'Shift + w' -- Hotbar Row #5 Col #2
68+
keybinds.R5.C03 = 'Shift + e' -- Hotbar Row #5 Col #3
69+
keybinds.R5.C04 = 'Shift + r' -- Hotbar Row #5 Col #4
70+
keybinds.R5.C05 = 'Shift + t' -- Hotbar Row #5 Col #5
71+
keybinds.R5.C06 = 'Shift + y' -- Hotbar Row #5 Col #6
72+
keybinds.R5.C07 = 'Shift + u' -- Hotbar Row #5 Col #7
73+
keybinds.R5.C08 = 'Shift + i' -- Hotbar Row #5 Col #8
74+
keybinds.R5.C09 = 'Shift + o' -- Hotbar Row #5 Col #9
75+
keybinds.R5.C10 = 'Shift + p' -- Hotbar Row #5 Col #10
76+
keybinds.R5.C11 = 'Shift + [' -- Hotbar Row #5 Col #11
77+
keybinds.R5.C12 = 'Shift + ]' -- Hotbar Row #5 Col #12
78+
keybinds.R6 = {}
79+
keybinds.R6.C01 = 'Alt + q' -- Hotbar Row #6 Col #1
80+
keybinds.R6.C02 = 'Alt + w' -- Hotbar Row #6 Col #2
81+
keybinds.R6.C03 = 'Alt + e' -- Hotbar Row #6 Col #3
82+
keybinds.R6.C04 = 'Alt + r' -- Hotbar Row #6 Col #4
83+
keybinds.R6.C05 = 'Alt + t' -- Hotbar Row #6 Col #5
84+
keybinds.R6.C06 = 'Alt + y' -- Hotbar Row #6 Col #6
85+
keybinds.R6.C07 = 'Alt + u' -- Hotbar Row #6 Col #7
86+
keybinds.R6.C08 = 'Alt + i' -- Hotbar Row #6 Col #8
87+
keybinds.R6.C09 = 'Alt + o' -- Hotbar Row #6 Col #9
88+
keybinds.R6.C10 = 'Alt + p' -- Hotbar Row #6 Col #10
89+
keybinds.R6.C11 = 'Alt + [' -- Hotbar Row #6 Col #11
90+
keybinds.R6.C12 = 'Alt + ]' -- Hotbar Row #6 Col #12
91+
92+
93+
return keybinds

data/keybinds.lua

Lines changed: 0 additions & 194 deletions
This file was deleted.

defaults.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,6 @@ defaults.Controls.ToggleBattleMode = 43
272272

273273
defaults.Dev = {}
274274
defaults.Dev.DevMode = false
275+
defaults.Keybinds = {}
275276

276277
return defaults

lib/action_manager.lua

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ action_manager.hotbar_settings = {}
8989
action_manager.hotbar_settings.max = 1
9090
action_manager.hotbar_settings.active_hotbar = 1
9191
action_manager.hotbar_settings.active_environment = 'battle'
92+
-- tracks usable inventory items for autoitem slots
93+
action_manager.items = {}
9294

9395
_job_fileG = {}
9496
_job_fileG.xivhotbar_keybinds_job = {}
@@ -257,7 +259,29 @@ local function add_action(am, action, environment, hotbar, slot)
257259
status = false
258260
end
259261

260-
am.hotbar[environment]['hotbar_' .. hotbar]['slot_' .. slot] = action
262+
if action.type == 'autoitem' then
263+
-- AUTO ITEM is the only type of action that gets loaded at runtime, as opposed to at parse time,
264+
-- due to the dynamic nature of detecting the items.
265+
local filter = action.action or ""
266+
local item = player:get_item_from_filter(filter)
267+
268+
if item then
269+
local new_action = {
270+
alias = shorten_ability_name(item.name),
271+
type = 'item',
272+
target = item.target,
273+
icon = action.icon,
274+
action = item.name
275+
}
276+
277+
am.hotbar[environment]['hotbar_' .. hotbar]['slot_' .. slot] = new_action
278+
else
279+
-- Couldn't load item, blank out the slot
280+
am.hotbar[environment]['hotbar_' .. hotbar]['slot_' .. slot] = nil
281+
end
282+
else
283+
am.hotbar[environment]['hotbar_' .. hotbar]['slot_' .. slot] = action
284+
end
261285
end
262286
end
263287

@@ -280,20 +304,6 @@ local function reindex_action_table(actions_table)
280304
actions_table.icon = reindex_table(actions_table.icon)
281305
end
282306

283-
local function shorten_ability_name(name)
284-
local function extractConsonants(word)
285-
return word:sub(2):gsub("[aeiouAEIOU]", "") -- Remove vowels from the rest of the word
286-
end
287-
288-
local shortenedName = name:gsub("(%a)([%a]*)", function(firstLetter, restOfWord)
289-
local consonants = extractConsonants(restOfWord)
290-
return firstLetter:upper() .. consonants
291-
end)
292-
293-
-- Keep the result within 6 characters if needed
294-
return shortenedName:sub(1, 6)
295-
end
296-
297307
local function fill_action_table(file_table, file_key, actions_table)
298308
-- Slot_key is 'battle 1 2' in a job/general file.
299309
-- file_table is each slot that contains a list of string. Example (First Key): file_table = {'battle 1 1', 'ma', 'Cure', 'stpc', 'Cure'}
@@ -427,7 +437,7 @@ function action_req_check(action_array)
427437

428438
-- Check if weapon skill is learned.
429439
return is_weaponskill_learned(action_name)
430-
elseif action_type == 'ct' or action_type == 'pet' or action_type == 'input' or action_type == 'macro' or action_type == 'gs' then
440+
elseif action_type == 'ct' or action_type == 'pet' or action_type == 'input' or action_type == 'macro' or action_type == 'gs' or action_type == 'autoitem' then
431441
-- Always allow these action types.
432442
return true
433443
else
@@ -1061,6 +1071,9 @@ end
10611071
-- This function is responsible for actually loading the LUA file definitions
10621072
-- and transforming them to be ready to be mapped to the hotbars.
10631073
function action_manager:load(player)
1074+
-- First time load of the inventory
1075+
player:update_inventory_items()
1076+
10641077
action_manager:init_action_tables() -- Create/Initialize MainJob, SubJob, Stance, Weaponskill, Stance Tables
10651078

10661079
local basepath = windower.addon_path .. 'data/' .. player.name .. '/'

0 commit comments

Comments
 (0)