Prevent DefaultContext from being unregistered from key event handlers
This commit is contained in:
@@ -3,4 +3,12 @@ package com.bartlomiejpluta.base.api.input;
|
||||
@FunctionalInterface
|
||||
public interface KeyEventHandler {
|
||||
void handleKeyEvent(KeyEvent event);
|
||||
|
||||
default void onKeyEventHandlerRegister() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
default void onKeyEventHandlerUnregister() {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.engine.audio.manager.SoundManager;
|
||||
import com.bartlomiejpluta.base.engine.core.engine.GameEngine;
|
||||
import com.bartlomiejpluta.base.engine.database.service.DatabaseService;
|
||||
import com.bartlomiejpluta.base.engine.error.AppException;
|
||||
import com.bartlomiejpluta.base.engine.gui.manager.FontManager;
|
||||
import com.bartlomiejpluta.base.engine.gui.manager.WidgetDefinitionManager;
|
||||
import com.bartlomiejpluta.base.engine.gui.render.NanoVGGUI;
|
||||
@@ -249,6 +250,11 @@ public class DefaultContext implements Context, KeyEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyEventHandlerUnregister() {
|
||||
throw new AppException("Context cannot be unregistered");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
gameRunner.update(dt);
|
||||
|
||||
@@ -54,10 +54,12 @@ public class GLFWInput implements Input {
|
||||
@Override
|
||||
public void addKeyEventHandler(@NonNull KeyEventHandler handler) {
|
||||
keyEventHandlers.addLast(handler);
|
||||
handler.onKeyEventHandlerRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeKeyEventHandler(@NonNull KeyEventHandler handler) {
|
||||
keyEventHandlers.remove(handler);
|
||||
handler.onKeyEventHandlerUnregister();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user