Prevented json array of numbers appending on merge
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / builder-impl.cpp
index d4a2a3e..de40d44 100644 (file)
@@ -67,6 +67,8 @@ Integration::Log::Filter* gFilterScript  = Integration::Log::Filter::New(Debug::
 namespace
 {
 
+#define TOKEN_STRING(x) #x
+
 const std::string KEYNAME_STYLES    = "styles";
 const std::string KEYNAME_TYPE      = "type";
 const std::string KEYNAME_ACTORS    = "actors";
@@ -122,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>() );
@@ -304,7 +301,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
         if( !SetPropertyFromNode( 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
@@ -550,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)
@@ -563,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)
@@ -576,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)
@@ -589,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)
     {
@@ -606,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 )
@@ -618,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)
   {
@@ -676,7 +672,7 @@ 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 ) )
       {
@@ -712,7 +708,7 @@ 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 ) )
       {
@@ -720,9 +716,13 @@ FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Re
         if( SetPropertyFromNode( *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;
+          }
         }
       }
     }
@@ -757,8 +757,8 @@ Path Builder::GetPath( const std::string& name )
             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 ) )
@@ -831,8 +831,8 @@ PathConstrainer Builder::GetPathConstrainer( const std::string& name )
             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 ) )
@@ -940,7 +940,7 @@ Dali::LinearConstrainer Builder::GetLinearConstrainer( const std::string& name )
             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);
@@ -1042,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") )
         {
@@ -1117,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
   {
@@ -1155,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 )
@@ -1357,6 +1355,14 @@ Builder::Builder()
 : mSlotDelegate( this )
 {
   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_STYLE_IMAGE_DIR) ] = DALI_STYLE_IMAGE_DIR;
+
+  AddConstants( defaultDirs );
 }
 
 Builder::~Builder()