Create ContextHolder helper class
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.bartlomiejpluta.base.api.context;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
public enum ContextHolder {
|
||||
INSTANCE;
|
||||
|
||||
@Getter
|
||||
private Context context;
|
||||
|
||||
public void setContext(@NonNull Context context) {
|
||||
if(this.context != null) {
|
||||
throw new IllegalStateException("Context cannot be reassigned");
|
||||
}
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.engine.context.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.context.ContextHolder;
|
||||
import com.bartlomiejpluta.base.api.runner.GameRunner;
|
||||
import com.bartlomiejpluta.base.engine.audio.manager.SoundManager;
|
||||
import com.bartlomiejpluta.base.engine.context.model.DefaultContext;
|
||||
@@ -66,7 +67,7 @@ public class DefaultContextManager implements ContextManager {
|
||||
var gameRunner = runnerClass.getConstructor().newInstance();
|
||||
|
||||
log.info("Building context up");
|
||||
return DefaultContext.builder()
|
||||
var context = DefaultContext.builder()
|
||||
.engine(engine)
|
||||
.entityManager(entityManager)
|
||||
.animationManager(animationManager)
|
||||
@@ -80,5 +81,9 @@ public class DefaultContextManager implements ContextManager {
|
||||
.gameRunner(gameRunner)
|
||||
.projectName(project.getName())
|
||||
.build();
|
||||
|
||||
ContextHolder.INSTANCE.setContext(context);
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user