From 546ee5eb65a0645b4fb7c663be3f8d3e55c507df Mon Sep 17 00:00:00 2001 From: Deyan Dobromirov Date: Thu, 12 Jan 2023 20:10:41 +0200 Subject: [PATCH] Added: Track assembly retrieve owner from entity (#44) Fixed: Dashes saves as UTF-8 Fixed: Integrated commit hook Fixed: Switch TA initialization to ANSI Improved: Better future support Improved: The way script handles the owner Updated: Keep code conversion Updated: Version equalize Updated: WS publish now calls integrated NP Added: Commit hooks ENV variables initial commit Added: Track assembly retrieve owner from entity Removed: Hook `pre-commit.bat` timeout Removed: Timeout at the execution end --- .tgitconfig | 5 + data/trackassembly/tools/hooks/pre-commit.bat | 6 +- lua/autorun/trackassembly_init.lua | 6 +- lua/trackassembly/trackasmlib.lua | 23 +++++ .../gmod_tool/stools/trackassembly.lua | 4 +- workshop_publish.bat | 99 +++++++------------ 6 files changed, 70 insertions(+), 73 deletions(-) create mode 100644 .tgitconfig diff --git a/.tgitconfig b/.tgitconfig new file mode 100644 index 0000000..c9f8bbf --- /dev/null +++ b/.tgitconfig @@ -0,0 +1,5 @@ +[hook "precommit"] +[hook "startcommit"] + cmdline = data\\trackassembly\\tools\\hooks\\pre-commit.bat + wait = true + show = true diff --git a/data/trackassembly/tools/hooks/pre-commit.bat b/data/trackassembly/tools/hooks/pre-commit.bat index 39d75ba..cdabdf8 100644 --- a/data/trackassembly/tools/hooks/pre-commit.bat +++ b/data/trackassembly/tools/hooks/pre-commit.bat @@ -8,10 +8,10 @@ set hookOutFile=trackassembly_init.lua set hookBasPath=%~dp0 :: The path to the Lua eceutable including -set hookLuaPath=%1 +set "hookLuaPath=%LUA_HOME%\bin\lua.exe" :: The path to the log file. Folder must exist! -set hookLogFile=%2 +set "hookLogFile=%TEMP%\commit_hook.log" :: Where to read the revision file from set hookCpyPath=%hookBasPath%..\..\..\..\lua\autorun @@ -37,5 +37,5 @@ echo Cleanup pieces manager buid...>>%hookLogFile% rd /s /q %hookPimMath%\bin rd /s /q %hookPimMath%\obj del %hookPimMath%\peaces_manager.layout -timeout 500 + exit 0 diff --git a/lua/autorun/trackassembly_init.lua b/lua/autorun/trackassembly_init.lua index b96e6c8..c5af92b 100644 --- a/lua/autorun/trackassembly_init.lua +++ b/lua/autorun/trackassembly_init.lua @@ -93,7 +93,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present ------------ CONFIGURE ASMLIB ------------ asmlib.InitBase("track","assembly") -asmlib.SetOpVar("TOOL_VERSION","8.697") +asmlib.SetOpVar("TOOL_VERSION","8.698") asmlib.SetIndexes("V" ,1,2,3) asmlib.SetIndexes("A" ,1,2,3) asmlib.SetIndexes("WV",1,2,3) @@ -240,7 +240,7 @@ local conElements = asmlib.GetContainer("LIST_VGUI") local conWorkMode = asmlib.GetContainer("WORK_MODE") conWorkMode:Push("SNAP" ) -- General spawning and snapping mode conWorkMode:Push("CROSS") -- Ray cross intersect interpolation - conWorkMode:Push("CURVE") -- Catmull–Rom spline interpolation fitting + conWorkMode:Push("CURVE") -- Catmull-Rom spline interpolation fitting conWorkMode:Push("OVER" ) -- Trace normal ray location piece flip-snap conWorkMode:Push("TURN" ) -- Produces smoother turns with Bezier curve @@ -496,7 +496,7 @@ if(CLIENT) then asmlib.ToIcon("dsvlist_extdb" , "database_go" ) asmlib.ToIcon("workmode_snap" , "plugin" ) -- General spawning and snapping mode asmlib.ToIcon("workmode_cross" , "chart_line" ) -- Ray cross intersect interpolation - asmlib.ToIcon("workmode_curve" , "vector" ) -- Catmull–Rom curve line segment fitting + asmlib.ToIcon("workmode_curve" , "vector" ) -- Catmull-Rom curve line segment fitting asmlib.ToIcon("workmode_over" , "shape_move_back" ) -- Trace normal ray location piece flip-spawn asmlib.ToIcon("workmode_turn" , "arrow_turn_right") -- Produces smoother turns with Bezier curve asmlib.ToIcon("property_type" , "package_green" ) diff --git a/lua/trackassembly/trackasmlib.lua b/lua/trackassembly/trackasmlib.lua index 1a1b6b6..38a731a 100644 --- a/lua/trackassembly/trackasmlib.lua +++ b/lua/trackassembly/trackasmlib.lua @@ -272,6 +272,29 @@ function IsPlayer(oPly) return true end +function GetOwner(oEnt) + if(not (oEnt and oEnt:IsValid())) then return nil end + local set, ows = oEnt.OnDieFunctions + -- Use CPPI first when installed. If fails search down + ows = ((CPPI and oEnt.CPPIGetOwner) and oEnt:CPPIGetOwner() or nil) + if(IsPlayer(ows)) then return ows else ows = nil end + -- Try the direct entity methods. Extract owner from functios + ows = (oEnt.GetOwner and oEnt:GetOwner() or nil) + if(IsPlayer(ows)) then return ows else ows = nil end + ows = (oEnt.GetCreator and oEnt:GetCreator() or nil) + if(IsPlayer(ows)) then return ows else ows = nil end + -- Try then various entity internal key values + ows = oEnt.player; if(IsPlayer(ows)) then return ows else ows = nil end + ows = oEnt.Owner; if(IsPlayer(ows)) then return ows else ows = nil end + ows = oEnt.owner; if(IsPlayer(ows)) then return ows else ows = nil end + if(set) then -- Duplicatior die functions are registered + set = set.GetCountUpdate; ows = (set.Args and set.Args[1] or nil) + if(IsPlayer(ows)) then return ows else ows = nil end + set = set.undo1; ows = (set.Args and set.Args[1] or nil) + if(IsPlayer(ows)) then return ows else ows = nil end + end; return nil -- No owner is found. Nothing is returned +end + function IsOther(oEnt) if(not IsHere(oEnt)) then return true end if(not IsEntity(oEnt)) then return true end diff --git a/lua/weapons/gmod_tool/stools/trackassembly.lua b/lua/weapons/gmod_tool/stools/trackassembly.lua index cc08b74..9a175ed 100644 --- a/lua/weapons/gmod_tool/stools/trackassembly.lua +++ b/lua/weapons/gmod_tool/stools/trackassembly.lua @@ -1587,8 +1587,8 @@ function TOOL:Reload(stTrace) end end local trRec = asmlib.CacheQueryPiece(trEnt:GetModel()) - if(asmlib.IsHere(trRec) and trEnt:GetCreator() == ply) then trEnt:Remove() - asmlib.LogInstance("(Prop) Remove piece",gtLogs); return true + if(asmlib.IsHere(trRec) and (asmlib.GetOwner(trEnt) == ply or ply:IsAdmin())) then + trEnt:Remove(); asmlib.LogInstance("(Prop) Remove piece",gtLogs); return true end; asmlib.LogInstance("(Prop) Success",gtLogs) end; return false end diff --git a/workshop_publish.bat b/workshop_publish.bat index 4d5c71f..4ea6034 100644 --- a/workshop_publish.bat +++ b/workshop_publish.bat @@ -11,95 +11,64 @@ setlocal EnableDelayedExpansion set gmadGitHEAD= set gmadRevPath=%~dp0 set gmadNameLOG=gmad_log.txt +set gmadNameGIT=gmad_git.txt set gmadName=TrackAssemblyTool set gmadCommits=https://github.com/dvdvideo1234/%gmadName%/commit/ -set gmadPathGIT=D:\Git\bin -set gmadBinPath=F:\Games\Steam\steamapps\common\GarrysMod\bin -set gmadADTools=%gmadRevPath%data\trackassembly\tools +set "gmadPathGIT=%GIT_HOME%\bin\git.exe" +set gmadBinPath=%GMOD_HOME%\bin +set "gmadADTools=%gmadRevPath%data\trackassembly\tools" set "gmadTime=%date% %time%" set gmadID=287012681 set gmadDirs=(lua resource) -set gmadLogs= -set gmadCRLF=^ - - -:: New line is actually needed when escaped title Addon %gmadName% updater/publisher -echo Press Crtl+C to terminate ! -echo Press a key if you do not want to wait ! -echo Rinning in %gmadRevPath%. -echo Npp Find --\h{1,}\n-- replace --\n-- in dos format before commit ! -echo. - -:: Extract repository source contents - -rd /S /Q !gmadRevPath!Workshop -del !gmadRevPath!!gmadNameLOG! +echo Press Crtl+C to terminate^^! +echo Press a key if you do not want to wait^^! +echo Rinning in: %gmadRevPath% +echo Npp Find --\h{1,}\n-- replace --\n-- in dos format before commit^^! +echo Extracting repository source contents^^! +if exist !gmadNameLOG! del !gmadNameLOG! +if exist !gmadNameGIT! del !gmadNameGIT! +if exist Workshop rd /S /Q Workshop timeout 5 -md %gmadRevPath%Workshop\!gmadName! +md "%gmadRevPath%Workshop\!gmadName!" >> !gmadNameLOG! for %%i in %gmadDirs% do ( - echo Extracting %%i - timeout 3 - xcopy !gmadRevPath!%%i !gmadRevPath!Workshop\!gmadName!\%%i /EXCLUDE:!gmadADTools!\workshop\key.txt /E /C /I /F /R /Y + echo Exporting addon content: %%i + call xcopy "!gmadRevPath!%%i" "!gmadRevPath!Workshop\!gmadName!\%%i" /EXCLUDE:!gmadADTools!\workshop\key.txt /E /C /I /F /R /Y >> !gmadNameLOG! ) -call copy !gmadADTools!\workshop\addon.json !gmadRevPath!Workshop\!gmadName!\addon.json -call !gmadBinPath!\gmad.exe create -folder "!gmadRevPath!Workshop\!gmadName!" -out "!gmadRevPath!Workshop\!gmadName!.gma" +call copy "!gmadADTools!\workshop\addon.json" "!gmadRevPath!Workshop\!gmadName!\addon.json" >> !gmadNameLOG! +call "!gmadBinPath!\gmad.exe" create -folder "!gmadRevPath!Workshop\!gmadName!" -out "!gmadRevPath!Workshop\!gmadName!.gma" >> !gmadNameLOG! -:: Obtain the latest commit hash from the repository -call !gmadPathGIT!\git.exe rev-parse HEAD>!gmadNameLOG! -call set /p gmadGitHEAD=!gmadNameLOG! -call echo.>>!gmadNameLOG! -call echo !gmadCommits!!gmadGitHEAD!>>!gmadNameLOG! -call echo. >> !gmadNameLOG! +for /F "tokens=*" %%i in ('call "!gmadPathGIT!" rev-parse HEAD') do (set "gmadGitHEAD=%%i") -!gmadPathGIT!\git.exe log -1 --pretty=%%B>>!gmadNameLOG! - -for /f "delims=" %%i in ('type !gmadNameLOG!') do ( - - IF DEFINED gmadLogs ( - set "gmadLogs=!gmadLogs!!gmadCRLF!%%i" - ) ELSE ( - set "gmadLogs=%%i" - ) -) - -:: Publish if ID is available or create if it is not. - -echo . -echo . -echo THIS IS THE LAST LOG -echo . -echo . -echo !gmadLogs! -echo . +call echo !gmadTime! >> !gmadNameGIT! +call echo. >> !gmadNameGIT! +call echo !gmadCommits!!gmadGitHEAD! >> !gmadNameGIT! +call echo. >> !gmadNameGIT! +call "!gmadPathGIT!" log -1 >> !gmadNameGIT! timeout 15 -IF DEFINED gmadID ( - call !gmadBinPath!\gmpublish.exe update -addon "!gmadRevPath!Workshop\!gmadName!.gma" -id "!gmadID!" -icon "!gmadADTools!\pictures\icon.jpg" -changes "Generated by batch !" -) ELSE ( - call !gmadBinPath!\gmpublish.exe create -addon "!gmadRevPath!Workshop\!gmadName!.gma" -icon "!gmadADTools!\pictures\icon.jpg" +if defined gmadID ( + call "!gmadBinPath!\gmpublish.exe" update -addon "!gmadRevPath!Workshop\!gmadName!.gma" -id "!gmadID!" -icon "!gmadADTools!\pictures\icon.jpg" -changes "Generated by batch" >> !gmadNameLOG! +) else ( + call "!gmadBinPath!\gmpublish.exe" create -addon "!gmadRevPath!Workshop\!gmadName!.gma" -icon "!gmadADTools!\pictures\icon.jpg" >> !gmadNameLOG! ) -:: Tell the user we are done and clean-up the directory +echo !gmadName! Published^^! -echo. -rd /S /Q !gmadRevPath!Workshop +call "%WINDIR%\System32\notepad.exe" "!gmadRevPath!!gmadNameGIT!" -echo !gmadName! Published ! -echo. -timeout 500 +echo Cleaning up the working directory^^! -:: Give a chance to copy the logs -del !gmadRevPath!!gmadNameLOG! +rd /S /Q "!gmadRevPath!Workshop" +del "!gmadRevPath!!gmadNameLOG!" +del "!gmadRevPath!!gmadNameGIT!" exit 0