109 lines
3.3 KiB
Lua
109 lines
3.3 KiB
Lua
local player = require("lua.player")
|
|
local utils = require("shared.utils")
|
|
|
|
return function(commands)
|
|
commands.moveUpdate = function(clientID, x, y, speedx, speedy)
|
|
if SERVER then
|
|
broadcast(clientID, "moveUpdate", x, y, speedx, speedy)
|
|
end
|
|
if not participants[clientID] then return end
|
|
|
|
participants[clientID].x = x
|
|
participants[clientID].y = y
|
|
if not participants[clientID].speed then participants[clientID].speed = {} end
|
|
participants[clientID].speed.x = speedx
|
|
participants[clientID].speed.y = speedy
|
|
end
|
|
|
|
|
|
commands.moveFlying = function(clientID, flying)
|
|
if SERVER then
|
|
broadcast(clientID, "moveFlying", flying)
|
|
end
|
|
if not participants[clientID] then return end
|
|
participants[clientID].flying = flying
|
|
end
|
|
|
|
|
|
commands.drawTexture = function(clientID, x, y, layer, hash, color)
|
|
if SERVER then
|
|
color.nwType = "color"
|
|
broadcast(clientID, "drawTexture", x, y, layer, hash, color)
|
|
end
|
|
if not participants[clientID] then return end
|
|
if not levelloop.textures[hash] then error("Failed to find hash!") return end
|
|
if not levelloop.textures[hash].image then
|
|
levelloop.textures[hash].image = love.graphics.newImage(levelloop.textures[hash].data)
|
|
end
|
|
love.graphics.setCanvas(levelloop.Canvas[layer])
|
|
love.graphics.setBlendMode("alpha")
|
|
utils.color_push()
|
|
love.graphics.setColor(color)
|
|
love.graphics.draw(levelloop.textures[hash].image, x, y)
|
|
utils.color_pop()
|
|
love.graphics.setCanvas()
|
|
end
|
|
|
|
|
|
commands.deleteTexture = function(clientID, x, y, width, height, layer)
|
|
if SERVER then
|
|
broadcast(clientID, "deleteTexture", x, y, width, height, layer)
|
|
end
|
|
if not participants[clientID] then return end
|
|
love.graphics.setCanvas(levelloop.Canvas[layer])
|
|
love.graphics.setBlendMode("replace")
|
|
utils.color_push()
|
|
love.graphics.setColor(0,0,0,0)
|
|
love.graphics.rectangle("fill", x, y, width, height)
|
|
utils.color_pop()
|
|
love.graphics.setBlendMode("alpha")
|
|
love.graphics.setCanvas()
|
|
end
|
|
|
|
|
|
commands.fillCanvas = function(clientID, layer, hash, color)
|
|
if SERVER then
|
|
color.nwType = "color"
|
|
broadcast(clientID, "fillCanvas", layer, hash, color)
|
|
end
|
|
if not participants[clientID] then return end
|
|
|
|
love.graphics.setCanvas(levelloop.Canvas[layer])
|
|
love.graphics.clear()
|
|
if not levelloop.textures[hash] then error("Failed to find hash!") return end
|
|
if not levelloop.textures[hash].image then
|
|
levelloop.textures[hash].image = love.graphics.newImage(levelloop.textures[hash].data)
|
|
end
|
|
utils.color_push()
|
|
love.graphics.setColor(color)
|
|
if not levelloop.textures[hash].image then
|
|
love.graphics.newImage(levelloop.textures[hash].data)
|
|
end
|
|
for x = 0, levelloop.world.x -levelloop.textures[hash].image:getPixelWidth(),
|
|
levelloop.textures[hash].image:getPixelWidth() do
|
|
for y = 0, levelloop.world.y -levelloop.textures[hash].image:getPixelHeight(),
|
|
levelloop.textures[hash].image:getPixelHeight() do
|
|
love.graphics.draw(levelloop.textures[hash].image, x, y)
|
|
end
|
|
end
|
|
|
|
utils.color_pop()
|
|
love.graphics.setCanvas()
|
|
end
|
|
|
|
|
|
commands.clearCanvas = function(clientID)
|
|
if SERVER then
|
|
broadcast(clientID, "clearCanvas")
|
|
end
|
|
love.graphics.setCanvas(levelloop.Canvas.fg)
|
|
love.graphics.clear()
|
|
love.graphics.setCanvas(levelloop.Canvas.bg)
|
|
love.graphics.clear()
|
|
love.graphics.setCanvas(levelloop.Canvas.dbg)
|
|
love.graphics.clear()
|
|
love.graphics.setCanvas()
|
|
levelloop.Canvas.physics = {}
|
|
end
|
|
end
|