mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-16 13:23:46 +03:00
Upload
This commit is contained in:
143
lua/imagetool/cl_hooks.lua
Normal file
143
lua/imagetool/cl_hooks.lua
Normal file
@@ -0,0 +1,143 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
Selenter - https://steamcommunity.com/id/selenter
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
|
||||
-- Создаем конвар с настройкой прорисовки
|
||||
ImageTool.dist = CreateClientConVar("imagetool_dist", 1000, true, nil, "Change distance of drawing pictures")
|
||||
|
||||
-- Менюшка с настройкой
|
||||
hook.Add( "PopulateToolMenu", "ImageTool.Menu", function()
|
||||
local l = "imagetool_"
|
||||
|
||||
spawnmenu.AddToolMenuOption("Options", "Image Tool", "imagetoolsettings", "Image Tool Settings", nil, nil, function(CPanel)
|
||||
CPanel:ClearControls()
|
||||
|
||||
CPanel:AddControl("Header",{
|
||||
Description = "In this menu you can change the settings for the ImageTool."
|
||||
})
|
||||
|
||||
CPanel:AddControl("Slider", {
|
||||
Label = "Draw distance:",
|
||||
Command = "imagetool_dist",
|
||||
Min = 0,
|
||||
Max = 10000
|
||||
})
|
||||
|
||||
local SettingsReset = vgui.Create("DButton")
|
||||
SettingsReset:SetText("Return to default settings")
|
||||
SettingsReset.DoClick = function()
|
||||
RunConsoleCommand(l .. "dist", ImageTool.dist:GetDefault())
|
||||
end
|
||||
CPanel:AddPanel(SettingsReset)
|
||||
|
||||
local HistoryReset = vgui.Create("DButton")
|
||||
HistoryReset:SetText("Clear the history")
|
||||
HistoryReset.DoClick = function()
|
||||
ImageTool:SaveHistory({})
|
||||
|
||||
timer.Simple(0.5, function()
|
||||
RunConsoleCommand("spawnmenu_reload")
|
||||
end)
|
||||
|
||||
LocalPlayer():ChatPrint(ImageTool.prefix .. " You have successfully cleared your history!")
|
||||
end
|
||||
CPanel:AddPanel(HistoryReset)
|
||||
|
||||
local ImageReset = vgui.Create("DButton")
|
||||
ImageReset:SetText("Delete all pictures on the map")
|
||||
ImageReset.DoClick = function()
|
||||
RunConsoleCommand(l .. "delete_all")
|
||||
end
|
||||
CPanel:AddPanel(ImageReset)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Получаем каждые 0.5 секунд все картинки возле игрока
|
||||
local showImagesList = {}
|
||||
local cache = {}
|
||||
timer.Create("ImageTool:Update", 0.5, 0, function()
|
||||
local client = LocalPlayer()
|
||||
if !IsValid(client) then return end
|
||||
|
||||
showImagesList = {}
|
||||
|
||||
for id, array in pairs(ImageTool:GetImages()) do
|
||||
-- Удаляем картинки которые слишком далеко от игрока
|
||||
if client:GetPos():DistToSqr(array.position) >= ImageTool.dist:GetInt() * 15000 then
|
||||
cache[id] = nil
|
||||
continue
|
||||
end
|
||||
|
||||
showImagesList[id] = array
|
||||
end
|
||||
end)
|
||||
|
||||
-- Удаляем из кеша картинки которые не прогружены
|
||||
timer.Create("ImageTool:Cleaner", 1, 0, function()
|
||||
for id in pairs(cache) do
|
||||
if !showImagesList[id] then
|
||||
cache[id] = nil
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function caching(id, array)
|
||||
cache[id] = array
|
||||
end
|
||||
|
||||
local function thread()
|
||||
local showImages
|
||||
|
||||
while true do
|
||||
showImages = showImagesList
|
||||
|
||||
if !next(showImages) then
|
||||
coroutine.yield()
|
||||
else
|
||||
for id, array in pairs(showImages) do
|
||||
coroutine.yield()
|
||||
|
||||
caching(id, array)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Кешируем по кадрово информацию о картинках
|
||||
local co
|
||||
hook.Add("Think", "ImageTool.Think", function()
|
||||
if !co or !coroutine.resume(co) then
|
||||
co = coroutine.create(thread)
|
||||
coroutine.resume(co)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Отображение картинок
|
||||
hook.Add("PostDrawTranslucentRenderables", "ImageTool.PostDrawTranslucentRenderables", function()
|
||||
-- Отрисовка всех картинки в мире
|
||||
for k, v in pairs(cache) do
|
||||
ImageTool:Start3D2D(v)
|
||||
end
|
||||
|
||||
ImageTool:DrawImageTool() -- Тул-Ган отрисовка
|
||||
end)
|
||||
293
lua/imagetool/cl_image.lua
Normal file
293
lua/imagetool/cl_image.lua
Normal file
@@ -0,0 +1,293 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
Selenter - https://steamcommunity.com/id/selenter
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
-- Создаем файл с конфигом, если его нету
|
||||
if !file.Exists(ImageTool.path .. "/" .. ImageTool.history, "DATA") then
|
||||
file.Write(ImageTool.path .. "/" .. ImageTool.history, "[]")
|
||||
end
|
||||
|
||||
|
||||
-- Получаем историю
|
||||
function ImageTool:GetHistory()
|
||||
local data = {}
|
||||
|
||||
if file.Exists(ImageTool.path .. "/" .. ImageTool.history, "DATA") then
|
||||
local info = file.Read(ImageTool.path .. "/" .. ImageTool.history)
|
||||
|
||||
data = util.JSONToTable(info)
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
-- Сохраняем историю
|
||||
function ImageTool:SaveHistory(data)
|
||||
data = util.TableToJSON(data)
|
||||
|
||||
file.Write(ImageTool.path .. "/" .. ImageTool.history, data)
|
||||
end
|
||||
|
||||
-- Если картинка находится в кеше, то возвращаем его
|
||||
function ImageTool:FindInCache(data)
|
||||
if self.cacheMaterials[data] then
|
||||
return self.cacheMaterials[data]
|
||||
end
|
||||
end
|
||||
|
||||
-- Получаем картинку по uniqueID
|
||||
function ImageTool:GetImage(data)
|
||||
local path = Format("%s/%s", self.path, game.GetMap())
|
||||
local filename = data .. ".png"
|
||||
|
||||
local cache = self:FindInCache(data)
|
||||
if cache then
|
||||
return cache
|
||||
end
|
||||
|
||||
return Material("data/" .. path .. "/" .. filename)
|
||||
end
|
||||
|
||||
-- Скачиваем картинку
|
||||
function ImageTool:DownloadImage(path, data)
|
||||
if !self.requestList[data] or CurTime() >= self.requestList[data] then
|
||||
if self:IsUsesTool(LocalPlayer()) then
|
||||
LocalPlayer():ChatPrint(self.prefix .. " Download the picture: " .. data)
|
||||
end
|
||||
|
||||
-- Запрос на сайт
|
||||
http.Fetch(data, function(body, size, headers)
|
||||
local extension = self:CheckExtensionImage(body, headers)
|
||||
if !extension then return end
|
||||
|
||||
file.Write(path, body)
|
||||
end)
|
||||
|
||||
self.requestList[data] = CurTime() + 10
|
||||
end
|
||||
end
|
||||
|
||||
-- Грузим картинку из URL
|
||||
function ImageTool:LoadingURL(data)
|
||||
local uniqueID = util.CRC(data) -- Уникальный ID картинки
|
||||
|
||||
-- Если картинка уже закешированна, то возвращаем ее
|
||||
if self:FindInCache(uniqueID) then
|
||||
return self:FindInCache(uniqueID)
|
||||
end
|
||||
|
||||
local path = Format("%s/%s", self.path, game.GetMap())
|
||||
local filename = uniqueID .. ".png"
|
||||
|
||||
-- Пытаемся найти картинку в дате
|
||||
if file.Exists(path .. "/" .. filename, "DATA") then
|
||||
local mat = self:GetImage(uniqueID)
|
||||
|
||||
if mat and !mat:IsError() then
|
||||
if self:IsUsesTool(LocalPlayer()) then
|
||||
LocalPlayer():ChatPrint(self.prefix .. " Image has been uploaded successfully: " .. data)
|
||||
end
|
||||
|
||||
self.cacheMaterials[uniqueID] = mat -- Сохраняем картинку в Кеше
|
||||
|
||||
return mat
|
||||
end
|
||||
|
||||
if !self.notifyErr[data] or CurTime() >= self.notifyErr[data] then
|
||||
if self:IsUsesTool(LocalPlayer()) then
|
||||
LocalPlayer():ChatPrint(self.prefix .. " It is not possible to upload a picture: " .. data .. ". Repeated request in 5 seconds!")
|
||||
end
|
||||
|
||||
self.notifyErr[data] = CurTime() + 5
|
||||
|
||||
-- Прерываем функцию и качаем картинку
|
||||
return self:DownloadImage(path .. "/" .. filename, data)
|
||||
end
|
||||
end
|
||||
|
||||
-- Если не нашли картинку, то качаем ее
|
||||
self:DownloadImage(path .. "/" .. filename, data)
|
||||
end
|
||||
|
||||
-- Рисуем выбранную картинку в TOOL-е
|
||||
function ImageTool:DrawImageTool()
|
||||
local client = LocalPlayer()
|
||||
|
||||
-- Если у нас в руках не ТулГан, то прерываем функцию
|
||||
local data = self:GetToolData(client)
|
||||
if !data then return end
|
||||
|
||||
self:Start3D2D(data)
|
||||
end
|
||||
|
||||
local function clear()
|
||||
if IsValid(ImageTool.historyPanel.List) then
|
||||
ImageTool.historyPanel.List:Remove()
|
||||
end
|
||||
|
||||
local historylist = ImageTool.historyPanel:GetChildren()[1]
|
||||
|
||||
for k, v in ipairs(historylist:GetChildren()) do
|
||||
if v.image then
|
||||
v:Remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local scale = 0.2
|
||||
local function set_size(panel1, panel2, mat)
|
||||
if panel1.setsize then return end
|
||||
|
||||
local w, h = mat:Width() * scale, mat:Height() * scale
|
||||
|
||||
panel1:SetSize(w, h)
|
||||
panel2:SetSize(w, h)
|
||||
|
||||
panel1.setsize = true
|
||||
end
|
||||
|
||||
local function drawing(url, w, h, panel1, panel2)
|
||||
local imageMaterial = ImageTool:LoadingURL(url)
|
||||
|
||||
if type(imageMaterial) == "IMaterial" and !imageMaterial:IsError() then
|
||||
set_size(panel1, panel2, imageMaterial)
|
||||
|
||||
surface.SetDrawColor(255, 255, 255)
|
||||
surface.SetMaterial(imageMaterial)
|
||||
surface.DrawTexturedRect(5, 5, w - 10, h - 10)
|
||||
else
|
||||
local alpha, dotStr = ImageTool:Anim()
|
||||
|
||||
surface.SetDrawColor(255, alpha, 255)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
draw.DrawText("Loading" .. dotStr, "Default", w / 2, h / 2 - 10, Color(alpha, 0, 0), TEXT_ALIGN_CENTER)
|
||||
end
|
||||
end
|
||||
|
||||
local function derma_menu(image, id, url)
|
||||
local menu = DermaMenu()
|
||||
menu:AddOption("Replace URL", function()
|
||||
local l = "imagetool_"
|
||||
|
||||
RunConsoleCommand(l .. "url", url)
|
||||
end):SetIcon("icon16/disconnect.png")
|
||||
|
||||
menu:AddOption("Copy URL", function()
|
||||
SetClipboardText(url)
|
||||
end):SetIcon("icon16/disk.png")
|
||||
|
||||
menu:AddOption("Remove", function()
|
||||
local history = ImageTool:GetHistory() or {}
|
||||
table.remove(history, id)
|
||||
|
||||
ImageTool:SaveHistory(history)
|
||||
|
||||
if IsValid(image) then
|
||||
image:Remove()
|
||||
end
|
||||
end):SetIcon("icon16/delete.png")
|
||||
menu:Open()
|
||||
end
|
||||
|
||||
-- Грузим историю
|
||||
function ImageTool:LoadingHistory()
|
||||
local panel = ImageTool.historyPanel
|
||||
if !IsValid(panel) then return end
|
||||
|
||||
clear()
|
||||
|
||||
local history = ImageTool:GetHistory() or {}
|
||||
for id, url in SortedPairs(history, true) do
|
||||
local image = panel:Add("Panel")
|
||||
image.image = true
|
||||
image:SetTall(100)
|
||||
image:Dock(TOP)
|
||||
image:DockMargin(2, 2, 2, 2)
|
||||
|
||||
local button = image:Add("DButton")
|
||||
button:SetText("")
|
||||
button:SetSize(100, 100)
|
||||
button:Dock(LEFT)
|
||||
button.alpha = 0
|
||||
button.Paint = function(this, w, h)
|
||||
this.alpha = Lerp(FrameTime() * 10, this.alpha, this:IsHovered() and 200 or 0)
|
||||
|
||||
surface.SetDrawColor(255, 61, 96, this.alpha)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
drawing(url, w, h, image, this)
|
||||
|
||||
surface.SetDrawColor(255, 61, 96, 150)
|
||||
surface.DrawOutlinedRect(0, 0, w, h, 1)
|
||||
end
|
||||
button.DoClick = function()
|
||||
derma_menu(image, id, url)
|
||||
end
|
||||
end
|
||||
|
||||
panel.List = ListImage
|
||||
|
||||
panel:Rebuild()
|
||||
end
|
||||
|
||||
-- Чото типо анимации)
|
||||
function ImageTool:Anim()
|
||||
local systime = SysTime()
|
||||
local alpha = math.sin(systime * 2) * 255
|
||||
local dotA = math.sin(systime * 1) * 255
|
||||
local dot = math.floor(math.abs(dotA) * 0.015)
|
||||
local dotStr = string.rep(".", dot + 1)
|
||||
|
||||
return alpha, dotStr
|
||||
end
|
||||
|
||||
-- Запускаем cam3d2d для отрисовки картинки
|
||||
function ImageTool:Start3D2D(data)
|
||||
if !data then return end
|
||||
|
||||
local alpha = tonumber(data.alpha) or 255
|
||||
local scale = (tonumber(data.scale) or 40) / 100
|
||||
local brightness = tonumber(data.brightness) or 255
|
||||
local imageMaterial = self:LoadingURL(data.url)
|
||||
|
||||
local w, h = tonumber(data.width), tonumber(data.height)
|
||||
if !isnumber(w) or !isnumber(h) then return end -- number expected, got string
|
||||
|
||||
-- Рисуем
|
||||
cam.Start3D2D(data.position, data.angles, scale)
|
||||
render.PushFilterMin(TEXFILTER.ANISOTROPIC)
|
||||
render.PushFilterMag(TEXFILTER.ANISOTROPIC)
|
||||
if type(imageMaterial) == "IMaterial" and !imageMaterial:IsError() then -- Проверяем загрузилась ли картинка
|
||||
surface.SetDrawColor(brightness, brightness, brightness, alpha)
|
||||
surface.SetMaterial(imageMaterial)
|
||||
surface.DrawTexturedRect(0, 0, w, h)
|
||||
else
|
||||
local alphaStr, dotStr = ImageTool:Anim()
|
||||
|
||||
surface.SetDrawColor(255, alphaStr, 255)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
draw.DrawText("Loading" .. dotStr, "Default", w / 2, h / 2 - 10, Color(alphaStr, 0, 0), TEXT_ALIGN_CENTER)
|
||||
end
|
||||
render.PopFilterMag()
|
||||
render.PopFilterMin()
|
||||
cam.End3D2D()
|
||||
end
|
||||
80
lua/imagetool/cl_net.lua
Normal file
80
lua/imagetool/cl_net.lua
Normal file
@@ -0,0 +1,80 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
Selenter - https://steamcommunity.com/id/selenter
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
|
||||
-- Получаем новую картинку
|
||||
net.Receive("image.SendImage", function()
|
||||
local length = net.ReadUInt(32)
|
||||
local id = net.ReadUInt(32)
|
||||
local data = net.ReadData(length)
|
||||
|
||||
local uncompressed = util.Decompress(data)
|
||||
local info = util.JSONToTable(uncompressed)
|
||||
|
||||
ImageTool.imageList[id] = info -- Добавляем
|
||||
|
||||
if ImageTool:IsUsesTool(LocalPlayer()) then
|
||||
LocalPlayer():ChatPrint(ImageTool.prefix .. " Image was added successfully! (ID: " .. id .. ")")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Удаляем картинку
|
||||
net.Receive("image.RemoveImage", function()
|
||||
local id = net.ReadUInt(32)
|
||||
|
||||
ImageTool.imageList[id] = nil -- Удаляем
|
||||
|
||||
if ImageTool:IsUsesTool(LocalPlayer()) then
|
||||
LocalPlayer():ChatPrint(ImageTool.prefix .. " Image has been successfully deleted! (ID: " .. id .. ")")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Удаляем все картинки
|
||||
net.Receive("image.RemoveImageAll", function()
|
||||
for id in pairs(ImageTool:GetImages()) do
|
||||
ImageTool.imageList[id] = nil -- Удаляем
|
||||
end
|
||||
|
||||
if ImageTool:IsUsesTool(LocalPlayer()) then
|
||||
LocalPlayer():ChatPrint(ImageTool.prefix .. " All pictures have been removed from the world!")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Сохраняем картинку в истории
|
||||
net.Receive("image.SaveImage", function()
|
||||
local url = net.ReadString()
|
||||
|
||||
local history = ImageTool:GetHistory() or {}
|
||||
|
||||
-- Если такой url уже есть в истории, то не сохраняем
|
||||
for k, v in ipairs(history) do
|
||||
if v == url then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(history, url)
|
||||
ImageTool:SaveHistory(history)
|
||||
|
||||
ImageTool:LoadingHistory()
|
||||
end)
|
||||
70
lua/imagetool/sh_batch.lua
Normal file
70
lua/imagetool/sh_batch.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
Selenter - https://steamcommunity.com/id/selenter
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
|
||||
ImageTool = ImageTool or {}
|
||||
ImageTool._INFORMATION = ImageTool._INFORMATION or {
|
||||
_TITLE = "Image Tool",
|
||||
_DESCRIPTION = "This system allows you to create Pictures on your map.",
|
||||
_AUTHOR = "Selenter",
|
||||
_VERSION = 0.1
|
||||
}
|
||||
|
||||
ImageTool.path = "imagetool" -- путь к папке хранения
|
||||
ImageTool.prefix = "[ImageTool]" -- Префикс для сообщений в чате
|
||||
|
||||
ImageTool.cacheMaterials = ImageTool.cacheMaterials or {} -- Закешированные материалы
|
||||
ImageTool.requestList = ImageTool.requestList or {} -- Все запросы на сайты
|
||||
ImageTool.notifyErr = ImageTool.notifyErr or {} -- Сайты которые выдают ошибки
|
||||
ImageTool.imageList = ImageTool.imageList or {} -- Список картинок которые отображаются в мире
|
||||
|
||||
ImageTool.config = "config.txt" -- файл с конфигом
|
||||
ImageTool.history = "history.txt" -- файл с иторией
|
||||
|
||||
-- Создаем каталог с картинками
|
||||
file.CreateDir(ImageTool.path)
|
||||
file.CreateDir(ImageTool.path .. "/" .. game.GetMap())
|
||||
|
||||
|
||||
|
||||
-- Инклаидаем остальные файлы
|
||||
do
|
||||
if SERVER then
|
||||
AddCSLuaFile(ImageTool.path .. "/cl_net.lua")
|
||||
AddCSLuaFile(ImageTool.path .. "/cl_image.lua")
|
||||
AddCSLuaFile(ImageTool.path .. "/cl_hooks.lua")
|
||||
elseif CLIENT then
|
||||
include(ImageTool.path .. "/cl_net.lua")
|
||||
include(ImageTool.path .. "/cl_image.lua")
|
||||
include(ImageTool.path .. "/cl_hooks.lua")
|
||||
end
|
||||
|
||||
include(ImageTool.path .. "/sh_image.lua")
|
||||
AddCSLuaFile(ImageTool.path .. "/sh_image.lua")
|
||||
|
||||
if SERVER then
|
||||
include(ImageTool.path .. "/sv_net.lua")
|
||||
include(ImageTool.path .. "/sv_image.lua")
|
||||
include(ImageTool.path .. "/sv_hooks.lua")
|
||||
end
|
||||
end
|
||||
106
lua/imagetool/sh_image.lua
Normal file
106
lua/imagetool/sh_image.lua
Normal file
@@ -0,0 +1,106 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
Selenter - https://steamcommunity.com/id/selenter
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
-- Допустимые для загрузки расширения
|
||||
ImageTool.ValidExtension = {
|
||||
realm = {
|
||||
["png"] = true,
|
||||
["jpg"] = true,
|
||||
["jfif"] = true
|
||||
},
|
||||
content = {
|
||||
["image/png"] = true,
|
||||
["image/jpeg"] = true
|
||||
}
|
||||
}
|
||||
|
||||
-- Использует ли пользователь Image Tool
|
||||
function ImageTool:IsUsesTool(client)
|
||||
if !IsValid(client) then return false end
|
||||
|
||||
local weapon = client:GetActiveWeapon()
|
||||
if !IsValid(weapon) then return false end
|
||||
|
||||
local class = weapon:GetClass()
|
||||
if class != "gmod_tool" then return false end
|
||||
|
||||
local tool = client:GetTool() and client:GetTool().Name or nil
|
||||
if tool != "Image Tool" then return false end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- Получаем информацию о Image Tool
|
||||
function ImageTool:GetToolData(client)
|
||||
if !self:IsUsesTool(client) then return end
|
||||
|
||||
local trace = client:GetEyeTrace()
|
||||
local position = trace.HitPos
|
||||
local angles = trace.HitNormal:Angle()
|
||||
angles:RotateAroundAxis(angles:Up(), 90)
|
||||
angles:RotateAroundAxis(angles:Forward(), 90)
|
||||
|
||||
local tool = client:GetTool()
|
||||
|
||||
local imageURL = tool:GetClientInfo("url")
|
||||
local imageWidth = tool:GetClientInfo("width")
|
||||
local imageHeight = tool:GetClientInfo("height")
|
||||
local imageScale = tool:GetClientInfo("scale")
|
||||
local imageBrightness = tool:GetClientInfo("brightness")
|
||||
local imageAlpha = tool:GetClientInfo("alpha")
|
||||
|
||||
imageURL = imageURL:gsub("cdn.discordapp.com", "media.discordapp.net") -- Fix Discord Cloudfire
|
||||
|
||||
local data = {
|
||||
url = imageURL,
|
||||
width = imageWidth,
|
||||
height = imageHeight,
|
||||
scale = imageScale,
|
||||
brightness = imageBrightness,
|
||||
position = position + angles:Up() * 0.5,
|
||||
angles = angles,
|
||||
alpha = imageAlpha
|
||||
}
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
-- Проверка на валидность на сайте картинки
|
||||
function ImageTool:CheckExtensionImage(body, header)
|
||||
local content = header["Content-Type"]
|
||||
local extension = self.ValidExtension
|
||||
|
||||
local urlLowerPNG = string.lower(string.sub(body, 2, 4))
|
||||
local urlLowerJPEG = string.lower(string.sub(body, 7, 10))
|
||||
|
||||
if extension.realm[urlLowerPNG] or extension.realm[urlLowerJPEG] or extension.content[content] then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- Получаем все картинки на карте
|
||||
function ImageTool:GetImages()
|
||||
return ImageTool.imageList or {}
|
||||
end
|
||||
35
lua/imagetool/sv_hooks.lua
Normal file
35
lua/imagetool/sv_hooks.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
Selenter - https://steamcommunity.com/id/selenter
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
|
||||
-- Отправляем только что подключившимуся игроку все картинки на карте
|
||||
hook.Add("PlayerInitialSpawn", "image.PlayerInitialSpawn", function(client)
|
||||
local config = ImageTool:GetConfig() or {}
|
||||
local map = game.GetMap()
|
||||
|
||||
config[map] = config[map] or {}
|
||||
|
||||
for k, v in pairs(config[map]) do
|
||||
ImageTool:SendImage(client, k, v)
|
||||
end
|
||||
end)
|
||||
137
lua/imagetool/sv_image.lua
Normal file
137
lua/imagetool/sv_image.lua
Normal file
@@ -0,0 +1,137 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
-- Создаем файл с конфигом, если его нету
|
||||
if !file.Exists(ImageTool.path .. "/" .. ImageTool.config, "DATA") then
|
||||
file.Write(ImageTool.path .. "/" .. ImageTool.config, "{}")
|
||||
end
|
||||
|
||||
|
||||
-- Получаем конфиг
|
||||
function ImageTool:GetConfig()
|
||||
local data = {}
|
||||
|
||||
if file.Exists(ImageTool.path .. "/" .. ImageTool.config, "DATA") then
|
||||
local info = file.Read(ImageTool.path .. "/" .. ImageTool.config)
|
||||
|
||||
data = util.JSONToTable(info)
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
-- Отправляем картинку игроку/игрокам
|
||||
function ImageTool:SendImage(client, id, data)
|
||||
data = util.TableToJSON(data)
|
||||
|
||||
local compressed = util.Compress(data)
|
||||
local length = compressed:len()
|
||||
|
||||
net.Start("image.SendImage")
|
||||
net.WriteUInt(length, 32)
|
||||
net.WriteUInt(id, 32)
|
||||
net.WriteData(compressed, length)
|
||||
|
||||
if IsValid(client) then
|
||||
net.Send(client)
|
||||
else
|
||||
net.Broadcast()
|
||||
end
|
||||
end
|
||||
|
||||
-- Сохраняем конфиг
|
||||
function ImageTool:SaveConfig(data)
|
||||
data = util.TableToJSON(data)
|
||||
|
||||
file.Write(ImageTool.path .. "/" .. ImageTool.config, data)
|
||||
end
|
||||
|
||||
-- Добавляем новую картинку в мир
|
||||
function ImageTool:AddImage(data)
|
||||
if !data then return end
|
||||
|
||||
local config = self:GetConfig() or {}
|
||||
local map = game.GetMap()
|
||||
|
||||
config[map] = config[map] or {}
|
||||
config[map][#config[map] + 1] = data -- Записываем
|
||||
|
||||
self:SaveConfig(config) -- Сохраняем конфиг
|
||||
self:SendImage(nil, #config[map], data) -- Передаем всем игрокам данную картинку
|
||||
end
|
||||
|
||||
-- Удаляем картинку из мира
|
||||
function ImageTool:RemoveImage(data)
|
||||
if !data then return end
|
||||
|
||||
local pos = data.position
|
||||
local config = ImageTool:GetConfig() or {}
|
||||
local map = game.GetMap()
|
||||
|
||||
config[map] = config[map] or {}
|
||||
|
||||
-- Находим картинку с наименьшей дистанцией
|
||||
local images = {}
|
||||
for k, v in pairs(config[map]) do
|
||||
if pos:Distance(v.position) <= 200 then
|
||||
local dist = math.floor(pos:Distance(v.position))
|
||||
|
||||
images[dist] = k
|
||||
end
|
||||
end
|
||||
|
||||
local imagesPack = {}
|
||||
for k, v in pairs(images) do
|
||||
if !isnumber(k) then continue end -- number expected err
|
||||
|
||||
imagesPack[#imagesPack + 1] = k
|
||||
end
|
||||
|
||||
if #imagesPack <= 0 then return end
|
||||
|
||||
local min = math.min(unpack(imagesPack))
|
||||
local imageMin = images[min]
|
||||
|
||||
-- Если нашли — удаляем
|
||||
if imageMin and config[map][imageMin] then
|
||||
config[map][imageMin] = nil
|
||||
|
||||
self:SaveConfig(config)
|
||||
|
||||
net.Start("image.RemoveImage")
|
||||
net.WriteUInt(imageMin, 32)
|
||||
net.Broadcast()
|
||||
end
|
||||
end
|
||||
|
||||
-- Удаляем все картинки из мира
|
||||
function ImageTool:RemoveImageAll()
|
||||
local config = ImageTool:GetConfig() or {}
|
||||
local map = game.GetMap()
|
||||
|
||||
config[map] = {}
|
||||
|
||||
ImageTool:SaveConfig(config)
|
||||
|
||||
net.Start("image.RemoveImageAll")
|
||||
net.Broadcast()
|
||||
end
|
||||
38
lua/imagetool/sv_net.lua
Normal file
38
lua/imagetool/sv_net.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
--[[
|
||||
© AsterionStaff 2022.
|
||||
This script was created from the developers of the AsterionTeam.
|
||||
You can get more information from one of the links below:
|
||||
Site - https://asterion.games
|
||||
Discord - https://discord.gg/CtfS8r5W3M
|
||||
|
||||
developer(s):
|
||||
Selenter - https://steamcommunity.com/id/selenter
|
||||
|
||||
——— Chop your own wood and it will warm you twice.
|
||||
]]--
|
||||
|
||||
|
||||
util.AddNetworkString("image.SendImage") -- net с отправкой картинки
|
||||
util.AddNetworkString("image.RemoveImage") -- net с удалением картинки
|
||||
util.AddNetworkString("image.RemoveImageAll") -- net с удалением всех картинок
|
||||
util.AddNetworkString("image.SaveImage") -- net с сохранением картинки
|
||||
|
||||
|
||||
-- Команда которая удаляет все картинки с карты
|
||||
concommand.Add("imagetool_delete_all", function(client)
|
||||
if !client:IsSuperAdmin() then
|
||||
return client:ChatPrint(ImageTool.prefix .. " You don't have access!")
|
||||
end
|
||||
|
||||
ImageTool:RemoveImageAll()
|
||||
end)
|
||||
Reference in New Issue
Block a user