Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
LiddulBOFH committed Jun 10, 2024
2 parents 2f39f97 + aa8e199 commit dd9dcd1
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 0 deletions.
131 changes: 131 additions & 0 deletions lua/entities/acf_rack/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,136 @@
local Clock = ACF.Utilities.Clock
local Queued = {}

include("shared.lua")

language.Add("Cleanup_acf_rack", "ACF Racks")
language.Add("Cleaned_acf_rack", "Cleaned up all ACF Racks")
language.Add("SBoxLimit__acf_rack", "You've hit the ACF Rack limit!")

do -- Overlay/networking
function ENT:RequestRackInfo()
if Queued[self] then return end

Queued[self] = true

timer.Simple(5, function() Queued[self] = nil end)

net.Start("ACF.RequestRackInfo")
net.WriteEntity(self)
net.SendToServer()
end

net.Receive("ACF.RequestRackInfo",function()
local Rack = net.ReadEntity()
if not IsValid(Rack) then return end

Queued[Rack] = nil

local RackInfo = util.JSONToTable(net.ReadString())
local CrateInfo = util.JSONToTable(net.ReadString())

if RackInfo.HasComputer then
local Computer = Entity(RackInfo.Computer)
if IsValid(Computer) then
Rack.Computer = Computer
end
end

if RackInfo.HasRadar then
local Radar = Entity(RackInfo.Radar)
if IsValid(Radar) then
Rack.Radar = Radar
end
end

Rack.MountPoints = {}
if next(RackInfo.MountPoints) then
for _,T in ipairs(RackInfo.MountPoints) do
local Dir = Vector(1,0,0)
Dir:Rotate(T.Ang)
Rack.MountPoints[#Rack.MountPoints + 1] = {Index = T.Index, Pos = T.Pos, Dir = Dir}
end
end

local CrateEnts = {}
for _,E in ipairs(CrateInfo) do
local Crate = Entity(E)

if IsValid(Crate) then
local Col = ColorAlpha(Crate:GetColor(),25)
CrateEnts[#CrateEnts + 1] = {Ent = Crate, Col = Col}
end
end

Rack.Crates = CrateEnts
Rack.HasData = true
Rack.Age = Clock.CurTime + 5
end)

-- icon16/feed.png radar sprite
-- icon16/joystick.png controller sprite
local RadarSprite = Material("icon16/transmit.png")
local JoystickMat = Material("icon16/joystick.png")
local RadarColor = Color(255,255,0,25)
local ControllerColor = Color(0,255,0,25)

function ENT:DrawOverlay()
local SelfTbl = self:GetTable()

if not SelfTbl.HasData then
self:RequestRackInfo()
return
elseif Clock.CurTime > SelfTbl.Age then
self:RequestRackInfo()
end

if next(SelfTbl.Crates) then
for _,T in ipairs(SelfTbl.Crates) do
local E = T.Ent

if IsValid(E) then
render.DrawWireframeBox(E:GetPos(),E:GetAngles(),E:OBBMins(),E:OBBMaxs(),T.Col,true)
render.DrawBox(E:GetPos(),E:GetAngles(),E:OBBMins(),E:OBBMaxs(),T.Col)
end
end
end

if next(SelfTbl.MountPoints) then
for _,T in ipairs(SelfTbl.MountPoints) do
local Pos1 = self:LocalToWorld(T.Pos - T.Dir * 6)
local Pos2 = self:LocalToWorld(T.Pos + T.Dir * 6)
render.DrawBeam(Pos1, Pos2, 2, 0, 0, color_black)
render.DrawBeam(Pos1, Pos2, 1.5, 0, 0, color_white)
end

cam.Start2D()
for _,T in ipairs(SelfTbl.MountPoints) do
local Pos = self:LocalToWorld(T.Pos):ToScreen()
draw.SimpleTextOutlined("Mount " .. T.Index,"ACF_Title",Pos.x,Pos.y,color_white,TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,color_black)
end
cam.End2D()
end

if IsValid(SelfTbl.Radar) then
local Radar = SelfTbl.Radar
local RadPos, RadAng, OBBMin, OBBMax = Radar:GetPos(), Radar:GetAngles(), Radar:OBBMins(), Radar:OBBMaxs()
render.DrawWireframeBox(RadPos,RadAng,OBBMin,OBBMax,RadarColor,true)
render.DrawBox(RadPos,RadAng,OBBMin,OBBMax,RadarColor)

render.SetMaterial(RadarSprite)
render.DrawSprite(Radar:LocalToWorld(Radar:OBBCenter()), 12, 12, color_white)
end

render.SetColorMaterial()

if IsValid(SelfTbl.Computer) then
local Computer = SelfTbl.Computer
local ComPos, ComAng, OBBMin, OBBMax = Computer:GetPos(), Computer:GetAngles(), Computer:OBBMins(), Computer:OBBMaxs()
render.DrawWireframeBox(ComPos,ComAng,OBBMin,OBBMax,ControllerColor,true)
render.DrawBox(ComPos,ComAng,OBBMin,OBBMax,ControllerColor)

render.SetMaterial(JoystickMat)
render.DrawSprite(Computer:LocalToWorld(Computer:OBBCenter()), 12, 12, color_white)
end
end
end
39 changes: 39 additions & 0 deletions lua/entities/acf_rack/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,45 @@ do -- Duplicator Support -----------------------
end
end ---------------------------------------------

do -- Overlay/networking
util.AddNetworkString("ACF.RequestRackInfo")
net.Receive("ACF.RequestRackInfo",function(_,Ply)
local Rack = net.ReadEntity()
if not IsValid(Rack) then return end

local RackInfo = {}
local Crates = {}

if IsValid(Rack.Computer) then
RackInfo.HasComputer = true
RackInfo.Computer = Rack.Computer:EntIndex()
end

if IsValid(Rack.Radar) then
RackInfo.HasRadar = true
RackInfo.Radar = Rack.Radar:EntIndex()
end

RackInfo.MountPoints = {}

for _,Point in pairs(Rack.MountPoints) do
RackInfo.MountPoints[#RackInfo.MountPoints + 1] = {Pos = Point.Position, Ang = Point.Angle, Index = Point.Index}
end

if next(Rack.Crates) then
for Crate in pairs(Rack.Crates) do
Crates[#Crates + 1] = Crate:EntIndex()
end
end

net.Start("ACF.RequestRackInfo")
net.WriteEntity(Rack)
net.WriteString(util.TableToJSON(RackInfo))
net.WriteString(util.TableToJSON(Crates))
net.Send(Ply)
end)
end

do -- Misc -------------------------------------
local function GetPosition(Entity)
local PhysObj = Entity:GetPhysicsObject()
Expand Down
68 changes: 68 additions & 0 deletions lua/entities/acf_radar/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,73 @@
local Clock = ACF.Utilities.Clock
local Queued = {}

include ("shared.lua")

language.Add("Cleanup_acf_radar", "ACF Radars")
language.Add("Cleaned_acf_radar", "Cleaned up all ACF Radars")
language.Add("SBoxLimit__acf_radar", "You've hit the ACF Radar limit!")

do -- Overlay/networking
function ENT:RequestRadarInfo()
if Queued[self] then return end

Queued[self] = true

timer.Simple(5, function() Queued[self] = nil end)

net.Start("ACF.RequestRadarInfo")
net.WriteEntity(self)
net.SendToServer()
end

net.Receive("ACF.RequestRadarInfo",function()
local Radar = net.ReadEntity()
if not IsValid(Radar) then return end

Queued[Radar] = nil

local RadarInfo = util.JSONToTable(net.ReadString())

Radar.Spherical = RadarInfo.Spherical
Radar.Cone = RadarInfo.Cone
Radar.Origin = RadarInfo.Origin
Radar.Range = RadarInfo.Range

Radar.HasData = true
Radar.Age = Clock.CurTime + 5
end)

local Col = Color(255,255,0,25)
local Col2 = Color(255,255,0)
function ENT:DrawOverlay()
local SelfTbl = self:GetTable()

if not SelfTbl.HasData then
self:RequestRadarInfo()
return
elseif Clock.CurTime > SelfTbl.Age then
self:RequestRadarInfo()
end

local Origin = self:LocalToWorld(SelfTbl.Origin)
if SelfTbl.Spherical then
render.DrawWireframeSphere(Origin,SelfTbl.Range,50,50,Col2)
else

for I = 0, 7 do
local Dir = Vector(16384,0,0)
Dir:Rotate(Angle(SelfTbl.Cone,0,0))
Dir:Rotate(Angle(0,0,45 * I))
local Point = self:LocalToWorld(SelfTbl.Origin + Dir)
local Dir2 = Vector(16384,0,0)
Dir2:Rotate(Angle(SelfTbl.Cone,0,0))
Dir2:Rotate(Angle(0,0,45 * (I + 1)))
local Point2 = self:LocalToWorld(SelfTbl.Origin + Dir2)

render.DrawQuad(Origin, Point, Point2, Point, Col)
render.DrawLine(Point, Point2, Col, true)
render.DrawLine(Origin, Point, Col, true)
end
end
end
end
19 changes: 19 additions & 0 deletions lua/entities/acf_radar/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,23 @@ function ENT:OnRemove()
timer.Remove("ACF Radar Clock " .. self:EntIndex())

WireLib.Remove(self)
end

do -- Overlay/networking
util.AddNetworkString("ACF.RequestRadarInfo")
net.Receive("ACF.RequestRadarInfo",function(_,Ply)
local Radar = net.ReadEntity()
if not IsValid(Radar) then return end

local RadarInfo = {}
RadarInfo.Spherical = (Radar.ConeDegs == nil) and true or false
RadarInfo.Cone = Radar.ConeDegs and math.Round(Radar.ConeDegs, 2) or 0
RadarInfo.Range = Radar.Range and math.Round(Radar.Range,2) or 0
RadarInfo.Origin = Radar.Origin

net.Start("ACF.RequestRadarInfo")
net.WriteEntity(Radar)
net.WriteString(util.TableToJSON(RadarInfo))
net.Send(Ply)
end)
end

0 comments on commit dd9dcd1

Please sign in to comment.