Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getJsonNames(file)
- local names = {}
- for i,v in ipairs(json.decode(file)) do
- names[i] = v.Name
- end
- return names
- end
- function getJsonKeys(file, index)
- local keys = {}
- for k,_ in spairs(json.decode(file)[index]) do
- table.insert(keys, k)
- end
- return keys
- end
- function getJsonValues(file, index)
- local values,i = {},1
- for _,v in spairs(json.decode(file)[index]) do
- values[i], i = v, i+1
- end
- return values
- end
- function spairs(t, order)
- -- collect the keys
- local keys = {}
- for k in pairs(t) do keys[#keys+1] = k end
- -- if order function given, sort by it by passing the table and keys a, b,
- -- otherwise just sort the keys
- if order then
- table.sort(keys, function(a,b) return order(t, a, b) end)
- else
- table.sort(keys)
- end
- -- return the iterator function
- local i = 0
- return function()
- i = i + 1
- if keys[i] then
- return keys[i], t[keys[i]]
- end
- end
- end
- function listRax()
- local panel = Soda.Window{
- title = "Unit Designer",
- hidden = false,
- x=0, y=0.5, w=0, h=0.8,
- blurred = true, --style = Soda.style.darkBlurred, --gaussian blurs what is underneath it
- shadow = true,
- shapeArgs = { corners = 1 | 3 | ~4 }
- }
- local keys =
- Soda.List{
- parent = panel,
- x = .6, y = 20, w = .251, h = .8,
- text = getJsonKeys(rax, 1)
- }
- local values =
- Soda.List{
- parent = panel,
- x = .78, y = 20, w = .1, h = .8,
- text = getJsonValues(rax, 1)
- }
- local unit_names = Soda.List{
- parent = panel,
- x = .325, y = 20, w = .25, h = .8,
- text = getJsonNames(rax),
- default = 1,
- callback = function(_, selected, __)
- keys.text = getJsonKeys(rax, selected.idNo)
- values.text = getJsonValues(rax, selected.idNo)
- end
- }
- --local textEntry = Soda.TextEntry{ --callback in values list (the one with text=getJsonValues)
- --parent = panel
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement