Roast it (if you want)
Code: Select all
--main.lua
function love.load()
require("libs/sav")
tmp = nil
ar = {}
y = 0
mode = "run"
fnt = love.graphics.newFont(12)
love.filesystem.createDirectory("saves")
function initar(file, add)
tmp = load(file)
for i = 1, #tmp, 1 do
ar[i] = tmp:sub(i, i)
end
for i = 1, #ar, 1 do
if ar[i] == "/" and ar[i + 1] == "n" then
ar[i] = "\n"
for i = i + 2, #ar, 1 do
ar[i - 1] = ar[i]
if i == #ar then
ar[i] = nil
end
end
end
end
if add then
ar[#ar + 1] = "\b"
end
if ar[#ar - 1] == "n" then
ar[#ar - 1] = ""
end
end
initar("saves/def_save.txt", true)
function getnewlines(array, offset)
tmp = {}
tmp[1] = 0
tmp[2] = offset
while true do
tmp[1] = tmp[1] + 1
if array[tmp[1]] == "\n" then
tmp[2] = tmp[2] + 1
elseif array[tmp[1]] == nil then
return tmp[2]
end
end
end
love.keyboard.setKeyRepeat(true)
love.window.showMessageBox("Credit", "Made by Zalan(Zalnder)", "info")
tmp = love.window.showMessageBox("Warning", "This is not a fully finished build of version 2.0.1 bugs may occur. \n Continue ?", {"yes", "no(exit)"}, "warning")
if tmp == 2 then
love.event.quit(0)
end
love.graphics.setFont(fnt)
end
function love.update(dt)
if mode == "run" then
if (getnewlines(ar, 1) + 3) * 14 - math.abs(y) > love.graphics.getHeight() then
y = y - 12
end
end
if love.keyboard.isDown("escape") then
tmp = ""
ar[#ar] = nil
for i = 1, #ar, 1 do
if ar[i] == "\n" then
tmp = tmp.."/n"
else
tmp = tmp..ar[i]
end
end
save("saves/def_save.txt", tmp)
love.event.quit(0)
end
end
function love.draw()
if getnewlines(ar, 1) > 100 then
love.graphics.print(ar, 32, y)
else
love.graphics.print(ar, 20, y)
end
for i = 0, getnewlines(ar, 1), 1 do
love.graphics.print(i, 0, i * 14 + y)
end
love.graphics.rectangle("line", 0, love.graphics.getHeight() - 20, love.graphics.getWidth(), 30)
love.graphics.print("This is a extreamly early protoype !", 0, love.graphics.getHeight() - 20)
if mode == "run" then
love.graphics.print("Press left control to save", 12 * 36, love.graphics.getHeight() - 20)
elseif mode == "file opn" then
love.graphics.print("This is load mode enter filename to be loaded", 12 * 36, love.graphics.getHeight() - 20)
elseif mode == "file sav" then
love.graphics.print("This is save mode enter filene to be saved", 12 * 36, love.graphics.getHeight() - 20)
end
if love.keyboard.isDown("lctrl") and mode == "run" then
love.graphics.print("(saved)", love.graphics.getWidth() - 69, love.graphics.getHeight() - 20)
end
end
function love.keypressed(key)
ar[#ar] = nil
if key == "return" or key == "down" then
if mode == "run" then
if ar[#ar - 1] == "/" and ar[#ar] == "l" then
ar = {}
mode = "file opn"
elseif ar[#ar - 1] == "/" and ar[#ar] == "s" then
ar = {}
mode = "file sav"
else
ar[#ar + 1] = "\n"
end
else
if mode == "file opn" then
tmp = ""
for i = 1, #ar, 1 do
tmp = tmp..ar[i]
end
print(tmp)
if not(love.filesystem.getInfo("saves/"..tmp)) then
error("file not found") -- error out if file is not found
end
save("saves/def_save.txt", love.filesystem.read("saves/"..tmp))
ar = {}
initar("saves/def_save.txt", true)
mode = "run"
end
if mode == "file sav" then
tmp = ""
for i = 1, #ar, 1 do
tmp = tmp..ar[i]
end
if not(love.filesystem.getInfo("saves/"..tmp)) then
love.filesystem.newFile("saves/"..tmp)
end
save("saves/"..tmp, load("saves/def_save.txt"))
ar = {}
initar("saves/def_save.txt", true)
mode = "run"
end
end
end
if key == "backspace" then
if mode == "run" then
if not(y == 0) then
if ar[#ar] == "\n" then
if y > 0 then
y = 0
else
y = y + 15
end
end
end
end
ar[#ar] = nil
end
if mode == "run" then
if key == "lctrl" then
tmp = ""
for i = 1, #ar, 1 do
if ar[i] == "\n" then
tmp = tmp.."/n"
else
tmp = tmp..ar[i]
end
end
save("saves/def_save.txt", tmp)
end
end
ar[#ar + 1] = "\b"
end
function love.textinput(key)
ar[#ar] = nil
ar[#ar + 1] = key
ar[#ar + 1] = "\b"
end
Code: Select all
--save.lua (libs)
function save(filename, data)
if love.filesystem.getInfo(filename) then
love.filesystem.write(filename, data)
else
love.filesystem.newFile(filename)
love.filesystem.write(filename, data)
end
end
function load(filename)
if love.filesystem.getInfo(filename) then
return(love.filesystem.read(filename))
else
-- else is edited for this project
love.filesystem.newFile(filename)
love.filesystem.write(filename, "Type away~ /")
return(love.filesystem.read(filename))
end
end