Added utility scripts for gem data
Kevin Lyles [12-11-10 - 15:43]
Added utility scripts for gem data
diff --git a/.gitignore b/.gitignore
index 45a7fe5..1981574 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
Todo
.dotest/
full-item-info
+gem-ids-to-item-info.lua
+inconsistent-gems.lua
diff --git a/create-gem-ids-file.lua b/create-gem-ids-file.lua
new file mode 100644
index 0000000..5955e8a
--- /dev/null
+++ b/create-gem-ids-file.lua
@@ -0,0 +1,67 @@
+local item_info = {}
+
+loadfile("scanned/gem-info.lua")()
+
+local function strsplit(delimiter, subject, pieces)
+ delimiter = string.gsub(delimiter, "([%[%]+?()%%*-])", "%%%1")
+ subject = string.gsub(subject, delimiter, "\a")
+ local iterator = string.gmatch(subject, "[^\a]+")
+ local result = {}
+ if pieces then
+ for i = 1, pieces do
+ table.insert(result, iterator())
+ end
+ else
+ local str = iterator()
+ while str do
+ table.insert(result, str)
+ str = iterator()
+ end
+ end
+ return unpack(result)
+end
+
+local function getPadLength(num)
+ return tostring(num):len()
+end
+
+local function padInteger(num, len)
+ return string.rep("0", len - getPadLength(num)) .. num
+end
+
+i = 0
+local start = padInteger(i, 5)
+local finish = padInteger(i + 999, 5)
+
+local func = loadfile(string.format("scanned/item-info-%s_%s.lua", start, finish))
+while func do
+ func()
+
+ for k, v in pairs(_G[string.format("IS_item_info_%s_%s", start, finish)]) do
+ item_info[k] = v
+ end
+
+ i = i + 1000
+ start = padInteger(i, 5)
+ finish = padInteger(i + 999, 5)
+ func = loadfile(string.format("scanned/item-info-%s_%s.lua", start, finish))
+end
+
+local gem_ids_to_item_info = {}
+
+for gemId, gemInfo in pairs(IS_gem_info) do
+ local _, itemId = strsplit("|", gemInfo[2])
+ local pieces = { strsplit(":", itemId) }
+ pieces[1] = pieces[1]:sub(2)
+ itemId = table.concat(pieces, ":", 1, 10)
+ gem_ids_to_item_info[gemId] = item_info[itemId]
+ if not item_info[itemId] then
+ io.write(string.format("Unhandled item: %s\n", itemId))
+ end
+end
+
+loadfile("sort.lua")()
+
+io.output("gem-ids-to-item-info.lua")
+sort(gem_ids_to_item_info, "gem_ids_to_item_info")
+io.close()
diff --git a/find-inconsistent-gems.lua b/find-inconsistent-gems.lua
new file mode 100644
index 0000000..07e2517
--- /dev/null
+++ b/find-inconsistent-gems.lua
@@ -0,0 +1,62 @@
+loadfile("load-all-item-info.lua")()
+
+local itemText = {}
+
+for itemNum, itemInfo in pairs(item_info) do
+ if itemInfo[1] then
+ local itemName = itemInfo[1].left
+ itemText[itemName] = itemText[itemName] or {}
+ for i = 2, #(itemInfo) do
+ local text = itemInfo[i].left
+ itemText[itemName][text] = itemText[itemName][text] or {}
+ itemText[itemName][text][itemNum] = true
+ end
+ end
+end
+
+local invalidItems = {}
+
+for itemName, text in pairs(itemText) do
+ local shouldCompare = false
+ for line, itemLinks in pairs(text) do
+ if line:find("Matches ") and line:find(" Socket") then
+ shouldCompare = true
+ break
+ end
+ end
+ if shouldCompare then
+ local compareText
+ for line, itemLinks in pairs(text) do
+ if line ~= " " then
+ compareText = line
+ break
+ end
+ end
+ for line, itemLinks in pairs(text) do
+ if line ~= " " then
+ if #(itemLinks) == #(text[compareText]) then
+ for link in pairs(itemLinks) do
+ if not text[compareText][link] then
+ invalidItems[itemName] = text
+ break
+ end
+ end
+ for link in pairs(text[compareText]) do
+ if not itemLinks[link] then
+ invalidItems[itemName] = text
+ break
+ end
+ end
+ else
+ invalidItems[itemName] = text
+ end
+ end
+ end
+ end
+end
+
+loadfile("sort.lua")()
+
+io.output("inconsistent-gems.lua")
+sort(invalidItems, "invalidItems")
+io.close()
diff --git a/update-generated-files.sh b/update-generated-files.sh
new file mode 100755
index 0000000..1cedad7
--- /dev/null
+++ b/update-generated-files.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+lua splice-item-info.lua
+lua create-gem-ids-file.lua
+lua find-inconsistent-gems.lua