Compare commits

..

No commits in common. "bce53de48c05ec3008d11b98814aad54c11ab449" and "ae6e7171a845782c277c86207fcedd32a84502ff" have entirely different histories.

12 changed files with 62 additions and 197 deletions

View File

@ -1,5 +1,4 @@
love.conf = function(conf) love.conf = function(conf)
conf.identity = "Poppy"
conf.window.height = 612 conf.window.height = 612
conf.window.minheight = 480 conf.window.minheight = 480
conf.window.width = 1024 conf.window.width = 1024

View File

@ -4,7 +4,7 @@ local utils = require("shared.utils")
local fonts = require("shared.fonts") local fonts = require("shared.fonts")
local commands = {} local commands = {}
local sharedCommands = require("shared.commands") local sharedCommands = require("lua.sharedCommands")
commands.commandsInit = sharedCommands.commandsInit commands.commandsInit = sharedCommands.commandsInit
@ -33,16 +33,6 @@ commands.ping = function(clientID)
end end
commands.saveWorld = function(clientID, args)
local status, savename = utils.nextStringRecord(args)
if status == "failed" then
ui.addChatEntry("SERVER", "Failed to save world!")
elseif status == "sucess" then
ui.addChatEntry("SERVER", "saved world. " .. savename)
end
end
commands.playerJoin = function(clientID, args) commands.playerJoin = function(clientID, args)
local nickname, avatarEncoded = utils.nextStringRecord(args) local nickname, avatarEncoded = utils.nextStringRecord(args)
avatarHash = love.data.decode("string", "base64", avatarEncoded) avatarHash = love.data.decode("string", "base64", avatarEncoded)

View File

@ -7,10 +7,10 @@ local socket = require "socket"
local utils = require("shared.utils") local utils = require("shared.utils")
local fonts = require("shared.fonts") local fonts = require("shared.fonts")
local errorHandler = require("shared.error")
local rpc = require("server.rpc") local rpc = require("server.rpc")
local constants = require("server.constants") local constants = require("server.constants")
local errorHandler = require("lua.error")
gameloop.nwChecklist = {} gameloop.nwChecklist = {}
gameloop.Canvas = {} gameloop.Canvas = {}

View File

@ -1,6 +1,5 @@
local layout = {} local layout = {}
layout.uiState = {} layout.uiState = {}
layout.uiStateMenu = {}
local fonts = require("shared.fonts") local fonts = require("shared.fonts")
local utils = require("shared.utils") local utils = require("shared.utils")
@ -58,15 +57,6 @@ function layout.cursorSelect(container, x, y, simulate)
end end
function layout.cursorSelectMenu(container, x, y, simulate)
x2, y2 = layout.handle(container[1], x, y, simulate)
if not simulate then
table.insert(layout.uiStateMenu, { identifier = container.identifier, kind=container.kind,
x=x, x2=x2, y=y, y2=y2 })
end
return x2, y2
end
function layout.linewidth(container, x, y, simulate) function layout.linewidth(container, x, y, simulate)
assert(container.width, "layout.linewidth (container) no container.width provided!") assert(container.width, "layout.linewidth (container) no container.width provided!")

View File

@ -1,5 +1,6 @@
menu = {} menu = {}
menu.serverlist = { menu.serverlist = {
{description = "Lenjas server", host = "192.168.178.39", port = "11150"},
{description = "A localhost server", host = "::1", port = "11150"}, {description = "A localhost server", host = "::1", port = "11150"},
{description = "A localhost server [ipv4]", host = "127.0.0.1", port = "11150"} {description = "A localhost server [ipv4]", host = "127.0.0.1", port = "11150"}
} }

View File

