Tutorial 4 JSIActionGroupSwitch - MOARdV/AvionicsSystems GitHub Wiki

An example to compare RasterPropMonitor and Avionics Systems in implementing a JSIActionGroupSwitch replacement:

RasterPropMonitor:

PROP
{
	name = MOARdV.switchTumble_Backlight
	MODEL
	{
		model = ASET/ASET_Props/Control/Switch_Tumble/SwitchTumble
	}
	MODULE
	{
		name = JSIActionGroupSwitch
		animationName = SwitchTumbleAnim
		switchTransform = SwitchColider
		actionName = dummy
		perPodPersistenceName = BackLight
		switchSound = ASET/ASET_Props/Sounds/tumbleClick01
	}

	MODULE
	{
		name = JSILabel
		transformName = TextTopObj
		fontSize = 7.5
		labelText = PNL LIGHT
		oneshot = true
		transformOffset = 0.0250, -0.008
		fontName = Arial Bold
		alignment = Center
		anchor = MiddleCenter
		emissive = active
		variableName = CUSTOM_ALCOR_BACKLIGHT_ON
		positiveColor = COLOR_BacklightColor
		negativeColor = 255, 0, 0, 255
		zeroColor = COLOR_MOARdV_UnlitText
	}


	MODULE
	{
		name = JSICallbackAnimator
		variableName = CUSTOM_ALCOR_BACKLIGHT_ON

		VARIABLESET
		{
			scale = 0.5,1.1
			coloredObject = GlowBorder
			passiveColor = 0,0,0,255
			activeColor = COLOR_BacklightColor
		}
		VARIABLESET
		{
			coloredObject = TumblerMarkObj
			passiveColor = 0,0,0,255
			activeColor = 145,145,145,255
			scale = 0.5,1.1
		}
	}
}

Three modules, four components.

Avionics Systems:

PROP
{
	name = MOARdV.AS_switchTumble_Backlight
	MODEL
	{
		model = ASET/ASET_Props/Control/Switch_Tumble/SwitchTumble
	}
	MODULE
	{
		name = MASComponent
		
		COLLIDER_EVENT
		{
			name = Toggle switch
			collider = SwitchColider
			onClick = fc.TogglePersistent("Backlight")
		}
		
		ANIMATION_PLAYER
		{
			name = swToggle
			animation = SwitchTumbleAnim
			animationSpeed = 1.0
			variable = fc.GetPersistent("Backlight")
		}
		
		AUDIO_PLAYER
		{
			name = Clicker
			sound = ASET/ASET_Props/Sounds/tumbleClick01
			volume = 1.0
			trigger = BOTH
			variable = fc.GetPersistent("Backlight")
		}
		
		COLOR_SHIFT
		{
			name = Glow Border
			transform = GlowBorder
			passiveColor = 0,0,0,255
			activeColor = COLOR_BacklightColor
			variable = fc.Conditioned(fc.GetPersistentAsNumber("Backlight"))
		}
		COLOR_SHIFT
		{
			name = Tumbler Mark
			transform = TumblerMarkObj
			passiveColor = 0,0,0,255
			activeColor = 145,145,145,255
			variable = fc.Conditioned(fc.GetPersistentAsNumber("Backlight"))
		}
		TEXT_LABEL
		{
			name = Name Plate
			transform = TextTopObj
			fontSize = 7.5
			oneshot = true
			font = InconsolataGo-Bold
			alignment = Center
			anchor = MiddleCenter
			transformOffset = 0.0250, -0.008
			emissive = active
			variable = fc.Conditioned(fc.GetPersistentAsNumber("Backlight"))
			activeColor = COLOR_BacklightColor
			passiveColor = COLOR_MOARdV_UnlitText
			text = PNL LIGHT
		}
	}
}

Avionics Systems: one module, six components. However, there is finer control of the configuration: three of those components replace JSIActionGroupSwitch, allowing the collider event to be defined separately from the animation that is played and the sound that is played. The audio controller has more control, too. It can be configured to trigger when its controlling variable is enabled or disabled or both. Another improvement: for simple binary variables (0 is off, 1 is on), there is no need to define a range for the variable. MAS recognizes a value of 0 or less as "off", and greater than 0 as "on".

The backlight behavior in RPM is based on CUSTOM_ALCOR_BACKLIGHT_ON, which is based on several other custom variables that must be evaluated. In Avionics Systems, the backlight behavior is controlled by fc.Conditioned(), which will set a variable to 0 if there is insufficient power in the vessel, or if the vessel is under high g-forces (in which case the lights will flicker). fc.Conditioned makes the effects applied by CUSTOM_ALCOR_BACKLIGHT_ON part of core MAS, and it allows the effects to be tuned per-pod in the MASFlightComputer node of the pod's config.