package speiger.src.coreengine.rendering.inputOld.bindings.utils;

import java.util.StringJoiner;

import speiger.src.coreengine.rendering.inputOld.Keyboard;

public final class ModType
{
	public static final int NONE = 0;
	public static final int CTRL = 1;
	public static final int SHIFT = 2;
	public static final int ALT = 4;
	public static final int IGNORE = 8;
	
	public static boolean isActive(int flags) {
		boolean ignore = (flags & IGNORE) != 0;
		return valid(Keyboard.isCtrlDown(), (flags & CTRL) != 0, ignore) && valid(Keyboard.isShiftDown(), (flags & SHIFT) != 0, ignore) && valid(Keyboard.isAltDown(), (flags & ALT) != 0, ignore);
	}
	
	public static String getMods(int flags) {
		flags &= ~IGNORE;
		if(flags == 0) return "";
		StringJoiner builder = new StringJoiner(" + ", "", " + ");
		if((flags & CTRL) != 0) builder.add("Ctrl");
		if((flags & SHIFT) != 0) builder.add("Shift");
		if((flags & ALT) != 0) builder.add("Alt");
		return builder.toString();
	}
	
	static boolean valid(boolean binding, boolean flags, boolean ignore) {
		return (flags == binding) || (!flags && ignore);
	}
}
