poppy-client/shared/commands.lua

109 lines
3.3 KiB
Lua
Raw Permalink Normal View History

2022-08-04 19:06:21 +00:00
local player = require("lua.player")
local utils = require("shared.utils")
return function(commands)
2024-02-25 20:48:04 +00:00
commands.moveUpdate = function(clientID, x, y, speedx, speedy)
2022-12-17 16:22:46 +00:00
if SERVER then
2024-02-25 20:48:04 +00:00
broadcast(clientID, "moveUpdate", x, y, speedx, speedy)
2022-12-17 16:22:46 +00:00
end
if not participants[clientID] then return end
2022-08-04 19:06:21 +00:00
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
2022-08-04 19:06:21 +00:00
end
2024-02-25 20:48:04 +00:00
commands.moveFlying = function(clientID, flying)
2022-12-12 14:25:03 +00:00
if SERVER then
2024-02-25 20:48:04 +00:00
broadcast(clientID, "moveFlying", flying)
2022-12-12 14:25:03 +00:00
end
2022-12-17 16:22:46 +00:00
if not participants[clientID] then return end
2024-02-25 20:48:04 +00:00
participants[clientID].flying = flying
2022-10-09 10:51:38 +00:00
end
2022-10-10 17:46:27 +00:00
2022-08-04 19:06:21 +00:00
2024-02-25 20:48:04 +00:00
commands.drawTexture = function(clientID, x, y, layer, hash, color)
2022-12-17 16:22:46 +00:00
if SERVER then
2024-02-25 20:48:04 +00:00
color.nwType = "color"
broadcast(clientID, "drawTexture", x, y, layer, hash, color)
end
2022-12-17 16:22:46 +00:00
if not participants[clientID] then return end
2022-12-04 10:08:48 +00:00
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()
2024-02-25 20:48:04 +00:00
love.graphics.setColor(color)
2022-12-04 10:08:48 +00:00
love.graphics.draw(levelloop.textures[hash].image, x, y)
utils.color_pop()
love.graphics.setCanvas()
end
2022-08-04 19:06:21 +00:00
2024-02-25 20:48:04 +00:00
commands.deleteTexture = function(clientID, x, y, width, height, layer)
2022-12-17 16:22:46 +00:00
if SERVER then
2024-02-25 20:48:04 +00:00
broadcast(clientID, "deleteTexture", x, y, width, height, layer)
end
2022-12-17 16:22:46 +00:00
if not participants[clientID] then return end
2022-12-04 10:08:48 +00:00
love.graphics.setCanvas(levelloop.Canvas[layer])
love.graphics.setBlendMode("replace")
2022-10-09 10:51:38 +00:00
utils.color_push()
love.graphics.setColor(0,0,0,0)
love.graphics.rectangle("fill", x, y, width, height)
2022-10-09 10:51:38 +00:00
utils.color_pop()
love.graphics.setBlendMode("alpha")
love.graphics.setCanvas()
end
2022-08-04 19:06:21 +00:00
2022-12-04 10:08:48 +00:00
2024-02-25 20:48:04 +00:00
commands.fillCanvas = function(clientID, layer, hash, color)
2022-12-17 16:22:46 +00:00
if SERVER then
2024-02-25 20:48:04 +00:00
color.nwType = "color"
broadcast(clientID, "fillCanvas", layer, hash, color)
2022-12-17 16:22:46 +00:00
end
2022-12-04 10:08:48 +00:00
if not participants[clientID] then return end
love.graphics.setCanvas(levelloop.Canvas[layer])
love.graphics.clear()
2022-12-04 10:08:48 +00:00
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()
2024-02-25 20:48:04 +00:00
love.graphics.setColor(color)
2022-12-17 16:22:46 +00:00
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
2022-12-04 10:08:48 +00:00
utils.color_pop()
love.graphics.setCanvas()
2022-12-12 14:25:03 +00:00
end
commands.clearCanvas = function(clientID)
2022-12-17 16:22:46 +00:00
if SERVER then
broadcast(clientID, "clearCanvas")
end
2022-12-12 14:25:03 +00:00
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 = {}
2022-10-10 17:46:27 +00:00
end
2022-08-04 19:06:21 +00:00
end