From 3b5c8249289b6d82c5e19ad6e446e66972ae8371 Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Wed, 9 Nov 2022 21:36:50 -0800 Subject: metascene: recurse into meta-meta-scenes and provide array of SceneItem for multiple matches. This is an API-breaking change. --- src/obswebsocket.cr | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/obswebsocket.cr') diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr index 8a729d5..0753bb0 100644 --- a/src/obswebsocket.cr +++ b/src/obswebsocket.cr @@ -553,17 +553,23 @@ module OBSWebSocket end # Sources may be present a scene via other scenes. # We can still look these up by source name. - # FIXME: does not recurse # Note: OBS refuses to create a referential loop - # FIXME: only returns one SceneItem - def metascene : Hash( String, OBSWebSocket::SceneItem ) + def metascene : Hash( String, Array( OBSWebSocket::SceneItem ) ) @subscenes.empty? && populate - metascene = Hash( String, OBSWebSocket::SceneItem ).new - @subscenes.each do | subscene | - metascene.merge!(subscene.to_h) + metascene = Hash( String, Array( OBSWebSocket::SceneItem ) ).new + newsubscenes = @subscenes + while ( subscene = newsubscenes.shift? ) + subscene.to_h.each do | siname, sceneitem | + if sceneitem.type == "OBS_SOURCE_TYPE_SCENE" + newsubscenes.push( parent[siname] ) + end + metascene[ siname ]? || ( metascene[ siname ] = Array( OBSWebSocket::SceneItem ).new ) + metascene[ siname ].push( sceneitem ) + end end @items_by_id.values.each do | sitem | - metascene[ sitem.name ] = sitem + metascene[ sitem.name ]? || ( metascene[ sitem.name ] = Array( OBSWebSocket::SceneItem ).new ) + metascene[ sitem.name ].push( sitem ) end return metascene end -- cgit v1.2.3