Advertisement
massacring

Commons

Jun 21st, 2025
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.67 KB | None | 0 0
  1. local Credit = require('Credit')
  2.  
  3. local Paint = {}
  4. Paint.primaryBackgroundColor = 128
  5. Paint.secondaryBackgroundColor = 256
  6. Paint.defaultTextColor = 1
  7.  
  8. function Paint.drawSquare(window, x, y, span, length, color)
  9.     local oldTerm = term.redirect(window)
  10.     term.setCursorPos(x,y)
  11.     term.setBackgroundColor(color)
  12.     for row = 1, length, 1 do
  13.         term.setCursorPos(x,y+row-1)
  14.         term.write(string.rep(" ", span))
  15.     end
  16.     term.redirect(oldTerm)
  17. end
  18.  
  19. function Paint.write(window, text, x, y, textColor, backGroundColor)
  20.     local oldTerm = term.redirect(window)
  21.     if backGroundColor == nil then
  22.         if y % 2 == 1 then
  23.             backGroundColor = Paint.primaryBackgroundColor
  24.         else
  25.             backGroundColor = Paint.secondaryBackgroundColor
  26.         end
  27.     end
  28.     textColor = textColor or Paint.defaultTextColor
  29.     term.setCursorPos(x,y)
  30.     term.setBackgroundColor(backGroundColor)
  31.     term.setTextColor(textColor)
  32.     term.write(text)
  33.     term.redirect(oldTerm)
  34. end
  35.  
  36. function Paint.clear(window, width, height, primaryColor, secondaryColor)
  37.     local oldTerm = term.redirect(window)
  38.     for x=1,width,1 do
  39.         for y=1,height,1 do
  40.             if (y % 2 == 1) then
  41.                 term.setBackgroundColor(primaryColor)
  42.             else
  43.                 term.setBackgroundColor(secondaryColor)
  44.             end
  45.             term.setCursorPos(x,y)
  46.             term.write(" ")
  47.         end
  48.     end
  49.     term.redirect(oldTerm)
  50. end
  51.  
  52. local Credits = {}
  53. Credits.SMALL = 1
  54. Credits.MEDIUM = 2
  55. Credits.LARGE = 3
  56. Credits.credits = {
  57.     --["emeralds"] = Credit.new("emeralds"),
  58.     ["iron"] = Credit.new("iron", {
  59.         [Credits.LARGE] = { ['id'] = 'minecraft:iron_block', ['multiplier'] = 9 },
  60.         [Credits.MEDIUM] = { ['id'] = 'minecraft:iron_ingot', ['multiplier'] = 9 },
  61.         [Credits.SMALL] = { ['id'] = 'minecraft:iron_nugget' },
  62.     }),
  63. }
  64. Credits.selectedCredit = nil
  65.  
  66. function Credits.validCurrency(name)
  67.     for _,credit in pairs(Credits.credits) do
  68.         for _,data in pairs(credit.values) do
  69.             if (name == data["id"]) then return true end
  70.         end
  71.     end
  72.     return false
  73. end
  74.  
  75. function Credits.getValueByName(name)
  76.     for _,credit in pairs(Credits.credits) do
  77.         for size,data in pairs(credit.values) do
  78.             if (name == data["id"]) then
  79.                 local multiplier = data["multiplier"] or 1
  80.                 return multiplier ^ (size-1)
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86. function Credits.getValueBySize(size)
  87.     if Credits.selectedCredit == nil then return nil end
  88.     if type(size) ~= "number" then return nil end
  89.     if size < 1 or size > 3 then return nil end
  90.     local multiplier = Credits.credits[Credits.selectedCredit].values[size]["multiplier"]
  91.     return multiplier ^ (size-1)
  92. end
  93.  
  94. function Credits.getSizeByName(name)
  95.     for _,credit in pairs(Credits.credits) do
  96.         for size,data in pairs(credit.values) do
  97.             if (name == data["id"]) then return size end
  98.         end
  99.     end
  100. end
  101.  
  102. function Credits.getName(itemName)
  103.     for name,credit in pairs(Credits.credits) do
  104.         for _,data in pairs(credit.values) do
  105.             if (itemName == data["id"]) then return name end
  106.         end
  107.     end
  108. end
  109.  
  110. function Credits.getCurrentId(size)
  111.     if Credits.selectedCredit == nil then return nil end
  112.     if type(size) ~= "number" then return nil end
  113.     if size < 1 or size > 3 then return nil end
  114.     return Credits.credits[Credits.selectedCredit].values[size]["id"]
  115. end
  116.  
  117. function Credits.drawCredit(window, x, y, textColor, backGroundColor)
  118.     local label = "Credit Type: " .. Credits.selectedCredit
  119.  
  120.     Paint.write(window, label, x, y, textColor, backGroundColor)
  121. end
  122.  
  123. local Score = {}
  124. Score.value = 0
  125. Score.max = 10000
  126. Score.min = 4
  127.  
  128. function Score.updateScore(num)
  129.     print("Updating score: " .. tostring(num))
  130.     Score.value = num
  131. end
  132.  
  133. function Score.getScore()
  134.     print("Score is: " .. tostring(Score.value))
  135.     return Score.value
  136. end
  137.  
  138. function Score.drawScore(window, x, y, primaryTextColor, primaryBackgroundColor, secondaryTextColor, secondaryBackgroundColor, offset)
  139.     local scoreTitle = "Score:"
  140.     local scoreText = tostring(Score.value)
  141.     local scoreTextLen = string.len(scoreText) + 2
  142.     if scoreTextLen < 13 then scoreTextLen = 13 end
  143.     if offset then x = x - math.floor(scoreTextLen / 2) end
  144.  
  145.     Paint.write(window, scoreTitle, x+1, y, secondaryTextColor, secondaryBackgroundColor)
  146.     Paint.drawSquare(window, x, y+1, scoreTextLen, 3, primaryBackgroundColor)
  147.     Paint.write(window, scoreText, x+1, y+2, primaryTextColor, primaryBackgroundColor)
  148. end
  149.  
  150. return { Paint = Paint, Credits = Credits, Score = Score }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement