Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Bram-Hub/Legup into native-b…
Browse files Browse the repository at this point in the history
…inary-windows
  • Loading branch information
Chase-Grajeda committed Jul 21, 2022
2 parents bbbb3bc + 654c27d commit 8228639
Show file tree
Hide file tree
Showing 122 changed files with 3,650 additions and 1,166 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ An example for the Battleship puzzle demonstrates the proper format for XML file

```
<edu.rpi.legup.Legup>
<edu.rpi.legup.puzzle qualifiedClassName="edu.rpi.legup.puzzle.battleship.BattleShip">
<edu.rpi.legup.puzzle qualifiedClassName="edu.rpi.legup.puzzle.battleship.Battleship">
<board size="10">
<puzzleElement>
<puzzleElement value="1" x="2" y="0"/>
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/edu/rpi/legup/app/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Config {
private final static Logger Logger = LogManager.getLogger(Config.class.getName());

private Map<String, String> puzzles;
private Map<String, Boolean> fileCreationDisabledStatuses;
private static final String CONFIG_LOCATION = "edu/rpi/legup/legup/config";

/**
Expand All @@ -27,7 +28,8 @@ public class Config {
* @throws InvalidConfigException
*/
public Config() throws InvalidConfigException {
puzzles = new Hashtable<>();
this.puzzles = new Hashtable<>();
this.fileCreationDisabledStatuses = new Hashtable<>();
loadConfig(this.getClass().getClassLoader().getResourceAsStream(CONFIG_LOCATION));
}

Expand All @@ -40,6 +42,16 @@ public List<String> getPuzzleNames() {
return new ArrayList<>(puzzles.keySet());
}

public List<String> getFileCreationEnabledPuzzles()
{
LinkedList<String> puzzles = new LinkedList<String>();
for (String puzzle : this.puzzles.keySet())
if (!this.fileCreationDisabledStatuses.get(puzzle))
puzzles.add(puzzle);
return puzzles;
}


/**
* Gets a {@link edu.rpi.legup.model.Puzzle} class for a puzzle name
*
Expand Down Expand Up @@ -77,8 +89,10 @@ private void loadConfig(InputStream stream) throws InvalidConfigException {
Element puzzle = (Element) puzzleNodes.item(i);
String name = puzzle.getAttribute("name");
String className = puzzle.getAttribute("qualifiedClassName");
boolean status = Boolean.parseBoolean(puzzle.getAttribute("fileCreationDisabled").toLowerCase());
Logger.debug("Class Name: "+className);
puzzles.put(name, className);
this.puzzles.put(name, className);
this.fileCreationDisabledStatuses.put(name, Boolean.valueOf(status));
}

} catch (ParserConfigurationException | SAXException | IOException e) {
Expand Down
60 changes: 58 additions & 2 deletions src/main/java/edu/rpi/legup/app/GameBoardFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.tree.Tree;
import edu.rpi.legup.ui.ProofEditorPanel;
import edu.rpi.legup.ui.PuzzleEditorPanel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -42,6 +44,10 @@ public class GameBoardFacade implements IHistorySubject {

private LegupUI legupUI;

private ProofEditorPanel puzzleSolver;

private PuzzleEditorPanel puzzleEditor;

private String curFileName;

private History history;
Expand Down Expand Up @@ -73,13 +79,16 @@ public synchronized static GameBoardFacade getInstance() {
public void initializeUI() {
EventQueue.invokeLater(() ->{
legupUI = new LegupUI();
addHistoryListener(legupUI);
puzzleSolver = legupUI.getProofEditor();
puzzleEditor = legupUI.getPuzzleEditor();
addHistoryListener(legupUI.getProofEditor());
addHistoryListener(legupUI.getPuzzleEditor());
});
}

public void setPuzzle(Puzzle puzzle) {
this.puzzle = puzzle;
this.legupUI.setPuzzleView(puzzle);
this.puzzleSolver.setPuzzleView(puzzle);
this.history.clear();
}

Expand All @@ -93,10 +102,57 @@ public static void setupConfig() {
GameBoardFacade.getInstance().setConfig(config);
}


public void setPuzzleEditor(Puzzle puzzle) {
this.puzzle = puzzle;
this.puzzleEditor.setPuzzleView(puzzle);
}

public void setConfig(Config config) {
this.config = config;
}

/**
* Loads an empty puzzle
*
* @param game name of the puzzle
* @param rows the number of rows on the board
* @param columns the number of columns on the board
*/
public void loadPuzzle(String game, int rows, int columns) throws RuntimeException {
String qualifiedClassName = config.getPuzzleClassForName(game);
LOGGER.debug("Loading " + qualifiedClassName);

try {
Class<?> c = Class.forName(qualifiedClassName);
Constructor<?> cons = c.getConstructor();
Puzzle puzzle = (Puzzle) cons.newInstance();
setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle");

PuzzleImporter importer = puzzle.getImporter();
if (importer == null) {
LOGGER.error("Puzzle importer is null");
throw new RuntimeException("Puzzle importer null");
}

importer.initializePuzzle(rows, columns);

puzzle.initializeView();
// puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode());
setPuzzleEditor(puzzle);
}
catch (IllegalArgumentException exception)
{
throw new IllegalArgumentException(exception.getMessage());
}
catch(ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException | InstantiationException e)
{
LOGGER.error(e);
throw new RuntimeException("Puzzle creation error");
}
}

/**
* Loads a puzzle file
*
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
import edu.rpi.legup.model.rules.ContradictionRule;
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.rules.RuleType;
import edu.rpi.legup.ui.treeview.TreeView;
import edu.rpi.legup.ui.treeview.TreeViewSelection;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.HashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static edu.rpi.legup.app.GameBoardFacade.getInstance;

public class PuzzleKeyAccelerator implements KeyListener {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void mouseMoved(MouseEvent e) {
*/
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
System.out.println(e.getWheelRotation());
// System.out.println(e.getWheelRotation());
if (e.isControlDown()) {
if (e.getWheelRotation() != 0){
viewer.zoom(e.getWheelRotation() * 2, e.getPoint());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package edu.rpi.legup.controller;

import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.app.LegupPreferences;
import edu.rpi.legup.history.*;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.elements.Element;
import edu.rpi.legup.model.gameboard.CaseBoard;
import edu.rpi.legup.model.rules.*;
import edu.rpi.legup.model.tree.TreeElement;
import edu.rpi.legup.model.tree.TreeElementType;
import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;
import edu.rpi.legup.ui.puzzleeditorui.elementsview.ElementButton;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import static edu.rpi.legup.app.GameBoardFacade.getInstance;

public class EditorElementController implements ActionListener {
protected Object lastSource;

public EditorElementController() {
super();
}

public void buttonPressed(Element element) {
// TODO: implement what happens when element is pressed
}

@Override
public void actionPerformed(ActionEvent e) {
lastSource = e.getSource();
ElementButton button = (ElementButton) lastSource;
buttonPressed(button.getElement());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import edu.rpi.legup.ui.boardview.ElementSelection;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.boardview.SelectionItemView;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;
import edu.rpi.legup.history.ICommand;
import edu.rpi.legup.history.EditDataCommand;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/rpi/legup/controller/RuleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import edu.rpi.legup.model.gameboard.CaseBoard;
import edu.rpi.legup.model.rules.*;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.rulesview.RuleButton;
import edu.rpi.legup.ui.rulesview.RulePanel;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton;
import edu.rpi.legup.ui.proofeditorui.rulesview.RulePanel;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/rpi/legup/controller/TreeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.tree.Tree;
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
Expand Down Expand Up @@ -149,6 +150,6 @@ public void mouseMoved(MouseEvent e) {
*/
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
super.mouseWheelMoved(e);
super.viewer.scroll(e.getWheelRotation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.treeview.TreeElementView;
import edu.rpi.legup.ui.treeview.TreeView;
import edu.rpi.legup.ui.treeview.TreeViewSelection;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeView;
import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.rules.BasicRule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.awt.event.MouseEvent;
import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.observer.ITreeListener;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.util.List;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/history/EditDataCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.boardview.ElementView;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.awt.event.MouseEvent;
import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/rpi/legup/history/MergeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.rules.MergeRule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.rules.BasicRule;
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.rules.ContradictionRule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.ui.treeview.*;
import edu.rpi.legup.ui.proofeditorui.treeview.*;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Loading

0 comments on commit 8228639

Please sign in to comment.