Skip to content

Commit

Permalink
Merge 55504e9 into e16786b
Browse files Browse the repository at this point in the history
  • Loading branch information
dragontho committed Oct 24, 2019
2 parents e16786b + 55504e9 commit 132c1ea
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 67 deletions.
15 changes: 15 additions & 0 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ image::CommitActivityDiagram.png[]
** Cons: Requires dealing with commands that have already been undone: We must remember to skip these commands. Violates Single Responsibility Principle and Separation of Concerns as `HistoryManager` now needs to do two different things.
// end::undoredo[]

// tag::settings[]
=== Settings
==== Implementation
`AppSettings` was a class that was created to be integrated into the `Model` of the app. It currently contains these functionalities:

* `difficulty [EASY/MEDIUM/HARD]` to change the difficulty of the game.
* `hints [ON/OFF]` to turn hints on or off.
* `theme [DARK/LIGHT]` to change the theme of the app. Currently only supporting dark and light themes.

This feature provides the user an interface to make their own changes to the state of the machine. The settings set by the user will also be saved to a `.json` file under `data/appsettings.json`.
// end::settings[]


// end::settings[]

// tag::dataencryption[]
=== [Proposed] Data Encryption

Expand Down
41 changes: 41 additions & 0 deletions docs/diagrams/DifficultySequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@startuml
!include style.puml

Actor User as user USER_COLOR
Participant ":UI" as ui UI_COLOR
Participant ":AppManager" as appmanager APPMANAGER_COLOR
Participant ":Logic" as logic LOGIC_COLOR
Participant ":Model" as model MODEL_COLOR
Participant ":Storage" as storage STORAGE_COLOR

user -[USER_COLOR]> ui : "difficulty hard"
activate ui UI_COLOR

ui -[UI_COLOR]> appmanager : execute("difficulty hard")
activate appmanager APPMANAGER_COLOR

appmanager -[APPMANAGER_COLOR]> logic : execute("difficulty hard")
activate logic LOGIC_COLOR

logic -[LOGIC_COLOR]> model : deletePerson(p)
activate model MODEL_COLOR

model -[MODEL_COLOR]-> logic
deactivate model

logic -[LOGIC_COLOR]> storage : saveAddressBook(addressBook)
activate storage STORAGE_COLOR

storage -[STORAGE_COLOR]> storage : Save to file
activate storage STORAGE_COLOR_T1
deactivate storage

storage --[STORAGE_COLOR]> logic
deactivate storage

logic --[LOGIC_COLOR]> ui
deactivate logic

ui--[UI_COLOR]> user
deactivate ui
@enduml
2 changes: 2 additions & 0 deletions docs/diagrams/style.puml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
!define STORAGE_COLOR_T3 #806600
!define STORAGE_COLOR_T2 #544400

!define APPMANAGER_COLOR #D1D1D1

!define USER_COLOR #000000

skinparam BackgroundColor #FFFFFFF
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Modify parseCommand()
2 user modes: Game mode and Normal mode
*/

parserManager.updateState(model.bankLoaded(), model.gameIsOver());

Command command = parserManager.parseCommand(commandText);

