Browse Source

Bugfixes, Graphic-Engine, Update der alten Graphic-Types, PreScriptExceptions(unfertig)

Kajetan Johannes Hammerle 8 years ago
parent
commit
91527a633f

+ 1 - 1
nbproject/private/private.xml

@@ -4,8 +4,8 @@
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
         <group>
             <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/code/CodeParser.java</file>
-            <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/code/Code.java</file>
             <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/code/Script.java</file>
+            <file>file:/Users/kajetanjohannes/Dropbox/Projekte/Informatik/SnuviScript/src/me/hammerle/graphics/GraphicPanel.java</file>
         </group>
     </open-files>
 </project-private>

+ 201 - 156
src/me/hammerle/code/Code.java

@@ -4,6 +4,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Stack;
 import java.util.TreeSet;
+import me.hammerle.exceptions.PrescriptException;
 
 public class Code implements Comparable<Code>
 {
@@ -201,6 +202,11 @@ public class Code implements Comparable<Code>
                 case ';':
                 case '{':
                 case '}':
+                    if(bracketCounter != 0)
+                    {
+                        throw new PrescriptException("unbalanced ()", code.substring(pos - 1, Math.min(code.length(), pos + 10))); 
+                    }
+                    return pos + 1;
                 case ' ':
                 case '+':
                 case '-':
@@ -208,6 +214,10 @@ public class Code implements Comparable<Code>
                 case '/':
                 case '^':
                 case '=':
+                case '>':
+                case '<':
+                case '!':
+                case '%':
                     if(bracketCounter != 0)
                     {
                         break;
@@ -254,6 +264,11 @@ public class Code implements Comparable<Code>
                 case ';':
                 case '{':
                 case '}':
+                    if(bracketCounter != 0)
+                    {
+                        throw new PrescriptException("unbalanced ()", code.substring(pos - 1, Math.min(code.length(), pos + 10))); 
+                    }
+                    return pos;
                 case ' ':
                 case '+':
                 case '-':
@@ -261,7 +276,10 @@ public class Code implements Comparable<Code>
                 case '/':
                 case '^':
                 case '=':
-                    case '%':
+                case '>':
+                case '<':
+                case '!':
+                case '%':
                     if(bracketCounter != 0)
                     {
                         break;
@@ -350,6 +368,7 @@ public class Code implements Comparable<Code>
                 newSyntax.append(sb.substring(pos + slength, end).trim());
             }
             newSyntax.append(")");
+            pos -= end - start - newSyntax.length();
             sb.replace(start, end, newSyntax.toString());
         }
         return sb.toString();
@@ -383,6 +402,7 @@ public class Code implements Comparable<Code>
             newSyntax.append(",");
             newSyntax.append(sb.substring(pos + slength, end).trim());
             newSyntax.append("))");
+            pos -= end - start - newSyntax.length();
             sb.replace(start, end, newSyntax.toString());
         }
         return sb.toString();
