/// <inheritdoc /> public override void Create(string outputPath, object arg) { // Load templates var headerTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.h")); var sourceTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.cpp")); // Find the module that this script is being added (based on the path) var module = string.Empty; var project = TryGetProjectAtFolder(outputPath, out var moduleName); if (project != null) { module = moduleName.ToUpperInvariant() + "_API "; } // Format var gameSettings = GameSettings.Load(); var scriptName = ScriptItem.CreateScriptName(outputPath); var filename = Path.GetFileNameWithoutExtension(outputPath); var copyrightComment = string.IsNullOrEmpty(gameSettings.CopyrightNotice) ? string.Empty : string.Format("// {0}{1}{1}", gameSettings.CopyrightNotice, Environment.NewLine); headerTemplate = headerTemplate.Replace("%copyright%", copyrightComment); headerTemplate = headerTemplate.Replace("%class%", scriptName); headerTemplate = headerTemplate.Replace("%module%", module); sourceTemplate = sourceTemplate.Replace("%filename%", filename); sourceTemplate = sourceTemplate.Replace("%copyright%", copyrightComment); sourceTemplate = sourceTemplate.Replace("%class%", scriptName); sourceTemplate = sourceTemplate.Replace("%filename%", filename); // Save File.WriteAllText(Path.ChangeExtension(outputPath, ".h"), headerTemplate, Encoding.UTF8); File.WriteAllText(outputPath, sourceTemplate, Encoding.UTF8); }
/// <inheritdoc /> public override void Create(string outputPath, object arg) { // Load template var templatePath = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.cs"); var scriptTemplate = File.ReadAllText(templatePath); // Find the module that this script is being added (based on the path) var scriptNamespace = Editor.Instance.GameProject.Name; var project = TryGetProjectAtFolder(outputPath, out var moduleName); if (project != null) { scriptNamespace = moduleName.Length != 0 ? moduleName : project.Name; } scriptNamespace = scriptNamespace.Replace(" ", ""); // Format var gameSettings = GameSettings.Load(); var scriptName = ScriptItem.CreateScriptName(outputPath); var copyrightComment = string.IsNullOrEmpty(gameSettings.CopyrightNotice) ? string.Empty : string.Format("// {0}{1}{1}", gameSettings.CopyrightNotice, Environment.NewLine); scriptTemplate = scriptTemplate.Replace("%copyright%", copyrightComment); scriptTemplate = scriptTemplate.Replace("%class%", scriptName); scriptTemplate = scriptTemplate.Replace("%namespace%", scriptNamespace); // Save File.WriteAllText(outputPath, scriptTemplate, Encoding.UTF8); }
/// <inheritdoc /> public override void Create(string outputPath) { // Load template var templatePath = StringUtils.CombinePaths(Globals.EditorFolder, "Scripting/ScriptTemplate.cs"); var scriptTemplate = File.ReadAllText(templatePath); var scriptNamespace = Editor.ProjectName.Replace(" ", ""); // Format var scriptName = ScriptItem.CreateScriptName(outputPath); scriptTemplate = scriptTemplate.Replace("%class%", scriptName); scriptTemplate = scriptTemplate.Replace("%namespace%", scriptNamespace); // Save File.WriteAllText(outputPath, scriptTemplate, Encoding.UTF8); }
/// <inheritdoc /> public override void Create(string outputPath, object arg) { // Load template var templatePath = StringUtils.CombinePaths(Globals.EditorFolder, "Scripting/ScriptTemplate.cs"); var scriptTemplate = File.ReadAllText(templatePath); var scriptNamespace = Editor.Instance.ProjectInfo.Name.Replace(" ", "") + ".Source"; // Get directories var sourceDirectory = Globals.ProjectFolder.Replace('\\', '/') + "/Source/"; var outputDirectory = new FileInfo(outputPath).DirectoryName.Replace('\\', '/'); // Generate "sub" namespace from relative path between source root and output path // NOTE: Could probably use Replace instead substring, but this is faster :) var subNamespaceStr = outputDirectory.Substring(sourceDirectory.Length - 1).Replace(" ", "").Replace(".", "").Replace('/', '.'); // Replace all namespace invalid characters // NOTE: Need to handle number sequence at the beginning since namespace which begin with numeric sequence are invalid string subNamespace = string.Empty; bool isStart = true; for (int pos = 0; pos < subNamespaceStr.Length; pos++) { var c = subNamespaceStr[pos]; if (isStart) { // Skip characters that cannot start the sub namespace if (char.IsLetter(c)) { isStart = false; subNamespace += '.'; subNamespace += c; } } else { // Add only valid characters if (char.IsLetterOrDigit(c) || c == '_') { subNamespace += c; } // Check for sub namespace start else if (c == '.') { isStart = true; } } } // Append if valid if (subNamespace.Length > 1) { scriptNamespace += subNamespace; } // Format var gameSettings = GameSettings.Load(); var scriptName = ScriptItem.CreateScriptName(outputPath); var copyrightComment = string.IsNullOrEmpty(gameSettings.CopyrightNotice) ? string.Empty : string.Format("// {0}{1}{1}", gameSettings.CopyrightNotice, Environment.NewLine); scriptTemplate = scriptTemplate.Replace("%copyright%", copyrightComment); scriptTemplate = scriptTemplate.Replace("%class%", scriptName); scriptTemplate = scriptTemplate.Replace("%namespace%", scriptNamespace); // Save File.WriteAllText(outputPath, scriptTemplate, Encoding.UTF8); }