Skip to content

Commit

Permalink
Added: Categories for Modular city streets
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdvideo1234 committed Sep 4, 2024
1 parent cae7c8f commit ed3ae57
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","8.764")
asmlib.SetOpVar("TOOL_VERSION","8.765")

------------ CONFIGURE GLOBAL INIT OPVARS ------------

Expand Down Expand Up @@ -4366,7 +4366,9 @@ else
PIECES:Record({"models/sligwolf/rerailer/rerailer_2.mdl", "#", "Double Middle", 2, "-1882.106, 0, 3.031", "-2367.072, 0, -5.412", "0,-180,0"})
PIECES:Record({"models/sligwolf/rerailer/rerailer_3.mdl", "#", "Double Long", 1, "-258.249, -0.01, -0.002", "219.415, 0, -5.409"})
PIECES:Record({"models/sligwolf/rerailer/rerailer_3.mdl", "#", "Double Long", 2, "-3124.199, -0.01, 2.997", "-3601.869, -0.377, -5.416", "0,-180,0"})
asmlib.Categorize("Modular City Street")
asmlib.Categorize("Modular City Street", {"models/propper/dingles_modular_streets/",
{{"highway", true}, {"street" , true}, {"endcap"}, {"turn"},
{"ramp"}, {"connector"}, {"tjunction"}, {"intersection"}, {"elevated"}}})
PIECES:Record({"models/propper/dingles_modular_streets/street64x512.mdl", "#", "#", 1, "", "0,-64,0", "0,-90,0"})
PIECES:Record({"models/propper/dingles_modular_streets/street64x512.mdl", "#", "#", 2, "", "0, 64,0", "0,90,0"})
PIECES:Record({"models/propper/dingles_modular_streets/street64x768.mdl", "#", "#", 1, "", "0,-64,0", "0,-90,0"})
Expand Down
54 changes: 45 additions & 9 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,7 @@ function ModelToNameRule(sRule, gCut, gSub, gApp)
else LogInstance("Wrong mode: "..sRule); return false end
end

function Categorize(oTyp, fCat)
function Categorize(oTyp, fCat, ...)
local tCat = GetOpVar("TABLE_CATEGORIES")
if(not IsHere(oTyp)) then
local sTyp = tostring(GetOpVar("DEFAULT_TYPE") or "")
Expand All @@ -2330,14 +2330,50 @@ function Categorize(oTyp, fCat)
local sTyp = tostring(GetOpVar("DEFAULT_TYPE") or "")
local fsLog = GetOpVar("FORM_LOGSOURCE") -- The actual format value
local ssLog = "*"..fsLog:format("TYPE","Categorize",tostring(oTyp))
if(isstring(fCat)) then tCat[sTyp] = {}
tCat[sTyp].Txt = fCat; tTyp = (tCat and tCat[sTyp] or nil)
tCat[sTyp].Cmp = CompileString("return ("..fCat..")", sTyp)
local bS, vO = pcall(tCat[sTyp].Cmp); if(not bS) then
LogInstance("Failed "..GetReport(fCat)..": "..vO, ssLog); return nil end
tCat[sTyp].Cmp = vO; tTyp = tCat[sTyp]
return sTyp, (tTyp and tTyp.Txt), (tTyp and tTyp.Cmp)
else LogInstance("Skip "..GetReport(fCat), ssLog) end
if(isstring(fCat)) then
tTyp = (tCat[sTyp] or {}); tCat[sTyp] = tTyp; tTyp.Txt = fCat
elseif(istable(fCat)) then
tTyp = (tCat[sTyp] or {}); tCat[sTyp] = tTyp
tTyp.Txt = [[function(m)
local o = {}
function setBranch(v, p, b)
if(v:find(p)) then
local e = v:gsub("%W*"..p.."%W*", "_")
if(b and o.M) then return e end
if(b and not o.M) then o.M = p end
table.insert(o, p); return e
end; return v
end]]
tTyp.Txt = tTyp.Txt.."\nlocal r = m:gsub(\""..fCat[1].."\",\"\"):gsub(\"%.mdl$\",\"\");"
for iD = 1, #fCat[2] do local v = fCat[2][iD]
tTyp.Txt = tTyp.Txt.."\nr = setBranch(r, \""..tostring(v[1]).."\", "..(v[2] and "true" or "false")..")"
end
tTyp.Txt = tTyp.Txt.."\no.M = nil; return o, r:gsub(\"^_+\", \"\"):gsub(\"_+$\", \"\"):gsub(\"_+\", \"_\") end"
elseif(isnumber(fCat)) then local tArg = {...}
tTyp = (tCat[sTyp] or {}); tCat[sTyp] = tTyp
tTyp.Txt = "function(m)"
tTyp.Txt = tTyp.Txt.."\nlocal n = math.floor(tonumber("..fCat..") or 0)"
tTyp.Txt = tTyp.Txt.."\nlocal m = m:gsub(\""..tostring(tArg[1] or "").."\", \"\")\n"
for i = 2, #tArg do local aP, aN = tArg[i], tArg[i+1]
if(aP and aN) then tTyp.Txt = tTyp.Txt.."\nlocal m = m:gsub(\""..aP.."\", \""..aN.."\")\n" end end
tTyp.Txt = tTyp.Txt..[[local t, x = {n = 0}, m:find("/", 1, true)
while(x and x > 0) do
t.n = t.n + 1
t[t.n] = m:sub(1, x-1)
m = m:sub(x+1, -1)
x = m:find("/", 1, true)
end; m = m:gsub("%.mdl$","")
if(n == 0) then return t, m end; local a = math.abs(n)
if(a > t.n) then return t, m end; local s = #t-a
if(n < 0) then for i = 1, a do t[i] = t[i+s] end end
while(s > 0) do table.remove(t); s = s - 1 end
return t, m
end]]
else LogInstance("Skip "..GetReport(fCat), ssLog); return nil end
tTyp.Cmp = CompileString("return ("..tTyp.Txt..")", sTyp)
local bS, vO = pcall(tTyp.Cmp); if(not bS) then
LogInstance("Failed "..GetReport(fCat)..": "..vO, ssLog); return nil end
tTyp.Cmp = vO; return sTyp, tTyp.Txt, tTyp.Cmp
end
end

Expand Down

0 comments on commit ed3ae57

Please sign in to comment.