@ -9,27 +9,24 @@ local textures
function commands.commandsInit() function commands.commandsInit()
if gameloop then -- client if gameloop then -- client
CLIENT = true
players = _G.players players = _G.players
textures = gameloop.textures textures = gameloop.textures
else else
SERVER = true
players = _G.clients
textures = serverloop.textures
canvas.fg = serverloop.Canvas.fg canvas.fg = serverloop.Canvas.fg
canvas.bg = serverloop.Canvas.bg canvas.bg = serverloop.Canvas.bg
players = _G.clients
textures = serverloop.textures
end end
end end
function commands.commandsWorldInit() function commands.commandsWorldInit()
if CLIENT then if gameloop then
canvas.fg = gameloop.Canvas.fg canvas.fg = gameloop.Canvas.fg
canvas.bg = gameloop.Canvas.bg canvas.bg = gameloop.Canvas.bg
end end
end end
commands.moveUpdate = function(clientID, args) commands.moveUpdate = function(clientID, args)
if not players[clientID] then return end if not players[clientID] then return end
local x, args = utils.nextIntRecord(args) local x, args = utils.nextIntRecord(args)
@ -51,9 +48,7 @@ end
commands.drawTexture = function(clientID, args) commands.drawTexture = function(clientID, args)
if _G.camera then if clientID == camera.target then return end
if clientID == camera.target then return end
end
local x, args = utils.nextIntRecord(args) local x, args = utils.nextIntRecord(args)
local y, args = utils.nextIntRecord(args) local y, args = utils.nextIntRecord(args)
local layer, args = utils.nextStringRecord(args) local layer, args = utils.nextStringRecord(args)
@ -63,10 +58,13 @@ commands.drawTexture = function(clientID, args)
local g, args = utils.nextIntRecord(args) local g, args = utils.nextIntRecord(args)
local b, args = utils.nextIntRecord(args) local b, args = utils.nextIntRecord(args)
a = tonumber(args) or 1 a = tonumber(args) or 1
if not textures[hash] then error("Failed to find hash!") return end if not gameloop.textures[hash] then error("Failed to find hash!") return end
if not textures[hash].image then if not textures[hash].image then love.graphics.newImage(textures[hash].data) end
textures[hash].image = love.graphics.newImage(textures[hash].data)
end print(x, y, layer, r, g, b, a)
print(hashEncoded)
print(type(canvas))
print(type(canvas[layer]))
love.graphics.setCanvas(canvas[layer]) love.graphics.setCanvas(canvas[layer])
love.graphics.setBlendMode("alpha") love.graphics.setBlendMode("alpha")
utils.color_push() utils.color_push()
@ -78,9 +76,7 @@ end
commands.deleteTexture = function(clientID, args) commands.deleteTexture = function(clientID, args)
if _G.camera then if clientID == camera.target then return end
if clientID == camera.target then return end
end
local x, args = utils.nextIntRecord(args) local x, args = utils.nextIntRecord(args)
local y, args = utils.nextIntRecord(args) local y, args = utils.nextIntRecord(args)
local width, args = utils.nextIntRecord(args) local width, args = utils.nextIntRecord(args)

View File

