mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
get tweak mode working again, remove debug msg, remove unneeded access levels (fixes #3435)
This commit is contained in:
@@ -2677,8 +2677,8 @@ public class JavaEditor extends Editor {
|
||||
|
||||
// TWEAK MODE
|
||||
|
||||
static final String prefTweakPort = "tweak.port";
|
||||
static final String prefTweakShowCode = "tweak.showcode";
|
||||
static final String PREF_TWEAK_PORT = "tweak.port";
|
||||
static final String PREF_TWEAK_SHOW_CODE = "tweak.showcode";
|
||||
|
||||
public String[] baseCode;
|
||||
TweakClient tweakClient;
|
||||
@@ -2881,9 +2881,9 @@ public class JavaEditor extends Editor {
|
||||
|
||||
// get port number from preferences.txt
|
||||
int port;
|
||||
String portStr = Preferences.get(prefTweakPort);
|
||||
String portStr = Preferences.get(PREF_TWEAK_PORT);
|
||||
if (portStr == null) {
|
||||
Preferences.set(prefTweakPort, "auto");
|
||||
Preferences.set(PREF_TWEAK_PORT, "auto");
|
||||
portStr = "auto";
|
||||
}
|
||||
|
||||
@@ -2891,7 +2891,7 @@ public class JavaEditor extends Editor {
|
||||
// random port for udp (0xc000 - 0xffff)
|
||||
port = (int)(Math.random()*0x3fff) + 0xc000;
|
||||
} else {
|
||||
port = Preferences.getInteger(prefTweakPort);
|
||||
port = Preferences.getInteger(PREF_TWEAK_PORT);
|
||||
}
|
||||
|
||||
// create the client that will send the new values to the sketch
|
||||
@@ -2946,7 +2946,7 @@ public class JavaEditor extends Editor {
|
||||
}
|
||||
|
||||
// add the server code that will receive the value change messages
|
||||
header += TweakClient.getServerCode(port, numOfInts>0, numOfFloats>0);
|
||||
// header += TweakClient.getServerCode(port, numOfInts>0, numOfFloats>0);
|
||||
header += "TweakModeServer tweakmode_Server;\n";
|
||||
|
||||
header += "void tweakmode_initAllVars() {\n";
|
||||
@@ -2975,15 +2975,18 @@ public class JavaEditor extends Editor {
|
||||
setupEndPos = SketchParser.getSetupEnd(c);
|
||||
c = replaceString(c, setupEndPos, setupEndPos, addToSetup);
|
||||
|
||||
code[0].setProgram(header + c);
|
||||
// Server code defines a class, so it should go later in the sketch
|
||||
String serverCode =
|
||||
TweakClient.getServerCode(port, numOfInts>0, numOfFloats>0);
|
||||
code[0].setProgram(header + c + serverCode);
|
||||
|
||||
// print out modified code
|
||||
String showModCode = Preferences.get(prefTweakShowCode);
|
||||
String showModCode = Preferences.get(PREF_TWEAK_SHOW_CODE);
|
||||
if (showModCode == null) {
|
||||
Preferences.setBoolean(prefTweakShowCode, false);
|
||||
Preferences.setBoolean(PREF_TWEAK_SHOW_CODE, false);
|
||||
}
|
||||
|
||||
if (Preferences.getBoolean(prefTweakShowCode)) {
|
||||
if (Preferences.getBoolean(PREF_TWEAK_SHOW_CODE)) {
|
||||
System.out.println("\nTweakMode modified code:\n");
|
||||
for (int i=0; i<code.length; i++) {
|
||||
System.out.println("tab " + i + "\n");
|
||||
|
||||
@@ -35,36 +35,37 @@ public class SketchParser {
|
||||
|
||||
String[] codeTabs;
|
||||
boolean requiresComment;
|
||||
ArrayList<ColorMode> colorModes;
|
||||
List<ColorMode> colorModes;
|
||||
|
||||
List<List<Range>> scientificNotations;
|
||||
|
||||
|
||||
Range setupFunction;
|
||||
|
||||
|
||||
List<List<Range>> commentBlocks;
|
||||
List<int[]> curlyScopes;
|
||||
|
||||
|
||||
|
||||
public SketchParser(String[] codeTabs, boolean requiresComment) {
|
||||
this.codeTabs = codeTabs;
|
||||
this.requiresComment = requiresComment;
|
||||
intVarCount=0;
|
||||
floatVarCount=0;
|
||||
|
||||
intVarCount = 0;
|
||||
floatVarCount = 0;
|
||||
|
||||
// get all comment blocks
|
||||
commentBlocks = new ArrayList<>();
|
||||
for (String code : codeTabs) {
|
||||
commentBlocks.add(getCommentBlocks(code));
|
||||
}
|
||||
|
||||
|
||||
// get setup function range (to ignore all numbers there)
|
||||
setupFunction = new Range(getSetupStart(codeTabs[0]), getSetupEnd(codeTabs[0]));
|
||||
|
||||
|
||||
// build curly scope for every character in the code
|
||||
curlyScopes = new ArrayList<>();
|
||||
for (String code : codeTabs) {
|
||||
curlyScopes.add(getCurlyScopes(code));
|
||||
curlyScopes.add(getCurlyScopes(code));
|
||||
}
|
||||
|
||||
|
||||
// get all scientific notation (to ignore them)
|
||||
scientificNotations = getAllScientificNotations();
|
||||
|
||||
@@ -84,7 +85,7 @@ public class SketchParser {
|
||||
}
|
||||
|
||||
|
||||
public void addAllNumbers() {
|
||||
private void addAllNumbers() {
|
||||
allHandles = new ArrayList<>();
|
||||
|
||||
addAllDecimalNumbers();
|
||||
@@ -123,7 +124,7 @@ public class SketchParser {
|
||||
// ignore comments
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (setupFunction.contains(start)) {
|
||||
// ignore numbers in setup
|
||||
continue;
|
||||
@@ -215,7 +216,7 @@ public class SketchParser {
|
||||
// ignore comments
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (setupFunction.contains(start)) {
|
||||
// ignore number in setup
|
||||
continue;
|
||||
@@ -276,7 +277,7 @@ public class SketchParser {
|
||||
// ignore comments
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (setupFunction.contains(start)) {
|
||||
// ignore number in setup
|
||||
continue;
|
||||
@@ -380,7 +381,7 @@ public class SketchParser {
|
||||
// ignore colors in a comment
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (setupFunction.contains(m.start())) {
|
||||
// ignore number in setup
|
||||
continue;
|
||||
@@ -464,7 +465,7 @@ public class SketchParser {
|
||||
// ignore colors in a comment
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (setupFunction.contains(m.start())) {
|
||||
// ignore number in setup
|
||||
continue;
|
||||
@@ -683,28 +684,28 @@ public class SketchParser {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds an int array for every tab that represents the scope depth at each character
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static private int[] getCurlyScopes(String code)
|
||||
{
|
||||
List<Range> comments = getCommentBlocks(code);
|
||||
|
||||
|
||||
int[] scopes = new int[code.length()];
|
||||
int curlyScope = 0;
|
||||
boolean arrayAssignmentMaybeCommingFlag = false;
|
||||
int arrayAssignmentCurlyScope = 0;
|
||||
for (int pos=0; pos<code.length(); pos++) {
|
||||
scopes[pos] = curlyScope;
|
||||
|
||||
|
||||
if (isInRangeList(pos, comments)) {
|
||||
// we are inside a comment, ignore and move on
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (code.charAt(pos) == '{') {
|
||||
if (arrayAssignmentMaybeCommingFlag ||
|
||||
arrayAssignmentCurlyScope>0) {
|
||||
@@ -731,10 +732,10 @@ public class SketchParser {
|
||||
arrayAssignmentMaybeCommingFlag = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return scopes;
|
||||
}
|
||||
|
||||
|
||||
static private boolean isWhiteSpace(char c) {
|
||||
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
|
||||
}
|
||||
@@ -745,15 +746,15 @@ public class SketchParser {
|
||||
* @param codeTabIndex index of the code in codeTabs
|
||||
* @return
|
||||
* true if the position 'pos' is in global scope in the code 'codeTabs[codeTabIndex]'
|
||||
*
|
||||
*
|
||||
*/
|
||||
private boolean isGlobal(int pos, int codeTabIndex) {
|
||||
return (curlyScopes.get(codeTabIndex)[pos]==0);
|
||||
};
|
||||
|
||||
public static List<Range> getCommentBlocks(String code) {
|
||||
static private List<Range> getCommentBlocks(String code) {
|
||||
List<Range> commentBlocks = new ArrayList<Range>();
|
||||
|
||||
|
||||
int lastBlockStart=0;
|
||||
boolean lookForEnd = false;
|
||||
for (int pos=0; pos<code.length()-1; pos++) {
|
||||
@@ -775,19 +776,19 @@ public class SketchParser {
|
||||
commentBlocks.add(new Range(pos, getEndOfLine(pos, code)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return commentBlocks;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isInRangeList(int pos, List<Range> rangeList) {
|
||||
for (Range r : rangeList) {
|
||||
if (r.contains(pos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -826,7 +827,7 @@ public class SketchParser {
|
||||
}
|
||||
|
||||
|
||||
public static int getSetupStart(String code) {
|
||||
static public int getSetupStart(String code) {
|
||||
Pattern p = Pattern.compile("void[\\s\\t\\r\\n]*setup[\\s\\t]*\\(\\)[\\s\\t\\r\\n]*\\{");
|
||||
Matcher m = p.matcher(code);
|
||||
|
||||
@@ -836,42 +837,43 @@ public class SketchParser {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getSetupEnd(String code) {
|
||||
|
||||
|
||||
static public int getSetupEnd(String code) {
|
||||
List<Range> comments = getCommentBlocks(code);
|
||||
|
||||
|
||||
int setupStart = getSetupStart(code);
|
||||
if (setupStart == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("setup start = " + setupStart);
|
||||
|
||||
|
||||
// count brackets to look for setup end
|
||||
int bracketCount=1;
|
||||
int pos = setupStart;
|
||||
while (bracketCount>0 && pos<code.length()) {
|
||||
|
||||
|
||||
if (isInRangeList(pos, comments)) {
|
||||
// in a comment, ignore and move on
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (code.charAt(pos) == '{') {
|
||||
bracketCount++;
|
||||
}
|
||||
else if (code.charAt(pos) == '}') {
|
||||
bracketCount--;
|
||||
}
|
||||
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
|
||||
if (bracketCount == 0) {
|
||||
return pos-1;
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -880,12 +882,12 @@ public class SketchParser {
|
||||
int start;
|
||||
int end;
|
||||
|
||||
public Range(int s, int e) {
|
||||
Range(int s, int e) {
|
||||
start = s;
|
||||
end = e;
|
||||
}
|
||||
|
||||
public boolean contains(int v) {
|
||||
boolean contains(int v) {
|
||||
return v >= start && v < end;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user