summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@fairlystable.org>2022-11-12 16:36:34 -0800
committerJoe Rayhawk <jrayhawk@fairlystable.org>2022-11-12 16:36:34 -0800
commit8532e6c397fb43955fa45329a585bd13a2328e10 (patch)
tree06d80282c519f2a507403226485ee9c6bc9daeaf
parentc4892dd7730f1e047bbdeb954b1157eac605d30b (diff)
downloadcrystal-obs-websocket-8532e6c397fb43955fa45329a585bd13a2328e10.tar.gz
crystal-obs-websocket-8532e6c397fb43955fa45329a585bd13a2328e10.zip
Scene.metascene simplify metascene[] and fix metascene?[]
-rw-r--r--src/obswebsocket.cr27
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