/*
Expand All @@ -82,7 +84,7 @@ Modify parseCommand()

commandResult = command.execute(model);

parserManager.updateState(model.gameIsOver());
parserManager.updateState(model.bankLoaded(), model.gameIsOver());

// todo need to save wordbankstatistics after deletion.
// todo possible solution -> just save on every command like how the word bank is saved.
Expand Down Expand Up @@ -166,8 +168,12 @@ public void setGuiSettings(GuiSettings guiSettings) {
@Override
public void saveUpdatedWbStatistics(GameStatistics gameStatistics) throws CommandException {
try {
requireNonNull(model.getWordBankStatistics());
WordBankStatistics currWbStats = model.getWordBankStatistics();
WordBankStatistics currWbStats;
if (model.getWordBankStatistics() == null) {
currWbStats = WordBankStatistics.getEmpty("sample");
} else {
currWbStats = model.getWordBankStatistics();
}
currWbStats.update(gameStatistics, model.getCurrentGameDifficulty());

Path targetPath = Path.of(model.getUserPrefs().getDataFilePath().toString(), "wbstats",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ public class HomeCommand extends SwitchCommand {

public static final String COMMAND_WORD = "home";

public static final String MESSAGE_HOME_ACKNOWLEDGEMENT = "Going home as requested";

public static final String MESSAGE_HOME_ACKNOWLEDGEMENT = "Going home page as requested";

public ModeEnum getNewMode(ModeEnum old) throws ModeSwitchException {
return ModeEnum.HOME;
}

@Override
public CommandResult execute(Model model) {
return new CommandResult(MESSAGE_HOME_ACKNOWLEDGEMENT, false, false);
}

public ModeEnum getNewMode(ModeEnum old) throws ModeSwitchException {
return ModeEnum.APP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
/**
* Terminates the program.
*/
public class LoadScreenCommand extends SwitchCommand {
public class OpenCommand extends SwitchCommand {

public static final String COMMAND_WORD = "load";
public static final String COMMAND_WORD = "open";

public static final String MESSAGE_HOME_ACKNOWLEDGEMENT = "Opening bank";

public static final String MESSAGE_HOME_ACKNOWLEDGEMENT = "Going load page as requested";

public ModeEnum getNewMode(ModeEnum old) throws ModeSwitchException {
return ModeEnum.LOAD;
}

@Override
public CommandResult execute(Model model) {
return new CommandResult(MESSAGE_HOME_ACKNOWLEDGEMENT, false, false);
}

public ModeEnum getNewMode(ModeEnum old) throws ModeSwitchException {
return ModeEnum.OPEN;
}
}
26 changes: 14 additions & 12 deletions src/main/java/seedu/address/logic/parser/ParserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import seedu.address.logic.commands.settingcommands.HintsCommand;
import seedu.address.logic.commands.settingcommands.ThemeCommand;
import seedu.address.logic.commands.switches.HomeCommand;
import seedu.address.logic.commands.switches.LoadScreenCommand;
import seedu.address.logic.commands.switches.OpenCommand;
import seedu.address.logic.commands.switches.StartCommand;
import seedu.address.logic.commands.switches.SwitchToSettingsCommand;
import seedu.address.logic.parser.app.AddCommandParser;
Expand Down Expand Up @@ -61,16 +61,17 @@ public class ParserManager {

private ModeEnum mode;
private boolean gameIsOver;
private boolean bankLoaded;

private SpecificModeParser switchParser;
private SpecificModeParser currentParser;

public ParserManager () {
this.mode = ModeEnum.LOAD;
this.mode = ModeEnum.HOME;
this.gameIsOver = true;
this.switchParser = new SpecificModeParser();
switchParser.add(OpenCommand.class, null);
switchParser.add(HomeCommand.class, null);
switchParser.add(LoadScreenCommand.class, null);
switchParser.add(StartCommand.class, StartCommandParser.class);
switchParser.add(SwitchToSettingsCommand.class, null);
this.currentParser = setCurrentParser(this.mode);
Expand All @@ -84,7 +85,7 @@ private SpecificModeParser setCurrentParser(ModeEnum mode) {

SpecificModeParser temp = new SpecificModeParser();
switch (this.mode) {
case APP:
case OPEN:
temp.add(AddCommand.class, AddCommandParser.class);
temp.add(EditCommand.class, EditCommandParser.class);
temp.add(DeleteCommand.class, DeleteCommandParser.class);
Expand All @@ -94,7 +95,7 @@ private SpecificModeParser setCurrentParser(ModeEnum mode) {
temp.add(ExitCommand.class, null);
temp.add(HelpCommand.class, null);
return temp;
case LOAD:
case HOME:
temp.add(BankCommand.class, BankCommandParser.class);
temp.add(ImportCommand.class, ImportCommandParser.class);
temp.add(ExportCommand.class, ExportCommandParser.class);
Expand All @@ -121,13 +122,14 @@ private SpecificModeParser setCurrentParser(ModeEnum mode) {
* Sets new state within parsermanager if command was successful.
* @param command
*/
public void updateState(boolean gameIsOver) {
public void updateState(boolean bankLoaded, boolean gameIsOver) {
this.bankLoaded = bankLoaded;
this.gameIsOver = gameIsOver;
}

public List<AutoFillAction> getAutoFill(String input) {
List<AutoFillAction> temp = new ArrayList<>();
if (gameIsOver) {
if (gameIsOver && bankLoaded) {
for (AutoFillAction action : switchParser.getAutoFill(input)) {
temp.add(action);
}
Expand All @@ -148,7 +150,7 @@ public List<AutoFillAction> getAutoFill(String input) {
*/
public Command parseCommand(String userInput) throws ParseException, ModeSwitchException {
Command temp = null;
if (gameIsOver) {
if (gameIsOver && bankLoaded) {
temp = switchParser.parseCommand(userInput);
}
if (temp != null) {
Expand All @@ -166,12 +168,12 @@ public Command parseCommand(String userInput) throws ParseException, ModeSwitchE

public List<ModeEnum> getModes() {
List<ModeEnum> temp = new ArrayList<>();
if (gameIsOver) {
temp.add(ModeEnum.APP);
temp.add(ModeEnum.LOAD);
if (gameIsOver && bankLoaded) {
temp.add(ModeEnum.OPEN);
temp.add(ModeEnum.HOME);
temp.add(ModeEnum.SETTINGS);
temp.add(ModeEnum.GAME);
}
temp.add(ModeEnum.GAME);
return temp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.logic.commands.gamecommands.GuessCommand;
import seedu.address.logic.commands.settingcommands.ThemeCommand;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;
Expand All @@ -18,7 +17,7 @@ public ThemeCommand parse(String userInput) throws ParseException {
String trimmedArgs = userInput.trim();
if (trimmedArgs.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, GuessCommand.MESSAGE_USAGE));
String.format(MESSAGE_INVALID_COMMAND_FORMAT, "usage is theme <dark/light>"));
}
ThemeEnum theme;
switch (trimmedArgs.toUpperCase()) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/util/ModeEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/
public enum ModeEnum {

APP {
OPEN {
public String toString() {
return "home";
return "open";
}
},
GAME {
public String toString() {
return "game";
}
},
LOAD {
HOME {
public String toString() {
return "load";
return "home";
}
},
SETTINGS {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public interface Model {

boolean gameIsOver();

boolean bankLoaded();

Game getGame();


Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ public WordBankStatistics getWordBankStatistics() {
return this.wordBankStatistics;
}

@Override
public boolean bankLoaded() {
return !wordBank.getName().equals("Empty wordbank");
}

@Override
public void setWordBankStatistics(WordBankStatistics wordBankStats) {
this.wordBankStatistics = wordBankStats;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ private void handleFinishedGame() {
throw new IllegalStateException("gameStatistics in gameManager should not be null when game"
+ "is finished");
}

modularDisplay.swapToGameResult(modularDisplayPlaceholder, appManager.getGameStatistics(),
appManager.getActiveWordBankStatistics());
}
Expand All @@ -240,7 +241,7 @@ private CommandResult executeCommand(String commandText) throws CommandException
resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser());

//Updates the Ui.
updateUi.updateModularDisplay(commandText, uiLogicHelper.getMode(), modularDisplayPlaceholder);
updateUi.updateModularDisplay(uiLogicHelper.getMode(), modularDisplayPlaceholder);

updateUi.setTheme(appManager.getAppSettings().getDefaultTheme(), scene);

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/ui/ModularDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ public void swapToList(StackPane paneToDisplay) {
public void swapToGameResult(StackPane paneToDisplay, GameStatistics gameStatistics,
WordBankStatistics wbStatistics) {
paneToDisplay.getChildren().clear();
paneToDisplay.getChildren().add(new GameResultPanel(gameStatistics, wbStatistics).getRoot());
if (gameStatistics == null || wbStatistics == null) {
System.out.println("YOOOOO somthings null here");
} else {
paneToDisplay.getChildren().add(new GameResultPanel(gameStatistics, wbStatistics).getRoot());
}

}

/**
Expand Down
38 changes: 17 additions & 21 deletions src/main/java/seedu/address/ui/UpdateUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,38 @@ public UpdateUi(ModularDisplay modularDisplay, CurrentModeFooter currentModeFoot
/**
* Updates the {@code ModularDisplay} in {@code MainWindow}.
*
* @param command The command that triggers the update.
* @param modeEnum The mode that the app is currently in.
* @param modularDisplayPlaceholder {@code modularDisplayPlaceholder} in {@code MainWindow} that gets updated.
*/
public void updateModularDisplay(String command, ModeEnum modeEnum, StackPane modularDisplayPlaceholder) {
String firstArg = command.split(" ")[0];
if (firstArg.equals("load")) {
modularDisplay.swapToBanks(modularDisplayPlaceholder);
} else if (firstArg.equals("bank")) {
public void updateModularDisplay(ModeEnum modeEnum, StackPane modularDisplayPlaceholder) {
switch (modeEnum) {
case OPEN:
modularDisplay.swapToBankDisplay(modularDisplayPlaceholder);
} else if (firstArg.equals("list")) {
modularDisplay.swapToList(modularDisplayPlaceholder);
} else if (firstArg.equals("skip")) {

} else if (modeEnum.equals(ModeEnum.SETTINGS)) {
modularDisplay.swapToSettings(modularDisplayPlaceholder);
} else {
if (modeEnum.equals(ModeEnum.GAME)) {
// Swapping to load display by default disabled when in game mode (by Yida).
return;
}
break;
case HOME:
modularDisplay.swapToLoadDisplay(modularDisplayPlaceholder);
break;
case SETTINGS:
modularDisplay.swapToSettings(modularDisplayPlaceholder);
break;
default:
break;
}
}

public void setTheme(ThemeEnum theme, Scene scene) {
if (theme.equals(ThemeEnum.DARK)) {
scene.getStylesheets().remove(ThemeEnum.LIGHT.getThemeUrl());
scene.getStylesheets().remove(ThemeEnum.LIGHT.getExtensionUrl());
scene.getStylesheets().clear();
scene.getStylesheets().add(theme.getThemeUrl());
scene.getStylesheets().add(theme.getExtensionUrl());
} else {
scene.getStylesheets().remove(ThemeEnum.DARK.getThemeUrl());
scene.getStylesheets().remove(ThemeEnum.DARK.getExtensionUrl());
scene.getStylesheets().clear();
scene.getStylesheets().add(theme.getThemeUrl());
scene.getStylesheets().add(theme.getExtensionUrl());
}
for (String url: scene.getStylesheets()) {
System.out.println(url + "<--------------------------");
}
}

}

0 comments on commit 132c1ea

Please sign in to comment.