Class ModelWrapper

java.lang.Object
it.polimi.ingsw.Model.ModelWrapper

public class ModelWrapper extends Object
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.
  • Field Details

  • Constructor Details

    • ModelWrapper

      public ModelWrapper(Model model, OptionalValue<Lobby> lobby)
      Wraps a Model along with a OptionalValueinvalid 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 Model
      lobby - 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 a ModelUpdateEvent and also (if necessary) of a GameOverEvent
    • modelCopy

      public Model modelCopy(boolean sanitize)
      When called, returns a copy of the Model object
      Parameters:
      sanitize - if set to true, tells the method to remove the StudentBag 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 a ModelWrapper.ModelModifier type of function to carry out changes to the Model, then notifies the lobby of such changes
      Parameters:
      modelModifier - a function or method that can be linked to the ModelWrapper.ModelModifier interface
      keepUnsafeReference - 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.