@@ -420,160 +440,184 @@ public class Code implements Comparable<Code>
     
     public static Code[] generate(String code, HashMap<String, Integer> gotos)
     {
-        // Anfängliches Austauschen mit Functionssyntax
-        code = changeBiSyntax("^", "math.pow", code, false);
-        code = changeBiSyntax("/", "div", code, false);
-        code = changeBiSyntax("%", "math.mod", code, false);
-        code = changeBiSyntax("*", "mul", code, false);
-        code = changeBiSyntax("-", "sub", code, false);
-        code = changeBiSyntax("+", "add", code, false);
-        
-        code = changeBiSyntax("==", "equal", code, false);
-        code = changeBiSyntax("!=", "notequal", code, false);
-        code = changeBiSyntax("<", "less", code, false);
-        code = changeBiSyntax(">", "greater", code, false);
-        code = changeBiSyntax(">=", "greaterequal", code, false);
-        code = changeBiSyntax("<=", "lessequal", code, false);
-        
-        code = changeUnSyntax("+=", "add", code);
-        code = changeUnSyntax("-=", "add", code);
-        code = changeUnSyntax("/=", "add", code);
-        code = changeUnSyntax("*=", "add", code);
-        
-        code = changeBiSyntax("=", "setvar", code, true);
-        
-        //code = replaceChar('[', '(', code);
-        //code = replaceChar(']', ')', code);
-        
-        System.out.println(code);
-        //System.exit(0);
-        // Ende des Austauschen
-        // Zerlegen des Codes in Zeilen
-        ArrayList<Code> list = new ArrayList<>();
-        sublines = 0;
-        String actual;
-        int length = code.length();
-        int level = 1;
-        int old;
-        int pos = 0;
-        int line = 0;
-        while(pos < length)
+        try
         {
-            old = pos;
-            pos = findEndOfLine(code, pos);
-            actual = code.substring(old, pos).trim();
-            if(actual.startsWith("@"))
-            {
-                gotos.put(actual.substring(1), line);
+            // Anfängliches Austauschen mit Functionssyntax
+            code = changeBiSyntax("^", "math.pow", code, false);
+            code = changeBiSyntax("/", "div", code, false);
+            code = changeBiSyntax("%", "math.mod", code, false);
+            code = changeBiSyntax("*", "mul", code, false);
+            code = changeBiSyntax("-", "sub", code, false);
+            code = changeBiSyntax("+", "add", code, false);
+
+            code = changeBiSyntax("==", "equal", code, false);
+            code = changeBiSyntax("!=", "notequal", code, false);
+            code = changeBiSyntax("<", "less", code, false);
+            code = changeBiSyntax(">", "greater", code, false);
+            code = changeBiSyntax(">=", "greaterequal", code, false);
+            code = changeBiSyntax("<=", "lessequal", code, false);
+
+            code = changeUnSyntax("+=", "add", code);
+            code = changeUnSyntax("-=", "sub", code);
+            code = changeUnSyntax("/=", "div", code);
+            code = changeUnSyntax("*=", "mul", code);
+
+            code = changeBiSyntax("=", "setvar", code, true);
+
+            //code = replaceChar('[', '(', code);
+            //code = replaceChar(']', ')', code);
+
+            //System.out.println(code);
+            //System.exit(0);
+            // Ende des Austauschen
+            // Zerlegen des Codes in Zeilen
+            ArrayList<Code> list = new ArrayList<>();
+            sublines = 0;
+            String actual;
+            int length = code.length();
+            int level = 1;
+            int old;
+            int pos = 0;
+            int line = 0;
+            while(pos < length)
+            {
+                old = pos;
+                pos = findEndOfLine(code, pos);
+                actual = code.substring(old, pos).trim();
+                //System.out.println("WUSI: " + actual);
+                if(actual.startsWith("@"))
+                {
+                    gotos.put(actual.substring(1), line);
+                    pos++;
+                    continue;
+                }
+                switch(code.charAt(pos))
+                {
+                    case '{':
+                        line++;
+                        splitFunctions(list, actual, level, line);
+                        level++;
+                        break;
+                    case '}': 
+                        level--;
+                        break;
+                    case ';': 
+                        line++;
+                        splitFunctions(list, actual, level, line);
+                        break;
+                }
                 pos++;
-                continue;
-            }
-            switch(code.charAt(pos))
-            {
-                case '{':
-                    line++;
-                    splitFunctions(list, actual, level, line);
-                    level++;
-                    break;
-                case '}': 
-                    level--;
-                    break;
-                case ';': 
-                    line++;
-                    splitFunctions(list, actual, level, line);
-                    break;
             }
-            pos++;
-        }
-        // Ende der Zeilenzerlegung
-        
-        // Anlegen eines Trees zum sortieren und einfügen von Code
-        TreeSet<Code> tree = new TreeSet(list);
-        Code[] helper = tree.toArray(new Code[tree.size()]);
-        
-        // Einfügen von "gotoline" bei while-Schleifen
-        String function;
-        int baseLevel;
-        for(int i = 0; i < helper.length; i++)
-        {
-            function = helper[i].function;
-            if(function == null || !function.equals("while"))
-            {
-                continue;
-            }
-            baseLevel = helper[i].level;
-            for(int j = i + 1; j < helper.length; j++)
+            // Ende der Zeilenzerlegung
+
+            // Anlegen eines Trees zum sortieren und einfügen von Code
+            TreeSet<Code> tree = new TreeSet(list);
+            Code[] helper = tree.toArray(new Code[tree.size()]);
+
+            // Einfügen von "gotoline" bei while-Schleifen
+            String function;
+            int baseLevel;
+            for(int i = 0; i < helper.length; i++)
             {
-                if(helper[j].level <= baseLevel)
+                function = helper[i].function;
+                if(function == null || !function.equals("while"))
                 {
-                    helper[i].jump = j - i + 1;
-                    Code c = new Code("gotoline", helper[i].level, 0, helper[j].line, helper[j].subline + 1);
-                    while(tree.contains(c)) // Damit keine Whiles, die gleich enden, sich überschreiben
+                    continue;
+                }
+                baseLevel = helper[i].level;
+                for(int j = i + 1; j < helper.length; j++)
+                {
+                    if(helper[j].level <= baseLevel)
                     {
-                        c.subline++;
+                        helper[i].jump = j - i + 1;
+                        Code c = new Code("gotoline", helper[i].level, 0, helper[j].line, helper[j].subline + 1);
+                        while(tree.contains(c)) // Damit keine Whiles, die gleich enden, sich überschreiben
+                        {
+                            c.subline++;
+                        }
+                        tree.add(c);
+                        break;
                     }
-                    tree.add(c);
-                    break;
                 }
             }
-        }
-        // Ende des While-Handlings
-        // Erstellen der Sprungmarken der Schlüsselwörter
-        helper = tree.toArray(new Code[tree.size()]);
-        
-        boolean whileCheck = false;
-        int lastLineChange = 0;
-        line = 0;
-        for(int i = 0; i < helper.length; i++)
-        {
-            function = helper[i].function;
-            if(helper[i].line != line)
-            {
-                line = helper[i].line;
-                lastLineChange = i;
-            }
-            if(function == null)
-            {
-                continue;
-            }
-            switch(function)
+            // Ende des While-Handlings
+            // Erstellen der Sprungmarken der Schlüsselwörter
+            helper = tree.toArray(new Code[tree.size()]);
+
+            boolean whileCheck = false;
+            int lastLineChange = 0;
+            line = 0;
+            for(int i = 0; i < helper.length; i++)
             {
-                case "if":
-                case "else":
-                case "try":
-                case "catch":
-                    break;
-                case "while":
-                    whileCheck = true;
-                    break;
-                default:
+                function = helper[i].function;
+                if(helper[i].line != line)
+                {
+                    line = helper[i].line;
+                    lastLineChange = i;
+                }
+                if(function == null)
+                {
                     continue;
-            }
-            baseLevel = helper[i].level;
-            for(int j = i + 1; j < helper.length; j++)
-            {
-                if(helper[j].level <= baseLevel)
+                }
+                switch(function)
                 {
-                    helper[i].jump = j - i;
-                    if(whileCheck)
+                    case "if":
+                    case "else":
+                    case "try":
+                    case "catch":
+                        break;
+                    case "while":
+                        whileCheck = true;
+                        break;
+                    default:
+                        continue;
+                }
+                baseLevel = helper[i].level;
+                for(int j = i + 1; j < helper.length; j++)
+                {
+                    if(helper[j].level <= baseLevel)
                     {
-                        whileCheck = false;
-                        helper[j].jump = lastLineChange - j;
+                        helper[i].jump = j - i;
+                        if(whileCheck)
+                        {
+                            whileCheck = false;
+                            helper[j].jump = lastLineChange - j;
+                        }
+                        break;
                     }
-                    break;
+                }
+                if(helper[i].jump == 0)
+                {
+                   helper[i].jump = list.size() - i; 
                 }
             }
-            if(helper[i].jump == 0)
+            // Ende der Srungmarken
+            // Korrektur der Gotos;
+            Code[] c = tree.toArray(new Code[list.size()]);
+            gotos.entrySet().forEach((i) -> 
             {
-               helper[i].jump = list.size() - i; 
-            }
+                int value = i.getValue() + 1;
+                for(int j = value; j < c.length; j++)
+                {
+                    if(c[j].line == value)
+                    {
+                        i.setValue(j);
+                        return;
+                    }
+                }
+            });
+            // Ende
+            //java.util.Arrays.stream(c).forEach(co -> System.out.println(co.toString()));
+            //gotos.forEach((k, v) -> System.out.println(k + "   " + v));
+            //System.exit(0);
+            return c;
+        }
+        catch(PrescriptException ex)
+        {
+            ScriptUtils.printError("PrescriptException");
+            ScriptUtils.printError(ex.getBadString() + " - " + ex.getException());
+            return null;
         }
-        // Ende
-        
-        //tree.stream().forEach(c -> System.out.println(c.toString()));
-        //gotos.forEach((k, v) -> System.out.println(k + "   " + v));
-        //System.exit(0);
-        return tree.toArray(new Code[list.size()]);
     } 
     
     private static int findOpenBracket(String code, int pos)
