Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- AIConveyorBelt
- AIImplement
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BunkerSiloCompacter
- BunkerSiloInteractor
- BuyableBale
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- JigglingParts
- Leveler
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- MixerWagon
- Motorized
- Mountable
- Mower
- Pickup
- Pipe
- Plow
- PowerConsumer
- PowerTakeOffs
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StrawBlower
- StumpCutter
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TipOccluder
- Trailer
- TreePlanter
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Wearable
- Weeder
- Wheels
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
DynamicallyLoadedParts
DescriptionSpecialization for loading and linking external i3d files/assets (e.g. wheelChocks) to a vehicleFunctions
- loadDynamicallyPartsFromXML
- onDelete
- onLoad
- prerequisitesPresent
- registerEventListeners
- registerFunctions
loadDynamicallyPartsFromXML
DescriptionLoad dynamically loaded parts from xml and link them to targetDefinition
loadDynamicallyPartsFromXML(table dynamicallyLoadedPart, integer xmlFile, string key)Arguments
table | dynamicallyLoadedPart | dynamically loaded part |
integer | xmlFile | id of xml object |
string | key | key |
boolean | success | success |
70 | function DynamicallyLoadedParts:loadDynamicallyPartsFromXML(dynamicallyLoadedPart, xmlFile, key) |
71 | local filename = getXMLString(xmlFile, key .. "#filename") |
72 | if filename ~= nil then |
73 | dynamicallyLoadedPart.filename = filename |
74 | local i3dNode = g_i3DManager:loadSharedI3DFile(filename, self.baseDirectory, false, false, false) |
75 | if i3dNode ~= 0 then |
76 | local node = I3DUtil.indexToObject(i3dNode, Utils.getNoNil(getXMLString(xmlFile, key .. "#node"), "0|0"), self.i3dMappings) |
77 | local linkNode = I3DUtil.indexToObject(self.components, Utils.getNoNil(getXMLString(xmlFile, key .. "#linkNode"), "0>"), self.i3dMappings) |
78 | if linkNode == nil then |
79 | g_logManager:xmlWarning(self.configFileName, "Failed to load dynamicallyLoadedPart '%s'. Unable to find linkNode", key) |
80 | return false |
81 | end |
82 | |
83 | local x,y,z = StringUtil.getVectorFromString(getXMLString(xmlFile, key .. "#position")) |
84 | if x ~= nil and y ~= nil and z ~= nil then |
85 | setTranslation(node, x,y,z) |
86 | end |
87 | |
88 | local rotationNode = I3DUtil.indexToObject(i3dNode, getXMLString(xmlFile, key .. "#rotationNode"), self.i3dMappings) or node |
89 | local rotX, rotY, rotZ = StringUtil.getVectorFromString(getXMLString(xmlFile, key .. "#rotation")) |
90 | if rotX ~= nil and rotY ~= nil and rotZ ~= nil then |
91 | rotX = MathUtil.degToRad(rotX) |
92 | rotY = MathUtil.degToRad(rotY) |
93 | rotZ = MathUtil.degToRad(rotZ) |
94 | setRotation(rotationNode, rotX, rotY, rotZ) |
95 | end |
96 | |
97 | local shaderParameterName = getXMLString(xmlFile, key .. "#shaderParameterName") |
98 | local x,y,z,w = StringUtil.getVectorFromString(getXMLString(xmlFile, key .. "#shaderParameter")) |
99 | if shaderParameterName ~= nil and x ~= nil and y ~= nil and z ~= nil and w ~= nil then |
100 | setShaderParameter(node, shaderParameterName, x, y, z, w, false) |
101 | end |
102 | |
103 | link(linkNode, node) |
104 | delete(i3dNode) |
105 | return true |
106 | end |
107 | end |
108 | |
109 | return false |
110 | end |
onDelete
DescriptionDefinitiononDelete()Code
54 | function DynamicallyLoadedParts:onDelete() |
55 | local spec = self.spec_dynamicallyLoadedParts |
56 | |
57 | for _, part in pairs(spec.parts) do |
58 | if part.filename ~= nil then |
59 | g_i3DManager:releaseSharedI3DFile(part.filename, self.baseDirectory, true) |
60 | end |
61 | end |
62 | end |
onLoad
DescriptionDefinitiononLoad()Code
34 | function DynamicallyLoadedParts:onLoad(savegame) |
35 | local spec = self.spec_dynamicallyLoadedParts |
36 | |
37 | spec.parts = {} |
38 | local i=0 |
39 | while true do |
40 | local baseName = string.format("vehicle.dynamicallyLoadedParts.dynamicallyLoadedPart(%d)", i) |
41 | if not hasXMLProperty(self.xmlFile, baseName) then |
42 | break |
43 | end |
44 | local part = {} |
45 | if self:loadDynamicallyPartsFromXML(part, self.xmlFile, baseName) then |
46 | table.insert(spec.parts, part) |
47 | end |
48 | i = i + 1 |
49 | end |
50 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
15 | function DynamicallyLoadedParts.prerequisitesPresent(specializations) |
16 | return true |
17 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
27 | function DynamicallyLoadedParts.registerEventListeners(vehicleType) |
28 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", DynamicallyLoadedParts) |
29 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", DynamicallyLoadedParts) |
30 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
21 | function DynamicallyLoadedParts.registerFunctions(vehicleType) |
22 | SpecializationUtil.registerFunction(vehicleType, "loadDynamicallyPartsFromXML", DynamicallyLoadedParts.loadDynamicallyPartsFromXML) |
23 | end |