From f1c798576c3b4248ae35971d914d101697a5542b Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 3 Oct 2023 16:33:29 -0400 Subject: [PATCH] Fixed a bug --- .../rpi/legup/puzzle/battleship/BattleshipExporter.java | 9 ++++++++- .../edu/rpi/legup/puzzle/fillapix/FillapixExporter.java | 9 ++++++++- .../edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java | 9 ++++++++- .../edu/rpi/legup/puzzle/lightup/LightUpExporter.java | 9 ++++++++- .../java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java | 9 ++++++++- .../legup/puzzle/skyscrapers/SkyscrapersExporter.java | 9 ++++++++- .../java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java | 9 ++++++++- 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java index b954a1065..4205d0125 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class BattleshipExporter extends PuzzleExporter { @@ -18,7 +19,13 @@ public BattleshipExporter(Battleship battleShip) { */ @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - BattleshipBoard board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard(); + BattleshipBoard board; + if (puzzle.getTree() != null) { + board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (BattleshipBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java index f7dc9d375..757d14cd8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class FillapixExporter extends PuzzleExporter { @@ -12,7 +13,13 @@ public FillapixExporter(Fillapix fillapix) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - FillapixBoard board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard(); + FillapixBoard board; + if (puzzle.getTree() != null) { + board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (FillapixBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java index a23273ab4..344a0be92 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class HeyawakeExporter extends PuzzleExporter { @@ -12,7 +13,13 @@ public HeyawakeExporter(Heyawake heyawake) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - HeyawakeBoard board = (HeyawakeBoard) puzzle.getTree().getRootNode().getBoard(); + HeyawakeBoard board; + if (puzzle.getTree() != null) { + board = (HeyawakeBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (HeyawakeBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java index 78270e112..89024ad6c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class LightUpExporter extends PuzzleExporter { @@ -12,7 +13,13 @@ public LightUpExporter(LightUp lightUp) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - LightUpBoard board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard(); + LightUpBoard board; + if (puzzle.getTree() != null) { + board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (LightUpBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java index 471be22f1..e5fb071b4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class MasyuExporter extends PuzzleExporter { @@ -12,7 +13,13 @@ public MasyuExporter(Masyu masyu) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - MasyuBoard board = (MasyuBoard) puzzle.getTree().getRootNode().getBoard(); + MasyuBoard board; + if (puzzle.getTree() != null) { + board = (MasyuBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (MasyuBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java index dac09bd16..d5d5a9911 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class SkyscrapersExporter extends PuzzleExporter { @@ -12,7 +13,13 @@ public SkyscrapersExporter(Skyscrapers skyscrapers) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - SkyscrapersBoard board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard(); + SkyscrapersBoard board; + if (puzzle.getTree() != null) { + board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (SkyscrapersBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java index 5950fa7f4..45e320293 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import org.w3c.dom.Document; public class SudokuExporter extends PuzzleExporter { @@ -12,7 +13,13 @@ public SudokuExporter(Sudoku sudoku) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - SudokuBoard board = (SudokuBoard) puzzle.getTree().getRootNode().getBoard(); + SudokuBoard board; + if (puzzle.getTree() != null) { + board = (SudokuBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (SudokuBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("size", String.valueOf(board.getSize()));