Browse Source

Improvements to require(), use die on widgets instead of destroying immediately, release compile fix

Josh Engebretson 10 years ago
parent
commit
421a699910

+ 1 - 1
Data/AtomicPlayer/Resources/CoreData/AtomicModules/AtomicGame.js

@@ -70,7 +70,7 @@ Game.prototype.showDebugHud = function() {
 
 Game.prototype.createScene2D = function() {
 
-	var scene = new Atomic.Scene();
+		var scene = new Atomic.Scene();
     scene.createComponent("Octree");
 
     var cameraNode = scene.createChild("Camera");

+ 1 - 1
Source/Atomic/UI/UI.h

@@ -41,7 +41,7 @@ public:
 
     void Shutdown();
 
-    void LoadSkin(const String& skin, const String& overrideSkin);
+    void LoadSkin(const String& skin, const String& overrideSkin = String::EMPTY);
     void AddFont(const String& fontFile, const String &name);
     void SetDefaultFont(const String& name, int size);
 

+ 7 - 4
Source/Atomic/UI/UIWidget.cpp

@@ -215,15 +215,18 @@ UIWidget* UIWidget::GetContentRoot()
     return ui->WrapWidget(root);
 }
 
-void UIWidget::Destroy()
+void UIWidget::Die()
 {
     if (!widget_)
         return;
 
-    if (widget_->GetParent())
-        widget_->GetParent()->RemoveChild(widget_);
+    // clear delegate
+    widget_->SetDelegate(NULL);
+    // explictly die (can trigger an animation)
+    widget_->Die();
+    // call OnDelete, which unwraps the widget and does some bookkeeping
+    OnDelete();
 
-    delete widget_;
 }
 
 void UIWidget::RemoveChild(UIWidget* child, bool cleanup)

+ 1 - 1
Source/Atomic/UI/UIWidget.h

@@ -47,7 +47,7 @@ public:
 
 
     void Invalidate();
-    void Destroy();
+    void Die();
 
     // get this or child widget with id
     UIWidget* GetWidget(const String& id);

+ 3 - 0
Source/AtomicJS/Javascript/JSUIAPI.cpp

@@ -138,8 +138,11 @@ int UI_DebugShowSettingsWindow(duk_context* ctx)
     if (!widget)
         return 0;
 
+#ifdef TB_RUNTIME_DEBUG_INFO
     if (widget->GetInternalWidget())
         tb::ShowDebugInfoSettingsWindow(widget->GetInternalWidget());
+#endif
+
 
     return 0;
 }

+ 16 - 2
Source/AtomicJS/Javascript/JSVM.cpp

@@ -314,7 +314,8 @@ int JSVM::js_module_search(duk_context* ctx)
 {
     JSVM* vm = GetJSVM(ctx);
 
-    ResourceCache* cache = vm->GetContext()->GetSubsystem<ResourceCache>();
+    FileSystem* fs = vm->GetSubsystem<FileSystem>();
+    ResourceCache* cache = vm->GetSubsystem<ResourceCache>();
 
     String path = duk_to_string(ctx, 0);
 
@@ -334,7 +335,20 @@ int JSVM::js_module_search(duk_context* ctx)
     }
     else
     {
-        path = vm->moduleSearchPath_ + "/" + path + ".js";
+        // a module can exist in the Modules path or reside in a project directory
+        // prefer modules path
+        String modulePath = vm->moduleSearchPath_ + "/" + path + ".js";
+
+        if (fs->FileExists(modulePath))
+        {
+            // unless the file doesn't exist and then use project path
+            path = modulePath;
+        }
+        else
+        {
+            path += ".js";
+        }
+
     }
 
     SharedPtr<File> jsfile(cache->GetFile(path));