@@ -599,11 +643,15 @@ public class Code implements Comparable<Code>
             }
             pos++;
         }
-        return length;
+        return -1;
     }
     
     private static int findClosingBracket(String code, int pos)
     {
+        if(pos == -1)
+        {
+           pos++;
+        }
         int length = code.length();
         char c;
         boolean text = false;
@@ -623,18 +671,18 @@ public class Code implements Comparable<Code>
                     break;
                 case ')':
                     brackets--;
+                    if(brackets == 0)
+                    {
+                        return pos;
+                    }
                     break;
                 case '"':
                     text = !text;
                     break;
             }
-            if(brackets == 0)
-            {
-                return pos;
-            }
             pos++;
         }
-        return code.length() - 1;
+        return -1;
     }
     
     private static ArrayList<String> splitComma(String code)
@@ -688,25 +736,22 @@ public class Code implements Comparable<Code>
         sublines++;
         int start = findOpenBracket(f, 0);
         int end = findClosingBracket(f, start);
-        if(start >= end - 1)
+        if((start != -1 || end != -1) && (((start == -1 || end == -1) && start != end) || end != f.length() - 1))
         {
-            if(start == f.length())
-            {
-                list.add(new Code(level, 0, line, sublines, convertInput(f.substring(0, start))));
-                return;
-            }
-            list.add(new Code(f.substring(0, start), level, 0, line, sublines));
-            return;
+            throw new PrescriptException("unbalanced ()", f);
         }
-        ArrayList<String> splitted = splitComma(f.substring(start + 1, end));
-        if(start == f.length())
+        if(start == -1)
         {
-            list.add(new Code(level, 0, line, sublines, convertInput(f.substring(0, start))));
+            list.add(new Code(level, 0, line, sublines, convertInput(f)));
+            return;
         }
-        else
+        else if(start >= end - 1)
         {
-            list.add(new Code(f.substring(0, start), level, splitted.size(), line, sublines));
+            list.add(new Code(f.substring(0, start), level, 0, line, sublines));
+            return;
         }
+        ArrayList<String> splitted = splitComma(f.substring(start + 1, end));
+        list.add(new Code(f.substring(0, start), level, splitted.size(), line, sublines));
         splitted.forEach(s -> splitFunctions(list, s, level, line));
     }
     

+ 135 - 21
src/me/hammerle/code/CodeParser.java

@@ -1,5 +1,6 @@
 package me.hammerle.code;
 
+import java.awt.Color;
 import me.hammerle.exceptions.HoldCodeException;
 import me.hammerle.exceptions.IllegalStringException;
 import me.hammerle.exceptions.NoSuchMethodException;
@@ -18,6 +19,7 @@ import java.util.function.BiFunction;
 import java.util.function.BiConsumer;
 import java.util.stream.Collectors;
 import me.hammerle.console.ConsoleUtils;
+import me.hammerle.graphics.*;
 import me.hammerle.scheduler.SnuviScheduler;
 
 public class CodeParser 
@@ -50,12 +52,14 @@ public class CodeParser
                 0);
         registerFunction("", (args, sc) -> 
                 args[0]);
+        registerConsumer("error", (args, sc) -> 
+                printStack = !printStack);
         
         // -------------------------------------------------------------    
         // Script-Consolen-Bibliothek 
         // -------------------------------------------------------------  
         registerConsumer("script.list", (args, sc) -> 
-                { ScriptUtils.printDebug("The following scripts are active:"); ScriptControl.getScripts().forEach(s -> ScriptUtils.printDebug(s.getId() + " | " + s.getName()));}); 
+                { ScriptUtils.print("The following scripts are active:"); ScriptControl.getScripts().forEach(s -> ScriptUtils.print(s.getId() + " | " + s.getName()));}); 
         registerConsumer("script.load", (args, sc) -> 
                 ScriptControl.startScriptFromFile(args[0].toString())); 
         registerConsumer("clear", (args, sc) -> 
@@ -187,22 +191,60 @@ public class CodeParser
         // Time-Bibliothek   
         // -------------------------------------------------------------
         registerFunction("time.get", (args, sc) ->                            
-                System.currentTimeMillis());
+                (double) System.currentTimeMillis());
         registerFunction("time.nextday", (args, sc) ->         
-                getNextDay(args));   
+                (double) getNextDay(args));   
         registerFunction("time.getyear", (args, sc) ->         
-                getYear(args));   
+                (double) getYear(args));   
         registerFunction("time.getmonth", (args, sc) ->         
-                getMonth(args));   
+                (double) getMonth(args));   
         registerFunction("time.getday", (args, sc) ->         
-                getDay(args));   
+                (double) getDay(args));   
         registerFunction("time.gethour", (args, sc) ->         
-                getHour(args));   
+                (double) getHour(args));   
         registerFunction("time.getminute", (args, sc) ->         
-                getMinute(args));   
+                (double) getMinute(args));   
         registerFunction("time.getsecond", (args, sc) ->         
-                getSecond(args));                   
+                (double) getSecond(args));                   
 
