Skip to content

Commit

Permalink
Merge pull request Bram-Hub#545 from MMosley502/puzzle_editor-short_t…
Browse files Browse the repository at this point in the history
…ruth_table-file_saving

Puzzle editor short truth table file saving
  • Loading branch information
MMosley502 authored Apr 28, 2023
2 parents beb60a2 + 1d1a562 commit 2e82547
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 141 deletions.
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ public boolean isValidDimensions(int rows, int columns) {
* @return true if the statements are valid for Short Truth Table, false otherwise
*/
public boolean isValidTextInput(String[] statements) {
if (statements.length == 0)
if (statements.length == 0) {
return false;

}
ShortTruthTableImporter importer = (ShortTruthTableImporter) this.getImporter();
for (String s : statements)
if (!importer.validGrammar(s))
for (String s : statements) {
if (!importer.validGrammar(s)) {
return false;
}
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package edu.rpi.legup.puzzle.shorttruthtable;

import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;

import edu.rpi.legup.puzzle.shorttruthtable.*;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand All @@ -24,6 +26,50 @@ public ShortTruthTableBoard(int width, int height, ShortTruthTableStatement[] st

}

/**
* Sets ShortTruthTable cell at position (x,y)
* @param x position on the x axis
* @param y position on the y axis
* @param e element to set the type of this ShortTruthTable cell to
*/
@Override
public void setCell(int x, int y, Element e, MouseEvent m) {
if (e != null && y * dimension.width + x >= puzzleElements.size() || x >= dimension.width ||
y >= dimension.height || x < 0 || y < 0) {
return;
}
else {
if (e != null) {
puzzleElements.get(y * dimension.width + x).setType(e, m);
int count = 0;
// remakes statement that included original cell to include new cell
for (ShortTruthTableStatement s : statements) {
for (int i = 0; i < s.getLength(); i++) {
if (s.getCell(i).getX() == x && s.getCell(i).getY() == y) {
List<ShortTruthTableCell> cells = new ArrayList<ShortTruthTableCell>();
// adds new cell to cell list
for (int c = 0; c < s.getLength(); c++) {
if (i == c) {
ShortTruthTableCell newC = new ShortTruthTableCell(s.getCell(i).getSymbol(), s.getCell(i).getType(), s.getCell(i).getLocation());
cells.add(newC);
}
else {
cells.add(s.getCell(c));
}
}

// modifies StringRep
String newS = s.getStringRep().substring(0, i) + cells.get(i).getSymbol() + s.getStringRep().substring(i + 1);
// makes modified statement
ShortTruthTableStatement temp = new ShortTruthTableStatement(newS, cells);
statements[count] = temp;
}
}
count++;
}
}
}
}

public Set<ShortTruthTableCell> getCellsWithSymbol(char symbol) {
Set<ShortTruthTableCell> cells = new HashSet<ShortTruthTableCell>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public ShortTruthTableExporter(ShortTruthTable stt) {
@Override
protected org.w3c.dom.Element createBoardElement(Document newDocument) {
ShortTruthTableBoard board = (ShortTruthTableBoard) puzzle.getTree().getRootNode().getBoard();

org.w3c.dom.Element boardElement = newDocument.createElement("board");

org.w3c.dom.Element dataElement = newDocument.createElement("data");
Expand Down

0 comments on commit 2e82547

Please sign in to comment.