mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-01-07 19:52:40 +01:00
2к-помойку вынес на хуй
This commit is contained in:
parent
728fa175d9
commit
56f03d0dbe
@ -1,258 +0,0 @@
|
||||
return {
|
||||
0x000000,
|
||||
0x000040,
|
||||
0x000080,
|
||||
0x0000BF,
|
||||
0x0000FF,
|
||||
0x002400,
|
||||
0x002440,
|
||||
0x002480,
|
||||
0x0024BF,
|
||||
0x0024FF,
|
||||
0x004900,
|
||||
0x004940,
|
||||
0x004980,
|
||||
0x0049BF,
|
||||
0x0049FF,
|
||||
0x006D00,
|
||||
0x006D40,
|
||||
0x006D80,
|
||||
0x006DBF,
|
||||
0x006DFF,
|
||||
0x009200,
|
||||
0x009240,
|
||||
0x009280,
|
||||
0x0092BF,
|
||||
0x0092FF,
|
||||
0x00B600,
|
||||
0x00B640,
|
||||
0x00B680,
|
||||
0x00B6BF,
|
||||
0x00B6FF,
|
||||
0x00DB00,
|
||||
0x00DB40,
|
||||
0x00DB80,
|
||||
0x00DBBF,
|
||||
0x00DBFF,
|
||||
0x00FF00,
|
||||
0x00FF40,
|
||||
0x00FF80,
|
||||
0x00FFBF,
|
||||
0x00FFFF,
|
||||
0x0F0F0F,
|
||||
0x1E1E1E,
|
||||
0x2D2D2D,
|
||||
0x330000,
|
||||
0x330040,
|
||||
0x330080,
|
||||
0x3300BF,
|
||||
0x3300FF,
|
||||
0x332400,
|
||||
0x332440,
|
||||
0x332480,
|
||||
0x3324BF,
|
||||
0x3324FF,
|
||||
0x334900,
|
||||
0x334940,
|
||||
0x334980,
|
||||
0x3349BF,
|
||||
0x3349FF,
|
||||
0x336D00,
|
||||
0x336D40,
|
||||
0x336D80,
|
||||
0x336DBF,
|
||||
0x336DFF,
|
||||
0x339200,
|
||||
0x339240,
|
||||
0x339280,
|
||||
0x3392BF,
|
||||
0x3392FF,
|
||||
0x33B600,
|
||||
0x33B640,
|
||||
0x33B680,
|
||||
0x33B6BF,
|
||||
0x33B6FF,
|
||||
0x33DB00,
|
||||
0x33DB40,
|
||||
0x33DB80,
|
||||
0x33DBBF,
|
||||
0x33DBFF,
|
||||
0x33FF00,
|
||||
0x33FF40,
|
||||
0x33FF80,
|
||||
0x33FFBF,
|
||||
0x33FFFF,
|
||||
0x3C3C3C,
|
||||
0x4B4B4B,
|
||||
0x5A5A5A,
|
||||
0x660000,
|
||||
0x660040,
|
||||
0x660080,
|
||||
0x6600BF,
|
||||
0x6600FF,
|
||||
0x662400,
|
||||
0x662440,
|
||||
0x662480,
|
||||
0x6624BF,
|
||||
0x6624FF,
|
||||
0x664900,
|
||||
0x664940,
|
||||
0x664980,
|
||||
0x6649BF,
|
||||
0x6649FF,
|
||||
0x666D00,
|
||||
0x666D40,
|
||||
0x666D80,
|
||||
0x666DBF,
|
||||
0x666DFF,
|
||||
0x669200,
|
||||
0x669240,
|
||||
0x669280,
|
||||
0x6692BF,
|
||||
0x6692FF,
|
||||
0x66B600,
|
||||
0x66B640,
|
||||
0x66B680,
|
||||
0x66B6BF,
|
||||
0x66B6FF,
|
||||
0x66DB00,
|
||||
0x66DB40,
|
||||
0x66DB80,
|
||||
0x66DBBF,
|
||||
0x66DBFF,
|
||||
0x66FF00,
|
||||
0x66FF40,
|
||||
0x66FF80,
|
||||
0x66FFBF,
|
||||
0x66FFFF,
|
||||
0x696969,
|
||||
0x787878,
|
||||
0x878787,
|
||||
0x969696,
|
||||
0x990000,
|
||||
0x990040,
|
||||
0x990080,
|
||||
0x9900BF,
|
||||
0x9900FF,
|
||||
0x992400,
|
||||
0x992440,
|
||||
0x992480,
|
||||
0x9924BF,
|
||||
0x9924FF,
|
||||
0x994900,
|
||||
0x994940,
|
||||
0x994980,
|
||||
0x9949BF,
|
||||
0x9949FF,
|
||||
0x996D00,
|
||||
0x996D40,
|
||||
0x996D80,
|
||||
0x996DBF,
|
||||
0x996DFF,
|
||||
0x999200,
|
||||
0x999240,
|
||||
0x999280,
|
||||
0x9992BF,
|
||||
0x9992FF,
|
||||
0x99B600,
|
||||
0x99B640,
|
||||
0x99B680,
|
||||
0x99B6BF,
|
||||
0x99B6FF,
|
||||
0x99DB00,
|
||||
0x99DB40,
|
||||
0x99DB80,
|
||||
0x99DBBF,
|
||||
0x99DBFF,
|
||||
0x99FF00,
|
||||
0x99FF40,
|
||||
0x99FF80,
|
||||
0x99FFBF,
|
||||
0x99FFFF,
|
||||
0xA5A5A5,
|
||||
0xB4B4B4,
|
||||
0xC3C3C3,
|
||||
0xCC0000,
|
||||
0xCC0040,
|
||||
0xCC0080,
|
||||
0xCC00BF,
|
||||
0xCC00FF,
|
||||
0xCC2400,
|
||||
0xCC2440,
|
||||
0xCC2480,
|
||||
0xCC24BF,
|
||||
0xCC24FF,
|
||||
0xCC4900,
|
||||
0xCC4940,
|
||||
0xCC4980,
|
||||
0xCC49BF,
|
||||
0xCC49FF,
|
||||
0xCC6D00,
|
||||
0xCC6D40,
|
||||
0xCC6D80,
|
||||
0xCC6DBF,
|
||||
0xCC6DFF,
|
||||
0xCC9200,
|
||||
0xCC9240,
|
||||
0xCC9280,
|
||||
0xCC92BF,
|
||||
0xCC92FF,
|
||||
0xCCB600,
|
||||
0xCCB640,
|
||||
0xCCB680,
|
||||
0xCCB6BF,
|
||||
0xCCB6FF,
|
||||
0xCCDB00,
|
||||
0xCCDB40,
|
||||
0xCCDB80,
|
||||
0xCCDBBF,
|
||||
0xCCDBFF,
|
||||
0xCCFF00,
|
||||
0xCCFF40,
|
||||
0xCCFF80,
|
||||
0xCCFFBF,
|
||||
0xCCFFFF,
|
||||
0xD2D2D2,
|
||||
0xE1E1E1,
|
||||
0xF0F0F0,
|
||||
0xFF0000,
|
||||
0xFF0040,
|
||||
0xFF0080,
|
||||
0xFF00BF,
|
||||
0xFF00FF,
|
||||
0xFF2400,
|
||||
0xFF2440,
|
||||
0xFF2480,
|
||||
0xFF24BF,
|
||||
0xFF24FF,
|
||||
0xFF4900,
|
||||
0xFF4940,
|
||||
0xFF4980,
|
||||
0xFF49BF,
|
||||
0xFF49FF,
|
||||
0xFF6D00,
|
||||
0xFF6D40,
|
||||
0xFF6D80,
|
||||
0xFF6DBF,
|
||||
0xFF6DFF,
|
||||
0xFF9200,
|
||||
0xFF9240,
|
||||
0xFF9280,
|
||||
0xFF92BF,
|
||||
0xFF92FF,
|
||||
0xFFB600,
|
||||
0xFFB640,
|
||||
0xFFB680,
|
||||
0xFFB6BF,
|
||||
0xFFB6FF,
|
||||
0xFFDB00,
|
||||
0xFFDB40,
|
||||
0xFFDB80,
|
||||
0xFFDBBF,
|
||||
0xFFDBFF,
|
||||
0xFFFF00,
|
||||
0xFFFF40,
|
||||
0xFFFF80,
|
||||
0xFFFFBF,
|
||||
0xFFFFFF,
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
|
||||
|
||||
local colors = { }
|
||||
local color = 0x000000
|
||||
local gray = 0x000000
|
||||
|
||||
local xPos, yPos = 2, 2
|
||||
|
||||
local function printColor(color)
|
||||
gpu.setForeground(color)
|
||||
gpu.set(xPos, yPos, ecs.HEXtoString(color, 6, true))
|
||||
yPos = yPos + 1
|
||||
if yPos > 48 then yPos = 2; xPos = xPos + 10 end
|
||||
end
|
||||
|
||||
local function addColor(value)
|
||||
table.insert(colors, color)
|
||||
printColor(color)
|
||||
color = color + value
|
||||
end
|
||||
|
||||
local function add4()
|
||||
addColor(0x40)
|
||||
addColor(0x40)
|
||||
addColor(0x3F)
|
||||
addColor(0x40)
|
||||
addColor(0x40)
|
||||
color = bit32.band(color, 0xffff00)
|
||||
end
|
||||
|
||||
local function createNext4(value)
|
||||
add4()
|
||||
color = color + value
|
||||
yPos = yPos + 1
|
||||
end
|
||||
|
||||
local function add8()
|
||||
createNext4(0x2300)
|
||||
createNext4(0x2400)
|
||||
createNext4(0x2300)
|
||||
createNext4(0x2400)
|
||||
createNext4(0x2300)
|
||||
createNext4(0x2400)
|
||||
createNext4(0x2300)
|
||||
createNext4(0x2400)
|
||||
end
|
||||
|
||||
local function newGray()
|
||||
gray = gray + 0x0F0F0F
|
||||
printColor(gray)
|
||||
table.insert(colors, gray)
|
||||
end
|
||||
|
||||
local function add8WithGray()
|
||||
add8()
|
||||
for i = 1, 3 do
|
||||
newGray()
|
||||
end
|
||||
color = bit32.band(color, 0xff0000)
|
||||
color = color + 0x320000
|
||||
end
|
||||
|
||||
ecs.prepareToExit()
|
||||
ecs.error("Создаем таблицу")
|
||||
for i = 1, 6 do
|
||||
add8WithGray()
|
||||
end
|
||||
|
||||
for i = 1, 3 do
|
||||
table.remove(colors, #colors)
|
||||
end
|
||||
|
||||
ecs.wait()
|
||||
ecs.prepareToExit()
|
||||
ecs.error("Размер массива = " .. #colors .. ", рисуем таблицу")
|
||||
xPos, yPos = 2, 2
|
||||
local file = io.open("colors.lua", "w")
|
||||
file:write("return {\n")
|
||||
for i = 1, #colors do
|
||||
printColor(colors[i])
|
||||
file:write(" [" .. ecs.HEXtoString(i - 1, 2, true) .. "] = " .. ecs.HEXtoString(colors[i], 6, true) .. ",\n")
|
||||
end
|
||||
file:write("}\n")
|
||||
file:close()
|
||||
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
{
|
||||
0x000000, 0x000040, 0x000080, 0x0000BF, 0x0000FF, 0x002400, 0x002440, 0x002480, 0x0024BF, 0x0024FF, 0x004900, 0x004940, 0x004980, 0x0049BF, 0x0049FF, 0x006D00,
|
||||
0x006D40, 0x006D80, 0x006DBF, 0x006DFF, 0x009200, 0x009240, 0x009280, 0x0092BF, 0x0092FF, 0x00B600, 0x00B640, 0x00B680, 0x00B6BF, 0x00B6FF, 0x00DB00, 0x00DB40,
|
||||
0x00DB80, 0x00DBBF, 0x00DBFF, 0x00FF00, 0x00FF40, 0x00FF80, 0x00FFBF, 0x00FFFF, 0x0F0F0F, 0x1E1E1E, 0x2D2D2D, 0x330000, 0x330040, 0x330080, 0x3300BF, 0x3300FF,
|
||||
0x332400, 0x332440, 0x332480, 0x3324BF, 0x3324FF, 0x334900, 0x334940, 0x334980, 0x3349BF, 0x3349FF, 0x336D00, 0x336D40, 0x336D80, 0x336DBF, 0x336DFF, 0x339200,
|
||||
0x339240, 0x339280, 0x3392BF, 0x3392FF, 0x33B600, 0x33B640, 0x33B680, 0x33B6BF, 0x33B6FF, 0x33DB00, 0x33DB40, 0x33DB80, 0x33DBBF, 0x33DBFF, 0x33FF00, 0x33FF40,
|
||||
0x33FF80, 0x33FFBF, 0x33FFFF, 0x3C3C3C, 0x4B4B4B, 0x5A5A5A, 0x660000, 0x660040, 0x660080, 0x6600BF, 0x6600FF, 0x662400, 0x662440, 0x662480, 0x6624BF, 0x6624FF,
|
||||
0x664900, 0x664940, 0x664980, 0x6649BF, 0x6649FF, 0x666D00, 0x666D40, 0x666D80, 0x666DBF, 0x666DFF, 0x669200, 0x669240, 0x669280, 0x6692BF, 0x6692FF, 0x66B600,
|
||||
0x66B640, 0x66B680, 0x66B6BF, 0x66B6FF, 0x66DB00, 0x66DB40, 0x66DB80, 0x66DBBF, 0x66DBFF, 0x66FF00, 0x66FF40, 0x66FF80, 0x66FFBF, 0x66FFFF, 0x696969, 0x787878,
|
||||
0x878787, 0x969696, 0x990000, 0x990040, 0x990080, 0x9900BF, 0x9900FF, 0x992400, 0x992440, 0x992480, 0x9924BF, 0x9924FF, 0x994900, 0x994940, 0x994980, 0x9949BF,
|
||||
0x9949FF, 0x996D00, 0x996D40, 0x996D80, 0x996DBF, 0x996DFF, 0x999200, 0x999240, 0x999280, 0x9992BF, 0x9992FF, 0x99B600, 0x99B640, 0x99B680, 0x99B6BF, 0x99B6FF,
|
||||
0x99DB00, 0x99DB40, 0x99DB80, 0x99DBBF, 0x99DBFF, 0x99FF00, 0x99FF40, 0x99FF80, 0x99FFBF, 0x99FFFF, 0xA5A5A5, 0xB4B4B4, 0xC3C3C3, 0xCC0000, 0xCC0040, 0xCC0080,
|
||||
0xCC00BF, 0xCC00FF, 0xCC2400, 0xCC2440, 0xCC2480, 0xCC24BF, 0xCC24FF, 0xCC4900, 0xCC4940, 0xCC4980, 0xCC49BF, 0xCC49FF, 0xCC6D00, 0xCC6D40, 0xCC6D80, 0xCC6DBF,
|
||||
0xCC6DFF, 0xCC9200, 0xCC9240, 0xCC9280, 0xCC92BF, 0xCC92FF, 0xCCB600, 0xCCB640, 0xCCB680, 0xCCB6BF, 0xCCB6FF, 0xCCDB00, 0xCCDB40, 0xCCDB80, 0xCCDBBF, 0xCCDBFF,
|
||||
0xCCFF00, 0xCCFF40, 0xCCFF80, 0xCCFFBF, 0xCCFFFF, 0xD2D2D2, 0xE1E1E1, 0xF0F0F0, 0xFF0000, 0xFF0040, 0xFF0080, 0xFF00BF, 0xFF00FF, 0xFF2400, 0xFF2440, 0xFF2480,
|
||||
0xFF24BF, 0xFF24FF, 0xFF4900, 0xFF4940, 0xFF4980, 0xFF49BF, 0xFF49FF, 0xFF6D00, 0xFF6D40, 0xFF6D80, 0xFF6DBF, 0xFF6DFF, 0xFF9200, 0xFF9240, 0xFF9280, 0xFF92BF,
|
||||
0xFF92FF, 0xFFB600, 0xFFB640, 0xFFB680, 0xFFB6BF, 0xFFB6FF, 0xFFDB00, 0xFFDB40, 0xFFDB80, 0xFFDBBF, 0xFFDBFF, 0xFFFF00, 0xFFFF40, 0xFFFF80, 0xFFFFBF, 0xFFFFFF,
|
||||
}
|
||||
@ -1,163 +0,0 @@
|
||||
local ecs = require("ECSAPI")
|
||||
|
||||
local component = require "component"
|
||||
local event = require "event"
|
||||
local ser = require "serialization"
|
||||
local unicode = require "unicode"
|
||||
|
||||
local gpu = component.gpu
|
||||
|
||||
-- КОНСТАНТЫ --
|
||||
local bgColor = 0xffffff
|
||||
local fgColor = 0x000000
|
||||
local questionsFilePath = "schoolQuestions.lua"
|
||||
local screenWidth, screenHeight = gpu.getResolution()
|
||||
|
||||
-- РАЗНОЕ --
|
||||
function swap(array, index1, index2)
|
||||
array[index1], array[index2] = array[index2], array[index1]
|
||||
end
|
||||
|
||||
function shake(array)
|
||||
local counter = #array
|
||||
|
||||
while counter > 1 do
|
||||
local index = math.random(counter)
|
||||
|
||||
swap(array, index, counter)
|
||||
counter = counter - 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Информация о кнопках --
|
||||
local buttons = {}
|
||||
|
||||
local buttonStyle = {
|
||||
standart = {
|
||||
buttonColor = 0xBBBBBB,
|
||||
textColor = 0xffffff,
|
||||
},
|
||||
correct = {
|
||||
buttonColor = 0x008800,
|
||||
textColor = 0xffffff,
|
||||
},
|
||||
incorrect = {
|
||||
buttonColor = 0xFF4444,
|
||||
textColor = 0xffffff,
|
||||
}
|
||||
}
|
||||
|
||||
-- Информация о кол-ве вопросов и текущем вопросе --
|
||||
local database
|
||||
local currentQuestion = 1
|
||||
local currentCategory = "Информатика"
|
||||
local buttonsWidth = 0
|
||||
|
||||
-- Получение массива вопросов из файла --
|
||||
local function readDatabase( filename )
|
||||
local file = assert( io.open(filename, "r"), "File not found!" )
|
||||
database = ser.unserialize( file:read("*a") )
|
||||
file:close()
|
||||
end
|
||||
|
||||
local xOffset, yOffset, spaceBetweenButtons = 4, 1, 2
|
||||
local xPos, yPos
|
||||
|
||||
local function drawMain(x)
|
||||
|
||||
buttons = {}
|
||||
buttonsWidth = 0
|
||||
for i = 1, #database.categories[currentCategory].exercises[currentQuestion].answers do
|
||||
buttonsWidth = buttonsWidth + spaceBetweenButtons + xOffset * 2 + unicode.len(database.categories[currentCategory].exercises[currentQuestion].answers[i])
|
||||
end
|
||||
buttonsWidth = buttonsWidth
|
||||
|
||||
xPos, yPos = math.floor(x + screenWidth / 2 - buttonsWidth / 2 - 1), math.floor(screenHeight / 2) - 3
|
||||
|
||||
ecs.square(1, yPos, screenWidth, 8, 0xFFFFFF)
|
||||
|
||||
ecs.colorText(x + math.floor(screenWidth / 2 - unicode.len(database.categories[currentCategory].exercises[currentQuestion].question) / 2 - 1), yPos, 0x262626, database.categories[currentCategory].exercises[currentQuestion].question)
|
||||
yPos = yPos + 3
|
||||
|
||||
local xButtons = xPos
|
||||
for i = 1, #database.categories[currentCategory].exercises[currentQuestion].answers do
|
||||
local data = { ecs.drawAdaptiveButton(xButtons, yPos, xOffset, yOffset, database.categories[currentCategory].exercises[currentQuestion].answers[i], buttonStyle.standart.buttonColor, buttonStyle.standart.textColor) }
|
||||
data.text = database.categories[currentCategory].exercises[currentQuestion].answers[i]
|
||||
table.insert(buttons, data)
|
||||
xButtons = xButtons + spaceBetweenButtons + xOffset * 2 + unicode.len(database.categories[currentCategory].exercises[currentQuestion].answers[i])
|
||||
end
|
||||
|
||||
yPos = yPos - 3
|
||||
end
|
||||
|
||||
local function startAnimation(speed)
|
||||
for i = screenWidth - screenWidth*0.2, 1, -speed do
|
||||
drawMain(i)
|
||||
os.sleep(0.05)
|
||||
end
|
||||
end
|
||||
|
||||
local function drawProgress()
|
||||
local width = math.floor(screenWidth * 0.65)
|
||||
local xPos = math.floor(screenWidth / 2 - width / 2)
|
||||
local yPos = math.floor(screenHeight / 2 + 5)
|
||||
gpu.setBackground(0xFFFFFF)
|
||||
|
||||
gpu.setForeground(0xCCCCCC)
|
||||
gpu.fill( xPos, yPos, width, 1, '▂' )
|
||||
|
||||
gpu.setForeground(0xBF2008)
|
||||
gpu.fill( xPos, yPos, (width * (currentQuestion - 1)) / #database.categories[currentCategory].exercises, 1, '▂' )
|
||||
end
|
||||
|
||||
local function endAnimation(speed)
|
||||
for i = screenWidth, 1, -5 do
|
||||
gpu.copy(1, yPos, screenWidth, 8, -speed, 0)
|
||||
os.sleep(0.05)
|
||||
end
|
||||
end
|
||||
|
||||
local function test()
|
||||
local animationSpeed = 6
|
||||
ecs.square(1, 1, screenWidth, screenHeight, 0xFFFFFF)
|
||||
|
||||
for i = 1, #database.categories[currentCategory].exercises do
|
||||
currentQuestion = i
|
||||
local correctAnswer = database.categories[currentCategory].exercises[i].correctAnswer
|
||||
|
||||
drawProgress()
|
||||
startAnimation(animationSpeed)
|
||||
|
||||
local doWhile = true
|
||||
while doWhile do
|
||||
if exitWhile then break end
|
||||
local e = {event.pull()}
|
||||
if e[1] == "touch" then
|
||||
for key = 1, #buttons do
|
||||
if ecs.clickedAtArea(e[3], e[4], buttons[key][1], buttons[key][2], buttons[key][3], buttons[key][4]) then
|
||||
if key == correctAnswer then
|
||||
ecs.drawAdaptiveButton(buttons[key][1], buttons[key][2], xOffset, yOffset, buttons[key].text, buttonStyle.correct.buttonColor, buttonStyle.correct.textColor)
|
||||
else
|
||||
ecs.drawAdaptiveButton(buttons[key][1], buttons[key][2], xOffset, yOffset, buttons[key].text, buttonStyle.incorrect.buttonColor, buttonStyle.incorrect.textColor)
|
||||
end
|
||||
doWhile = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
endAnimation(animationSpeed)
|
||||
end
|
||||
|
||||
ecs.square(1, 1, screenWidth, screenHeight, 0xFFFFFF)
|
||||
end
|
||||
|
||||
readDatabase(questionsFilePath)
|
||||
test()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
{
|
||||
categories = {
|
||||
["Математика"] = {
|
||||
|
||||
},
|
||||
["Информатика"] = {
|
||||
exercises = {
|
||||
{
|
||||
question = "Сколько истребителей на хуй?",
|
||||
correctAnswer = 1,
|
||||
answers = {
|
||||
"12",
|
||||
"Низнаю",
|
||||
"Я не учил!",
|
||||
"Можно пересдать?",
|
||||
}
|
||||
},
|
||||
{
|
||||
question = "Любишь сосать хуй?",
|
||||
correctAnswer = 1,
|
||||
answers = {
|
||||
"Да",
|
||||
"Нет",
|
||||
"Пидора ответ",
|
||||
"Чмок",
|
||||
}
|
||||
},
|
||||
{
|
||||
question = "Сколько будет 5 в двоичной системе счисления?",
|
||||
correctAnswer = 3,
|
||||
answers = {
|
||||
"100",
|
||||
"011",
|
||||
"101",
|
||||
"010",
|
||||
}
|
||||
},
|
||||
{
|
||||
question = "Наименьшая структурная единица информации?",
|
||||
correctAnswer = 2,
|
||||
answers = {
|
||||
"Байт",
|
||||
"Бит",
|
||||
"Мегабайт",
|
||||
"Килобайт",
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,262 +0,0 @@
|
||||
local c = require("component")
|
||||
local computer = require("computer")
|
||||
local event = require("event")
|
||||
local ecs = require("ECSAPI")
|
||||
local colors = require("colors")
|
||||
local sides = require("sides")
|
||||
local config = require("config")
|
||||
local fs = require("filesystem")
|
||||
local rs = c.redstone
|
||||
local gpu = c.gpu
|
||||
local modem = c.modem
|
||||
|
||||
modem.open(512)
|
||||
|
||||
---------------------------------------------------------------------
|
||||
|
||||
local pathToWhitelist = "System/Home/whitelist.txt"
|
||||
local pathToDoors = "System/Home/doors.txt"
|
||||
|
||||
local whitelist
|
||||
local doors
|
||||
|
||||
if not fs.exists(pathToWhitelist) then
|
||||
fs.makeDirectory(fs.path(pathToWhitelist))
|
||||
config.write(pathToWhitelist, "Igor_Timofeev", "owner")
|
||||
end
|
||||
|
||||
if not fs.exists(pathToDoors) then
|
||||
config.write(pathToDoors, "3b1ea", colors.lightblue)
|
||||
config.write(pathToDoors, "9d482", colors.yellow)
|
||||
doors = config.readAll(pathToDoors)
|
||||
end
|
||||
|
||||
whitelist = config.readAll(pathToWhitelist)
|
||||
doors = config.readAll(pathToDoors)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
local redstoneSide = sides.bottom
|
||||
|
||||
local xScale, yScale = 40, 20
|
||||
local xSize, ySize = gpu.getResolution()
|
||||
|
||||
local doorTimer = 3
|
||||
|
||||
local buttons = {{false, 0x444444, colors.lightblue}, {false, 0x444444, colors.black}, {false, 0x444444, colors.brown}, {true, ecs.colors.green, colors.pink}, {true, ecs.colors.green, colors.red}, {true, ecs.colors.green, colors.orange}}
|
||||
|
||||
local killWireColor = colors.blue
|
||||
|
||||
---------------------------------------
|
||||
|
||||
local obj = {}
|
||||
local function newObj(class, name, ...)
|
||||
obj[class] = obj[class] or {}
|
||||
obj[class][name] = {...}
|
||||
end
|
||||
|
||||
local function getScreens()
|
||||
local list = c.list()
|
||||
local screens = {}
|
||||
for key, val in pairs(list) do
|
||||
if val == "screen" then
|
||||
screens[key] = {val, c.isPrimary(key)}
|
||||
end
|
||||
end
|
||||
return screens
|
||||
end
|
||||
|
||||
local function clearMonitor(backColor, frontColor, text)
|
||||
gpu.setBackground(backColor)
|
||||
local xSize, ySize = gpu.getResolution()
|
||||
gpu.fill(1, 1, xSize, ySize, " ")
|
||||
gpu.setForeground(frontColor)
|
||||
ecs.centerText("xy", 1, text)
|
||||
end
|
||||
|
||||
local screens = getScreens()
|
||||
local primaryScreen = c.getPrimary("screen").address
|
||||
|
||||
local function bind(address)
|
||||
if address then
|
||||
gpu.bind(address)
|
||||
gpu.setResolution(xScale, yScale)
|
||||
else
|
||||
gpu.bind(primaryScreen)
|
||||
gpu.setResolution(xSize, ySize)
|
||||
end
|
||||
end
|
||||
|
||||
local function checkNick(nick)
|
||||
for key, val in pairs(whitelist) do
|
||||
if key == nick then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--DOORS
|
||||
|
||||
local function door(which, open)
|
||||
|
||||
local color = 0
|
||||
local address
|
||||
for key, val in pairs(doors) do
|
||||
address = c.get(key, "screen")
|
||||
if address == which then
|
||||
color = tonumber(val)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if open then
|
||||
rs.setBundledOutput(redstoneSide, color, 100)
|
||||
else
|
||||
rs.setBundledOutput(redstoneSide, color, 0)
|
||||
end
|
||||
end
|
||||
|
||||
local function openAllDoors(open)
|
||||
local color
|
||||
for key, val in pairs(doors) do
|
||||
color = tonumber(val)
|
||||
if open then
|
||||
rs.setBundledOutput(redstoneSide, color, 100)
|
||||
else
|
||||
rs.setBundledOutput(redstoneSide, color, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function mini()
|
||||
clearMonitor(0xffffff, 0x444444, "Приложите палец для идентификации")
|
||||
end
|
||||
|
||||
local function infa()
|
||||
gpu.setBackground(0xffffff)
|
||||
gpu.setForeground(0x444444)
|
||||
|
||||
local yPos = ySize - 3
|
||||
if c.isAvailable("mfsu") then ecs.centerText("x", yPos, "Заряд МФСУ: "..c.mfsu.getStored()); yPos = yPos + 1 end
|
||||
if c.isAvailable("reactor") then ecs.centerText("x", yPos, "Нагрев реактора: "..math.ceil(c.reactor.getHeat() / c.reactor.getMaxHeat() * 100).."%"); yPos = yPos + 1 end
|
||||
if c.isAvailable("reactor_chamber") then ecs.centerText("x", yPos, "Нагрев реактора: "..math.ceil(c.reactor_chamber.getHeat() / c.reactor_chamber.getMaxHeat() * 100).."%"); yPos = yPos + 1 end
|
||||
end
|
||||
|
||||
local function main()
|
||||
gpu.setBackground(0xffffff)
|
||||
gpu.fill(1, 1, xSize, ySize, " ")
|
||||
|
||||
local yCenter = math.floor(ySize / 2)
|
||||
local yPos = yCenter - 12
|
||||
newObj("buttons", 1, ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Открыть двери", buttons[1][2] or 0x444444, 0xffffff)); yPos = yPos + 4
|
||||
newObj("buttons", 2, ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Фабрика материи", buttons[2][2] or 0x444444, 0xffffff)); yPos = yPos + 4
|
||||
newObj("buttons", 3, ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Управление реактором", buttons[3][2] or 0x444444, 0xffffff)); yPos = yPos + 4
|
||||
newObj("buttons", 4, ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Свет на втором этаже", buttons[4][2] or 0x444444, 0xffffff)); yPos = yPos + 4
|
||||
newObj("buttons", 5, ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Свет на первом этаже", buttons[5][2] or 0x444444, 0xffffff)); yPos = yPos + 4
|
||||
newObj("buttons", 6, ecs.drawAdaptiveButton("auto", yPos, 3, 1, "Свет в шахте", buttons[6][2] or 0x444444, 0xffffff)); yPos = yPos + 4
|
||||
|
||||
infa()
|
||||
end
|
||||
|
||||
local function redstoneRecontrol()
|
||||
for i = 1, #buttons do
|
||||
if buttons[i][1] then
|
||||
rs.setBundledOutput(redstoneSide, buttons[i][3], 100)
|
||||
else
|
||||
rs.setBundledOutput(redstoneSide, buttons[i][3], 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function killThemAll()
|
||||
ecs.square(1, 1, xSize, ySize, 0xff0000)
|
||||
gpu.setForeground(0xffffff)
|
||||
ecs.centerText("xy", 1, "KILL THEM ALL!")
|
||||
rs.setBundledOutput(redstoneSide, killWireColor, 100)
|
||||
os.sleep(2)
|
||||
rs.setBundledOutput(redstoneSide, killWireColor, 0)
|
||||
main("Помещение очищено от всего живого.")
|
||||
end
|
||||
|
||||
local function switchButton(key, buttonColor)
|
||||
if buttons[key][1] then
|
||||
buttons[key][1] = false
|
||||
buttons[key][2] = 0x444444
|
||||
else
|
||||
buttons[key][1] = true
|
||||
buttons[key][2] = buttonColor or ecs.colors.green
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------
|
||||
|
||||
main("Ничего интересного.")
|
||||
|
||||
for key, val in pairs(screens) do
|
||||
if not val[2] then
|
||||
bind(key)
|
||||
mini()
|
||||
bind()
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
local e = {event.pull()}
|
||||
if e[1] == "touch" then
|
||||
|
||||
--ЕСЛИ КЛИКНУТО НА ГЛАВНОМ МОНИКЕ
|
||||
if e[2] == primaryScreen then
|
||||
for key, val in pairs(obj["buttons"]) do
|
||||
if ecs.clickedAtArea(e[3], e[4], obj["buttons"][key][1], obj["buttons"][key][2], obj["buttons"][key][3], obj["buttons"][key][4]) then
|
||||
local color
|
||||
if key == 3 then color = ecs.colors.red end
|
||||
switchButton(key, color)
|
||||
main("Изменен параметр кнопки "..tostring(key).." на "..tostring(buttons[key][1]))
|
||||
if key == 1 then
|
||||
openAllDoors(buttons[key][1])
|
||||
else
|
||||
redstoneRecontrol()
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
--ЕСЛИ КЛИКНУТО НА КАКОМ-ТО ЛЕВОМ МОНИКЕ
|
||||
else
|
||||
bind(e[2])
|
||||
|
||||
if checkNick(e[6]) then
|
||||
clearMonitor(0x44ff44, 0xffffff, "С возвращением, "..e[6].."!")
|
||||
door(e[2], true)
|
||||
os.sleep(doorTimer)
|
||||
door(e[2], false)
|
||||
mini()
|
||||
bind()
|
||||
main(e[6].." вернулся в нашу скромную обитель!")
|
||||
else
|
||||
clearMonitor(0xff0000, 0xffffff, "Недостойным дороги нет.")
|
||||
bind()
|
||||
killThemAll()
|
||||
bind(e[2])
|
||||
os.sleep(doorTimer)
|
||||
mini()
|
||||
bind()
|
||||
main(e[6].." попытался зайти в дом. Убей его. Убей чужака!")
|
||||
end
|
||||
end
|
||||
|
||||
infa()
|
||||
elseif e[1] == "modem_message" then
|
||||
if e[6] == "killThemAll!" then
|
||||
killThemAll()
|
||||
elseif e[6] == "openAllDoors" then
|
||||
switchButton(1)
|
||||
openAllDoors(buttons[1][1])
|
||||
main("Двери открыты!")
|
||||
end
|
||||
elseif e[1] == "key_down" then
|
||||
if e[4] == 28 then
|
||||
killThemAll()
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1 +0,0 @@
|
||||
Демонстрационная программа, генерирующая всем известный "дождь" из символов из не менее известного фильма "Матрица". Идеально вписывается в любой интерьер.
|
||||
@ -1 +0,0 @@
|
||||
Демонстрационная программа, генерирующая всем известный "дождь" из символов из не менее известного фильма "Матрица". Идеально вписывается в любой интерьер.
|
||||
Binary file not shown.
@ -1,60 +0,0 @@
|
||||
|
||||
local event = require("event")
|
||||
local gpu = require("component").gpu
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local backgroundColor = 0x000000
|
||||
local maximumLines = 20
|
||||
local minumLineLength = 5
|
||||
local maximumLineLength = 25
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- local chars = {"%", "?", "@", "#", "$", "!", "0", "/", "№", "&"}
|
||||
local chars = {"ァ", "ア", "ィ", "イ", "ゥ", "ウ", "ェ", "エ", "ォ", "オ", "カ", "ガ", "キ", "ギ", "ク", "グ", "ケ", "ゲ", "コ", "ゴ", "サ", "ザ", "シ", "ジ", "ス", "ズ", "セ", "ゼ", "ソ", "ゾ", "タ", "ダ", "チ", "ヂ", "ッ", "ツ", "ヅ", "テ", "デ", "ト", "ド", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "バ", "パ", "ヒ", "ビ", "ピ", "フ", "ブ", "プ", "ヘ", "ベ", "ペ", "ホ", "ボ", "ポ", "マ", "ミ", "ム", "メ", "モ", "ャ", "ヤ", "ュ", "ユ", "ョ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ヮ", "ワ", "ヰ", "ヱ", "ヲ", "ン", "ヴ", "ヵ", "ヶ", "ヷ", "ヸ", "ヹ", "ヺ", "・", "ー", "ヽ", "ヾ", "ヿ"}
|
||||
local lineColorsForeground = { 0xFFFFFF, 0xBBFFBB, 0x88FF88, 0x33FF33, 0x00FF00, 0x00EE00, 0x00DD00, 0x00CC00, 0x00BB00, 0x00AA00, 0x009900, 0x008800, 0x007700, 0x006600, 0x005500, 0x004400, 0x003300, 0x002200, 0x001100 }
|
||||
local lineColorsBackground = { 0x004400, 0x004400, 0x003300, 0x003300, 0x002200, 0x001100 }
|
||||
local xScreen, yScreen = gpu.getResolution()
|
||||
local lines = {}
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
gpu.setBackground(backgroundColor)
|
||||
gpu.fill(1, 1, xScreen, yScreen, " ")
|
||||
|
||||
while true do
|
||||
while #lines < maximumLines do
|
||||
table.insert(lines, { x = math.random(1, xScreen), y = 1, length = math.random(minumLineLength, maximumLineLength) })
|
||||
end
|
||||
|
||||
gpu.copy(1, 1, xScreen, yScreen, 0, 1)
|
||||
gpu.setBackground(backgroundColor)
|
||||
gpu.fill(1, 1, xScreen, 1, " ")
|
||||
|
||||
local i = 1
|
||||
while i <= #lines do
|
||||
local part = math.ceil(lines[i].y * #lineColorsForeground / lines[i].length)
|
||||
gpu.setBackground(lineColorsBackground[part] or 0x000000)
|
||||
gpu.setForeground(lineColorsForeground[part])
|
||||
gpu.set(lines[i].x, 1, chars[math.random(1, #chars)])
|
||||
|
||||
lines[i].y = lines[i].y + 1
|
||||
if lines[i].y - lines[i].length > 0 then
|
||||
table.remove(lines, i)
|
||||
i = i - 1
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
local e = {event.pull(0.03)}
|
||||
if (e[1] == "key_down" and e[4] == 28) or e[1] == "touch" then
|
||||
gpu.setBackground(backgroundColor)
|
||||
gpu.fill(1, 1, xScreen, yScreen, " ")
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,93 +0,0 @@
|
||||
|
||||
local args = {...}
|
||||
local fs = require("filesystem")
|
||||
local component = require("component")
|
||||
local compressor
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local compressorPath = "/lib/compressor.lua"
|
||||
local MineOSPackagePath = "/MineOS.pkg"
|
||||
|
||||
local compressorURL = "https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/compressor.lua"
|
||||
local MineOSPackageURL = "https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/MineOS/MineOS.pkg"
|
||||
|
||||
local packageFileList = {
|
||||
"/boot/",
|
||||
"/lib/",
|
||||
"/bin/",
|
||||
"/usr/",
|
||||
"/home/",
|
||||
"/etc/",
|
||||
"/MineOS/",
|
||||
"/OS.lua",
|
||||
"/init.lua",
|
||||
"/autorun.lua",
|
||||
}
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function getFile(url, path)
|
||||
local file = io.open(path, "w")
|
||||
|
||||
local pcallSuccess, requestHandle, requestReason = pcall(component.internet.request, url)
|
||||
if pcallSuccess then
|
||||
if requestHandle then
|
||||
while true do
|
||||
local data, reason = requestHandle.read(math.huge)
|
||||
if data then
|
||||
file:write(data)
|
||||
else
|
||||
requestHandle:close()
|
||||
if not reason then
|
||||
file:close()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
file:close()
|
||||
print("Failed")
|
||||
os.exit()
|
||||
end
|
||||
|
||||
local function getCompressor()
|
||||
print("Downloading compressor library...")
|
||||
getFile(compressorURL, compressorPath)
|
||||
compressor = dofile(compressorPath)
|
||||
print("Done.")
|
||||
print(" ")
|
||||
end
|
||||
|
||||
local function getPackage()
|
||||
print("Downloading MineOS package...")
|
||||
getFile(MineOSPackageURL, MineOSPackagePath)
|
||||
print("Done.")
|
||||
print(" ")
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if args[1] == "pack" then
|
||||
getCompressor()
|
||||
packageFileList[#packageFileList + 1] = true
|
||||
compressor.pack(args[2], table.unpack(packageFileList))
|
||||
elseif args[1] == "unpack" and args[2] and fs.exists(args[2]) then
|
||||
getCompressor()
|
||||
compressor.unpack(args[2], "/", true)
|
||||
require("computer").shutdown(true)
|
||||
elseif args[1] == "unpackFromMineOSRepository" then
|
||||
getCompressor()
|
||||
getPackage()
|
||||
compressor.unpack(MineOSPackagePath, "/", true)
|
||||
fs.remove(MineOSPackagePath)
|
||||
require("computer").shutdown(true)
|
||||
else
|
||||
print("Usage:")
|
||||
print(" MineOSPacker pack <path>")
|
||||
print(" MineOSPacker unpack <path>")
|
||||
print(" MineOSPacker unpackFromMineOSRepository")
|
||||
print(" ")
|
||||
end
|
||||
@ -1,28 +0,0 @@
|
||||
Tier 2 and 3 screens can act as touch screens - don't attach a keyboard or sneak-activate them.
|
||||
You can change the text size on screens by changing their resolution - run `resolution 40 16` in the shell.
|
||||
Firing arrows on touch capable screens can trigger touch events.
|
||||
Item colors indicate their tier - white is tier one, yellow is tier two and cyan is tier three.
|
||||
Use an Analyzer to get more information on blocks - for example, to find out why a computer crashed.
|
||||
Keyboards have to be attached to or placed next to a screen to work.
|
||||
You can install OpenOS on a writable medium by running the `install` program.
|
||||
Internet Cards can be used to make HTTP requests and open raw TCP connections.
|
||||
If you crafted something by mistake or don't need it any longer, throw it into a disassembler.
|
||||
Have a look at the code of the built-in programs for examples on how to use the APIs.
|
||||
Most programs can be interrupted by pressing Ctrl+Alt+C.
|
||||
Paste the contents of the clipboard using the middle mouse button or a configurable key (default: insert).
|
||||
Computers will consume less power while idling - i.e. when os.sleep(n > 0.05) is called.
|
||||
Screens will consume more power the more lit characters they display.
|
||||
Most blocks act as 'cables' - use switches and power distributers to create separate networks.
|
||||
Welcome to the dark side - here, have some cookies.
|
||||
Screens can display Unicode - paste the special chars or use unicode.char.
|
||||
Run `help` or `man programname` for ingame help on programs shipped with OpenOS - start with `man man`.
|
||||
For more help, there's a wiki at http://ocdoc.cil.li/ - or find the IRC loot disk and join #oc.
|
||||
Computers have a very basic, built-in speaker - control it using computer.beep().
|
||||
Many component methods have a short documentation - use `=component.componentName.methodName` in the Lua interpreter to see it.
|
||||
You can get a list of all attached components using the `components` program.
|
||||
If you encounter out of memory errors, throw more RAM at your computer.
|
||||
Have you tried turning it off and on again?
|
||||
To disable this greeting, install OpenOS to a writeable medium and delete `/etc/motd`.
|
||||
Did you know OpenComputers has a forum? No? Well, it's at http://oc.cil.li/.
|
||||
Please report bugs on the Github issue tracker, thank you!
|
||||
Beware of cycles when building networks, or you may get duplicate messages!
|
||||
@ -1,11 +0,0 @@
|
||||
Вы можете изменить размер текста на экране, изменяя его разрешение - введите resolution 40 16 в коммандную строку
|
||||
Стрельба стрелами на сенсорный экран активирует ивент touch
|
||||
Вы можете изменить цвет вашего компьютера, монитора или кабеля с помощью обычных красителей
|
||||
Используйте Анализатор, чтобы получить больше информации о блоках - например, чтобы понять, какого хуя компьютер вылетел с ошибкой
|
||||
Чтобы вставить содержимое буфера обмена, нажмите среднюю кнопку мыши или специальную конфигурируемую клавишу, по умолчанию insert
|
||||
Большинство программ можно завершить, нажав Ctrl+Alt+C
|
||||
Экраны могут отображать Юникод - вставляйте нужные символы в код или используйте unicode.char()
|
||||
Официальная вики мода находится по адресу http://ocdoc.cil.li/
|
||||
У компьютеров есть простенький динамик, контролируйте его через computer.beep()
|
||||
Чтобы избавиться от этих подсказок, удалите файл /etc/motd
|
||||
Избегайте циклов, создавая сети, иначе ваши сообщения могут дублироваться!
|
||||
@ -1,55 +0,0 @@
|
||||
#!/bin/lua
|
||||
|
||||
local component = require("component")
|
||||
local computer = require("computer")
|
||||
local text = require("text")
|
||||
local unicode = require("unicode")
|
||||
|
||||
if not component.isAvailable("gpu") then
|
||||
return
|
||||
end
|
||||
|
||||
local gpu = component.gpu
|
||||
local xSize, ySize = gpu.getResolution()
|
||||
local oldBackground = gpu.getBackground()
|
||||
local oldForeground = gpu.getForeground()
|
||||
|
||||
local lines = { "OpenOS (customized by ECS), " .. math.floor(computer.totalMemory() / 1024) .. "KB RAM"}
|
||||
local maxWidth = unicode.len(lines[1])
|
||||
local f = io.open("/usr/misc/greetings/" .. _G.OSSettings.language .. ".txt")
|
||||
if f then
|
||||
local greetings = {}
|
||||
pcall(function()
|
||||
for line in f:lines() do table.insert(greetings, line) end
|
||||
end)
|
||||
f:close()
|
||||
local greeting = greetings[math.random(1, #greetings)]
|
||||
if greeting then
|
||||
local width = math.max(10, component.gpu.getResolution())
|
||||
for line in text.wrappedLines(greeting, width - 4, width - 4) do
|
||||
table.insert(lines, line)
|
||||
maxWidth = math.max(maxWidth, unicode.len(line))
|
||||
end
|
||||
end
|
||||
end
|
||||
local borders = {{unicode.char(0x2552), unicode.char(0x2550), unicode.char(0x2555)},
|
||||
{unicode.char(0x2502), nil, unicode.char(0x2502)},
|
||||
{unicode.char(0x2514), unicode.char(0x2500), unicode.char(0x2518)}}
|
||||
|
||||
|
||||
gpu.setBackground(0xcccccc)
|
||||
gpu.fill(1, 1, xSize, #lines + 2, " ")
|
||||
|
||||
io.write(" \n")
|
||||
io.write("")
|
||||
gpu.setForeground(0x000000)
|
||||
io.write(" " .. text.padRight(lines[1], maxWidth) .. " \n")
|
||||
table.remove(lines, 1)
|
||||
gpu.setForeground(0x555555)
|
||||
for _, line in ipairs(lines) do
|
||||
io.write(" " .. text.padRight(line, maxWidth) .. " \n")
|
||||
end
|
||||
io.write(" \n\n")
|
||||
|
||||
gpu.setBackground(oldBackground)
|
||||
gpu.setForeground(oldForeground)
|
||||
Binary file not shown.
@ -1,620 +0,0 @@
|
||||
require("advancedLua")
|
||||
local component = require("component")
|
||||
local event = require("event")
|
||||
local term = require("term")
|
||||
local unicode = require("unicode")
|
||||
local ecs = require("ECSAPI")
|
||||
local fs = require("filesystem")
|
||||
local shell = require("shell")
|
||||
local internet = require("internet")
|
||||
local context = require("context")
|
||||
local xml = require("xmlParser")
|
||||
local unixtime = require("unixtime")
|
||||
local SHA2 = require("SHA2")
|
||||
-- local computer = require("computer")
|
||||
-- local keyboard = require("keyboard")
|
||||
-- local image = require("image")
|
||||
|
||||
local gpu = component.gpu
|
||||
|
||||
--//replace 1,3,12,11,13,7,16,15,14,582,56,73,166,165,21,167,168,228,229,10,11 0
|
||||
--
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local xSize, ySize = gpu.getResolution()
|
||||
local centerX, centerY = math.floor(xSize / 2), math.floor(ySize / 2)
|
||||
|
||||
local username = nil
|
||||
local password = nil
|
||||
|
||||
local userkey = nil
|
||||
local devKey = "e98db6da803203282d172156bc46137c"
|
||||
local pastebin_url = nil
|
||||
|
||||
local isNotLoggedIn = true
|
||||
|
||||
local pathToConfig = "System/Pastebin/Login.cfg"
|
||||
|
||||
--МАССИВ СО ВСЕМИ ПАСТАМИ С ПАСТЕБИНА
|
||||
local MyMassivWithPastes = {}
|
||||
local drawPastesFrom = 1
|
||||
|
||||
local tabColor1 = 0x103258
|
||||
local tabColor2 = 0x034879
|
||||
local tabTextColor = 0xffffff
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--СОЗДАНИЕ ОБЪЕКТОВ
|
||||
local obj = {}
|
||||
local function newObj(class, name, ...)
|
||||
obj[class] = obj[class] or {}
|
||||
obj[class][name] = {...}
|
||||
end
|
||||
|
||||
--ЗАГРУЗИТЬ ФАЙЛ С ПАСТЕБИНА
|
||||
local function get(pasteId, filename)
|
||||
local f, reason = io.open(filename, "w")
|
||||
if not f then
|
||||
io.stderr:write("Failed opening file for writing: " .. reason)
|
||||
return
|
||||
end
|
||||
|
||||
--io.write("Downloading from pastebin.com... ")
|
||||
local url = "http://pastebin.com/raw.php?i=" .. pasteId
|
||||
local result, response = pcall(internet.request, url)
|
||||
if result then
|
||||
--io.write("success.\n")
|
||||
for chunk in response do
|
||||
--if not options.k then
|
||||
chunk = string.gsub(chunk, "\r\n", "\n")
|
||||
chunk = string.gsub(chunk, " ", " ")
|
||||
--end
|
||||
f:write(chunk)
|
||||
end
|
||||
|
||||
f:close()
|
||||
--io.write("Saved data to " .. filename .. "\n")
|
||||
else
|
||||
--io.write("failed.\n")
|
||||
f:close()
|
||||
fs.remove(filename)
|
||||
io.stderr:write("HTTP request failed: " .. response .. "\n")
|
||||
end
|
||||
end
|
||||
|
||||
-- This makes a string safe for being used in a URL.
|
||||
local function encode(code)
|
||||
if code then
|
||||
code = string.gsub(code, "([^%w ])", function (c)
|
||||
return string.format("%%%02X", string.byte(c))
|
||||
end)
|
||||
code = string.gsub(code, " ", "+")
|
||||
end
|
||||
return code
|
||||
end
|
||||
|
||||
|
||||
|
||||
--Удалить файлецкий
|
||||
local function delete(paste)
|
||||
local result, response = pcall(internet.request,
|
||||
"http://pastebin.com/api/api_post.php",
|
||||
"api_option=delete&"..
|
||||
"api_dev_key="..devKey.."&"..
|
||||
"api_user_key="..userKey.."&"..
|
||||
"api_paste_key="..paste
|
||||
)
|
||||
|
||||
if result then
|
||||
return true
|
||||
else
|
||||
ecs.error("Отсутствует соединение с Pastebin.com")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--ЗАЛОГИНИТЬСЯ В АККАУНТ
|
||||
local function loginToAccount(username, password)
|
||||
|
||||
--print("Логинюсь в пастебине... ")
|
||||
local result, response = pcall(internet.request,
|
||||
"http://pastebin.com/api/api_login.php",
|
||||
"api_dev_key="..devKey..
|
||||
"&api_user_name="..username..
|
||||
"&api_user_password="..password
|
||||
)
|
||||
|
||||
if result then
|
||||
--print("Запрос на пастебин пришел!")
|
||||
local info = ""
|
||||
for chunk in response do
|
||||
info = info .. chunk
|
||||
end
|
||||
if string.match(info, "^Bad API request, ") then
|
||||
--io.write(info)
|
||||
return false, info
|
||||
--ЕСЛИ ВСЕ ЗАЕБОК
|
||||
else
|
||||
--print("Получен юзеркей!")
|
||||
userKey = info
|
||||
--print("Вот так оно выглядит: "..info)
|
||||
return true
|
||||
end
|
||||
else
|
||||
--print("Хуйня произошла. Либо URL неверный, либо пастебин недоступен.\n")
|
||||
--io.stderr:write(response)
|
||||
return false, response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--ЗАГРУЗКА СПИСКА ФАЙЛОВ
|
||||
local function getFileListFromPastebin(countOfFilesToShow)
|
||||
local result, response = pcall(internet.request,
|
||||
"http://pastebin.com/api/api_post.php",
|
||||
"api_dev_key="..devKey..
|
||||
"&api_user_key="..userKey..
|
||||
"&api_results_limit="..countOfFilesToShow..
|
||||
"&api_option=list"
|
||||
)
|
||||
|
||||
--КИНУТЬ ОШИБКУ, ЕСЛИ ЧЕТ НЕ ТАК
|
||||
if not result then io.stderr:write( response ) end
|
||||
|
||||
--ПРОЧИТАТЬ ОТВЕТ С СЕРВЕРА ПАСТЕБИНА
|
||||
local info = ""
|
||||
for chunk in response do
|
||||
info = info .. chunk
|
||||
end
|
||||
|
||||
--РАСПАСИТЬ ХМЛ
|
||||
local x = xml.collect(info)
|
||||
|
||||
--ЗАХУЯРИТЬ МАССИВ С ПАСТАМИ
|
||||
MyMassivWithPastes = {}
|
||||
for pasteID = 1, #x do
|
||||
MyMassivWithPastes[pasteID]={}
|
||||
MyMassivWithPastes[pasteID]["paste_key"] = x[pasteID][1][1]
|
||||
MyMassivWithPastes[pasteID]["paste_date"] = x[pasteID][2][1]
|
||||
MyMassivWithPastes[pasteID]["paste_title"] = x[pasteID][3][1]
|
||||
MyMassivWithPastes[pasteID]["paste_size"] = x[pasteID][4][1]
|
||||
MyMassivWithPastes[pasteID]["paste_expire_date"] = x[pasteID][5][1]
|
||||
MyMassivWithPastes[pasteID]["paste_private"] = x[pasteID][6][1]
|
||||
MyMassivWithPastes[pasteID]["paste_format_long"] = x[pasteID][7][1]
|
||||
MyMassivWithPastes[pasteID]["paste_format_short"] = x[pasteID][8][1]
|
||||
MyMassivWithPastes[pasteID]["paste_url"] = x[pasteID][9][1]
|
||||
MyMassivWithPastes[pasteID]["paste_hits"] = x[pasteID][10][1]
|
||||
end
|
||||
end
|
||||
|
||||
local xPos, yPos
|
||||
local widthTitle
|
||||
local widthOthers
|
||||
local xDate
|
||||
local xDownloads
|
||||
local xSyntax
|
||||
local maxPastesCountToShow = math.floor((ySize - 7) / 2)
|
||||
|
||||
local function displayPaste(i, background, foreground)
|
||||
|
||||
ecs.square(1, yPos, xSize - 2, 1, background)
|
||||
|
||||
--Нарисовать цветной кружочек
|
||||
local color = ecs.colors.green
|
||||
if tonumber(MyMassivWithPastes[i]["paste_private"]) == 1 then
|
||||
color = ecs.colors.red
|
||||
end
|
||||
ecs.colorText(xPos, yPos, color, "●")
|
||||
color = nil
|
||||
|
||||
--Нарисовать имя пасты
|
||||
ecs.colorText(xPos + 2, yPos, foreground, ecs.stringLimit("end", MyMassivWithPastes[i]["paste_title"], widthTitle - 3))
|
||||
|
||||
--Нарисовать дату пасты
|
||||
local date = unixtime.convert(tonumber(MyMassivWithPastes[i]["paste_date"]))
|
||||
gpu.set(xDate, yPos, date)
|
||||
|
||||
--Нарисовать Хитсы
|
||||
gpu.set(xDownloads, yPos, MyMassivWithPastes[i]["paste_hits"])
|
||||
|
||||
--Нарисовать формат
|
||||
gpu.set(xSyntax, yPos, MyMassivWithPastes[i]["paste_format_long"])
|
||||
end
|
||||
|
||||
--Нарисовать пасты
|
||||
local function displayPastes(from)
|
||||
|
||||
obj["Pastes"] = nil
|
||||
|
||||
--Стартовые коорды
|
||||
xPos, yPos = 2, 6
|
||||
|
||||
--Размеры таблицы
|
||||
widthTitle = math.floor((xSize - 2) / 2) + 5
|
||||
widthOthers = math.floor((xSize - 2 - widthTitle) / 3)
|
||||
xDate = xPos + widthTitle
|
||||
xDownloads = xDate + widthOthers
|
||||
xSyntax = xDownloads + widthOthers
|
||||
|
||||
--Цвет фона на нужный сразу
|
||||
gpu.setBackground(0xffffff)
|
||||
|
||||
--Стартовая инфотаблица - ну, имя там, размер, дата и прочее
|
||||
ecs.colorText(xPos, yPos, 0x990000, "Имя")
|
||||
gpu.set(xDate, yPos, "Дата")
|
||||
gpu.set(xDownloads, yPos, "Скачиваний")
|
||||
gpu.set(xSyntax, yPos, "Синтакс")
|
||||
|
||||
ecs.colorText(1, yPos + 1, 0x990000, string.rep("─", xSize - 2))
|
||||
yPos = yPos + 2
|
||||
|
||||
ecs.srollBar(xSize - 1, 6, 2, ySize - 5, #MyMassivWithPastes, from, 0xcccccc, ecs.colors.blue)
|
||||
|
||||
--Все пасты рисуем
|
||||
for i = from, (from + maxPastesCountToShow - 1) do
|
||||
|
||||
if MyMassivWithPastes[i] then
|
||||
displayPaste(i, 0xffffff, 0x000000)
|
||||
|
||||
newObj("Pastes", i, 1, yPos, xSize - 2, yPos)
|
||||
|
||||
--Нарисовать разделитель
|
||||
if i ~= (from + maxPastesCountToShow - 1) then ecs.colorText(1, yPos + 1, 0xcccccc, string.rep("─", xSize - 2)) end
|
||||
else
|
||||
ecs.square(1, yPos, xSize - 2, 2, 0xffffff)
|
||||
end
|
||||
|
||||
yPos = yPos + 2
|
||||
end
|
||||
end
|
||||
|
||||
local function getRandomCifri(length)
|
||||
local cifri = ""
|
||||
for i = 1, length do
|
||||
cifri = cifri .. tostring(math.random(0, 1))
|
||||
end
|
||||
return cifri
|
||||
end
|
||||
|
||||
local function drawTopBar()
|
||||
|
||||
--Полосочки
|
||||
ecs.square(1, 1, xSize, 1, tabColor1)
|
||||
|
||||
gpu.setBackground(tabColor2)
|
||||
gpu.setForeground( tabColor1 )
|
||||
gpu.fill(1, 2, xSize, 3, "░")
|
||||
|
||||
ecs.square(1, 5, xSize, 1, tabColor1)
|
||||
|
||||
--Листочек
|
||||
local sheetWidth = 6
|
||||
gpu.setForeground(0x000000)
|
||||
gpu.setBackground(0xffffff)
|
||||
|
||||
gpu.set(2, 2, getRandomCifri(sheetWidth))
|
||||
gpu.set(3, 3, getRandomCifri(sheetWidth))
|
||||
gpu.set(4, 4, getRandomCifri(sheetWidth))
|
||||
|
||||
--Надписи всякие
|
||||
ecs.colorTextWithBack(2, 1, tabColor2, tabColor1, "#1 paste tool since 2002")
|
||||
ecs.colorTextWithBack(11, 3, tabTextColor, tabColor2, "PASTEBIN")
|
||||
local name = "⛨Загрузить новый файл"; newObj("TopButtons", name, ecs.drawAdaptiveButton(1, 5, 1, 0, name, tabColor1, tabTextColor))
|
||||
|
||||
local xPos = xSize - 23
|
||||
if username then
|
||||
name = "Разлогиниться"; newObj("TopButtons", name, ecs.drawAdaptiveButton(xPos, 5, 1, 0, name, tabColor1, tabTextColor)); xPos = xPos + unicode.len(name) + 3
|
||||
name = "Выход"; newObj("TopButtons", name, ecs.drawAdaptiveButton(xPos, 5, 1, 0, name, tabColor1, tabTextColor)); xPos = xPos + unicode.len(name) + 3
|
||||
|
||||
--Никнейм
|
||||
ecs.colorTextWithBack(xSize - 1 - unicode.len(username), 3, tabTextColor, tabColor2, username)
|
||||
end
|
||||
end
|
||||
|
||||
local function clear()
|
||||
ecs.square(1, 6, xSize, ySize, 0xffffff)
|
||||
end
|
||||
|
||||
local function inputPassword()
|
||||
--local massiv = ecs.input("auto", "auto", 20, "Войти в Pastebin", {"input", "Логин", ""}, {"input", "Пароль", ""})
|
||||
|
||||
local data = ecs.universalWindow("auto", "auto", 24, tabColor1, true, {"EmptyLine"}, {"CenterText", 0xffffff, "Авторизация"}, {"EmptyLine"}, {"Input", 0xffffff, 0xccccff, "Логин"}, {"Input", 0xffffff, 0xccccff, "Пароль", "●"}, {"EmptyLine"}, {"Button", {tabColor2, 0xffffff, "Войти в аккаунт"}, {0x006dbf, 0xffffff, "Отмена"}})
|
||||
|
||||
if data[3] == "Отмена" then return false end
|
||||
|
||||
username = data[1] or ""
|
||||
password = data[2] or ""
|
||||
clear()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function analyseConfig()
|
||||
if fs.exists(pathToConfig) then
|
||||
local massiv = table.fromFile(pathToConfig)
|
||||
username = massiv.username
|
||||
password = massiv.password
|
||||
massiv = nil
|
||||
else
|
||||
fs.makeDirectory(fs.path(pathToConfig))
|
||||
local success = inputPassword()
|
||||
if not success then return false end
|
||||
table.toFile(pathToConfig, {username = username, password = password})
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function waitForSuccessLogin()
|
||||
while true do
|
||||
|
||||
local success = analyseConfig()
|
||||
if not success then return false end
|
||||
ecs.info("auto", "auto", " ", "Захожу в аккаунт...")
|
||||
local success, reason = loginToAccount(username, password)
|
||||
|
||||
if success then
|
||||
break
|
||||
else
|
||||
if string.match(reason, "^Bad API request, ") then
|
||||
reason = string.sub(reason, 18, -1)
|
||||
end
|
||||
|
||||
if reason == "invalid login" then fs.remove(pathToConfig); ecs.error("Неверное сочетание логин/пароль!"); clear() end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function drawAll()
|
||||
ecs.clearScreen(0xffffff)
|
||||
drawTopBar()
|
||||
end
|
||||
|
||||
local function viewPaste(i)
|
||||
local id = MyMassivWithPastes[i]["paste_key"]
|
||||
local tmp = "System/Pastebin/tempfile.lua"
|
||||
ecs.info("auto", "auto", " ", "Загружаю файл...")
|
||||
os.sleep(0.3)
|
||||
get(id, tmp)
|
||||
|
||||
local file = io.open(tmp, "r")
|
||||
local lines = {}
|
||||
for line in file:lines() do
|
||||
table.insert(lines, line)
|
||||
end
|
||||
file:close()
|
||||
|
||||
ecs.clearScreen(0xffffff)
|
||||
|
||||
local from = 1
|
||||
|
||||
local back = 0xbbbbbb
|
||||
|
||||
ecs.square(1, 1, xSize, 1, back)
|
||||
gpu.setForeground(0xffffff)
|
||||
ecs.centerText("x", 1, "Просмотр "..id)
|
||||
ecs.colorTextWithBack(xSize, 1, 0x000000, back, "X")
|
||||
|
||||
--ecs.error("#lines = ".. #lines)
|
||||
|
||||
ecs.textField(1, 2, xSize, ySize - 1, lines, from, 0xffffff, 0x262626, 0xdddddd, ecs.colors.blue)
|
||||
|
||||
fs.remove(tmp)
|
||||
|
||||
while true do
|
||||
local e = {event.pull()}
|
||||
if e[1] == "scroll" then
|
||||
if e[5] == 1 then
|
||||
if from > 1 then from = from - 1; ecs.textField(1, 2, xSize, ySize - 1, lines, from, 0xffffff, 0x262626, 0xdddddd, ecs.colors.blue) end
|
||||
else
|
||||
if from < #lines then from = from + 1; ecs.textField(1, 2, xSize, ySize - 1, lines, from, 0xffffff, 0x262626, 0xdddddd, ecs.colors.blue) end
|
||||
end
|
||||
elseif e[1] == "touch" then
|
||||
if e[3] == (xSize) and e[4] == 1 then
|
||||
ecs.colorTextWithBack(xSize, 1, 0xffffff, back, "X")
|
||||
os.sleep(0.3)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function launch(i)
|
||||
local tmp = "System/Pastebin/tempfile.lua"
|
||||
ecs.info("auto", "auto", " ", "Загружаю файл...")
|
||||
get(MyMassivWithPastes[i]["paste_key"], tmp)
|
||||
|
||||
ecs.prepareToExit()
|
||||
local s, r = shell.execute(tmp)
|
||||
if not s then
|
||||
ecs.displayCompileMessage(1, r, true, false)
|
||||
else
|
||||
ecs.prepareToExit()
|
||||
print("Программа выполнена успешно. Нажмите любую клавишу, чтобы продолжить.")
|
||||
ecs.waitForTouchOrClick()
|
||||
end
|
||||
|
||||
|
||||
|
||||
fs.remove(tmp)
|
||||
end
|
||||
|
||||
--ЗАГРУЗИТЬ ФАЙЛ НА ПАСТЕБИН
|
||||
local function upload(path, title)
|
||||
ecs.info("auto", "auto", " ", "Загружаю \""..fs.name(path).."\"...")
|
||||
local file = io.open(path, "r")
|
||||
local sText = file:read("*a")
|
||||
file:close()
|
||||
|
||||
local result, response = pcall(internet.request,
|
||||
"http://pastebin.com/api/api_post.php",
|
||||
"api_option=paste&"..
|
||||
"api_dev_key="..devKey.."&"..
|
||||
"api_user_key="..userKey.."&"..
|
||||
"api_paste_private=0&"..
|
||||
"api_paste_format=lua&"..
|
||||
"api_paste_name="..encode(title).."&"..
|
||||
"api_paste_code="..encode(sText)
|
||||
)
|
||||
|
||||
if result then
|
||||
--ecs.error(response)
|
||||
else
|
||||
ecs.error("Отсутствует соединение с Pastebin.com")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local pasteLoadLimit = 50
|
||||
local args = {...}
|
||||
|
||||
drawAll()
|
||||
if not waitForSuccessLogin() then ecs.prepareToExit(); return true end
|
||||
drawTopBar()
|
||||
|
||||
if #args > 1 then
|
||||
if args[1] == "upload" or args[1] == "load" then
|
||||
if fs.exists(args[2]) and not fs.isDirectory(args[2]) then
|
||||
upload(args[2], fs.name(args[2]))
|
||||
os.sleep(5) -- Ждем, пока 100% прогрузится апи пастебина
|
||||
else
|
||||
ecs.error("Файл не существует или является директорией.")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ecs.info("auto", "auto", " ", "Получаю список файлов...")
|
||||
getFileListFromPastebin(pasteLoadLimit)
|
||||
|
||||
displayPastes(drawPastesFrom)
|
||||
|
||||
while true do
|
||||
local e = {event.pull()}
|
||||
if e[1] == "scroll" then
|
||||
if e[5] == 1 then
|
||||
if drawPastesFrom > 1 then drawPastesFrom = drawPastesFrom - 1; displayPastes(drawPastesFrom) end
|
||||
else
|
||||
if drawPastesFrom < pasteLoadLimit then drawPastesFrom = drawPastesFrom + 1; displayPastes(drawPastesFrom) end
|
||||
end
|
||||
elseif e[1] == "touch" then
|
||||
for key, val in pairs(obj["Pastes"]) do
|
||||
if ecs.clickedAtArea(e[3], e[4], obj["Pastes"][key][1], obj["Pastes"][key][2], obj["Pastes"][key][3], obj["Pastes"][key][4] ) then
|
||||
--ecs.error("key = "..key)
|
||||
yPos = obj["Pastes"][key][2]
|
||||
displayPaste(key, ecs.colors.blue, 0xffffff)
|
||||
|
||||
if e[5] == 1 then
|
||||
local action = context.menu(e[3], e[4], {"Просмотр"}, "-", {"Запустить"}, {"Сохранить как"}, "-",{"Удалить"})
|
||||
|
||||
if action == "Сохранить как" then
|
||||
local data = ecs.universalWindow("auto", "auto", 36, tabColor1, true, {"EmptyLine"}, {"CenterText", 0xffffff, "Сохранить как"}, {"EmptyLine"}, {"Input", 0xffffff, 0xccccff, "Имя"}, {"EmptyLine"}, {"Button", {0xffffff, 0xccccff, "OK"}} )
|
||||
local path = data[1]
|
||||
if path ~= nil or path ~= "" or path ~= " " then
|
||||
fs.makeDirectory(fs.path(path))
|
||||
local action2 = ecs.askForReplaceFile(path)
|
||||
ecs.info("auto", "auto", " ", "Загружаю файл...")
|
||||
if action2 == nil or action2 == "replace" then
|
||||
fs.remove(path)
|
||||
get(MyMassivWithPastes[key]["paste_key"], path)
|
||||
ecs.select("auto", "auto", " ", {{"Загрузка завершена."}}, {{"Заебись!"}})
|
||||
elseif action2 == "keepBoth" then
|
||||
get(MyMassivWithPastes[key]["paste_key"], fs.path(path).."(copy)"..fs.name(path))
|
||||
end
|
||||
drawAll()
|
||||
displayPastes(drawPastesFrom)
|
||||
else
|
||||
ecs.error("Сохранение не удалось: не указан путь.")
|
||||
end
|
||||
elseif action == "Удалить" then
|
||||
ecs.info("auto", "auto", " ", "Удаляю файл...")
|
||||
delete(MyMassivWithPastes[key]["paste_key"])
|
||||
os.sleep(5)
|
||||
ecs.info("auto", "auto", " ", "Перезагружаю список файлов...")
|
||||
getFileListFromPastebin(pasteLoadLimit)
|
||||
drawAll()
|
||||
displayPastes(drawPastesFrom)
|
||||
elseif action == "Просмотр" then
|
||||
viewPaste(key)
|
||||
drawAll()
|
||||
displayPastes(drawPastesFrom)
|
||||
elseif action == "Запустить" then
|
||||
launch(key)
|
||||
drawAll()
|
||||
displayPastes(drawPastesFrom)
|
||||
end
|
||||
|
||||
displayPaste(key, 0xffffff, 0x000000)
|
||||
else
|
||||
--os.sleep(0.3)
|
||||
viewPaste(key)
|
||||
drawAll()
|
||||
displayPastes(drawPastesFrom)
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
for key, val in pairs(obj["TopButtons"]) do
|
||||
if ecs.clickedAtArea(e[3], e[4], obj["TopButtons"][key][1], obj["TopButtons"][key][2], obj["TopButtons"][key][3], obj["TopButtons"][key][4] ) then
|
||||
ecs.drawAdaptiveButton(obj["TopButtons"][key][1], obj["TopButtons"][key][2], 1, 0, key, tabColor2, tabTextColor)
|
||||
|
||||
os.sleep(0.3)
|
||||
|
||||
if key == "Разлогиниться" then
|
||||
fs.remove("System/Pastebin/Login.cfg")
|
||||
drawAll()
|
||||
if not waitForSuccessLogin() then
|
||||
ecs.prepareToExit()
|
||||
return true
|
||||
end
|
||||
drawTopBar()
|
||||
ecs.info("auto", "auto", " ", "Получаю список файлов...")
|
||||
getFileListFromPastebin(pasteLoadLimit)
|
||||
drawAll()
|
||||
displayPastes(drawPastesFrom)
|
||||
elseif key == "⛨Загрузить новый файл" then
|
||||
local data = ecs.universalWindow("auto", "auto", 36, tabColor1, true, {"EmptyLine"}, {"CenterText", 0xffffff, "Загрузить на Pastebin"}, {"EmptyLine"}, {"Input", 0xffffff, 0xccccff, "Путь к файлу"}, {"Input", 0xffffff, 0xccccff, "Имя на Pastebin"}, {"EmptyLine"}, {"Button", {tabColor2, 0xffffff, "OK"}})
|
||||
if fs.exists(data[1]) then
|
||||
if not fs.isDirectory(data[1]) then
|
||||
upload(data[1], data[2] or "Untitled")
|
||||
os.sleep(5)
|
||||
ecs.info("auto", "auto", " ", "Перезагружаю список файлов...")
|
||||
|
||||
getFileListFromPastebin(pasteLoadLimit)
|
||||
drawAll()
|
||||
drawPastesFrom = 1
|
||||
displayPastes(drawPastesFrom)
|
||||
else
|
||||
ecs.error("Нельзя загружать папки.")
|
||||
end
|
||||
else
|
||||
ecs.error("Файл \""..fs.name(data[1]).."\" не существует.")
|
||||
end
|
||||
elseif key == "Выход" then
|
||||
ecs.prepareToExit()
|
||||
return true
|
||||
end
|
||||
|
||||
drawTopBar()
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
Binary file not shown.
@ -1,4 +0,0 @@
|
||||
2d2d2d ffffff ┌ 2d2d2d ffffff ─ 2d2d2d ffffff ─ 2d2d2d ffffff ─ 2d2d2d ffffff ─ 2d2d2d ffffff ─ 2d2d2d ffffff ─ 2d2d2d ffffff ┐
|
||||
2d2d2d ffffff │ 2d2d2d ffffff 2d2d2d ffffff 2d2d2d ffffff 2d2d2d ffffff 2d2d2d ffffff 2d2d2d 33ff80 ⇄ 2d2d2d ffffff │
|
||||
2d2d2d ffffff └ 2d2d2d ffffff ─ 2d2d2d ffffff ─ 2d2d2d ffffff ┬ 2d2d2d ffffff ┬ 2d2d2d ffffff ─ 2d2d2d ffffff ─ 2d2d2d ffffff ┘
|
||||
2d2d2d ffffff 2d2d2d ffffff 2d2d2d ffffff ─ 2d2d2d ffffff ┴ 2d2d2d ffffff ┴ 2d2d2d ffffff ─ 2d2d2d ffffff 2d2d2d ffffff
|
||||
@ -1,135 +0,0 @@
|
||||
local c = require("component")
|
||||
local event = require("event")
|
||||
local unicode = require("unicode")
|
||||
local modem = c.modem
|
||||
local gpu = c.gpu
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--Открываем порт
|
||||
local port = 512
|
||||
modem.open(port)
|
||||
|
||||
--Запрашиваем адрес клиента
|
||||
local clientAddress = "3659a020-b21d-4993-aa79-1d8acd5110f3"
|
||||
local data = ecs.universalWindow("auto", "auto", 40, ecs.windowColors.background, true, {"EmptyLine"}, {"CenterText", 0x880000, "RCON"}, {"EmptyLine"}, {"CenterText", 0x262626, "Введите адрес удаленного компьютера:"}, {"EmptyLine"}, {"Input", 0x262626, 0x880000, clientAddress}, {"EmptyLine"}, {"Button", {0xbbbbbb, 0xffffff, "Далее"}})
|
||||
clientAddress = data[1]
|
||||
|
||||
local oldPixels = ecs.info("auto", "auto", " ", "Connecting to client...")
|
||||
--Отправляем сообщение
|
||||
modem.send(clientAddress, port, "RCON", "iWantToControl")
|
||||
--Ждем результата
|
||||
local controlAccepted
|
||||
local e = {event.pull(5, "modem_message")}
|
||||
local protocol, messsage = e[6], e[7]
|
||||
if protocol == "RCON" then
|
||||
if messsage == "acceptControl" then
|
||||
controlAccepted = 1
|
||||
elseif messsage == "denyControl" then
|
||||
controlAccepted = 2
|
||||
end
|
||||
end
|
||||
|
||||
--Удаляем окошко коннекта
|
||||
ecs.drawOldPixels(oldPixels)
|
||||
|
||||
--Проверяем, че там и как
|
||||
if controlAccepted == 2 then
|
||||
ecs.error("Клиент отклонил управление!")
|
||||
return
|
||||
elseif controlAccepted == nil then
|
||||
ecs.error("Клиент не принял запрос, отключаюсь.")
|
||||
return
|
||||
end
|
||||
|
||||
local function RCONExecute(...)
|
||||
modem.send(clientAddress, port, "RCON", ...)
|
||||
end
|
||||
|
||||
|
||||
--Для окошечка все
|
||||
local commandsHistory = {
|
||||
"Добро пожаловать в RCON-клиент для OpenComputers!",
|
||||
" ",
|
||||
"Нажмите любую клавишу - и эта же клавиша нажмется на",
|
||||
"удаленном компьютере.",
|
||||
" ",
|
||||
"Кликните на экран - и удаленный компьютер также кликнет",
|
||||
"в эту же точку.",
|
||||
" ",
|
||||
"Введите команду в командную строку ниже - и эта команда",
|
||||
"выполнится на удаленном ПК через shell.execute()",
|
||||
" ",
|
||||
"----------------------------------------------------------------",
|
||||
" ",
|
||||
}
|
||||
|
||||
local width, height = 80, 25
|
||||
local x, y = ecs.correctStartCoords("auto", "auto", width, height)
|
||||
local xEnd, yEnd = x + width - 1, y + height - 1
|
||||
|
||||
local function drawWindow()
|
||||
ecs.square(x, y, width, height, 0xeeeeee)
|
||||
ecs.colorText(x + 1, y, ecs.colors.red, "⮾")
|
||||
ecs.colorText(x + 3, y, ecs.colors.orange, "⮾")
|
||||
ecs.colorText(x + 5, y, ecs.colors.green, "⮾")
|
||||
local text = "RCON"; ecs.colorText(x + math.floor(width / 2 - #text / 2) - 1, y, 0x262626, text)
|
||||
ecs.border(x + 1, yEnd - 2, width - 2, 3, 0xeeeeee, 0x262626)
|
||||
|
||||
--Подпарсиваем историю
|
||||
local xPos, yPos = x + 2, y + 2
|
||||
local limit = height - 6
|
||||
if #commandsHistory > limit then
|
||||
for i = 1, (#commandsHistory - limit) do
|
||||
table.remove(commandsHistory, 1)
|
||||
end
|
||||
end
|
||||
|
||||
--Рисуем историю
|
||||
gpu.setBackground(0xeeeeee)
|
||||
gpu.setForeground(0x555555)
|
||||
for i = 1, limit do
|
||||
local stro4ka = commandsHistory[i]
|
||||
if stro4ka then
|
||||
gpu.set(xPos, yPos, ecs.stringLimit("end", stro4ka, width - 4))
|
||||
yPos = yPos + 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function insertToHistory(che)
|
||||
table.insert(commandsHistory, che)
|
||||
drawWindow()
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
oldPixels = ecs.rememberOldPixels(x, y, x + width - 1, y + height - 1)
|
||||
drawWindow()
|
||||
|
||||
while true do
|
||||
local e = {event.pull()}
|
||||
if e[1] == "key_down" then
|
||||
RCONExecute("key_down", e[3], e[4], e[5])
|
||||
insertToHistory("Нажать клавишу \""..unicode.char(e[3]).."\" от имени "..e[5])
|
||||
elseif e[1] == "touch" then
|
||||
--Если в комманд зону
|
||||
if ecs.clickedAtArea(e[3], e[4], x + 2, yEnd - 1, xEnd - 2, yEnd - 1) then
|
||||
local cmd = ecs.inputText(x + 3, yEnd - 1, width - 6, "", 0xeeeeee, 0x262626)
|
||||
RCONExecute("execute", cmd)
|
||||
insertToHistory("Выполнить \""..cmd.."\"")
|
||||
elseif ecs.clickedAtArea(e[3], e[4], x + 1, y, x + 2, y) then
|
||||
ecs.colorTextWithBack(x + 1, y, ecs.colors.blue, 0xeeeeee, "⮾")
|
||||
os.sleep(0.2)
|
||||
RCONExecute("closeConnection")
|
||||
ecs.drawOldPixels(oldPixels)
|
||||
return
|
||||
else
|
||||
RCONExecute("touch", e[3], e[4], e[5], e[6])
|
||||
insertToHistory("Кликнуть на экран на позиции "..tostring(e[3]).."x"..tostring(e[4]).." клавишей мыши "..tostring(e[5]).." от имени "..tostring(e[6]))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,87 +0,0 @@
|
||||
|
||||
|
||||
local unicode = require("unicode")
|
||||
local component = require("component")
|
||||
local modem = component.modem
|
||||
local gpu = component.gpu
|
||||
local event = require("event")
|
||||
|
||||
local port = 512
|
||||
modem.open(port)
|
||||
|
||||
local function sendString(data)
|
||||
local stringSize = string.len(data)
|
||||
local maxPacketSize = modem.maxPacketSize()
|
||||
local myPacketSize = maxPacketSize - 32
|
||||
|
||||
modem.broadcast(port, "TVS")
|
||||
local i = 1
|
||||
while i <= stringSize do
|
||||
local str = data:sub(i, i + myPacketSize - 1)
|
||||
modem.broadcast(port, "TVC", str)
|
||||
i = i + myPacketSize
|
||||
end
|
||||
modem.broadcast(port, "TVE")
|
||||
end
|
||||
|
||||
local function getScreenString()
|
||||
local resolutionX, resolutionY = gpu.getResolution()
|
||||
local str = string.format("%02X", resolutionX) .. string.format("%02X", resolutionY)
|
||||
for y = 1, resolutionY do
|
||||
for x = 1, resolutionX do
|
||||
local symbol, foreground, background = gpu.get(x, y)
|
||||
str = str .. string.format("%06X", background) .. string.format("%06X", foreground) .. symbol
|
||||
end
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
local function decodeScreenString(str)
|
||||
local resolutionX, resolutionY = tonumber("0x" .. unicode.sub(str, 1, 2)), tonumber("0x" .. unicode.sub(str, 3, 4))
|
||||
-- print("RES: ", resolutionX, resolutionY)
|
||||
local x, y, i = 1, 1, 5
|
||||
while i <= unicode.len(str) do
|
||||
local background, foreground, symbol = unicode.sub(str, i, i + 5), unicode.sub(str, i + 6, i + 11), unicode.sub(str, i + 12, i + 12)
|
||||
-- print(x, y, background, foreground, symbol)
|
||||
gpu.setBackground(tonumber("0x" .. background))
|
||||
gpu.setForeground(tonumber("0x" .. foreground))
|
||||
gpu.set(x, y, symbol)
|
||||
-- event.pull("touch")
|
||||
x = x + 1
|
||||
if x > resolutionX then
|
||||
os.sleep(0)
|
||||
x, y = 1, y + 1
|
||||
end
|
||||
i = i + 13
|
||||
end
|
||||
end
|
||||
|
||||
local function receive()
|
||||
local str
|
||||
while true do
|
||||
local e = {event.pull()}
|
||||
if e[1] == "modem_message" then
|
||||
if e[6] == "TVS" then
|
||||
str = ""
|
||||
elseif e[6] == "TVC" then
|
||||
str = str .. e[7]
|
||||
elseif e[6] == "TVE" then
|
||||
return str
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- sendString(getScreenString())
|
||||
decodeScreenString(receive())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,132 +0,0 @@
|
||||
|
||||
|
||||
local event = require("event")
|
||||
local tetris = require("tetris")
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local width = 10
|
||||
local height = 20
|
||||
|
||||
local snake = {
|
||||
{2, 3},
|
||||
{3, 3},
|
||||
{4, 3},
|
||||
}
|
||||
|
||||
local direction = 3
|
||||
|
||||
local speed = 0.2
|
||||
|
||||
local xFood, yFood
|
||||
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local function checkCoords(x, y)
|
||||
if x < 1 then x = width elseif x > width then x = 1 end
|
||||
if y < 1 then y = height elseif y > height then y = 1 end
|
||||
return x, y
|
||||
end
|
||||
|
||||
local function displaySnake()
|
||||
tetris.generateScreenArray(width, height)
|
||||
tetris.screen.main[snake[1][2]][snake[1][1]][1] = true
|
||||
tetris.screen.main[snake[1][2]][snake[1][1]][2] = 0x7
|
||||
for i = 2, #snake do
|
||||
tetris.screen.main[snake[i][2]][snake[i][1]][1] = true
|
||||
end
|
||||
tetris.screen.main[yFood][xFood][1] = true
|
||||
tetris.screen.main[yFood][xFood][2] = 0xB
|
||||
tetris.drawPixels(tetris.xScreen, tetris.yScreen, "main")
|
||||
end
|
||||
|
||||
local function createFood()
|
||||
while true do
|
||||
local x, y = math.random(1, width), math.random(1, height)
|
||||
local success = true
|
||||
|
||||
for i = 1, #snake do
|
||||
if snake[i][1] == x and snake[i][2] == y then
|
||||
success = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if success then
|
||||
xFood, yFood = x, y
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function checkFood()
|
||||
if snake[1][1] == xFood and snake[1][2] == yFood then return true else return false end
|
||||
end
|
||||
|
||||
local function checkSnakeHitForItself()
|
||||
for i = 2, #snake do
|
||||
if snake[1][1] == snake[i][1] and snake[1][2] == snake[i][2] then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function moveSnake()
|
||||
if direction == 1 then
|
||||
table.insert(snake, 1, { checkCoords(snake[1][1], snake[1][2] - 1) })
|
||||
elseif direction == 2 then
|
||||
table.insert(snake, 1, { checkCoords(snake[1][1] + 1, snake[1][2]) })
|
||||
elseif direction == 3 then
|
||||
table.insert(snake, 1, { checkCoords(snake[1][1], snake[1][2] + 1) })
|
||||
else
|
||||
table.insert(snake, 1, { checkCoords(snake[1][1] - 1, snake[1][2]) })
|
||||
end
|
||||
|
||||
if checkFood() then tetris.screen.score = tetris.screen.score + 300; createFood() else table.remove(snake, #snake) end
|
||||
|
||||
tetris.screen.score = math.max(0, tetris.screen.score - 5)
|
||||
|
||||
tetris.drawInfoPanel()
|
||||
|
||||
displaySnake()
|
||||
|
||||
return checkSnakeHitForItself()
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--ecs.prepareToExit()
|
||||
tetris.screen.score = 0
|
||||
tetris.draw(32, 3, width, height, true)
|
||||
createFood()
|
||||
gpu.setBackground(tetris.colors.screen)
|
||||
displaySnake()
|
||||
|
||||
while true do
|
||||
local eventData = { event.pull(speed) }
|
||||
if #eventData > 0 then
|
||||
if eventData[1] == "key_down" then
|
||||
if eventData[4] == 200 and (direction ~= 1 and direction ~= 3) then
|
||||
direction = 1
|
||||
if not moveSnake() then ecs.error("Игра закончена со счетом "..tetris.screen.score.."!"); break end
|
||||
elseif eventData[4] == 208 and (direction ~= 1 and direction ~= 3) then
|
||||
direction = 3
|
||||
if not moveSnake() then ecs.error("Игра закончена со счетом "..tetris.screen.score.."!"); break end
|
||||
elseif eventData[4] == 203 and (direction ~= 2 and direction ~= 4) then
|
||||
direction = 4
|
||||
if not moveSnake() then ecs.error("Игра закончена со счетом "..tetris.screen.score.."!"); break end
|
||||
elseif eventData[4] == 205 and (direction ~= 2 and direction ~= 4) then
|
||||
direction = 2
|
||||
if not moveSnake() then ecs.error("Игра закончена со счетом "..tetris.screen.score.."!"); break end
|
||||
end
|
||||
end
|
||||
else
|
||||
if not moveSnake() then ecs.error("Игра закончена со счетом "..tetris.screen.score.."!"); break end
|
||||
end
|
||||
end
|
||||
|
||||
--ecs.prepareToExit()
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,249 +0,0 @@
|
||||
|
||||
---------------------------------------------------- Библиотеки ----------------------------------------------------------------
|
||||
|
||||
local serialization = require("serialization")
|
||||
local event = require("event")
|
||||
local ecs = require("ECSAPI")
|
||||
local fs = require("filesystem")
|
||||
local buffer = require("doubleBuffering")
|
||||
local unicode = require("unicode")
|
||||
local component = require("component")
|
||||
|
||||
---------------------------------------------------- Константы ----------------------------------------------------------------
|
||||
|
||||
buffer.start()
|
||||
|
||||
local tablica = {}
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local function drawGrid(x, y)
|
||||
local gridWidth = 74
|
||||
local gridHeight = 39
|
||||
|
||||
buffer.clear(0xFFFFFF)
|
||||
|
||||
local lines = {
|
||||
" ┃ ┃ ",
|
||||
" ┃ ┃ ",
|
||||
" ┃ ┃ ",
|
||||
"━━━━━━━╋━━━━━━━╋━━━━━━━",
|
||||
" ┃ ┃ ",
|
||||
" ┃ ┃ ",
|
||||
" ┃ ┃ ",
|
||||
"━━━━━━━╋━━━━━━━╋━━━━━━━",
|
||||
" ┃ ┃ ",
|
||||
" ┃ ┃ ",
|
||||
" ┃ ┃ ",
|
||||
}
|
||||
|
||||
--Тонкие
|
||||
local xPos, yPos = x, y
|
||||
for a = 1, 3 do
|
||||
for j = 1, 3 do
|
||||
for i = 1, #lines do
|
||||
buffer.text(xPos, yPos, 0x000000, lines[i])
|
||||
yPos = yPos + 1
|
||||
end
|
||||
yPos = yPos + 1
|
||||
end
|
||||
yPos = y
|
||||
xPos = xPos + unicode.len(lines[1]) + 2
|
||||
end
|
||||
|
||||
--Толстые
|
||||
--Горизонтальные
|
||||
buffer.square(x, y + (#lines + 1) - 1, (unicode.len(lines[1]) + 2) * 3, 1, 0x000000)
|
||||
buffer.square(x, y + (#lines + 1) * 2 - 1, (unicode.len(lines[1]) + 2) * 3, 1, 0x000000)
|
||||
--Вертикальные
|
||||
buffer.square(x + (unicode.len(lines[1]) + 1) - 1, y, 2, (#lines + 1) * 3, 0x000000)
|
||||
buffer.square(x + (unicode.len(lines[1]) * 2 + 3 ) - 1, y, 2, (#lines + 1) * 3, 0x000000)
|
||||
|
||||
--Значения
|
||||
yPos = y
|
||||
for j = 1, #tablica do
|
||||
xPos = x + 1
|
||||
|
||||
for i = 1, #tablica[j] do
|
||||
if i == 4 or i == 7 then xPos = xPos + 1 end
|
||||
|
||||
if tablica[j][i].value then
|
||||
buffer.set(xPos + 2, yPos + 1, 0xFFFFFF, 0x000000, tostring(tablica[j][i].value))
|
||||
elseif tablica[j][i].possibleValues and #tablica[j][i].possibleValues > 0 then
|
||||
local xPossible, yPossible = xPos, yPos
|
||||
for a = 1, #tablica[j][i].possibleValues do
|
||||
local background, foreground = 0xFFFFFF, 0xAAAAAA
|
||||
if #tablica[j][i].possibleValues == 1 then background = 0x88FF88; foreground = 0x000000 end
|
||||
buffer.set(xPossible, yPossible, background, foreground, tablica[j][i].possibleValues[a])
|
||||
xPossible = xPossible + 2
|
||||
if a % 3 == 0 then xPossible = xPos; yPossible = yPossible + 1 end
|
||||
end
|
||||
end
|
||||
|
||||
xPos = xPos + 8
|
||||
end
|
||||
|
||||
yPos = yPos + 4
|
||||
end
|
||||
|
||||
buffer.draw()
|
||||
end
|
||||
|
||||
local function checkCellValue(xCell, yCell, requestedValue)
|
||||
if tablica[yCell][xCell].value and tablica[yCell][xCell].value == requestedValue then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function checkCellForRules(xCell, yCell, requestedValue)
|
||||
--Чекаем горизонтально, включая эту же ячейку
|
||||
for i = (xCell + 1), 9 do if not checkCellValue(i, yCell, requestedValue) then return false end end
|
||||
for i = 1, (xCell - 1) do if not checkCellValue(i, yCell, requestedValue) then return false end end
|
||||
|
||||
--Вертикально
|
||||
for i = (yCell + 1), 9 do if not checkCellValue(xCell, i, requestedValue) then return false end end
|
||||
for i = 1, (yCell - 1) do if not checkCellValue(xCell, i, requestedValue) then return false end end
|
||||
|
||||
--И вокруг
|
||||
local xFrom, yFrom = 1, 1
|
||||
if xCell >= 4 and xCell <= 6 then xFrom = 4 elseif xCell >= 7 and xCell <= 9 then xFrom = 7 end
|
||||
if yCell >= 4 and yCell <= 6 then yFrom = 4 elseif yCell >= 7 and yCell <= 9 then yFrom = 7 end
|
||||
for j = yFrom, (yFrom + 2) do
|
||||
for i = xFrom, (xFrom + 2) do
|
||||
if not checkCellValue(i, j, requestedValue) then return false end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function clearTablica()
|
||||
tablica = {}
|
||||
for i = 1, 9 do table.insert(tablica, { {},{},{}, {},{},{}, {},{},{} }) end
|
||||
end
|
||||
|
||||
local function generateSudoku(startCountOfNumbers)
|
||||
clearTablica()
|
||||
|
||||
for i = 1, startCountOfNumbers do
|
||||
while true do
|
||||
local randomNumber = math.random(1, 9)
|
||||
local randomX = math.random(1, 9)
|
||||
local randomY = math.random(1, 9)
|
||||
|
||||
if not tablica[randomY][randomX].value and checkCellForRules(randomX, randomY, randomNumber) then
|
||||
tablica[randomY][randomX].value = randomNumber
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function getpossibleValuesForCell(xCell, yCell)
|
||||
--Получаем невозможные числа
|
||||
local impossibleValues = {}
|
||||
--Горизонтально
|
||||
for i = 1, (xCell - 1) do if tablica[yCell][i].value then impossibleValues[tablica[yCell][i].value] = true end end
|
||||
for i = (xCell + 1), 9 do if tablica[yCell][i].value then impossibleValues[tablica[yCell][i].value] = true end end
|
||||
--Вертикально
|
||||
for i = 1, (yCell - 1) do if tablica[i][xCell].value then impossibleValues[tablica[i][xCell].value] = true end end
|
||||
for i = (yCell + 1), 9 do if tablica[i][xCell].value then impossibleValues[tablica[i][xCell].value] = true end end
|
||||
--Квадратно
|
||||
local xFrom, yFrom = 1, 1
|
||||
if xCell >= 4 and xCell <= 6 then xFrom = 4 elseif xCell >= 7 and xCell <= 9 then xFrom = 7 end
|
||||
if yCell >= 4 and yCell <= 6 then yFrom = 4 elseif yCell >= 7 and yCell <= 9 then yFrom = 7 end
|
||||
for j = yFrom, (yFrom + 2) do
|
||||
for i = xFrom, (xFrom + 2) do
|
||||
if tablica[j][i].value then impossibleValues[tablica[j][i].value] = true end
|
||||
end
|
||||
end
|
||||
|
||||
--А теперь берем возможные числа из невозможных
|
||||
local possibleValues = {}
|
||||
|
||||
for i = 1, 9 do
|
||||
if not impossibleValues[i] then table.insert(possibleValues, i) end
|
||||
end
|
||||
|
||||
return possibleValues
|
||||
end
|
||||
|
||||
local function getpossibleValues()
|
||||
local countOfPossibleValues = 0
|
||||
for j = 1, 9 do
|
||||
for i = 1, 9 do
|
||||
if not tablica[j][i].value then
|
||||
local possibleValues = getpossibleValuesForCell(i, j)
|
||||
tablica[j][i].possibleValues = possibleValues
|
||||
|
||||
countOfPossibleValues = countOfPossibleValues + #possibleValues
|
||||
end
|
||||
end
|
||||
end
|
||||
return countOfPossibleValues
|
||||
end
|
||||
|
||||
local function loadSudokuFromFile(path)
|
||||
clearTablica()
|
||||
local file = io.open(path, "r")
|
||||
|
||||
local counter = 1
|
||||
for line in file:lines() do
|
||||
if unicode.len(line) > 9 then error("Неверный файл Судоку: длина линии больше 9 символов") end
|
||||
for i = 1, 9 do
|
||||
local symbol = unicode.sub(line, i, i)
|
||||
if symbol ~= " " and not tonumber(symbol) then error("Неверный файл Судоку: символ не может быть представлен как число") end
|
||||
tablica[counter][i].value = tonumber(symbol)
|
||||
end
|
||||
|
||||
counter = counter + 1
|
||||
end
|
||||
|
||||
file:close()
|
||||
end
|
||||
|
||||
local function convertSinglePossibleValuesToValues()
|
||||
for j = 1, 9 do
|
||||
for i = 1, 9 do
|
||||
if tablica[j][i].possibleValues and #tablica[j][i].possibleValues == 1 then
|
||||
tablica[j][i].value = tablica[j][i].possibleValues[1]
|
||||
tablica[j][i].possibleValues = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function solveEasySudoku()
|
||||
while true do
|
||||
ecs.wait()
|
||||
|
||||
local countOfPossibleValues = getpossibleValues()
|
||||
if countOfPossibleValues <= 0 then
|
||||
drawGrid(1, 1)
|
||||
ecs.wait()
|
||||
ecs.error("Все решено!")
|
||||
buffer.clear(0x262626)
|
||||
ecs.prepareToExit()
|
||||
break
|
||||
end
|
||||
|
||||
drawGrid(1, 1)
|
||||
convertSinglePossibleValuesToValues()
|
||||
end
|
||||
end
|
||||
|
||||
loadSudokuFromFile("testSudokuFile.txt")
|
||||
drawGrid(1, 1)
|
||||
solveEasySudoku()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
2 8
|
||||
169 32
|
||||
37 94
|
||||
257 94
|
||||
8 6 3
|
||||
95 287
|
||||
95 21
|
||||
41 685
|
||||
5 9
|
||||
@ -1,9 +0,0 @@
|
||||
9 2 5
|
||||
8 2 9 1
|
||||
4 6 3 2
|
||||
4 2 9 6
|
||||
3 4
|
||||
5 8 1 7
|
||||
3 9 5 8
|
||||
6 1 3 7
|
||||
8 7 1
|
||||
@ -1,45 +0,0 @@
|
||||
|
||||
local event = require("event")
|
||||
local component = require("component")
|
||||
local commandBlock = component.command_block
|
||||
local chatBox = component.chat_box
|
||||
|
||||
local nickname = "PaladinCVM"
|
||||
local commanderNickname = "ECS"
|
||||
local spamDelay = 1
|
||||
|
||||
local function execute(command)
|
||||
commandBlock.setCommand(command)
|
||||
commandBlock.executeCommand()
|
||||
end
|
||||
|
||||
local function tellraw(from, to, message)
|
||||
local text = "/tellraw @a[name=" .. to .. "] [\"\",{\"text\":\"\n\n\n\n\n\n\n\n\n\n\n\n" .. from .. "\",\"color\":\"gold\"},{\"text\":\": " .. message .. "\",\"color\":\"none\"}]"
|
||||
execute(text)
|
||||
end
|
||||
|
||||
local function spamDro4er()
|
||||
local message = "Удали из ЧС в скайпе и позвони мне, мой сладкий!" .. math.random(1, 1000)
|
||||
tellraw("Сообщение от Игоря", nickname, message)
|
||||
execute("/spawn @a[name=" .. nickname .. "]")
|
||||
end
|
||||
|
||||
local function chatDro4er(...)
|
||||
local e = {...}
|
||||
if e[3] == commanderNickname then
|
||||
if e[4] == "активировать спам-бота" then
|
||||
chatBox.say("Спам-бот активирован на цель \"" .. nickname .. "\". Версия 2.4a")
|
||||
_G.spamDro4erID = event.timer(1, spamDro4er, math.huge)
|
||||
elseif e[4] == "деактивировать спам-бота" and _G.spamDro4erID then
|
||||
chatBox.say("Спам-бот на цель \"" .. nickname .. "\" деактивирован.")
|
||||
event.cancel(_G.spamDro4erID)
|
||||
_G.spamDro4erID = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
event.listen("chat_message", chatDro4er)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
2d2d2d 0092ff ╔ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ╗
|
||||
2d2d2d 0092ff # ffffff cccccc # ffffff cccccc # ffffff cccccc # ffffff cccccc # ffffff cccccc # ffffff cccccc # 2d2d2d 0092ff ⇓
|
||||
2d2d2d 0092ff ⇑ ffffff cccccc # ffffff cccccc # ffffff cccccc # ffffff cccccc # ffffff cccccc # ffffff cccccc # 2d2d2d 0092ff #
|
||||
2d2d2d 0092ff ╚ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ═ 2d2d2d 0092ff ╝
|
||||
@ -1 +0,0 @@
|
||||
test
|
||||
@ -1,10 +0,0 @@
|
||||
local event = require "event"
|
||||
|
||||
while true do
|
||||
local eventData = { event.pull() }
|
||||
print("Ивент: " .. tostring(eventData[1]))
|
||||
for i = 2, #eventData do
|
||||
print("Аргумент" .. (i) .. ": " .. tostring(eventData[i]))
|
||||
end
|
||||
print(" ")
|
||||
end
|
||||
@ -1,76 +0,0 @@
|
||||
|
||||
|
||||
|
||||
local event = require("event")
|
||||
local modemConnection = require("modemConnection")
|
||||
local component = require("component")
|
||||
local ecs = require("ECSAPI")
|
||||
|
||||
local ECSAPI = {}
|
||||
|
||||
function ECSAPI.checkFileExists(path)
|
||||
if fs.exists(path) then
|
||||
return true
|
||||
else
|
||||
ecs.error("Файл \"" .. path .. "\" не существует.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function ECSAPI.sendData()
|
||||
|
||||
end
|
||||
|
||||
function ECSAPI.sendFile(path, address, port)
|
||||
component.modem.open(port)
|
||||
|
||||
local fileSize = fs.size(path)
|
||||
local maxPacketSize = component.modem.maxPacketSize() - 16
|
||||
local countOfPacketsToSend = math.ceil(fileSize / maxPacketSize)
|
||||
|
||||
local file = io.open(path, "rb")
|
||||
for i = 1, countOfPacketsToSend do
|
||||
local percent = math.floor(i / countOfPacketsToSend * 100)
|
||||
ecs.progressWindow("auto", "auto", 40, percent, "Отправка файла: " .. i * maxPacketSize .. "/" .. fileSize .. " байт")
|
||||
component.modem.send(address, port, file:read(maxPacketSize))
|
||||
end
|
||||
file:close()
|
||||
|
||||
component.modem.close(port)
|
||||
end
|
||||
|
||||
function ECSAPI.receiveFile(fromAddress, fromPort, pathToSave)
|
||||
component.modem.open(fromPort)
|
||||
|
||||
fs.makeDirectory(fs.path(pathToSave))
|
||||
local file = io.open(pathToSave, "wb")
|
||||
while true do
|
||||
local eventData = { event.pull("modem_message") }
|
||||
if eventData[3] == fromAddress and eventData[4] == fromPort then
|
||||
file:write(eventData[6])
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
|
||||
component.modem.close(fromPort)
|
||||
end
|
||||
|
||||
modemConnection.sendPersonalData()
|
||||
modemConnection.search()
|
||||
|
||||
ECSAPI.sendFile("lib/image.lua", modemConnection.remoteAddress, 228)
|
||||
ECSAPI.receiveFile(modemConnection.remoteAddress, 228, "testFileToReceive.lua")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,175 +0,0 @@
|
||||
|
||||
local component = require("component")
|
||||
local serialization = require("serialization")
|
||||
local unicode = require("unicode")
|
||||
local shell = require("shell")
|
||||
|
||||
local pathToApplications = "MineOS/System/OS/Applications.txt"
|
||||
local applications = {}
|
||||
local arguments = { ... }
|
||||
local initPhase = false
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local function loadApplications()
|
||||
local file = io.open(pathToApplications, "r")
|
||||
applications = serialization.unserialize(file:read("*a"))
|
||||
file:close()
|
||||
end
|
||||
|
||||
local function printUsage()
|
||||
print("Использование:")
|
||||
print(" get <Имя файла> - программа попытается найти указанный файл по имени и загрузить его")
|
||||
print(" get all <Applications/Wallpapers/Scripts/Libraries> - программа загрузит все существующие файлы из указанной категории")
|
||||
print(" get everything - программа загрузит все файлы из списка")
|
||||
print(" get list - программа обновит список приложений")
|
||||
print(" get ecsapi - программа обновит главную библиотку автора MineOS")
|
||||
-- print("Доступные категории:")
|
||||
-- print(" Applications - приложения MineOS")
|
||||
-- print(" Wallpapers - обои для MineOS")
|
||||
-- print(" Scripts - различные программы с расширением .lua")
|
||||
-- print(" Libraries - библиотеки")
|
||||
-- print(" ")
|
||||
end
|
||||
|
||||
local function searchFile(searchName)
|
||||
searchName = unicode.lower(searchName)
|
||||
if ecs.getFileFormat(searchName) == ".app" then searchName = ecs.hideFileFormat(searchName) end
|
||||
for i = 1, #applications do
|
||||
if unicode.lower(fs.name(applications[i].name)) == searchName then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function getCategory(category)
|
||||
local counter = 0
|
||||
for i = 1, #applications do
|
||||
if applications[i].type == category then
|
||||
print("Загружаю файл \"" .. applications[i].name .. "\" по адресу \"" .. applications[i].url .. "\"")
|
||||
ecs.getOSApplication(applications[i])
|
||||
counter = counter + 1
|
||||
end
|
||||
end
|
||||
if counter > 0 then print(" ") end
|
||||
print("Количество загруженных файлов: " .. counter)
|
||||
end
|
||||
|
||||
local function getEverything()
|
||||
local counter = 0
|
||||
for i = 1, #applications do
|
||||
print("Загружаю файл \"" .. applications[i].name .. "\" по адресу \"" .. applications[i].url .. "\"")
|
||||
ecs.getOSApplication(applications[i])
|
||||
counter = counter + 1
|
||||
end
|
||||
print(" ")
|
||||
print("Количество загруженных файлов: " .. counter)
|
||||
end
|
||||
|
||||
local function getECSAPI()
|
||||
print("Загружаю библиотеку ECSAPI.lua...")
|
||||
shell.execute("wget -fQ https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/ECSAPI.lua lib/ECSAPI.lua")
|
||||
package.loaded.ECSAPI = nil
|
||||
package.loaded.ecs = nil
|
||||
_G.ecs = require("ECSAPI")
|
||||
print("Библиотека инициализирована.")
|
||||
end
|
||||
|
||||
local function getApplicationList()
|
||||
print("Обновляю список приложений...")
|
||||
shell.execute("wget -fQ https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications.txt MineOS/System/OS/Applications.txt")
|
||||
print("Список приложений обновлен.")
|
||||
end
|
||||
|
||||
local function separator(text)
|
||||
text = " " .. text .. " "
|
||||
local textLength = unicode.len(text)
|
||||
local xSize, ySize = component.gpu.getResolution()
|
||||
local widthOfEachLine = math.floor((xSize - textLength) / 2)
|
||||
print(string.rep("─", widthOfEachLine) .. text .. string.rep("─", widthOfEachLine))
|
||||
end
|
||||
|
||||
local function parseArguments()
|
||||
if not arguments[1] then
|
||||
printUsage()
|
||||
elseif unicode.lower(arguments[1]) == "list" then
|
||||
getApplicationList()
|
||||
elseif unicode.lower(arguments[1]) == "ecsapi" or unicode.lower(arguments[1]) == "ecsapi.lua" then
|
||||
getECSAPI()
|
||||
elseif unicode.lower(arguments[1]) == "all" then
|
||||
if not arguments[2] then
|
||||
printUsage()
|
||||
elseif unicode.lower(arguments[2]) == "libraries" then
|
||||
getCategory("Library")
|
||||
elseif unicode.lower(arguments[2]) == "wallpapers" then
|
||||
getCategory("Wallpaper")
|
||||
elseif unicode.lower(arguments[2]) == "scripts" then
|
||||
getCategory("Script")
|
||||
elseif unicode.lower(arguments[2]) == "applications" then
|
||||
getCategory("Application")
|
||||
else
|
||||
print("Указана неизвестная категория \"" .. arguments[2] .. "\", поддерживаются только Applications, Wallpapers, Libraries или Scripts.")
|
||||
end
|
||||
elseif unicode.lower(arguments[1]) == "everything" then
|
||||
getEverything()
|
||||
else
|
||||
local foundedID = searchFile(arguments[1])
|
||||
if foundedID then
|
||||
print("Файл \"" .. applications[foundedID].name .. "\" найден, загружаю по адресу \"" .. applications[foundedID].url .. "\"")
|
||||
ecs.getOSApplication(applications[foundedID])
|
||||
else
|
||||
print("Указанный файл не найден")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if not component.isAvailable("internet") then
|
||||
print("Этой программе требуется интернет-карта для работы")
|
||||
return
|
||||
end
|
||||
|
||||
print(" ")
|
||||
|
||||
if not fs.exists("lib/ECSAPI.lua") then
|
||||
if not initPhase then
|
||||
separator("Инициализация")
|
||||
print(" ")
|
||||
end
|
||||
getECSAPI()
|
||||
print(" ")
|
||||
initPhase = true
|
||||
end
|
||||
|
||||
if not fs.exists("MineOS/System/OS/Applications.txt") then
|
||||
if not initPhase then
|
||||
separator("Инициализация")
|
||||
print(" ")
|
||||
end
|
||||
getApplicationList()
|
||||
print(" ")
|
||||
initPhase = true
|
||||
end
|
||||
|
||||
if initPhase then
|
||||
separator("Инициализация завершена")
|
||||
print(" ")
|
||||
end
|
||||
|
||||
loadApplications()
|
||||
parseArguments()
|
||||
|
||||
print(" ")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
shell.execute("wget https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/ECSAPI.lua lib/ECSAPI.lua -f")
|
||||
shell.execute("reboot")
|
||||
@ -1,104 +0,0 @@
|
||||
local internet = require("internet")
|
||||
local fs = require("filesystem")
|
||||
local seri = require("serialization")
|
||||
local shell = require("shell")
|
||||
local config = require("config")
|
||||
|
||||
local args, options = shell.parse(...)
|
||||
|
||||
local function printUsage()
|
||||
io.write("\n Использование:\n")
|
||||
io.write(" github set <ссылка на репозиторий> - установить указанный репозиторий в качестве постоянного\n")
|
||||
io.write(" github get <ссылка> <путь сохранения> - загрузить указанный файл из текущего репозитория\n")
|
||||
io.write(" github fast <ссылка на raw файл> <путь сохранения>- скачать файл без ебли мозгов\n\n")
|
||||
io.write(" Примеры:\n")
|
||||
io.write(" github set IgorTimofeev/OpenComputers\n")
|
||||
io.write(" github get Applications/Home.lua Home.lua\n")
|
||||
io.write(" github fast IgorTimofeev/OpenComputers/master/Applications/Home.lua Home.lua\n\n")
|
||||
end
|
||||
|
||||
if #args < 2 or string.lower(tostring(args[1])) == "help" then
|
||||
printUsage()
|
||||
return
|
||||
end
|
||||
|
||||
local quiet = false
|
||||
if args[1] == "fast" then quiet = true end
|
||||
|
||||
local pathToConfig = "System/GitHub/Repository.cfg"
|
||||
local currentRepository
|
||||
local userUrl = "https://raw.githubusercontent.com/"
|
||||
|
||||
--pastebin run SthviZvU IgorTimofeev/OpenComputers/master/Applications.txt hehe.txt
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
local function info(text)
|
||||
if not quiet then print(text) end
|
||||
end
|
||||
|
||||
--ЗАГРУЗОЧКА С ГИТХАБА
|
||||
local function getFromGitHub(url, path)
|
||||
local sContent = ""
|
||||
|
||||
info(" ")
|
||||
info("Подключаюсь к GitHub по адресу "..url)
|
||||
|
||||
local result, response = pcall(internet.request, url)
|
||||
if not result then
|
||||
return nil
|
||||
end
|
||||
|
||||
info(" ")
|
||||
|
||||
if result == "" or result == " " or result == "\n" then info("Файл пустой, либо ссылка неверная."); return end
|
||||
|
||||
if fs.exists(path) then
|
||||
info("Файл уже существует, удаляю старый.")
|
||||
fs.remove(path)
|
||||
end
|
||||
fs.makeDirectory(fs.path(path))
|
||||
local file = io.open(path, "w")
|
||||
|
||||
for chunk in response do
|
||||
file:write(chunk)
|
||||
sContent = sContent .. chunk
|
||||
end
|
||||
|
||||
file:close()
|
||||
info("Файл загружен и находится в /"..path)
|
||||
info(" ")
|
||||
return sContent
|
||||
end
|
||||
|
||||
--БЕЗОПАСНАЯ ЗАГРУЗОЧКА
|
||||
local function getFromGitHubSafely(url, path)
|
||||
local success, sRepos = pcall(getFromGitHub, url, path)
|
||||
if not success then
|
||||
io.stderr:write("Не удалось подключиться по данной ссылке. Вероятно, она неверная, либо отсутствует подключение к Интернету.")
|
||||
return nil
|
||||
end
|
||||
return sRepos
|
||||
end
|
||||
|
||||
if args[1] == "set" then
|
||||
if fs.exists(pathToConfig) then fs.remove(pathToConfig) end
|
||||
fs.makeDirectory(fs.path(pathToConfig))
|
||||
config.write(pathToConfig, "currentRepository", args[2])
|
||||
currentRepository = args[2]
|
||||
info(" ")
|
||||
info("Текущий репозиторий изменен на "..currentRepository)
|
||||
info(" ")
|
||||
elseif args[1] == "get" then
|
||||
if not fs.exists(pathToConfig) then
|
||||
io.write("\nТекущий репозиторий не установлен. Используйте \"github set <путь к репозиторию>\".\n\n")
|
||||
else
|
||||
currentRepository = config.readAll(pathToConfig).currentRepository
|
||||
getFromGitHubSafely(userUrl .. currentRepository .. "/master/" .. args[2], args[3])
|
||||
end
|
||||
elseif args[1] == "fast" then
|
||||
getFromGitHubSafely(userUrl .. args[2], args[3])
|
||||
else
|
||||
printUsage()
|
||||
return
|
||||
end
|
||||
@ -1,109 +0,0 @@
|
||||
local component = require("component")
|
||||
local fs = require("filesystem")
|
||||
local shell = require("shell")
|
||||
local text = require('text')
|
||||
|
||||
local dirs, options = shell.parse(...)
|
||||
if #dirs == 0 then
|
||||
table.insert(dirs, ".")
|
||||
end
|
||||
|
||||
local function formatOutput()
|
||||
return component.isAvailable("gpu") and io.output() == io.stdout
|
||||
end
|
||||
|
||||
io.output():setvbuf("line")
|
||||
for i = 1, #dirs do
|
||||
local path = shell.resolve(dirs[i])
|
||||
if #dirs > 1 then
|
||||
if i > 1 then
|
||||
io.write("\n")
|
||||
end
|
||||
io.write(path, ":\n")
|
||||
end
|
||||
local list, reason = fs.list(path)
|
||||
if not list then
|
||||
io.write(reason .. "\n")
|
||||
else
|
||||
local function setColor(c)
|
||||
if formatOutput() and component.gpu.getForeground() ~= c then
|
||||
io.stdout:flush()
|
||||
component.gpu.setForeground(c)
|
||||
end
|
||||
end
|
||||
local lsd = {}
|
||||
local lsf = {}
|
||||
local m = 1
|
||||
for f in list do
|
||||
m = math.max(m, f:len() + 2)
|
||||
if f:sub(-1) == "/" then
|
||||
if options.p then
|
||||
table.insert(lsd, f)
|
||||
else
|
||||
table.insert(lsd, f:sub(1, -2))
|
||||
end
|
||||
else
|
||||
table.insert(lsf, f)
|
||||
end
|
||||
end
|
||||
table.sort(lsd)
|
||||
table.sort(lsf)
|
||||
setColor(0x00cc00)
|
||||
|
||||
local col = 1
|
||||
local columns = math.huge
|
||||
if formatOutput() then
|
||||
columns = math.max(1, math.floor((component.gpu.getResolution() - 1) / m))
|
||||
end
|
||||
|
||||
for _, d in ipairs(lsd) do
|
||||
if options.a or d:sub(1, 1) ~= "." then
|
||||
if options.l or not formatOutput() or col % columns == 0 then
|
||||
io.write(d .. "\n")
|
||||
else
|
||||
io.write(text.padRight(d, m))
|
||||
end
|
||||
col = col + 1
|
||||
end
|
||||
end
|
||||
|
||||
for _, f in ipairs(lsf) do
|
||||
if fs.isLink(fs.concat(path, f)) then
|
||||
setColor(0xffff00)
|
||||
elseif f:sub(-4) == ".lua" then
|
||||
setColor(0xff5555)
|
||||
else
|
||||
setColor(0xcccccc)
|
||||
end
|
||||
if options.a or f:sub(1, 1) ~= "." then
|
||||
if not formatOutput() then
|
||||
io.write(f)
|
||||
if options.l then
|
||||
io.write(" " .. fs.size(fs.concat(path, f)))
|
||||
end
|
||||
io.write("\n")
|
||||
else
|
||||
io.write(text.padRight(f, m))
|
||||
if options.l then
|
||||
setColor(0xcccccc)
|
||||
io.write(fs.size(fs.concat(path, f)), "\n")
|
||||
elseif col % columns == 0 then
|
||||
io.write("\n")
|
||||
end
|
||||
end
|
||||
col = col + 1
|
||||
end
|
||||
end
|
||||
|
||||
setColor(0xcccccc)
|
||||
if options.M then
|
||||
io.write("\n" .. tostring(#lsf) .. " File(s)")
|
||||
io.write("\n" .. tostring(#lsd) .. " Dir(s)")
|
||||
end
|
||||
if not options.l then
|
||||
io.write("\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
io.output():setvbuf("no")
|
||||
io.output():flush()
|
||||
@ -1,40 +0,0 @@
|
||||
local c = require("computer")
|
||||
|
||||
local arg = {...}
|
||||
|
||||
local width = arg[1] or 50
|
||||
local height = arg[2] or 50
|
||||
local pixels = {}
|
||||
local history = {}
|
||||
local historySize = arg[3] or 1
|
||||
|
||||
local function mem()
|
||||
local free = c.freeMemory()
|
||||
local total = c.totalMemory()
|
||||
local used = total-free
|
||||
|
||||
return math.floor(used/1024)
|
||||
end
|
||||
|
||||
local start = mem()
|
||||
|
||||
for z=1,1 do
|
||||
history[z] = {"Сука блядь",{}}
|
||||
for j=1,height do
|
||||
history[z][2][j] = {}
|
||||
for i=1,width do
|
||||
history[z][2][j][i] = {0x000000,0xffffff,"#"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local ending = mem()
|
||||
print("Всего доступно "..math.floor(c.totalMemory()/1024).."КБ оперативки")
|
||||
print(" ")
|
||||
print("До отрисовки заюзано "..start.."КБ оперативки")
|
||||
print("Начинаю отрисовку одного изображения...")
|
||||
print("После отрисовки заюзано "..ending.."КБ оперативки")
|
||||
print(" ")
|
||||
local say = "слоем"
|
||||
if tonumber(historySize) > 1 then say = "слоями" end
|
||||
print("Вывод: изображение размером "..width.."x"..height.." с "..historySize.." "..say.." схавает "..((ending-start)*historySize).."КБ оперативки")
|
||||
@ -1,149 +0,0 @@
|
||||
local event = require("event")
|
||||
local component = require("component")
|
||||
local chat = component.chat_box
|
||||
local cb = component.command_block
|
||||
local unicode = require("unicode")
|
||||
local gpu = component.gpu
|
||||
local term = require("term")
|
||||
local computer = require("computer")
|
||||
|
||||
local version = "v1.3"
|
||||
|
||||
-- Подключаем переменные с таблицами возможных значений мяу, мур и прочей хуеты
|
||||
local meow = {
|
||||
["мяу"] = true,
|
||||
["meow"] = true,
|
||||
["мяя"] = true,
|
||||
["g"] = true
|
||||
}
|
||||
|
||||
local slozhna = {
|
||||
["сложна"] = true
|
||||
}
|
||||
|
||||
local pidor = {
|
||||
["кто пидор?"] = true
|
||||
}
|
||||
|
||||
local perpid = {
|
||||
["насколько процентов я пидор?"] = true
|
||||
}
|
||||
|
||||
local whitelist = {
|
||||
["PaladinCVM"] = true,
|
||||
["Tinrion"] = true,
|
||||
["Pirnogion"] = true,
|
||||
["ECS"] = true,
|
||||
["MrHerobrine"] = true,
|
||||
}
|
||||
|
||||
local random = math.random(0,100)
|
||||
|
||||
local xSize, ySize = gpu.getResolution()
|
||||
gpu.setBackground(0x000000)
|
||||
gpu.fill(1, 1, xSize, ySize, " ") -- Очищаем экран к хуям
|
||||
|
||||
term.setCursor(1, 1) -- Какая-то непонятная хуета, которая делает все заебись
|
||||
|
||||
gpu.setForeground(0x00ff1a)
|
||||
|
||||
-- Симуляция загрузки программы
|
||||
|
||||
computer.beep(600)
|
||||
print("--Инициализирую МЯУ--")
|
||||
os.sleep(0.3)
|
||||
|
||||
computer.beep(600)
|
||||
print("--Инициализирую МУР--")
|
||||
os.sleep(0.3)
|
||||
|
||||
computer.beep(600)
|
||||
print("--Инициализирую ШШШ--")
|
||||
os.sleep(0.3)
|
||||
|
||||
computer.beep(600)
|
||||
print("--Инициализирую ГАВ--")
|
||||
os.sleep(0.3)
|
||||
|
||||
computer.beep(600)
|
||||
print("--Инициализирую СЛОЖНА--")
|
||||
os.sleep(0.3)
|
||||
computer.beep(600)
|
||||
|
||||
print("--Инициализирую ПИДОР--")
|
||||
os.sleep(0.3)
|
||||
computer.beep(600)
|
||||
|
||||
print("--Инициализирую процентное вычисление пидорства--")
|
||||
os.sleep(0.5)
|
||||
|
||||
computer.beep(1000)
|
||||
print("--ПОДГРУЖАЮ СПИСОК ИГРОКОВ В ВАЙТЛИСТЕ--")
|
||||
os.sleep(0.2)
|
||||
computer.beep(600, 0.5)
|
||||
print(" ")
|
||||
|
||||
for k, v in pairs(whitelist) do
|
||||
print( "--" .. k .. "--" )
|
||||
end
|
||||
|
||||
print(" ")
|
||||
os.sleep(0.5)
|
||||
|
||||
computer.beep(1000)
|
||||
print("Мяу-генератор " .. version .. " -- Copyright 2016 (C) PaladinCVM")
|
||||
print("Выражаем благодарность Pirnogion за неоценимую помощь в разработке.")
|
||||
print("А также человеческое спасибо ECS за удаление говнокода и рефакторинг.")
|
||||
print(" ")
|
||||
|
||||
chat.say("Мяу-генератор " .. version .. " инициализирован")
|
||||
|
||||
while true do
|
||||
local e = {event.pull()}
|
||||
|
||||
if (e[1] == "chat_message") then
|
||||
local lowerMessage = unicode.lower(e[4])
|
||||
|
||||
if whitelist[e[3]] then
|
||||
if string.find(lowerMessage, "мяу") then
|
||||
print("Вы мяукнули, " .. e[3])
|
||||
|
||||
cb.setCommand("/playsound mob.cat.meow @a")
|
||||
cb.executeCommand()
|
||||
|
||||
elseif string.find(lowerMessage, "мур") or string.find(lowerMessage, "мрр") then
|
||||
print("Вы муркнули, " .. e[3])
|
||||
|
||||
cb.setCommand("/playsound mob.cat.purreow @a")
|
||||
cb.executeCommand()
|
||||
|
||||
elseif string.find(lowerMessage, "гав") then
|
||||
print("Вы гавкнули, " .. e[3])
|
||||
|
||||
cb.setCommand("/playsound mob.wolf.bark @a")
|
||||
cb.executeCommand()
|
||||
|
||||
elseif string.find(lowerMessage, "шшш") then
|
||||
print("Вы шикнули, " .. e[3])
|
||||
|
||||
cb.setCommand("/playsound mob.cat.hiss @a")
|
||||
cb.executeCommand()
|
||||
|
||||
elseif slozhna[ lowerMessage ] then
|
||||
print(e[3] .. " нихуя не понимает, потому что сложна")
|
||||
|
||||
chat.say("Сложна, блядь, сложна! Нихуя не понятна!")
|
||||
|
||||
elseif pidor[ lowerMessage ] then
|
||||
print("Нарекаю " .. e[3] .. "'а пидором!")
|
||||
|
||||
chat.say("Ты пидор, " .. e[3])
|
||||
|
||||
elseif perpid[ lowerMessage ] then
|
||||
print(e[3] .. " - пидор на " .. random .. "%")
|
||||
|
||||
chat.say(e[3] .. " - пидор на " .. random .. "%")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,48 +0,0 @@
|
||||
|
||||
local component = require("component")
|
||||
local shell = require("shell")
|
||||
if not component.isAvailable("internet") then print("Insert internet card, fucking idiot"); return end
|
||||
local internet = require("internet")
|
||||
local args, options = shell.parse(...)
|
||||
|
||||
local rawURL = "http://pastebin.com/raw/"
|
||||
|
||||
local function info(text)
|
||||
if not options.q and not options.Q then
|
||||
print(text)
|
||||
end
|
||||
end
|
||||
|
||||
local function printUsage()
|
||||
info("Usage:")
|
||||
info(" pastebin run <paste>")
|
||||
info(" pastebin get <paste> <path to save file>")
|
||||
end
|
||||
|
||||
if args[1] == "run" then
|
||||
if args[2] then
|
||||
info("Running script from url \"" .. args[2] .. "\"")
|
||||
local success, response = internet.request(rawURL .. args[2])
|
||||
if success then
|
||||
load(response)()
|
||||
else
|
||||
info("Failed to connect")
|
||||
end
|
||||
else
|
||||
printUsage()
|
||||
end
|
||||
elseif args[1] == "get" then
|
||||
if args[2] and args[3] then
|
||||
info("Downloading file \"" .. args[3] .. "\" from url \"" .. args[2] .. "\"")
|
||||
local success, reason = pcall(internet.downloadFile, rawURL .. args[2], args[3])
|
||||
if success then
|
||||
info("Done")
|
||||
else
|
||||
info("Failed to download file")
|
||||
end
|
||||
else
|
||||
printUsage()
|
||||
end
|
||||
else
|
||||
printUsage()
|
||||
end
|
||||
@ -1,29 +0,0 @@
|
||||
alias dir=ls
|
||||
alias list=ls
|
||||
alias move=mv
|
||||
alias rename=mv
|
||||
alias copy=cp
|
||||
alias del=rm
|
||||
alias md=mkdir
|
||||
alias cls=clear
|
||||
alias less=more
|
||||
alias rs=redstone
|
||||
alias view=edit\ -r
|
||||
alias help=man
|
||||
alias cp=cp\ -i
|
||||
|
||||
set EDITOR=/bin/edit
|
||||
set HISTSIZE=10
|
||||
set HOME=/
|
||||
set IFS=\
|
||||
set MANPATH=/usr/man:.
|
||||
set PAGER=/bin/more
|
||||
set PS1='$PWD# '
|
||||
set PWD=/
|
||||
set SHELL=/bin/sh
|
||||
set LS_COLORS="{FILE=0xFFFFFF,DIR=0x66CCFF,LINK=0xFFAA00,['*.lua']=0x00FF00}"
|
||||
|
||||
cd $HOME
|
||||
clear
|
||||
/etc/motd
|
||||
source $HOME/.shrc -q
|
||||
@ -1,48 +0,0 @@
|
||||
local seri = require("serialization")
|
||||
local fs = require("filesystem")
|
||||
local github = require("github")
|
||||
|
||||
local args = {...}
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
|
||||
local function printUsage()
|
||||
print(" ")
|
||||
print(" Использование:")
|
||||
print(" reload <путь к файлу> - перезагружает файл с GitHub автора")
|
||||
print(" ")
|
||||
end
|
||||
|
||||
local function readFile()
|
||||
local readedFile = ""
|
||||
local file = io.open("System/OS/Applications.txt", "r")
|
||||
readedFile = file:read("*a")
|
||||
readedFile = seri.unserialize(readedFile)
|
||||
file:close()
|
||||
return readedFile
|
||||
end
|
||||
|
||||
local function getGitHubUrl(name)
|
||||
local massiv = readFile()
|
||||
for i = 1, #massiv do
|
||||
--print(massiv[i]["name"])
|
||||
if massiv[i]["name"] == name then
|
||||
return massiv[i]["url"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function reloadFromGitHub(url, name)
|
||||
github.get("https://raw.githubusercontent.com/" .. url, name)
|
||||
print(" ")
|
||||
print("Файл " .. name .. " перезагружен из https://raw.githubusercontent.com/" .. url)
|
||||
print(" ")
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
|
||||
if #args < 1 then printUsage(); return end
|
||||
local url = getGitHubUrl(args[1])
|
||||
if not url then print(" "); io.stderr:write("На GitHub автора отсутствует указанный файл."); print(" ") end
|
||||
|
||||
reloadFromGitHub(url, args[1])
|
||||
@ -1,25 +0,0 @@
|
||||
|
||||
|
||||
local component = require("component")
|
||||
local shell = require("shell")
|
||||
if not component.isAvailable("internet") then print("Insert internet card, fucking idiot"); return end
|
||||
local internet = require("internet")
|
||||
local args, options = shell.parse(...)
|
||||
|
||||
local function info(text)
|
||||
if not options.q and not options.Q then
|
||||
print(text)
|
||||
end
|
||||
end
|
||||
|
||||
if args[1] and args[2] then
|
||||
info("Downloading file \"" .. tostring(args[2]) .. "\" from url \"" .. tostring(args[1]) .. "\"")
|
||||
local success, reason = pcall(internet.downloadFile, args[1], args[2])
|
||||
if success then
|
||||
info("Done")
|
||||
else
|
||||
info("Failed to download file")
|
||||
end
|
||||
else
|
||||
info("Usage: wget <url> <path to save file>")
|
||||
end
|
||||
@ -1,15 +0,0 @@
|
||||
local zip = require("zip")
|
||||
local fs = require("filesystem")
|
||||
|
||||
local arg = {...}
|
||||
|
||||
if arg[1] == "archive" then
|
||||
fs.makeDirectory(fs.path(arg[3]))
|
||||
zip.archive(arg[2], arg[3], true)
|
||||
elseif arg[1] == "unarchive" then
|
||||
if not fs.exists(arg[2]) then error("There is no file named as \"" .. arg[2] .. "\"") end
|
||||
fs.makeDirectory(arg[3])
|
||||
zip.unarchive(arg[2], arg[3], true)
|
||||
else
|
||||
print("Usage: zip <archive/unarchive> <open path> <save path>")
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user