+        // -------------------------------------------------------------    
+        // Graphic-Bibliothek 
+        // -------------------------------------------------------------
+        registerConsumer("g.new", (args, sc) ->                            
+                sc.newFrame(getInt(args[0]), getInt(args[1])));
+        registerFunction("g.get", (args, sc) ->                            
+                sc.getGraphicPanel().getGraphic(getInt(args[0])));
+        registerConsumer("g.repaint", (args, sc) ->                            
+                sc.getGraphicPanel().repaint());
+        registerConsumer("g.newpoint", (args, sc) ->                            
+                newPoint(args, sc));
+        registerConsumer("g.newline", (args, sc) ->                            
+                newLine(args, sc));
+        registerConsumer("g.newoval", (args, sc) ->                            
+                newOval(args, sc));
+        registerConsumer("g.newrectangle", (args, sc) ->                            
+                newRectangle(args, sc));
+        registerConsumer("g.translate", (args, sc) ->                            
+                ((Graphic) args[0]).translate(getInt(args[1]), getInt(args[2])));
+        registerConsumer("g.setcolor", (args, sc) ->                            
+                ((Colorable) args[0]).setColor((Color) args[1]));
+        registerConsumer("g.setfilled", (args, sc) ->                            
+                ((Colorable) args[0]).setFilled((boolean) args[1]));
+        registerConsumer("g.setx1", (args, sc) ->                            
+                ((Line) args[0]).setFirstX(getInt(args[1])));
+        registerConsumer("g.setx2", (args, sc) ->                            
+                ((Line) args[0]).setSecondX(getInt(args[1])));
+        registerConsumer("g.sety1", (args, sc) ->                            
+                ((Line) args[0]).setFirstY(getInt(args[1])));
+        registerConsumer("g.sety2", (args, sc) ->                            
+                ((Line) args[0]).setSecondY(getInt(args[1])));
+        
+        // -------------------------------------------------------------    
+        // Read-Bibliothek
+        // -------------------------------------------------------------  
+        registerFunction("read.color", (args, sc) ->         
+                getColor(args, sc));
+        
         // -------------------------------------------------------------    
         // Ohne Bibliothek
         // -------------------------------------------------------------    
@@ -225,7 +267,9 @@ public class CodeParser
         registerConsumer("removevar", (args, sc) -> 
                 sc.removeVar(args[0].toString()));
         registerConsumer("debug", (args, sc) -> 
-                ConsoleUtils.sendMessage(ScriptUtils.connect(args, 0), null));
+                ScriptUtils.printDebug(ScriptUtils.connect(args, 0)));
+        registerConsumer("print", (args, sc) -> 
+                print(args, sc));
         registerConsumer("reset", (args, sc) -> 
                 sc.resetLoopCounter());
         registerConsumer("wait", (args, sc) -> 
@@ -233,7 +277,7 @@ public class CodeParser
         registerConsumer("goto", (args, sc) -> 
                 sc.gotoLabel(args[0].toString()));
         registerConsumer("gotoline", (args, sc) -> 
-                { sc.gotoSpecialJumpLine(); sc.incLoopCounter();});
+                { sc.gotoSpecialJumpLine(); sc.incLoopCounter(); });
         registerConsumer("sgoto", (args, sc) -> 
                 scheduleGoto(args, sc));
         registerConsumer("gosub", (args, sc) -> 
@@ -283,7 +327,7 @@ public class CodeParser
                 waitFor(args, sc));
     }
     
-    public static boolean printStack = true;
+    public static boolean printStack = false;
 
     @SuppressWarnings("unchecked")
     public static Object parseFunction(Script sc, String function, Object[] args) throws HoldCodeException
@@ -323,20 +367,20 @@ public class CodeParser
     {
         sc.resetLoopCounter();
         ScriptUtils.printError("Error in");
-        ScriptUtils.printErrorList("Script", sc.getName());
-        ScriptUtils.printErrorList("Zeile", line);
-        ScriptUtils.printErrorList("Zeilennummer", sc.getActiveCodeLine());
+        ScriptUtils.printErrorList("script:", sc.getName());
+        ScriptUtils.printErrorList("line:", line);
+        ScriptUtils.printErrorList("line number:", sc.getActiveCodeLine());
         if(ex.getLocalizedMessage() == null)
         {
-            ScriptUtils.printErrorList("Exception", ex.getClass().getSimpleName());
+            ScriptUtils.printErrorList("exception:", ex.getClass().getSimpleName());
         }
         else
         {
-            ScriptUtils.printErrorList("Exception", ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage());
+            ScriptUtils.printErrorList("exception:", ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage());
         }
         if(ex instanceof IllegalStringException)
         {
-            ScriptUtils.printErrorList("Ungültiger Wert", ((IllegalStringException) ex).getBadString());
+            ScriptUtils.printErrorList("illegal value:", ((IllegalStringException) ex).getBadString());
         }
     }
     
@@ -380,7 +424,7 @@ public class CodeParser
     {
         if(Arrays.stream(args).anyMatch(s -> (boolean) s == false))
         {
-            sc.gotoSpecialJumpLine();
+            sc.gotoSpecialJumpLine(0);
         }
     } 
                   
@@ -401,7 +445,7 @@ public class CodeParser
             try
             {
                 sc.gotoLabel(args[1].toString());
-                sc.setHalt(true);
+                sc.setHalt(false);
                 sc.runCode();
             }
             catch(Exception ex)
@@ -429,7 +473,6 @@ public class CodeParser
             sc.setHalt(false);
             sc.runCode();
         }, i); 
-        throw new HoldCodeException();
     }   
     
     private static Number increaseVar(Object var, Script sc, int value)
@@ -467,6 +510,77 @@ public class CodeParser
         sc.setVar(args[0].toString(), list);
     }   
     
