Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by toastonrye.
- --- DateTime: 8/10/2022 6:13 AM
- ---
- -- basalt configurated installer
- -- https://basalt.madefor.cc/#/home/installer?id=basic-installer
- local filePath = "basalt.lua"
- if not(fs.exists(filePath))then
- shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", ""))
- end
- -- requires
- local basalt = require(filePath:gsub(".lua", ""))
- require("masterLib")
- -- [FUNCTION]-------------------------------------------------------- fancyButton function
- -- with lua's concept of overloading methods??
- local function fancyButton(button,override)
- button:onClick(function(self)
- button:setBackground(colours.black)
- button:setForeground(colours.lightGrey)
- end)
- button:onClickUp(function(self)
- button:setBackground(override or colours.grey)
- button:setForeground(colours.black)
- end)
- button:onLoseFocus(function(self)
- button:setBackground(override or colours.grey)
- button:setForeground(colours.black)
- end)
- end
- -- [FUNCTION]-------------------------------------------------------- generateSecretCode function
- -- TODO prevent duplicate coloured pegs ??
- local function generateSecretCode(secretPane)
- local r = {}
- for i=1, 4 do
- table.insert(r, math.random(1,8))
- end
- local randomPegs = {}
- local rOffset = 2
- for k, v in ipairs(r) do
- randomPegs[k] = secretPane:addPane()
- :setSize(1,1)
- :setValue(pinsStr[v])
- :setPosition(rOffset,2)
- :setBackground(pins[v])
- rOffset = rOffset + 2
- --basalt.debug(randomPeg[k]:getValue().." getValue() from pinsStr[]")
- end
- return randomPegs
- end
- -- [FUNCTION]-------------------------------------------------------- initScoreBoard function
- local function initScoreBoard(frame, maxRows, userGuessFrame)
- local rowTable = {}
- local initRow
- local inputTable = {}
- -- draws the fancy multi coloured scoreboard rows
- for i=1, maxRows do
- rowTable[i] = frame:addFrame()
- :setSize(9,3)
- :setPosition(1,-2+(i*3))
- if i%2 == 0 then
- rowTable[i]:setBackground(colours.lightGrey)
- end
- end
- -- Makes 4 white slots on the black user input thing
- for i=1, 4 do
- inputTable[i] = userGuessFrame:addPane()
- :setBackground(colours.white)
- :setPosition(0+(i*2),2)
- :setValue("colours.white")
- end
- return inputTable, rowTable --initRow
- end
- -- [FUNCTION]-------------------------------------------------------- scoreUserGuess function
- local function scoreUserGuess(frame, pegTable) ---------ISSUES IN HERE!!!!!!!!!
- local scoreTable = {}
- for i=1, #pegTable do
- scoreTable = frame[rowPosition]:addPane() -- scoringRows is a bunch of frames??
- :setBackground(pegTable[i]:getBackground())
- :setPosition(0+(i*2),2)
- :setValue(pegTable[i]:getValue())
- end
- basalt.debug(rowPosition.." row pos")
- return scoreTable
- end
- -- [GLOBAL VAR]-------------------------------------------------------- generateSecretCode function
- currentGuess = {} -- user's guess, submitted or cleared by enter/x buttons
- secretCode = {} -- random 4 peg table
- scoringRows = {}
- rowPosition = 1
- pegPosition = 1 -- tracks peg position of currentGuess[] (1 through 4)
- -- [FRAMES START] =================================================================
- local mainFrame = basalt.createFrame("mainFrame")
- :show()
- :setBackground(colours.lightBlue)
- local w, h = term.getSize()
- local gameFrame = mainFrame.addFrame()
- :setBackground(colours.cyan)
- :setSize(w-3,h)
- :setPosition(2,1)
- local secretCodeFrame = gameFrame:addFrame()
- :setSize(9,3)
- :setPosition(16,2)
- :setBackground(colours.brown)
- local inputFrame = gameFrame:addFrame()
- :setSize(26,9)
- :setPosition(3,6)
- :setMoveable(true)
- local userGuessFrame = inputFrame:addFrame()
- :setSize(9,3)
- :setPosition(10,2)
- :setBackground(colours.black)
- local scoringFrame = gameFrame:addFrame()
- :setSize(9,50)
- :setPosition(35,2)
- -- [FRAMES] function makes some scoreboard rows and inits things
- currentGuess, scoringRows = initScoreBoard(scoringFrame, 12, userGuessFrame) -- hard coded to 1 for init
- -- [SCROLLBAR: mainFrame]-----------------------------------------------------
- local scrollbar = mainFrame:addScrollbar()
- :setPosition(w-1,3)
- :setSize(1,h-3)
- :setMaxValue(30)
- :onChange(function(self)
- local y = self:getValue()
- gameFrame:setOffset(0,y-2)
- end)
- -- [BUTTON: NEW GAME]-----------------------------------------------------
- fancyButton(gameFrame:addButton("getCode")
- :setPosition(3,2)
- :setValue("NEW GAME")
- :onClick(function()
- secretCode = generateSecretCode(secretCodeFrame)
- end)) -- no colour overloading fancyButton function, nil
- -- [BUTTON: ENTER]--------------------------------------------------------
- fancyButton(inputFrame:addButton()
- :setPosition(2,2)
- :setSize(7,3)
- :setValue("ENTER")
- :setBackground(colours.green)
- :onClick(function()
- basalt.debug("ENTER clicked")
- scoreUserGuess(scoringRows, currentGuess) --scoringRows actually many 12 frames
- rowPosition = rowPosition + 1
- end), colours.green)
- -- [BUTTON: X]-----------------------------------------------------------
- fancyButton(inputFrame:addButton()
- :setPosition(20,2)
- :setSize(3,3)
- :setValue("X")
- :setBackground(colours.red)
- :onClick(function()
- basalt.debug("X clicked")
- pegPosition = 1
- for i=1, #currentGuess do
- currentGuess[i]:setBackground(colours.white)
- currentGuess[i]:setValue("")
- end
- end), colours.red)
- -- --------------------------------------------------------------------------- START COLOUR KEYBOARD
- -- in game keyboard/ pin colour picker
- local guessInput = {}
- for i=1, #pins do
- guessInput[i] = fancyButton(inputFrame:addButton()
- :setPosition(-1+(i*3),6)
- :setValue(i)
- :setSize(3,3)
- :setBackground(pins[i])
- :onClick(function(self)
- if pegPosition > 4 then
- pegPosition = 1
- end
- currentGuess[pegPosition]:setBackground(pins[i])
- :setValue(pinsStr[i])
- basalt.debug(currentGuess[pegPosition]:getValue().." str stored")
- pegPosition = pegPosition + 1
- end) , pins[i]) -- overloading fancyButton, restores appropriate button colour
- end
- --basalt.debug("W: "..w.." H: "..h)
- basalt.autoUpdate()
Add Comment
Please, Sign In to add comment