private static bool onSwitchActivate(On.Celeste.Switch.orig_Activate orig, Switch self)
        {
            if (self.Entity.GetType().ToString() == "Celeste.Mod.OutbackHelper.MovingTouchSwitch")
            {
                DynData <TouchSwitch> selfData = new DynData <TouchSwitch>((TouchSwitch)self.Entity);
                if (selfData.Data.ContainsKey("flag"))
                {
                    DynData <Switch> selfSwitch = new DynData <Switch>(self);
                    string           flag       = selfData.Get <string>("flag");
                    Level            level      = self.Entity.SceneAs <Level>();

                    // do what the regular Switch.Activate() method does
                    if (self.Finished || self.Activated)
                    {
                        return(false);
                    }
                    selfSwitch["Activated"] = true;
                    if (self.OnActivate != null)
                    {
                        self.OnActivate();
                    }

                    // use the same logic as flag touch switches to determine if the group is complete.
                    return(FlagTouchSwitch.HandleCollectedFlagTouchSwitch(flag, inverted: false, selfData.Get <bool>("persistent"), level, selfData.Get <int>("id"),
                                                                          selfData.Get <List <FlagTouchSwitch> >("allTouchSwitchesInRoom"), selfData.Get <List <TouchSwitch> >("allMovingFlagTouchSwitchesInRoom"), () => { }));
                }
            }

            // if we are here, it means we aren't dealing with a flag moving touch switch.
            // so, we want regular behavior!
            return(orig(self));
        }
        public static Entity Load(Level level, LevelData levelData, Vector2 offset, EntityData entityData)
        {
            string flag = entityData.Attr("flag");

            if (level.Session.GetFlag(flag) || level.Session.GetFlag(flag + "_switch" + entityData.ID))
            {
                // moving touch switches can't be persistent, but we can very much spawn a flag touch switch instead!
                Vector2[] nodes        = entityData.Nodes;
                Vector2   origPosition = entityData.Position;
                entityData.Position = nodes[nodes.Length - 1];
                FlagTouchSwitch flagTouchSwitch = new FlagTouchSwitch(entityData, offset);
                entityData.Position = origPosition;
                return(flagTouchSwitch);
            }
            else
            {
                // build the moving touch switch
                TouchSwitch movingTouchSwitch = (TouchSwitch)Activator.CreateInstance(movingTouchSwitchType,
                                                                                      new object[] { entityData.NodesOffset(offset), entityData, offset });

                // save its attributes as DynData
                DynData <TouchSwitch> switchData = new DynData <TouchSwitch>(movingTouchSwitch);
                switchData["flag"]        = entityData.Attr("flag");
                switchData["id"]          = entityData.ID;
                switchData["persistent"]  = entityData.Bool("persistent", false);
                switchData["movingColor"] = Calc.HexToColor(entityData.Attr("movingColor", "FF8080"));

                // these attributes actually exist in TouchSwitch and as such, they work!
                switchData["inactiveColor"]   = Calc.HexToColor(entityData.Attr("inactiveColor", "5FCDE4"));
                switchData["activeColor"]     = Calc.HexToColor(entityData.Attr("activeColor", "FFFFFF"));
                switchData["finishColor"]     = Calc.HexToColor(entityData.Attr("finishColor", "F141DF"));
                switchData["P_RecoloredFire"] = new ParticleType(TouchSwitch.P_Fire)
                {
                    Color = switchData.Get <Color>("finishColor")
                };

                // set up the icon
                string iconAttribute = entityData.Attr("icon", "vanilla");
                Sprite icon          = new Sprite(GFX.Game, iconAttribute == "vanilla" ? "objects/touchswitch/icon" : $"objects/MaxHelpingHand/flagTouchSwitch/{iconAttribute}/icon");
                icon.Add("idle", "", 0f, default(int));
                icon.Add("spin", "", 0.1f, new Chooser <string>("spin", 1f), 0, 1, 2, 3, 4, 5);
                icon.Play("spin");
                icon.Color = switchData.Get <Color>("inactiveColor");
                icon.CenterOrigin();
                movingTouchSwitch.Remove(movingTouchSwitch.Get <Sprite>());
                movingTouchSwitch.Add(icon);
                movingTouchSwitchIcon.SetValue(movingTouchSwitch, icon);
                switchData["icon"] = icon;

                // collect the list of flag touch switches in the room as soon as the entity is awake, like regular flag touch switches.
                movingTouchSwitch.Add(new TouchSwitchListAttacher(entityData.Attr("flag")));

                return(movingTouchSwitch);
            }
        }