Skip to content

Commit 8b7a8bd

Browse files
PhilippPhilipp
authored andcommitted
WIP 1.9.13
1 parent 659af40 commit 8b7a8bd

10 files changed

Lines changed: 81 additions & 27 deletions

File tree

Examples/demos/Snake Game

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ drawGrid = {
9494

9595
try {
9696
exec "cls";
97-
clearConsole;
97+
gui.clear;
9898
};
9999

100100

Examples/demos/hangman

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ blacklist = [];
99
drawScreen = {
1010
try {
1111
exec cls;
12-
clearConsole;
12+
gui.clear;
1313
};
1414

1515
allright = $true;
@@ -40,7 +40,7 @@ drawScreen = {
4040
drawEndScreen = {
4141
try {
4242
exec cls;
43-
clearConsole;
43+
gui.clear;
4444
};
4545

4646
if $0 {
@@ -96,6 +96,7 @@ addToBlacklist = {
9696
push $0 $blacklist;
9797
};
9898

99+
gui.size 600 200;
99100
call $chooseWord;
100101
life = 10;
101102
loop {

Examples/demos/raycast

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
MANUAL_CONTROL = $true;
1010

11+
# Toogle fullscreen #
12+
gui.fullscreen $true;
1113

1214
sizeX = 100;
1315
sizeY = 30;
@@ -260,7 +262,7 @@ loop {
260262

261263
try {
262264
exec "cls";
263-
clearConsole;
265+
gui.clear;
264266
};
265267
call $drawScreen;
266268

changelog.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
- Added some additional commands to resize the console window or to clean the window
1212
- gui.clear
1313
- gui.setSize [sizeX] [sizeY]
14-
- gui.fullscreen [true/false]
14+
- gui.fullscreen [$true/$false]
1515
(The command "clearConsole" is still available but will be removed in future releases by the "gui.clear" command)
16-
- Started to make some plans to implement a simple graphics library to control java awt elements.
17-
16+
- Started to make some plans to implement a simple graphics library to control java awt elements ;)
17+
1818
1.9.12:
1919
- DevScript can now property handle the null variable $null. (="undefined")
2020
- Added an explanation for the "wait" command

src/com/devkev/devscript/raw/Block.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.ArrayList;
44

5-
import com.devkev.devscript.raw.ProcessUtils.ExitCodes;
5+
import com.devkev.devscript.raw.ExecutionState.ExitCodes;
66

77
public class Block { //So stupid...
88

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.devkev.devscript.raw;
2+
3+
/**This class describes wether a script block execution was successful or not.
4+
* Instead of calling the {@link Process#kill(Block, String)} method from within a block,
5+
* a execution state is reported as a return value of the function that executed a specific block.
6+
* Using this method, an exception can be thrown or controlled without specifying the {@link Block#setAsTryCatch()} method.*/
7+
public class ExecutionState {
8+
9+
public interface ExitCodes {
10+
public byte DONE = 0;
11+
public byte ERROR = 1;
12+
}
13+
14+
public final byte exitCode;
15+
public final String stateMessage;
16+
public final Block block;
17+
18+
public ExecutionState(Block block, byte exitCode, String stateMessage) {
19+
this.exitCode = exitCode;
20+
this.block = block;
21+
this.stateMessage = stateMessage;
22+
}
23+
24+
25+
26+
}

src/com/devkev/devscript/raw/Process.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.Random;
1111

1212
import com.devkev.devscript.nativecommands.NativeLibrary;
13-
import com.devkev.devscript.raw.ProcessUtils.ExitCodes;
13+
import com.devkev.devscript.raw.ExecutionState.ExitCodes;
1414

1515
public class Process {
1616

@@ -29,12 +29,11 @@ public class Process {
2929

3030
Block main;
3131
//Main block is not never in the list, since the process gets terminated, if main is killed.
32-
//private final ArrayList<Block> aliveBlocks = new ArrayList<Block>(1);
3332
boolean breakRequested = false;
3433

3534
public long maxRuntime = 0; //Runtime in ms. If < 0, allowed runtime is infinite
3635
private long currentChar = 0;
37-
public final String version = "1.9.12";
36+
public final String version = "1.9.13";
3837

3938
private boolean caseSensitive = false;
4039

@@ -545,10 +544,10 @@ public ArrayList<Object> interpretArguments(StringBuilder command, int start, bo
545544
/**@param garbageCollector - If the process should remove variables after the block was executed.
546545
* Usually true, because the variables would not be accessible anymore anyway.
547546
* @param isConstructor - If the block is used as a constructor. This means, that variables created in this block are:
548-
* not garbegage collected and are isolated from other blocks.*/
547+
* not garbegage collected and are isolated from other blocks.
548+
* @return The execution state wether this block executed successful or with an exception*/
549549
public void executeBlock(Block block, boolean garbageCollector, Object... args) {
550550
if(block == null) block = getMain();
551-
//if(block.alive) kill(block, "Block already running");
552551

553552
/*The arguments are just variables declared in the block - local scope and removed afterwards, if requested*/
554553
if(block != null) {
@@ -664,18 +663,24 @@ public synchronized void kill(Block block, String errorMessage) {
664663

665664
finalizeExit(1, errorMessage);
666665

667-
/*for(int i = 0; i < aliveBlocks.size(); i++) {
668-
aliveBlocks.get(i).cached.clear();
669-
aliveBlocks.get(i).alive = false;
670-
aliveBlocks.get(i).interrupted = true;
671-
}*/
672666
block.alive = false;
673667
block.interrupted = true;
674668
block.currentCommand = "";
675669
}
676670

671+
try {
672+
//Notify the stream, in case an input is still awaited and fire the
673+
synchronized (inputStream) {
674+
inputStream.notify();
675+
}
676+
677+
inputStream.close();
678+
679+
} catch (IOException e) {
680+
e.printStackTrace();
681+
}
682+
677683
block.exitCode = ExitCodes.ERROR;
678-
//aliveBlocks.clear();
679684
garbageCollection(main);
680685
}
681686

src/com/devkev/devscript/raw/ProcessUtils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
/**This class holds various constants etc for the script.*/
44
public final class ProcessUtils {
55

6-
public interface ExitCodes {
7-
public byte DONE = 0;
8-
public byte ERROR = 1;
9-
}
10-
116
public enum Type {
127
//Base data types
138
NULL("null"),

src/com/devkev/gui/Console.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public void actionPerformed(ActionEvent arg0) {
6666
@Override
6767
public void actionPerformed(ActionEvent e) {
6868
if(parent.p.isRunning()) {
69+
70+
waitForEnter = false;
71+
consoleText.setCaretColor(Color.black);
72+
consoleStatus.setText("Running ...");
73+
consoleText.setEditable(false);
74+
6975
parent.p.kill(parent.p.getMain(), "Terminated by DevScript Console");
7076
consolePane.getVerticalScrollBar().setValue(consolePane.getVerticalScrollBar().getMaximum());
7177
}
@@ -82,7 +88,8 @@ public void actionPerformed(ActionEvent e) {
8288
rerun.addActionListener(new ActionListener() {
8389
@Override
8490
public void actionPerformed(ActionEvent e) {
85-
if(p.isRunning()) return;
91+
if(p.isRunning())
92+
p.kill(p.getMain(), "Rerunning script");;
8693

8794
consoleText.setText("");
8895
toFront();
@@ -102,6 +109,8 @@ public void actionPerformed(ActionEvent e) {
102109
contentPane.add(consolePane);
103110

104111
consoleText = new JTextArea();
112+
consoleText.setEditable(false);
113+
consoleText.setFont(new Font("Monospaced", Font.PLAIN, 11));
105114
consolePane.setViewportView(consoleText);
106115

107116
consoleStatus = new JLabel("");

src/com/devkev/gui/Window.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class Window {
8181

8282
private static Font font;
8383
private File openedFile = null; //Null means, creating a new file when saving.
84-
private static String TITLE = "Devscript 1.9.12 Editor ";
84+
private static String TITLE = "Devscript 1.9.13 Editor ";
8585
private ArrayList<String> history = new ArrayList<String>();
8686
private int historyIndex = 0;
8787
public int maxHistorySize = 50;
@@ -145,8 +145,10 @@ public void awaitInput() {
145145
waitForEnter = true;
146146
console.setEnabled(true);
147147
inputStart = console.consoleText.getText().length();
148+
console.consoleText.setEditable(true);
148149
console.consoleText.setCaretPosition(inputStart);
149-
console.consoleText.setCaretColor(Color.black);
150+
console.consoleText.setCaretColor(Color.green);
151+
console.consoleStatus.setText("Waiting for input. Press ENTER");
150152
}
151153
};
152154
p.setInput(input);
@@ -180,6 +182,18 @@ public Object execute(Object[] args, Process application, Block block) throws Ex
180182
} else application.kill(block, "Argument 1 and 2 need to be positive integers");
181183
return null;
182184
}
185+
},
186+
187+
new Command("gui.fullscreen", "boolean", "Toggles fullscreen for the console window") {
188+
@Override
189+
public Object execute(Object[] args, Process application, Block block) throws Exception {
190+
if(args[0].toString().equals("true")) {
191+
console.setExtendedState(JFrame.MAXIMIZED_BOTH);
192+
} else {
193+
console.setExtendedState(JFrame.NORMAL);
194+
}
195+
return null;
196+
}
183197
}
184198
};
185199
}
@@ -197,6 +211,8 @@ public boolean dispatchKeyEvent(KeyEvent e) {
197211
input.flush(console.consoleText.getText().substring(inputStart, console.consoleText.getCaretPosition()) + "\n");
198212
waitForEnter = false;
199213
console.consoleText.setCaretColor(Color.black);
214+
console.consoleStatus.setText("Running ...");
215+
console.consoleText.setEditable(false);
200216
}
201217
return false;
202218
}

0 commit comments

Comments
 (0)