Skip to content

Commit

Permalink
Fixed: Logs parametrization
Browse files Browse the repository at this point in the history
Fixed: IsEmptyString() not being a global
Fixed: Nil logging on color reset
Fixed: Current log count is displayed two time instead of one
Added: Subtype support organized by directories
Changed: Derma tree length to 400 instead of 300 ( contain more models )
Changed: Origin from mass-centre position/angle calculation
Changed: GetCenterMC() now returns a local
Changed: BorderValue() now checks if the border exists
  • Loading branch information
dvdvideo1234 committed Jun 25, 2016
1 parent a19b026 commit bd3bcb0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 44 deletions.
19 changes: 14 additions & 5 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@ local asmlib = trackasmlib

------ CONFIGURE ASMLIB ------
asmlib.InitAssembly("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","5.257")
asmlib.SetOpVar("TOOL_VERSION","5.258")
asmlib.SetIndexes("V",1,2,3)
asmlib.SetIndexes("A",1,2,3)
asmlib.SetIndexes("S",4,5,6,7)
asmlib.SetOpVar("LOG_ONLY",nil)
asmlib.SetOpVar("LOG_SKIP",{"QuickSort","ModelToName","GetEntitySpawn: Not hitting active point","CacheQueryPiece: Record not located", "GetEntitySpawn: Trace model missing"})
asmlib.SetOpVar("LOG_SKIP",{
"QuickSort",
"ModelToName",
"GetEntitySpawn: Not hitting active point",
"CacheQueryPiece: Record not located",
"GetEntitySpawn: Trace model missing",
"MakeScreen.SetColor: Color reset",
"MakeScreen.DrawLine: Start out of border",
"MakeScreen.DrawLine: End out of border"
})

------ CONFIGURE LOGGING ------
asmlib.MakeAsmVar("logsmax" , {0,1}, nil, bitBor(FCVAR_ARCHIVE, FCVAR_ARCHIVE_XBOX, FCVAR_NOTIFY, FCVAR_PRINTABLEONLY), "Maximum logging lines to be printed")
asmlib.MakeAsmVar("logfile" , "" , nil, bitBor(FCVAR_ARCHIVE, FCVAR_ARCHIVE_XBOX, FCVAR_NOTIFY, FCVAR_PRINTABLEONLY), "File to store the logs ( if any )")
asmlib.MakeAsmVar("logsmax" , "0" , {0}, bitBor(FCVAR_ARCHIVE, FCVAR_ARCHIVE_XBOX, FCVAR_NOTIFY, FCVAR_PRINTABLEONLY), "Maximum logging lines to be printed")
asmlib.MakeAsmVar("logfile" , "" , nil , bitBor(FCVAR_ARCHIVE, FCVAR_ARCHIVE_XBOX, FCVAR_NOTIFY, FCVAR_PRINTABLEONLY), "File to store the logs ( if any )")
asmlib.SetLogControl(asmlib.GetAsmVar("logsmax","INT"),asmlib.GetAsmVar("logfile","STR"))

------ CONFIGURE REPLICATED CVARS ----- Server tells the client what value to use
Expand Down Expand Up @@ -1606,7 +1615,7 @@ else
asmlib.InsertRecord({"models/bobsters_trains/rails/2ft/curves/curve_rack_90_left_1024.mdl", "#", "#", 2, "", "651.898,651.898,3.016", "0,90,0"})
asmlib.DefaultType("Ron's 2ft track pack", function(m)
local r = stringGsub(m,"models/ron/2ft/",""); r = stringSub(r,1,stringFind(r,"/")-1);
return stringUpper(stringSub(r,1,1))..stringLower(stringSub(r,2,-1)); end)
return stringGsub(stringUpper(stringSub(r,1,1))..stringLower(stringSub(r,2,-1)),"_"," "); end)
asmlib.InsertRecord({"models/ron/2ft/misc/buffer.mdl", "#", "#", 1, "", "64,0,6.016", ""})
asmlib.InsertRecord({"models/ron/2ft/misc/buffer_2.mdl","#","Buffer SH2",1,""," 32,0,6.016",""})
asmlib.InsertRecord({"models/ron/2ft/misc/buffer_2.mdl","#","Buffer SH2",2,"","-32,0,6.016","0,-180,0"})
Expand Down
11 changes: 5 additions & 6 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function IsString(anyValue)
return (getmetatable(anyValue) == GetOpVar("TYPEMT_STRING"))
end