+    private static void print(Object[] args, Script sc)
+    {
+        if(args.length == 0)
+        {
+            ScriptUtils.print("");
+        } 
+        else if(args[0] instanceof Color)
+        {
+            ConsoleUtils.sendMessage(ScriptUtils.connect(args, 1), (Color) args[0]);
+        }
+        else
+        {
+            ScriptUtils.print(ScriptUtils.connect(args, 0));
+        }
+    }
+    
+    // -------------------------------------------------------------------------    
+    // Read-Handler
+    // ------------------------------------------------------------------------- 
+    
+    private static Color getColor(Object[] args, Script sc)
+    {
+        int r = getInt(args[0]);
+        int g = getInt(args[1]);
+        int b = getInt(args[2]);
+        int a;
+        if(args.length >= 4)
+        {
+            a = getInt(args[3]);
+        }
+        else
+        {
+            a = 255;
+        }
+        return new Color(r, g, b, a);
+    }
+    
+    // -------------------------------------------------------------------------    
+    // Graphics
+    // ------------------------------------------------------------------------- 
+    
+    private static void newLine(Object[] args, Script sc)
+    {
+        sc.getGraphicPanel().addGraphic(getInt(args[0]), new Line((Color) args[1], getInt(args[2]), getInt(args[3]), getInt(args[4]), getInt(args[5])));
+    }
+    
+    private static void newPoint(Object[] args, Script sc)
+    {
+        sc.getGraphicPanel().addGraphic(getInt(args[0]), new Point((Color) args[1], getInt(args[2]), getInt(args[3])));
+    }
+    
+    private static void newOval(Object[] args, Script sc)
+    {
+        Oval oval = new Oval((Color) args[1], getInt(args[2]), getInt(args[3]), getInt(args[4]), getInt(args[5]));
+        if(args.length >= 7)
+        {
+            oval.setFilled((boolean) args[6]);
+        }
+        sc.getGraphicPanel().addGraphic(getInt(args[0]), oval);
+    }
+    
+    private static void newRectangle(Object[] args, Script sc)
+    {
+        Rectangle rec = new Rectangle((Color) args[1], getInt(args[2]), getInt(args[3]), getInt(args[4]), getInt(args[5]));
+        if(args.length >= 7)
+        {
+            rec.setFilled((boolean) args[6]);
+        }
+        sc.getGraphicPanel().addGraphic(getInt(args[0]), rec);
+    }
+    
     // -------------------------------------------------------------------------    
     // Int-Handler, weil die Objekte double immer zu Double konvertieren
     // ------------------------------------------------------------------------- 

+ 0 - 49
src/me/hammerle/code/GraphicEngine.java

@@ -1,49 +0,0 @@
-package me.hammerle.code;
-
-import java.awt.Graphics;
-import java.util.TreeMap;
-import javax.swing.JPanel;
-import me.hammerle.graphics.GraphicObject;
-
-public class GraphicEngine extends JPanel
-{
-    private final TreeMap<Integer, GraphicObject> objects;
-    private GraphicObject buffer;
-    
-    public GraphicEngine()
-    {
-        this.objects = new TreeMap<>();
-    }
-    
-    public GraphicObject getBuffer()
-    {
-        return buffer;
-    }
-    
-    public GraphicObject loadGraphicObjectIntoBuffer(int id)
-    {
-        buffer = objects.get(id);
-        return buffer;
-    }
-    
-    public void removeGraphicObject(int id)
-    {
-        objects.remove(id);
-    }
-    
-    public void addGraphicObject(int id, GraphicObject go)
-    {
-        objects.put(id, go);
-    }
-    
-    @Override
-    public void paint(Graphics g) 
-    {
-        super.paint(g);
-        objects.forEach((i, go) -> 
-        {
-            g.setColor(go.getColor());
-            go.paint(g);
-        });
-    }   
-}

+ 50 - 1
src/me/hammerle/code/Script.java

@@ -6,6 +6,8 @@ import java.util.Stack;
 import me.hammerle.exceptions.CodeTooLongException;
 import me.hammerle.exceptions.GotoLabelNotFoundException;
 import me.hammerle.exceptions.HoldCodeException;
+import me.hammerle.graphics.GraphicFrame;
+import me.hammerle.graphics.GraphicPanel;
 
 public class Script 
 {
@@ -28,6 +30,10 @@ public class Script
     
     private int tryJumpLine;
     
+    private GraphicFrame frame;
+    private GraphicPanel panel;
+    
+    @SuppressWarnings("LeakingThisInConstructor")
     public Script(int id, String name, String code)
     {       
         this.id = id;
@@ -40,6 +46,11 @@ public class Script
         returnStack = new Stack<>();
         
         this.code = Code.generate(code, gotos);
+        if(this.code == null)
+        {
+            ScriptControl.term(this);
+            return;
+        }
         
         position = 0;
 
@@ -49,6 +60,8 @@ public class Script
         valid = true;
         
         tryJumpLine = -1;
+        
+        frame = null;
     }
     
     // -----------------------------------------------------------------------------------
@@ -123,11 +136,16 @@ public class Script
                 {
                     code[position].executeFunction(this, valueStack);
                     position++;
+                    if(isHalt())
+                    {
+                        return;
+                    }
                 }
                 ScriptControl.term(this);
             }
             catch(Exception ex)
             {
+                position++;
                 if(ex.getClass() != HoldCodeException.class)
                 {
                     CodeParser.printQuestException(this, ex, code[position].toString());
@@ -199,9 +217,14 @@ public class Script
         position = returnStack.pop(); 
     }
     
+    public void gotoSpecialJumpLine(int i)
+    {
+        position += code[position].getJumpLine() + i;
+    }
+    
     public void gotoSpecialJumpLine()
     {
-        position += code[position].getJumpLine() - 1;
+        gotoSpecialJumpLine(-1);
     }
     
     public void jumpNextIfElse()
@@ -241,4 +264,30 @@ public class Script
     {
         return tryJumpLine; 
     }
+    
+    // -----------------------------------------------------------------------------------
+    // Frame
+    // -----------------------------------------------------------------------------------
+    
+    public void newFrame(int width, int height)
+    {
+        if(frame == null)
+        {
+            frame = new GraphicFrame(width, height, this);
+            panel = frame.graphics;
+        }
+    }
+    
+    public GraphicPanel getGraphicPanel()
+    {
+        return panel;
+    }
+    
+    public void closeFrame()
+    {
+        if(frame != null)
+        {
+            frame.dispose();
+        }
+    }
 }

+ 6 - 1
src/me/hammerle/code/ScriptControl.java

@@ -25,12 +25,17 @@ public class ScriptControl
             return;
         }
         sc.setInvalid();
+        sc.closeFrame();
         SnuviScheduler.doScheduledTask(() -> SCRIPTS.remove(sc.getId()));
     }
     
     public static void termScripts()
     {
-        SCRIPTS.values().forEach(sc -> sc.setInvalid());
+        SCRIPTS.values().forEach(sc -> 
+        {
+            sc.setInvalid();
+            sc.closeFrame();
+        });
         SnuviScheduler.doScheduledTask(() -> SCRIPTS.clear());
     }
     

+ 17 - 24
src/me/hammerle/code/ScriptUtils.java

@@ -3,29 +3,17 @@ package me.hammerle.code;
 import java.awt.Color;
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.MalformedInputException;
 import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
 import java.util.stream.Collectors;
 import me.hammerle.console.ConsoleUtils;
