From fc4f3d9ad98b0a14f95bc0db56a5c847074b4d95 Mon Sep 17 00:00:00 2001 From: Jeija Date: Thu, 26 Jul 2012 12:51:50 +0200 Subject: [PATCH] Add tool that helps you create modlists --- createlist.lua | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 createlist.lua diff --git a/createlist.lua b/createlist.lua new file mode 100644 index 0000000..bacb2e2 --- /dev/null +++ b/createlist.lua @@ -0,0 +1,98 @@ +dofile ("table.lua") + +local s = "" +local list = {} +local filename = "mods.list" +local command + +while command ~="quit" do + print("command: ") + command = io.read() + if command == "help" then + print("Modlist Creation Utility for Minetest") + print("Available commands:") + print("filename : Enter another filename for the modlist (default:mod.list)") + print("load : Load the old mods.list (to change it)") + print("add : Add a mod") + print("list : List all mods") + print("update : Update a mod [WIP]") + print("remove : Remove a mod") + elseif command == "filename" then + print("Enter filename: ") + filename = io.read() + elseif command == "load" then + list, err = table.load(filename) + if err ~= nil then + list = {} + print("Table could not be loaded. Make sure the file exists. Error: "..err.." Filename: "..filename) + else + print("Success!") + end + elseif command == "add" then + print("name: ") + local name = io.read() + print("url: ") + local url = io.read() + print("description") + local description = io.read() + print("version") + local version = io.read() + local modspec = {name=name, url=url, description=description, version=version} + table.insert(list, modspec) + elseif command == "list" then + local i = 1 + while (list[i]~=nil) do + print("name : "..list[i].name ) + print("url : "..list[i].url ) + print("description: "..list[i].description) + print("version : "..list[i].version ) + print("") + i = i + 1 + end + elseif command == "remove" then + print("name: ") + local name = io.read() + local i = 1 + while (list[i]~=nil) do + if list[i].name == name then + list[i] = nil + j = i + 1 + while (list[j]~=nil) do + if list[j]~=nil then + list[j-1] = list[j] + list[j] = nil + end + end + end + i = i + 1 + end + elseif command == "update" then + print("name: ") + local name = io.read() + local i = 1 + local found = false + while (list[i]~=nil) do + if list[i].name == name then + print("Enter nothing to keep old info") + print("url") + local url = io.read() + if url~="" then list[i].url = url end + print("description") + local description = io.read() + if description~="" then list[i].description = description end + print("version") + local version = io.read() + if version~="" then list[i].version = version end + found = true + end + i = i + 1 + end + if not found then print("Error: Mod not found.") end + else + print("Command not found. Enter 'help' for more information.") + end +end + +print("Saving to "..filename) +table.save(list, filename) +print("Done!")