Compare commits

...

6 Commits

Author SHA1 Message Date
Pascal Abresch d6015ef155 fix menu server entries 2022-10-09 12:52:44 +02:00
Pascal Abresch 761fa00cbd redo ui 2022-10-09 12:52:17 +02:00
Pascal Abresch 388964b2c3 style fix 2022-10-09 12:51:50 +02:00
Pascal Abresch a5649210a5 fix canvas, more errors 2022-10-09 12:51:38 +02:00
Pascal Abresch 2306586af4 style fix 2022-10-09 12:50:22 +02:00
Pascal Abresch 03f18b8c8a adjust default window size 2022-10-09 12:49:43 +02:00
10 changed files with 143 additions and 207 deletions

View File

@ -1,7 +1,7 @@
love.conf = function(conf)
conf.window.height = 1000
conf.window.height = 612
conf.window.minheight = 480
conf.window.width = 1000
conf.window.width = 1024
conf.window.minwidth = 640
conf.window.resizable = true
conf.window.vsync = -1

View File

@ -9,7 +9,9 @@ local altPressed, enterPressed = false, false
function camera.keypressed(key, _)
if key == "return" then enterPressed = true end
if key == "lalt" then altPressed = true end
if key == "f11" or (altPressed and key == "return") or (enterPressed and key == "lalt") then
if key == "f11"
or (altPressed and key == "return")
or (enterPressed and key == "lalt") then
fullscreen = not fullscreen
love.window.setFullscreen(fullscreen, "desktop")
end

View File

@ -8,6 +8,8 @@ local sharedCommands = require("lua.sharedCommands")
commands.commandsInit = sharedCommands.commandsInit
commands.commandsWorldInit = sharedCommands.commandsWorldInit
commands.init = function(clientID, args)
local nickname, args = utils.nextStringRecord(args)
local avatarEncoded, args = utils.nextStringRecord(args)

View File

@ -24,16 +24,16 @@ end
function drawing.fillCanvas(layer, hash)
love.graphics.setCanvas(gameloop.Canvas[layer])
love.graphics.clear()
for x = 0, gameloop.world.x -gameloop.textures[hash].image:getPixelWidth(),
gameloop.textures[hash].image:getPixelWidth() do
for y = 0, gameloop.world.y -gameloop.textures[hash].image:getPixelHeight(),
gameloop.textures[hash].image:getPixelHeight() do
love.graphics.draw(gameloop.textures[hash].image, x, y)
end
love.graphics.setCanvas(gameloop.Canvas[layer])
love.graphics.clear()
for x = 0, gameloop.world.x -gameloop.textures[hash].image:getPixelWidth(),
gameloop.textures[hash].image:getPixelWidth() do
for y = 0, gameloop.world.y -gameloop.textures[hash].image:getPixelHeight(),
gameloop.textures[hash].image:getPixelHeight() do
love.graphics.draw(gameloop.textures[hash].image, x, y)
end
love.graphics.setCanvas()
end
love.graphics.setCanvas()
end

43
lua/error.lua Normal file
View File

@ -0,0 +1,43 @@
local errorHandler = {}
function errorHandler.redscreen(msg)
local scale = 0.5
local errorfont
if love.filesystem.getInfo("fonts/font.ttf") then
errorfont = love.graphics.newFont("fonts/font.ttf", 45 * scale)
else
errorfont = love.graphics.newFont(45 * scale)
end
love.graphics.reset()
love.graphics.origin()
love.graphics.clear(.4, 0, 0)
love.graphics.setColor(1, 1, 1)
local message = love.graphics.newText(errorfont, "Poppy has encountered a critical fault")
local message2 = love.graphics.newText(errorfont, "Press q to exit")
local message3 = love.graphics.newText(errorfont, msg)
love.graphics.draw(message, 40, 40 * scale, 0, 1, 1)
love.graphics.draw(message2, 40, 90 * scale, 0, 1, 1)
love.graphics.draw(message3, 40, 140 * scale, 0, 1, 1)
print(msg)
local indent = 0
local messageline
for line in debug.traceback():gmatch("([^\n]*)\n?") do
print(line)
messageline = love.graphics.newText(errorfont, line)
love.graphics.draw(messageline, 40, (250 * scale) + indent, 0, 1, 1)
indent = indent + 50 * scale
end
love.graphics.present()
return function()
love.event.pump()
for event, action in love.event.poll() do
if event == "quit" then return 1 end
if event == "keypressed" then
if action == "q" then
love.event.quit( 1 )
end
end
end
love.timer.sleep(0.1)
end
end
return errorHandler

