Skip to content

Commit

Permalink
Merge pull request #60 from mrthinger/rename-lookup-tables
Browse files Browse the repository at this point in the history
Rename lookup tables & minor tweaks
  • Loading branch information
mrthinger authored Apr 12, 2023
2 parents 7730c08 + 777a8f9 commit e7fc3c6
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 109 deletions.
32 changes: 26 additions & 6 deletions AI_VoiceOver/Common/DataModules.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
setfenv(1, VoiceOver)

local CURRENT_MODULE_VERSION = 1
local FORCE_ENABLE_DISABLED_MODULES = true
local LOAD_ALL_MODULES = true

DataModules =
Expand Down Expand Up @@ -59,7 +60,7 @@ function DataModules:EnumerateAddons()
local playerName = UnitName("player")
for i = 1, GetNumAddOns() do
local moduleVersion = tonumber(GetAddOnMetadata(i, "X-VoiceOver-DataModule-Version"))
if moduleVersion and GetAddOnEnableState(playerName, i) ~= 0 then
if moduleVersion and (FORCE_ENABLE_DISABLED_MODULES or GetAddOnEnableState(playerName, i) ~= 0) then
local name = GetAddOnInfo(i)
local mapsString = GetAddOnMetadata(i, "X-VoiceOver-DataModule-Maps")
local maps = {}
Expand All @@ -86,7 +87,7 @@ function DataModules:EnumerateAddons()

-- Maybe in the future we can load modules based on the map the player is in (select(8, GetInstanceInfo())), but for now - just load everything
if LOAD_ALL_MODULES and IsAddOnLoadOnDemand(name) then
LoadAddOn(name)
DataModules:LoadModule(module)
end
end
end
Expand All @@ -97,8 +98,27 @@ function DataModules:EnumerateAddons()
end
end

function DataModules:LoadModule(module)
if not module.LoadOnDemand or self:GetModule(module.AddonName) or IsAddOnLoaded(module.AddonName) then
return false
end

if FORCE_ENABLE_DISABLED_MODULES and GetAddOnEnableState(UnitName("player"), module.AddonName) == 0 then
EnableAddOn(module.AddonName)
end

-- We deliberately use a high ##Interface version in TOC to ensure that all clients will load it.
-- Otherwise pre-classic-rerelease clients will refuse to load addons with version < 20000.
-- Here we temporarily enable "Load out of date AddOns" to load the module, and restore the user's setting afterwards.
local oldLoadOutOfDateAddons = GetCVar("checkAddonVersion")
SetCVar("checkAddonVersion", 0)
local loaded = LoadAddOn(module.AddonName)
SetCVar("checkAddonVersion", oldLoadOutOfDateAddons)
return loaded
end

function DataModules:GetNPCGossipTextHash(soundData)
local table = soundData.unitGUID and "NPCToTextToTemplateHash" or "GossipLookup"
local table = soundData.unitGUID and "GossipLookupByNPCID" or "GossipLookupByNPCName"
local npc = soundData.unitGUID and Utils:GetIDFromGUID(soundData.unitGUID) or soundData.name
local text = soundData.text

Expand Down Expand Up @@ -193,7 +213,7 @@ end

function DataModules:GetQuestLogNPCID(questID)
for _, module in self:GetModules() do
local data = module.QuestlogNpcGuidTable
local data = module.NPCIDLookupByQuestID
if data then
local npcID = data[questID]
if npcID then
Expand All @@ -205,7 +225,7 @@ end

function DataModules:GetNPCName(npcID)
for _, module in self:GetModules() do
local data = module.NPCNameLookup
local data = module.NPCNameLookupByNPCID
if data then
local npcName = data[npcID]
if npcName then
Expand Down Expand Up @@ -239,7 +259,7 @@ function DataModules:PrepareSound(soundData)
end

for _, module in self:GetModules() do
local data = module.SoundLengthTable
local data = module.SoundLengthLookupByFileName
if data then
local playerGenderedFileName = DataModules:AddPlayerGenderToFilename(soundData.fileName)
if data[playerGenderedFileName] then
Expand Down
4 changes: 2 additions & 2 deletions AI_VoiceOver/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function Options:AddDataModule(module, order)
end

