/// <summary>
 /// Applied before RenderEveryTick runs.
 /// </summary>
 internal static bool Prefix(LogicBitSelectorSideScreen __instance,
                             Color ___activeColor, Color ___inactiveColor,
                             ILogicRibbonBitSelector ___target)
 {
     if (__instance != null && __instance.isActiveAndEnabled && ___target != null)
     {
         foreach (var pair in __instance.toggles_by_int)
         {
             int  bit = pair.Key;
             bool active = ___target.IsBitActive(bit), update = bit >= lastValues.
                                                                Count;
             if (!update)
             {
                 // If in range, see if bit changed
                 update = active != lastValues[bit];
                 if (update)
                 {
                     lastValues[bit] = active;
                 }
             }
             if (update)
             {
                 UpdateBit(pair.Value, active, ___activeColor, ___inactiveColor);
             }
         }
     }
     return(false);
 }
 /// <summary>
 /// Applied after OnSpawn runs.
 /// </summary>
 internal static void Postfix(LogicBitSelectorSideScreen __instance)
 {
     if (__instance != null)
     {
         __instance.UpdateInputOutputDisplay();
     }
     ForceUpdate(__instance);
 }
 /// <summary>
 /// Applied after OnSpawn runs.
 /// </summary>
 internal static void Postfix(LogicBitSelectorSideScreen __instance,
                              Color ___activeColor, Color ___inactiveColor,
                              ILogicRibbonBitSelector ___target)
 {
     if (__instance != null)
     {
         UPDATE_IO_DISPLAY.Invoke(__instance);
     }
     ForceUpdate(__instance, ___activeColor, ___inactiveColor, ___target);
 }
 /// <summary>
 /// Updates all bits of the logic bit selector side screen.
 /// </summary>
 private static void ForceUpdate(LogicBitSelectorSideScreen instance,
                                 Color activeColor, Color inactiveColor, ILogicRibbonBitSelector target)
 {
     lastValues.Clear();
     foreach (var pair in instance.toggles_by_int)
     {
         int  bit    = pair.Key;
         bool active = target.IsBitActive(bit);
         while (lastValues.Count <= bit)
         {
             lastValues.Add(false);
         }
         lastValues[bit] = active;
         UpdateBit(pair.Value, active, activeColor, inactiveColor);
     }
 }
        /// <summary>
        /// Updates all bits of the logic bit selector side screen.
        /// </summary>
        /// <param name="instance">The screen to update.</param>
        private static void ForceUpdate(LogicBitSelectorSideScreen instance)
        {
            var target        = instance.target;
            var activeColor   = instance.activeColor;
            var inactiveColor = instance.inactiveColor;
            var lv            = LAST_VALUES;

            lv.Clear();
            foreach (var pair in instance.toggles_by_int)
            {
                int  bit    = pair.Key;
                bool active = target.IsBitActive(bit);
                while (lv.Count <= bit)
                {
                    lv.Add(false);
                }
                lv[bit] = active;
                UpdateBit(pair.Value, active, activeColor, inactiveColor);
            }
        }
 /// <summary>
 /// Applied after RefreshToggles runs.
 /// </summary>
 internal static void Postfix(LogicBitSelectorSideScreen __instance,
                              Color ___activeColor, Color ___inactiveColor,
                              ILogicRibbonBitSelector ___target)
 {
     ForceUpdate(__instance, ___activeColor, ___inactiveColor, ___target);
 }
 /// <summary>
 /// Applied after RefreshToggles runs.
 /// </summary>
 internal static void Postfix(LogicBitSelectorSideScreen __instance)
 {
     ForceUpdate(__instance);
 }