(string outputPath, object arg)
| 78 | |
| 79 | /// <inheritdoc /> |
| 80 | public override void Create(string outputPath, object arg) |
| 81 | { |
| 82 | // Load template |
| 83 | var templatePath = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.cs"); |
| 84 | var scriptTemplate = File.ReadAllText(templatePath); |
| 85 | var scriptNamespace = Editor.Instance.GameProject.Name.Replace(" ", "") + ".Source"; |
| 86 | |
| 87 | // Get directories |
| 88 | var sourceDirectory = Globals.ProjectFolder.Replace('\\', '/') + "/Source/"; |
| 89 | var outputDirectory = new FileInfo(outputPath).DirectoryName.Replace('\\', '/'); |
| 90 | |
| 91 | // Generate "sub" namespace from relative path between source root and output path |
| 92 | // NOTE: Could probably use Replace instead substring, but this is faster :) |
| 93 | var subNamespaceStr = outputDirectory.Substring(sourceDirectory.Length - 1).Replace(" ", "").Replace(".", "").Replace('/', '.'); |
| 94 | |
| 95 | // Replace all namespace invalid characters |
| 96 | // NOTE: Need to handle number sequence at the beginning since namespace which begin with numeric sequence are invalid |
| 97 | string subNamespace = string.Empty; |
| 98 | bool isStart = true; |
| 99 | for (int pos = 0; pos < subNamespaceStr.Length; pos++) |
| 100 | { |
| 101 | var c = subNamespaceStr[pos]; |
| 102 | |
| 103 | if (isStart) |
| 104 | { |
| 105 | // Skip characters that cannot start the sub namespace |
| 106 | if (char.IsLetter(c)) |
| 107 | { |
| 108 | isStart = false; |
| 109 | subNamespace += '.'; |
| 110 | subNamespace += c; |
| 111 | } |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | // Add only valid characters |
| 116 | if (char.IsLetterOrDigit(c) || c == '_') |
| 117 | { |
| 118 | subNamespace += c; |
| 119 | } |
| 120 | // Check for sub namespace start |
| 121 | else if (c == '.') |
| 122 | { |
| 123 | isStart = true; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // Append if valid |
| 129 | if (subNamespace.Length > 1) |
| 130 | scriptNamespace += subNamespace; |
| 131 | |
| 132 | // Format |
| 133 | var gameSettings = GameSettings.Load(); |
| 134 | var scriptName = ScriptItem.CreateScriptName(outputPath); |
| 135 | var copyrightComment = string.IsNullOrEmpty(gameSettings.CopyrightNotice) ? string.Empty : string.Format("// {0}{1}{1}", gameSettings.CopyrightNotice, Environment.NewLine); |
| 136 | scriptTemplate = scriptTemplate.Replace("%copyright%", copyrightComment); |
| 137 | scriptTemplate = scriptTemplate.Replace("%class%", scriptName); |
nothing calls this directly
no test coverage detected