local name, title, notes, loadable, reason = GetAddOnInfo(module.AddonName)
if reason == "DEMAND_LOADED" then
if reason == "DEMAND_LOADED" or reason == "INTERFACE_VERSION" then
reason = nil
end
DataModulesTab.args[module.AddonName] = {
Expand Down Expand Up @@ -419,7 +419,7 @@ function Options:AddDataModule(module, order)
name = "Load",
hidden = function() return reason or not module.LoadOnDemand or DataModules:GetModule(module.AddonName) end,
func = function()
LoadAddOn(module.AddonName)
DataModules:LoadModule(module)
end,
},
}
Expand Down
2 changes: 1 addition & 1 deletion AI_VoiceOver/VoiceOver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local defaults = {
Audio = {
GossipFrequency = Enums.GossipFrequency.OncePerQuestNPC,
SoundChannel = Enums.SoundChannel.Master,
AutoToggleDialog = false,
AutoToggleDialog = true,
},
MinimapButton = {
LibDBIcon = {}, -- Table used by LibDBIcon to store position (minimapPos), dragging lock (lock) and hidden state (hide)
Expand Down
32 changes: 26 additions & 6 deletions AI_VoiceOver_112/Common/DataModules.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
setfenv(1, VoiceOver)

local CURRENT_MODULE_VERSION = 1
local FORCE_ENABLE_DISABLED_MODULES = true
local LOAD_ALL_MODULES = true

DataModules =
Expand Down Expand Up @@ -59,7 +60,7 @@ function DataModules:EnumerateAddons()
local playerName = UnitName("player")
for i = 1, GetNumAddOns() do
local moduleVersion = tonumber(GetAddOnMetadata(i, "X-VoiceOver-DataModule-Version"))
if moduleVersion and GetAddOnEnableState(playerName, i) ~= 0 then
if moduleVersion and (FORCE_ENABLE_DISABLED_MODULES or GetAddOnEnableState(playerName, i) ~= 0) then
local name = GetAddOnInfo(i)
local mapsString = GetAddOnMetadata(i, "X-VoiceOver-DataModule-Maps")
local maps = {}
Expand All @@ -86,7 +87,7 @@ function DataModules:EnumerateAddons()

-- Maybe in the future we can load modules based on the map the player is in (select(8, GetInstanceInfo())), but for now - just load everything
if LOAD_ALL_MODULES and IsAddOnLoadOnDemand(name) then
LoadAddOn(name)
DataModules:LoadModule(module)
end
end
end
Expand All @@ -97,8 +98,27 @@ function DataModules:EnumerateAddons()
-- end
end

function DataModules:LoadModule(module)
if not module.LoadOnDemand or self:GetModule(module.AddonName) or IsAddOnLoaded(module.AddonName) then
return false
end

if FORCE_ENABLE_DISABLED_MODULES and GetAddOnEnableState(UnitName("player"), module.AddonName) == 0 then
EnableAddOn(module.AddonName)
end

-- We deliberately use a high ##Interface version in TOC to ensure that all clients will load it.
-- Otherwise pre-classic-rerelease clients will refuse to load addons with version < 20000.
-- Here we temporarily enable "Load out of date AddOns" to load the module, and restore the user's setting afterwards.
local oldLoadOutOfDateAddons = GetCVar("checkAddonVersion")
SetCVar("checkAddonVersion", 0)
local loaded = LoadAddOn(module.AddonName)
SetCVar("checkAddonVersion", oldLoadOutOfDateAddons)
return loaded
end

function DataModules:GetNPCGossipTextHash(soundData)
local table = soundData.unitGUID and "NPCToTextToTemplateHash" or "GossipLookup"
local table = soundData.unitGUID and "GossipLookupByNPCID" or "GossipLookupByNPCName"
local npc = soundData.unitGUID and Utils:GetIDFromGUID(soundData.unitGUID) or soundData.name
local text = soundData.text

Expand Down Expand Up @@ -193,7 +213,7 @@ end

function DataModules:GetQuestLogNPCID(questID)
for _, module in self:GetModules() do
local data = module.QuestlogNpcGuidTable
local data = module.NPCIDLookupByQuestID
if data then
local npcID = data[questID]
if npcID then
Expand All @@ -205,7 +225,7 @@ end

function DataModules:GetNPCName(npcID)
for _, module in self:GetModules() do
local data = module.NPCNameLookup
local data = module.NPCNameLookupByNPCID
if data then
local npcName = data[npcID]
if npcName then
Expand Down Expand Up @@ -239,7 +259,7 @@ function DataModules:PrepareSound(soundData)
end

for _, module in self:GetModules() do
local data = module.SoundLengthTable
local data = module.SoundLengthLookupByFileName
if data then
local playerGenderedFileName = DataModules:AddPlayerGenderToFilename(soundData.fileName)
if data[playerGenderedFileName] then
Expand Down
4 changes: 2 additions & 2 deletions cli-main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
from prompt_toolkit.shortcuts import checkboxlist_dialog, radiolist_dialog, message_dialog, yes_no_dialog
from tts_cli.sql_queries import get_gossip_dataframe, get_quest_dataframe, query_dataframe_for_all_quests_and_gossip, query_dataframe_for_area
from prompt_toolkit.shortcuts import checkboxlist_dialog, radiolist_dialog, yes_no_dialog
from tts_cli.sql_queries import query_dataframe_for_all_quests_and_gossip, query_dataframe_for_area
from tts_cli.tts_utils import TTSProcessor
from tts_cli.init_db import download_and_extract_latest_db_dump, import_sql_files_to_database
from tts_cli.consts import RACE_DICT_INV, GENDER_DICT_INV, race_gender_tuple_to_strings
Expand Down
2 changes: 1 addition & 1 deletion tts_cli/length_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def write_sound_length_table_lua(module_name: str, sound_folder_path: str, outpu
# Write the dictionary to the output file in Lua table format
with open(output_folder_path + '/sound_length_table.lua', "w") as f:
f.write(DATAMODULE_TABLE_GUARD_CLAUSE + "\n")
f.write(f"{module_name}.SoundLengthTable = {{\n")
f.write(f"{module_name}.SoundLengthLookupByFileName = {{\n")
for key, value in soundDict.items():
f.write(f" [\"{key}\"] = {value},\n")
f.write("}\n")
87 changes: 0 additions & 87 deletions tts_cli/sql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,93 +12,6 @@ def make_connection():
)


def get_gossip_dataframe():
db = make_connection()
sql_query = '''
SELECT DISTINCT
cdie.DisplayRaceID,
cdie.DisplaySexID,
creature.id,
ct.name,
IF(cdie.DisplaySexID = 0, bt.male_text, bt.female_text) AS text
FROM creature
JOIN creature_template ct ON creature.id = ct.entry
JOIN gossip_menu gm ON ct.gossip_menu_id = gm.entry
JOIN npc_text nt ON gm.text_id = nt.ID
JOIN broadcast_text bt ON nt.BroadcastTextID0 = bt.entry
JOIN db_CreatureDisplayInfo cdi ON ct.display_id1 = cdi.ID
JOIN db_CreatureDisplayInfoExtra cdie ON cdi.ExtendedDisplayInfoID = cdie.ID
WHERE
creature.map = 1
AND (cdie.DisplayRaceID = 2 OR cdie.DisplayRaceID = 8 OR cdie.DisplayRaceID = 6 OR cdie.DisplayRaceID = 9)
AND creature.position_x > -1000 AND creature.position_x < 2000
AND creature.position_y > -5500 AND creature.position_y < -1000
AND (
(cdie.DisplaySexID = 0 AND bt.male_text IS NOT NULL AND bt.male_text != '')
OR (cdie.DisplaySexID = 1 AND bt.female_text IS NOT NULL AND bt.female_text != '')
);
'''

gossip_df = pd.read_sql_query(sql_query, db)
db.close()

return gossip_df


def get_quest_dataframe():
db = make_connection()

sql_query = '''
WITH quest_relations AS (
SELECT 'accept' as source, qr.quest, creature.id as creature_id, creature.position_x, creature.position_y, creature.map
FROM creature
JOIN creature_questrelation qr ON qr.id = creature.id
UNION ALL
SELECT 'complete' as source, qr.quest, creature.id as creature_id, creature.position_x, creature.position_y, creature.map
FROM creature
JOIN creature_involvedrelation qr ON qr.id = creature.id
UNION ALL
SELECT 'progress' as source, qr.quest, creature.id as creature_id, creature.position_x, creature.position_y, creature.map
FROM creature
JOIN creature_involvedrelation qr ON qr.id = creature.id
)
SELECT
distinct
qr.source,
qr.quest,
CASE
WHEN qr.source = 'accept' THEN qt.Details
WHEN qr.source = 'progress' THEN qt.RequestItemsText
ELSE qt.OfferRewardText
END as "text",
cdie.DisplayRaceID,
cdie.DisplaySexID,
ct.name,
qr.creature_id as id
FROM
quest_relations qr
JOIN quest_template qt ON qr.quest = qt.entry
JOIN creature_template ct ON qr.creature_id = ct.entry
JOIN db_CreatureDisplayInfo cdi ON ct.display_id1 = cdi.ID
JOIN db_CreatureDisplayInfoExtra cdie ON cdi.ExtendedDisplayInfoID = cdie.ID
where
qr.map = 1
AND (cdie.DisplayRaceID = 2 OR cdie.DisplayRaceID = 8 OR cdie.DisplayRaceID = 6 OR cdie.DisplayRaceID = 9)
and qr.position_x > -1000 and qr.position_x < 2000
and qr.position_y > -5500 and qr.position_y < -1000
AND (
(qr.source = 'accept' AND qt.Details IS NOT NULL AND qt.Details != '')
OR (qr.source = 'progress' AND qt.RequestItemsText IS NOT NULL AND qt.RequestItemsText != '')
OR (qr.source = 'complete' AND qt.OfferRewardText IS NOT NULL AND qt.OfferRewardText != '')
);
'''

quest_df = pd.read_sql_query(sql_query, db)
db.close()

return quest_df


def query_dataframe_for_area(x_range, y_range, map_id):
db = make_connection()
sql_query = '''
Expand Down
8 changes: 4 additions & 4 deletions tts_cli/tts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def write_gossip_file_lookups_table(self, df, module_name):

with open(output_file, "w") as f:
f.write(DATAMODULE_TABLE_GUARD_CLAUSE + "\n")
f.write(f"{module_name}.NPCToTextToTemplateHash = ")
f.write(f"{module_name}.GossipLookupByNPCID = ")
f.write(lua.encode(gossip_table))
f.write("\n")

Expand All @@ -246,7 +246,7 @@ def write_questlog_npc_lookups_table(self, df, module_name):

with open(output_file, "w") as f:
f.write(DATAMODULE_TABLE_GUARD_CLAUSE + "\n")
f.write(f"{module_name}.QuestlogNpcGuidTable = ")
f.write(f"{module_name}.NPCIDLookupByQuestID = ")
f.write(lua.encode(questlog_table))
f.write("\n")

Expand All @@ -260,7 +260,7 @@ def write_npc_name_lookup_table(self, df, module_name):

with open(output_file, "w") as f:
f.write(DATAMODULE_TABLE_GUARD_CLAUSE + "\n")
f.write(f"{module_name}.NPCNameLookup = ")
f.write(f"{module_name}.NPCNameLookupByNPCID = ")
f.write(lua.encode(npc_name_table))
f.write("\n")

Expand Down Expand Up @@ -323,7 +323,7 @@ def write_npc_name_gossip_file_lookups_table(self, df, module_name):

with open(output_file, "w") as f:
f.write(DATAMODULE_TABLE_GUARD_CLAUSE + "\n")
f.write(f"{module_name}.GossipLookup = ")
f.write(f"{module_name}.GossipLookupByNPCName = ")
f.write(lua.encode(gossip_table))
f.write("\n")

Expand Down

0 comments on commit e7fc3c6

Please sign in to comment.