[Release] Lua Questcompiling Script

07/25/2015 16:08 rollback#1
Benötigt: Lua Installation
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"
}
beachtet hierbei, dass die Keys (z.B. "Biologe", "Biologe1") nichts mit der Ordnerstruktur zu tun haben müssen!

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()
07/25/2015 16:08 Yiv#2
Wie gesagt, du hast viel zu viel Zeit.
Dennoch danke dafür :o

MfG
07/25/2015 16:14 x3PrInZpIx3#3
Ich muss ehrlich gesagt sagen, dass ich den Sinn daran nicht ganz verstehe :/
07/25/2015 16:19 rollback#4
Quote:
Originally Posted by x3PrInZpIx3 View Post
Ich muss ehrlich gesagt sagen, dass ich den Sinn daran nicht ganz verstehe :/
Du kannst deine Quests in der quest_list in Kategorien unterteilen und diese Kategorien einzeln compilen.

Beispiel:
Du hast eine Änderung an einer Funktion gemacht, die nur Dungeons betrifft, und möchtest nicht alle Quests neu compilen sondern nur die Dungeons.
Dann machst du eine Kategorie mit "Dungeons" und schreibst dort alle Verweise zu Dungone-Quests rein und kannst mit dem Script alle Quests aus der Kategorie compilen lassen.
07/25/2015 16:36 .K0rí#5
Schicke Idee. Ich habe sowas ähnliches in Python aber da kann ich mir ja mal was abschauen da es mit den Kategorien sehr Interessant ist :D
07/25/2015 17:09 ..ѕιяιυѕѕ¢нωєят#6
Schick Schick :)
07/25/2015 19:44 SinSay#7
Gute arbeit von dir danke! :)
07/26/2015 17:30 deltous'fabius#8
@Sensi schönes Release. Da ich mich mit Lua nicht grade auskenne, könntest du das Script auch ohne Menü zur verfügung stellen, dass einfach alle Quest einmal kompiliert werden?
07/26/2015 17:32 rollback#9
Quote:
Originally Posted by deltous'fabius View Post
@Sensi schönes Release. Da ich mich mit Lua nicht grade auskenne, könntest du das Script auch ohne Menü zur verfügung stellen, dass einfach alle Quest einmal kompiliert werden?
einfach ganz unten main_menu() durch compile_all() ersetzen ;)
07/26/2015 18:38 DerZynx#10
Sieht nice aus. Danke, werd ich direkt mal benutzen ^^
07/29/2015 01:28 Deus #11
Sehr schicke Sache, mach weiter so!