SHOW:
|
|
- or go back to the newest paste.
| 1 | - | os.loadAPI("System/API/windows")
|
| 1 | + | |
| 2 | ||
| 3 | - | --ПАРОЛЬ |
| 3 | + | |
| 4 | {"1","2","3"},
| |
| 5 | {"4","5","6"},
| |
| 6 | - | --СКОЛЬКО БУДЕТ ОТКРЫТА ДВЕРЬ |
| 6 | + | |
| 7 | - | local doorOpenTime = 5 |
| 7 | + | |
| 8 | } | |
| 9 | - | --СКОЛЬКО БУДЕТ НАЖАТА КНОПКА |
| 9 | + | |
| 10 | - | local buttonPressTime = 0.2 |
| 10 | + | |
| 11 | ||
| 12 | - | --ПЕРЕМЕННАЯ ТАЙМЕРА |
| 12 | + | |
| 13 | - | local changePasswordTimer = nil |
| 13 | + | |
| 14 | local xSize,ySize = term.getSize() | |
| 15 | - | --РЕЖИМ РАБОТЫ ДИСПЛЕЯ |
| 15 | + | local centerX = math.floor(xSize/2) |
| 16 | - | local mode = "default" |
| 16 | + | local centerX = math.floor(ySize/2) |
| 17 | ||
| 18 | - | --СКРЫВАТЬ ЛИ ВВОДИМЫЙ ПАРОЛЬ |
| 18 | + | |
| 19 | - | local hidePassword = "false" |
| 19 | + | |
| 20 | local PeriList = peripheral.getNames() | |
| 21 | - | --ОТСЮДА ИЗЛУЧАТЬ СИГНАЛ РЕДА, ЕСЛИ ПАРОЛЬ ВЕРЕН |
| 21 | + | |
| 22 | - | local redstoneSide = "left" |
| 22 | + | |
| 23 | - | --А ОТСЮДА, ЕСЛИ НЕ ВЕРЕН |
| 23 | + | |
| 24 | - | local redstoneSideOnWrongPassword = "right" |
| 24 | + | |
| 25 | end | |
| 26 | - | --КНОПОЧКИ |
| 26 | + | |
| 27 | ||
| 28 | --ЧТЕНИЕ КОНФИГА | |
| 29 | function configRead(pathToConfig,whatToRead) | |
| 30 | if not fs.exists(pathToConfig) then error("No such file") end
| |
| 31 | local file = fs.open(pathToConfig,"r") | |
| 32 | while true do | |
| 33 | local line = file.readLine() | |
| 34 | - | --МАССИВ ОБЪЕКТОВ |
| 34 | + | |
| 35 | local key, value = string.match(line,"(.*)=(.*)") | |
| 36 | if value ~= nil and key == whatToRead then | |
| 37 | - | --МАССИВ СИМВОЛОВ, ВВЕДЕННЫХ С ПОМОЩЬЮ КНОПОК |
| 37 | + | |
| 38 | return value | |
| 39 | end | |
| 40 | - | --ПОЛУЧЕНИЕ РАЗМЕРА МОНИТОРА |
| 40 | + | |
| 41 | - | local xSize, ySize = term.getSize() |
| 41 | + | |
| 42 | break | |
| 43 | end | |
| 44 | end | |
| 45 | end | |
| 46 | ||
| 47 | --ЗАПИСЬ В КОНФИГ | |
| 48 | local function configWrite(pathToConfig,key,value) | |
| 49 | if not fs.exists(pathToConfig) then | |
| 50 | local file = fs.open(pathToConfig,"w") | |
| 51 | file.close() | |
| 52 | end | |
| 53 | - | --УНИВЕРСАЛЬНАЯ ФУНКЦИЯ ДЛЯ ОТОБРАЖЕНИЯ ТЕКСТА ПО ЦЕНТРУ ЭКРАНА |
| 53 | + | |
| 54 | - | local function centerText(how,coord,text,textColor,backColor) |
| 54 | + | |
| 55 | local Massiv = {}
| |
| 56 | ||
| 57 | - | if how == "xy" then |
| 57 | + | |
| 58 | - | term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2)) |
| 58 | + | |
| 59 | - | elseif how == "x" then |
| 59 | + | |
| 60 | - | term.setCursorPos(math.floor(xSize/2-#text/2),coord) |
| 60 | + | |
| 61 | - | elseif how == "y" then |
| 61 | + | |
| 62 | - | term.setCursorPos(coord,math.floor(ySize/2)) |
| 62 | + | |
| 63 | file.close() | |
| 64 | break | |
| 65 | end | |
| 66 | lineCounter = lineCounter + 1 | |
| 67 | end | |
| 68 | ||
| 69 | local success = false | |
| 70 | for i=1,#Massiv do | |
| 71 | local key1, value1 = string.match(Massiv[i],"(.*)=(.*)") | |
| 72 | if value1 ~= nil and key1 == key then | |
| 73 | Massiv[i] = key.."="..value | |
| 74 | success = true | |
| 75 | end | |
| 76 | end | |
| 77 | ||
| 78 | if success == false then Massiv[#Massiv+1] = key.."="..value end | |
| 79 | ||
| 80 | local file = fs.open(pathToConfig,"w") | |
| 81 | for i=1,#Massiv do | |
| 82 | file.writeLine(Massiv[i]) | |
| 83 | end | |
| 84 | file.close() | |
| 85 | end | |
| 86 | ||
| 87 | --ОБЪЕКТЫ | |
| 88 | local function newObj(name,x,y) | |
| 89 | Obj[name]={}
| |
| 90 | Obj[name]["x"]=x | |
| 91 | Obj[name]["y"]=y | |
| 92 | end | |
| 93 | ||
| 94 | --ПРОСТАЯ ЗАЛИВКА ЭКРАНА ЦВЕТОМ | |
| 95 | local function clearScreen(color) | |
| 96 | term.setBackgroundColor(color) | |
| 97 | term.clear() | |
| 98 | end | |
| 99 | ||
| 100 | --ПРОСТОЙ ТЕКСТ | |
| 101 | local function usualText(x,y,text) | |
| 102 | term.setCursorPos(x,y) | |
| 103 | term.write(text) | |
| 104 | end | |
| 105 | ||
| 106 | --ОТРИСОВКА ВЕРХНЕЙ ШТУЧКИ | |
| 107 | local function drawTab(textColor,backColor) | |
| 108 | term.setBackgroundColor(backColor) | |
| 109 | term.setTextColor(textColor) | |
| 110 | term.setCursorPos(2,1) | |
| 111 | term.clearLine() | |
| 112 | term.write("-----")
| |
| 113 | ||
| 114 | for i=1,#inputCode do | |
| 115 | usualText(1+i,1,inputCode[i]) | |
| 116 | end | |
| 117 | end | |
| 118 | ||
| 119 | ----------------------CТАРТ ПРОГРАММЫ------------------------------------ | |
| 120 | ||
| 121 | --ПОДКЛЮЧЕНИЕ МОНИТОРА | |
| 122 | local m = findPeripheral("monitor")
| |
| 123 | if m ~= nil then | |
| 124 | m = peripheral.wrap(m) | |
| 125 | if not m.isColor() then error("This program works ONLY with advanced monitor.") end
| |
| 126 | m.setTextScale(1) | |
| 127 | term.redirect(m) | |
| 128 | else | |
| 129 | error("This program requires advanced external monitor.")
| |
| 130 | end | |
| 131 | ||
| 132 | --ЧТЕНИЕ КОНФИГА | |
| 133 | if fs.exists("System/CodeDoor/password.cfg") then
| |
| 134 | password = configRead("System/CodeDoor/password.cfg","password")
| |
| 135 | else | |
| 136 | configWrite("System/CodeDoor/password.cfg","password","12345")
| |
| 137 | end | |
| 138 | ||
| 139 | term.setCursorBlink(false) | |
| 140 | clearScreen(colors.white) | |
| 141 | term.setTextColor(colors.black) | |
| 142 | ||
| 143 | for j=1,#buttons do | |
| 144 | for i=1,#buttons[j] do | |
| 145 | local xPos = i*2 | |
| 146 | local yPos = 1+j | |
| 147 | usualText(xPos,yPos,buttons[j][i]) | |
| 148 | newObj(buttons[j][i],xPos,yPos) | |
| 149 | end | |
| 150 | end | |
| 151 | ||
| 152 | drawTab(colors.white,colors.black) | |
| 153 | ||
| 154 | - | if hidePassword == "true" then |
| 154 | + | |
| 155 | - | usualText(i+1,1,"*") |
| 155 | + | |
| 156 | if event == "monitor_touch" then | |
| 157 | - | usualText(i+1,1,inputCode[i]) |
| 157 | + | |
| 158 | if x==Obj[key]["x"] and y==Obj[key]["y"] then | |
| 159 | term.setBackgroundColor(colors.green) | |
| 160 | term.setTextColor(colors.white) | |
| 161 | usualText(Obj[key]["x"],Obj[key]["y"],key) | |
| 162 | - | --ОТРИСОВКА КОНКРЕТНОЙ КНОПКИ |
| 162 | + | sleep(0.2) |
| 163 | - | local function drawButton(name,textColor,backColor) |
| 163 | + | term.setBackgroundColor(colors.white) |
| 164 | term.setTextColor(colors.black) | |
| 165 | usualText(Obj[key]["x"],Obj[key]["y"],key) | |
| 166 | - | usualText(Obj[name]["x"],Obj[name]["y"],name) |
| 166 | + | |
| 167 | if key ~= "C" and key ~= "#" then | |
| 168 | if #inputCode < 5 then | |
| 169 | inputCode[#inputCode+1] = key | |
| 170 | - | --ОТРИСОВКА ВСЕГО ИНТЕРФЕЙСА |
| 170 | + | |
| 171 | - | local function gui() |
| 171 | + | |
| 172 | - | --ОЧИСТКА ЭКРАНА |
| 172 | + | |
| 173 | - | term.setCursorBlink(false) |
| 173 | + | elseif key == "C" then |
| 174 | - | clearScreen(colors.white) |
| 174 | + | |
| 175 | - | term.setTextColor(colors.black) |
| 175 | + | drawTab(colors.white,colors.black) |
| 176 | ||
| 177 | - | --ОТРИСОВКА КНОПОЧЕК |
| 177 | + | |
| 178 | - | for j=1,#buttons do |
| 178 | + | |
| 179 | - | for i=1,#buttons[j] do |
| 179 | + | |
| 180 | - | local xPos = i*2 |
| 180 | + | |
| 181 | - | local yPos = 1+j |
| 181 | + | |
| 182 | - | usualText(xPos,yPos,buttons[j][i]) |
| 182 | + | |
| 183 | - | newObj(buttons[j][i],xPos,yPos) |
| 183 | + | if inputPass == password then |
| 184 | drawTab(colors.white,colors.green) | |
| 185 | sleep(5) | |
| 186 | inputCode = {}
| |
| 187 | - | --ОТРИСОВКА ВЕРХНЕЙ ШНЯГИ |
| 187 | + | |
| 188 | - | drawTab(colors.white,colors.black) |
| 188 | + | |
| 189 | drawTab(colors.white,colors.red) | |
| 190 | sleep(1) | |
| 191 | - | ------------------------------CТАРТ ПРОГРАММЫ------------------------------------ |
| 191 | + | |
| 192 | end | |
| 193 | - | if not term.isColor() then |
| 193 | + | |
| 194 | - | error("This program requires an advanced computer.")
|
| 194 | + | |
| 195 | break | |
| 196 | end | |
| 197 | - | --РИСУЕМ В КОМПЕ ХУЙНЮ |
| 197 | + | |
| 198 | end | |
| 199 | - | centerText("xy",0,"Program started.",colors.lightGray,colors.white)
|
| 199 | + | end |