Added better dependency injection mechanism and purified LoginScene

one thing could for whatever reason not be avoided: Even though the
processors of the caches inside WriteProxy are initialized, they somehow
get "de-initialized" and have to be initialized again...
This commit is contained in:
delvh
2020-09-01 20:14:02 +02:00
parent 88f28e60f1
commit 9f517cfc6b
14 changed files with 401 additions and 359 deletions

View File

@ -51,6 +51,12 @@ public final class Cache<T> implements Consumer<T>, Serializable {
*/
public void setProcessor(Consumer<T> processor) { this.processor = processor; }
/**
* @return the processor
* @since Envoy Client v0.2-beta
*/
public Consumer<T> getProcessor() { return processor; }
/**
* Relays all cached elements to the processor.
*

View File

@ -0,0 +1,97 @@
package envoy.client.data;
import javafx.stage.Stage;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
import envoy.client.ui.SceneContext;
/**
* Provides access to commonly used objects.
* <p>
* Project: <strong>client</strong><br>
* File: <strong>Context.java</strong><br>
* Created: <strong>01.09.2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public class Context {
private final Client client = new Client();
private WriteProxy writeProxy;
private LocalDB localDB;
private Stage stage;
private SceneContext sceneContext;
private static final Context instance = new Context();
/**
* @return the instance of {@code Context} used throughout Envoy
* @since Envoy Client v0.2-beta
*/
public static Context getInstance() { return instance; }
/**
* @return the localDB
* @since Envoy Client v0.2-beta
*/
public LocalDB getLocalDB() { return localDB; }
/**
* @param localDB the localDB to set
* @since Envoy Client v0.2-beta
*/
public void setLocalDB(LocalDB localDB) { this.localDB = localDB; }
/**
* @return the sceneContext
* @since Envoy Client v0.2-beta
*/
public SceneContext getSceneContext() { return sceneContext; }
/**
* @param sceneContext the sceneContext to set. Additionally sets the stage.
* @since Envoy Client v0.2-beta
*/
public void setSceneContext(SceneContext sceneContext) {
this.sceneContext = sceneContext;
stage = sceneContext.getStage();
}
/**
* @return the client
* @since Envoy Client v0.2-beta
*/
public Client getClient() { return client; }
/**
* @return the writeProxy
* @since Envoy Client v0.2-beta
*/
public WriteProxy getWriteProxy() { return writeProxy; }
/**
* @return the stage
* @since Envoy Client v0.2-beta
*/
public Stage getStage() { return stage; }
private Context() {}
/**
* @param writeProxy the writeProxy to set
* @since Envoy Client v0.2-beta
*/
public void setWriteProxy(WriteProxy writeProxy) { this.writeProxy = writeProxy; }
/**
* @param stage the stage to set
* @since Envoy Client v0.2-beta
*/
public void setStage(Stage stage) { this.stage = stage; }
}