diff options
-rw-r--r-- | src/obswebsocket.cr | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr index 0753bb0..e6f4623 100644 --- a/src/obswebsocket.cr +++ b/src/obswebsocket.cr @@ -557,7 +557,7 @@ module OBSWebSocket def metascene : Hash( String, Array( OBSWebSocket::SceneItem ) ) @subscenes.empty? && populate metascene = Hash( String, Array( OBSWebSocket::SceneItem ) ).new - newsubscenes = @subscenes + newsubscenes = [ self ] while ( subscene = newsubscenes.shift? ) subscene.to_h.each do | siname, sceneitem | if sceneitem.type == "OBS_SOURCE_TYPE_SCENE" @@ -565,25 +565,24 @@ module OBSWebSocket end metascene[ siname ]? || ( metascene[ siname ] = Array( OBSWebSocket::SceneItem ).new ) metascene[ siname ].push( sceneitem ) + # We can have the same scene included in the scene graph multiple times, which will duplicate all its sceneitems in the resulting metascene array. Might be a good idea to add a uniqueness constraint at some point? Not sure anyone would really care one way or the other. end end - @items_by_id.values.each do | sitem | - metascene[ sitem.name ]? || ( metascene[ sitem.name ] = Array( OBSWebSocket::SceneItem ).new ) - metascene[ sitem.name ].push( sitem ) - end return metascene end - # less requests generated with this method - # but Nil union is more annoying - # FIXME: See metascene() + # returns first SceneItem it finds or Nil + # less requests are generated with this method + # but managing Nil unions is more annoying def metasceneitem?( name : String ) : OBSWebSocket::SceneItem | Nil result = nil - if self[name]? - result = self[name] - else - @subscenes.each do | scene | - if scene[name]? - result = scene[name] + newsubscenes = [ self ] + while ( subscene = newsubscenes.shift? ) + subscene.to_h.each do | siname, sceneitem | + if sceneitem.type == "OBS_SOURCE_TYPE_SCENE" + newsubscenes.push( parent[siname] ) + end + if siname == name + result = sceneitem break end end |