Package it.polimi.ingsw.Model
Class ModelWrapper
java.lang.Object
it.polimi.ingsw.Model.ModelWrapper
This class is used by the controller to enact the game logic and (optionally) notifies the view (ie the server)
whenever a meaningful change to the underlying data is carried out.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn interface that covers methods trying to access the Model. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionModelWrapper(Model model, OptionalValue<Lobby> lobby) Wraps aModelalong with aOptionalValueinvalid input: '<'Lobby> object to allow for easy notification to the view (ie the lobby component) of any and all changes to the model that are carried through this object's method:editModel(ModelModifier, boolean) -
Method Summary
Modifier and TypeMethodDescriptionvoideditModel(ModelWrapper.ModelModifier modelModifier, boolean keepUnsafeReference) When called, allows aModelWrapper.ModelModifiertype of function to carry out changes to theModel, then notifies the lobby of such changesmodelCopy(boolean sanitize) When called, returns a copy of the Model objectprivate voidWhen called, notifies all clients connected to the lobby of aModelUpdateEventand also (if necessary) of aGameOverEvent
-
Field Details
-
toNotify
-
model
-
-
Constructor Details
-
ModelWrapper
Wraps aModelalong with aOptionalValueinvalid input: '<'Lobby> object to allow for easy notification to the view (ie the lobby component) of any and all changes to the model that are carried through this object's method:editModel(ModelModifier, boolean)- Parameters:
model- a non null reference to the Modellobby- a non null optional value (can obviously be empty, but not null)
-
-
Method Details
-
notifyLobby
private void notifyLobby()When called, notifies all clients connected to the lobby of aModelUpdateEventand also (if necessary) of aGameOverEvent -
modelCopy
When called, returns a copy of the Model object- Parameters:
sanitize- if set to true, tells the method to remove theStudentBagreference to prevent peeking at the contents of the bag- Returns:
- an optionally sanitized clone of the wrapped
Modelobject
-
editModel
public void editModel(ModelWrapper.ModelModifier modelModifier, boolean keepUnsafeReference) throws Exception When called, allows aModelWrapper.ModelModifiertype of function to carry out changes to theModel, then notifies the lobby of such changes- Parameters:
modelModifier- a function or method that can be linked to theModelWrapper.ModelModifierinterfacekeepUnsafeReference- if set to true, the model reference is kept unaltered after a successful edit action, allowing for debugging introspection of the model. If unsure, set it to false for best security.- Throws:
Exception- the modelModifier can optionally throw Exceptions, which will be escalated to the caller.
-