local constructionutil = require "::/scripts/construction/constructionutil.lua" local vec3 = require "::/scripts/vec3.tl" local transf = require "::/scripts/mat4.tl" local function resolve(list, index) return list[index] or list[1] end function data() return { checkEnabledFn = function(captureParams, params) -- The game's API typedef passes (params, scriptRefParams); the wiki example shows the reverse. --local captureParams, params = first, second -- if captureParams.conditions == nil then -- captureParams, params = second, first -- end -- if captureParams.conditions == nil then -- return "Hidden" -- end debugPrint("----- checkEnabledScript -----") for _, condition in ipairs(captureParams.conditions) do debugPrint("Condition") debugPrint(condition.key) debugPrint("Specified Value") debugPrint(condition.value) debugPrint("Actual Value") debugPrint(params[condition.key]) if params[condition.key] ~= condition.value then debugPrint("Returning Hidden") return "Hidden" end end debugPrint("Returning Enabled") return "Enabled" end, updateFn = function(captureParams, params) debugPrint("Its-a me, updateFn!") local prefix = captureParams.prefix local names = {} -- The game also calls updateFn with no custom params set; fall back to the slider's centre position. local rotY = params[prefix .. "_rotY"] or 21 --local age = params[prefix .. "_age"] * 5 * 4 * 365 --5 years per notch on the slider, 4 parts per day, 365 days per year. local setIndex = params[prefix .. "_vehicle_set"] debugPrint("SET INDEX") debugPrint(setIndex) if not captureParams.sets[setIndex] then setIndex = 1 end local set = captureParams.sets[setIndex] local vehicleIndex = params[prefix .. "_vehicle_" .. setIndex] debugPrint("VEH INDEX") debugPrint(vehicleIndex) if not set.vehicles[vehicleIndex] then vehicleIndex = 1 end local vehicle = set.vehicles[vehicleIndex] local variantIndex = params[prefix .. "_variant_" .. setIndex .. "_" .. vehicleIndex] debugPrint("VAR INDEX") debugPrint(variantIndex) local modelId = resolve(vehicle.variants, variantIndex) -- Resolving Slider RotY if rotY < 20 then -- it defaults to position 21 = 0 degrees rotation rotY = -4 + rotY * 0.2 elseif rotY > 20 then rotY = 4 - (40-rotY) * 0.2 else rotY = 0 end local subconstruction = {} subconstruction.models = {} local transf = transf.scaleRotZYXTransl(vec3.new(1, 1, 1), vec3.degToRad (0, rotY, 0), vec3.new(0, 0, 0)) subconstruction.models[#subconstruction.models+1] = { id = modelId, transf = constructionutil.rotateTransf(params, transf), tag = "veh", } subconstruction.terrainAlignmentLists = { { type = "EQUAL", faces = { }, }, } local result = { } result.snapPoint = { transportModes = { "TRAIN", "ELECTRIC_TRAIN" }, allowSnapToBaseEdgeEnds = true, allowSnapToMesh = true, } result.subconstructions = { subconstruction } return result end, } end