View File

@ -10,6 +10,7 @@ local fonts = require("shared.fonts")
local rpc = require("server.rpc")
local constants = require("server.constants")
local errorHandler = require("lua.error")
gameloop.nwChecklist = {}
gameloop.Canvas = {}
@ -129,49 +130,7 @@ end
local function errorhandlerNetwork(msg)
gameloop.networkSend(unit("playerLeave"))
return errorhandler(msg)
end
function errorhandler(msg)
local errorfont
if love.filesystem.getInfo("fonts/font.ttf") then
errorfont = love.graphics.newFont("fonts/font.ttf", 45)
else
errorfont = love.graphics.newFont(45)
end
love.graphics.reset()
love.graphics.origin()
love.graphics.clear(.4, 0, 0)
love.graphics.setColor(1, 1, 1)
local message = love.graphics.newText(errorfont, "Poppy has encountered a critical fault")
local message2 = love.graphics.newText(errorfont, "Press q to exit")
local message3 = love.graphics.newText(errorfont, msg)
love.graphics.draw(message, 40, 40, 0, 1, 1)
love.graphics.draw(message2, 40, 90, 0, 1, 1)
love.graphics.draw(message3, 40, 140, 0, 1, 1)
print(msg)
local indent = 0
local messageline
for line in debug.traceback():gmatch("([^\n]*)\n?") do
print(line)
messageline = love.graphics.newText(errorfont, line)
love.graphics.draw(messageline, 40, 250 + indent, 0, 1, 1)
indent = indent + 50
end
love.graphics.present()
return function()
love.event.pump()
for event, action in love.event.poll() do
if event == "quit" then return 1 end
if event == "keypressed" then
if action == "q" then
love.event.quit( 1 )
end
end
end
love.timer.sleep(0.1)
end
return errorHandler.redscreen(msg)
end
@ -204,7 +163,7 @@ end
function gameloop.init(server, nickname, avatarHash)
local US = constants.US
--love.errorhandler = errorhandler
love.errorhandler = errorHandler.redscreen
assert(server, "Gameloop called without server to connect to?")
assert(nickname, "Gameloop called without nickname?")
assert(avatarHash, "Gameloop called without avatar?")
@ -322,6 +281,7 @@ function gameloop.loadworld(world)
gameloop.Canvas.dbg2 = love.graphics.newCanvas(world.x, world.y)
end
gameloop.Canvas.physics = {}
commands.commandsWorldInit()
ui.init()
drawing.init()

View File

