Getestet mit: Lua 5.0
Befehl zum Ausführen: cd /usr/.../quest && lua compile_quests.lua
| Screens | |
|
|
|
Ich habe mal ein kleines Lua-Script geschrieben, um den questcompiler anzusprechen. Verwaltet wird das ganze über die Datei quest_list.lua, welche die Pfade zu den Quests beinhaltet.
Wenn ihr Keys setzt, wie im Beispiel zu sehen, könnt ihr auch einzelne Kategorien compilen, z.B. alle Quests in der Kategorie Biologe.
Beispiel quest_list.lua:
Code:
quest_list = {
["Biologe"] = {
["Biologe1"] = "biologe1.quest",
["Biologe2"] = {
"biologe2_1.quest",
"biologe2_2.quest"
},
"biologe.quest"
},
["Dt"] = "deviltowerzone.quest"
}
Das Script (compile_quests.lua)
Code:
local qcname = "qc_x64"
local luaquest_list = "quest_list.lua"
--[[
#########################
####### Functions #######
#########################
]]
local println = function(text)
io.write(text.."\n")
end
local function file_exists(name)
return os.rename(name, name)
end
-- ##################################################
-- Check if required files exist
if not file_exists(qcname) then
println("Can't find the qc: "..qcname)
io.flush()
return
elseif not file_exists(luaquest_list) then
println("Can't find the quest_list: "..luaquest_list)
io.flush()
return
end
-- Chekc if required files exist end
-- ##################################################
local function in_list(compare, list)
for _,v in ipairs(list) do
if compare == v then return true end
end
return false
end
local function compile(dir)
println("Compiling: "..dir)
os.execute("./"..qcname.." "..dir)
end
local function compile_tbl(value)
if type(value) == "string" then
compile(value)
return
end
for k,v in pairs(value) do
if type(v) == "table" then
compile_tbl(v)
else
compile(v)
end
end
end
local function compile_all()
os.execute("rm -R object")
compile_tbl(quest_list)
end
--[[
#####################
####### Menus #######
#####################
]]
local function compile_by_directory_menu()
println("")
println("What's the directory of the quest you want to compile?")
io.flush()
local dir = io.read()
if not file_exists(dir) then
local answer = ""
local possible_answers = {"1", "exit"}
repeat
println("")
println("The directory doesnt exist: "..dir)
println(" ("..possible_answers[1]..") new directory")
println(" ("..possible_answers[2]..") exit")
io.flush()
answer = io.read()
until in_list(answer, possible_answers)
if answer == possible_answers[1] then --new directory
compile_by_directory_menu()
return
else
return
end
end
compile(dir)
end
local function compile_by_category_menu(srctable)
println("")
println("What's key to the quest(s) you want to compile?")
io.flush()
local key = io.read()
local result = srctable[key]
if not result then
local answer = ""
local possible_answers = {"1", "exit"}
repeat
println("")
println("Can't find a value matching to the key: "..key)
println(" ("..possible_answers[1]..") new key")
println(" ("..possible_answers[2]..") exit")
io.flush()
answer = io.read()
until in_list(answer, possible_answers)
if answer == possible_answers[1] then --new key
compile_by_category_menu(srctable)
return
else
return
end
elseif type(result) == "table" then
local answer = ""
local possible_answers = {"1", "2", "exit"}
repeat
println("")
println("The value matching to your key is a table")
println(" ("..possible_answers[1]..") compile all quests in this category and it's subcategories")
println(" ("..possible_answers[2]..") go deeper (insert subcategory)")
println(" ("..possible_answers[3]..") exit")
io.flush()
answer = io.read()
until in_list(answer, possible_answers)
if answer == possible_answers[1] then --compile all quests in this category
compile_tbl(result)
return
elseif answer == possible_answers[2] then --go deeper
compile_by_category_menu(result)
return
else
return
end
end
compile_tbl(result)
end
local function main_menu()
local answer = ""
local possible_answers = {"1", "2", "3", "exit"}
repeat
println("What do you want to do?")
println(" ("..possible_answers[1]..") Compile all quests")
println(" ("..possible_answers[2]..") Compile quest(s) by key")
println(" ("..possible_answers[3]..") Compile quest by directory")
println(" ("..possible_answers[4]..") exit")
io.flush()
answer = io.read()
until in_list(answer, possible_answers)
if answer == possible_answers[1] then --compile all quests
compile_all()
elseif answer == possible_answers[2] then --compile all quests by category
compile_by_category_menu(quest_list)
elseif answer == possible_answers[3] then --compile quest by directory
compile_by_directory_menu()
else
return
end
end
--[[
############################
####### Calling menu #######
############################
]]
dofile(luaquest_list)
main_menu()






