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
Modifier and TypeClassDescriptionstatic interface
An interface that covers methods trying to access the Model. -
Field Summary
-
Constructor Summary
ConstructorDescriptionModelWrapper
(Model model, OptionalValue<Lobby> lobby) Wraps aModel
along with aOptionalValue
invalid 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 TypeMethodDescriptionvoid
editModel
(ModelWrapper.ModelModifier modelModifier, boolean keepUnsafeReference) When called, allows aModelWrapper.ModelModifier
type 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 void
When called, notifies all clients connected to the lobby of aModelUpdateEvent
and also (if necessary) of aGameOverEvent
-
Field Details
-
toNotify
-
model
-
-
Constructor Details
-
ModelWrapper
Wraps aModel
along with aOptionalValue
invalid 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 aModelUpdateEvent
and 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 theStudentBag
reference to prevent peeking at the contents of the bag- Returns:
- an optionally sanitized clone of the wrapped
Model
object
-
editModel
public void editModel(ModelWrapper.ModelModifier modelModifier, boolean keepUnsafeReference) throws Exception When called, allows aModelWrapper.ModelModifier
type 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.ModelModifier
interfacekeepUnsafeReference
- 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.
-