Browse Source

Adding preliminary TypeScript importer and resource view

Josh Engebretson 10 years ago
parent
commit
a44199d3b4

+ 1 - 1
Script/AtomicEditor/ui/frames/ResourceFrame.ts

@@ -68,7 +68,7 @@ class ResourceFrame extends ScriptWidget {
 
         var editor: Editor.ResourceEditor = null;
 
-        if (ext == ".js" || ext == ".txt" || ext == ".json") {
+        if (ext == ".js" || ext == ".txt" || ext == ".json" || ext == ".ts") {
 
             editor = new Editor.JSResourceEditor(path, this.tabcontainer);
 

+ 5 - 0
Source/ToolCore/Assets/Asset.cpp

@@ -27,6 +27,7 @@
 #include "PEXImporter.h"
 #include "TextImporter.h"
 #include "NETAssemblyImporter.h"
+#include "TypeScriptImporter.h"
 
 #include "AssetEvents.h"
 #include "Asset.h"
@@ -269,6 +270,10 @@ bool Asset::CreateImporter()
         {
             importer_ = new JavascriptImporter(context_, this);
         }
+        else if (ext == ".ts")
+        {
+            importer_ = new TypeScriptImporter(context_, this);
+        }
         else if (ext == ".json")
         {
             importer_ = new JSONImporter(context_, this);

+ 85 - 0
Source/ToolCore/Assets/TypeScriptImporter.cpp

@@ -0,0 +1,85 @@
+//
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// LICENSE: Atomic Game Engine Editor and Tools EULA
+// Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
+// license information: https://github.com/AtomicGameEngine/AtomicGameEngine
+//
+
+#include <Atomic/IO/Log.h>
+#include <Atomic/IO/File.h>
+#include <Atomic/Resource/ResourceCache.h>
+#include <Atomic/Resource/Image.h>
+
+#include <AtomicJS/Javascript/JSComponentFile.h>
+
+#include "Asset.h"
+#include "AssetDatabase.h"
+#include "TypeScriptImporter.h"
+
+
+namespace ToolCore
+{
+
+TypeScriptImporter::TypeScriptImporter(Context* context, Asset *asset) : AssetImporter(context, asset)
+{
+    requiresCacheFile_ = false;
+    isComponentFile_ = false;
+}
+
+TypeScriptImporter::~TypeScriptImporter()
+{
+
+}
+
+void TypeScriptImporter::SetDefaults()
+{
+    AssetImporter::SetDefaults();
+}
+
+bool TypeScriptImporter::Import()
+{
+    isComponentFile_ = false;
+
+    return true;
+}
+
+bool TypeScriptImporter::LoadSettingsInternal(JSONValue& jsonRoot)
+{
+    if (!AssetImporter::LoadSettingsInternal(jsonRoot))
+        return false;
+
+    JSONValue import = jsonRoot.Get("TypeScriptImporter");
+
+    isComponentFile_ = import.Get("IsComponentFile").GetBool();
+
+    return true;
+}
+
+bool TypeScriptImporter::SaveSettingsInternal(JSONValue& jsonRoot)
+{
+    if (!AssetImporter::SaveSettingsInternal(jsonRoot))
+        return false;
+
+    JSONValue import;
+    import.Set("IsComponentFile", JSONValue(isComponentFile_));
+    jsonRoot.Set("TypeScriptImporter", import);
+
+    return true;
+}
+
+Resource* TypeScriptImporter::GetResource(const String& typeName)
+{
+    if (!isComponentFile_)
+        return 0;
+
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
+
+    JSComponentFile* jsc = cache->GetResource<JSComponentFile>(asset_->GetPath());
+
+    return jsc;
+
+}
+
+
+
+}

+ 41 - 0
Source/ToolCore/Assets/TypeScriptImporter.h

@@ -0,0 +1,41 @@
+//
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// LICENSE: Atomic Game Engine Editor and Tools EULA
+// Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
+// license information: https://github.com/AtomicGameEngine/AtomicGameEngine
+//
+
+#pragma once
+
+#include "AssetImporter.h"
+
+namespace ToolCore
+{
+
+class TypeScriptImporter : public AssetImporter
+{
+    OBJECT(TypeScriptImporter);
+
+public:
+    /// Construct.
+    TypeScriptImporter(Context* context, Asset* asset);
+    virtual ~TypeScriptImporter();
+
+    virtual void SetDefaults();
+
+    bool IsComponentFile() { return isComponentFile_; }
+
+    Resource* GetResource(const String& typeName = String::EMPTY);
+
+protected:
+
+    bool Import();
+
+    bool isComponentFile_;
+
+    virtual bool LoadSettingsInternal(JSONValue& jsonRoot);
+    virtual bool SaveSettingsInternal(JSONValue& jsonRoot);
+
+};
+
+}