Guest User

Untitled

a guest
Nov 1st, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. local hexnums = { [10] = "a", [11] = "b", [12] = "c", [13] = "d", [14] = "e", [15] = "f" }
  2. function parseValue(tMap, x, y, sChar)
  3. if tMap == nil then
  4. error("tMap is ?(a nil value)")
  5. end
  6. if tonumber(lchar, 16) then
  7. sChar = math.pow(2, tonumber(sChar, 16))
  8.  
  9. if sChar == colors.white then
  10. tMap[y][x] = 0
  11. elseif sChar == colors.orange then
  12. tMap[y][x] = 1
  13. end
  14. end
  15. end
  16. function saveMap(tMap, _sPath1, sPath2, sizex, sizey)
  17. if not fs.exists(_sPath1) then return false
  18. elseif tMap == nil then return false end
  19. tMap = {}
  20. local file = fs.open(_sPath1, "r")
  21. local line = file:readLine()
  22. while line do
  23. tMap[#tMap+1] = {}
  24. for i=1,math.min(#line,sizex) do
  25. local lchar = string.sub(line,i,i)
  26. parseValue(i, #tMap, lchar)
  27. end
  28. if #tMap == sizey then break end
  29. line = file:readLine()
  30. end
  31. file:close()
  32. local f = fs.open(sPath2, "w")
  33. f.write(textutils.serialize(tMap))
  34. f.close()
  35. return true
  36. end
  37. function loadMap(sPath)
  38. local file = fs.open(sPath, "r")
  39. local data = file.readAll()
  40. file.close()
  41. return textutils.unserialize(data)
  42. end
  43. function checkValue(mapPath, x, y)
  44. local map = loadMap(mapPath)
  45. return map[y][x]
  46. end
Advertisement
Add Comment
Please, Sign In to add comment