1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package me.hammerle.snuviengine.api;
- import java.util.HashMap;
- public final class KeyHandler
- {
- private final static HashMap<Integer, KeyBinding> BINDINGS = new HashMap<>();
-
- public static KeyBinding register(int key) throws KeyDuplicateException
- {
- KeyBinding binding = new KeyBinding();
- if(BINDINGS.putIfAbsent(key, binding) != null)
- {
- throw new KeyDuplicateException("the key '" + key + "' has already been registered");
- }
- return binding;
- }
- protected static void onKeyDownEvent(int key)
- {
- KeyBinding binding = BINDINGS.get(key);
- if(binding != null)
- {
- binding.onKeyDownEvent();
- }
- }
- protected static void onKeyUpEvent(int key)
- {
- KeyBinding binding = BINDINGS.get(key);
- if(binding != null)
- {
- binding.onKeyUpEvent();
- }
- }
-
- protected static void tick()
- {
- BINDINGS.values().forEach(binding -> binding.tick());
- }
- }
|