Browse Source

Working on editor generated C# projects

Josh Engebretson 10 years ago
parent
commit
7c223d1e95

+ 45 - 7
Source/ToolCore/NETTools/NETProjectGen.cpp

@@ -10,6 +10,8 @@
 #include <Atomic/IO/FileSystem.h>
 #include <Atomic/IO/FileSystem.h>
 
 
 #include "../ToolEnvironment.h"
 #include "../ToolEnvironment.h"
+#include "../ToolSystem.h"
+#include "../Project/Project.h"
 #include "NETProjectGen.h"
 #include "NETProjectGen.h"
 
 
 namespace ToolCore
 namespace ToolCore
@@ -29,12 +31,20 @@ NETProjectBase::~NETProjectBase()
 void NETProjectBase::ReplacePathStrings(String& path)
 void NETProjectBase::ReplacePathStrings(String& path)
 {
 {
     ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
     ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
+    ToolSystem* tsys = GetSubsystem<ToolSystem>();
 
 
     const String& atomicRoot = tenv->GetRootSourceDir();
     const String& atomicRoot = tenv->GetRootSourceDir();
     const String& scriptPlatform = projectGen_->GetScriptPlatform();
     const String& scriptPlatform = projectGen_->GetScriptPlatform();
 
 
     path.Replace("$ATOMIC_ROOT$", atomicRoot, false);
     path.Replace("$ATOMIC_ROOT$", atomicRoot, false);
     path.Replace("$SCRIPT_PLATFORM$", scriptPlatform, false);
     path.Replace("$SCRIPT_PLATFORM$", scriptPlatform, false);
+
+    Project* project = tsys->GetProject();
+    if (project)
+    {
+        path.Replace("$PROJECT_ROOT$", project->GetProjectPath(), false);
+    }
+
 }
 }
 
 
 NETCSProject::NETCSProject(Context* context, NETProjectGen* projectGen) : NETProjectBase(context, projectGen)
 NETCSProject::NETCSProject(Context* context, NETProjectGen* projectGen) : NETProjectBase(context, projectGen)
@@ -240,16 +250,39 @@ bool NETCSProject::Generate()
 
 
 bool NETCSProject::Load(const JSONValue& root)
 bool NETCSProject::Load(const JSONValue& root)
 {
 {
+    bool gameBuild = projectGen_->GetGameBuild();
 
 
     name_ = root["name"].GetString();
     name_ = root["name"].GetString();
     projectGuid_ = root["projectGuid"].GetString();
     projectGuid_ = root["projectGuid"].GetString();
-    outputType_ = root["outputType"].GetString();
+
+    if (gameBuild)
+        outputType_ = "Library";
+    else
+        outputType_ = root["outputType"].GetString();
+
     rootNamespace_ = root["rootNamespace"].GetString();
     rootNamespace_ = root["rootNamespace"].GetString();
     assemblyName_ = root["assemblyName"].GetString();
     assemblyName_ = root["assemblyName"].GetString();
     assemblyOutputPath_ = root["assemblyOutputPath"].GetString();
     assemblyOutputPath_ = root["assemblyOutputPath"].GetString();
     ReplacePathStrings(assemblyOutputPath_);
     ReplacePathStrings(assemblyOutputPath_);
 
 
-    assemblySearchPaths_ = root["assemblyOutputPath"].GetString();
+    assemblySearchPaths_ = root["assemblySearchPaths"].GetString();
+
+    if (gameBuild)
+    {
+        ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
+        const String& engineAssemblyPath = tenv->GetAtomicNETEngineAssemblyPath();
+        if (assemblySearchPaths_.Length())
+        {
+            assemblySearchPaths_ += ";";
+            assemblySearchPaths_ += engineAssemblyPath;
+        }
+        else
+        {
+            assemblySearchPaths_ = engineAssemblyPath;
+        }
+
+    }
+
     ReplacePathStrings(assemblySearchPaths_);
     ReplacePathStrings(assemblySearchPaths_);
 
 
     const JSONArray& references = root["references"].GetArray();
     const JSONArray& references = root["references"].GetArray();
@@ -261,13 +294,17 @@ bool NETCSProject::Load(const JSONValue& root)
         references_.Push(reference);
         references_.Push(reference);
     }
     }
 
 
+    if (gameBuild)
+    {
+        references_.Push("AtomicNETEngine");
+    }
+
     // msvc doesn't like including these
     // msvc doesn't like including these
     if (projectGen_->GetMonoBuild())
     if (projectGen_->GetMonoBuild())
     {
     {
         references_.Push("System.Console");
         references_.Push("System.Console");
         references_.Push("System.IO");
         references_.Push("System.IO");
         references_.Push("System.IO.FileSystem");
         references_.Push("System.IO.FileSystem");
-
     }
     }
 
 
     const JSONArray& sources = root["sources"].GetArray();
     const JSONArray& sources = root["sources"].GetArray();
