示例#1
0
        public static string Declaration(int indent, RootAccessModifier scope, string typeName, string inherits, List <Interface> interfaces, string attributes, string parameters, List <Variable> variables, string customVariables, string constructors, Methods methods, bool isLive)
        {
            var output = string.Empty;

            output += attributes + (string.IsNullOrEmpty(attributes) ? string.Empty : "\n");
            output += CodeBuilder.Indent(indent) + CodeBuilder.Scope(scope) + " " + Patcher.ObjectTypeName(ObjectKind.Class) + " " + typeName + CodeBuilder.TryAddBaseTypeSeperator(inherits, interfaces) + inherits + CodeBuilder.Interfaces(interfaces, inherits, (interfaces.Count > 0) ? true : false);
            output += "\n";
            output += CodeBuilder.Indent(indent) + "{";
            output += "\n";
            output += CodeBuilder.Variables(variables, indent + 1);
            output += (string.IsNullOrEmpty(constructors) ? string.Empty : "\n");
            output += constructors;
            output += CodeBuilder.Indent(indent) + "}";
            return(output);
        }
示例#2
0
        public static string MethodHeader(int depth, AccessModifier scope, MethodModifier modifier, Type returnType, string name, Dictionary <string, Type> parameters)
        {
            var header      = string.Empty;
            var keys        = parameters.Keys.ToListPooled();
            var values      = parameters.Values.ToListPooled();
            var _parameters = string.Empty;

            for (int i = 0; i < parameters.Count; i++)
            {
                _parameters += ((i > 0) ?" " : string.Empty);
                _parameters += values[i].CSharpName() + " ";
                _parameters += Patcher.LegalVariableName(keys[i], false) + ((i != parameters.Count - 1) ? "," : string.Empty);
            }

            header += "\n";
            header += CodeBuilder.Indent(depth) + Patcher.AddLowerUpperNeighboringSpaces(scope.ToString()).ToLower() +
                      " " + ((modifier == MethodModifier.None) ? string.Empty : modifier.ToString().ToLower()) +
                      ((modifier == MethodModifier.None) ? string.Empty : " ") +
                      (returnType == null || returnType == typeof(Void) ? typeof(void).CSharpName() : Ludiq.CSharpNameUtility.CSharpName(returnType)) + " " +
                      name + "(" + _parameters + ")";

            return(header);
        }
示例#3
0
        public static string EnumDeclaration(int indent, RootAccessModifier scope, string typeName, string attributes, List <Enum> items, bool isLive)
        {
            var output = string.Empty;

            output += attributes + (string.IsNullOrEmpty(attributes) ? string.Empty : "\n");
            output += CodeBuilder.Indent(indent) + CodeBuilder.Scope(scope) + " " + Patcher.ObjectTypeName(ObjectKind.Enum) + " " + typeName;
            output += "\n";
            output += CodeBuilder.Indent(indent) + "{";
            output += "\n";

            for (int i = 0; i < items.Count; i++)
            {
                output += CodeBuilder.Indent(indent + 1) + items[i].name + " = " + items[i].index.ToString();
                if (i != items.Count - 1)
                {
                    output += ",";
                }
                output += "\n";
            }

            output += CodeBuilder.Indent(indent) + "}";

            return(output);
        }
示例#4
0
        public static string Variables(List <Variable> variables, int indent)
        {
            var output = string.Empty;
            var count  = 0;

            foreach (Variable variable in variables)
            {
                count++;

                var asReadOnly = string.Empty;

                var type = variable.type.type;

                output += Indent(indent) + Scope(variable.scope) + VariableModifier(variable) + " " + Patcher.AsActualName(type) + " " + Patcher.LegalVariableName(variable.name, true);

                output += VariableScope(variable, indent);

                if (count < variables.Count)
                {
                    output += "\n";
                }
            }

            return(output);
        }
示例#5
0
 public static string Scope(AccessModifier modifier)
 {
     return(Patcher.AddLowerUpperNeighboringSpaces(modifier.ToString()).ToLower());
 }
示例#6
0
 public static string Scope(RootAccessModifier scope)
 {
     return(Patcher.AddLowerUpperNeighboringSpaces(scope.ToString().ToLower()));
 }
