diff options
author | Joe Rayhawk <jrayhawk@fairlystable.org> | 2022-11-12 16:36:34 -0800 |
---|---|---|
committer | Joe Rayhawk <jrayhawk@fairlystable.org> | 2022-11-12 16:36:34 -0800 |
commit | 8532e6c397fb43955fa45329a585bd13a2328e10 (patch) | |
tree | 06d80282c519f2a507403226485ee9c6bc9daeaf | |
parent | c4892dd7730f1e047bbdeb954b1157eac605d30b (diff) | |
download | crystal-obs-websocket-8532e6c397fb43955fa45329a585bd13a2328e10.tar.gz crystal-obs-websocket-8532e6c397fb43955fa45329a585bd13a2328e10.zip |
Scene.metascene simplify metascene[] and fix metascene?[]
-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 |