예제 #1
0
        /// <summary>
        /// Compile and Serialize the specified script file.
        /// </summary>
        /// <param name="scriptPathWithoutExtension">Script path without extension.</param>
        public void serialize(string scriptPathWithoutExtension)
        {
            Console.WriteLine("...Compiling: " + scriptPathWithoutExtension);
            string scriptText = File.ReadAllText(scriptPathWithoutExtension + "." + ScriptKeyword.SCRIPT_EXTENSION, System.Text.Encoding.UTF8);

            System.Console.WriteLine("...Deleting comments");
            string scriptTextWithoutComment = Regex.Replace(scriptText, "\\/\\/[^\\n]*", string.Empty);

            System.Console.WriteLine("...Comment deleted");
            //System.Console.Write (scriptTextWithoutComment);
            DokiScriptCompiler compiler = null;

            compiler = new DokiScriptCompiler();

            List <Action> actions = compiler.compile(scriptTextWithoutComment);

            try{
                BinaryFormatter bf = new BinaryFormatter();

                Script scriptData = new Script();
                scriptData.actions = actions;

                FileStream scriptFile = File.Create(scriptPathWithoutExtension + "." + ScriptKeyword.SCRIPT_EXTENSION + "." + ScriptKeyword.SCRIPT_COMPILED_EXTENSION);
                bf.Serialize(scriptFile, scriptData);
                scriptFile.Close();
            }catch (IOException ex) {
                Console.WriteLine("IO error when saving: " + ex.Message);
            }

            for (int i = 0; i < actions.Count; i++)
            {
                Console.Write(actions[i].tag);
                Console.Write(": ");
                foreach (KeyValuePair <string, string> kv in actions[i].parameters)
                {
                    Console.Write(kv.Key + "=" + kv.Value + " ");
                }
                Console.WriteLine();
            }
        }
예제 #2
0
        /// <summary>
        /// Compile and Serialize the specified script file.
        /// </summary>
        /// <param name="scriptPathWithoutExtension">Script path without extension.</param>
        public void serialize(string scriptPathWithoutExtension)
        {
            Console.WriteLine ("...Compiling: "+scriptPathWithoutExtension);
            string scriptText = File.ReadAllText(scriptPathWithoutExtension + "." + ScriptKeyword.SCRIPT_EXTENSION, System.Text.Encoding.UTF8);

            System.Console.WriteLine ("...Deleting comments");
            string scriptTextWithoutComment = Regex.Replace(scriptText,"\\/\\/[^\\n]*", string.Empty);
            System.Console.WriteLine ("...Comment deleted");
            //System.Console.Write (scriptTextWithoutComment);
            DokiScriptCompiler  compiler = null;
            compiler = new DokiScriptCompiler();

            List<Action> actions = compiler.compile(scriptTextWithoutComment);

            try{
                BinaryFormatter bf = new BinaryFormatter();

                Script scriptData = new Script();
                scriptData.actions = actions;

                FileStream scriptFile = File.Create(scriptPathWithoutExtension + "." + ScriptKeyword.SCRIPT_EXTENSION + "." + ScriptKeyword.SCRIPT_COMPILED_EXTENSION);
                bf.Serialize(scriptFile, scriptData);
                scriptFile.Close();
            }catch(IOException ex){
                Console.WriteLine("IO error when saving: " + ex.Message);
            }

            for(int i=0;i<actions.Count; i++){
                Console.Write (actions[i].tag);
                Console.Write (": ");
                foreach (KeyValuePair<string, string> kv in actions[i].parameters) {
                    Console.Write (kv.Key + "=" + kv.Value + " ");
                }
                Console.WriteLine ();
            }
        }