Browse Source

Merge pull request #123 from AtomicGameEngine/JME-ROBOMAN-TS

Various improvements made while porting Roboman to TypeScript
JoshEngebretson 10 years ago
parent
commit
a2bdf6fd7d

+ 12 - 0
Script/AtomicEditor/resources/ResourceOps.ts

@@ -2,6 +2,18 @@ import EditorEvents = require("../editor/EditorEvents");
 
 
 class ResourceOps extends Atomic.ScriptObject {
 class ResourceOps extends Atomic.ScriptObject {
 
 
+    constructor() {
+
+        super();
+
+        this.subscribeToEvent("AssetImportError", (ev: ToolCore.AssetImportErrorEvent) => {
+
+            resourceOps.sendEvent(EditorEvents.ModalError, { title: "Asset Import Error", message: ev.error });
+
+        })
+
+    }
+
 
 
 }
 }
 
 

+ 2 - 0
Script/AtomicEditor/ui/inspector/MaterialInspector.ts

@@ -380,6 +380,8 @@ class MaterialInspector extends ScriptWidget {
         lp.width = 140;
         lp.width = 140;
         field.layoutParams = lp;
         field.layoutParams = lp;
 
 
+        field.text = material.name;
+
         var texture = material.getTexture(Atomic.TU_DIFFUSE);
         var texture = material.getTexture(Atomic.TU_DIFFUSE);
 
 
         if (texture)
         if (texture)

+ 6 - 1
Script/Packages/Atomic/Scene.json

@@ -37,7 +37,12 @@
 			"getChildrenWithName(name:string, recursive?:boolean):Node[];",
 			"getChildrenWithName(name:string, recursive?:boolean):Node[];",
 			"getChildrenWithComponent(componentType:string, recursive?:boolean):Node[];",
 			"getChildrenWithComponent(componentType:string, recursive?:boolean):Node[];",
 			"getComponents(componentType?:string, recursive?:boolean):Component[];",
 			"getComponents(componentType?:string, recursive?:boolean):Component[];",
-			"getChildAtIndex(index:number):Node;"
+			"getChildAtIndex(index:number):Node;",
+			"createJSComponent(name:string, args?:{});",
+			"getJSComponent(name:string):JSComponent;"
+		],
+		"Scene" : [
+			"getMainCamera():Camera;"
 		]
 		]
 	}
 	}
 
 

+ 3 - 0
Script/TypeScript/Atomic.d.ts

@@ -1799,6 +1799,8 @@ declare module Atomic {
       getChildrenWithComponent(componentType:string, recursive?:boolean):Node[];
       getChildrenWithComponent(componentType:string, recursive?:boolean):Node[];
       getComponents(componentType?:string, recursive?:boolean):Component[];
       getComponents(componentType?:string, recursive?:boolean):Component[];
       getChildAtIndex(index:number):Node;
       getChildAtIndex(index:number):Node;
+      createJSComponent(name:string, args?:{});
+      getJSComponent(name:string):JSComponent;
 
 
    }
    }
 
 
@@ -1936,6 +1938,7 @@ declare module Atomic {
       getVarNamesAttr(): string;
       getVarNamesAttr(): string;
       // Prepare network update by comparing attributes and marking replication states dirty as necessary.
       // Prepare network update by comparing attributes and marking replication states dirty as necessary.
       prepareNetworkUpdate(): void;
       prepareNetworkUpdate(): void;
+      getMainCamera():Camera;
 
 
    }
    }
 
 

+ 7 - 0
Script/TypeScript/AtomicWork.d.ts

@@ -192,6 +192,13 @@ declare module ToolCore {
 
 
     }
     }
 
 
+    export interface AssetImportErrorEvent {
+
+        path:string;
+        guid:string;
+        error: string;
+
+    }
 
 
     export var toolEnvironment: ToolEnvironment;
     export var toolEnvironment: ToolEnvironment;
     export var toolSystem: ToolSystem;
     export var toolSystem: ToolSystem;

+ 3 - 0
Script/TypeScript/ToolCore.d.ts

