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
Foldable
DescriptionSpecialization for vehicle parts with two or three folding states (e.g. tedder, cultivator, sowing machine)Functions
- actionEventFold
- actionEventFoldMiddle
- allowLoadMovingToolStates
- getAllowDynamicMountObjects
- getAllowsLowering
- getCanAIImplementContinueWork
- getCanBeSelected
- getCanBeTurnedOn
- getCompensationAngleScale
- getFoldAnimTime
- getIsAdditionalCharacterActive
- getIsFoldAllowed
- getIsFoldMiddleAllowed
- getIsGroundAdjustedNodeActive
- getIsInputAttacherActive
- getIsInWorkPosition
- getIsLevelerPickupNodeActive
- getIsLowered
- getIsMovingToolActive
- getIsNextCoverStateAllowed
- getIsSpeedRotatingPartActive
- getIsSprayTypeActive
- getIsSteeringAxleAllowed
- getIsSupportAnimationAllowed
- getIsUnfolded
- getIsVersatileYRotActive
- getIsWorkAreaActive
- getSpecValueWorkingWidth
- getToggledFoldDirection
- getToggledFoldMiddleDirection
- getTurnedOnNotAllowedWarning
- initSpecialization
- isDetachAllowed
- loadAdditionalCharacterFromXML
- loadCompensationNodeFromXML
- loadDynamicWheelDataFromXML
- loadGroundAdjustedNodeFromXML
- loadInputAttacherJoint
- loadLevelerNodeFromXML
- loadMovingToolFromXML
- loadSpecValueWorkingWidth
- loadSpeedRotatingPartFromXML
- loadSprayTypeFromXML
- loadSteeringAxleFromXML
- loadSupportAnimationFromXML
- loadWorkAreaFromXML
- onAIImplementEnd
- onAIImplementEndLine
- onAIImplementStart
- onAIImplementStartLine
- onDeactivate
- onLoad
- onPostLoad
- onReadStream
- onRegisterActionEvents
- onSetLoweredAll
- onUpdate
- onWriteStream
- prerequisitesPresent
- registerEventListeners
- registerEvents
- registerFunctions
- registerLoweringActionEvent
- registerOverwrittenFunctions
- registerSelfLoweringActionEvent
- saveToXMLFile
- setAnimTime
- setFoldDirection
- setFoldState
- updateActionEventFold
- updateActionEventFoldMiddle
actionEventFold
DescriptionDefinitionactionEventFold()Code
1270 | function Foldable.actionEventFold(self, actionName, inputValue, callbackState, isAnalog) |
1271 | local spec = self.spec_foldable |
1272 | |
1273 | if table.getn(spec.foldingParts) > 0 then |
1274 | local toggleDirection = self:getToggledFoldDirection() |
1275 | if self:getIsFoldAllowed(toggleDirection, false) then |
1276 | if toggleDirection == spec.turnOnFoldDirection then |
1277 | self:setFoldState(toggleDirection, true) |
1278 | else |
1279 | self:setFoldState(toggleDirection, false) |
1280 | end |
1281 | end |
1282 | end |
1283 | end |
actionEventFoldMiddle
DescriptionDefinitionactionEventFoldMiddle()Code
1287 | function Foldable.actionEventFoldMiddle(self, actionName, inputValue, callbackState, isAnalog) |
1288 | local spec = self.spec_foldable |
1289 | if table.getn(spec.foldingParts) > 0 then |
1290 | if self:getIsFoldMiddleAllowed() then |
1291 | local direction = self:getToggledFoldMiddleDirection() |
1292 | if direction ~= 0 then |
1293 | if direction == spec.turnOnFoldDirection then |
1294 | self:setFoldState(direction, false) |
1295 | else |
1296 | self:setFoldState(direction, true) |
1297 | end |
1298 | |
1299 | -- equalize moveDown state of the attacher joint with the inverse fold middle state |
1300 | -- before we execute setJointMoveDown with the AttacherJoints.actionEventLowerImplement below |
1301 | -- so the fold middle state and the joint move down state are always in line |
1302 | if self.getAttacherVehicle ~= nil then |
1303 | local attacherVehicle = self:getAttacherVehicle() |
1304 | local attacherJointIndex = attacherVehicle:getAttacherJointIndexFromObject(self) |
1305 | if attacherJointIndex ~= nil then |
1306 | local attacherJoints = attacherVehicle:getAttacherJoints() |
1307 | local attacherJoint = attacherJoints[attacherJointIndex] |
1308 | |
1309 | attacherJoint.moveDown = direction ~= spec.turnOnFoldDirection |
1310 | end |
1311 | end |
1312 | end |
1313 | end |
1314 | end |
1315 | |
1316 | -- also execute the lower implement function if we are using the same action button to control the fold middle state |
1317 | if spec.foldMiddleLoweringOverwritten ~= nil and spec.foldMiddleLoweringOverwritten then |
1318 | AttacherJoints.actionEventLowerImplement(self, actionName, inputValue, callbackState, isAnalog) |
1319 | end |
1320 | end |
allowLoadMovingToolStates
DescriptionDefinitionallowLoadMovingToolStates()Code
556 | function Foldable:allowLoadMovingToolStates(superFunc) |
557 | local spec = self.spec_foldable |
558 | |
559 | if spec.foldAnimTime > spec.loadMovingToolStatesMaxLimit or spec.foldAnimTime < spec.loadMovingToolStatesMinLimit then |
560 | return false |
561 | end |
562 | |
563 | return superFunc(self) |
564 | end |
getAllowDynamicMountObjects
DescriptionDefinitiongetAllowDynamicMountObjects()Code
1013 | function Foldable:getAllowDynamicMountObjects(superFunc) |
1014 | local spec = self.spec_foldable |
1015 | local foldAnimTime = self:getFoldAnimTime() |
1016 | if foldAnimTime < spec.dynamicMountMinLimit or foldAnimTime > spec.dynamicMountMaxLimit then |
1017 | return false |
1018 | end |
1019 | |
1020 | return superFunc(self) |
1021 | end |
getAllowsLowering
DescriptionReturns true if tool can be loweredDefinition
getAllowsLowering()Return Values
boolean | detachAllowed | detach is allowed |
string | warning | [optional] warning text to display |
822 | function Foldable:getAllowsLowering(superFunc) |
823 | local spec = self.spec_foldable |
824 | |
825 | if spec.foldAnimTime > spec.loweringMaxLimit or spec.foldAnimTime < spec.loweringMinLimit then |
826 | return false, spec.unfoldWarning |
827 | end |
828 | |
829 | return superFunc(self) |
830 | end |
getCanAIImplementContinueWork
DescriptionDefinitiongetCanAIImplementContinueWork()Code
1144 | function Foldable:getCanAIImplementContinueWork(superFunc) |
1145 | local spec = self.spec_foldable |
1146 | |
1147 | local ret = true |
1148 | if table.getn(spec.foldingParts) > 0 and spec.allowUnfoldingByAI then |
1149 | ret = spec.foldAnimTime == spec.foldMiddleAnimTime or spec.foldAnimTime == 0 or spec.foldAnimTime == 1 |
1150 | end |
1151 | |
1152 | return superFunc(self) and ret |
1153 | end |
getCanBeSelected
DescriptionDefinitiongetCanBeSelected()Code
958 | function Foldable:getCanBeSelected(superFunc) |
959 | return true |
960 | end |
getCanBeTurnedOn
DescriptionDefinitiongetCanBeTurnedOn()Code
750 | function Foldable:getCanBeTurnedOn(superFunc) |
751 | local spec = self.spec_foldable |
752 | if spec.foldAnimTime > spec.turnOnFoldMaxLimit or spec.foldAnimTime < spec.turnOnFoldMinLimit then |
753 | return false |
754 | end |
755 | |
756 | return superFunc(self) |
757 | end |
getCompensationAngleScale
DescriptionDefinitiongetCompensationAngleScale()Code
614 | function Foldable:getCompensationAngleScale(superFunc, compensationNode) |
615 | local scale = superFunc(self, compensationNode) |
616 | |
617 | if compensationNode.foldAngleScale ~= nil then |
618 | local spec = self.spec_foldable |
619 | local animTime = 1-spec.foldAnimTime |
620 | if spec.foldMiddleAnimTime ~= nil then |
621 | scale = scale * MathUtil.lerp(compensationNode.foldAngleScale, 1, animTime / (1 - spec.foldMiddleAnimTime)) |
622 | else |
623 | scale = scale * MathUtil.lerp(compensationNode.foldAngleScale, 1, animTime) |
624 | end |
625 | end |
626 | |
627 | return scale |
628 | end |
getFoldAnimTime
DescriptionDefinitiongetFoldAnimTime()Code
479 | function Foldable:getFoldAnimTime() |
480 | local spec = self.spec_foldable |
481 | return spec.loadedFoldAnimTime or spec.foldAnimTime |
482 | end |
getIsAdditionalCharacterActive
DescriptionDefinitiongetIsAdditionalCharacterActive()Code
999 | function Foldable:getIsAdditionalCharacterActive(superFunc) |
1000 | local spec = self.spec_enterable |
1001 | if spec.additionalCharacterFoldMinLimit ~= nil and spec.additionalCharacterFoldMaxLimit ~= nil then |
1002 | local foldAnimTime = self:getFoldAnimTime() |
1003 | if foldAnimTime >= spec.additionalCharacterFoldMinLimit and foldAnimTime <= spec.additionalCharacterFoldMaxLimit then |
1004 | return true |
1005 | end |
1006 | end |
1007 | |
1008 | return superFunc(self) |
1009 | end |
getIsFoldAllowed
DescriptionDefinitiongetIsFoldAllowed()Code
486 | function Foldable:getIsFoldAllowed(direction, onAiTurnOn) |
487 | if self.getAttacherVehicle ~= nil and self:getAttacherVehicle() ~= nil then |
488 | local inputAttacherJoint = self:getActiveInputAttacherJoint() |
489 | if inputAttacherJoint.foldMinLimit ~= nil and inputAttacherJoint.foldMaxLimit ~= nil then |
490 | local foldAnimTime = self:getFoldAnimTime() |
491 | if foldAnimTime < inputAttacherJoint.foldMinLimit or foldAnimTime > inputAttacherJoint.foldMaxLimit then |
492 | return false |
493 | end |
494 | end |
495 | end |
496 | |
497 | return true |
498 | end |
getIsFoldMiddleAllowed
DescriptionDefinitiongetIsFoldMiddleAllowed()Code
502 | function Foldable:getIsFoldMiddleAllowed() |
503 | local spec = self.spec_foldable |
504 | return spec.foldMiddleAnimTime ~= nil |
505 | end |
getIsGroundAdjustedNodeActive
DescriptionDefinitiongetIsGroundAdjustedNodeActive()Code
913 | function Foldable:getIsGroundAdjustedNodeActive(superFunc, adjustedNode) |
914 | local spec = self.spec_foldable |
915 | |
916 | local foldAnimTime = spec.foldAnimTime |
917 | if foldAnimTime ~= nil and (foldAnimTime > adjustedNode.foldMaxLimit or foldAnimTime < adjustedNode.foldMinLimit) then |
918 | return false |
919 | end |
920 | |
921 | return superFunc(self, adjustedNode) |
922 | end |
getIsInputAttacherActive
DescriptionReturns true if input attacher is active and can be used to attachDefinition
getIsInputAttacherActive(table inputAttacherJoint)Arguments
table | inputAttacherJoint | input attacher joint |
boolean | isActive | input attacher is active |
975 | function Foldable:getIsInputAttacherActive(superFunc, inputAttacherJoint) |
976 | if inputAttacherJoint.foldMinLimit ~= nil and inputAttacherJoint.foldMaxLimit ~= nil then |
977 | local foldAnimTime = self:getFoldAnimTime() |
978 | if foldAnimTime < inputAttacherJoint.foldMinLimit or foldAnimTime > inputAttacherJoint.foldMaxLimit then |
979 | return false |
980 | end |
981 | end |
982 | |
983 | return superFunc(self, inputAttacherJoint) |
984 | end |
getIsInWorkPosition
DescriptionDefinitiongetIsInWorkPosition()Code
776 | function Foldable:getIsInWorkPosition(superFunc) |
777 | local spec = self.spec_foldable |
778 | |
779 | if spec.turnOnFoldDirection ~= 0 and not (table.getn(spec.foldingParts) == 0 or (spec.turnOnFoldDirection == -1 and spec.foldAnimTime == 0) or (spec.turnOnFoldDirection == 1 and spec.foldAnimTime == 1)) then |
780 | return false |
781 | end |
782 | |
783 | return superFunc(self) |
784 | end |
getIsLevelerPickupNodeActive
DescriptionDefinitiongetIsLevelerPickupNodeActive()Code
708 | function Foldable:getIsLevelerPickupNodeActive(superFunc, levelerNode) |
709 | local spec = self.spec_foldable |
710 | |
711 | if not levelerNode.foldLimitedOuterRange then |
712 | if spec.foldAnimTime > levelerNode.foldMaxLimit or spec.foldAnimTime < levelerNode.foldMinLimit then |
713 | return false |
714 | end |
715 | else |
716 | if spec.foldAnimTime <= levelerNode.foldMaxLimit and spec.foldAnimTime > levelerNode.foldMinLimit then |
717 | return false |
718 | end |
719 | end |
720 | |
721 | return superFunc(self, levelerNode) |
722 | end |
getIsLowered
DescriptionDefinitiongetIsLowered()Code
834 | function Foldable:getIsLowered(superFunc, default) |
835 | local spec = self.spec_foldable |
836 | |
837 | if self:getIsFoldMiddleAllowed() then |
838 | if spec.foldMiddleAnimTime ~= nil and spec.foldMiddleInputButton ~= nil then |
839 | |
840 | if spec.foldMoveDirection ~= 0 then |
841 | if spec.foldMiddleDirection > 0 then |
842 | if spec.foldAnimTime < spec.foldMiddleAnimTime + 0.01 then |
843 | return spec.foldMoveDirection < 0 and spec.moveToMiddle ~= true |
844 | end |
845 | else |
846 | if spec.foldAnimTime > spec.foldMiddleAnimTime - 0.01 then |
847 | return spec.foldMoveDirection > 0 and spec.moveToMiddle ~= true |
848 | end |
849 | end |
850 | else |
851 | if spec.foldMiddleDirection > 0 and spec.foldAnimTime < 0.01 then |
852 | return true |
853 | elseif spec.foldMiddleDirection < 0 and math.abs(1.0 - spec.foldAnimTime) < 0.01 then |
854 | return true |
855 | end |
856 | end |
857 | |
858 | return false |
859 | |
860 | end |
861 | end |
862 | |
863 | return superFunc(self, default) |
864 | end |
getIsMovingToolActive
DescriptionDefinitiongetIsMovingToolActive()Code
739 | function Foldable:getIsMovingToolActive(superFunc, movingTool) |
740 | local foldAnimTime = self:getFoldAnimTime() |
741 | if foldAnimTime > movingTool.foldMaxLimit or foldAnimTime < movingTool.foldMinLimit then |
742 | return false |
743 | end |
744 | |
745 | return superFunc(self, movingTool) |
746 | end |
getIsNextCoverStateAllowed
DescriptionDefinitiongetIsNextCoverStateAllowed()Code
761 | function Foldable:getIsNextCoverStateAllowed(superFunc, nextState) |
762 | if not superFunc(self, nextState) then |
763 | return false |
764 | end |
765 | |
766 | local spec = self.spec_foldable |
767 | if spec.foldAnimTime > spec.toggleCoverMaxLimit or spec.foldAnimTime < spec.toggleCoverMinLimit then |
768 | return false |
769 | end |
770 | |
771 | return true |
772 | end |
getIsSpeedRotatingPartActive
DescriptionDefinitiongetIsSpeedRotatingPartActive()Code
588 | function Foldable:getIsSpeedRotatingPartActive(superFunc, speedRotatingPart) |
589 | local spec = self.spec_foldable |
590 | |
591 | if not speedRotatingPart.foldLimitedOuterRange then |
592 | if spec.foldAnimTime > speedRotatingPart.foldMaxLimit or spec.foldAnimTime < speedRotatingPart.foldMinLimit then |
593 | return false |
594 | end |
595 | else |
596 | if spec.foldAnimTime <= speedRotatingPart.foldMaxLimit and spec.foldAnimTime > speedRotatingPart.foldMinLimit then |
597 | return false |
598 | end |
599 | end |
600 | |
601 | return superFunc(self, speedRotatingPart) |
602 | end |
getIsSprayTypeActive
DescriptionDefinitiongetIsSprayTypeActive()Code
937 | function Foldable:getIsSprayTypeActive(superFunc, sprayType) |
938 | local spec = self.spec_foldable |
939 | |
940 | if sprayType.foldMinLimit ~= nil and sprayType.foldMaxLimit ~= nil then |
941 | local foldAnimTime = spec.foldAnimTime |
942 | if foldAnimTime ~= nil and (foldAnimTime > sprayType.foldMaxLimit or foldAnimTime < sprayType.foldMinLimit) then |
943 | return false |
944 | end |
945 | end |
946 | |
947 | if sprayType.foldingConfigurationIndex ~= nil then |
948 | if (self.configurations["folding"] or 1) ~= sprayType.foldingConfigurationIndex then |
949 | return false |
950 | end |
951 | end |
952 | |
953 | return superFunc(self, sprayType) |
954 | end |
getIsSteeringAxleAllowed
DescriptionDefinitiongetIsSteeringAxleAllowed()Code
1057 | function Foldable:getIsSteeringAxleAllowed(superFunc) |
1058 | local spec = self.spec_attachable |
1059 | local foldAnimTime = self:getFoldAnimTime() |
1060 | if foldAnimTime < spec.foldMinLimit or foldAnimTime > spec.foldMaxLimit then |
1061 | return false |
1062 | end |
1063 | |
1064 | return superFunc(self) |
1065 | end |
getIsSupportAnimationAllowed
DescriptionReturns if support animation is allowed to playDefinition
getIsSupportAnimationAllowed()Code
1037 | function Foldable:getIsSupportAnimationAllowed(superFunc, supportAnimation) |
1038 | local foldAnimTime = self:getFoldAnimTime() |
1039 | if foldAnimTime < supportAnimation.foldMinLimit or foldAnimTime > supportAnimation.foldMaxLimit then |
1040 | return false |
1041 | end |
1042 | |
1043 | return superFunc(self, supportAnimation) |
1044 | end |
getIsUnfolded
DescriptionDefinitiongetIsUnfolded()Code
453 | function Foldable:getIsUnfolded() |
454 | local spec = self.spec_foldable |
455 | |
456 | if table.getn(spec.foldingParts) > 0 then |
457 | if spec.foldMiddleAnimTime ~= nil then |
458 | if (spec.turnOnFoldDirection == -1 and spec.foldAnimTime < spec.foldMiddleAnimTime + 0.01) or |
459 | (spec.turnOnFoldDirection == 1 and spec.foldAnimTime > spec.foldMiddleAnimTime - 0.01) |
460 | then |
461 | return true |
462 | else |
463 | return false |
464 | end |
465 | else |
466 | if (spec.turnOnFoldDirection == -1 and spec.foldAnimTime == 0) or (spec.turnOnFoldDirection == 1 and spec.foldAnimTime == 1) then |
467 | return true |
468 | else |
469 | return false |
470 | end |
471 | end |
472 | else |
473 | return true |
474 | end |
475 | end |
getIsVersatileYRotActive
DescriptionDefinitiongetIsVersatileYRotActive()Code
642 | function Foldable:getIsVersatileYRotActive(superFunc, wheel) |
643 | local spec = self.spec_foldable |
644 | |
645 | if spec.foldAnimTime > wheel.versatileFoldMaxLimit or spec.foldAnimTime < wheel.versatileFoldMinLimit then |
646 | return false |
647 | end |
648 | |
649 | return superFunc(self, wheel) |
650 | end |
getIsWorkAreaActive
DescriptionDefinitiongetIsWorkAreaActive()Code
674 | function Foldable:getIsWorkAreaActive(superFunc, workArea) |
675 | local spec = self.spec_foldable |
676 | |
677 | if not workArea.foldLimitedOuterRange then |
678 | if spec.foldAnimTime > workArea.foldMaxLimit or spec.foldAnimTime < workArea.foldMinLimit then |
679 | return false |
680 | end |
681 | else |
682 | if spec.foldAnimTime <= workArea.foldMaxLimit and spec.foldAnimTime > workArea.foldMinLimit then |
683 | return false |
684 | end |
685 | end |
686 | |
687 | return superFunc(self, workArea) |
688 | end |
getSpecValueWorkingWidth
DescriptionDefinitiongetSpecValueWorkingWidth()Code
1344 | function Foldable.getSpecValueWorkingWidth(storeItem, realItem, hasRealItem, config, formatted) |
1345 | if storeItem.specs.workingWidthVar ~= nil then |
1346 | local workingWidth = storeItem.specs.workingWidthVar[config or 1] |
1347 | if (formatted == nil or formatted) and workingWidth ~= nil then |
1348 | return string.format(g_i18n:getText("shop_workingWidthValue"), g_i18n:formatNumber(workingWidth, 1, true)) |
1349 | else |
1350 | return workingWidth |
1351 | end |
1352 | end |
1353 | |
1354 | return nil |
1355 | end |
getToggledFoldDirection
DescriptionDefinitiongetToggledFoldDirection()Code
509 | function Foldable:getToggledFoldDirection() |
510 | local spec = self.spec_foldable |
511 | |
512 | local foldMidTime = 0.5 |
513 | if spec.foldMiddleAnimTime ~= nil then |
514 | if spec.foldMiddleDirection > 0 then |
515 | foldMidTime = (1 + spec.foldMiddleAnimTime) * 0.5 |
516 | else |
517 | foldMidTime = spec.foldMiddleAnimTime * 0.5 |
518 | end |
519 | end |
520 | if spec.moveToMiddle then |
521 | return spec.foldMiddleDirection |
522 | elseif spec.foldMoveDirection > 0.1 or (spec.foldMoveDirection == 0 and spec.foldAnimTime > foldMidTime) then |
523 | return -1 |
524 | else |
525 | return 1 |
526 | end |
527 | end |
getToggledFoldMiddleDirection
DescriptionDefinitiongetToggledFoldMiddleDirection()Code
531 | function Foldable:getToggledFoldMiddleDirection() |
532 | local spec = self.spec_foldable |
533 | |
534 | local ret = 0 |
535 | if spec.foldMiddleAnimTime ~= nil then |
536 | if spec.foldMoveDirection > 0.1 then |
537 | ret = -1 |
538 | else |
539 | ret = 1 |
540 | end |
541 | if spec.foldMiddleDirection > 0 then |
542 | if spec.foldAnimTime >= spec.foldMiddleAnimTime - 0.01 then |
543 | ret = -1 |
544 | end |
545 | else |
546 | if spec.foldAnimTime <= spec.foldMiddleAnimTime + 0.01 then |
547 | ret = 1 |
548 | end |
549 | end |
550 | end |
551 | return ret |
552 | end |
getTurnedOnNotAllowedWarning
DescriptionDefinitiongetTurnedOnNotAllowedWarning()Code
788 | function Foldable:getTurnedOnNotAllowedWarning(superFunc) |
789 | local spec = self.spec_foldable |
790 | |
791 | if spec.foldAnimTime > spec.turnOnFoldMaxLimit or spec.foldAnimTime < spec.turnOnFoldMinLimit then |
792 | return spec.unfoldWarning |
793 | end |
794 | |
795 | return superFunc(self) |
796 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
103 | function Foldable.initSpecialization() |
104 | g_configurationManager:addConfigurationType("folding", g_i18n:getText("configuration_folding"), "foldable", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION) |
105 | |
106 | g_storeManager:addSpecType("workingWidthVar", "shopListAttributeIconWorkingWidth", Foldable.loadSpecValueWorkingWidth, Foldable.getSpecValueWorkingWidth) |
107 | end |
isDetachAllowed
DescriptionReturns true if detach is allowedDefinition
isDetachAllowed()Return Values
boolean | detachAllowed | detach is allowed |
string | warning | [optional] warning text to display |
802 | function Foldable:isDetachAllowed(superFunc) |
803 | local spec = self.spec_foldable |
804 | |
805 | if spec.foldAnimTime > spec.detachingMaxLimit or spec.foldAnimTime < spec.detachingMinLimit then |
806 | return false, spec.unfoldWarning |
807 | end |
808 | |
809 | if not spec.allowDetachingWhileFolding then |
810 | if (spec.foldMiddleAnimTime == nil or math.abs(spec.foldAnimTime-spec.foldMiddleAnimTime) > 0.001) and (spec.foldAnimTime > 0 and spec.foldAnimTime < 1) then |
811 | return false, spec.unfoldWarning |
812 | end |
813 | end |
814 | |
815 | return superFunc(self) |
816 | end |
loadAdditionalCharacterFromXML
DescriptionDefinitionloadAdditionalCharacterFromXML()Code
988 | function Foldable:loadAdditionalCharacterFromXML(superFunc, xmlFile) |
989 | local spec = self.spec_enterable |
990 | |
991 | spec.additionalCharacterFoldMinLimit = getXMLFloat(self.xmlFile, "vehicle.enterable.additionalCharacter#foldMinLimit") |
992 | spec.additionalCharacterFoldMaxLimit = getXMLFloat(self.xmlFile, "vehicle.enterable.additionalCharacter#foldMaxLimit") |
993 | |
994 | return superFunc(self, xmlFile) |
995 | end |
loadCompensationNodeFromXML
DescriptionDefinitionloadCompensationNodeFromXML()Code
606 | function Foldable:loadCompensationNodeFromXML(superFunc, compensationNode, xmlFile, key) |
607 | compensationNode.foldAngleScale = getXMLFloat(self.xmlFile, key.."#foldAngleScale") |
608 | |
609 | return superFunc(self, compensationNode, xmlFile, key) |
610 | end |
loadDynamicWheelDataFromXML
DescriptionDefinitionloadDynamicWheelDataFromXML()Code
632 | function Foldable:loadDynamicWheelDataFromXML(superFunc, xmlFile, key, wheelnamei, wheel) |
633 | local fallbackOldKey = "vehicle.wheels" |
634 | wheel.versatileFoldMinLimit = ConfigurationUtil.getConfigurationValue(xmlFile, key, wheelnamei, "#versatileFoldMinLimit", getXMLFloat, 0, nil, fallbackOldKey) |
635 | wheel.versatileFoldMaxLimit = ConfigurationUtil.getConfigurationValue(xmlFile, key, wheelnamei, "#versatileFoldMaxLimit", getXMLFloat, 1, nil, fallbackOldKey) |
636 | |
637 | return superFunc(self, xmlFile, key, wheelnamei, wheel) |
638 | end |
loadGroundAdjustedNodeFromXML
DescriptionDefinitionloadGroundAdjustedNodeFromXML()Code
897 | function Foldable:loadGroundAdjustedNodeFromXML(superFunc, xmlFile, key, adjustedNode) |
898 | if not superFunc(self, xmlFile, key, adjustedNode) then |
899 | return true |
900 | end |
901 | |
902 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMinLimit", key..".foldable#minLimit") --FS17 to FS19 |
903 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMaxLimit", key..".foldable#maxLimit") --FS17 to FS19 |
904 | |
905 | adjustedNode.foldMinLimit = getXMLFloat(xmlFile, key..".foldable#minLimit") or 0 |
906 | adjustedNode.foldMaxLimit = getXMLFloat(xmlFile, key..".foldable#maxLimit") or 1 |
907 | |
908 | return true |
909 | end |
loadInputAttacherJoint
DescriptionDefinitionloadInputAttacherJoint()Code
964 | function Foldable:loadInputAttacherJoint(superFunc, xmlFile, key, inputAttacherJoint, index) |
965 | inputAttacherJoint.foldMinLimit = getXMLFloat(xmlFile, key .. "#foldMinLimit2") |
966 | inputAttacherJoint.foldMaxLimit = getXMLFloat(xmlFile, key .. "#foldMaxLimit2") |
967 | |
968 | return superFunc(self, xmlFile, key, inputAttacherJoint, index) |
969 | end |
loadLevelerNodeFromXML
DescriptionDefinitionloadLevelerNodeFromXML()Code
692 | function Foldable:loadLevelerNodeFromXML(superFunc, levelerNode, xmlFile, key) |
693 | levelerNode.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false) |
694 | local minFoldLimit = 0 |
695 | local maxFoldLimit = 1 |
696 | if levelerNode.foldLimitedOuterRange then |
697 | minFoldLimit = 0.5 |
698 | maxFoldLimit = 0.5 |
699 | end |
700 | levelerNode.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMinLimit"), minFoldLimit) |
701 | levelerNode.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMaxLimit"), maxFoldLimit) |
702 | |
703 | return superFunc(self, levelerNode, xmlFile, key) |
704 | end |
loadMovingToolFromXML
DescriptionDefinitionloadMovingToolFromXML()Code
726 | function Foldable:loadMovingToolFromXML(superFunc, xmlFile, key, entry) |
727 | if not superFunc(self, xmlFile, key, entry) then |
728 | return false |
729 | end |
730 | |
731 | entry.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#foldMinLimit"), 0) |
732 | entry.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#foldMaxLimit"), 1) |
733 | |
734 | return true |
735 | end |
loadSpecValueWorkingWidth
DescriptionDefinitionloadSpecValueWorkingWidth()Code
1324 | function Foldable.loadSpecValueWorkingWidth(xmlFile, customEnvironment) |
1325 | local workingWidths = {} |
1326 | |
1327 | local i = 0 |
1328 | while true do |
1329 | local baseKey = string.format("vehicle.foldable.foldingConfigurations.foldingConfiguration(%d)", i) |
1330 | if not hasXMLProperty(xmlFile, baseKey) then |
1331 | break |
1332 | end |
1333 | |
1334 | workingWidths[i+1] = getXMLFloat(xmlFile, baseKey.."#workingWidth") |
1335 | |
1336 | i = i + 1 |
1337 | end |
1338 | |
1339 | return workingWidths |
1340 | end |
loadSpeedRotatingPartFromXML
DescriptionDefinitionloadSpeedRotatingPartFromXML()Code
568 | function Foldable:loadSpeedRotatingPartFromXML(superFunc, speedRotatingPart, xmlFile, key) |
569 | if not superFunc(self, speedRotatingPart, xmlFile, key) then |
570 | return false |
571 | end |
572 | |
573 | speedRotatingPart.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false) |
574 | local minFoldLimit = 0 |
575 | local maxFoldLimit = 1 |
576 | if speedRotatingPart.foldLimitedOuterRange then |
577 | minFoldLimit = 0.5 |
578 | maxFoldLimit = 0.5 |
579 | end |
580 | speedRotatingPart.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMinLimit"), minFoldLimit) |
581 | speedRotatingPart.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key.."#foldMaxLimit"), maxFoldLimit) |
582 | |
583 | return true |
584 | end |
loadSprayTypeFromXML
DescriptionDefinitionloadSprayTypeFromXML()Code
926 | function Foldable:loadSprayTypeFromXML(superFunc, xmlFile, key, sprayType) |
927 | sprayType.foldMinLimit = getXMLFloat(self.xmlFile, key.. "#foldMinLimit") |
928 | sprayType.foldMaxLimit = getXMLFloat(self.xmlFile, key.. "#foldMaxLimit") |
929 | |
930 | sprayType.foldingConfigurationIndex = getXMLInt(self.xmlFile, key.. "#foldingConfigurationIndex") |
931 | |
932 | return superFunc(self, xmlFile, key, sprayType) |
933 | end |
loadSteeringAxleFromXML
DescriptionDefinitionloadSteeringAxleFromXML()Code
1048 | function Foldable:loadSteeringAxleFromXML(superFunc, spec, xmlFile, key) |
1049 | spec.foldMinLimit = getXMLFloat(xmlFile, key.."#foldMinLimit") or 0 |
1050 | spec.foldMaxLimit = getXMLFloat(xmlFile, key.."#foldMaxLimit") or 1 |
1051 | |
1052 | return superFunc(self, spec, xmlFile, key) |
1053 | end |
loadSupportAnimationFromXML
DescriptionLoads support animation from xmlDefinition
loadSupportAnimationFromXML(table spec, int xmlFile, string key)Arguments
table | spec | spec |
int | xmlFile | xmlFile id |
string | key | key to load from |
1028 | function Foldable:loadSupportAnimationFromXML(superFunc, supportAnimation, xmlFile, key) |
1029 | supportAnimation.foldMinLimit = getXMLFloat(xmlFile, key.."#foldMinLimit") or 0 |
1030 | supportAnimation.foldMaxLimit = getXMLFloat(xmlFile, key.."#foldMaxLimit") or 1 |
1031 | |
1032 | return superFunc(self, supportAnimation, xmlFile, key) |
1033 | end |
loadWorkAreaFromXML
DescriptionDefinitionloadWorkAreaFromXML()Code
654 | function Foldable:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
655 | workArea.foldLimitedOuterRange = Utils.getNoNil(getXMLBool(xmlFile, key.."#foldLimitedOuterRange"), false) |
656 | local minFoldLimit = 0 |
657 | local maxFoldLimit = 1 |
658 | if workArea.foldLimitedOuterRange then |
659 | minFoldLimit = 0.5 |
660 | maxFoldLimit = 0.5 |
661 | end |
662 | |
663 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMinLimit", key..".folding#minLimit") --FS17 to FS19 |
664 | XMLUtil.checkDeprecatedXMLElements(xmlFile, self.configFileName, key.."#foldMaxLimit", key..".folding#maxLimit") --FS17 to FS19 |
665 | |
666 | workArea.foldMinLimit = Utils.getNoNil(getXMLFloat(xmlFile, key..".folding#minLimit"), minFoldLimit) |
667 | workArea.foldMaxLimit = Utils.getNoNil(getXMLFloat(xmlFile, key..".folding#maxLimit"), maxFoldLimit) |
668 | |
669 | return superFunc(self, workArea, xmlFile, key) |
670 | end |
onAIImplementEnd
DescriptionDefinitiononAIImplementEnd()Code
1097 | function Foldable:onAIImplementEnd() |
1098 | local spec = self.spec_foldable |
1099 | if spec.allowUnfoldingByAI and spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAIRaiseDirection ~= 0 then |
1100 | if spec.foldMiddleAIRaiseDirection > 0 then |
1101 | if spec.foldAnimTime > spec.foldMiddleAnimTime then |
1102 | self:setFoldState(spec.foldMiddleAIRaiseDirection, false, true) |
1103 | else |
1104 | self:setFoldState(spec.foldMiddleAIRaiseDirection, true, true) |
1105 | end |
1106 | else |
1107 | if spec.foldAnimTime < spec.foldMiddleAnimTime then |
1108 | self:setFoldState(spec.foldMiddleAIRaiseDirection, false, true) |
1109 | else |
1110 | self:setFoldState(spec.foldMiddleAIRaiseDirection, true, true) |
1111 | end |
1112 | end |
1113 | end |
1114 | end |
onAIImplementEndLine
DescriptionDefinitiononAIImplementEndLine()Code
1127 | function Foldable:onAIImplementEndLine() |
1128 | local spec = self.spec_foldable |
1129 | if spec.allowUnfoldingByAI and spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAIRaiseDirection ~= 0 then |
1130 | if spec.foldMiddleAIRaiseDirection > 0 then |
1131 | if spec.foldAnimTime < spec.foldMiddleAnimTime then |
1132 | self:setFoldState(1, true) |
1133 | end |
1134 | else |
1135 | if spec.foldAnimTime > spec.foldMiddleAnimTime then |
1136 | self:setFoldState(-1, true) |
1137 | end |
1138 | end |
1139 | end |
1140 | end |
onAIImplementStart
DescriptionDefinitiononAIImplementStart()Code
1088 | function Foldable:onAIImplementStart() |
1089 | local spec = self.spec_foldable |
1090 | if spec.allowUnfoldingByAI and spec.turnOnFoldDirection ~= 0 then |
1091 | self:setFoldState(spec.turnOnFoldDirection, true, true) |
1092 | end |
1093 | end |
onAIImplementStartLine
DescriptionDefinitiononAIImplementStartLine()Code
1118 | function Foldable:onAIImplementStartLine() |
1119 | local spec = self.spec_foldable |
1120 | if spec.allowUnfoldingByAI and spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAIRaiseDirection ~= 0 then |
1121 | self:setFoldState(-spec.foldMiddleAIRaiseDirection, false) |
1122 | end |
1123 | end |
onDeactivate
DescriptionDefinitiononDeactivate()Code
1157 | function Foldable:onDeactivate() |
1158 | self:setFoldDirection(0, true) |
1159 | end |
onLoad
DescriptionDefinitiononLoad()Code
111 | function Foldable:onLoad(savegame) |
112 | local spec = self.spec_foldable |
113 | |
114 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.foldingParts", "vehicle.foldable.foldingConfigurations.foldingConfiguration.foldingParts") --FS17 to FS19 |
115 | |
116 | local foldingConfigurationId = Utils.getNoNil(self.configurations["folding"], 1) |
117 | local configKey = string.format("vehicle.foldable.foldingConfigurations.foldingConfiguration(%d).foldingParts", foldingConfigurationId -1) |
118 | ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.foldable.foldingConfigurations.foldingConfiguration", foldingConfigurationId , self.components, self) |
119 | |
120 | -- fallback key |
121 | if not hasXMLProperty(self.xmlFile, configKey) then |
122 | configKey = "vehicle.foldable.foldingParts" |
123 | end |
124 | |
125 | spec.posDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#posDirectionText"), "action_foldOBJECT") |
126 | spec.negDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#negDirectionText"), "action_unfoldOBJECT") |
127 | spec.middlePosDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#middlePosDirectionText"), "action_liftOBJECT") |
128 | spec.middleNegDirectionText = Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#middleNegDirectionText"), "action_lowerOBJECT") |
129 | spec.startAnimTime = getXMLFloat(self.xmlFile, configKey.."#startAnimTime") |
130 | spec.foldMoveDirection = 0 |
131 | spec.moveToMiddle = false |
132 | if spec.startAnimTime == nil then |
133 | spec.startAnimTime = 0 |
134 | local startMoveDirection = Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#startMoveDirection"), 0) |
135 | if startMoveDirection > 0.1 then |
136 | spec.startAnimTime = 1 |
137 | end |
138 | end |
139 | spec.turnOnFoldDirection = 1 |
140 | if spec.startAnimTime > 0.5 then |
141 | spec.turnOnFoldDirection = -1 |
142 | end |
143 | |
144 | spec.turnOnFoldDirection = MathUtil.sign(Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#turnOnFoldDirection"), spec.turnOnFoldDirection)) |
145 | |
146 | spec.allowUnfoldingByAI = Utils.getNoNil(getXMLBool(self.xmlFile, configKey.."#allowUnfoldingByAI"), true) |
147 | |
148 | local foldInputButtonStr = getXMLString(self.xmlFile, configKey.."#foldInputButton"); |
149 | if foldInputButtonStr ~= nil then |
150 | spec.foldInputButton = InputAction[foldInputButtonStr]; |
151 | end |
152 | spec.foldInputButton = Utils.getNoNil(spec.foldInputButton, InputAction.IMPLEMENT_EXTRA2); |
153 | |
154 | local foldMiddleInputButtonStr = getXMLString(self.xmlFile, configKey.."#foldMiddleInputButton"); |
155 | if foldMiddleInputButtonStr ~= nil then |
156 | spec.foldMiddleInputButton = InputAction[foldMiddleInputButtonStr]; |
157 | end |
158 | spec.foldMiddleInputButton = Utils.getNoNil(spec.foldMiddleInputButton, InputAction.LOWER_IMPLEMENT); |
159 | |
160 | spec.foldMiddleAnimTime = getXMLFloat(self.xmlFile, configKey.."#foldMiddleAnimTime") |
161 | spec.foldMiddleDirection = Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#foldMiddleDirection"), 1) |
162 | spec.foldMiddleAIRaiseDirection = Utils.getNoNil(getXMLInt(self.xmlFile, configKey.."#foldMiddleAIRaiseDirection"), spec.foldMiddleDirection) |
163 | |
164 | spec.turnOnFoldMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#turnOnFoldMaxLimit"), 1) |
165 | spec.turnOnFoldMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#turnOnFoldMinLimit"), 0) |
166 | spec.toggleCoverMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#toggleCoverMaxLimit"), 1) |
167 | spec.toggleCoverMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#toggleCoverMinLimit"), 0) |
168 | spec.detachingMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#detachingMaxLimit"), 1) |
169 | spec.detachingMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#detachingMinLimit"), 0) |
170 | spec.allowDetachingWhileFolding = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#allowDetachingWhileFolding"), false) |
171 | spec.loweringMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loweringMaxLimit"), 1) |
172 | spec.loweringMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loweringMinLimit"), 0) |
173 | spec.loadMovingToolStatesMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loadMovingToolStatesMaxLimit"), 1) |
174 | spec.loadMovingToolStatesMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#loadMovingToolStatesMinLimit"), 0) |
175 | spec.dynamicMountMinLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#dynamicMountMinLimit"), 0) |
176 | spec.dynamicMountMaxLimit = Utils.getNoNil(getXMLFloat(self.xmlFile, configKey.."#dynamicMountMaxLimit"), 1) |
177 | spec.unfoldWarning = string.format(g_i18n:getText(Utils.getNoNil(getXMLString(self.xmlFile, configKey.."#unfoldWarning"), "warning_firstUnfoldTheTool"), self.customEnvironment), self.typeDesc) |
178 | |
179 | spec.foldAnimTime = 0 |
180 | spec.maxFoldAnimDuration = 0.0001 |
181 | |
182 | spec.foldingParts = {} |
183 | local i=0 |
184 | while true do |
185 | local baseName = string.format(configKey..".foldingPart(%d)", i) |
186 | if not hasXMLProperty(self.xmlFile, baseName) then |
187 | break |
188 | end |
189 | |
190 | local isValid = false |
191 | local entry = {} |
192 | entry.speedScale = Utils.getNoNil(getXMLFloat(self.xmlFile, baseName.."#speedScale"), 1) |
193 | local componentJointIndex = getXMLInt(self.xmlFile, baseName.. "#componentJointIndex") |
194 | local componentJoint = nil |
195 | if componentJointIndex ~= nil then |
196 | if componentJointIndex == 0 then |
197 | componentJointIndex = nil |
198 | g_logManager:xmlWarning(self.configFileName, "Invalid componentJointIndex for folding part '%s'. Indexing starts with 1!", baseName) |
199 | else |
200 | componentJoint = self.componentJoints[componentJointIndex] |
201 | entry.componentJoint = componentJoint |
202 | end |
203 | end |
204 | entry.anchorActor = Utils.getNoNil(getXMLInt(self.xmlFile, baseName.."#anchorActor"), 0) |
205 | |
206 | entry.animCharSet = 0 |
207 | |
208 | local rootNode = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, baseName.."#rootNode"), self.i3dMappings) |
209 | if rootNode ~= nil then |
210 | local animCharSet = getAnimCharacterSet(rootNode) |
211 | if animCharSet ~= 0 then |
212 | local clip = getAnimClipIndex(animCharSet, getXMLString(self.xmlFile, baseName.."#animationClip")) |
213 | if clip >= 0 then |
214 | isValid = true |
215 | |
216 | entry.animCharSet = animCharSet |
217 | assignAnimTrackClip(entry.animCharSet, 0, clip) |
218 | setAnimTrackLoopState(entry.animCharSet, 0, false) |
219 | entry.animDuration = getAnimClipDuration(entry.animCharSet, clip) |
220 | |
221 | end |
222 | end |
223 | end |
224 | -- try AnimatedVehicle specialization support |
225 | if not isValid then |
226 | local specAnimatedVehicle = self.spec_animatedVehicle |
227 | if specAnimatedVehicle ~= nil then --and self.playAnimation ~= nil and self.animations ~= nil then |
228 | local animationName = getXMLString(self.xmlFile, baseName.."#animationName") |
229 | if animationName ~= nil then |
230 | if specAnimatedVehicle.animations[animationName] ~= nil then |
231 | isValid = true |
232 | entry.animDuration = self:getAnimationDuration(animationName) |
233 | entry.animationName = animationName |
234 | end |
235 | end |
236 | end |
237 | end |
238 | |
239 | if isValid then |
240 | spec.maxFoldAnimDuration = math.max(spec.maxFoldAnimDuration, entry.animDuration) |
241 | if componentJoint ~= nil then |
242 | local node = self.components[componentJoint.componentIndices[((entry.anchorActor+1)%2)+1] ].node |
243 | entry.x,entry.y,entry.z = worldToLocal(componentJoint.jointNode, getWorldTranslation(node)) |
244 | entry.upX,entry.upY,entry.upZ = worldDirectionToLocal(componentJoint.jointNode, localDirectionToWorld(node, 0, 1, 0)) |
245 | entry.dirX,entry.dirY,entry.dirZ = worldDirectionToLocal(componentJoint.jointNode, localDirectionToWorld(node, 0, 0, 1)) |
246 | end |
247 | |
248 | table.insert(spec.foldingParts, entry) |
249 | end |
250 | i = i+1 |
251 | end |
252 | |
253 | if table.getn(spec.foldingParts) > 0 then |
254 | self.isSelectable = true |
255 | end |
256 | |
257 | spec.actionEventsLowering = {} |
258 | |
259 | if savegame ~= nil and not savegame.resetVehicles then |
260 | spec.loadedFoldAnimTime = getXMLFloat(savegame.xmlFile, savegame.key..".foldable#foldAnimTime") |
261 | end |
262 | |
263 | if spec.loadedFoldAnimTime == nil then |
264 | spec.loadedFoldAnimTime = spec.startAnimTime |
265 | end |
266 | |
267 | if spec.loadedFoldAnimTime <= 0 then |
268 | spec.foldMoveDirection = -1 |
269 | else |
270 | spec.foldMoveDirection = 1 |
271 | end |
272 | end |
onPostLoad
DescriptionDefinitiononPostLoad()Code
276 | function Foldable:onPostLoad(savegame) |
277 | local spec = self.spec_foldable |
278 | Foldable.setAnimTime(self, spec.loadedFoldAnimTime, false) |
279 | end |
onReadStream
DescriptionDefinitiononReadStream()Code
290 | function Foldable:onReadStream(streamId, connection) |
291 | local direction = streamReadUIntN(streamId, 2)-1 |
292 | local moveToMiddle = streamReadBool(streamId) |
293 | local animTime = streamReadFloat32(streamId) |
294 | Foldable.setAnimTime(self, animTime, false) |
295 | self:setFoldState(direction, moveToMiddle, true) |
296 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
1069 | function Foldable:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
1070 | if self.isClient then |
1071 | local spec = self.spec_foldable |
1072 | self:clearActionEventsTable(spec.actionEvents) |
1073 | |
1074 | if isActiveForInputIgnoreSelection then |
1075 | local isOnlyLowering = spec.foldMiddleAnimTime ~= nil and spec.foldMiddleAnimTime == 1 |
1076 | if table.getn(spec.foldingParts) > 0 and not isOnlyLowering then |
1077 | local _, actionEventId = self:addActionEvent(spec.actionEvents, spec.foldInputButton, self, Foldable.actionEventFold, false, true, false, true, nil) |
1078 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) |
1079 | Foldable.updateActionEventFold(self) |
1080 | end |
1081 | end |
1082 | end |
1083 | end |
onSetLoweredAll
DescriptionDefinitiononSetLoweredAll()Code
1163 | function Foldable:onSetLoweredAll(doLowering, jointDescIndex) |
1164 | local spec = self.spec_foldable |
1165 | if spec.foldMiddleAnimTime ~= nil then |
1166 | if self:getIsFoldMiddleAllowed() then |
1167 | if doLowering then |
1168 | self:setFoldState(-spec.foldMiddleAIRaiseDirection, false) |
1169 | else |
1170 | self:setFoldState(spec.foldMiddleAIRaiseDirection, true) |
1171 | end |
1172 | end |
1173 | end |
1174 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
311 | function Foldable:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
312 | local spec = self.spec_foldable |
313 | |
314 | -- update actionEvents |
315 | if self.isClient then |
316 | Foldable.updateActionEventFold(self) |
317 | if spec.foldMiddleAnimTime ~= nil then |
318 | Foldable.updateActionEventFoldMiddle(self) |
319 | end |
320 | end |
321 | |
322 | if math.abs(spec.foldMoveDirection) > 0.1 then |
323 | local isInvalid = false |
324 | local foldAnimTime = 0 |
325 | if spec.foldMoveDirection < -0.1 then |
326 | foldAnimTime = 1 |
327 | end |
328 | for _,foldingPart in pairs(spec.foldingParts) do |
329 | local charSet = foldingPart.animCharSet |
330 | if spec.foldMoveDirection > 0 then |
331 | local animTime |
332 | if charSet ~= 0 then |
333 | animTime = getAnimTrackTime(charSet, 0) |
334 | else |
335 | animTime = self:getRealAnimationTime(foldingPart.animationName) |
336 | end |
337 | if animTime < foldingPart.animDuration then |
338 | isInvalid = true |
339 | end |
340 | foldAnimTime = math.max(foldAnimTime, animTime / spec.maxFoldAnimDuration) |
341 | elseif spec.foldMoveDirection < 0 then |
342 | local animTime |
343 | if charSet ~= 0 then |
344 | animTime = getAnimTrackTime(charSet, 0) |
345 | else |
346 | animTime = self:getRealAnimationTime(foldingPart.animationName) |
347 | end |
348 | if animTime > 0 then |
349 | isInvalid = true |
350 | end |
351 | foldAnimTime = math.min(foldAnimTime, animTime / spec.maxFoldAnimDuration) |
352 | end |
353 | end |
354 | spec.foldAnimTime = MathUtil.clamp(foldAnimTime, 0, 1) |
355 | |
356 | if isInvalid and self.isServer then |
357 | for _,foldingPart in pairs(spec.foldingParts) do |
358 | if foldingPart.componentJoint ~= nil then |
359 | self:setComponentJointFrame(foldingPart.componentJoint, foldingPart.anchorActor) |
360 | end |
361 | end |
362 | end |
363 | end |
364 | end |
onWriteStream
DescriptionDefinitiononWriteStream()Code
300 | function Foldable:onWriteStream(streamId, connection) |
301 | local spec = self.spec_foldable |
302 | |
303 | local direction = MathUtil.sign(spec.foldMoveDirection)+1 |
304 | streamWriteUIntN(streamId, direction, 2) |
305 | streamWriteBool(streamId, spec.moveToMiddle) |
306 | streamWriteFloat32(streamId, spec.foldAnimTime) |
307 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
19 | function Foldable.prerequisitesPresent(specializations) |
20 | return true |
21 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
86 | function Foldable.registerEventListeners(vehicleType) |
87 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", Foldable) |
88 | SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", Foldable) |
89 | SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Foldable) |
90 | SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Foldable) |
91 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Foldable) |
92 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", Foldable) |
93 | SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", Foldable) |
94 | SpecializationUtil.registerEventListener(vehicleType, "onSetLoweredAll", Foldable) |
95 | SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStart", Foldable) |
96 | SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEnd", Foldable) |
97 | SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStartLine", Foldable) |
98 | SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEndLine", Foldable) |
99 | end |
registerEvents
DescriptionDefinitionregisterEvents()Code
25 | function Foldable.registerEvents(vehicleType) |
26 | SpecializationUtil.registerEvent(vehicleType, "onFoldStateChanged") |
27 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
31 | function Foldable.registerFunctions(vehicleType) |
32 | SpecializationUtil.registerFunction(vehicleType, "setFoldDirection", Foldable.setFoldDirection) |
33 | SpecializationUtil.registerFunction(vehicleType, "setFoldState", Foldable.setFoldState) |
34 | SpecializationUtil.registerFunction(vehicleType, "getIsUnfolded", Foldable.getIsUnfolded) |
35 | SpecializationUtil.registerFunction(vehicleType, "getFoldAnimTime", Foldable.getFoldAnimTime) |
36 | SpecializationUtil.registerFunction(vehicleType, "getIsFoldAllowed", Foldable.getIsFoldAllowed) |
37 | SpecializationUtil.registerFunction(vehicleType, "getIsFoldMiddleAllowed", Foldable.getIsFoldMiddleAllowed) |
38 | SpecializationUtil.registerFunction(vehicleType, "getToggledFoldDirection", Foldable.getToggledFoldDirection) |
39 | SpecializationUtil.registerFunction(vehicleType, "getToggledFoldMiddleDirection", Foldable.getToggledFoldMiddleDirection) |
40 | end |
registerLoweringActionEvent
DescriptionDefinitionregisterLoweringActionEvent()Code
868 | function Foldable:registerLoweringActionEvent(superFunc, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions) |
869 | local spec = self.spec_foldable |
870 | if table.getn(spec.foldingParts) > 0 then |
871 | if spec.foldMiddleAnimTime ~= nil then |
872 | self:clearActionEventsTable(spec.actionEventsLowering) |
873 | |
874 | local state, actionEventId = self:addActionEvent(spec.actionEventsLowering, spec.foldMiddleInputButton, self, Foldable.actionEventFoldMiddle, false, true, false, true, nil, nil, ignoreCollisions) |
875 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH) |
876 | Foldable.updateActionEventFoldMiddle(self) |
877 | |
878 | -- if we are using the same button we use only Foldable.actionEventFoldMiddle, if not, we use both |
879 | if spec.foldMiddleInputButton == inputAction then |
880 | spec.foldMiddleLoweringOverwritten = true |
881 | return state, actionEventId |
882 | end |
883 | end |
884 | end |
885 | |
886 | return superFunc(self, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName) |
887 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
44 | function Foldable.registerOverwrittenFunctions(vehicleType) |
45 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "allowLoadMovingToolStates", Foldable.allowLoadMovingToolStates) |
46 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSpeedRotatingPartFromXML", Foldable.loadSpeedRotatingPartFromXML) |
47 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSpeedRotatingPartActive", Foldable.getIsSpeedRotatingPartActive) |
48 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadCompensationNodeFromXML", Foldable.loadCompensationNodeFromXML) |
49 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCompensationAngleScale", Foldable.getCompensationAngleScale) |
50 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadDynamicWheelDataFromXML", Foldable.loadDynamicWheelDataFromXML) |
51 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsVersatileYRotActive", Foldable.getIsVersatileYRotActive) |
52 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadWorkAreaFromXML", Foldable.loadWorkAreaFromXML) |
53 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsWorkAreaActive", Foldable.getIsWorkAreaActive) |
54 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadLevelerNodeFromXML", Foldable.loadLevelerNodeFromXML) |
55 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsLevelerPickupNodeActive", Foldable.getIsLevelerPickupNodeActive) |
56 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadMovingToolFromXML", Foldable.loadMovingToolFromXML) |
57 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsMovingToolActive", Foldable.getIsMovingToolActive) |
58 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeTurnedOn", Foldable.getCanBeTurnedOn) |
59 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsNextCoverStateAllowed", Foldable.getIsNextCoverStateAllowed) |
60 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsInWorkPosition", Foldable.getIsInWorkPosition) |
61 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getTurnedOnNotAllowedWarning", Foldable.getTurnedOnNotAllowedWarning) |
62 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed", Foldable.isDetachAllowed) |
63 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowsLowering", Foldable.getAllowsLowering) |
64 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsLowered", Foldable.getIsLowered) |
65 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanAIImplementContinueWork", Foldable.getCanAIImplementContinueWork) |
66 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "registerLoweringActionEvent", Foldable.registerLoweringActionEvent) |
67 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "registerSelfLoweringActionEvent", Foldable.registerSelfLoweringActionEvent) |
68 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadGroundAdjustedNodeFromXML", Foldable.loadGroundAdjustedNodeFromXML) |
69 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsGroundAdjustedNodeActive", Foldable.getIsGroundAdjustedNodeActive) |
70 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSprayTypeFromXML", Foldable.loadSprayTypeFromXML) |
71 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSprayTypeActive", Foldable.getIsSprayTypeActive) |
72 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", Foldable.getCanBeSelected) |
73 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadInputAttacherJoint", Foldable.loadInputAttacherJoint) |
74 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsInputAttacherActive", Foldable.getIsInputAttacherActive) |
75 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadAdditionalCharacterFromXML", Foldable.loadAdditionalCharacterFromXML) |
76 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsAdditionalCharacterActive", Foldable.getIsAdditionalCharacterActive) |
77 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getAllowDynamicMountObjects", Foldable.getAllowDynamicMountObjects) |
78 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSupportAnimationFromXML", Foldable.loadSupportAnimationFromXML) |
79 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSupportAnimationAllowed", Foldable.getIsSupportAnimationAllowed) |
80 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "loadSteeringAxleFromXML", Foldable.loadSteeringAxleFromXML) |
81 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsSteeringAxleAllowed", Foldable.getIsSteeringAxleAllowed) |
82 | end |
registerSelfLoweringActionEvent
DescriptionDefinitionregisterSelfLoweringActionEvent()Code
891 | function Foldable:registerSelfLoweringActionEvent(superFunc, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions) |
892 | return Foldable.registerLoweringActionEvent(self, superFunc, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions) |
893 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
283 | function Foldable:saveToXMLFile(xmlFile, key, usedModNames) |
284 | local spec = self.spec_foldable |
285 | setXMLFloat(xmlFile, key.."#foldAnimTime", spec.foldAnimTime) |
286 | end |
setAnimTime
DescriptionDefinitionsetAnimTime()Code
1178 | function Foldable.setAnimTime(self, animTime, placeComponents) |
1179 | local spec = self.spec_foldable |
1180 | |
1181 | spec.foldAnimTime = animTime |
1182 | spec.loadedFoldAnimTime = nil |
1183 | for _,foldingPart in pairs(spec.foldingParts) do |
1184 | if foldingPart.animCharSet ~= 0 then |
1185 | enableAnimTrack(foldingPart.animCharSet, 0) |
1186 | setAnimTrackTime(foldingPart.animCharSet, 0, spec.foldAnimTime * foldingPart.animDuration, true) |
1187 | disableAnimTrack(foldingPart.animCharSet, 0) |
1188 | else |
1189 | animTime = (spec.foldAnimTime * spec.maxFoldAnimDuration) / self:getAnimationDuration(foldingPart.animationName) |
1190 | self:setAnimationTime(foldingPart.animationName, animTime, true) |
1191 | end |
1192 | end |
1193 | |
1194 | if placeComponents == nil then |
1195 | placeComponents = true |
1196 | end |
1197 | |
1198 | if self.updateCylinderedInitial ~= nil then |
1199 | self:updateCylinderedInitial(placeComponents) |
1200 | end |
1201 | |
1202 | if placeComponents then |
1203 | if self.isServer then |
1204 | for _,foldingPart in pairs(spec.foldingParts) do |
1205 | if foldingPart.componentJoint ~= nil then |
1206 | local componentJoint = foldingPart.componentJoint |
1207 | |
1208 | local jointNode = componentJoint.jointNode |
1209 | if foldingPart.anchorActor == 1 then |
1210 | jointNode = componentJoint.jointNodeActor1 |
1211 | end |
1212 | |
1213 | local node = self.components[componentJoint.componentIndices[ ((foldingPart.anchorActor + 1) % 2) + 1] ].node |
1214 | local x,y,z = localToWorld(jointNode, foldingPart.x, foldingPart.y, foldingPart.z) |
1215 | local upX,upY,upZ = localDirectionToWorld(jointNode, foldingPart.upX,foldingPart.upY,foldingPart.upZ) |
1216 | local dirX,dirY,dirZ = localDirectionToWorld(jointNode, foldingPart.dirX,foldingPart.dirY,foldingPart.dirZ) |
1217 | setWorldTranslation(node, x,y,z) |
1218 | I3DUtil.setWorldDirection(node, dirX,dirY,dirZ, upX,upY,upZ) |
1219 | |
1220 | self:setComponentJointFrame(componentJoint, foldingPart.anchorActor) |
1221 | end |
1222 | end |
1223 | end |
1224 | end |
1225 | end |
setFoldDirection
DescriptionDefinitionsetFoldDirection()Code
368 | function Foldable:setFoldDirection(direction, noEventSend) |
369 | self:setFoldState(direction, false, noEventSend) |
370 | end |
setFoldState
DescriptionDefinitionsetFoldState()Code
374 | function Foldable:setFoldState(direction, moveToMiddle, noEventSend) |
375 | local spec = self.spec_foldable |
376 | |
377 | if spec.foldMiddleAnimTime == nil then |
378 | moveToMiddle = false |
379 | end |
380 | if spec.foldMoveDirection ~= direction or spec.moveToMiddle ~= moveToMiddle then |
381 | if noEventSend == nil or noEventSend == false then |
382 | if g_server ~= nil then |
383 | g_server:broadcastEvent(FoldableSetFoldDirectionEvent:new(self, direction, moveToMiddle), nil, nil, self) |
384 | else |
385 | g_client:getServerConnection():sendEvent(FoldableSetFoldDirectionEvent:new(self, direction, moveToMiddle)) |
386 | end |
387 | end |
388 | spec.foldMoveDirection = direction |
389 | spec.moveToMiddle = moveToMiddle |
390 | |
391 | for _,foldingPart in pairs(spec.foldingParts) do |
392 | local speedScale = nil |
393 | -- We don't do any animations if we are already past the middle time |
394 | if spec.foldMoveDirection > 0.1 then |
395 | if not spec.moveToMiddle or spec.foldAnimTime < spec.foldMiddleAnimTime then |
396 | speedScale = foldingPart.speedScale |
397 | end |
398 | elseif spec.foldMoveDirection < -0.1 then |
399 | if not spec.moveToMiddle or spec.foldAnimTime > spec.foldMiddleAnimTime then |
400 | speedScale = -foldingPart.speedScale |
401 | end |
402 | end |
403 | |
404 | local charSet = foldingPart.animCharSet |
405 | if charSet ~= 0 then |
406 | if speedScale ~= nil then |
407 | if speedScale > 0 then |
408 | if getAnimTrackTime(charSet, 0) < 0.0 then |
409 | setAnimTrackTime(charSet, 0, 0.0) |
410 | end |
411 | else |
412 | if getAnimTrackTime(charSet, 0) > foldingPart.animDuration then |
413 | setAnimTrackTime(charSet, 0, foldingPart.animDuration) |
414 | end |
415 | end |
416 | setAnimTrackSpeedScale(charSet, 0, speedScale) |
417 | enableAnimTrack(charSet, 0) |
418 | else |
419 | disableAnimTrack(charSet, 0) |
420 | end |
421 | else |
422 | -- always stop to make sure the animation state is reset |
423 | local animTime |
424 | if self:getIsAnimationPlaying(foldingPart.animationName) then |
425 | animTime = self:getAnimationTime(foldingPart.animationName) |
426 | else |
427 | animTime = (spec.foldAnimTime * spec.maxFoldAnimDuration) / self:getAnimationDuration(foldingPart.animationName) |
428 | end |
429 | self:stopAnimation(foldingPart.animationName, true) |
430 | if speedScale ~= nil then |
431 | self:playAnimation(foldingPart.animationName, speedScale, animTime, true) |
432 | |
433 | if moveToMiddle then |
434 | local stopAnimTime = (spec.foldMiddleAnimTime * spec.maxFoldAnimDuration)/ self:getAnimationDuration(foldingPart.animationName) |
435 | self:setAnimationStopTime(foldingPart.animationName, stopAnimTime) |
436 | end |
437 | end |
438 | end |
439 | end |
440 | -- slightly move fold anim time, so that fold limits can trigger for different actions |
441 | if spec.foldMoveDirection > 0.1 then |
442 | spec.foldAnimTime = math.min(spec.foldAnimTime + 0.0001, math.max(spec.foldAnimTime, 1)) |
443 | elseif spec.foldMoveDirection < -0.1 then |
444 | spec.foldAnimTime = math.max(spec.foldAnimTime - 0.0001, math.min(spec.foldAnimTime, 0)) |
445 | end |
446 | |
447 | SpecializationUtil.raiseEvent(self, "onFoldStateChanged", direction, moveToMiddle) |
448 | end |
449 | end |
updateActionEventFold
DescriptionDefinitionupdateActionEventFold()Code
1229 | function Foldable.updateActionEventFold(self) |
1230 | local spec = self.spec_foldable |
1231 | local actionEvent = spec.actionEvents[spec.foldInputButton] |
1232 | if actionEvent ~= nil then |
1233 | local direction = self:getToggledFoldDirection() |
1234 | local state = self:getIsFoldAllowed(direction, false) |
1235 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, state) |
1236 | if state then |
1237 | local text |
1238 | if direction == spec.turnOnFoldDirection then |
1239 | text = spec.negDirectionText |
1240 | else |
1241 | text = spec.posDirectionText |
1242 | end |
1243 | g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText(text, self.customEnvironment), self.typeDesc)) |
1244 | end |
1245 | end |
1246 | end |
updateActionEventFoldMiddle
DescriptionDefinitionupdateActionEventFoldMiddle()Code
1250 | function Foldable.updateActionEventFoldMiddle(self) |
1251 | local spec = self.spec_foldable |
1252 | local actionEvent = spec.actionEventsLowering[spec.foldMiddleInputButton] |
1253 | if actionEvent ~= nil then |
1254 | local state = self:getIsFoldMiddleAllowed() |
1255 | g_inputBinding:setActionEventActive(actionEvent.actionEventId, state) |
1256 | if state then |
1257 | local text |
1258 | if self:getToggledFoldMiddleDirection() == spec.foldMiddleDirection then |
1259 | text = spec.middlePosDirectionText |
1260 | else |
1261 | text = spec.middleNegDirectionText |
1262 | end |
1263 | g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText(text, self.customEnvironment), self.typeDesc)) |
1264 | end |
1265 | end |
1266 | end |