@@ -363,7 +400,7 @@ bool NETSolution::Load(const JSONValue& root)
 }
 }
 
 
 NETProjectGen::NETProjectGen(Context* context) : Object(context),
 NETProjectGen::NETProjectGen(Context* context) : Object(context),
-    monoBuild_(false)
+    monoBuild_(false), gameBuild_(false)
 {
 {
 
 
 #ifndef ATOMIC_PLATFORM_WINDOWS
 #ifndef ATOMIC_PLATFORM_WINDOWS
@@ -389,9 +426,10 @@ bool NETProjectGen::Generate()
     return true;
     return true;
 }
 }
 
 
-bool NETProjectGen::LoadProject(const JSONValue &root)
+bool NETProjectGen::LoadProject(const JSONValue &root, bool gameBuild)
 {
 {
 
 
+    gameBuild_ = gameBuild;
     solution_ = new NETSolution(context_, this);
     solution_ = new NETSolution(context_, this);
 
 
     solution_->Load(root["solution"]);
     solution_->Load(root["solution"]);
@@ -420,7 +458,7 @@ bool NETProjectGen::LoadProject(const JSONValue &root)
     return true;
     return true;
 }
 }
 
 
-bool NETProjectGen::LoadProject(const String& projectPath)
+bool NETProjectGen::LoadProject(const String& projectPath, bool gameBuild)
 {
 {
     SharedPtr<File> file(new File(context_));
     SharedPtr<File> file(new File(context_));
 
 
@@ -435,7 +473,7 @@ bool NETProjectGen::LoadProject(const String& projectPath)
     if (!JSONFile::ParseJSON(json, jvalue))
     if (!JSONFile::ParseJSON(json, jvalue))
         return false;
         return false;
 
 
-    return LoadProject(jvalue);
+    return LoadProject(jvalue, gameBuild);
 }
 }
 
 
 }
 }

+ 5 - 2
Source/ToolCore/NETTools/NETProjectGen.h

@@ -112,7 +112,9 @@ public:
     const String& GetScriptPlatform() { return scriptPlatform_; }
     const String& GetScriptPlatform() { return scriptPlatform_; }
 
 
     NETSolution* GetSolution() { return solution_; }
     NETSolution* GetSolution() { return solution_; }
+
     bool GetMonoBuild() { return monoBuild_; }
     bool GetMonoBuild() { return monoBuild_; }
+    bool GetGameBuild() { return gameBuild_; }
 
 
     const Vector<SharedPtr<NETCSProject>>& GetCSProjects() { return projects_; }
     const Vector<SharedPtr<NETCSProject>>& GetCSProjects() { return projects_; }
 
 
@@ -120,14 +122,15 @@ public:
 
 
     bool Generate();
     bool Generate();
 
 
-    bool LoadProject(const JSONValue& root);
-    bool LoadProject(const String& projectPath);
+    bool LoadProject(const JSONValue& root, bool gameBuild = false);
+    bool LoadProject(const String& projectPath, bool gameBuild = false);
 
 
 private:
 private:
 
 
     String scriptPlatform_;
     String scriptPlatform_;
 
 
     bool monoBuild_;
     bool monoBuild_;
+    bool gameBuild_;
 
 
     SharedPtr<NETSolution> solution_;
     SharedPtr<NETSolution> solution_;
     Vector<SharedPtr<NETCSProject>> projects_;
     Vector<SharedPtr<NETCSProject>> projects_;

+ 37 - 0
Source/ToolCore/NETTools/NETToolSystem.cpp

@@ -6,9 +6,14 @@
 //
 //
 
 
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/Log.h>
+#include <Atomic/IO/FileSystem.h>
 #include <AtomicNET/NETCore/NETCore.h>
 #include <AtomicNET/NETCore/NETCore.h>
 
 
+#include "../ToolEvents.h"
+#include "../ToolEnvironment.h"
+
 #include "NETToolSystem.h"
 #include "NETToolSystem.h"
+#include "NETProjectGen.h"
 
 
 namespace ToolCore
 namespace ToolCore
 {
 {
@@ -22,7 +27,10 @@ NETToolSystem::NETToolSystem(Context* context) : Object(context)
         {
         {
             LOGERROR("NETToolSystem::NETToolSystem - Unable to resolve delagate AtomicNETTools.InspectAssembly");
             LOGERROR("NETToolSystem::NETToolSystem - Unable to resolve delagate AtomicNETTools.InspectAssembly");
         }
         }
+
+        SubscribeToEvent(E_PROJECTLOADED, HANDLER(NETToolSystem, HandleProjectLoaded));
     }
     }
