Refactor cpp script templates after new features
This commit is contained in:
@@ -14,8 +14,10 @@ API_CLASS() class %module%%class% : public ISerializable
|
|||||||
API_AUTO_SERIALIZATION();
|
API_AUTO_SERIALIZATION();
|
||||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(%class%);
|
DECLARE_SCRIPTING_TYPE_NO_SPAWN(%class%);
|
||||||
public:
|
public:
|
||||||
|
// Custom float value.
|
||||||
API_FIELD(Attributes = "Range(0, 20), EditorOrder(0), EditorDisplay(\"Data\")")
|
API_FIELD(Attributes = "Range(0, 20), EditorOrder(0), EditorDisplay(\"Data\")")
|
||||||
float FloatValue = 20.0f;
|
float FloatValue = 20.0f;
|
||||||
|
// Custom vector data.
|
||||||
API_FIELD(Attributes = "EditorOrder(1), EditorDisplay(\"Data\")")
|
API_FIELD(Attributes = "EditorOrder(1), EditorDisplay(\"Data\")")
|
||||||
Vector3 Vector3Value = Vector3(0.1f);
|
Vector3 Vector3Value = Vector3(0.1f);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,5 @@
|
|||||||
|
|
||||||
void %class%::RunNativeAction(Vector4 data)
|
void %class%::RunNativeAction(Vector4 data)
|
||||||
{
|
{
|
||||||
LOG(Warning, "Data in RunNativeAction: {0}", data.ToString());
|
LOG(Warning, "Data in RunNativeAction: {0}", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <Engine/Scripting/Script.h>
|
#include <Engine/Scripting/Script.h>
|
||||||
#include <Engine/Core/Math/Vector4.h>
|
#include <Engine/Core/Math/Vector4.h>
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// %class% Function Library
|
/// %class% Function Library
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -10,10 +11,10 @@ API_CLASS(Static) class %module%%class%
|
|||||||
{
|
{
|
||||||
DECLARE_SCRIPTING_TYPE_MINIMAL(%class%);
|
DECLARE_SCRIPTING_TYPE_MINIMAL(%class%);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs the function parameter natively.
|
/// Logs the function parameter natively.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">Vector4 parameter</param>
|
/// <param name="data">Data to pass to native code</param>
|
||||||
/// <returns>void</returns>
|
|
||||||
API_FUNCTION() static void RunNativeAction(Vector4 data);
|
API_FUNCTION() static void RunNativeAction(Vector4 data);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
%copyright%
|
%copyright%
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Engine/Scripting/Script.h"
|
#include <Engine/Scripting/Script.h>
|
||||||
|
|
||||||
API_CLASS() class %module%%class% : public Script
|
API_CLASS() class %module%%class% : public Script
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using FlaxEditor.Content.Settings;
|
|
||||||
using FlaxEngine;
|
|
||||||
|
|
||||||
namespace FlaxEditor.Content
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Context proxy object for C++ Json Asset files.
|
|
||||||
/// </summary>
|
|
||||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
|
||||||
public class CppAssetProxy : ScriptProxy
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string Name => "C++ Json Asset";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool IsProxyFor(ContentItem item)
|
|
||||||
{
|
|
||||||
return item is CppScriptItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Create(string outputPath, object arg)
|
|
||||||
{
|
|
||||||
// Load templates
|
|
||||||
var headerTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppAssetTemplate.h"));
|
|
||||||
|
|
||||||
// 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 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);
|
|
||||||
// Save
|
|
||||||
File.WriteAllText(Path.ChangeExtension(outputPath, ".h"), headerTemplate, Encoding.UTF8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string FileExtension => "cpp";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Color AccentColor => Color.FromRGB(0x9c1c9c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
134
Source/Editor/Content/Proxy/CppProxy.cs
Normal file
134
Source/Editor/Content/Proxy/CppProxy.cs
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using FlaxEditor.Content.Settings;
|
||||||
|
using FlaxEngine;
|
||||||
|
|
||||||
|
namespace FlaxEditor.Content
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Context proxy object for C++ files.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||||
|
public abstract class CppProxy : ScriptProxy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the paths for header and source files to format.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="headerTemplate">The header template path.</param>
|
||||||
|
/// <param name="sourceTemplate">The source template path.</param>
|
||||||
|
protected abstract void GetTemplatePaths(out string headerTemplate, out string sourceTemplate);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool IsProxyFor(ContentItem item)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Create(string outputPath, object arg)
|
||||||
|
{
|
||||||
|
// 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 ";
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
GetTemplatePaths(out var headerTemplatePath, out var sourceTemplatePath);
|
||||||
|
if (headerTemplatePath != null)
|
||||||
|
{
|
||||||
|
var headerTemplate = File.ReadAllText(headerTemplatePath);
|
||||||
|
headerTemplate = headerTemplate.Replace("%copyright%", copyrightComment);
|
||||||
|
headerTemplate = headerTemplate.Replace("%class%", scriptName);
|
||||||
|
headerTemplate = headerTemplate.Replace("%module%", module);
|
||||||
|
headerTemplate = headerTemplate.Replace("%filename%", filename);
|
||||||
|
File.WriteAllText(Path.ChangeExtension(outputPath, ".h"), headerTemplate, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
if (sourceTemplatePath != null)
|
||||||
|
{
|
||||||
|
var sourceTemplate = File.ReadAllText(sourceTemplatePath);
|
||||||
|
sourceTemplate = sourceTemplate.Replace("%copyright%", copyrightComment);
|
||||||
|
sourceTemplate = sourceTemplate.Replace("%class%", scriptName);
|
||||||
|
sourceTemplate = sourceTemplate.Replace("%module%", module);
|
||||||
|
sourceTemplate = sourceTemplate.Replace("%filename%", filename);
|
||||||
|
File.WriteAllText(outputPath, sourceTemplate, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string FileExtension => "cpp";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Color AccentColor => Color.FromRGB(0x9c1c9c);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Context proxy object for C++ script files.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||||
|
public class CppScriptProxy : CppProxy
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Name => "C++ Script";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool IsProxyFor(ContentItem item)
|
||||||
|
{
|
||||||
|
return item is CppScriptItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate)
|
||||||
|
{
|
||||||
|
headerTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.h");
|
||||||
|
sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/ScriptTemplate.cpp");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Context proxy object for C++ Json Asset files.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||||
|
public class CppStaticClassProxy : CppProxy
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Name => "C++ Function Library";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate)
|
||||||
|
{
|
||||||
|
headerTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.h");
|
||||||
|
sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.cpp");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Context proxy object for C++ Json Asset files.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
||||||
|
public class CppAssetProxy : CppProxy
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Name => "C++ Json Asset";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void GetTemplatePaths(out string headerTemplate, out string sourceTemplate)
|
||||||
|
{
|
||||||
|
headerTemplate = null;
|
||||||
|
sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppAssetTemplate.h");
|
||||||
|
//sourceTemplate = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppAssetTemplate.cpp");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string FileExtension => "h";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using FlaxEditor.Content.Settings;
|
|
||||||
using FlaxEngine;
|
|
||||||
|
|
||||||
namespace FlaxEditor.Content
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Context proxy object for C++ script files.
|
|
||||||
/// </summary>
|
|
||||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
|
||||||
public class CppScriptProxy : ScriptProxy
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string Name => "C++ Script";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool IsProxyFor(ContentItem item)
|
|
||||||
{
|
|
||||||
return item is CppScriptItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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 string FileExtension => "cpp";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Color AccentColor => Color.FromRGB(0x9c1c9c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using FlaxEditor.Content.Settings;
|
|
||||||
using FlaxEngine;
|
|
||||||
|
|
||||||
namespace FlaxEditor.Content
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Context proxy object for C++ Json Asset files.
|
|
||||||
/// </summary>
|
|
||||||
/// <seealso cref="FlaxEditor.Content.CSharpScriptProxy" />
|
|
||||||
public class CppStaticClassProxy : ScriptProxy
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string Name => "C++ Function Library";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool IsProxyFor(ContentItem item)
|
|
||||||
{
|
|
||||||
return item is CppScriptItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Create(string outputPath, object arg)
|
|
||||||
{
|
|
||||||
// Load templates
|
|
||||||
var headerTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.h"));
|
|
||||||
var sourceTemplate = File.ReadAllText(StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor/Scripting/CppStaticClassTemplate.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 string FileExtension => "cpp";
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Color AccentColor => Color.FromRGB(0x9c1c9c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user