From 1899169a2e6130e8b730504ccfb3132c6527acd7 Mon Sep 17 00:00:00 2001 From: emerycp Date: Sat, 8 Jul 2023 00:19:25 -0400 Subject: [PATCH] File Broweser - Add Wren Script on Right-Click --- Editor/src/Windows/FileSystemUI.cpp | 72 ++++++++++++++++++----------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 6c5096d6..13acd965 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -9,35 +9,34 @@ #include "src/Rendering/Textures/TextureManager.h" #include "EditorInterface.h" -const std::string TEMPLATE_SCRIPT_BEGIN = "import \"Nuake:Engine\" for Engine \ -import \"Nuake:ScriptableEntity\" for ScriptableEntity \ -import \"Nuake:Input\" for Input \ -import \"Nuake:Scene\" for Scene \ -\ -class "; +const std::string TEMPLATE_SCRIPT = R"(import "Nuake:Engine" for Engine +import "Nuake:ScriptableEntity" for ScriptableEntity +import "Nuake:Input" for Input +import "Nuake:Math" for Vector3, Math +import "Nuake:Scene" for Scene -const std::string TEMPLATE_SCRIPT_END = " is ScriptableEntity {\ -construct new(){\ - _ReloadSpeed = 0.1\ - _Intensity = 0.0\ -}\ -\ -init() {\ -}\ -\ -// Updates every frame\ -update(ts) {\ -\ -}\ -\ -// Updates every tick\ -fixedUpdate(ts) {\ - \ -}\ -\ -exit() {\ -}\ -}"; +class MyEntityScript is ScriptableEntity { + construct new() { + } + + // Called when the scene gets initialized + init() { + // Engine.Log("Hello World!") + } + + // Called every update + update(ts) { + } + + // Called 90 times per second + fixedUpdate(ts) { + } + + // Called on shutdown + exit() { + } +} +)"; #include @@ -215,6 +214,23 @@ namespace Nuake { } } + if (ImGui::MenuItem("Wren Script")) + { + std::string path = FileDialog::SaveFile("*.wren"); + if (!String::EndsWith(path, ".wren")) + { + path += ".wren"; + } + + if (!path.empty()) + { + + FileSystem::BeginWriteFile(path); + FileSystem::WriteLine(TEMPLATE_SCRIPT); + FileSystem::EndWriteFile(); + } + } + ImGui::EndMenu(); }