Advertisement
Pinkishu

Untitled

Sep 6th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. --dofile("lib\\textutils.lua")
  2. --dofile("lib\\tableIO.lua")
  3. require("lib\\tableIO")
  4. local ex = nil
  5. local exArg = {}
  6.  
  7. local data = tableIO.load("hm.data")
  8.  
  9. function readNumber(min,max)
  10.     local inp
  11.     while type(inp) ~= "number" or (math.ceil(inp)~=inp or inp < min or inp>max) do
  12.         inp = tonumber(io.read())
  13.     end
  14.     return inp
  15. end
  16.  
  17. function listStrings(person)
  18.     for i,v in pairs(data.people[person].strings) do
  19.         print(i .. " - \""..v.text.."\"".. " (P:"..v.priority..")")
  20.     end
  21. end
  22.  
  23. function addString(person)
  24.     print("Person: " .. person)
  25.     print("")
  26.     print("Add string:")
  27.     local inp
  28.     while type(inp) ~= "string" do
  29.         inp = io.read()
  30.     end
  31.  
  32.     table.insert(data.people[person].strings,{text=inp,priority=(#data.people[person].strings+1)})
  33.  
  34.     ex = updateStrings
  35.  
  36. end
  37.  
  38. function swapStrings(person)
  39.     print("Person: " .. person)
  40.     print("")
  41.     listStrings(person)
  42.     print("")
  43.     print("Input String #1 (0 to cancel)")
  44.     local s1 = readNumber(0,#data.people[person].strings)
  45.     if s1 == 0 then
  46.         ex = updateStrings
  47.         return
  48.     end
  49.  
  50.     print("Input String #2 (0 to cancel)")
  51.     local s2 = readNumber(0,#data.people[person].strings)
  52.     if s2 == 0 or s1 == s2 then
  53.         ex = updateStrings
  54.         return
  55.     end
  56.  
  57.     local strings = data.people[person].strings
  58.     local temp = strings[s1].priority
  59.     strings[s1].priority = strings[s2].priority
  60.     strings[s2].priority = temp
  61.  
  62.     ex = updateStrings
  63. end
  64.  
  65. function updateStrings(person)
  66.     print("Person: ".. person)
  67.     print("")
  68.     listStrings(person)
  69.     print("\n1 - Add string\n2 - Delete string\n3 - Swap strings\n4 - back")
  70.  
  71.     local inp = readNumber(1,3)
  72.     if inp == 1 then
  73.         ex = addString
  74.     elseif inp == 2 then
  75.         ex = delString
  76.     elseif inp == 3 then
  77.         if #data.people[person].strings > 1 then
  78.             ex = swapStrings
  79.         end
  80.     elseif inp == 4 then
  81.         exArg = {}
  82.         ex = personMenu
  83.     end
  84. end
  85.  
  86.  
  87. function delString(person)
  88.     print("Person: " .. person)
  89.     print("")
  90.     listStrings(person)
  91.     print("")
  92.     print("Delete which string? (0 to cancel)")
  93.     local n = readNumber(0,#data.people[person].strings)
  94.     if n ~= 0 then
  95.         local sPriority = data.people[person].strings[n].priority
  96.         table.remove(data.people[person].strings,n)
  97.         for i,v in ipairs(data.people[person].strings) do
  98.             if v.priority > sPriority then
  99.                 v.priority = v.priority-1
  100.             end
  101.         end
  102.     end
  103.     ex = updateStrings
  104. end
  105.  
  106.  
  107. function personMenu()
  108.     print("\n\nWhich person?")
  109.     local person
  110.     while data.people[person] == nil and person ~= "back" do
  111.         person = io.read():lower()
  112.     end
  113.     if person == "back" then
  114.         exArg = {}
  115.         ex = main
  116.         return
  117.     end
  118.  
  119.     print("Do what?\n1 - update strings\n2 - update gifts\n")
  120.     local inp = readNumber(1,2)
  121.  
  122.     exArg = {person}
  123.     if inp == 1 then
  124.         ex = updateStrings     
  125.     elseif inp == 2 then
  126.         ex = updateGifts
  127.     end
  128.  
  129. end
  130.  
  131. function clear()
  132.     os.execute("cls")
  133. end
  134.  
  135. function main()
  136.     clear()
  137.     print("Do what?\n\n1 - person\n2 - gift\n")
  138.     local inp = readNumber(1,2)
  139.  
  140.     if inp == 1 then
  141.         ex = personMenu
  142.     else
  143.         ex = giftMenu
  144.     end
  145. end
  146.  
  147. ex = main
  148. while true do
  149.     clear()
  150.     ex(unpack(exArg))
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement