public InterpretedClass(ClassDeclarationExpression expression, Scope scope)
            {
                _rootscope        = scope.Root;
                _name             = expression.Name;
                _parents          = expression.Parents;
                _interfaces       = expression.Interfaces;
                _methods          = new MethodCollection();
                _fields           = new FieldCollection();
                _classes          = new ClassCollection();
                _static_variables = new VariableCollection();

                ScriptScope script_scope = null;

                scope.FindNearestScope <ScriptScope> (ss => script_scope = ss);

                foreach (ClassMethodDeclarationExpression m in expression.Methods)
                {
                    _methods.Add(new InterpretedMethod(m, script_scope));
                }

                foreach (ClassFieldDeclarationExpression f in expression.Fields)
                {
                    IVariable var = _static_variables.EnsureExists(f.Name);
                    if (f.Initializer is Expression initializer_expr)
                    {
                        var.Value = Interpreters.Execute(initializer_expr, script_scope).ResultValue;
                    }
                }
            }
Beispiel #2
0
 public ClassDeclarationExpression(NameOfClass name, ImmutableArray <NameOfClass> parents, ImmutableArray <NameOfClass> interfaces, ImmutableArray <ClassFieldDeclarationExpression> fields, ImmutableArray <ClassMethodDeclarationExpression> methods)
 {
     Name       = name;
     Parents    = parents;
     Interfaces = interfaces;
     Fields     = fields;
     Methods    = methods;
 }
Beispiel #3
0
        private void standardAICharacterClass(string pathString)
        {
            string copyPath = pathString + NameOfClass + ".cs";

            Debug.Log("Creating Classfile: " + copyPath);

            if (!File.Exists(copyPath))
            {
                using (StreamWriter outfile =
                           new StreamWriter(copyPath))
                {
                    if (withCustomBrains)
                    {
                        outfile.WriteLine("using " + nameOfNamespace + ".Entity.Behaviour;");
                    }
                    if (!nameOfNamespace.Equals(namespaceOfParentClass))
                    {
                        Debug.Log(nameOfNamespace + "   " + namespaceOfParentClass);
                        outfile.WriteLine("using " + namespaceOfParentClass + ".Entity.NonPlayerCharacter;");
                    }
                    outfile.WriteLine("using " + nameOfNamespace + ".Entity.NonPlayerCharacter.StateMachine.Logic." + NameOfClass + ";");
                    outfile.WriteLine("using GameLib.Entity.NonPlayerCharacter.StateMachine;\n");
                    outfile.WriteLine("namespace " + nameOfNamespace + ".Entity.NonPlayerCharacter");
                    outfile.WriteLine("{");
                    if (NameOfClass.Equals(nameOfParentClass))
                    {
                        outfile.WriteLine("\tpublic class " + NameOfClass + " : " + namespaceOfParentClass + ".Entity.NonPlayerCharacter." + nameOfParentClass);
                    }
                    else
                    {
                        outfile.WriteLine("\tpublic class " + NameOfClass + " : " + nameOfParentClass);
                    }
                    outfile.WriteLine("\t{");
                    outfile.WriteLine("\t\t// Use this for initialization");
                    outfile.WriteLine("\t\tprotected override void init()");
                    outfile.WriteLine("\t\t{");
                    outfile.WriteLine("\t\t\tbase.init();");
                    outfile.WriteLine("\t\t\tIAIControllerFactory controllerFactory = AIControllerFactory.getEntity();");
                    outfile.WriteLine("\t\t\taiCharacterController = controllerFactory.getAICharacterController(this, new BrainFactory());");
                    outfile.WriteLine("\t\t\t//Initialize your attributes or other necessities below.\n");
                    outfile.WriteLine("\t\t}\n");

                    outfile.WriteLine("\t\tprotected override void fixedUpdateBody()");
                    outfile.WriteLine("\t\t{");
                    outfile.WriteLine("\t\t\tbase.fixedUpdateBody();");
                    outfile.WriteLine("\t\t\t//Add your code below.\n");
                    outfile.WriteLine("\t\t}");
                    outfile.WriteLine("\t}");
                    outfile.WriteLine("}");
                }//File written
            }
        }