-
-
Save RA80533/31b9cff5250f5e187699897713d880ce to your computer and use it in GitHub Desktop.
World of Warcrafts Dungeon Journal Exporter to XML (may cause hangout, use with caution)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local flags = {"tank", "dps", "healer", "heroic", "deadly", "important", "interruptible", "magic", "curse", "poison", "disease", "enrage", "enrage"} | |
local EJ_DIFF_N = 1 | |
local EJ_DIFF_HC = 2 | |
local EJ_DIFF_10 = 3 | |
local EJ_DIFF_25 = 4 | |
local EJ_DIFF_10HC = 5 | |
local EJ_DIFF_25HC = 6 | |
local EJ_DIFF_LFR = 7 | |
local EJ_DIFF_CHA = 8 | |
local EJ_DIFF_40 = 9 | |
local EJ_DIFF_SCE = 11 | |
local EJ_DIFF_SCEHC = 12 | |
local EJ_DIFF_FLE = 14 | |
local EJ_SelectInstance, EJ_GetInstanceInfo, EJ_GetEncounterInfo, EJ_GetEncounterInfoByIndex, EJ_InstanceIsRaid, EJ_GetSectionInfo, EJ_SetDifficulty = EJ_SelectInstance, EJ_GetInstanceInfo, EJ_GetEncounterInfo, EJ_GetEncounterInfoByIndex, EJ_InstanceIsRaid, EJ_GetSectionInfo, EJ_SetDifficulty | |
local tcon = table.concat | |
local function stringify(s) | |
if s == nil then return "" | |
elseif type(s) == "boolean" then return s and "true" or "false" | |
elseif type(s) ~= "string" then return ""..s | |
else return s end | |
end | |
local function escapeA(s) | |
s = stringify(s) | |
return s:gsub("&","&"):gsub("\"","""):gsub("\n"," "); | |
end | |
local function escapeE(s) | |
s = stringify(s) | |
return s:gsub("&","&"):gsub("<","<") | |
end | |
local function processMarkup(s) | |
s = s:gsub("|T([^:]*):%d+:%d+:%d+:%d+|t", "<icon src=\"%1\"/>") | |
s = s:gsub("|CFF(......)([^|]*)|r", "<color color=\"#%1\">%2</color>") | |
return s | |
end | |
local function getSectionModes(sectionId) | |
EJ_SetDifficulty(EJ_DIFF_N) | |
local _, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local n = not filtered | |
EJ_SetDifficulty(EJ_DIFF_HC) | |
_, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local hc = not filtered | |
EJ_SetDifficulty(EJ_DIFF_10) | |
_, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local n10 = not filtered | |
EJ_SetDifficulty(EJ_DIFF_25) | |
_, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local n25 = not filtered | |
EJ_SetDifficulty(EJ_DIFF_10HC) | |
_, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local h10 = not filtered | |
EJ_SetDifficulty(EJ_DIFF_25HC) | |
_, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local h25 = not filtered | |
EJ_SetDifficulty(EJ_DIFF_LFR) | |
_, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local lfr = not filtered | |
EJ_SetDifficulty(EJ_DIFF_FLE) | |
_, _, _, _, _, _, _, filtered = EJ_GetSectionInfo(sectionId) | |
local fle = not filtered | |
--[[ | |
local s | |
if h25 and h10 and n25 and n10 then s = "all" | |
elseif h25 and h10 and not n25 and not n10 then s = "heroic only" | |
elseif n25 and n10 and not h25 and not h10 then s = "normal only" | |
elseif h25 and n25 and not h10 and not n10 then s = "25-man only" | |
elseif h10 and n10 and not h25 and not n20 then s = "10-man only" | |
elseif h25 and not n25 and not h10 and not n10 then s = "25-man heroic only" | |
elseif h10 and not n10 and not h25 and not n25 then s = "10-man heroic only" | |
elseif n25 and not h25 and not h10 and not n10 then s = "25-man normal only" | |
elseif n10 and not h10 and not h25 and not n25 then s = "10-man normal only" | |
elseif h25 and n25 and h10 and not n10 then s = "not in 10-man normal" | |
elseif not h25 and not n25 and not h10 and not n10 then s = "not used" | |
else | |
s = "" | |
if h25 then s = s.." h25" end | |
if n25 then s = s.." n25" end | |
if h10 then s = s.." h10" end | |
if n10 then s = s.." n10" end | |
if fle then s = s.." flex" end | |
s = s:sub(2) | |
end | |
--]] | |
return 25, n25, h10, n10, lfr, fle | |
end | |
local function findInstanceByName(name, isRaid) | |
if isRaid == nil then | |
local id = findInstanceByName(name, true) | |
if not id then id = findInstanceByName(name, false) end | |
return id | |
end | |
local i = 1 | |
local instanceId,instanceName = EJ_GetInstanceByIndex(i, isRaid) | |
name = name:lower() | |
while instanceId do | |
if name == instanceName:lower() then return instanceId end | |
i = i + 1 | |
instanceId, instanceName = EJ_GetInstanceByIndex(i, isRaid) | |
end | |
return nil | |
end | |
local function exportSectionDescription(sectionId, mode, prefix) | |
EJ_SetDifficulty(mode) | |
local title, description = EJ_GetSectionInfo(sectionId) | |
local s = "" | |
if mode == EJ_DIFF_N then s = "N" | |
elseif mode == EJ_DIFF_HC then s = "HC" | |
elseif mode == EJ_DIFF_10 then s = "10" | |
elseif mode == EJ_DIFF_25 then s = "25" | |
elseif mode == EJ_DIFF_10HC then s = "10HC" | |
elseif mode == EJ_DIFF_25HC then s = "25HC" | |
elseif mode == EJ_DIFF_LFR then s = "LFR" | |
elseif mode == EJ_DIFF_CHA then s = "CHA" | |
elseif mode == EJ_DIFF_40 then s = "40" | |
elseif mode == EJ_DIFF_SCE then s = "SCE" | |
elseif mode == EJ_DIFF_SCEHC then s = "SCEHC" | |
elseif mode == EJ_DIFF_FLE then s = "FLEX" end | |
description=processMarkup(escapeE(description)) | |
return string.format(prefix.." <description mode=\"%s\">%s</description>\n", s, description) | |
end | |
local function exportSection(sectionId, prefix) | |
local h25, n25, h10, n10, lfr, fle=getSectionModes(sectionId) | |
EJ_SetDifficulty(EJ_DIFF_25) | |
local title, description, depth, abilityIcon, displayInfo, siblingId, nextSectionId, | |
filteredByDifficulty, link, startsOpen, flag1, flag2, flag3, flag4 = EJ_GetSectionInfo(sectionId) | |
local data={} | |
data[#data+1]=string.format(prefix.."<section sectionid=\"%s\"", escapeA(sectionId)) | |
if abilityIcon and abilityIcon~="" then | |
data[#data+1]=string.format(" abilityIcon=\"%s\"", escapeA(abilityIcon)) | |
end | |
if flag1 then data[#data+1]=string.format(" flag_%s=\"1\"", flags[flag1+1]) end | |
if flag2 then data[#data+1]=string.format(" flag_%s=\"1\"", flags[flag2+1]) end | |
if flag3 then data[#data+1]=string.format(" flag_%s=\"1\"", flags[flag3+1]) end | |
if flag4 then data[#data+1]=string.format(" flag_%s=\"1\"", flags[flag4+1]) end | |
--if modes~="all" then | |
--data[#data+1]=string.format(" modes=\"%s\"", escapeA(modes)) | |
--end | |
data[#data+1]=">\n" | |
data[#data+1]=string.format(prefix.." <title>%s</title>\n", escapeE(title)) | |
if n10 then data[#data+1]=exportSectionDescription(sectionId, EJ_DIFF_10, prefix) end | |
if n25 then data[#data+1]=exportSectionDescription(sectionId, EJ_DIFF_25, prefix) end | |
if h10 then data[#data+1]=exportSectionDescription(sectionId, EJ_DIFF_10HC, prefix) end | |
if h25 then data[#data+1]=exportSectionDescription(sectionId, EJ_DIFF_25HC, prefix) end | |
if lfr then data[#data+1]=exportSectionDescription(sectionId, EJ_DIFF_LFR, prefix) end | |
if fle then data[#data+1]=exportSectionDescription(sectionId, EJ_DIFF_FLE, prefix) end | |
--description=processMarkup(escapeE(description)) | |
--data[#data+1]=string.format(prefix.." <description>%s</description>\n", description) | |
if nextSectionId then | |
data[#data+1]=prefix.."<sections>\n" | |
data[#data+1]=exportSection(nextSectionId, prefix.." ") | |
data[#data+1]=prefix.."</sections>\n" | |
end | |
data[#data+1]=prefix.."</section>\n" | |
if siblingId then | |
data[#data+1]=exportSection(siblingId, prefix) | |
end | |
return tcon(data) | |
end | |
local function exportCreature(creatureIndex) | |
local creatureId,creatureName,creatureDescription,displayInfo,icon=EJ_GetCreatureInfo(creatureIndex) | |
local data={} | |
data[#data+1]=string.format(" <creature creatureid=\"%s\">\n", escapeA(creatureId)) | |
data[#data+1]=string.format(" <name>%s</name>\n", escapeE(creatureName)) | |
data[#data+1]=" </creature>\n" | |
return tcon(data); | |
end | |
local function exportEncounter(encounterId) | |
EJ_SelectEncounter(encounterId) | |
local encounterName, encounterDesc, _, rootSectionId = EJ_GetEncounterInfo(encounterId) | |
local data={} | |
data[#data+1]=string.format(" <encounter encounterid=\"%s\">\n", escapeA(encounterId)) | |
data[#data+1]=string.format(" <name>%s</name>\n", escapeE(encounterName)) | |
data[#data+1]=string.format(" <description>%s</description>\n", escapeE(encounterDesc)) | |
data[#data+1]=" <sections>\n"; | |
data[#data+1]=exportSection(rootSectionId, " ") | |
data[#data+1]=" </sections>\n"; | |
data[#data+1]=" <creatures>\n"; | |
local i = 1 | |
repeat | |
local _, name = EJ_GetCreatureInfo(i) | |
if name ~= nil then | |
data[#data+1]=exportCreature(i) | |
end | |
i = i + 1 | |
until name == nil | |
data[#data+1]=" </creatures>\n"; | |
data[#data+1]=" </encounter>\n" | |
return tcon(data) | |
end | |
local function exportInstance(instanceId) | |
EJ_SelectInstance(instanceId) | |
local instanceName, instanceDesc = EJ_GetInstanceInfo() | |
local data={} | |
data[#data+1]=string.format(" <instance instanceid=\"%s\">\n", escapeA(instanceId)) | |
data[#data+1]=string.format(" <name>%s</name>\n", escapeE(instanceName)) | |
data[#data+1]=string.format(" <description>%s</description>\n", escapeE(instanceDesc)) | |
data[#data+1]=" <encounters>\n" | |
local i = 14 | |
repeat | |
name, _, encounterId = EJ_GetEncounterInfoByIndex(i) | |
if name ~= nil then | |
data[#data+1]=exportEncounter(encounterId) | |
end | |
i = i + 1 | |
--until true | |
until name == nil | |
data[#data+1]=" </encounters>\n" | |
data[#data+1]=" </instance>\n" | |
return tcon(data) | |
end | |
local function export() | |
data = {} | |
data[#data+1]="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" | |
data[#data+1]="<instances>\n" | |
data[#data+1]=exportInstance(findInstanceByName("Siege of Orgrimmar")) | |
data[#data+1]="</instances>\n" | |
return tcon(data) | |
end | |
local function showText(s) | |
local AceGUI=LibStub("AceGUI-3.0") | |
local f=AceGUI:Create("Frame") | |
f:SetTitle("Encounter journal export") | |
f:SetLayout("Fill") | |
f:SetCallback('OnClose',function(widget) | |
AceGUI:Release(widget) | |
end) | |
local edit= AceGUI:Create("MultiLineEditBox") | |
edit:SetLabel("Copy this to clipboard") | |
edit:SetText(s) | |
edit.editBox:HighlightText() | |
local isAutoFocus=edit.editBox:IsAutoFocus() | |
edit.editBox:SetAutoFocus(true) | |
edit:SetCallback("OnRelease",function() edit.editBox:SetAutoFocus(isAutoFocus) end) | |
f:AddChild(edit) | |
f:Show() | |
end | |
showText(export()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment