Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- GM Character Sheet
- Just Does Games
- ]]--
- local w,h = term.getSize()
- function setSize(nw,nh)
- assert(type(nw) == "number", "Invalid width. Expected number got '"..type(nw).."'.")
- assert(type(nh) == "number", "Invalid height. Expected number got '"..type(nh).."'.")
- w,h = nw,nh
- end
- setSize(w*6,h*9) -- default CraftOS-PC GM screen size
- local mChar = "1212021"
- local default_font = {
- "011121000121101121000121010121000120111",
- "011121111121010121111121000121101120111",
- "20101211111211111211111201112001",
- "200120111211111201112001",
- "001201112001211111211111200120111",
- "200120111211111211111200120111",
- "22001120111120111120011",
- "1111112111111211001121000012100001211001121111112111111",
- "",
- "",
- "20001112000011200110120100120100120011",
- "0111210001210001210001201112001201112001",
- "",
- "201111201001201111201211211",
- "201111120100012011111201000121100112110011",
- "212111211111211121",
- "200001200111211111200111200001",
- "0012011121111120012001211111201112001",
- "100121001210012100121001221001",
- "01111210101210101201101200101200101200101",
- "011112112101121000120110120001121111",
- "222221111112111111",
- "001201112111112001211111201112001211111",
- "001201112111112001200120012001",
- "001200120012001211111201112001",
- "20001200011211111120001120001",
- "20012011211111120112001",
- "222212111111",
- "22010012111111201001",
- "200120012011120111211111",
- "211111201112011120012001",
- "0000002",
- "001200120012001200122001",
- "0010120010120101",
- "010120101211111201012111112010120101",
- "0012011112120111200001211112001",
- "1000121001200012001201201001210001",
- "0012010120012011012101121001201101",
- "0001200012001",
- "0001120012012012012001200011",
- "01120001200001200001200001200012011",
- "220100012001112010001",
- "2001200121111120012001",
- "2222200120012001",
- "22211111",
- "222220012001",
- "000012000120001200120120121",
- "011121000121001121010121100121000120111",
- "00120112001200120012001211111",
- "011121000120000120011201210001211111",
- "01112100012000012001120000121000120111",
- "00011200101201001210001211111200001200001",
- "11111212111120000120000121000120111",
- "0011201212111121000121000120111",
- "1111121000120000120001200120012001",
- "01112100012100012011121000121000120111",
- "0111210001210001201111200001200012011",
- "220012001220012001",
- "2200120012200120012001",
- "0001200120121201200120001",
- "221111122211111",
- "1201200120001200120121",
- "011121000120000120001200122001",
- "0111121000012101101210111121201111",
- "0111210001211111210001210001210001210001",
- "11112100012111121000121000121000121111",
- "011121000121212121000120111",
- "111121000121000121000121000121000121111",
- "11111212111212121211111",
- "1111121211121212121",
- "011112121001121000121000121000120111",
- "10001210001211111210001210001210001210001",
- "01112001200120012001200120111",
- "0000120000120000120000120000121000120111",
- "1000121001211121001210001210001210001",
- "12121212121211111",
- "10001211011210101210001210001210001210001",
- "10001211001210101210011210001210001210001",
- "0111121000012100001210000121000012100001201111",
- "11112100012111121212121",
- "011121000121000121000121000121001201101",
- "111121000121111210001210001210001210001",
- "01111212011120000120000121000120111",
- "11111200120012001200120012001",
- "1000121000121000121000121000121000120111",
- "1000121000121000121000120101201012001",
- "10001210001210001210001210101211011210001",
- "1000120101200120101210001210001210001",
- "100012010120012001200120012001",
- "1111120000120001200120121211111",
- "011120120120120120120111",
- "120120120012000120001200001",
- "0111200012000120001200012000120111",
- "00120101210001",
- "222222211111",
- "001200120001",
- "220111200001201111210001201111",
- "1212101121100121000121000121111",
- "2201112100012121000120111",
- "00001200001201101210011210001210001201111",
- "22011121000121111121201111",
- "0001120012011112001200120012001",
- "220111121000121000120111120000121111",
- "12121011211001210001210001210001",
- "000122000120001200012000120001",
- "00001220000120000120000121000121000120111",
- "0120120100120101201120101201001",
- "0012001200120012001200120001",
- "221101210101210101210001210001",
- "221111210001210001210001210001",
- "22011121000121000121000120111",
- "221011211001210001211112121",
- "2201101210011210001201111200001200001",
- "221011211001212121",
- "2201111212011120000121111",
- "00120012011120012001200120001",
- "2210001210001210001210001201111",
- "2210001210001210001201012001",
- "2210001210001210101210101201111",
- "221000120101200120101210001",
- "221000121000121000120111120000121111",
- "2211111200012001201211111",
- "00112012012120120120011",
- "001200120012001200120012001",
- "11200120012000120012001211",
- "011001210011",
- "01001210012001001201001210012001001201001210012001001",
- "",
- "11121112111",
- "00011120001112000111",
- "11111121111112111111",
- "22211121112111",
- "11121112111211121112111",
- "00011120001112000111211121112111",
- "11111121111112111111211121112111",
- "22200011120001112000111",
- "11121112111200011120001112000111",
- "00011120001112000111200011120001112000111",
- "11111121111112111111200011120001112000111",
- "22211111121111112111111",
- "11121112111211111121111112111111",
- "00011120001112000111211111121111112111111",
- "11111121111112111111211111121111112111111",
- "22222211121112111",
- "11121112111222211121112111",
- "00011120001112000111222211121112111",
- "11111121111112111111222211121112111",
- "22211121112111211121112111",
- "11121112111211121112111211121112111",
- "00011120001112000111211121112111211121112111",
- "11111121111112111111211121112111211121112111",
- "22200011120001112000111211121112111",
- "11121112111200011120001112000111211121112111",
- "00011120001112000111200011120001112000111211121112111",
- "11111121111112111111200011120001112000111211121112111",
- "22211111121111112111111211121112111",
- "11121112111211111121111112111111211121112111",
- "00011120001112000111211111121111112111111211121112111",
- "11111121111112111111211111121111112111111211121112111",
- "",
- "001220012001200120012001",
- "20012011121000121210001201112001",
- "001120100120121111201201211111",
- "2100012011121000121000121000120111210001",
- "1000120101211111200121111120012001",
- "001200120012200120012001",
- "011112112101121000120110120001121111",
- "0101",
- "2011112100101210100121010012100101201111",
- "01120001201112100120111",
- "220010120101210120101200101",
- "22211111200001",
- "22211111",
- "2011112101101210110121010112100001201111",
- "11111",
- "01121001210012011",
- "20012001211111200120012211111",
- "120121121211",
- "11201211201211",
- "0121",
- "221000121000121000121000121111012121",
- "01111210101210101201101200101200101200101",
- "222001120011",
- "222222200012001",
- "012112012111",
- "2011121000121000121000120111",
- "2210120101200101201012101",
- "1000121001200012001201011201011210001",
- "100012100120001200120100120101210011",
- "1100120101211012001201011201011210001",
- "001220012012121000120111",
- "11220111210001211111210001210001",
- "00011220111210001211111210001210001",
- "011121000120111210001211111210001210001",
- "0101210120111210001211111210001210001",
- "0101220111210001211111210001210001",
- "001220111210001211111210001210001",
- "01111210121012111121012101210111",
- "0111210001212121000120111200012001",
- "112211111212111121211111",
- "000112211111212111121211111",
- "0111210001211111212111121211111",
- "01012211111212111121211111",
- "01122011120012001200120111",
- "001122011120012001200120111",
- "001201012011120012001200120111",
- "010122011120012001200120111",
- "111121000121000121100121000121000121111",
- "0010120101210001211001210101210011210001",
- "112011121000121000121000121000120111",
- "000112011121000121000121000121000120111",
- "01112100012011121000121000121000120111",
- "010121012011121000121000121000120111",
- "01012011121000121000121000121000120111",
- "21000120101200120101210001",
- "011121000121001121010121100121000120111",
- "11221000121000121000121000120111",
- "00011221000121000121000121000120111",
- "00120101221000121000121000120111",
- "0101221000121000121000121000120111",
- "00011221000120101200120012001",
- "011120012001120010120011200120111",
- "1111210001210112100012100012100012101121",
- "11220111200001201111210001201111",
- "00011220111200001201111210001201111",
- "011121000120111200001201111210001201111",
- "0101210120111200001201111210001201111",
- "0101220111200001201111210001201111",
- "001220111200001201111210001201111",
- "2201011210100121111121012010111",
- "201112100012121000120111200012001",
- "1122011121000121111121201111",
- "0001122011121000121111121201111",
- "01112100012011121000121111121201111",
- "010122011121000121111121201111",
- "011220012001200120012001",
- "0011220012001200120012001",
- "0012010120012001200120012001",
- "0101220012001200120012001",
- "0012000120111121000121000121000120111",
- "0101210121111210001210001210001210001",
- "1122011121000121000121000120111",
- "0001122011121000121000121000120111",
- "01112100012011121000121000121000120111",
- "010121012011121000121000121000120111",
- "010122011121000121000121000120111",
- "2001221111122001",
- "22011121001121010121100120111",
- "112210001210001210001210001201111",
- "000112210001210001210001210001201111",
- "001201012210001210001210001201111",
- "01012210001210001210001210001201111",
- "00011221000121000121000120111120000121111",
- "01120012001120010120011200120111",
- "0101221000121000121000120111120000121111",
- }
- font = default_font
- function loadFont(dir)
- if fs.exists(dir) then
- local f = fs.open(dir, "r")
- if f then
- local i = 1
- while true do
- font[i] = f.readLine()
- if font[i] == nil then break else i=i+1 end
- end
- f.close()
- if #font > 255 then font = {} return error("Invalid Font: Supasses 255 character limit") end
- else
- return error("Could not open directory '"..dir.."'")
- end
- else
- return error("Directory '"..dir.."' does not exists.")
- end
- end
- local function drawChar(char)
- local tmpText = term.getTextColor()
- if not char then
- char = mChar
- term.setTextColor(colors.red)
- end
- local x,y = term.getCursorPos()
- local x2,y2,lx = x,y,0
- local prevBack = term.getBackgroundColor()
- -- Check position of text
- for i=1, char:len() do
- if char:sub(i,i) == "2" then
- if lx < x then lx = x end
- x=x2
- else
- x=x+1
- end
- end
- if lx > w then -- if going off screen
- x2,y2 = 1,y2+9
- --term.setCursorPos(x2,y2)
- x,y = x2,y2
- end
- x,y,lx = x2,y2,0
- -- Draw to screen
- for i=1, char:len() do
- if char:sub(i,i) == "0" then
- x=x+1
- elseif char:sub(i,i) == "1" then
- paintutils.drawPixel(x,y,term.getTextColor())
- x=x+1
- elseif char:sub(i,i) == "2" then
- if lx < x then lx = x end
- x=x2
- y=y+1
- end
- end
- sleep(.01)
- if lx < x then lx = x end
- term.setBackgroundColor(prevBack)
- term.setCursorPos(lx+1,y2)
- if tmpText ~= term.getTextColor() then term.setTextColor(tmpText) end
- end
- function writeText(text, x,y)
- if type(x) == "number" and type(y) == "number" then term.setCursorPos(x,y) end
- for i=1, text:len() do
- --error(string.byte(text:sub(i,i)))
- drawChar(font[string.byte(text:sub(i,i))])
- end
- end
- local function GMFC() -- MAX CHARACTER SIZE: 6x9 (FOR MOSTLY IN 51x19 MODE AND NOT GM)
- local c = function(t) print("[GMC] "..t) end
- local devFont = {}
- local sel = 1
- if fs.exists("/gmc_font_dev.lua") then
- c("Found dev font!")
- local f = fs.open("/gmc_font_dev.lua", "r")
- devFont = textutils.unserialize(f.readAll())
- f.close()
- else
- for i=1, 255 do devFont[i] = {"0000002","0000002","0000002","0000002","0000002","0000002","0000002","0000002","0000002"} end
- end
- --[[for i=1, #devFont do
- table.insert(devFont[i], 1, "0000002")
- end]]
- local function compressChar(char)
- local nChar = ""
- for i=1, #char do
- local tmp, rem, cnt = string.reverse(char[i] or "2"), true, 1
- local tmp2 = {}
- for i=1, tmp:len() do
- tmp2[i] = tmp:sub(i,i)
- end
- while true do
- if tmp2[cnt] then
- if tmp2[cnt] == "0" and rem then
- table.remove(tmp2, cnt)
- elseif tmp2[cnt] == "1" then
- rem = false cnt = cnt+1
- else
- cnt = cnt+1
- end
- else
- break
- end
- end tmp = ""
- for i=1, #tmp2 do
- tmp = tmp..tmp2[i]
- end
- nChar = nChar..tmp
- end
- while true do
- if nChar:sub(1,1) == "2" then
- nChar = nChar:sub(2,nChar:len())
- else
- break
- end
- end
- return string.reverse(nChar)
- end
- local function reload()
- term.setCursorPos(1,1)
- term.setTextColor(colors.gray)
- for i=1, 10 do
- for ii=1, 6 do
- write(string.char(127))
- end
- term.setCursorPos(1,i)
- end
- term.setTextColor(colors.gray)
- term.setCursorPos(1,1) drawChar(compressChar(devFont[math.max(1,sel-1)]))
- term.setTextColor(colors.white)
- term.setCursorPos(1,1) drawChar(compressChar(devFont[sel]))
- term.setCursorPos(1,10) write("Char: "..sel.."/255 ("..(sel ~= 10 and string.char(sel) or " ")..") ")
- term.setCursorPos(1,h) write("Press CTRL for menu")
- end
- local function save()
- term.clear() term.setCursorPos(1,1)
- c("Saving...") sleep(1)
- local f = fs.open("/gmc_font_dev.lua", "w")
- if f then f.write(textutils.serialize(devFont)) f.close() else error("Failed to open dev file.") end
- c("Complete!")
- sleep(1) term.clear() reload() return true
- end
- local function export()
- term.clear() term.setCursorPos(1,1)
- c("Exporting...") sleep(1)
- for i=1, #devFont do
- devFont[i] = compressChar(devFont[i])
- end
- local f = fs.open("/gmc_font_dev_ex.lua", "w")
- if f then f.write(textutils.serialize(devFont)) f.close() else error("Failed to open dev_ex file.") end
- c("Complete!")
- sleep(1) return false
- end
- term.setBackgroundColor(colors.black) term.clear()
- reload() local run = true
- while run do
- a,b,x,y = os.pullEvent()
- if a == "key" then
- if b == keys.leftCtrl or b == keys.rightCtrl then
- local m, sel = {{"Save", save}, {"Export", export}, {"Close Menu", 0}, {"Exit GMFC", 1}}, 1
- local function drawMenu()
- term.setCursorPos(1,h)
- for i=1, #m do
- if sel == i then write("["..m[i][1].."]") else write(" "..m[i][1].." ") end
- end
- end
- while true do
- drawMenu()
- local a,b = os.pullEvent("key")
- if b == keys.left or b == keys.a then
- if sel ~= 1 then sel = sel-1 end
- elseif b == keys.right or b == keys.d then
- if sel ~= #m then sel = sel+1 end
- elseif b == keys.leftCtrl or b == keys.rightCtrl then
- break
- elseif b == keys.enter or b == keys.e then
- if type(m[sel][2]) ~= "function" then
- if m[sel][2] == 0 then
- break
- elseif m[sel][2] == 1 then
- run = false break
- end
- else run = m[sel][2]() break end
- end
- end term.setTextColor(colors.black)
- drawMenu() term.setTextColor(colors.white) term.setCursorPos(1,h) write("Press CTRL for menu")
- elseif b == keys.left or b == keys.a then
- if sel <= 1 then sel = #devFont else sel = sel-1 end reload()
- elseif b == keys.right or b == keys.d then
- if sel >= #devFont then sel = 1 else sel = sel+1 end reload()
- end
- elseif a == "mouse_click" or a == "mouse_drag" then
- if x <= 6 and y <= 9 then
- if b == 1 then
- devFont[sel][#devFont[sel]-y+1] = devFont[sel][#devFont[sel]-y+1]:sub(1, x - 1).."1"..devFont[sel][#devFont[sel]-y+1]:sub(x + 1)
- paintutils.drawPixel(x,y,colors.white) term.setBackgroundColor(colors.black)
- elseif b == 2 then
- devFont[sel][#devFont[sel]-y+1] = devFont[sel][#devFont[sel]-y+1]:sub(1, x - 1).."0"..devFont[sel][#devFont[sel]-y+1]:sub(x + 1)
- term.setCursorPos(x,y) term.setTextColor(colors.gray) write(string.char(127)) term.setTextColor(colors.white)
- end
- end
- end
- end
- term.clear() term.setCursorPos(1,1) print("GMFC Closed.")
- end
- --GMFC()
Advertisement
Add Comment
Please, Sign In to add comment