#!/usr/bin/perl
#use Mooix::Thing;
#use Mooix::Root;
run sub {
	my $this=shift;
	%_=@_;
	my $oldloc=$_{oldloc};
	if ($this->state == $this->filterstate) {
		# Lights are off, so remove dark from old location and add
		# it to new. Only if they are rooms though.
		my $room=$Mooix::Root->concrete->room;
		if (ref $oldloc && $oldloc->isa($room)) {
			$oldloc->messagefilters->remove(object => $this->filter);
		}
		my $loc=$this->location;
		if (ref $loc && $loc->isa($room)){
			$loc->messagefilters->add(object=> $this->filter);
		}
		else {
			# New loc is not a room, so let's set the switch to
			# have no effect, so when it is added to a room, the
			# room does not immediatly become dark.
			$this->state(! $this->filterstate);
		}
	}
}