@@ -215,6 +215,7 @@ declare module ToolCore {
 
 
    export class OpenAssetImporter extends Atomic.AObject {
    export class OpenAssetImporter extends Atomic.AObject {
 
 
+      errorMessage: string;
       importNode: Atomic.Node;
       importNode: Atomic.Node;
       startTime: number;
       startTime: number;
       endTime: number;
       endTime: number;
@@ -225,6 +226,7 @@ declare module ToolCore {
       constructor();
       constructor();
 
 
       load(assetPath: string): boolean;
       load(assetPath: string): boolean;
+      getErrorMessage(): string;
       exportModel(outName: string, animName?: string, animationOnly?: boolean): void;
       exportModel(outName: string, animName?: string, animationOnly?: boolean): void;
       setImportNode(node: Atomic.Node): void;
       setImportNode(node: Atomic.Node): void;
       setStartTime(startTime: number): void;
       setStartTime(startTime: number): void;
@@ -264,6 +266,7 @@ declare module ToolCore {
       getImporterType(): string;
       getImporterType(): string;
       getImporterTypeName(): string;
       getImporterTypeName(): string;
       getImporter(): AssetImporter;
       getImporter(): AssetImporter;
+      postImportError(message: string): void;
       getParent(): Asset;
       getParent(): Asset;
       setDirty(dirty: boolean): void;
       setDirty(dirty: boolean): void;
       isDirty(): boolean;
       isDirty(): boolean;

+ 7 - 0
Source/AtomicEditor/CMakeLists.txt

@@ -71,3 +71,10 @@ if (TARGET_PROPERTIES)
 endif ()
 endif ()
 
 
 add_dependencies(AtomicEditor AtomicTool)
 add_dependencies(AtomicEditor AtomicTool)
+
+GroupSources("Application")
+GroupSources("EditorMode")
+GroupSources("Editors")
+GroupSources("Javascript")
+GroupSources("PlayerMode")
+GroupSources("Utils")

+ 2 - 0
Source/AtomicEditor/Editors/ResourceEditor.cpp

@@ -95,6 +95,7 @@ ResourceEditor::~ResourceEditor()
 
 
 void ResourceEditor::HandleFileChanged(StringHash eventType, VariantMap& eventData)
 void ResourceEditor::HandleFileChanged(StringHash eventType, VariantMap& eventData)
 {
 {
+    /*
     using namespace FileChanged;
     using namespace FileChanged;
     const String& fileName = eventData[P_FILENAME].GetString();
     const String& fileName = eventData[P_FILENAME].GetString();
     const String& resourceName = eventData[P_RESOURCENAME].GetString();
     const String& resourceName = eventData[P_RESOURCENAME].GetString();
@@ -105,6 +106,7 @@ void ResourceEditor::HandleFileChanged(StringHash eventType, VariantMap& eventDa
         if (!fs->FileExists(fullpath_))
         if (!fs->FileExists(fullpath_))
             Close();
             Close();
     }
     }
+    */
 }
 }
 
 
 void ResourceEditor::Close(bool navigateToAvailableResource)
 void ResourceEditor::Close(bool navigateToAvailableResource)

+ 24 - 2
Source/ToolCore/Assets/Asset.cpp

@@ -16,6 +16,7 @@
 #include "PrefabImporter.h"
 #include "PrefabImporter.h"
 #include "JavascriptImporter.h"
 #include "JavascriptImporter.h"
 
 
+#include "AssetEvents.h"
 #include "Asset.h"
 #include "Asset.h"
 
 
 namespace ToolCore
 namespace ToolCore
@@ -62,7 +63,7 @@ String Asset::GetRelativePath()
 
 
 bool Asset::CheckCacheFile()
 bool Asset::CheckCacheFile()
 {
 {
-    if (importer_.Null() || !importer_->RequiresCacheFile())
+    if (importer_.Null())
         return true;
         return true;
 
 
     FileSystem* fs = GetSubsystem<FileSystem>();
     FileSystem* fs = GetSubsystem<FileSystem>();
@@ -71,8 +72,18 @@ bool Asset::CheckCacheFile()
 
 
     String cacheFile = cachePath + guid_;
     String cacheFile = cachePath + guid_;
 
 
-    if (!fs->FileExists(cacheFile) || fs->GetLastModifiedTime(cacheFile) < fs->GetLastModifiedTime(path_))
+    unsigned modifiedTime = fs->GetLastModifiedTime(path_);
+
+    if (importer_->RequiresCacheFile()) {
+
+        if (!fs->FileExists(cacheFile) || fs->GetLastModifiedTime(cacheFile) < modifiedTime)
+            return false;
+    }
+
+    if (fs->GetLastModifiedTime(GetDotAssetFilename()) < modifiedTime)
+    {
         return false;
         return false;
+    }
 
 
     return true;
     return true;
 }
 }
@@ -95,6 +106,17 @@ bool Asset::Preload()
     //return importer_->Preload();
     //return importer_->Preload();
 }
 }
 
 
+void Asset::PostImportError(const String& message)
+{
+    VariantMap eventData;
+    eventData[AssetImportError::P_PATH] = path_;
+    eventData[AssetImportError::P_GUID] = guid_;
+    eventData[AssetImportError::P_ERROR] = message;
+
+    SendEvent(E_ASSETIMPORTERROR, eventData);
+
+}
+
 // load .asset
 // load .asset
 bool Asset::Load()
 bool Asset::Load()
 {
 {

+ 3 - 0
Source/ToolCore/Assets/Asset.h

@@ -41,6 +41,8 @@ public:
 
 
     AssetImporter* GetImporter() { return importer_; }
     AssetImporter* GetImporter() { return importer_; }
 
 
+    void PostImportError(const String& message);
+
     Asset* GetParent();
     Asset* GetParent();
 
 
     void SetDirty(bool dirty) { dirty_ = dirty; }
     void SetDirty(bool dirty) { dirty_ = dirty; }
@@ -56,6 +58,7 @@ public:
     // save .asset
     // save .asset
     bool Save();
     bool Save();
 
 
+
 private:
 private:
 
 
     bool CreateImporter();
     bool CreateImporter();

+ 43 - 0
Source/ToolCore/Assets/AssetDatabase.cpp

@@ -6,6 +6,7 @@
 #include <Atomic/IO/FileSystem.h>
 #include <Atomic/IO/FileSystem.h>
 #include <Atomic/Math/Random.h>
 #include <Atomic/Math/Random.h>
 
 
+#include <Atomic/Resource/ResourceEvents.h>
 #include <Atomic/Resource/ResourceCache.h>
 #include <Atomic/Resource/ResourceCache.h>
 
 
 #include "../ToolEvents.h"
 #include "../ToolEvents.h"
@@ -22,6 +23,7 @@ AssetDatabase::AssetDatabase(Context* context) : Object(context)
 {
 {
     SubscribeToEvent(E_PROJECTLOADED, HANDLER(AssetDatabase, HandleProjectLoaded));
     SubscribeToEvent(E_PROJECTLOADED, HANDLER(AssetDatabase, HandleProjectLoaded));
     SubscribeToEvent(E_PROJECTUNLOADED, HANDLER(AssetDatabase, HandleProjectUnloaded));
     SubscribeToEvent(E_PROJECTUNLOADED, HANDLER(AssetDatabase, HandleProjectUnloaded));
+    SubscribeToEvent(E_FILECHANGED, HANDLER(AssetDatabase, HandleFileChanged));
 }
 }
 
 
 AssetDatabase::~AssetDatabase()
 AssetDatabase::~AssetDatabase()
@@ -398,6 +400,11 @@ void AssetDatabase::HandleProjectLoaded(StringHash eventType, VariantMap& eventD
 {
 {
     project_ = GetSubsystem<ToolSystem>()->GetProject();
     project_ = GetSubsystem<ToolSystem>()->GetProject();
 
 
+    FileSystem* fs = GetSubsystem<FileSystem>();
+
+    if (!fs->DirExists(GetCachePath()))
+        fs->CreateDir(GetCachePath());
+
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     cache->AddResourceDir(GetCachePath());
     cache->AddResourceDir(GetCachePath());
 
 
@@ -413,5 +420,41 @@ void AssetDatabase::HandleProjectUnloaded(StringHash eventType, VariantMap& even
     project_ = 0;
     project_ = 0;
 }
 }
 
 
+void AssetDatabase::HandleFileChanged(StringHash eventType, VariantMap& eventData)
+{
+    using namespace FileChanged;
+    const String& fullPath = eventData[P_FILENAME].GetString();
+
+    FileSystem* fs = GetSubsystem<FileSystem>();
+
+    String pathName, fileName, ext;
+
+    SplitPath(fullPath, pathName, fileName, ext);
+
+    Asset* asset = GetAssetByPath(fullPath);
+
+    if (!asset && fs->FileExists(fullPath))
+    {
+        Scan();
+        return;
+    }
+
+    if (asset)
+    {
+        if(!fs->FileExists(fullPath))
+        {
+            DeleteAsset(asset);
+        }
+        else
+        {
+            asset->SetDirty(true);
+            Scan();
+        }
+
+    }
+
+
+}
+
 
 
 }
 }

+ 1 - 0
Source/ToolCore/Assets/AssetDatabase.h

@@ -46,6 +46,7 @@ private:
 
 
     void HandleProjectLoaded(StringHash eventType, VariantMap& eventData);
     void HandleProjectLoaded(StringHash eventType, VariantMap& eventData);
     void HandleProjectUnloaded(StringHash eventType, VariantMap& eventData);
     void HandleProjectUnloaded(StringHash eventType, VariantMap& eventData);
+    void HandleFileChanged(StringHash eventType, VariantMap& eventData);
 
 
     void AddAsset(SharedPtr<Asset>& asset);
     void AddAsset(SharedPtr<Asset>& asset);
 
 

+ 8 - 0
Source/ToolCore/Assets/AssetEvents.h

@@ -16,4 +16,12 @@ EVENT(E_RESOURCEREMOVED, ResourceRemoved)
     PARAM(P_GUID, GUID);                  // string
     PARAM(P_GUID, GUID);                  // string
 }
 }
 
 
+EVENT(E_ASSETIMPORTERROR, AssetImportError)
+{
+    PARAM(P_PATH, Path);                  // string
+    PARAM(P_GUID, GUID);                  // string
+    PARAM(P_ERROR, Error);                  // string
+}
+
+
 }
 }

+ 4 - 0
Source/ToolCore/Assets/ModelImporter.cpp

@@ -56,6 +56,10 @@ bool ModelImporter::ImportModel()
 
 
         return true;
         return true;
     }
     }
