From fbeac51b6d419082a88c5817656d687da5667e7a Mon Sep 17 00:00:00 2001 From: Deyan Dobromirov Date: Thu, 31 Dec 2015 21:45:15 +0200 Subject: [PATCH] Fixed: Bodygroup ID list not created to numbers properly Changed: Retrieve a library variable for the string "," instead of creating one dynamically Changed: Some code rearrangements --- .../dsv/cl_TRACKASSEMBLY_ADDITIONS.txt | 2 +- .../dsv/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt | 2 +- .../dsv/cl_TRACKASSEMBLY_PIECES.txt | 2 +- .../dsv/sv_TRACKASSEMBLY_ADDITIONS.txt | 2 +- .../dsv/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt | 2 +- .../dsv/sv_TRACKASSEMBLY_PIECES.txt | 2 +- .../exp/cl_TRACKASSEMBLY_ADDITIONS.txt | 2 +- .../exp/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt | 2 +- .../exp/cl_TRACKASSEMBLY_PIECES.txt | 2 +- .../exp/sv_TRACKASSEMBLY_ADDITIONS.txt | 2 +- .../exp/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt | 2 +- .../exp/sv_TRACKASSEMBLY_PIECES.txt | 2 +- lua/autorun/trackassembly_init.lua | 2 +- lua/trackassembly/trackasmlib.lua | 62 +++++++++---------- 14 files changed, 43 insertions(+), 45 deletions(-) diff --git a/data/trackassembly/dsv/cl_TRACKASSEMBLY_ADDITIONS.txt b/data/trackassembly/dsv/cl_TRACKASSEMBLY_ADDITIONS.txt index 383afa6d..41a069ef 100644 --- a/data/trackassembly/dsv/cl_TRACKASSEMBLY_ADDITIONS.txt +++ b/data/trackassembly/dsv/cl_TRACKASSEMBLY_ADDITIONS.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( DSV ): 12/31/15 20:43:07 [ LUA ] +# ExportIntoFile( DSV ): 12/31/15 21:41:25 [ LUA ] # Data settings: MODELBASE MODELADD ENTCLASS LINEID POSOFF ANGOFF MOVETYPE PHYSINIT DRSHADOW PHMOTION PHYSLEEP SETSOLID TRACKASSEMBLY_ADDITIONS models/shinji85/train/rail_r_switch.mdl "models/shinji85/train/sw_lever.mdl" "buttonswitch" 1 "-100,125,0" "NULL" -1 -1 -1 -1 -1 -1 TRACKASSEMBLY_ADDITIONS models/shinji85/train/rail_r_switch.mdl "models/shinji85/train/rail_r_switcher1.mdl" "prop_dynamic" 2 "NULL" "NULL" 6 6 -1 1 1 6 diff --git a/data/trackassembly/dsv/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt b/data/trackassembly/dsv/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt index 1e83ff23..ce75e445 100644 --- a/data/trackassembly/dsv/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt +++ b/data/trackassembly/dsv/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( DSV ): 12/31/15 20:43:07 [ LUA ] +# ExportIntoFile( DSV ): 12/31/15 21:41:25 [ LUA ] # Data settings: TYPE LINEID NAME TRACKASSEMBLY_PHYSPROPERTIES "Special" 1 "default" TRACKASSEMBLY_PHYSPROPERTIES "Special" 2 "default_silent" diff --git a/data/trackassembly/dsv/cl_TRACKASSEMBLY_PIECES.txt b/data/trackassembly/dsv/cl_TRACKASSEMBLY_PIECES.txt index 9e39cc0e..d73ec1a2 100644 --- a/data/trackassembly/dsv/cl_TRACKASSEMBLY_PIECES.txt +++ b/data/trackassembly/dsv/cl_TRACKASSEMBLY_PIECES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( DSV ): 12/31/15 20:43:07 [ LUA ] +# ExportIntoFile( DSV ): 12/31/15 21:41:25 [ LUA ] # Data settings: MODEL TYPE NAME LINEID POINT ORIGIN ANGLE TRACKASSEMBLY_PIECES "models/bobsters_trains/rails/2ft/misc/cross.mdl" "Bobster's two feet rails" "Cross" 1 "83,0,3.015" "83,0,3.015" "0,0,0" TRACKASSEMBLY_PIECES "models/bobsters_trains/rails/2ft/misc/cross.mdl" "Bobster's two feet rails" "Cross" 2 "0.003,83,3.015" "0.003,83,3.015" "0,90,0" diff --git a/data/trackassembly/dsv/sv_TRACKASSEMBLY_ADDITIONS.txt b/data/trackassembly/dsv/sv_TRACKASSEMBLY_ADDITIONS.txt index e7b5b7b9..de6c7c6d 100644 --- a/data/trackassembly/dsv/sv_TRACKASSEMBLY_ADDITIONS.txt +++ b/data/trackassembly/dsv/sv_TRACKASSEMBLY_ADDITIONS.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( DSV ): 12/31/15 20:43:01 [ LUA ] +# ExportIntoFile( DSV ): 12/31/15 21:41:32 [ LUA ] # Data settings: MODELBASE MODELADD ENTCLASS LINEID POSOFF ANGOFF MOVETYPE PHYSINIT DRSHADOW PHMOTION PHYSLEEP SETSOLID TRACKASSEMBLY_ADDITIONS models/shinji85/train/rail_r_switch.mdl "models/shinji85/train/sw_lever.mdl" "buttonswitch" 1 "-100,125,0" "NULL" -1 -1 -1 -1 -1 -1 TRACKASSEMBLY_ADDITIONS models/shinji85/train/rail_r_switch.mdl "models/shinji85/train/rail_r_switcher1.mdl" "prop_dynamic" 2 "NULL" "NULL" 6 6 -1 1 1 6 diff --git a/data/trackassembly/dsv/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt b/data/trackassembly/dsv/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt index efcc194a..33b915b7 100644 --- a/data/trackassembly/dsv/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt +++ b/data/trackassembly/dsv/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( DSV ): 12/31/15 20:43:01 [ LUA ] +# ExportIntoFile( DSV ): 12/31/15 21:41:32 [ LUA ] # Data settings: TYPE LINEID NAME TRACKASSEMBLY_PHYSPROPERTIES "Special" 1 "default" TRACKASSEMBLY_PHYSPROPERTIES "Special" 2 "default_silent" diff --git a/data/trackassembly/dsv/sv_TRACKASSEMBLY_PIECES.txt b/data/trackassembly/dsv/sv_TRACKASSEMBLY_PIECES.txt index c5c82172..9bcd92c0 100644 --- a/data/trackassembly/dsv/sv_TRACKASSEMBLY_PIECES.txt +++ b/data/trackassembly/dsv/sv_TRACKASSEMBLY_PIECES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( DSV ): 12/31/15 20:43:01 [ LUA ] +# ExportIntoFile( DSV ): 12/31/15 21:41:32 [ LUA ] # Data settings: MODEL TYPE NAME LINEID POINT ORIGIN ANGLE TRACKASSEMBLY_PIECES "models/bobsters_trains/rails/2ft/misc/cross.mdl" "Bobster's two feet rails" "Cross" 1 "83,0,3.015" "83,0,3.015" "0,0,0" TRACKASSEMBLY_PIECES "models/bobsters_trains/rails/2ft/misc/cross.mdl" "Bobster's two feet rails" "Cross" 2 "0.003,83,3.015" "0.003,83,3.015" "0,90,0" diff --git a/data/trackassembly/exp/cl_TRACKASSEMBLY_ADDITIONS.txt b/data/trackassembly/exp/cl_TRACKASSEMBLY_ADDITIONS.txt index de9254ce..6459d2d8 100644 --- a/data/trackassembly/exp/cl_TRACKASSEMBLY_ADDITIONS.txt +++ b/data/trackassembly/exp/cl_TRACKASSEMBLY_ADDITIONS.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( INS ): 12/31/15 20:43:07 [ LUA ] +# ExportIntoFile( INS ): 12/31/15 21:41:25 [ LUA ] # Data settings: MODELBASE,MODELADD,ENTCLASS,LINEID,POSOFF,ANGOFF,MOVETYPE,PHYSINIT,DRSHADOW,PHMOTION,PHYSLEEP,SETSOLID asmlib.InsertRecord("ADDITIONS", {"models/shinji85/train/sw_lever.mdl","buttonswitch",1,"-100,125,0","NULL",-1,-1,-1,-1,-1,-1}) asmlib.InsertRecord("ADDITIONS", {"models/shinji85/train/rail_r_switcher1.mdl","prop_dynamic",2,"NULL","NULL",6,6,-1,1,1,6}) diff --git a/data/trackassembly/exp/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt b/data/trackassembly/exp/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt index c86bfb92..2aa9b362 100644 --- a/data/trackassembly/exp/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt +++ b/data/trackassembly/exp/cl_TRACKASSEMBLY_PHYSPROPERTIES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( INS ): 12/31/15 20:43:07 [ LUA ] +# ExportIntoFile( INS ): 12/31/15 21:41:25 [ LUA ] # Data settings: TYPE,LINEID,NAME asmlib.InsertRecord("PHYSPROPERTIES", {"Special",1,"default"}) asmlib.InsertRecord("PHYSPROPERTIES", {"Special",2,"default_silent"}) diff --git a/data/trackassembly/exp/cl_TRACKASSEMBLY_PIECES.txt b/data/trackassembly/exp/cl_TRACKASSEMBLY_PIECES.txt index f09830da..f598d0bb 100644 --- a/data/trackassembly/exp/cl_TRACKASSEMBLY_PIECES.txt +++ b/data/trackassembly/exp/cl_TRACKASSEMBLY_PIECES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( INS ): 12/31/15 20:43:07 [ LUA ] +# ExportIntoFile( INS ): 12/31/15 21:41:25 [ LUA ] # Data settings: MODEL,TYPE,NAME,LINEID,POINT,ORIGIN,ANGLE asmlib.InsertRecord("PIECES", {"models/bobsters_trains/rails/2ft/misc/cross.mdl","Bobster's two feet rails","Cross",1,"83,0,3.015","83,0,3.015","0,0,0"}) asmlib.InsertRecord("PIECES", {"models/bobsters_trains/rails/2ft/misc/cross.mdl","Bobster's two feet rails","Cross",2,"0.003,83,3.015","0.003,83,3.015","0,90,0"}) diff --git a/data/trackassembly/exp/sv_TRACKASSEMBLY_ADDITIONS.txt b/data/trackassembly/exp/sv_TRACKASSEMBLY_ADDITIONS.txt index 3629da04..9b29d289 100644 --- a/data/trackassembly/exp/sv_TRACKASSEMBLY_ADDITIONS.txt +++ b/data/trackassembly/exp/sv_TRACKASSEMBLY_ADDITIONS.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( INS ): 12/31/15 20:43:01 [ LUA ] +# ExportIntoFile( INS ): 12/31/15 21:41:32 [ LUA ] # Data settings: MODELBASE,MODELADD,ENTCLASS,LINEID,POSOFF,ANGOFF,MOVETYPE,PHYSINIT,DRSHADOW,PHMOTION,PHYSLEEP,SETSOLID asmlib.InsertRecord("ADDITIONS", {"models/shinji85/train/sw_lever.mdl","buttonswitch",1,"-100,125,0","NULL",-1,-1,-1,-1,-1,-1}) asmlib.InsertRecord("ADDITIONS", {"models/shinji85/train/rail_r_switcher1.mdl","prop_dynamic",2,"NULL","NULL",6,6,-1,1,1,6}) diff --git a/data/trackassembly/exp/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt b/data/trackassembly/exp/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt index 999ae8a8..ed5ad67a 100644 --- a/data/trackassembly/exp/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt +++ b/data/trackassembly/exp/sv_TRACKASSEMBLY_PHYSPROPERTIES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( INS ): 12/31/15 20:43:01 [ LUA ] +# ExportIntoFile( INS ): 12/31/15 21:41:32 [ LUA ] # Data settings: TYPE,LINEID,NAME asmlib.InsertRecord("PHYSPROPERTIES", {"Special",1,"default"}) asmlib.InsertRecord("PHYSPROPERTIES", {"Special",2,"default_silent"}) diff --git a/data/trackassembly/exp/sv_TRACKASSEMBLY_PIECES.txt b/data/trackassembly/exp/sv_TRACKASSEMBLY_PIECES.txt index 75b7fbae..5cc6e9a2 100644 --- a/data/trackassembly/exp/sv_TRACKASSEMBLY_PIECES.txt +++ b/data/trackassembly/exp/sv_TRACKASSEMBLY_PIECES.txt @@ -1,4 +1,4 @@ -# ExportIntoFile( INS ): 12/31/15 20:43:01 [ LUA ] +# ExportIntoFile( INS ): 12/31/15 21:41:32 [ LUA ] # Data settings: MODEL,TYPE,NAME,LINEID,POINT,ORIGIN,ANGLE asmlib.InsertRecord("PIECES", {"models/bobsters_trains/rails/2ft/misc/cross.mdl","Bobster's two feet rails","Cross",1,"83,0,3.015","83,0,3.015","0,0,0"}) asmlib.InsertRecord("PIECES", {"models/bobsters_trains/rails/2ft/misc/cross.mdl","Bobster's two feet rails","Cross",2,"0.003,83,3.015","0.003,83,3.015","0,90,0"}) diff --git a/lua/autorun/trackassembly_init.lua b/lua/autorun/trackassembly_init.lua index cdee5651..c1dbe1c8 100644 --- a/lua/autorun/trackassembly_init.lua +++ b/lua/autorun/trackassembly_init.lua @@ -26,7 +26,7 @@ asmlib.SetIndexes("V",1,2,3) asmlib.SetIndexes("A",1,2,3) asmlib.SetIndexes("S",4,5,6,7) asmlib.InitAssembly("track","assembly") -asmlib.SetOpVar("TOOL_VERSION","5.151") +asmlib.SetOpVar("TOOL_VERSION","5.152") asmlib.SetOpVar("DIRPATH_BAS",asmlib.GetOpVar("TOOLNAME_NL")..asmlib.GetOpVar("OPSYM_DIRECTORY")) asmlib.SetOpVar("DIRPATH_EXP","exp"..asmlib.GetOpVar("OPSYM_DIRECTORY")) asmlib.SetOpVar("DIRPATH_DSV","dsv"..asmlib.GetOpVar("OPSYM_DIRECTORY")) diff --git a/lua/trackassembly/trackasmlib.lua b/lua/trackassembly/trackasmlib.lua index a0c37404..a2e991b7 100644 --- a/lua/trackassembly/trackasmlib.lua +++ b/lua/trackassembly/trackasmlib.lua @@ -255,6 +255,7 @@ function InitAssembly(sName,sPurpose) SetOpVar("OPSYM_REVSIGN","@") SetOpVar("OPSYM_DIVIDER","_") SetOpVar("OPSYM_DIRECTORY","/") + SetOpVar("OPSYM_SEPARATOR",",") SetOpVar("SPAWN_ENTITY",{ F = Vector(), R = Vector(), @@ -1174,15 +1175,16 @@ local function StringPOA(arPOA,sOffs) return StatusLog(nil,"StringPOA: Missing Offsets") end local symRevs = GetOpVar("OPSYM_REVSIGN") local symDisa = GetOpVar("OPSYM_DISABLE") + local symSepa = GetOpVar("OPSYM_SEPARATOR") local sModeDB = GetOpVar("MODE_DATABASE") local Result = ((arPOA[csD] and symDisa) or "") if(sOffs == "V") then - Result = Result..((arPOA[csX] == -1) and symRevs or "")..tostring(arPOA[cvX]).."," - ..((arPOA[csY] == -1) and symRevs or "")..tostring(arPOA[cvY]).."," + Result = Result..((arPOA[csX] == -1) and symRevs or "")..tostring(arPOA[cvX])..symSepa + ..((arPOA[csY] == -1) and symRevs or "")..tostring(arPOA[cvY])..symSepa ..((arPOA[csZ] == -1) and symRevs or "")..tostring(arPOA[cvZ]) elseif(sOffs == "A") then - Result = Result..((arPOA[csX] == -1) and symRevs or "")..tostring(arPOA[caP]).."," - ..((arPOA[csY] == -1) and symRevs or "")..tostring(arPOA[caY]).."," + Result = Result..((arPOA[csX] == -1) and symRevs or "")..tostring(arPOA[caP])..symSepa + ..((arPOA[csY] == -1) and symRevs or "")..tostring(arPOA[caY])..symSepa ..((arPOA[csZ] == -1) and symRevs or "")..tostring(arPOA[caR]) else return StatusLog("","StringPOA: Missed offset mode "..sOffs) end return stringGsub(Result," ","") -- Get rid of the spaces @@ -1218,25 +1220,26 @@ local function DecodePOA(sStr) local DatInd = 1 local ComCnt = 0 local Len = stringLen(sStr) - local SymOff = GetOpVar("OPSYM_DISABLE") - local SymRev = GetOpVar("OPSYM_REVSIGN") + local symOff = GetOpVar("OPSYM_DISABLE") + local symRev = GetOpVar("OPSYM_REVSIGN") + local symSep = GetOpVar("OPSYM_SEPARATOR") local arPOA = GetOpVar("ARRAY_DECODEPOA") local Ch = "" local S = 1 local E = 1 local Cnt = 1 ReloadPOA() - if(stringSub(sStr,Cnt,Cnt) == SymOff) then + if(stringSub(sStr,Cnt,Cnt) == symOff) then arPOA[7] = true Cnt = Cnt + 1 S = S + 1 end while(Cnt <= Len) do Ch = stringSub(sStr,Cnt,Cnt) - if(Ch == SymRev) then + if(Ch == symRev) then arPOA[3+DatInd] = -arPOA[3+DatInd] S = S + 1 - elseif(Ch == ",") then + elseif(Ch == symSep) then ComCnt = ComCnt + 1 E = Cnt - 1 if(ComCnt > 2) then break end @@ -1584,21 +1587,20 @@ function StringPad(sStr,sPad,nCnt) return (sPad..sStr) end -function String2BGID(sStr,nLen) +function String2BGID(sStr) if(not IsExistent(sStr)) then return StatusLog(nil, "String2BGID: String missing") end if(IsEmptyString(sStr)) then return StatusLog(nil, "String2BGID: Empty string") end - local Data = StringExplode(sStr,",") - local Cnt = 1 - local exLen = tonumber(nLen) or ArrayCount(Data) - while(Cnt <= exLen) do + local Cnt = 1 + local Data = StringExplode(sStr,GetOpVar("OPSYM_SEPARATOR")) + while(Data[Cnt]) do local Num = tonumber(Data[Cnt]) if(not Num) then return StatusLog(nil, "String2BGID: Value not a number") end if((mathFloor(Num) - Num) ~= 0) then return StatusLog(nil, "String2BGID: Floats are forbidden") end - Data[Cnt] = tonumber(Data[Cnt]) + Data[Cnt] = Num Cnt = Cnt + 1 end if(IsExistent(Data[1]))then return Data end @@ -1668,13 +1670,11 @@ function ArrayPrint(arArr,sName,nCol) return StatusLog(0,"ArrayPrint: Array is "..type(arArr)) end if(not arArr[1]) then return StatusLog(0,"ArrayPrint: Array empty") end - local Cnt = 1 - local Col = 0 - local Max = 0 - local Cols = 0 + local Cnt, Next = 1 + local Col, Max, Cols = 0, 0, 0 local Line = (sName or "Data").." = { \n" local Pad = StringPad(" "," ",stringLen(Line)-1) - local Next + local symSep = GetOpVar("OPSYM_SEPARATOR") while(arArr[Cnt]) do Col = stringLen(tostring(arArr[Cnt])) if(Col > Max) then @@ -1692,7 +1692,7 @@ function ArrayPrint(arArr,sName,nCol) end Line = Line..StringPad(tostring(arArr[Cnt])," ",-Max-1) if(Next) then - Line = Line.."," + Line = Line..symSep end if(nCol and Cols == 0) then Cols = Col - 1 @@ -3401,8 +3401,9 @@ function GetPropBodyGrp(oEnt) if(not (BG and BG[1])) then return StatusLog("","GetPropBodyGrp: Bodygroup table empty") end local Rez, Cnt = "", 1 + local symSep = GetOpVar("OPSYM_SEPARATOR") while(BG[Cnt]) do - Rez = Rez..","..tostring(bgEnt:GetBodygroup(BG[Cnt].id) or 0) + Rez = Rez..symSep..tostring(bgEnt:GetBodygroup(BG[Cnt].id) or 0) Cnt = Cnt + 1 end Rez = stringSub(Rez,2,-1) @@ -3413,22 +3414,19 @@ end function AttachBodyGroups(ePiece,sBgrpIDs) local sBgrpIDs = sBgrpIDs or "" if(not (sBgrpIDs and IsString(sBgrpIDs))) then - return StatusLog(false,"AttachBodyGroups: Expecting string argument for bodygroup IDs") end - local sNumBG = ePiece:GetNumBodyGroups() + return StatusLog(false,"AttachBodyGroups: Expecting string argument") end LogInstance("AttachBodyGroups: BGS: "..sBgrpIDs) - LogInstance("AttachBodyGroups: NUM: "..sNumBG) - local IDs = String2BGID(sBgrpIDs,sNumBG) + local IDs = String2BGID(sBgrpIDs) if(not IsExistent(IDs)) then -- Nil or table - return StatusLog(false,"AttachBodyGroups: Expecting string argument for bodygroup IDs") end - local BG = ePiece:GetBodyGroups() - Print(IDs,"IDs") + return StatusLog(false,"AttachBodyGroups: Bodygroup ID not matched") end local Cnt = 1 + local BG = ePiece:GetBodyGroups() + local symSep = GetOpVar("OPSYM_SEPARATOR") while(BG[Cnt]) do local CurBG = BG[Cnt] local BGCnt = ePiece:GetBodygroupCount(CurBG.id) - if(IDs[Cnt] > BGCnt or - IDs[Cnt] < 0) then IDs[Cnt] = 0 end - LogInstance("ePiece:SetBodygroup("..CurBG.id..","..(IDs[Cnt] or 0)..")") + if(IDs[Cnt] < 0 or IDs[Cnt] > BGCnt) then IDs[Cnt] = 0 end + LogInstance("ePiece:SetBodygroup("..CurBG.id..symSep..(IDs[Cnt] or 0)..")") ePiece:SetBodygroup(CurBG.id,IDs[Cnt] or 0) Cnt = Cnt + 1 end