From bd4a6dfc29e8c25798abd6ca02b54edb854610b4 Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Mon, 9 Feb 2015 20:48:08 +0100 Subject: [PATCH] add a shell script to code & run Signed-off-by: philippe lhardy --- README | 6 +- doit.sh | 75 +++++++++++++++++++++ java/org/artisanlogiciel/games/Display.java | 14 ++-- 3 files changed, 86 insertions(+), 9 deletions(-) create mode 100755 doit.sh diff --git a/README b/README index 679fda2..d6e8217 100644 --- a/README +++ b/README @@ -1,10 +1,13 @@ This is a personal project to generate a 2D maze using in depth path generation. -this can generate a stl file, overall goal was to print it with a 3D printer, i didn't test it yet ( even i hav actualy have a 3D printer ). +this can generate a stl file, overall goal was to print it with a 3D printer, i didn't test it yet ( even if i actualy have a 3D printer ). This is the very first usable part. It was developped under debian 7/8 but since it is java based it might be very easily recompiled or even just copied on other platform. + +there is a console gui menu base with ./doit.sh + run it by : cd java @@ -31,7 +34,6 @@ It was tested up to 1000x1000 labyrinth and can realy generate huge labyrinth. Entry of labyrinth is upper left corner, exit is lower right ( this is different in 3D since Y axis where reversed ). - BUGS are numerous, and every bug was cleverly designed to drive you mad. DOCUMENTATION is self contained in code an in my brain. diff --git a/doit.sh b/doit.sh new file mode 100755 index 0000000..ac8ac9a --- /dev/null +++ b/doit.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +do_code() +{ + background=$1 + find java/org/artisanlogiciel/games/ -name "*.java" | + { + s= + while read codeline + do + javafile=$(basename $codeline) + javaclass=${javafile/.java/} + echo "$javafile $javaclass" + s="$s $javaclass $codeline" + done + javaclass=$($DIALOG --menu "Run it" 20 100 10 $s 3>&1 1>&2 2>&3) + if [[ -n $javaclass ]] + then + pushd java + if [[ $background == codebg ]] + then + nohup make work/$javaclass & + else + make work/$javaclass + fi + popd + fi + } + +} + + +possible_console_gui="whiptail dialog" + +for DIALOG in $possible_console_gui +do + DIALOG=$(which $DIALOG) + if [[ -n $DIALOG ]] + then + break + fi +done + +if [[ -z $DIALOG ]] +then + echo "no console gui support (within $possible_console_gui) => no menus " + exit 1 +fi + +action=initial + +while [[ $action != quit ]] +do + action=$($DIALOG --menu "Run it" 20 80 8 run "Run it" test "Test it" readme "Read me" code "Code" codebg "Code in background" quit "Quit" 3>&1 1>&2 2>&3) + + if [[ $action == run ]] + then + echo "run it" + pushd java + make display + popd + elif [[ $action == test ]] + then + echo "test it" + pushd java + make display + popd + elif [[ $action =~ code ]] + then + do_code $action + elif [[ $action == readme ]] + then + $DIALOG --textbox README 20 80 + fi +done diff --git a/java/org/artisanlogiciel/games/Display.java b/java/org/artisanlogiciel/games/Display.java index 9dc4ed8..18285dd 100644 --- a/java/org/artisanlogiciel/games/Display.java +++ b/java/org/artisanlogiciel/games/Display.java @@ -106,7 +106,7 @@ public class Display extends JFrame goNorth(); } }; - JButton north = addDirection("North", "UP", goNorth); + JButton north = addDirection(this,"North", "UP", goNorth); Action goEast = new AbstractAction() { public void actionPerformed(ActionEvent evt) @@ -116,7 +116,7 @@ public class Display extends JFrame goEast(); } }; - JButton east = addDirection("East", "RIGHT", goEast); + JButton east = addDirection(this,"East", "RIGHT", goEast); Action goWest = new AbstractAction() { @@ -127,7 +127,7 @@ public class Display extends JFrame goWest(); } }; - JButton west = addDirection("West", "LEFT", goWest); + JButton west = addDirection(this,"West", "LEFT", goWest); Action goSouth = new AbstractAction() { public void actionPerformed(ActionEvent evt) @@ -137,7 +137,7 @@ public class Display extends JFrame goSouth(); } }; - JButton south = addDirection("South", "DOWN", goSouth); + JButton south = addDirection(this,"South", "DOWN", goSouth); add(button,BorderLayout.CENTER); controlPanel.add(north,BorderLayout.NORTH); @@ -157,14 +157,14 @@ public class Display extends JFrame } - private JButton addDirection(final String direction, String key, Action goAction) + private JButton addDirection(final JPanel panel, final String direction, String key, Action goAction) { String actionName = "go" + direction; JButton button = new JButton(direction); button.addActionListener(goAction); KeyStroke keystroke=KeyStroke.getKeyStroke(key); - //getInputMap().put(keystroke,actionName); - //getActionMap().put(actionName,goAction); + panel.getInputMap().put(keystroke,actionName); + panel.getActionMap().put(actionName,goAction); controlPanel.getInputMap().put(keystroke,actionName); controlPanel.getActionMap().put(actionName,goAction); return button;