+    else
+    {
+        asset_->PostImportError(importer->GetErrorMessage());
+    }
 
 
     return false;
     return false;
 }
 }

+ 11 - 0
Source/ToolCore/CMakeLists.txt

@@ -15,3 +15,14 @@ file (GLOB_RECURSE SOURCE_FILES *.cpp *.h)
 add_library(ToolCore ${SOURCE_FILES})
 add_library(ToolCore ${SOURCE_FILES})
 
 
 target_link_libraries(ToolCore Assimp Poco)
 target_link_libraries(ToolCore Assimp Poco)
+
+GroupSources("Assets")
+GroupSources("Build")
+GroupSources("Command")
+GroupSources("Import")
+GroupSources("JSBind")
+GroupSources("License")
+GroupSources("Net")
+GroupSources("Platform")
+GroupSources("Project")
+GroupSources("Subprocess")

+ 4 - 1
Source/ToolCore/Import/OpenAssetImporter.cpp

@@ -115,7 +115,10 @@ bool OpenAssetImporter::Load(const String &assetPath)
     scene_ = aiImportFile(GetNativePath(assetPath).CString(), aiCurrentFlags_);
     scene_ = aiImportFile(GetNativePath(assetPath).CString(), aiCurrentFlags_);
 
 
     if (!scene_)
     if (!scene_)
