Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- indexToColor = {
- colors.blue,
- colors.green,
- colors.red,
- colors.orange,
- colors.magenta,
- colors.lightBlue,
- colors.yellow,
- colors.lime,
- colors.cyan,
- colors.purple
- }
- colorToIndex = {}
- for k, v in pairs(indexToColor) do colorToIndex[v] = k end
- colorCount = table.getn(indexToColor)
- local toastText = nil
- local statusText = nil
- function removeToast()
- if (toastText ~= nil) then toastText:remove() end
- toastText = nil
- end
- function removeStatus()
- if (statusText ~= nil) then statusText:remove() end
- statusText = nil
- end
- function label(frame, text, x, y)
- local newLabel = frame:addLabel():setText(text):setSize(#text,1):setPosition(x, y)
- return newLabel
- end
- function toast(frame, text, color)
- if (toastText ~= nil) then removeToast() end
- toastText = label(frame, text, 3, 18):setForeground(color)
- toastText:onClick(removeToast)
- -- frame:addTimer():onCall(removeToast):setTime(3):start()
- end
- function status(frame, text, color)
- if (statusText ~= nil) then removeStatus() end
- statusText = label(frame, text, string.format("parent.w - %d + 1", #text), 1):setForeground(color)
- -- frame:addTimer():onCall(removeStatus):setTime(3):start()
- end
- function saveTable(table, path)
- local file = fs.open(path, "w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function loadTable(path)
- local file = fs.open(path, "r")
- if (file == nil) then return {} end
- local data = file.readAll()
- file.close()
- local result = textutils.unserialize(data)
- if result == nil then return {} end
- return result
- end
- function saveCookbook(cookbook)
- saveTable(cookbook, "cookbook.dat")
- end
- function tally(t)
- local freq = {}
- for _, v in pairs(t) do
- freq[v] = (freq[v] or 0) + 1
- end
- local freqPairs = {}
- for key, value in pairs(freq) do
- table.insert(freqPairs, {key, value})
- end
- table.sort(freqPairs, function(a, b) return a[2] > b[2] end)
- return freqPairs
- end
- -- SO 640642 -- Tyler
- function deepCopy(obj, seen)
- if type(obj) ~= 'table' then return obj end
- if seen and seen[obj] then return seen[obj] end
- local s = seen or {}
- local res = setmetatable({}, getmetatable(obj))
- s[obj] = res
- for k, v in pairs(obj) do res[deepCopy(k, s)] = deepCopy(v, s) end
- return res
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement