Compare commits
2 Commits
ae6e7171a8
...
bce53de48c
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | bce53de48c | |
Pascal Abresch | 92ea3fe781 |
1
conf.lua
1
conf.lua
|
@ -1,4 +1,5 @@
|
||||||
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
|
||||||
|
|
|
@ -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("lua.sharedCommands")
|
local sharedCommands = require("shared.commands")
|
||||||
|
|
||||||
commands.commandsInit = sharedCommands.commandsInit
|
commands.commandsInit = sharedCommands.commandsInit
|
||||||
|
|
||||||
|
@ -33,6 +33,16 @@ 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)
|
||||||
|
|
|
@ -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 = {}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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")
|
||||||
|
@ -57,6 +58,15 @@ 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!")
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
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"}
|
||||||
}
|
}
|
||||||
|
|
138
lua/ui.lua
138
lua/ui.lua
|
@ -27,10 +27,42 @@ 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)
|
||||||
|
@ -262,6 +294,21 @@ 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
|
||||||
|
@ -280,52 +327,65 @@ 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
|
||||||
for i, v in ipairs(layout.uiState) do
|
if menuVisible then
|
||||||
if mousex >= v.x and mousex <= v.x2 then
|
for i, v in ipairs(layout.uiStateMenu) do
|
||||||
if mousey >= v.y and mousey <= v.y2 then
|
if mousex >= v.x and mousex <= v.x2 then
|
||||||
if v.kind == "picker" then
|
if mousey >= v.y and mousey <= v.y2 then
|
||||||
assert(v.identifier, "No identifier in picker!")
|
if v.kind == "button" then
|
||||||
drawing.cursorHash = v.identifier
|
if v.identifier == "save" then
|
||||||
drawing.cursor = textures[v.identifier]
|
gameloop.networkSend("saveWorld")
|
||||||
assert(drawing.cursor, "No cursor texture found!")
|
ui.keyreleased("escape")
|
||||||
ui.draw(window.x, window.y)
|
end
|
||||||
return
|
end
|
||||||
elseif v.kind == "tab" then
|
end
|
||||||
selectedTab = v.identifier
|
end
|
||||||
ui.draw(window.x, window.y)
|
end
|
||||||
return
|
else
|
||||||
elseif v.kind == "colorpicker" then
|
for i, v in ipairs(layout.uiState) do
|
||||||
local scale = 1.0 / granularity
|
if mousex >= v.x and mousex <= v.x2 then
|
||||||
local red = math.floor((mousey - v.y) / v.pointSize) / scale
|
if mousey >= v.y and mousey <= v.y2 then
|
||||||
local green = math.floor((mousex - v.x) / v.pointSize / (scale + 1)) / scale
|
if v.kind == "picker" then
|
||||||
local blue = (math.floor((mousex - v.x) / v.pointSize) % (scale + 1)) / scale
|
assert(v.identifier, "No identifier in picker!")
|
||||||
drawing.color = {red, green, blue, 1}
|
drawing.cursorHash = v.identifier
|
||||||
ui.draw(window.x, window.y)
|
drawing.cursor = textures[v.identifier]
|
||||||
return
|
assert(drawing.cursor, "No cursor texture found!")
|
||||||
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)
|
ui.draw(window.x, window.y)
|
||||||
return
|
return
|
||||||
elseif v.identifier == "decreaseUISize" then
|
elseif v.kind == "tab" then
|
||||||
ui.sidebarScale = 1
|
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)
|
ui.draw(window.x, window.y)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,11 @@ 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)
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
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
|
|
@ -4,8 +4,8 @@ return {
|
||||||
|
|
||||||
protocolVersion = "poppyV003",
|
protocolVersion = "poppyV003",
|
||||||
world = {
|
world = {
|
||||||
x = 3000,
|
x = 768,
|
||||||
y = 3000,
|
y = 768,
|
||||||
id = "NYAAA"
|
id = "NYAAA"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,11 @@ 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)
|
||||||
|
|
||||||
local errorHandler = require("lua.error")
|
sharedCommands = require("shared.commands")
|
||||||
|
|
||||||
|
local errorHandler = require("shared.error")
|
||||||
|
|
||||||
local unpriviligedCommands = {}
|
local unpriviligedCommands = {}
|
||||||
require("server.unpriviliged_commands.init")(unpriviligedCommands)
|
require("server.unpriviliged_commands.init")(unpriviligedCommands)
|
||||||
|
@ -107,6 +110,7 @@ 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()
|
||||||
|
|
|
@ -9,24 +9,27 @@ 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
|
||||||
canvas.fg = serverloop.Canvas.fg
|
SERVER = true
|
||||||
canvas.bg = serverloop.Canvas.bg
|
|
||||||
players = _G.clients
|
players = _G.clients
|
||||||
textures = serverloop.textures
|
textures = serverloop.textures
|
||||||
|
canvas.fg = serverloop.Canvas.fg
|
||||||
|
canvas.bg = serverloop.Canvas.bg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function commands.commandsWorldInit()
|
function commands.commandsWorldInit()
|
||||||
if gameloop then
|
if CLIENT 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)
|
||||||
|
@ -48,7 +51,9 @@ end
|
||||||
|
|
||||||
|
|
||||||
commands.drawTexture = function(clientID, args)
|
commands.drawTexture = function(clientID, args)
|
||||||
if clientID == camera.target then return end
|
if _G.camera then
|
||||||
|
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)
|
||||||
|
@ -58,13 +63,10 @@ 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 gameloop.textures[hash] then error("Failed to find hash!") return end
|
if not textures[hash] then error("Failed to find hash!") return end
|
||||||
if not textures[hash].image then love.graphics.newImage(textures[hash].data) end
|
if not textures[hash].image then
|
||||||
|
textures[hash].image = love.graphics.newImage(textures[hash].data)
|
||||||
print(x, y, layer, r, g, b, a)
|
end
|
||||||
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()
|
||||||
|
@ -76,7 +78,9 @@ end
|
||||||
|
|
||||||
|
|
||||||
commands.deleteTexture = function(clientID, args)
|
commands.deleteTexture = function(clientID, args)
|
||||||
if clientID == camera.target then return end
|
if _G.camera then
|
||||||
|
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)
|
Loading…
Reference in New Issue