@ -1,7 +1,8 @@
menu = {}
menu.serverlist = {
--{description = "A localhost server [ipv4]", host = "127.0.0.1", port = "11150"},
{description = "A localhost server", host = "::1", port = "11150"}
{description = "Lenjas server", host = "192.168.178.39", port = "11150"},
{description = "A localhost server", host = "::1", port = "11150"},
{description = "A localhost server [ipv4]", host = "127.0.0.1", port = "11150"}
}
local utils = require("shared.utils")
@ -57,7 +58,7 @@ function menu.mousepressed(mousex, mousey)
love.graphics.present()
print("Starting server!")
local serverloop = require("server.main")
serverloop.init()
serverloop.init(v.identifier)
end
if v.kind == "server" then
if firstClient then
@ -132,8 +133,8 @@ menu.layout = {name ="vertical",
{name = "horizontal",
{name = "spacer", width = 50},
{name = "vertical",
{name = "spacer", height = 50},
{name = "cursorSelect", kind = "localServer", identifier = "::1",
{name = "spacer", height = 20},
{name = "cursorSelect", kind = "localServer", identifier = {"::1", "11150"},
{name = "horizontal",
{name = "spacer", width = 10},
{name = "drawTexture",
@ -143,22 +144,36 @@ menu.layout = {name ="vertical",
{name = "label", text = "Spin up a local server"},
}
},
{name = "spacer", height = 40},
{name = "cursorSelect", kind = "localServer", identifier = {"0.0.0.0", "11150"},
{name = "horizontal",
{name = "spacer", width = 10},
{name = "drawTexture",
texture = love.graphics.newImage("textures/menu/serverPlay.png")
},
{name = "spacer", width = 10},
{name = "label", text = "Spin up a local server [IPV4]"},
}
},
{name = "spacer", height = 20},
{name = "label", text = "Or pick a server to join!", font = fonts.headerFont},
{name = "spacer", height = 20},
{name = "horizontal",
{name = "spacer", width = 10},
{name = "vertical",
menu.layoutServerList(),
{name = "spacer", height = 10},
{name = "horizontal",
{name = "drawTexture", texture = love.graphics.newImage("textures/menu/AddIcon.png")},
{name = "spacer", width = 10 },
{name = "label", text = "placeholder (new server)" },
{name = "spacer", width = 20 },
{name = "label", text = "host: newhost", font = fonts.smallFont},
{name = "spacer", width = 10 },
{name = "label", text = "port: newport", font = fonts.smallFont},
{name = "vertical",
menu.layoutServerList(),
},
{name = "vertical",
{name = "spacer", height = 10},
{name = "horizontal",
{name = "drawTexture", texture = love.graphics.newImage("textures/menu/AddIcon.png")},
{name = "spacer", width = 10 },
{name = "label", text = "placeholder (new server)" },
{name = "spacer", width = 20 },
{name = "label", text = "host: newhost", font = fonts.smallFont},
{name = "spacer", width = 10 },
{name = "label", text = "port: newport", font = fonts.smallFont},
}
}
}
}

View File

@ -9,8 +9,6 @@ local textures
function commands.commandsInit()
if gameloop then -- client
canvas.fg = gameloop.Canvas.fg
canvas.bg = gameloop.Canvas.bg
players = _G.players
textures = gameloop.textures
else
@ -22,6 +20,13 @@ function commands.commandsInit()
end
function commands.commandsWorldInit()
if gameloop then
canvas.fg = gameloop.Canvas.fg
canvas.bg = gameloop.Canvas.bg
end
end
commands.moveUpdate = function(clientID, args)
if not players[clientID] then return end
local x, args = utils.nextIntRecord(args)
@ -47,22 +52,25 @@ commands.drawTexture = function(clientID, args)
local x, args = utils.nextIntRecord(args)
local y, args = utils.nextIntRecord(args)
local layer, args = utils.nextStringRecord(args)
local hash, args = utils.nextStringRecord(args)
hash = love.data.decode("string", "base64", hash)
local hashEncoded, args = utils.nextStringRecord(args)
hash = love.data.decode("string", "base64", hashEncoded)
local r, args = utils.nextIntRecord(args)
local g, args = utils.nextIntRecord(args)
local b, a = utils.nextIntRecord(args)
a = tonumber(a)
if not gameloop.textures[hash] then print("Failed to find hash!") return end
love.graphics.setBlendMode("replace")
local b, args = utils.nextIntRecord(args)
a = tonumber(args) or 1
if not gameloop.textures[hash] then error("Failed to find hash!") return end
if not textures[hash].image then 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.bg)
if not textures[hash].image then love.graphics.newImage(textures[hash].data) end
utils.color_push()
love.graphics.setColor(r, g, b ,a)
love.graphics.draw(textures[hash].image, x, y)
utils.color_pop()
love.graphics.setBlendMode("alpha")
love.graphics.setBlendMode("alpha")
utils.color_push()
love.graphics.setColor(r, g, b ,a )
love.graphics.draw(textures[hash].image, x, y)
utils.color_pop()
love.graphics.setCanvas()
end

View File

@ -2,8 +2,8 @@ ui = {}
ui.textureTree = nil
local layout = require("lua.layout")
local utils = require("shared.utils")
local fonts = require("shared.fonts")
ui.sidebarScale = 1
ui.sidebarWidth = 13 * 16
@ -129,7 +129,7 @@ function ui.addChatEntry(user, message)
{name = "vertical",
{name = "label",
text = chatText,
font = ui.smallFont
font = fonts.smallFont
},
{name = "spacer",
height = 2
@ -253,126 +253,29 @@ end
function ui.helpDrawer(w, h)
return {name = "label",
text = ui.helptext
}
end
function ui.testDrawer(w, h)
local drawer = {name = "vertical"}
return drawer
end
local selectedTab = "blocks"
function ui.tabDrawer(textureTree, w, h)
local labels
local helpTab = {name = "label",
text = ui.helptext
}
local hWidth, hHeight = layout.handle(helpTab, 0, 0, true)
local blockTab = ui.blockDrawer(textureTree, w, h)
local bWidth, bHeight = layout.handle(blockTab, 0, 0, true)
labels = {name = "horizontal",
{name = "cursorSelect",
identifier = "help",
kind = "tab",
{name = "label",
text = "Help"
}
},
{name = "spacer",
width = 5
},
{name = "cursorSelect",
identifier = "blocks",
kind = "tab",
{name = "label",
text = "Blocks"
}
},
{name = "spacer",
width = 5
},
{name = "cursorSelect",
identifier = "disconnect",
kind = "button",
{name = "label",
text = " Disconnect. "
}
},
{name = "spacer",
width = 5
},
{name = "cursorSelect",
identifier = "increaseUISize",
kind = "button",
{name = "label",
text = "+"
}
},
{name = "spacer",
width = 5
},
{name = "cursorSelect",
identifier = "decreaseUISize",
kind = "button",
{name = "label",
text = "-"
}
},
{name = "spacer",
width = 5
},
}
if selectedTab == "blocks" then
tab = blockTab
elseif selectedTab == "help" then
tab = helpTab
end
local drawer = {
name = "vertical",
{name = "copySize",
{name = "rect",
fill = "fill",
color = { r = .4, g = 0, b = .4 }
},
{name = "horizontal",
labels,
{name = "spacer",
height = 40,
},
},
},
{name = "copySize",
{name = "rect",
fill = "fill",
color = { r = .15, g = .15, b = .15 }
},
tab
return {name = "color",
color = { 1, 1, 0.8, 0.4},
{name = "label",
text = ui.helptext,
font = fonts.smallFont
}
}
return drawer, math.max(hWidth, bWidth)
end
function ui.draw(w, h)
window.x, window.y = w, h
utils.color_push()
love.graphics.setCanvas(ui.buffer)
uiState = {}
layout.uiState = {}
love.graphics.clear( )
local sidebar, width = ui.tabDrawer(ui.textureTree, ui.sidebarWidth * ui.sidebarScale, h)
layout.handle(sidebar, window.x -width, 0)
ui.space = width
if textEnabled then
local chatLayout = ui.chatEntry()
local sizex, sizey = layout.handle(chatLayout, 0, 0, true)
layout.handle(chatLayout, 0, window.y - sizey)
end
local blockDrawer = ui.blockDrawer(ui.textureTree, w, h)
local helpDrawer = ui.helpDrawer(w, h)
blockMaxX, blockMaxY = layout.handle(blockDrawer, 0, 0, true)
helpMaxX, helpMaxY = layout.handle(helpDrawer, 0, 0, true)
local blockDrawerAdjusted = ui.blockDrawer(ui.textureTree, blockMaxX, blockMaxY)
layout.handle(blockDrawerAdjusted, window.x - blockMaxX, 0)
layout.handle(helpDrawer, window.x - blockMaxX - helpMaxX, window.y - helpMaxY)
layout.handle(ui.chatlog(), 25, 90)
utils.color_pop()
love.graphics.setCanvas()
end

View File

@ -13,6 +13,8 @@ require("server.commands.physics")(commands)
require("server.commands.drawing")(commands)
require("server.commands.chat")(commands)
local errorHandler = require("lua.error")
local unpriviligedCommands = {}
require("server.unpriviliged_commands.init")(unpriviligedCommands)
@ -25,13 +27,8 @@ serverloop = {}
serverloop.textures = {}
server:settimeout(0)
assert(server:setsockname("*", 11150))
local socketString = server:getsockname()
print(socketString)
if not server or not socket then error("failed to listen on socket") end
print("Server startup.")
function broadcast(clientID, message)
local payload = util.unit(protocolVersion, clientID, message)
for i, player in pairs(clients) do
@ -99,7 +96,13 @@ function mainloop(dt)
end
function serverloop.init()
function serverloop.init(host)
love.errorhandler = errorHandler.redscreen
status, value = server:setsockname(host[1], host[2])
if not status then
error("Server could not be started :( " .. value)
end
print("Server startup. listening on " .. server:getsockname())
loadTextures("textures/blocks", serverloop.textures)
serverloop.Canvas = {}
serverloop.Canvas.fg = love.graphics.newCanvas(constants.world.x, constants.world.y)
@ -109,7 +112,7 @@ function serverloop.init()
love.draw = function()
love.graphics.clear(.2, 0, .2)
love.graphics.print("Poppy server is running.", fonts.normalFont, 20, 20)
love.graphics.print("listening on " .. socketString, fonts.normalFont, 20, 50)
love.graphics.print("listening on " .. server:getsockname(), fonts.normalFont, 20, 50)
return end
love.keyreleased = function() return end
love.keypressed = function() return end