JustDoesGames

GMC

Nov 8th, 2020 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.62 KB | None | 0 0
  1. --[[
  2.  
  3. GM Character Sheet
  4. Just Does Games
  5.  
  6. ]]--
  7.  
  8. local w,h = term.getSize()
  9. function setSize(nw,nh)
  10.     assert(type(nw) == "number", "Invalid width. Expected number got '"..type(nw).."'.")
  11.     assert(type(nh) == "number", "Invalid height. Expected number got '"..type(nh).."'.")
  12.     w,h = nw,nh
  13. end
  14. setSize(w*6,h*9) -- default CraftOS-PC GM screen size
  15.  
  16. local mChar = "1212021"
  17.  
  18. local default_font = {
  19.     "011121000121101121000121010121000120111",
  20.     "011121111121010121111121000121101120111",
  21.     "20101211111211111211111201112001",
  22.     "200120111211111201112001",
  23.     "001201112001211111211111200120111",
  24.     "200120111211111211111200120111",
  25.     "22001120111120111120011",
  26.     "1111112111111211001121000012100001211001121111112111111",
  27.     "",
  28.     "",
  29.     "20001112000011200110120100120100120011",
  30.     "0111210001210001210001201112001201112001",
  31.     "",
  32.     "201111201001201111201211211",
  33.     "201111120100012011111201000121100112110011",
  34.     "212111211111211121",
  35.     "200001200111211111200111200001",
  36.     "0012011121111120012001211111201112001",
  37.     "100121001210012100121001221001",
  38.     "01111210101210101201101200101200101200101",
  39.     "011112112101121000120110120001121111",
  40.     "222221111112111111",
  41.     "001201112111112001211111201112001211111",
  42.     "001201112111112001200120012001",
  43.     "001200120012001211111201112001",
  44.     "20001200011211111120001120001",
  45.     "20012011211111120112001",
  46.     "222212111111",
  47.     "22010012111111201001",
  48.     "200120012011120111211111",
  49.     "211111201112011120012001",
  50.     "0000002",
  51.     "001200120012001200122001",
  52.     "0010120010120101",
  53.     "010120101211111201012111112010120101",
  54.     "0012011112120111200001211112001",
  55.     "1000121001200012001201201001210001",
  56.     "0012010120012011012101121001201101",
  57.     "0001200012001",
  58.     "0001120012012012012001200011",
  59.     "01120001200001200001200001200012011",
  60.     "220100012001112010001",
  61.     "2001200121111120012001",
  62.     "2222200120012001",
  63.     "22211111",
  64.     "222220012001",
  65.     "000012000120001200120120121",
  66.     "011121000121001121010121100121000120111",
  67.     "00120112001200120012001211111",
  68.     "011121000120000120011201210001211111",
  69.     "01112100012000012001120000121000120111",
  70.     "00011200101201001210001211111200001200001",
  71.     "11111212111120000120000121000120111",
  72.     "0011201212111121000121000120111",
  73.     "1111121000120000120001200120012001",
  74.     "01112100012100012011121000121000120111",
  75.     "0111210001210001201111200001200012011",
  76.     "220012001220012001",
  77.     "2200120012200120012001",
  78.     "0001200120121201200120001",
  79.     "221111122211111",
  80.     "1201200120001200120121",
  81.     "011121000120000120001200122001",
  82.     "0111121000012101101210111121201111",
  83.     "0111210001211111210001210001210001210001",
  84.     "11112100012111121000121000121000121111",
  85.     "011121000121212121000120111",
  86.     "111121000121000121000121000121000121111",
  87.     "11111212111212121211111",
  88.     "1111121211121212121",
  89.     "011112121001121000121000121000120111",
  90.     "10001210001211111210001210001210001210001",
  91.     "01112001200120012001200120111",
  92.     "0000120000120000120000120000121000120111",
  93.     "1000121001211121001210001210001210001",
  94.     "12121212121211111",
  95.     "10001211011210101210001210001210001210001",
  96.     "10001211001210101210011210001210001210001",
  97.     "0111121000012100001210000121000012100001201111",
  98.     "11112100012111121212121",
  99.     "011121000121000121000121000121001201101",
  100.     "111121000121111210001210001210001210001",
  101.     "01111212011120000120000121000120111",
  102.     "11111200120012001200120012001",
  103.     "1000121000121000121000121000121000120111",
  104.     "1000121000121000121000120101201012001",
  105.     "10001210001210001210001210101211011210001",
  106.     "1000120101200120101210001210001210001",
  107.     "100012010120012001200120012001",
  108.     "1111120000120001200120121211111",
  109.     "011120120120120120120111",
  110.     "120120120012000120001200001",
  111.     "0111200012000120001200012000120111",
  112.     "00120101210001",
  113.     "222222211111",
  114.     "001200120001",
  115.     "220111200001201111210001201111",
  116.     "1212101121100121000121000121111",
  117.     "2201112100012121000120111",
  118.     "00001200001201101210011210001210001201111",
  119.     "22011121000121111121201111",
  120.     "0001120012011112001200120012001",
  121.     "220111121000121000120111120000121111",
  122.     "12121011211001210001210001210001",
  123.     "000122000120001200012000120001",
  124.     "00001220000120000120000121000121000120111",
  125.     "0120120100120101201120101201001",
  126.     "0012001200120012001200120001",
  127.     "221101210101210101210001210001",
  128.     "221111210001210001210001210001",
  129.     "22011121000121000121000120111",
  130.     "221011211001210001211112121",
  131.     "2201101210011210001201111200001200001",
  132.     "221011211001212121",
  133.     "2201111212011120000121111",
  134.     "00120012011120012001200120001",
  135.     "2210001210001210001210001201111",
  136.     "2210001210001210001201012001",
  137.     "2210001210001210101210101201111",
  138.     "221000120101200120101210001",
  139.     "221000121000121000120111120000121111",
  140.     "2211111200012001201211111",
  141.     "00112012012120120120011",
  142.     "001200120012001200120012001",
  143.     "11200120012000120012001211",
  144.     "011001210011",
  145.     "01001210012001001201001210012001001201001210012001001",
  146.     "",
  147.     "11121112111",
  148.     "00011120001112000111",
  149.     "11111121111112111111",
  150.     "22211121112111",
  151.     "11121112111211121112111",
  152.     "00011120001112000111211121112111",
  153.     "11111121111112111111211121112111",
  154.     "22200011120001112000111",
  155.     "11121112111200011120001112000111",
  156.     "00011120001112000111200011120001112000111",
  157.     "11111121111112111111200011120001112000111",
  158.     "22211111121111112111111",
  159.     "11121112111211111121111112111111",
  160.     "00011120001112000111211111121111112111111",
  161.     "11111121111112111111211111121111112111111",
  162.     "22222211121112111",
  163.     "11121112111222211121112111",
  164.     "00011120001112000111222211121112111",
  165.     "11111121111112111111222211121112111",
  166.     "22211121112111211121112111",
  167.     "11121112111211121112111211121112111",
  168.     "00011120001112000111211121112111211121112111",
  169.     "11111121111112111111211121112111211121112111",
  170.     "22200011120001112000111211121112111",
  171.     "11121112111200011120001112000111211121112111",
  172.     "00011120001112000111200011120001112000111211121112111",
  173.     "11111121111112111111200011120001112000111211121112111",
  174.     "22211111121111112111111211121112111",
  175.     "11121112111211111121111112111111211121112111",
  176.     "00011120001112000111211111121111112111111211121112111",
  177.     "11111121111112111111211111121111112111111211121112111",
  178.     "",
  179.     "001220012001200120012001",
  180.     "20012011121000121210001201112001",
  181.     "001120100120121111201201211111",
  182.     "2100012011121000121000121000120111210001",
  183.     "1000120101211111200121111120012001",
  184.     "001200120012200120012001",
  185.     "011112112101121000120110120001121111",
  186.     "0101",
  187.     "2011112100101210100121010012100101201111",
  188.     "01120001201112100120111",
  189.     "220010120101210120101200101",
  190.     "22211111200001",
  191.     "22211111",
  192.     "2011112101101210110121010112100001201111",
  193.     "11111",
  194.     "01121001210012011",
  195.     "20012001211111200120012211111",
  196.     "120121121211",
  197.     "11201211201211",
  198.     "0121",
  199.     "221000121000121000121000121111012121",
  200.     "01111210101210101201101200101200101200101",
  201.     "222001120011",
  202.     "222222200012001",
  203.     "012112012111",
  204.     "2011121000121000121000120111",
  205.     "2210120101200101201012101",
  206.     "1000121001200012001201011201011210001",
  207.     "100012100120001200120100120101210011",
  208.     "1100120101211012001201011201011210001",
  209.     "001220012012121000120111",
  210.     "11220111210001211111210001210001",
  211.     "00011220111210001211111210001210001",
  212.     "011121000120111210001211111210001210001",
  213.     "0101210120111210001211111210001210001",
  214.     "0101220111210001211111210001210001",
  215.     "001220111210001211111210001210001",
  216.     "01111210121012111121012101210111",
  217.     "0111210001212121000120111200012001",
  218.     "112211111212111121211111",
  219.     "000112211111212111121211111",
  220.     "0111210001211111212111121211111",
  221.     "01012211111212111121211111",
  222.     "01122011120012001200120111",
  223.     "001122011120012001200120111",
  224.     "001201012011120012001200120111",
  225.     "010122011120012001200120111",
  226.     "111121000121000121100121000121000121111",
  227.     "0010120101210001211001210101210011210001",
  228.     "112011121000121000121000121000120111",
  229.     "000112011121000121000121000121000120111",
  230.     "01112100012011121000121000121000120111",
  231.     "010121012011121000121000121000120111",
  232.     "01012011121000121000121000121000120111",
  233.     "21000120101200120101210001",
  234.     "011121000121001121010121100121000120111",
  235.     "11221000121000121000121000120111",
  236.     "00011221000121000121000121000120111",
  237.     "00120101221000121000121000120111",
  238.     "0101221000121000121000121000120111",
  239.     "00011221000120101200120012001",
  240.     "011120012001120010120011200120111",
  241.     "1111210001210112100012100012100012101121",
  242.     "11220111200001201111210001201111",
  243.     "00011220111200001201111210001201111",
  244.     "011121000120111200001201111210001201111",
  245.     "0101210120111200001201111210001201111",
  246.     "0101220111200001201111210001201111",
  247.     "001220111200001201111210001201111",
  248.     "2201011210100121111121012010111",
  249.     "201112100012121000120111200012001",
  250.     "1122011121000121111121201111",
  251.     "0001122011121000121111121201111",
  252.     "01112100012011121000121111121201111",
  253.     "010122011121000121111121201111",
  254.     "011220012001200120012001",
  255.     "0011220012001200120012001",
  256.     "0012010120012001200120012001",
  257.     "0101220012001200120012001",
  258.     "0012000120111121000121000121000120111",
  259.     "0101210121111210001210001210001210001",
  260.     "1122011121000121000121000120111",
  261.     "0001122011121000121000121000120111",
  262.     "01112100012011121000121000121000120111",
  263.     "010121012011121000121000121000120111",
  264.     "010122011121000121000121000120111",
  265.     "2001221111122001",
  266.     "22011121001121010121100120111",
  267.     "112210001210001210001210001201111",
  268.     "000112210001210001210001210001201111",
  269.     "001201012210001210001210001201111",
  270.     "01012210001210001210001210001201111",
  271.     "00011221000121000121000120111120000121111",
  272.     "01120012001120010120011200120111",
  273.     "0101221000121000121000120111120000121111",
  274. }
  275.  
  276. font = default_font
  277.  
  278. function loadFont(dir)
  279.     if fs.exists(dir) then
  280.         local f = fs.open(dir, "r")
  281.         if f then
  282.             local i = 1
  283.             while true do
  284.                 font[i] = f.readLine()
  285.                 if font[i] == nil then break else i=i+1 end
  286.             end
  287.             f.close()
  288.             if #font > 255 then font = {} return error("Invalid Font: Supasses 255 character limit") end
  289.         else
  290.             return error("Could not open directory '"..dir.."'")
  291.         end
  292.     else
  293.         return error("Directory '"..dir.."' does not exists.")
  294.     end
  295. end
  296.  
  297. local function drawChar(char)
  298.     local tmpText = term.getTextColor()
  299.     if not char then
  300.         char = mChar
  301.         term.setTextColor(colors.red)
  302.     end
  303.     local x,y = term.getCursorPos()
  304.     local x2,y2,lx = x,y,0
  305.     local prevBack = term.getBackgroundColor()
  306.     -- Check position of text
  307.     for i=1, char:len() do
  308.         if char:sub(i,i) == "2" then
  309.             if lx < x then lx = x end
  310.             x=x2
  311.         else
  312.             x=x+1
  313.         end
  314.     end
  315.     if lx > w then -- if going off screen
  316.         x2,y2 = 1,y2+9
  317.         --term.setCursorPos(x2,y2)
  318.         x,y = x2,y2
  319.     end
  320.    
  321.     x,y,lx = x2,y2,0
  322.     -- Draw to screen
  323.     for i=1, char:len() do
  324.         if char:sub(i,i) == "0" then
  325.             x=x+1
  326.         elseif char:sub(i,i) == "1" then
  327.             paintutils.drawPixel(x,y,term.getTextColor())
  328.             x=x+1
  329.         elseif char:sub(i,i) == "2" then
  330.             if lx < x then lx = x end
  331.             x=x2
  332.             y=y+1
  333.         end
  334.     end
  335.     sleep(.01)
  336.     if lx < x then lx = x end
  337.     term.setBackgroundColor(prevBack)
  338.     term.setCursorPos(lx+1,y2)
  339.     if tmpText ~= term.getTextColor() then term.setTextColor(tmpText) end
  340. end
  341.  
  342. function writeText(text, x,y)
  343.     if type(x) == "number" and type(y) == "number" then term.setCursorPos(x,y) end
  344.     for i=1, text:len() do
  345.         --error(string.byte(text:sub(i,i)))
  346.         drawChar(font[string.byte(text:sub(i,i))])
  347.     end
  348. end
  349.  
  350. local function GMFC() -- MAX CHARACTER SIZE: 6x9 (FOR MOSTLY IN 51x19 MODE AND NOT GM)
  351.     local c = function(t) print("[GMC] "..t) end
  352.     local devFont = {}
  353.     local sel = 1
  354.     if fs.exists("/gmc_font_dev.lua") then
  355.         c("Found dev font!")
  356.         local f = fs.open("/gmc_font_dev.lua", "r")
  357.         devFont = textutils.unserialize(f.readAll())
  358.         f.close()
  359.     else
  360.         for i=1, 255 do devFont[i] = {"0000002","0000002","0000002","0000002","0000002","0000002","0000002","0000002","0000002"} end
  361.     end
  362.     --[[for i=1, #devFont do
  363.         table.insert(devFont[i], 1, "0000002")
  364.     end]]
  365.     local function compressChar(char)
  366.         local nChar = ""
  367.         for i=1, #char do
  368.             local tmp, rem, cnt = string.reverse(char[i] or "2"), true, 1
  369.             local tmp2 = {}
  370.             for i=1, tmp:len() do
  371.                 tmp2[i] = tmp:sub(i,i)
  372.             end
  373.             while true do
  374.                 if tmp2[cnt] then
  375.                     if tmp2[cnt] == "0" and rem then
  376.                         table.remove(tmp2, cnt)
  377.                     elseif tmp2[cnt] == "1" then
  378.                         rem = false cnt = cnt+1
  379.                     else
  380.                         cnt = cnt+1
  381.                     end
  382.                 else
  383.                     break
  384.                 end
  385.             end tmp = ""
  386.             for i=1, #tmp2 do
  387.                 tmp = tmp..tmp2[i]
  388.             end
  389.             nChar = nChar..tmp
  390.         end
  391.        
  392.         while true do
  393.             if nChar:sub(1,1) == "2" then
  394.                 nChar = nChar:sub(2,nChar:len())
  395.             else
  396.                 break
  397.             end
  398.         end
  399.         return string.reverse(nChar)
  400.        
  401.     end
  402.     local function reload()
  403.         term.setCursorPos(1,1)
  404.         term.setTextColor(colors.gray)
  405.         for i=1, 10 do
  406.             for ii=1, 6 do
  407.                 write(string.char(127))
  408.             end
  409.             term.setCursorPos(1,i)
  410.         end
  411.         term.setTextColor(colors.gray)
  412.         term.setCursorPos(1,1) drawChar(compressChar(devFont[math.max(1,sel-1)]))
  413.         term.setTextColor(colors.white)
  414.         term.setCursorPos(1,1) drawChar(compressChar(devFont[sel]))
  415.         term.setCursorPos(1,10) write("Char: "..sel.."/255 ("..(sel ~= 10 and string.char(sel) or " ")..")  ")
  416.         term.setCursorPos(1,h) write("Press CTRL for menu")
  417.     end
  418.     local function save()
  419.         term.clear() term.setCursorPos(1,1)
  420.         c("Saving...") sleep(1)
  421.         local f = fs.open("/gmc_font_dev.lua", "w")
  422.         if f then f.write(textutils.serialize(devFont)) f.close() else error("Failed to open dev file.") end
  423.         c("Complete!")
  424.         sleep(1) term.clear() reload() return true
  425.     end
  426.     local function export()
  427.         term.clear() term.setCursorPos(1,1)
  428.         c("Exporting...") sleep(1)
  429.         for i=1, #devFont do
  430.             devFont[i] = compressChar(devFont[i])
  431.         end
  432.         local f = fs.open("/gmc_font_dev_ex.lua", "w")
  433.         if f then f.write(textutils.serialize(devFont)) f.close() else error("Failed to open dev_ex file.") end
  434.         c("Complete!")
  435.         sleep(1) return false
  436.     end
  437.     term.setBackgroundColor(colors.black) term.clear()
  438.     reload() local run = true
  439.     while run do
  440.         a,b,x,y = os.pullEvent()
  441.         if a == "key" then
  442.             if b == keys.leftCtrl or b == keys.rightCtrl then
  443.                 local m, sel = {{"Save", save}, {"Export", export}, {"Close Menu", 0}, {"Exit GMFC", 1}}, 1
  444.                 local function drawMenu()
  445.                     term.setCursorPos(1,h)
  446.                     for i=1, #m do
  447.                         if sel == i then write("["..m[i][1].."]") else write(" "..m[i][1].." ") end
  448.                     end
  449.                 end
  450.                 while true do
  451.                     drawMenu()
  452.                     local a,b = os.pullEvent("key")
  453.                     if b == keys.left or b == keys.a then
  454.                         if sel ~= 1 then sel = sel-1 end
  455.                     elseif b == keys.right or b == keys.d then
  456.                         if sel ~= #m then sel = sel+1 end
  457.                     elseif b == keys.leftCtrl or b == keys.rightCtrl then
  458.                         break
  459.                     elseif b == keys.enter or b == keys.e then
  460.                         if type(m[sel][2]) ~= "function" then
  461.                             if m[sel][2] == 0 then
  462.                                 break
  463.                             elseif m[sel][2] == 1 then
  464.                                 run = false break
  465.                             end
  466.                         else run = m[sel][2]() break end
  467.                     end
  468.                 end term.setTextColor(colors.black)
  469.                 drawMenu() term.setTextColor(colors.white) term.setCursorPos(1,h) write("Press CTRL for menu")
  470.             elseif b == keys.left or b == keys.a then
  471.                 if sel <= 1 then sel = #devFont else sel = sel-1 end reload()
  472.             elseif b == keys.right or b == keys.d then
  473.                 if sel >= #devFont then sel = 1 else sel = sel+1 end reload()
  474.             end
  475.         elseif a == "mouse_click" or a == "mouse_drag" then
  476.             if x <= 6 and y <= 9 then
  477.                 if b == 1 then
  478.                     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)
  479.                     paintutils.drawPixel(x,y,colors.white) term.setBackgroundColor(colors.black)
  480.                 elseif b == 2 then
  481.                     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)
  482.                     term.setCursorPos(x,y) term.setTextColor(colors.gray) write(string.char(127)) term.setTextColor(colors.white)
  483.                 end
  484.             end
  485.         end
  486.     end
  487.     term.clear() term.setCursorPos(1,1) print("GMFC Closed.")
  488. end
  489. --GMFC()
Advertisement
Add Comment
Please, Sign In to add comment