Enable database support in :engine
This commit is contained in:
@@ -12,6 +12,11 @@ import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.internal.gc.Disposable;
|
||||
import com.bartlomiejpluta.base.internal.logic.Updatable;
|
||||
import com.bartlomiejpluta.base.internal.render.Renderable;
|
||||
import com.bartlomiejpluta.base.util.lambda.UncheckedConsumer;
|
||||
import com.bartlomiejpluta.base.util.lambda.UncheckedFunction;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface Context extends Updatable, Renderable, Disposable {
|
||||
GameRunner getGameRunner();
|
||||
@@ -38,6 +43,10 @@ public interface Context extends Updatable, Renderable, Disposable {
|
||||
|
||||
Sound createSound(String soundUid);
|
||||
|
||||
void withDatabase(UncheckedConsumer<Connection, SQLException> consumer);
|
||||
|
||||
<T> T withDatabase(UncheckedFunction<Connection, T, SQLException> extractor);
|
||||
|
||||
void disposeSound(Sound sound);
|
||||
|
||||
void playSound(String soundUid);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.bartlomiejpluta.base.util.lambda;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface UncheckedConsumer<T, E extends Throwable> {
|
||||
|
||||
void accept(T t) throws E;
|
||||
|
||||
default UncheckedConsumer<T, E> andThen(UncheckedConsumer<? super T, ? extends E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (T t) -> {
|
||||
accept(t);
|
||||
after.accept(t);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.bartlomiejpluta.base.util.lambda;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface UncheckedFunction<T, R, E extends Throwable> {
|
||||
|
||||
R apply(T t) throws E;
|
||||
|
||||
default <V> UncheckedFunction<V, R, E> compose(UncheckedFunction<? super V, ? extends T, ? extends E> before) {
|
||||
Objects.requireNonNull(before);
|
||||
return (V v) -> apply(before.apply(v));
|
||||
}
|
||||
|
||||
default <V> UncheckedFunction<T, V, E> andThen(UncheckedFunction<? super R, ? extends V, ? extends E> after) {
|
||||
Objects.requireNonNull(after);
|
||||
return (T t) -> after.apply(apply(t));
|
||||
}
|
||||
|
||||
static <T, E extends Throwable> UncheckedFunction<T, T, E> identity() {
|
||||
return t -> t;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user