+
 }
 }
 
 
 NETToolSystem::~NETToolSystem()
 NETToolSystem::~NETToolSystem()
@@ -30,6 +38,35 @@ NETToolSystem::~NETToolSystem()
 
 
 }
 }
 
 
+void NETToolSystem::HandleProjectLoaded(StringHash eventType, VariantMap& eventData)
+{
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+    String projectPath = eventData[ProjectLoaded::P_PROJECTPATH].GetString();
+
+    String pathName, fileName, ext;
+
+    SplitPath(projectPath, pathName, fileName, ext);
+
+    String netJSONPath = AddTrailingSlash(pathName) + "AtomicNET.json";
+
+    if (fileSystem->FileExists(netJSONPath))
+    {
+        SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
+
+#ifdef ATOMIC_PLATFORM_OSX
+        gen->SetScriptPlatform("MACOSX");
+#else
+        gen->SetScriptPlatform("WINDOWS");
+#endif
+        gen->LoadProject(netJSONPath, true);
+
+        gen->Generate();
+
+    }
+
+}
+
 bool NETToolSystem::InspectAssembly(const String& pathToAssembly, JSONValue &json)
 bool NETToolSystem::InspectAssembly(const String& pathToAssembly, JSONValue &json)
 {
 {
     json.SetType(JSON_NULL);
     json.SetType(JSON_NULL);

+ 2 - 0
Source/ToolCore/NETTools/NETToolSystem.h

@@ -29,6 +29,8 @@ public:
 
 
 private:
 private:
 
 
+    void HandleProjectLoaded(StringHash eventType, VariantMap& eventData);
+
     typedef const char* (*InpectAssemblyFuctionPtr)(const char* path);
     typedef const char* (*InpectAssemblyFuctionPtr)(const char* path);
     InpectAssemblyFuctionPtr inspectAssemblyFunction_;
     InpectAssemblyFuctionPtr inspectAssemblyFunction_;
 
 

+ 4 - 2
Source/ToolCore/ToolEnvironment.cpp

@@ -88,15 +88,16 @@ bool ToolEnvironment::InitFromJSON(bool atomicTool)
         SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
         SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
 
 
         netAssemblyLoadPaths_ = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
         netAssemblyLoadPaths_ = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
+        netAtomicNETEngineAssemblyPath_ = ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR);
 
 
 #ifdef ATOMIC_PLATFORM_WINDOWS
 #ifdef ATOMIC_PLATFORM_WINDOWS
         netCoreCLRAbsPath_ = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Release/x64/", ATOMIC_ROOT_SOURCE_DIR));
         netCoreCLRAbsPath_ = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Release/x64/", ATOMIC_ROOT_SOURCE_DIR));
-        netTPAPaths_ = ToString("%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
 #else
 #else
         netCoreCLRAbsPath_ = GetNativePath(ToString("%s/Submodules/CoreCLR/MacOSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
         netCoreCLRAbsPath_ = GetNativePath(ToString("%s/Submodules/CoreCLR/MacOSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
-        netTPAPaths_ = ToString("%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
 #endif
 #endif
 
 
+        netTPAPaths_ = ToString("%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
+
         return true;
         return true;
     }
     }
 
 
@@ -129,6 +130,7 @@ bool ToolEnvironment::InitFromJSON(bool atomicTool)
     else
     else
         return false;
         return false;
 
 
+
     return true;
     return true;
 
 
 }
 }

+ 2 - 0
Source/ToolCore/ToolEnvironment.h

@@ -61,6 +61,7 @@ public:
     const String& GetNETCoreCLRAbsPath() { return netCoreCLRAbsPath_; }
     const String& GetNETCoreCLRAbsPath() { return netCoreCLRAbsPath_; }
     const String& GetNETAssemblyLoadPaths() { return netAssemblyLoadPaths_; }
     const String& GetNETAssemblyLoadPaths() { return netAssemblyLoadPaths_; }
     const String& GetNETTPAPaths() { return netTPAPaths_; }
     const String& GetNETTPAPaths() { return netTPAPaths_; }
+    const String& GetAtomicNETEngineAssemblyPath() { return netAtomicNETEngineAssemblyPath_; }
 
 
     /// Data directories
     /// Data directories
     const String& GetDeploymentDataDir() { return toolBinary_; }
     const String& GetDeploymentDataDir() { return toolBinary_; }
@@ -103,6 +104,7 @@ private:
     String netCoreCLRAbsPath_;
     String netCoreCLRAbsPath_;
     String netAssemblyLoadPaths_;
     String netAssemblyLoadPaths_;
     String netTPAPaths_;
     String netTPAPaths_;
+    String netAtomicNETEngineAssemblyPath_;
 
 
     // resources
     // resources
     String resourceCoreDataDir_;
     String resourceCoreDataDir_;