-        ErrorExit("Could not open or parse input file " + assetPath + ": " + String(aiGetErrorString()));
+    {
+        errorMessage_ = "Could not open or parse input file " + assetPath + ": " + String(aiGetErrorString());
+        return false;
+    }
 
 
     if (verboseLog_)
     if (verboseLog_)
         Assimp::DefaultLogger::kill();
         Assimp::DefaultLogger::kill();

+ 4 - 0
Source/ToolCore/Import/OpenAssetImporter.h

@@ -53,6 +53,8 @@ public:
 
 
     bool Load(const String& assetPath);
     bool Load(const String& assetPath);
 
 
+    const String& GetErrorMessage() { return errorMessage_; }
+
     void ExportModel(const String& outName, const String& animName = String::EMPTY, bool animationOnly = false);
     void ExportModel(const String& outName, const String& animName = String::EMPTY, bool animationOnly = false);
 
 
     void SetImportNode(Node* node) { importNode_ = node; }
     void SetImportNode(Node* node) { importNode_ = node; }
@@ -92,6 +94,8 @@ private:
 
 
     void DumpNodes(aiNode* rootNode, unsigned level);
     void DumpNodes(aiNode* rootNode, unsigned level);
 
 
+    String errorMessage_;
+
     const aiScene* scene_;
     const aiScene* scene_;
     aiNode* rootNode_;
     aiNode* rootNode_;