Fixed Builder not allowing nested maps for properties
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / builder-impl.cpp
index 0371491..f7b89e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -52,10 +52,10 @@ namespace Internal
 class Replacement;
 
 extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot, Builder* const builder );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
+extern void DeterminePropertyFromNode( const TreeNode& node, Property::Value& value );
+extern void DeterminePropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
+extern bool DeterminePropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
+extern bool DeterminePropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
 extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
 extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
 extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant );
@@ -124,11 +124,6 @@ std::string PropertyValueToString( const Property::Value& value )
       ret = ToString( value.Get<int>() );
       break;
     }
-    case Property::UNSIGNED_INTEGER:
-    {
-      ret = ToString( value.Get<unsigned int>() );
-      break;
-    }
     case Property::VECTOR2:
     {
       ret = ToString( value.Get<Vector2>() );
@@ -303,10 +298,10 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
         Property::Type type = propertyObject.GetPropertyType(index);
 
         Property::Value value;
-        if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
+        if( !DeterminePropertyFromNode( keyChild.second, type, value, constant ) )
         {
           // verbose as this might not be a problem
-          // eg parent-origin can be a string which is picked up later
+          // eg parentOrigin can be a string which is picked up later
           DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
         }
         else
@@ -552,7 +547,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
   const Stage& stage = Stage::GetCurrent();
   Layer root  = stage.GetRootLayer();
 
-  if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "sourceActor") ) )
   {
     Actor actor = root.FindChildByName(*s);
     if(actor)
@@ -565,7 +560,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
     }
   }
 
-  if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "cameraActor") ) )
   {
     CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
     if(actor)
@@ -578,7 +573,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
     }
   }
 
-  if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "targetFrameBuffer") ) )
   {
     FrameBufferImage fb = GetFrameBufferImage( *s, constant );
     if(fb)
@@ -591,7 +586,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
     }
   }
 
-  if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "screenToFrameBufferFunction") ) )
   {
     if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
     {
@@ -608,8 +603,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
   }
 
   // other setup is via the property system
-  SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
-
+  SetProperties( node, task, constant );
 }
 
 void Builder::CreateRenderTask( const std::string &name )
@@ -620,7 +614,7 @@ void Builder::CreateRenderTask( const std::string &name )
 
   const Stage& stage = Stage::GetCurrent();
 
-  OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
+  OptionalChild tasks = IsChild(*mParser.GetRoot(), "renderTasks");
 
   if(tasks)
   {
@@ -678,12 +672,12 @@ ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacemen
   }
   else
   {
-    if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
+    if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shaderEffects") )
     {
       if( OptionalChild effect = IsChild( *effects, name ) )
       {
         Dali::Property::Value propertyMap(Property::MAP);
-        if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
+        if( DeterminePropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
         {
           ret = Dali::Scripting::NewShaderEffect( propertyMap );
           mShaderEffectLut[ name ] = ret;
@@ -714,17 +708,21 @@ FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Re
   }
   else
   {
-    if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
+    if( OptionalChild images = IsChild( *mParser.GetRoot(), "frameBufferImages") )
     {
       if( OptionalChild image = IsChild( *images, name ) )
       {
         Dali::Property::Value property(Property::MAP);
-        if( SetPropertyFromNode( *image, Property::MAP, property, constant ) )
+        if( DeterminePropertyFromNode( *image, Property::MAP, property, constant ) )
         {
           Property::Map* map = property.GetMap();
-          (*map)[ KEYNAME_TYPE ] = Property::Value(std::string("FrameBufferImage") );
-          ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( property ) );
-          mFrameBufferImageLut[ name ] = ret;
+
+          if( map )
+          {
+            (*map)[ KEYNAME_TYPE ] = Property::Value(std::string("FrameBufferImage") );
+            ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( property ) );
+            mFrameBufferImageLut[ name ] = ret;
+          }
         }
       }
     }
@@ -754,16 +752,16 @@ Path Builder::GetPath( const std::string& name )
         if( OptionalChild pointsProperty = IsChild( *path, "points") )
         {
           Dali::Property::Value points(Property::ARRAY);
-          if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+          if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
           {
             ret = Path::New();
             ret.SetProperty( Path::Property::POINTS, points);
 
-            //control-points property
-            if( OptionalChild pointsProperty = IsChild( *path, "control-points") )
+            //controlPoints property
+            if( OptionalChild pointsProperty = IsChild( *path, "controlPoints") )
             {
               Dali::Property::Value points(Property::ARRAY);
-              if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+              if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
               {
                 ret.SetProperty( Path::Property::CONTROL_POINTS, points);
               }
@@ -828,16 +826,16 @@ PathConstrainer Builder::GetPathConstrainer( const std::string& name )
         if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "points") )
         {
           Dali::Property::Value points(Property::ARRAY);
-          if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+          if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
           {
             ret = PathConstrainer::New();
             ret.SetProperty( PathConstrainer::Property::POINTS, points);
 
-            //control-points property
-            if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "control-points") )
+            //controlPoints property
+            if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "controlPoints") )
             {
               Dali::Property::Value points(Property::ARRAY);
-              if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+              if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
               {
                 ret.SetProperty( PathConstrainer::Property::CONTROL_POINTS, points);
               }
@@ -937,16 +935,16 @@ Dali::LinearConstrainer Builder::GetLinearConstrainer( const std::string& name )
         if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "value") )
         {
           Dali::Property::Value points(Property::ARRAY);
-          if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+          if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
           {
             ret = Dali::LinearConstrainer::New();
             ret.SetProperty( LinearConstrainer::Property::VALUE, points);
 
-            //control-points property
+            //controlPoints property
             if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "progress") )
             {
               Dali::Property::Value points(Property::ARRAY);
-              if( SetPropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+              if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
               {
                 ret.SetProperty( LinearConstrainer::Property::PROGRESS, points);
               }
@@ -1044,7 +1042,7 @@ void Builder::AddActors( const std::string &sectionName, Actor toActor )
     // to add automatically
     if( "stage" == sectionName )
     {
-      if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
+      if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "renderTasks") )
       {
         if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
         {
@@ -1119,7 +1117,6 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U
                       parser.GetErrorDescription().c_str() );
 
     DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
-
   }
   else
   {
@@ -1157,7 +1154,6 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U
   }
 
   DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
-
 }
 
 void Builder::AddConstants( const Property::Map& map )
@@ -1204,15 +1200,8 @@ void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap )
 #if defined(DEBUG_ENABLED)
         DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
 #endif
-        if( SetPropertyFromNode( (*iter).second, property, replacer ) )
-        {
-          intoMap[ (*iter).second.GetName() ] = property;
-        }
-        else
-        {
-          DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
-                              (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
-        }
+        DeterminePropertyFromNode( (*iter).second, property, replacer );
+        intoMap[ (*iter).second.GetName() ] = property;
       }
     }
   }
@@ -1361,9 +1350,10 @@ Builder::Builder()
   mParser = Dali::Toolkit::JsonParser::New();
 
   Property::Map defaultDirs;
-  defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ]  = DALI_IMAGE_DIR;
-  defaultDirs[ TOKEN_STRING(DALI_SOUND_DIR) ]  = DALI_SOUND_DIR;
-  defaultDirs[ TOKEN_STRING(DALI_STYLE_DIR) ] = DALI_STYLE_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ]       = DALI_IMAGE_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_SOUND_DIR) ]       = DALI_SOUND_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_STYLE_DIR) ]       = DALI_STYLE_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_STYLE_IMAGE_DIR) ] = DALI_STYLE_IMAGE_DIR;
 
   AddConstants( defaultDirs );
 }