Exemple #1
0
 public static string GetNamespace(FD.FlowWindow window)
 {
     return(string.Format("{0}{1}", Tpl.GetNamespace(), IO.GetRelativePath(window, ".")));
 }
Exemple #2
0
        private static void GenerateWindow(string newPath, FD.FlowWindow window, bool recompile, bool minimalScriptsSize)
        {
            if (window.compiled == true && recompile == false)
            {
                return;
            }

            var oldPath = window.compiledDirectory;

            var newInfo = new Tpl.Info(Tpl.GetNamespace(window), Tpl.GetDerivedClassName(window), Tpl.GetBaseClassName(window), Tpl.GetContainerClassName(window), window.directory);
            var oldInfo = new Tpl.Info(window);

            if (string.IsNullOrEmpty(oldPath) == true)
            {
                oldPath = newPath;
            }

            var path = oldPath;

            if (window.compiled == true && (oldPath != newPath))
            {
                // If window is moving and compiled - just rename

                // Replace in files
                IO.ReplaceInFiles(CompilerSystem.currentProjectDirectory, (file) => {
                    var text = file.text;
                    return(text.Contains(oldInfo.baseNamespace));
                }, (text) => {
                    return(Tpl.ReplaceText(text, oldInfo, newInfo));
                });

                // Rename base class name
                IO.RenameFile(oldPath + oldInfo.baseClassnameFile, oldPath + newInfo.baseClassnameFile);

                // Rename derived class name
                IO.RenameFile(oldPath + oldInfo.classnameFile, oldPath + newInfo.classnameFile);

                // Rename main folder
                IO.RenameDirectory(oldPath, newPath);

                path = newPath;
            }

            // Rebuild without rename
            //Debug.Log(window.title + " :: REBUILD BASE :: " + path);

            string baseClassTemplate = null;

            if (window.IsContainer() == true)
            {
                baseClassTemplate = TemplateGenerator.GenerateWindowLayoutContainerBaseClass(newInfo.baseClassname, newInfo.baseNamespace, newInfo.containerClassName);
            }
            else
            {
                baseClassTemplate = TemplateGenerator.GenerateWindowLayoutBaseClass(newInfo.baseClassname, newInfo.baseNamespace, newInfo.containerClassName, Tpl.GenerateTransitionMethods(window));
            }

            var derivedClassTemplate = TemplateGenerator.GenerateWindowLayoutDerivedClass(newInfo.classname, newInfo.baseClassname, newInfo.baseNamespace);

            //Debug.Log(newPath + " :: " + newInfo.containerClassName + " :: " + baseClassTemplate);
            //return;

            if (minimalScriptsSize == true)
            {
                baseClassTemplate = CompilerSystem.Compress(baseClassTemplate);
            }

            if (window.IsContainer() == false)
            {
                IO.CreateDirectory(path, string.Empty);
                IO.CreateDirectory(path, FlowDatabase.COMPONENTS_FOLDER);
                IO.CreateDirectory(path, FlowDatabase.LAYOUT_FOLDER);
                IO.CreateDirectory(path, FlowDatabase.SCREENS_FOLDER);
            }

            if (baseClassTemplate != null && derivedClassTemplate != null)
            {
                IO.CreateFile(path, newInfo.baseClassnameFile, baseClassTemplate, rewrite: true);
                IO.CreateFile(path, newInfo.classnameFile, derivedClassTemplate, rewrite: false);
            }

            window.compiledNamespace        = newInfo.baseNamespace;
            window.compiledScreenName       = newInfo.screenName;
            window.compiledBaseClassName    = newInfo.baseClassname;
            window.compiledDerivedClassName = newInfo.classname;

            window.compiledDirectory = path;
            window.compiled          = true;
        }