1 QuestHelper_File
["db_get.lua"] = "Development Version"
2 QuestHelper_Loadtime
["db_get.lua"] = GetTime()
8 local QHDB = QHDB_temp]]
9 QuestHelper
: Assert(#QHDB
== 4)
11 local weak_v
= { __mode
= 'v' }
12 local weak_k
= { __mode
= 'k' }
16 local frequencies
= setmetatable({}, weak_k
)
18 -- guhhh just want this to work
19 local freq_group
= setmetatable({}, weak_k
)
20 local freq_id
= setmetatable({}, weak_k
)
22 local function DBC_Get(group
, id
)
23 if not cache
[group
] then return end
24 return cache
[group
][id
]
27 local function DBC_Put(group
, id
, item
)
28 if not cache
[group
] then cache
[group
] = setmetatable({}, weak_v
) end
29 QuestHelper
: Assert(not cache
[group
][id
])
30 cache
[group
][id
] = item
32 --DB_how_many_are_used()
35 local function mark(tab
, tomark
)
36 for k
, v
in pairs(tab
) do
37 if type(v
) == "table" then
46 QuestHelper
: Assert(not initted
)
47 for _
, db
in ipairs(QHDB
) do
48 for _
, v
in pairs(db
) do
49 --print("db", not not v.__dictionary, not not v.__tokens)
50 if v
.__dictionary
and v
.__tokens
then
51 local redictix
= v
.__dictionary
52 if not redictix
:find("\"") then redictix
= redictix
.. "\"" end
53 if not redictix
:find(",") then redictix
= redictix
.. "," end
54 if not redictix
:find("\\") then redictix
= redictix
.. "\\" end
55 local tokens
= loadstring("return {" .. QH_LZW_Decompress_Dicts_Arghhacky(v
.__tokens
, redictix
) .. "}")()
56 QuestHelper
: Assert(tokens
)
58 local _
, _
, prep
= QH_LZW_Prepare_Arghhacky(v
.__dictionary
, tokens
)
59 QuestHelper
: Assert(prep
)
61 QuestHelper
: Assert(type(prep
) == "table")
74 function DB_GetItem(group
, id
, silent
, register
)
75 QuestHelper
: Assert(initted
)
77 QuestHelper
: Assert(group
, string.format("%s %s", tostring(group
), tostring(id
)))
78 QuestHelper
: Assert(id
, string.format("%s %s", tostring(group
), tostring(id
)))
79 local ite
= DBC_Get(group
, id
)
81 if type(id
) == "string" then QuestHelper
: Assert(not id
:match("__.*")) end
83 --QuestHelper:TextOut(string.format("%s %d", group, id))
85 for _
, db
in ipairs(QHDB
) do
86 --print(db, db[group], db[group] and db[group][id], type(group), type(id))
87 if db
[group
] and db
[group
][id
] then
88 if not ite
then ite
= QuestHelper
:CreateTable("db") end
92 if type(db
[group
][id
]) == "string" then
93 QuestHelper
: Assert(db
[group
].__tokens
== nil or type(db
[group
].__tokens
) == "table")
94 srctab
= loadstring("return {" .. QH_LZW_Decompress_Dicts_Prepared_Arghhacky(db
[group
][id
], db
[group
].__dictionary
, nil, db
[group
].__tokens
) .. "}")()
95 elseif type(db
[group
][id
]) == "table" then
96 srctab
= db
[group
][id
]
101 for k
, v
in pairs(srctab
) do
102 QuestHelper
: Assert(not ite
[k
])
112 DBC_Put(group
, id
, ite
)
114 freq_group
[ite
] = group
118 QuestHelper
:TextOut(string.format("Tried to get %s/%s, failed", tostring(group
), tostring(id
)))
124 frequencies
[ite
] = (frequencies
[ite
] or 0) + (register
and 1 or 1000000000) -- effectively infinity
130 local function incinerate(ite
, crunchy
)
131 if not crunchy
[ite
] then
134 for k
, v
in pairs(ite
) do
135 if type(k
) == "table" then incinerate(k
, crunchy
) end
136 if type(v
) == "table" then incinerate(v
, crunchy
) end
141 function DB_ReleaseItem(ite
)
142 QuestHelper
: Assert(ite
)
143 frequencies
[ite
] = frequencies
[ite
] - 1
145 if frequencies
[ite
] == 0 then
146 --print("incinerating", freq_group[ite], freq_id[ite])
147 cache
[freq_group
[ite]]
[freq_id
[ite]]
= nil
148 freq_group
[ite
] = nil
151 local incin
= QuestHelper
:CreateTable("incinerate")
152 incinerate(ite
, incin
)
153 for k
, _
in pairs(incin
) do
154 QuestHelper
:ReleaseTable(k
)
155 end -- burn baby burn
156 QuestHelper
:ReleaseTable(incin
)
160 function DB_ListItems(group
)
162 for _
, db
in ipairs(QHDB
) do
163 if db
[group
] then for k
, _
in pairs(db
[group
]) do
164 if type(k
) ~= "string" or not k
:match("__.*") then
171 for k
, _
in pairs(tab
) do
178 function DB_how_many_are_used()
180 for k
, v
in pairs(cache
) do
181 for k2
, v2
in pairs(v
) do
188 function DB_DumpItems()
190 for k
, v
in pairs(freq_group
) do
191 dt
[string.format("%s/%s", freq_group
[k
], tostring(freq_id
[k
]))] = true