package net.c0dei.rpg2d.hotkey;

import java.util.ArrayList;
import java.util.List;

import net.c0dei.rpg2d.EGameState;

import org.newdawn.slick.Input;

public class HotkeyManager {
	
	public List<Hotkey> hotkeys;
	
	public HotkeyManager() {
		hotkeys = new ArrayList<Hotkey>();
	}
	
	public void registerHotkey(Hotkey h) {
		hotkeys.add(h);
	}
	
	public void activate(String name, EGameState state) {
		if(hotkeys.size() > 0) for(Hotkey h : hotkeys) {
			if(h.key != -1) {
				if(h.name == name) {
					h.runSafe(state);
				}
			}
		}
	}
	
	public void update(Input i, EGameState state) {
		if(hotkeys.size() > 0) for(Hotkey h : hotkeys) {
			if(h.key != -1) {
				if(i.isKeyPressed(h.key)) {
					h.runSafe(state);
				}
			}
		}
	}
}