@ -27,42 +27,10 @@ ui.helptext = [[[P] toggle fly
{Cursor keys} Move camera {Cursor keys} Move camera
]] ]]
local menuVisible = false
local textEnabled = false local textEnabled = false
local textEntry = "" local textEntry = ""
function ui.keyreleased(key, _) function ui.keyreleased(key, _)
if key == "escape" then
menuVisible = not menuVisible
if menuVisible then
love.visible = function(visible)
if visible then
love.update = function(dt)
gameloop.networkSync(dt)
physics.update(dt)
camera.update(dt)
love.timer.sleep((1/60) -dt)
end
else
love.update = function(dt)
gameloop.networkSync(dt)
physics.update(dt)
end
end
end
ui.drawMenu(window.x, window.y)
else
love.visible = function(visible)
if visible then
love.update = gameloop.normalVisible
else
love.update = gameloop.reducedVisible
end
end
ui.draw(window.x, window.y)
end
love.visible(true)
return
end
if key == "return" and not love.keyboard.isDown("lalt") then if key == "return" and not love.keyboard.isDown("lalt") then
textEnabled = true textEnabled = true
love.keyboard.setTextInput(true) love.keyboard.setTextInput(true)
@ -294,21 +262,6 @@ function ui.helpDrawer(w, h)
} }
end end
function ui.menuDrawer(w, h)
return {name = "color",
color = { 1, 1, 0.8, 0.8},
{name = "cursorSelectMenu",
identifier = "save",
kind = "button",
{name = "label",
text = "Save world",
font = fonts.bigFont
}
}
}
end
function ui.draw(w, h) function ui.draw(w, h)
window.x, window.y = w, h window.x, window.y = w, h
@ -327,65 +280,52 @@ function ui.draw(w, h)
end end
function ui.drawMenu(w, h)
window.x, window.y = w, h
layout.uiStateMenu = {}
love.graphics.setCanvas(ui.buffer)
love.graphics.clear()
local menuDrawer = ui.menuDrawer(w, h)
menux, menuy = layout.handle(menuDrawer, 0, 0, true)
layout.handle(menuDrawer, (window.x - menux) /2, (window.y - menuy)/2)
love.graphics.setCanvas()
end
function ui.mousepressed(mousex, mousey) function ui.mousepressed(mousex, mousey)
local textures = gameloop.textures local textures = gameloop.textures
if menuVisible then for i, v in ipairs(layout.uiState) do
for i, v in ipairs(layout.uiStateMenu) do if mousex >= v.x and mousex <= v.x2 then
if mousex >= v.x and mousex <= v.x2 then if mousey >= v.y and mousey <= v.y2 then
if mousey >= v.y and mousey <= v.y2 then if v.kind == "picker" then
if v.kind == "button" then assert(v.identifier, "No identifier in picker!")
if v.identifier == "save" then drawing.cursorHash = v.identifier
gameloop.networkSend("saveWorld") drawing.cursor = textures[v.identifier]
ui.keyreleased("escape") assert(drawing.cursor, "No cursor texture found!")
end ui.draw(window.x, window.y)
end
end
end
end
else
for i, v in ipairs(layout.uiState) do
if mousex >= v.x and mousex <= v.x2 then
if mousey >= v.y and mousey <= v.y2 then
if v.kind == "picker" then
assert(v.identifier, "No identifier in picker!")
drawing.cursorHash = v.identifier
drawing.cursor = textures[v.identifier]
assert(drawing.cursor, "No cursor texture found!")
ui.draw(window.x, window.y)
return
elseif v.kind == "tab" then
selectedTab = v.identifier
ui.draw(window.x, window.y)
return
elseif v.kind == "colorpicker" then
local scale = 1.0 / granularity
local red = math.floor((mousey - v.y) / v.pointSize) / scale
local green = math.floor((mousex - v.x) / v.pointSize / (scale + 1)) / scale
local blue = (math.floor((mousex - v.x) / v.pointSize) % (scale + 1)) / scale
drawing.color = {red, green, blue, 1}
ui.draw(window.x, window.y)
return
elseif v.kind == "bwColorPicker" then
local scale = 1.0 / granularity
local saturation = math.floor((mousex - v.x) / v.pointSize) / scale
drawing.color = {saturation, saturation, saturation, 1}
ui.draw(window.x, window.y)
return
end
return return
elseif v.kind == "tab" then
selectedTab = v.identifier
ui.draw(window.x, window.y)
return
elseif v.kind == "colorpicker" then
local scale = 1.0 / granularity
local red = math.floor((mousey - v.y) / v.pointSize) / scale
local green = math.floor((mousex - v.x) / v.pointSize / (scale + 1)) / scale
local blue = (math.floor((mousex - v.x) / v.pointSize) % (scale + 1)) / scale
drawing.color = {red, green, blue, 1}
ui.draw(window.x, window.y)
return
elseif v.kind == "bwColorPicker" then
local scale = 1.0 / granularity
local saturation = math.floor((mousex - v.x) / v.pointSize) / scale
drawing.color = {saturation, saturation, saturation, 1}
ui.draw(window.x, window.y)
return
elseif v.kind == "button" then
if v.identifier == "disconnect" then
gameloop.networkSend(utils.unit("playerLeave"))
menu.init()
return
elseif v.identifier == "increaseUISize" then
ui.sidebarScale = 2
ui.draw(window.x, window.y)
return
elseif v.identifier == "decreaseUISize" then
ui.sidebarScale = 1
ui.draw(window.x, window.y)
return
end
end end
return
end end
end end
end end