local function IsEmptyString(anyValue)
function IsEmptyString(anyValue)
if(not IsString(anyValue)) then return false end
return (anyValue == "")
end
Expand Down Expand Up @@ -677,7 +677,7 @@ function MakeScreen(sW,sH,eW,eH,conColors)
function self:SetColor(keyColor,sMeth)
if(not IsExistent(keyColor) and not IsExistent(sMeth)) then
Colors.Key = GetOpVar("OOP_DEFAULTKEY")
return StatusLog("MakeScreen.SetColor: Color reset") end
return StatusLog(nil,"MakeScreen.SetColor: Color reset") end
local keyColor = keyColor or Colors.Key
if(not IsExistent(keyColor)) then
return StatusLog(nil,"MakeScreen.SetColor: Indexing skipped") end
Expand Down Expand Up @@ -1001,7 +1001,6 @@ function GetCenterMC(oEnt)
return StatusLog(Vector(0,0,0),"GetCenterMC: Phys object Invalid") end
local vRez = Phys:GetMassCenter()
vRez[cvX] = -vRez[cvX]; vRez[cvY] = -vRez[cvY]; vRez[cvZ] = 0
vRez:Rotate(oEnt:GetAngles())
return vRez
end

Expand Down Expand Up @@ -1029,8 +1028,8 @@ local function BorderValue(nsVal,sName)
local Border = GetOpVar("TABLE_BORDERS")
Border = Border[sName]
if(IsExistent(Border)) then
if (nsVal < Border[1]) then return Border[1]
elseif(nsVal > Border[2]) then return Border[2] end
if(Border[1] and nsVal < Border[1]) then return Border[1] end
if(Border[2] and nsVal > Border[2]) then return Border[2] end
end
return nsVal
end
Expand Down Expand Up @@ -3107,7 +3106,7 @@ local function SetPosBound(ePiece,vPos,oPly,sMode)
ePiece:Remove()
if(sMode == "HINT" or sMode == "GENERIC" or sMode == "ERROR") then
PrintNotifyPly(oPly,"Position out of map bounds!",sMode) end
return StatusLog(false,"SetPosBound("..sMode.."): Position "..tostring(vPos).." out of map bounds")
return StatusLog(false,"SetPosBound("..sMode.."): Position ["..tostring(vPos).."] out of map bounds")
end
return StatusLog(true,"SetPosBound("..sMode.."): Success")
end
Expand Down
67 changes: 34 additions & 33 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ end

