<commit_before>package pl.shockah.godwit;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Timer;

import java.lang.reflect.Field;
import java.util.Comparator;
import java.util.List;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Delegate;
import pl.shockah.func.Action1;
import pl.shockah.util.SortedLinkedList;

public class GestureInputManager extends BaseInputManager<GestureInputManager.Processor> {
	@Nonnull protected static final Comparator<Processor> orderComparator = (o1, o2) -> -Float.compare(o1.order, o2.order);

	@Getter(AccessLevel.PROTECTED)
	@Nonnull private final List<Processor> processors = new SortedLinkedList<>(orderComparator);

	@Getter @Setter(AccessLevel.PROTECTED)
	@Nullable protected Processor exclusive = null;

	protected GestureInputManager() {
	}

	protected void resetupMultiplexer() {
		int count = multiplexer.getProcessors().size;
		for (int i = 0; i < count; i++) {
			multiplexer.removeProcessor(0);
		}
		for (Processor processor : getProcessors()) {
			multiplexer.addProcessor(processor.detector);
		}
	}

	public void removeProcessor(Processor processor) {
		if (getExclusive() == processor)
			Gdx.app.postRunnable(() -> setExclusive(null));
		super.removeProcessor(processor);
	}

	@Nonnull private GestureDetectorListenerWrapper wrap(@Nonnull GestureDetector.GestureListener listener) {
		return new GestureDetectorListenerWrapper(listener);
	}

	private class GestureDetectorListenerWrapper implements GestureDetector.GestureListener {
		@Nonnull public final GestureDetector.GestureListener wrapped;

		private GestureDetectorListenerWrapper(@Nonnull GestureDetector.GestureListener wrapped) {
			this.wrapped = wrapped;
		}

		@Override
		public boolean touchDown(float x, float y, int pointer, int button) {
			if (exclusive == null || exclusive == wrapped) {<commit_msg>Resetting gesture multiplexer when entering exclusive mode<commit_after>package pl.shockah.godwit;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Timer;

import java.lang.reflect.Field;
import java.util.Comparator;
import java.util.List;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.experimental.Delegate;
import pl.shockah.func.Action1;
import pl.shockah.util.SortedLinkedList;

public class GestureInputManager extends BaseInputManager<GestureInputManager.Processor> {
	@Nonnull protected static final Comparator<Processor> orderComparator = (o1, o2) -> -Float.compare(o1.order, o2.order);

	@Getter(AccessLevel.PROTECTED)
	@Nonnull private final List<Processor> processors = new SortedLinkedList<>(orderComparator);

	@Getter
	@Nullable private Processor exclusive = null;

	protected GestureInputManager() {
	}

	protected void resetupMultiplexer() {
		int count = multiplexer.getProcessors().size;
		for (int i = 0; i < count; i++) {
			multiplexer.removeProcessor(0);
		}

		if (exclusive == null) {
			for (Processor processor : getProcessors()) {
				multiplexer.addProcessor(processor.detector);
			}
		} else {
			multiplexer.addProcessor(exclusive.detector);
		}
	}

	public void removeProcessor(Processor processor) {
		if (getExclusive() == processor)
			Gdx.app.postRunnable(() -> setExclusive(null));
		super.removeProcessor(processor);
	}

	public void setExclusive(@Nullable Processor exclusive) {
		this.exclusive = exclusive;
		resetupMultiplexer();
	}

	@Nonnull private GestureDetectorListenerWrapper wrap(@Nonnull GestureDetector.GestureListener listener) {
		return new GestureDetectorListenerWrapper(listener);
	}

	private class GestureDetectorListenerWrapper implements GestureDetector.GestureListener {
		@Nonnull public final GestureDetector.GestureListener wrapped;

		private GestureDetectorListenerWrapper(@Nonnull GestureDetector.GestureListener wrapped) {
			this.wrapped = wrapped;
		}

		@Override
		public boolean touchDown(float x, float y, int pointer, int button) {
			if (exclusive == null || exclusive == wrapped) {
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.003738317757009346, 'mean_word_length': 5.731132075471698, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1366508', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1287, 'n_words': 284}