-import me.hammerle.exceptions.IllegalColorException;
+import me.hammerle.exceptions.FileException;
 
 public class ScriptUtils
 {
-    public static Color getColor(Object o) throws IllegalColorException
-    {
-        try
-        {
-            String[] parts = o.toString().split(":");
-            return new Color(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
-        }
-        catch(NumberFormatException | ArrayIndexOutOfBoundsException ex)
-        {
-            throw new IllegalColorException(o.toString());
-        }
-    }
-    
     public static void printError(Object message)
     { 
         ConsoleUtils.sendMessage(String.valueOf(message), Color.RED);
@@ -36,11 +24,16 @@ public class ScriptUtils
         ConsoleUtils.sendMessage(" - " + message + " " + message2, Color.RED);
     }
     
-    public static void printDebug(Object message)
+    public static void print(Object message)
     {
         ConsoleUtils.sendMessage(String.valueOf(message), null);
     }
     
+    public static void printDebug(Object message)
+    {
+        ConsoleUtils.sendMessage(String.valueOf(message), Color.yellow);
+    }
+    
     public static int randomInt(int min, int max)
     {
         Random rand = new Random();
@@ -55,22 +48,22 @@ public class ScriptUtils
     
     public static List<String> readCode(String filename)
     {
-        File script = new File(filename + ".snuvi");  
+        File script = new File("./" + filename + ".snuvi");  
         if(script.exists())
         {
-            try 
+            try
             {
                 return Files.readAllLines(script.toPath());
             } 
+            catch (MalformedInputException ex) 
+            {
+                throw new FileException("file contains an illegal character, change file encoding");
+            }
             catch (IOException ex) 
             {
-                ScriptUtils.printError("File '" + filename + "' cannot be read.");
+                throw new FileException("file '" + filename + "' cannot be read");
             }
-        }
-        else
-        {
-            ScriptUtils.printError("File '" + filename + "' does not exist.");
-        }
-        return null;
+                   }
+        throw new FileException("file '" + filename + "' does not exist");
     }
 }

+ 8 - 1
src/me/hammerle/console/BlackBox.java

@@ -23,10 +23,14 @@ public class BlackBox extends JScrollPane
         area = new JTextPane();
         //area.setLineWrap(true);
         area.setBackground(Color.black);
-        area.setFont(new Font("Monaco", Font.PLAIN, 16));
+        area.setFont(new Font("Monaco", Font.PLAIN, 14));
         area.setForeground(Color.white);
         area.setCaretColor(Color.white);
         area.setAutoscrolls(true);
+        /*area.selectAll();
+        MutableAttributeSet set = new SimpleAttributeSet(area.getParagraphAttributes());
+        StyleConstants.setLineSpacing(set, -0.17f);
+        area.setParagraphAttributes(set, true);*/
         
         super.setViewportView(area);
         super.setBackground(Color.black);
@@ -45,6 +49,9 @@ public class BlackBox extends JScrollPane
             {
                 style = area.addStyle(c.toString(), null);
                 StyleConstants.setForeground(style, c);
+                /*StyleConstants.setLineSpacing(style, 0);
+                StyleConstants.setSpaceAbove(style, 20);
+                StyleConstants.setSpaceBelow(style, 0);*/
             }
         }
         try 

+ 9 - 0
src/me/hammerle/exceptions/FileException.java

@@ -0,0 +1,9 @@
+package me.hammerle.exceptions;
+
+public class FileException extends IllegalStringException
+{
+    public FileException(String s) 
+    {
+        super(s);
+    }
+}

+ 0 - 9
src/me/hammerle/exceptions/IllegalColorException.java

@@ -1,9 +0,0 @@
-package me.hammerle.exceptions;
-
-public class IllegalColorException extends IllegalStringException
-{
-    public IllegalColorException(String s) 
-    {
-        super(s);
-    }   
-}

+ 0 - 6
src/me/hammerle/exceptions/InfiniteLoopException.java

@@ -1,6 +0,0 @@
-package me.hammerle.exceptions;
-
-public class InfiniteLoopException extends Exception
-{
-    
-}

+ 9 - 1
src/me/hammerle/exceptions/PrescriptException.java

@@ -2,8 +2,16 @@ package me.hammerle.exceptions;
 
 public class PrescriptException extends IllegalStringException
 {
-    public PrescriptException(String s) 
+    private final String s2;
+    
+    public PrescriptException(String s, String s2) 
     {
         super(s);
+        this.s2 = s2;
+    }
+    
+    public String getException()
+    {
+        return s2;
     }
 }

+ 35 - 0
src/me/hammerle/graphics/Colorable.java

@@ -0,0 +1,35 @@
+package me.hammerle.graphics;
+
+import java.awt.Color;
+
+public abstract class Colorable 
+{
+    private Color c;
+    private boolean filled;
+    
+    public Colorable(Color c)
+    {
+        this.c = c; 
+        this.filled = false;
+    }
+    
+    public Color getColor()
+    {
+        return c;
+    }
+    
+    public void setColor(Color c)
+    {
+        this.c = c;
+    }
+    
+    public boolean isFilled()
+    {
+        return filled;
+    }
+    
+    public void setFilled(boolean filled)
+    {
+        this.filled = filled;
+    }
+}

+ 0 - 18
src/me/hammerle/graphics/FullOval.java