function TOOL:GetStatus(stTrace,anyMessage,hdEnt)
local iMaxlog = asmlib.GetOpVar("LOG_MAXLOGS")
if(iMaxlog == 0) then return "Status N/A" end
if(not (iMaxlog > 0)) then return "Status N/A" end
local ply, sDelim = self:GetOwner(), "\n"
local iCurLog = asmlib.GetOpVar("LOG_CURLOGS")
local sFleLog = asmlib.GetOpVar("LOG_LOGFILE")
Expand All @@ -377,7 +377,7 @@ function TOOL:GetStatus(stTrace,anyMessage,hdEnt)
sDu = sDu..sSpace.."Dumping logs state:"..sDelim
sDu = sDu..sSpace.." LogsMax: <"..tostring(iMaxlog)..">"..sDelim
sDu = sDu..sSpace.." LogsCur: <"..tostring(iCurLog)..">"..sDelim
sDu = sDu..sSpace.." LogsCur: <"..tostring(iCurLog)..">"..sDelim
sDu = sDu..sSpace.." LogFile: <"..tostring(sFleLog)..">"..sDelim
sDu = sDu..sSpace.." MaxProps: <"..tostring(GetConVar("sbox_maxprops"):GetInt())..">"..sDelim
sDu = sDu..sSpace.." MaxTrack: <"..tostring(GetConVar("sbox_max"..gsLimitName):GetInt())..">"..sDelim
sDu = sDu..sSpace.."Dumping player keys:"..sDelim
Expand Down Expand Up @@ -472,16 +472,12 @@ function TOOL:LeftClick(stTrace)
local nextpic, nextyaw, nextrol = self:GetAngOffsets()
asmlib.LoadKeyPly(ply)
if(stTrace.HitWorld) then -- Switch the tool mode ( Spawn )
local vPos, aAng = Vector(), asmlib.GetNormalAngle(ply,stTrace,surfsnap,ydegsnp)
local vPos = Vector(nextx,nexty,nextz + offsetup)
local aAng = asmlib.GetNormalAngle(ply,stTrace,surfsnap,ydegsnp)
if(mcspawn ~= 0) then -- Spawn on mass centre
local vPos:Add(stTrace.HitPos)
vPos:Add(offsetup * stTrace.HitNormal)
vPos:Add(nextz * aAng:Up())
vPos:Add(nexty * aAng:Right())
vPos:Add(nextx * aAng:Forward())
aAng:RotateAroundAxis(aAng:Up() ,-nextyaw)
aAng:RotateAroundAxis(aAng:Right() , nextpic)
aAng:RotateAroundAxis(aAng:Forward(), nextrol)
aAng:RotateAroundAxis(aAng:Up() ,-nextyaw)
aAng:RotateAroundAxis(aAng:Right() , nextpic)
aAng:RotateAroundAxis(aAng:Forward(), nextrol)
else
local stSpawn = asmlib.GetNormalSpawn(stTrace.HitPos + offsetup * stTrace.HitNormal,aAng,model,
pointid,nextx,nexty,nextz,nextpic,nextyaw,nextrol)
Expand All @@ -491,7 +487,12 @@ function TOOL:LeftClick(stTrace)
end
local ePiece = asmlib.MakePiece(ply,model,vPos,aAng,mass,bgskids,conPalette:Select("w"),bnderrmod)
if(ePiece) then -- Adjust the position if necessary when created correctly
if(mcspawn ~= 0) then vPos:Add(asmlib.GetCenterMC(ePiece)); ePiece:SetPos(vPos) end
if(mcspawn ~= 0) then
vPos:Add(asmlib.GetCenterMC(ePiece));
vPos:Rotate(aAng)
vPos:Add(stTrace.HitPos)
ePiece:SetPos(vPos)
end
if(not asmlib.ApplyPhysicalSettings(ePiece,ignphysgn,freeze,gravity,physmater)) then
return asmlib.StatusLog(false,self:GetStatus(stTrace,"TOOL:LeftClick(World): Failed to apply physical settings",ePiece)) end
if(not asmlib.ApplyPhysicalAnchor(ePiece,anEnt,weld,nocollide,maxforce)) then
Expand Down Expand Up @@ -956,7 +957,7 @@ function TOOL.BuildCPanel(CPanel)
local subTypes = asmlib.GetOpVar("TABLE_SUBTYPES")
local pTree = vguiCreate("DTree")
pTree:SetPos(2, CurY)
pTree:SetSize(2, 300)
pTree:SetSize(2, 400)
pTree:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".tree"))
pTree:SetIndentSize(0)
local iCnt, pFolders, pSubtype, pNode = 1, {}, {}
Expand All @@ -980,17 +981,20 @@ function TOOL.BuildCPanel(CPanel)
-- Register the subtype if definition functional is given
if(subTypes[Typ]) then -- There is a subtype definition
if(not pSubtype[Typ]) then pSubtype[Typ] = {} end
local Sub = subTypes[Typ](Mod)
if(Sub ~= "" and not pSubtype[Typ][Sub]) then -- No subtype folder made already
pItem = pItem:AddNode(Sub) -- The item pointer will refer to the new directory
pItem:SetName(Sub)
pItem.Icon:SetImage("icon16/folder.png")
pItem.InternalDoClick = function() end
pItem.DoClick = function() return false end
pItem.Label.UpdateColours = function(pSelf)
return pSelf:SetTextStyleColor(conPalette:Select("tx")) end
pSubtype[Typ][Sub] = pItem
end
local nmSub = subTypes[Typ](Mod)
local pnSub = pSubtype[Typ][nmSub]
if(not pnSub) then
if(not asmlib.IsEmptyString(nmSub)) then -- No subtype folder made already
pItem = pItem:AddNode(nmSub) -- The item pointer will refer to the new directory
pItem:SetName(nmSub)
pItem.Icon:SetImage("icon16/folder.png")
pItem.InternalDoClick = function() end
pItem.DoClick = function() return false end
pItem.Label.UpdateColours = function(pSelf)
return pSelf:SetTextStyleColor(conPalette:Select("tx")) end
pSubtype[Typ][nmSub] = pItem
end
else pItem = pnSub end
end
-- Register the node asociated with the track piece
pNode = pItem:AddNode(Nam)
Expand Down Expand Up @@ -1138,20 +1142,17 @@ function TOOL:UpdateGhost(oEnt, oPly)
local aAng = asmlib.GetNormalAngle(oPly,stTrace,surfsnap,ydegsnp)
if(mcspawn ~= 0) then
oEnt:SetAngles(aAng)
local vCen = asmlib.GetCenterMC(oEnt)
local vOBB = oEnt:OBBMins()
vCen:Add(stTrace.HitPos)
vCen:Add(-vOBB[cvZ] * stTrace.HitNormal)
vCen:Add(nextx * aAng:Forward())
vCen:Add(nexty * aAng:Right())
vCen:Add(nextz * aAng:Up())
local vCen = asmlib.GetCenterMC(oEnt)
vCen[cvX] = vCen[cvX] + nextx
vCen[cvY] = vCen[cvY] + nexty
vCen[cvZ] = vCen[cvZ] + nextz -vOBB[cvZ]
asmlib.ConCommandPly(oPly,"offsetup",-vOBB[cvZ])
aAng:RotateAroundAxis(aAng:Up() ,-nextyaw)
aAng:RotateAroundAxis(aAng:Right() , nextpic)
aAng:RotateAroundAxis(aAng:Forward(), nextrol)
oEnt:SetAngles(aAng)
oEnt:SetPos(vCen)
oEnt:SetNoDraw(false)
vCen:Rotate(aAng); vCen:Add(stTrace.HitPos)
oEnt:SetPos(vCen); oEnt:SetAngles(aAng); oEnt:SetNoDraw(false)
else
local pointUp = (asmlib.PointOffsetUp(oEnt,pointid) or 0)
local stSpawn = asmlib.GetNormalSpawn(stTrace.HitPos + pointUp * stTrace.HitNormal,aAng,model,
Expand Down

0 comments on commit bd3bcb0

Please sign in to comment.