Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. function getJsonNames(file)
  2. local names = {}
  3. for i,v in ipairs(json.decode(file)) do
  4. names[i] = v.Name
  5. end
  6. return names
  7. end
  8. function getJsonKeys(file, index)
  9. local keys = {}
  10. for k,_ in spairs(json.decode(file)[index]) do
  11. table.insert(keys, k)
  12. end
  13. return keys
  14. end
  15. function getJsonValues(file, index)
  16. local values,i = {},1
  17. for _,v in spairs(json.decode(file)[index]) do
  18. values[i], i = v, i+1
  19. end
  20. return values
  21. end
  22.  
  23. function spairs(t, order)
  24. -- collect the keys
  25. local keys = {}
  26. for k in pairs(t) do keys[#keys+1] = k end
  27.  
  28. -- if order function given, sort by it by passing the table and keys a, b,
  29. -- otherwise just sort the keys
  30. if order then
  31. table.sort(keys, function(a,b) return order(t, a, b) end)
  32. else
  33. table.sort(keys)
  34. end
  35.  
  36. -- return the iterator function
  37. local i = 0
  38. return function()
  39. i = i + 1
  40. if keys[i] then
  41. return keys[i], t[keys[i]]
  42. end
  43. end
  44. end
  45.  
  46. function listRax()
  47. local panel = Soda.Window{
  48. title = "Unit Designer",
  49. hidden = false,
  50. x=0, y=0.5, w=0, h=0.8,
  51. blurred = true, --style = Soda.style.darkBlurred, --gaussian blurs what is underneath it
  52. shadow = true,
  53. shapeArgs = { corners = 1 | 3 | ~4 }
  54. }
  55. local keys =
  56. Soda.List{
  57. parent = panel,
  58. x = .6, y = 20, w = .251, h = .8,
  59. text = getJsonKeys(rax, 1)
  60. }
  61. local values =
  62. Soda.List{
  63. parent = panel,
  64. x = .78, y = 20, w = .1, h = .8,
  65. text = getJsonValues(rax, 1)
  66. }
  67. local unit_names = Soda.List{
  68. parent = panel,
  69. x = .325, y = 20, w = .25, h = .8,
  70. text = getJsonNames(rax),
  71. default = 1,
  72. callback = function(_, selected, __)
  73.  
  74. keys.text = getJsonKeys(rax, selected.idNo)
  75. values.text = getJsonValues(rax, selected.idNo)
  76. end
  77. }
  78. --local textEntry = Soda.TextEntry{ --callback in values list (the one with text=getJsonValues)
  79. --parent = panel
  80.  
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement