Skip to content

Commit

Permalink
setprop! calls now persist to new connections
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeits committed Feb 11, 2020
1 parent 6e5b778 commit f2e5d41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ Base.setindex(p::Path, x, i::Int) = p.entries[i] = x
mutable struct SceneNode
object::Union{Vector{UInt8}, Nothing}
transform::Union{Vector{UInt8}, Nothing}
properties::Dict{String, Vector{UInt8}}
children::Dict{String, SceneNode}
end

SceneNode() = SceneNode(nothing, nothing, Dict{String, SceneNode}())
SceneNode() = SceneNode(nothing, nothing,
Dict{String, Vector{UInt8}}(),
Dict{String, SceneNode}())

Base.getindex(s::SceneNode, name::AbstractString) = get!(SceneNode, s.children, name)
function Base.delete!(s::SceneNode, name::AbstractString)
Expand Down
10 changes: 9 additions & 1 deletion src/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function add_connection!(core::CoreVisualizer, req)
wait()
end



function update_tree!(core::CoreVisualizer, cmd::SetObject, data)
core.tree[cmd.path].object = data
end
Expand All @@ -88,6 +90,10 @@ function update_tree!(core::CoreVisualizer, cmd::SetTransform, data)
core.tree[cmd.path].transform = data
end

function update_tree!(core::CoreVisualizer, cmd::SetProperty, data)
core.tree[cmd.path].properties[cmd.property] = data
end

function update_tree!(core::CoreVisualizer, cmd::Delete, data)
if length(cmd.path) == 0
core.tree = SceneNode()
Expand All @@ -97,7 +103,6 @@ function update_tree!(core::CoreVisualizer, cmd::Delete, data)
end

update_tree!(core::CoreVisualizer, cmd::SetAnimation, data) = nothing
update_tree!(core::CoreVisualizer, cmd::SetProperty, data) = nothing

function send_scene(core::CoreVisualizer, connection)
foreach(core.tree) do node
Expand All @@ -107,6 +112,9 @@ function send_scene(core::CoreVisualizer, connection)
if node.transform !== nothing
WebSockets.writeguarded(connection, node.transform)
end
for data in values(node.properties)
WebSockets.writeguarded(connection, data)
end
end
end

Expand Down

0 comments on commit f2e5d41

Please sign in to comment.