@@ -1,18 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Graphics;
-
-public class FullOval extends Oval
-{
-    public FullOval(Color c, int x1, int y1, int x2, int y2) 
-    {
-        super(c, x1, y1, x2, y2);
-    }   
-    
-    @Override
-    public void paint(Graphics g) 
-    {
-        g.fillOval(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
-    }
-}

+ 0 - 18
src/me/hammerle/graphics/FullRectangle.java

@@ -1,18 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Graphics;
-
-public class FullRectangle extends Rectangle
-{
-    public FullRectangle(Color c, int x1, int y1, int x2, int y2) 
-    {
-        super(c, x1, y1, x2, y2);
-    }   
-    
-    @Override
-    public void paint(Graphics g) 
-    {
-        g.fillRect(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
-    }
-}

+ 12 - 0
src/me/hammerle/graphics/Graphic.java

@@ -0,0 +1,12 @@
+package me.hammerle.graphics;
+
+import java.awt.Graphics;
+
+public interface Graphic 
+{
+    public void paint(Graphics g);
+    
+    public boolean hasColor();
+    
+    public void translate(int x, int y);
+}

+ 33 - 33
src/me/hammerle/code/ScriptEngine.java → src/me/hammerle/graphics/GraphicFrame.java

@@ -1,6 +1,5 @@
-package me.hammerle.code;
+package me.hammerle.graphics;
 
-import java.awt.Color;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
@@ -8,17 +7,24 @@ import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import javax.swing.JFrame;
 import javax.swing.event.MouseInputAdapter;
+import me.hammerle.code.Script;
 
-public class ScriptEngine extends JFrame
+public class GraphicFrame extends JFrame
 {
-    public final GraphicEngine graphics;
+    private final Script parent;
+    public final GraphicPanel graphics;
     
-    public ScriptEngine()
+    public GraphicFrame(int width, int height, Script sc)
     {
-        graphics = new GraphicEngine();
-        graphics.setBackground(Color.black);
-        super.add(graphics);
+        parent = sc;
+        graphics = new GraphicPanel();
+        
+        super.setSize(width, height + 22);
+        super.setResizable(false);
         super.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+        super.setVisible(true);
+        super.add(graphics);
+        
         super.addWindowListener(new WindowAdapter() 
         {
             @Override
@@ -59,40 +65,34 @@ public class ScriptEngine extends JFrame
     
     private void windowClosingEvent(WindowEvent e)
     {
-        /*ScriptData sd = SnuviScript.scriptController.getActiveScript();
-        if(sd.isEventLoaded("window-closing"))
+        if(parent.isLoadedEvent("window-closing"))
         {
-            sd.setVar("event", "window-closing");
-            sd.nextCodeLine();
-            CodeParser.continueCode(sd, null); 
-        }*/
+            parent.setVar("event", "window-closing");
+            parent.runCode(); 
+        }
     }
     
     private void keyEvent(KeyEvent e, String name)
     {
-        /*ScriptData sd = SnuviScript.scriptController.getActiveScript();
-        if(sd.isEventLoaded("key-" + name))
+        if(parent.isLoadedEvent("key-" + name))
         {
-            sd.setVar("event", "key-" + name);
-            sd.setVar("keycode", e.getKeyCode());
-            sd.setVar("keychar", e.getKeyChar());
-            sd.nextCodeLine();
-            CodeParser.continueCode(sd, null); 
-        }*/
+            parent.setVar("event", "key-" + name);
+            parent.setVar("keycode", e.getKeyCode());
+            parent.setVar("keychar", e.getKeyChar());
+            parent.runCode(); 
+        }
     }
     
     private void mouseEvent(MouseEvent e, String name)
-    {
-        /*ScriptData sd = SnuviScript.scriptController.getActiveScript();
-        if(sd.isEventLoaded("mouse-" + name))
+    {      
+        if(parent.isLoadedEvent("mouse-" + name))
         {
-            sd.setVar("event", "mouse-" + name);
-            sd.setVar("button", e.getButton());
-            sd.setVar("count", e.getClickCount());
-            sd.setVar("x", e.getX());
-            sd.setVar("y", e.getY());
-            sd.nextCodeLine();
-            CodeParser.continueCode(sd, null); 
-        }*/
+            parent.setVar("event", "mouse-" + name);
+            parent.setVar("button", e.getButton());
+            parent.setVar("count", e.getClickCount());
+            parent.setVar("x", e.getX());
+            parent.setVar("y", e.getY());
+            parent.runCode();  
+        }
     }
 }

+ 0 - 26
src/me/hammerle/graphics/GraphicObject.java

@@ -1,26 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Graphics;
-
-public abstract class GraphicObject 
-{
-    private Color c;
-    
-    public GraphicObject(Color c)
-    {
-        this.c = c;        
-    }
-    
-    public Color getColor()
-    {
-        return c;
-    }
-    
-    public void setColor(Color c)
-    {
-        this.c = c;
-    }
-    
-    public abstract void paint(Graphics g);
-}

+ 46 - 0
src/me/hammerle/graphics/GraphicPanel.java

@@ -0,0 +1,46 @@
+package me.hammerle.graphics;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.util.TreeMap;
+import javax.swing.JPanel;
+
+public class GraphicPanel extends JPanel
+{
+    private final TreeMap<Integer, Graphic> objects;
+    
+    public GraphicPanel()
+    {
+        this.objects = new TreeMap<>();
+        super.setBackground(Color.black);
+    }
+    
+    public synchronized Graphic getGraphic(int id)
+    {
+        return objects.get(id);
+    }
+    
+    public synchronized void removeGraphic(int id)
+    {
+        objects.remove(id);
+    }
+    
+    public synchronized void addGraphic(int id, Graphic g)
+    {
+        objects.put(id, g);
+    }
+    
+    @Override
+    public synchronized void paint(Graphics g) 
+    {
+        super.paint(g);
+        objects.values().forEach(go -> 
+        {
+            if(go.hasColor())
+            {
+                g.setColor(((Colorable) go).getColor());
+            }
+            go.paint(g);
+        });
+    }   
+}

+ 15 - 12
src/me/hammerle/graphics/Image.java

@@ -2,46 +2,43 @@ package me.hammerle.graphics;
 
 import java.awt.Graphics;
 import java.awt.image.BufferedImage;
-import me.hammerle.snuviscript.SnuviScript;
 
-public class Image extends Line implements StartPoint
+public class Image extends Line implements Graphic
 {
     private int x;
     private int y;
     private BufferedImage image;
+    private final GraphicPanel panel;
     
-    public Image(BufferedImage image, int x, int y, int x1, int y1, int x2, int y2)
+    public Image(GraphicPanel panel, BufferedImage image, int x, int y, int x1, int y1, int x2, int y2)
     {
         super(null, x1, y1, x2, y2);
         this.image = image;
         this.x = x;
         this.y = y;
+        this.panel = panel;
     }
     
-    public Image(BufferedImage image, int x, int y)
+    public Image(GraphicPanel panel, BufferedImage image, int x, int y)
     {
-        this(image, x, y, 0, 0, image.getWidth(), image.getHeight());
+        this(panel, image, x, y, 0, 0, image.getWidth(), image.getHeight());
     }
     
-    @Override
     public void setX(int x)
     {
         this.x = x;
     }
     
-    @Override
     public void setY(int y)
     {
         this.y = y;
     }
-    
-    @Override
+
     public int getX()
     {
         return x;
     }
-    
-    @Override
+
     public int getY()
     {
         return y;
@@ -55,6 +52,12 @@ public class Image extends Line implements StartPoint
     @Override
     public void paint(Graphics g) 
     {
-        g.drawImage(image.getSubimage(x1, y1, x2 - x1, y2 - y1), x, y, SnuviScript.screen);
+        g.drawImage(image.getSubimage(x1, y1, x2 - x1, y2 - y1), x, y, panel);
+    }
+
+    @Override
+    public boolean hasColor() 
+    {
+        return false;
     }
 }

+ 17 - 2
src/me/hammerle/graphics/Line.java

@@ -3,7 +3,7 @@ package me.hammerle.graphics;
 import java.awt.Color;
 import java.awt.Graphics;
 
-public class Line extends GraphicObject
+public class Line extends Colorable implements Graphic
 {
     protected int x1;
     protected int y1;
@@ -19,7 +19,7 @@ public class Line extends GraphicObject
         this.y2 = y2;
     }   
     
-    public void setFirstX(int x)    
+    public void setFirstX(int x) 
     {
         x1 = x;
     }
@@ -64,4 +64,19 @@ public class Line extends GraphicObject
     {
         g.drawLine(x1, y1, x2, y2);
     }
+
+    @Override
+    public boolean hasColor() 
+    {
+        return true;
+    }
+
+    @Override
+    public void translate(int x, int y) 
+    {
+        x1 += x;
+        x2 += x;
+        y1 += y;
+        y2 += y;
+    }
 }

+ 8 - 1
src/me/hammerle/graphics/Oval.java

@@ -13,6 +13,13 @@ public class Oval extends Line
     @Override
     public void paint(Graphics g) 
     {
-        g.drawOval(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
+        if(isFilled())
+        {
+            g.fillOval(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
+        }
+        else
+        {
+            g.drawOval(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
+        }
     }
 }

+ 39 - 0
src/me/hammerle/graphics/Point.java

@@ -0,0 +1,39 @@
+package me.hammerle.graphics;
+
+import java.awt.Color;
+
+public class Point extends Line
+{
+    public Point(Color c, int x, int y) 
+    {
+        super(c, x, y, x, y);
+    }
+    
+    @Override
+    public void setFirstX(int x) 
+    {
+        x1 = x;
+        x2 = x;
+    }
+    
+    @Override
+    public void setFirstY(int y)    
+    {
+        y1 = y;
+        y2 = y;
+    }
+    
+    @Override
+    public void setSecondX(int x)    
+    {
+        x2 = x;
+        x2 = x;
+    }
+    
+    @Override
+    public void setSecondY(int y)    
+    {
+        y2 = y;
+        y2 = y;
+    }
+}

+ 8 - 1
src/me/hammerle/graphics/Rectangle.java

@@ -13,6 +13,13 @@ public class Rectangle extends Line
     @Override
     public void paint(Graphics g) 
     {
-        g.drawRect(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
+        if(isFilled())
+        {
+            g.fillRect(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
+        }
+        else
+        {
+            g.drawRect(x1, y1, x2 - x1 - 1, y2 - y1 - 1);
+        }
     }
 }

+ 0 - 9
src/me/hammerle/graphics/StartPoint.java

@@ -1,9 +0,0 @@
-package me.hammerle.graphics;
-
-public interface StartPoint 
-{
-    public void setX(int x);
-    public void setY(int y);
-    public int getX();
-    public int getY();
-}

+ 0 - 73
src/me/hammerle/graphics/Text.java

@@ -1,73 +0,0 @@
-package me.hammerle.graphics;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics;
-
-public class Text extends GraphicObject implements StartPoint
-{
-    private String text;
-    private Font font;
-    private int x;
-    private int y;
-    
-    public Text(Color c, int x, int y, String text, Font font) 
-    {
-        super(c);
-        this.x = x;
-        this.y = y;
-        this.text = text;
-        this.font = font;
-    }
-    
-    @Override
-    public void setX(int x)
-    {
-        this.x = x;
-    }
-    
-    @Override
-    public void setY(int y)
-    {
-        this.y = y;
-    }
-    
-    @Override
-    public int getX()
-    {
-        return x;
-    }
-    
-    @Override
-    public int getY()
-    {
-        return y;
-    }
-    
-    public void setText(String text)
-    {
-        this.text = text;
-    }
-    
-    public void setfont(Font font)
-    {
-        this.font = font;
-    }
-    
-    public String getText()
-    {
-        return text;
-    }
-    
-    public Font getfont()
-    {
-        return font;
-    }
-
-    @Override
-    public void paint(Graphics g) 
-    {
-        g.setFont(font);
-        g.drawString(text, x, y);
-    }  
-}

+ 11 - 4
src/me/hammerle/snuviscript/SnuviScript.java

@@ -2,14 +2,12 @@ package me.hammerle.snuviscript;
 
 import me.hammerle.code.CodeParser;
 import me.hammerle.console.Console;
-import me.hammerle.code.ScriptEngine;
 import me.hammerle.code.ScriptControl;
+import me.hammerle.code.ScriptUtils;
+import me.hammerle.exceptions.FileException;
 
 public class SnuviScript 
 {
-    public static ScriptEngine screen;
-    public static ScriptControl scriptController;
-    
     public static Console console;
     
     public static void main(String[] args) 
@@ -17,6 +15,15 @@ public class SnuviScript
         CodeParser.initCodeParser();
         console = new Console();
         
+        try
+        {
+            ScriptControl.startScriptFromFile("start"); 
+        }
+        catch(FileException ex)
+        {
+            ScriptUtils.printDebug("You haven't configured a start file yet.");
+        }
+        
         /*for(String s : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())
         {
             System.out.println(s);

+ 20 - 0
start.snuvi

@@ -0,0 +1,20 @@
+time = time.get();
+c = read.color(255,255,255, 100);
+
+size = 500;
+
+g.new(size, size);
+
+i = 1;
+while(i < 1000)
+{
+    x = math.random(0, size);
+    y = math.random(0, size);
+    g.newPoint(i, c, x, y);
+    i += 1;
+    reset();
+}
+g.repaint();
+
+debug(time.get() - time);
+wait();