toastonrye

master.lua

Aug 9th, 2022 (edited)
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.35 KB | None | 0 0
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by toastonrye.
  4. --- DateTime: 8/10/2022 6:13 AM
  5. ---
  6.  
  7. -- basalt configurated installer
  8. -- https://basalt.madefor.cc/#/home/installer?id=basic-installer
  9. local filePath = "basalt.lua"
  10. if not(fs.exists(filePath))then
  11.     shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", ""))
  12. end
  13.  
  14. -- requires
  15. local basalt = require(filePath:gsub(".lua", ""))
  16. require("masterLib")
  17.  
  18. -- [FUNCTION]-------------------------------------------------------- fancyButton function
  19. -- with lua's concept of overloading methods??
  20. local function fancyButton(button,override)
  21.     button:onClick(function(self)
  22.         button:setBackground(colours.black)
  23.         button:setForeground(colours.lightGrey)
  24.     end)
  25.     button:onClickUp(function(self)
  26.         button:setBackground(override or colours.grey)
  27.         button:setForeground(colours.black)
  28.     end)
  29.     button:onLoseFocus(function(self)
  30.         button:setBackground(override or colours.grey)
  31.         button:setForeground(colours.black)
  32.     end)
  33. end
  34. -- [FUNCTION]-------------------------------------------------------- generateSecretCode function
  35. -- TODO prevent duplicate coloured pegs ??
  36. local function generateSecretCode(secretPane)
  37.     local r = {}
  38.     for i=1, 4 do
  39.         table.insert(r, math.random(1,8))
  40.     end
  41.     local randomPegs = {}
  42.     local rOffset = 2
  43.     for k, v in ipairs(r) do
  44.         randomPegs[k] = secretPane:addPane()
  45.                                   :setSize(1,1)
  46.                                   :setValue(pinsStr[v])
  47.                                   :setPosition(rOffset,2)
  48.                                   :setBackground(pins[v])
  49.         rOffset = rOffset + 2
  50.         --basalt.debug(randomPeg[k]:getValue().." getValue() from pinsStr[]")
  51.     end
  52.     return randomPegs
  53. end
  54. -- [FUNCTION]-------------------------------------------------------- initScoreBoard function
  55. local function initScoreBoard(frame, maxRows, userGuessFrame)
  56.     local rowTable = {}
  57.     local initRow
  58.     local inputTable = {}
  59.  
  60.     -- draws the fancy multi coloured scoreboard rows
  61.     for i=1, maxRows do
  62.         rowTable[i] = frame:addFrame()
  63.                            :setSize(9,3)
  64.                            :setPosition(1,-2+(i*3))
  65.         if i%2 == 0 then
  66.             rowTable[i]:setBackground(colours.lightGrey)
  67.         end
  68.     end
  69.     -- Makes 4 white slots on the black user input thing
  70.     for i=1, 4 do
  71.         inputTable[i] = userGuessFrame:addPane()
  72.                                         :setBackground(colours.white)
  73.                                         :setPosition(0+(i*2),2)
  74.                                         :setValue("colours.white")
  75.     end
  76.  
  77.  
  78.     return inputTable, rowTable --initRow
  79. end
  80. -- [FUNCTION]-------------------------------------------------------- scoreUserGuess function
  81. local function scoreUserGuess(frame, pegTable) ---------ISSUES IN HERE!!!!!!!!!
  82.     local scoreTable = {}
  83.     for i=1, #pegTable do
  84.         scoreTable = frame[rowPosition]:addPane() -- scoringRows is a bunch of frames??
  85.                                 :setBackground(pegTable[i]:getBackground())
  86.                                 :setPosition(0+(i*2),2)
  87.                                 :setValue(pegTable[i]:getValue())
  88.     end
  89.     basalt.debug(rowPosition.." row pos")
  90.     return scoreTable
  91. end
  92.  
  93. -- [GLOBAL VAR]-------------------------------------------------------- generateSecretCode function
  94. currentGuess = {}   -- user's guess, submitted or cleared by enter/x buttons
  95. secretCode = {}     -- random 4 peg table
  96. scoringRows = {}
  97. rowPosition = 1
  98. pegPosition = 1     -- tracks peg position of currentGuess[] (1 through 4)
  99.  
  100.  
  101. -- [FRAMES START] =================================================================
  102. local mainFrame = basalt.createFrame("mainFrame")
  103.                         :show()
  104.                         :setBackground(colours.lightBlue)
  105.  
  106. local w, h = term.getSize()
  107. local gameFrame = mainFrame.addFrame()
  108.                            :setBackground(colours.cyan)
  109.                            :setSize(w-3,h)
  110.                            :setPosition(2,1)
  111.  
  112. local secretCodeFrame = gameFrame:addFrame()
  113.                                  :setSize(9,3)
  114.                                  :setPosition(16,2)
  115.                                  :setBackground(colours.brown)
  116.  
  117. local inputFrame = gameFrame:addFrame()
  118.                             :setSize(26,9)
  119.                             :setPosition(3,6)
  120.                             :setMoveable(true)
  121.  
  122. local userGuessFrame = inputFrame:addFrame()
  123.                                  :setSize(9,3)
  124.                                  :setPosition(10,2)
  125.                                  :setBackground(colours.black)
  126.  
  127. local scoringFrame = gameFrame:addFrame()
  128.                               :setSize(9,50)
  129.                               :setPosition(35,2)
  130.  
  131. -- [FRAMES] function makes some scoreboard rows and inits things
  132. currentGuess, scoringRows = initScoreBoard(scoringFrame, 12, userGuessFrame) -- hard coded to 1 for init
  133.  
  134. -- [SCROLLBAR: mainFrame]-----------------------------------------------------
  135. local scrollbar = mainFrame:addScrollbar()
  136.                            :setPosition(w-1,3)
  137.                            :setSize(1,h-3)
  138.                            :setMaxValue(30)
  139.                            :onChange(function(self)
  140.                                 local y = self:getValue()
  141.                                 gameFrame:setOffset(0,y-2)
  142.                             end)
  143.  
  144. -- [BUTTON: NEW GAME]-----------------------------------------------------
  145. fancyButton(gameFrame:addButton("getCode")
  146.                      :setPosition(3,2)
  147.                      :setValue("NEW GAME")
  148.                      :onClick(function()
  149.                         secretCode = generateSecretCode(secretCodeFrame)
  150.                      end)) -- no colour overloading fancyButton function, nil
  151.  
  152. -- [BUTTON: ENTER]--------------------------------------------------------
  153. fancyButton(inputFrame:addButton()
  154.                       :setPosition(2,2)
  155.                       :setSize(7,3)
  156.                       :setValue("ENTER")
  157.                       :setBackground(colours.green)
  158.                       :onClick(function()
  159.                         basalt.debug("ENTER clicked")
  160.                         scoreUserGuess(scoringRows, currentGuess) --scoringRows actually many 12 frames
  161.                         rowPosition = rowPosition + 1
  162.                       end), colours.green)
  163.  
  164. -- [BUTTON: X]-----------------------------------------------------------
  165. fancyButton(inputFrame:addButton()
  166.                       :setPosition(20,2)
  167.                       :setSize(3,3)
  168.                       :setValue("X")
  169.                       :setBackground(colours.red)
  170.                       :onClick(function()
  171.                         basalt.debug("X clicked")
  172.                         pegPosition = 1
  173.                         for i=1, #currentGuess do
  174.                             currentGuess[i]:setBackground(colours.white)
  175.                             currentGuess[i]:setValue("")
  176.                         end
  177.                       end), colours.red)
  178.  
  179. -- --------------------------------------------------------------------------- START COLOUR KEYBOARD
  180. -- in game keyboard/ pin colour picker
  181. local guessInput = {}
  182. for i=1, #pins do
  183.     guessInput[i] = fancyButton(inputFrame:addButton()
  184.                                           :setPosition(-1+(i*3),6)
  185.                                           :setValue(i)
  186.                                           :setSize(3,3)
  187.                                           :setBackground(pins[i])
  188.                                           :onClick(function(self)
  189.                                             if pegPosition > 4 then
  190.                                                 pegPosition = 1
  191.                                             end
  192.                                             currentGuess[pegPosition]:setBackground(pins[i])
  193.                                                                     :setValue(pinsStr[i])
  194.                                             basalt.debug(currentGuess[pegPosition]:getValue().." str stored")
  195.                                             pegPosition = pegPosition + 1
  196.                                           end) , pins[i]) -- overloading fancyButton, restores appropriate button colour
  197. end
  198.  
  199. --basalt.debug("W: "..w.." H: "..h)
  200. basalt.autoUpdate()
Add Comment
Please, Sign In to add comment