示例#7
0
        public static string Declaration(int indent, RootAccessModifier scope, ClassModifier modifier, string typeName, string inherits, List <Interface> interfaces, string attributes, string parameters, List <Variable> variables, string customVariables, string constructors, string preMethodCustomText, Methods methods, bool isLive)
        {
            var output = string.Empty;

            output += attributes + (string.IsNullOrEmpty(attributes) ? string.Empty : "\n");
            output += CodeBuilder.Indent(indent) + CodeBuilder.Scope(scope) + " " + ((modifier == ClassModifier.None) ? string.Empty : Patcher.AddLowerUpperNeighboringSpaces(modifier.ToString()).ToLower()) + " " + Patcher.ObjectTypeName(ObjectKind.Class) + " " + typeName + CodeBuilder.TryAddBaseTypeSeperator(inherits, interfaces) + inherits + CodeBuilder.Interfaces(interfaces, inherits, (interfaces.Count > 0) ? true : false);
            output += "\n";
            output += CodeBuilder.Indent(indent) + "{";
            output += "\n";
            output += CodeBuilder.Variables(variables, indent + 1);
            output += customVariables;
            output += (string.IsNullOrEmpty(customVariables) ? string.Empty : "\n");
            output += constructors;
            output += preMethodCustomText;
            output += string.IsNullOrEmpty(preMethodCustomText) ? string.Empty : "\n\n";
            output += MethodBuilder.Methods(indent + 1, methods, isLive);
            output += CodeBuilder.Indent(indent) + "}";
            return(output);
        }
示例#8
0
        public static string Proxy(ObjectMacro asset)
        {
            var output          = string.Empty;
            var @namespace      = asset.@namespace;
            var isNamespaceNull = string.IsNullOrEmpty(@namespace);
            var usingStatements = new List <string>();
            var inherits        = asset.baseType;
            var implements      = asset.interfaces.ToListPooled();
            var typeName        = Patcher.TypeName(asset);
            var variables       = asset.variables;
            var scope           = asset.scope;
            var modifier        = asset.classModifier;
            var name            = asset.name;
            var methods         = asset.methods;

            AssemblyBuilder.UsingStatement("System", usingStatements);
            AssemblyBuilder.UsingStatement("System.Linq", usingStatements);
            AssemblyBuilder.UsingStatement("System.Collections.Generic", usingStatements);
            AssemblyBuilder.UsingStatement("UnityEngine", usingStatements);
            AssemblyBuilder.UsingStatement("Lasm.UAlive", usingStatements);
            AssemblyBuilder.UsingStatement("Ludiq", usingStatements);
            AssemblyBuilder.UsingStatements(variables, usingStatements);
            AssemblyBuilder.UsingStatement(inherits.type, usingStatements);


            implements.Add(new Interface()
            {
                type = typeof(ILiveObject)
            });

            //var dynamicVariables = CodeBuilder.Indent(isNamespaceNull ? 1 : 2) + "[Serialize]" + "\n";
            //dynamicVariables += CodeBuilder.Indent(isNamespaceNull ? 1 : 2) + "protected Dictionary<string, object> variables = new Dictionary<string, object>();";

            var objectMacro = CodeBuilder.Indent(isNamespaceNull ? 1 : 2) + "protected ObjectMacro macro;" + "\n";

            var methodMacros = string.Empty;

            foreach (Method method in methods)
            {
                methodMacros += CodeBuilder.Indent(isNamespaceNull ? 1 : 2) + "protected Method " + method.name + "_Method;" + "\n";
            }



            string typeDeclaration = ClassBuilder.Declaration(
                isNamespaceNull ? 0 : 1,
                scope,
                modifier,
                typeName,
                inherits.type.CSharpName(false) == "object" ? string.Empty : inherits.type.CSharpName(false),
                implements,
                string.Empty,
                string.Empty,
                variables,
                objectMacro + methodMacros,
                string.Empty,
                string.Empty,
                methods,
                true
                );

            output += AssemblyBuilder.GenerateUsingStatements(usingStatements);

            output += "\n";
            output += "#if UNITY_EDITOR";
            output += "\n";
            output += "using UnityEditor;";
            output += "\n";
            output += "#endif";
            output += "\n \n";

            if (!isNamespaceNull)
            {
                output += AssemblyBuilder.Namespace(typeDeclaration, @namespace);
                return(output);
            }

            output += typeDeclaration;

            return(output);
        }
示例#9
0
 public static string TypeName(ObjectMacro asset)
 {
     return(Patcher.LegalVariableName((string.IsNullOrEmpty(asset.name) ? CodeBuilder.GetExtensionlessFileName(CodeBuilder.GetFileName(asset)).Replace(" ", string.Empty) : asset.name).Replace(" ", string.Empty), false));
 }