wiremod-svn-archive/wire/lua/weapons/gmod_tool/stools/wire_wirelink.lua

153 lines
4.2 KiB
Lua
Raw Normal View History

2008-10-31 11:48:19 +00:00
TOOL.Category = "Wire - Tools"
TOOL.Name = "Expression 2 - Wirelink"
TOOL.Command = nil
TOOL.ConfigName = ""
if CLIENT then
language.Add( "Tool_wire_wirelink_name", "Expression 2 Wirelink Tool (Wire)" )
language.Add( "Tool_wire_wirelink_desc", "Adds a wirelink output to any wire compatible device, for use with Expression 2" )
language.Add( "Tool_wire_wirelink_0", "Primary: Add wirelink, Secondary: Remove wirelink" )
end
if SERVER then
2009-03-16 13:21:02 +00:00
local _Wire_Link_End = WireLib.Link_End
2008-10-31 11:48:19 +00:00
local _Wire_CreateSpecialOutputs = WireLib.CreateSpecialOutputs
local _Wire_AdjustSpecialOutputs = WireLib.AdjustSpecialOutputs
local _Wire_BuildDupeInfo = WireLib.BuildDupeInfo
local _Wire_ApplyDupeInfo = WireLib.ApplyDupeInfo
function RefreshSpecialOutputs(ent)
local names = {}
local types = {}
local descs = {}
if ent.Outputs then
local index = 1
for _,output in pairs(ent.Outputs) do
names[index] = output.Name
types[index] = output.Type
descs[index] = output.Desc
index = index + 1
end
ent.Outputs = WireLib.AdjustSpecialOutputs(ent, names, types, descs)
else
ent.Outputs = WireLib.CreateSpecialOutputs(ent, names, types, descs)
end
WireLib.TriggerOutput(ent, "link", ent)
end
function InfuseSpecialOutputs(func, ent, names, types, desc)
if ent.extended == nil then
return func(ent, names, types, desc)
end
2009-03-16 13:21:02 +00:00
if types == nil then
types = {}
for i,_ in ipairs(names) do
types[i] = "NORMAL"
end
end
table.insert(names, "link")
table.insert(types, "WIRELINK")
2008-10-31 11:48:19 +00:00
local outputs = func(ent, names, types, desc)
2009-03-16 13:21:02 +00:00
table.remove(names)
table.remove(types)
2008-10-31 11:48:19 +00:00
return outputs
end
function WireLib.BuildDupeInfo(ent)
local info = _Wire_BuildDupeInfo(ent)
2008-12-19 23:27:55 +00:00
if ent.extended then
if info == nil then info = {} end
info.extended = true
end
2008-10-31 11:48:19 +00:00
return info
end
function WireLib.ApplyDupeInfo(ply, ent, info, GetEntByID)
if info.extended then ent.extended = true end
RefreshSpecialOutputs(ent)
2009-03-16 13:21:02 +00:00
2008-10-31 11:48:19 +00:00
_Wire_ApplyDupeInfo(ply, ent, info, GetEntByID)
end
function WireLib.CreateSpecialOutputs(ent, names, types, desc)
return InfuseSpecialOutputs(_Wire_CreateSpecialOutputs, ent, names, types, desc)
end
function WireLib.AdjustSpecialOutputs(ent, names, types, desc)
return InfuseSpecialOutputs(_Wire_AdjustSpecialOutputs, ent, names, types, desc)
end
function WireLib.CreateOutputs(ent, names, desc)
2009-03-16 13:21:02 +00:00
return WireLib.CreateSpecialOutputs(ent, names, nil, desc)
2008-10-31 11:48:19 +00:00
end
function WireLib.AdjustOutputs(ent, names, desc)
2009-03-16 13:21:02 +00:00
return WireLib.AdjustSpecialOutputs(ent, names, nil, desc)
2008-10-31 11:48:19 +00:00
end
2009-03-16 13:21:02 +00:00
function WireLib.Link_End(idx, ent, pos, oname, pl)
if oname == "link" then
ent.extended = true
RefreshSpecialOutputs(ent)
end
return _Wire_Link_End(idx, ent, pos, oname, pl)
end
Wire_Link_End = WireLib.Link_End
2008-10-31 11:48:19 +00:00
Wire_CreateOutputs = WireLib.CreateOutputs
Wire_AdjustOutputs = WireLib.AdjustOutputs
2009-03-16 13:21:02 +00:00
Wire_BuildDupeInfo = WireLib.BuildDupeInfo
Wire_ApplyDupeInfo = WireLib.ApplyDupeInfo
2008-10-31 11:48:19 +00:00
end
function TOOL:LeftClick(trace)
if !trace.HitPos then return false end
if trace.Entity:IsPlayer() then return false end
if CLIENT then return true end
local ply = self:GetOwner()
if ( trace.Entity:IsValid() && (trace.Entity.Base == "base_wire_entity" || trace.Entity.TriggerInput) && (trace.Entity.pl == ply || trace.Entity.pl == nil) ) then
local ent = trace.Entity
if ent.extended then return false end
ent.extended = true
RefreshSpecialOutputs(ent)
return true
end
return false
end
function TOOL:RightClick(trace)
if !trace.HitPos then return false end
if trace.Entity:IsPlayer() then return false end
if CLIENT then return true end
local ply = self:GetOwner()
if ( trace.Entity:IsValid() && trace.Entity.TriggerInput && (trace.Entity.pl == ply || trace.Entity.pl == nil) ) then
local ent = trace.Entity
if !ent.extended then return false end
ent.extended = false
RefreshSpecialOutputs(ent)
return true
end
return false
end
function TOOL.BuildCPanel(panel)
panel:AddControl("Header", { Text = "#Tool_wire_wirelink_name", Description = "#Tool_wire_wirelink_desc" })
end