View File

@ -5,11 +5,9 @@ local rpc = require("server.rpc")
return function(commands) return function(commands)
function commands.drawTexture(clientID, args) function commands.drawTexture(clientID, args)
sharedCommands.drawTexture(clientID, args)
broadcast(clientID, util.unit("drawTexture", args)) broadcast(clientID, util.unit("drawTexture", args))
end end
function commands.deleteTexture(clientID, args) function commands.deleteTexture(clientID, args)
sharedCommands.deleteTexture(clientID, args)
broadcast(clientID, util.unit("deleteTexture", args)) broadcast(clientID, util.unit("deleteTexture", args))
end end
function commands.clearCanvas(clientID) function commands.clearCanvas(clientID)

View File

@ -1,45 +0,0 @@
local util = require("shared.utils")
local constants = require("server.constants")
local rpc = require("server.rpc")
local os = require("os")
return function(commands)
function commands.listSaves(clientID, args)
end
function commands.saveWorld(clientID, args)
local handle = io.popen("date -u --rfc-3339=seconds")
local datetime = handle:read("*a")
handle:close()
datetime = datetime:sub(1, -8)
datetime = datetime:gsub("%s+", "_")
datetime = datetime:gsub(":+", "")
print(datetime)
local savename = ""
if args then
savename = args .. "/" .. datetime
else
savename = datetime
end
local directory = "Saves/" .. savename
local result = love.filesystem.createDirectory(directory)
-- TODO check this result...
if result then
serverloop.Canvas.fg:newImageData():encode("png", directory .. "/fg.png")
serverloop.Canvas.bg:newImageData():encode("png", directory .. "/bg.png")
print("saved world. " .. savename)
broadcast("0", util.unit("saveWorld", "sucess", "" .. savename))
return
else
print("Failed to save world!")
return util.unit("saveWorld", "failed", "none")
end
end
function commands.loadWorld(clientID, args)
end
function commands.saveWorldAndLoad(clientID, args)
end
end

View File

@ -4,8 +4,8 @@ return {
protocolVersion = "poppyV003", protocolVersion = "poppyV003",
world = { world = {
x = 768, x = 3000,
y = 768, y = 3000,
id = "NYAAA" id = "NYAAA"
} }
} }

View File

@ -12,11 +12,8 @@ require("server.commands.players")(commands)
require("server.commands.physics")(commands) require("server.commands.physics")(commands)
require("server.commands.drawing")(commands) require("server.commands.drawing")(commands)
require("server.commands.chat")(commands) require("server.commands.chat")(commands)
require("server.commands.saving")(commands)
sharedCommands = require("shared.commands") local errorHandler = require("lua.error")
local errorHandler = require("shared.error")
local unpriviligedCommands = {} local unpriviligedCommands = {}
require("server.unpriviliged_commands.init")(unpriviligedCommands) require("server.unpriviliged_commands.init")(unpriviligedCommands)
@ -110,7 +107,6 @@ function serverloop.init(host)
serverloop.Canvas = {} serverloop.Canvas = {}
serverloop.Canvas.fg = love.graphics.newCanvas(constants.world.x, constants.world.y) serverloop.Canvas.fg = love.graphics.newCanvas(constants.world.x, constants.world.y)
serverloop.Canvas.bg = love.graphics.newCanvas(constants.world.x, constants.world.y) serverloop.Canvas.bg = love.graphics.newCanvas(constants.world.x, constants.world.y)
sharedCommands.commandsInit()
print("Startup!") print("Startup!")
love.update = mainloop love.update = mainloop
love.draw = function() love.draw = function()