Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- AIConveyorBelt
- AIDrivable
- AIFieldWorker
- AIImplement
- AIJobVehicle
- AIVehicle
- AIVehicleObstacle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- AutoLoader
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BigBag
- BunkerSiloCompacter
- BunkerSiloInteractor
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- CropSensor
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- ExtendedAIVehicle
- ExtendedCombine
- ExtendedMotorized
- ExtendedMower
- ExtendedSowingMachine
- ExtendedSprayer
- ExtendedWearable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- HeadlandAnimation
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- InlineWrapper
- JigglingParts
- Leveler
- LicensePlates
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- ManureSensor
- MixerWagon
- Motorized
- Mountable
- Mower
- Mulcher
- MultipleItemPurchase
- Pallet
- Pickup
- Pipe
- PlaceableAI
- PlaceableAnimatedObjects
- PlaceableBeehive
- PlaceableBeehivePalletSpa...
- PlaceableBunkerSilo
- PlaceableBuyingStation
- PlaceableCartridgePlayer
- PlaceableChargingStation
- PlaceableClearAreas
- PlaceableColorable
- PlaceableDeletedNodes
- PlaceableDoghouse
- PlaceableDynamicallyLoade...
- PlaceableFarmhouse
- PlaceableFence
- PlaceableFoliageAreas
- PlaceableGreenhouse
- PlaceableHighPressureWash...
- PlaceableHotspots
- PlaceableHusbandry
- PlaceableHusbandryAnimals
- PlaceableHusbandryFeeding...
- PlaceableHusbandryFence
- PlaceableHusbandryFood
- PlaceableHusbandryLiquidM...
- PlaceableHusbandryMilk
- PlaceableHusbandryPallets
- PlaceableHusbandryStraw
- PlaceableHusbandryWater
- PlaceableIncomePerHour
- PlaceableIndoorAreas
- PlaceableInfoTrigger
- PlaceableLeveling
- PlaceableLights
- PlaceableManureHeap
- PlaceablePlacement
- PlaceableProductionPoint
- PlaceableSellingStation
- PlaceableSilo
- PlaceableSiloExtension
- PlaceableSolarPanels
- PlaceableTipOcclusionArea...
- PlaceableTrainSystem
- PlaceableTriggerMarkers
- PlaceableVine
- PlaceableWardrobe
- PlaceableWeatherStation
- PlaceableWeighingStation
- PlaceableWindTurbine
- PlaceableWorkshop
- Plow
- PlowPacker
- PowerConsumer
- PowerTakeOffs
- PrecisionFarmingStatistic
- PushHandTool
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- RTKStation
- SaltSpreader
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SoilSampler
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StonePicker
- StrawBlower
- StumpCutter
- SupportVehicle
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TestAreas
- TipOccluder
- Trailer
- TreePlanter
- TreeSaplingPallet
- TreeSaw
- TurnOnVehicle
- VariableWorkWidth
- VehicleSettings
- VineCutter
- VineDetector
- VinePrepruner
- Washable
- WaterTrailer
- Wearable
- Weeder
- WeedSpotSpray
- Wheels
- WindBending
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
PlaceableColorable
DescriptionSpecialization for placeablesFunctions
- getAvailableColors
- getColor
- getHasColors
- loadFromXMLFile
- onLoad
- onReadStream
- onWriteStream
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerSavegameXMLPaths
- registerXMLPaths
- saveToXMLFile
- setColor
getAvailableColors
DescriptionDefinitiongetAvailableColors()Code
138 | function PlaceableColorable:getAvailableColors() |
139 | return self.spec_colorable.colors |
140 | end |
getColor
DescriptionDefinitiongetColor()Code
163 | function PlaceableColorable:getColor() |
164 | return self.spec_colorable.currentColorIndex |
165 | end |
getHasColors
DescriptionDefinitiongetHasColors()Code
169 | function PlaceableColorable:getHasColors() |
170 | return #self.spec_colorable.colors > 0 and #self.spec_colorable.nodes > 0 |
171 | end |
loadFromXMLFile
DescriptionDefinitionloadFromXMLFile()Code
119 | function PlaceableColorable:loadFromXMLFile(xmlFile, key) |
120 | local spec = self.spec_colorable |
121 | |
122 | spec.currentColorIndex = xmlFile:getValue(key .. ".color", math.min(#spec.colors, 1)) |
123 | self:setColor(spec.currentColorIndex) |
124 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
59 | function PlaceableColorable:onLoad(savegame) |
60 | local spec = self.spec_colorable |
61 | local xmlFile = self.xmlFile |
62 | |
63 | spec.nodes = {} |
64 | spec.colors = {} |
65 | spec.currentColorIndex = 0 |
66 | |
67 | xmlFile:iterate("placeable.colorable.nodes.node", function (_, nodeKey) |
68 | local node = xmlFile:getValue(nodeKey .. "#node", nil, self.components, self.i3dMappings) |
69 | if node ~= nil then |
70 | if not getHasShaderParameter(node, "colorScale0") then |
71 | Logging.xmlWarning(xmlFile, "Node '%s' has no shader parameter 'colorScale0' for key '%s'!", getName(node), nodeKey) |
72 | else |
73 | table.insert(spec.nodes, node) |
74 | end |
75 | end |
76 | end) |
77 | |
78 | xmlFile:iterate("placeable.colorable.colors.color", function (_, colorKey) |
79 | local color = xmlFile:getValue(colorKey .. "#value", nil, true) |
80 | |
81 | if color ~= nil then |
82 | table.insert(spec.colors, color) |
83 | end |
84 | |
85 | if #spec.colors == 255 then |
86 | return false |
87 | end |
88 | end) |
89 | |
90 | if #spec.colors > 0 then |
91 | self:setColor(1) |
92 | end |
93 | |
94 | if not self:getHasColors() then |
95 | SpecializationUtil.removeEventListener(self, "onWriteStream", PlaceableColorable) |
96 | SpecializationUtil.removeEventListener(self, "onReadStream", PlaceableColorable) |
97 | end |
98 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
102 | function PlaceableColorable:onReadStream(streamId, connection) |
103 | local spec = self.spec_colorable |
104 | |
105 | spec.currentColorIndex = streamReadUInt8(streamId) |
106 | self:setColor(spec.currentColorIndex) |
107 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
111 | function PlaceableColorable:onWriteStream(streamId, connection) |
112 | local spec = self.spec_colorable |
113 | |
114 | streamWriteUInt8(streamId, spec.currentColorIndex) |
115 | end |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
18 | function PlaceableColorable.prerequisitesPresent(specializations) |
19 | return true |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
33 | function PlaceableColorable.registerEventListeners(placeableType) |
34 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableColorable) |
35 | SpecializationUtil.registerEventListener(placeableType, "onWriteStream", PlaceableColorable) |
36 | SpecializationUtil.registerEventListener(placeableType, "onReadStream", PlaceableColorable) |
37 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableColorable.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "getAvailableColors", PlaceableColorable.getAvailableColors) |
26 | SpecializationUtil.registerFunction(placeableType, "setColor", PlaceableColorable.setColor) |
27 | SpecializationUtil.registerFunction(placeableType, "getColor", PlaceableColorable.getColor) |
28 | SpecializationUtil.registerFunction(placeableType, "getHasColors", PlaceableColorable.getHasColors) |
29 | end |
registerSavegameXMLPaths
DescriptionDefinitionregisterSavegameXMLPaths()Code
50 | function PlaceableColorable.registerSavegameXMLPaths(schema, basePath) |
51 | schema:setXMLSpecializationType("Colorable") |
52 | schema:register(XMLValueType.INT, basePath .. ".color", "Active color index") |
53 | schema:setXMLSpecializationType() |
54 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
41 | function PlaceableColorable.registerXMLPaths(schema, basePath) |
42 | schema:setXMLSpecializationType("Colorable") |
43 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".colorable.nodes.node(?)#node", "Bees action radius") |
44 | schema:register(XMLValueType.COLOR, basePath .. ".colorable.colors.color(?)#value", "Color") |
45 | schema:setXMLSpecializationType() |
46 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
128 | function PlaceableColorable:saveToXMLFile(xmlFile, key, usedModNames) |
129 | local spec = self.spec_colorable |
130 | |
131 | if self:getHasColors() then |
132 | xmlFile:setValue(key .. ".color", spec.currentColorIndex) |
133 | end |
134 | end |
setColor
DescriptionDefinitionsetColor()Code
144 | function PlaceableColorable:setColor(index) |
145 | local spec = self.spec_colorable |
146 | |
147 | index = math.min(index, #spec.colors) |
148 | spec.currentColorIndex = index |
149 | |
150 | -- No colors available |
151 | if index == 0 then |
152 | return |
153 | end |
154 | |
155 | local r, g, b = unpack(spec.colors[index]) |
156 | for _, node in ipairs(spec.nodes) do |
157 | setShaderParameter(node, "colorScale0", r, g, b, 1, false) |
158 | end |
159 | end |