2015-07-09 15:34:02 +02:00
|
|
|
|
|
|
|
class SpaceView < PIXI::Graphics
|
2015-07-13 18:08:35 +02:00
|
|
|
include Sof::Util
|
2015-07-09 15:34:02 +02:00
|
|
|
|
2015-07-13 17:49:46 +02:00
|
|
|
def initialize
|
2015-07-09 15:34:02 +02:00
|
|
|
super()
|
2015-07-13 17:49:46 +02:00
|
|
|
space = Virtual.machine.space
|
|
|
|
# just a way to get the space into a list. objects is an id => occurence mapping.
|
|
|
|
# occurence.object is the object
|
|
|
|
objects = Sof::Members.new(space).objects
|
2015-07-09 15:34:02 +02:00
|
|
|
@objects = objects
|
2015-07-13 17:49:46 +02:00
|
|
|
# create a mapping from id to volt models
|
|
|
|
@view_objects = {}
|
2015-07-09 15:34:02 +02:00
|
|
|
|
2015-07-13 17:49:46 +02:00
|
|
|
@objects.each do |i , o|
|
|
|
|
view = Volt::Model.new
|
2015-07-13 18:08:35 +02:00
|
|
|
view._object = o
|
2015-07-13 17:49:46 +02:00
|
|
|
@view_objects[i] = view
|
|
|
|
at = PIXI::Point.new 100 , 100
|
|
|
|
name = PIXI::Text.new i.to_s
|
|
|
|
view._name = name
|
|
|
|
add_child name
|
|
|
|
end
|
2015-07-09 15:34:02 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-07-13 17:49:46 +02:00
|
|
|
# should almost be called draw by now
|
2015-07-09 15:34:02 +02:00
|
|
|
def update
|
2015-07-13 17:49:46 +02:00
|
|
|
update_positions
|
2015-07-09 15:34:02 +02:00
|
|
|
self.clear
|
2015-07-13 17:49:46 +02:00
|
|
|
prev = nil
|
|
|
|
@view_objects.each do |i , view|
|
|
|
|
if prev
|
|
|
|
self.lineStyle(4, 0xffd900, 2)
|
|
|
|
self.moveTo( prev._name.position.x , prev._name.position.y )
|
|
|
|
self.lineTo( view._name.position.x , view._name.position.y )
|
|
|
|
end
|
|
|
|
prev = view
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_positions
|
|
|
|
@view_objects.each do |i , view|
|
|
|
|
view._name.position.x += 1
|
|
|
|
end
|
2015-07-09 15:34:02 +02:00
|
|
|
end
|
2015-07-13 18:08:35 +02:00
|
|
|
|
|
|
|
def fill_attributes
|
|
|
|
@view_objects.each do |i , view|
|
|
|
|
object = view._object
|
|
|
|
case object.class.name
|
|
|
|
when "Array" , "Parfait::List"
|
|
|
|
fill_array view
|
|
|
|
when "Hash" , "Parfait::Dictionary"
|
|
|
|
fill_hash view
|
|
|
|
else
|
|
|
|
# and recursively add attributes
|
|
|
|
attributes = attributes_for(object)
|
|
|
|
attributes.each do |a|
|
|
|
|
val = get_value( object , a)
|
|
|
|
if( @view_objects[vol.object_id])
|
|
|
|
#ref
|
|
|
|
end
|
|
|
|
view.set(a , val )
|
|
|
|
end
|
|
|
|
superclasses = [object.class.superclass.name]
|
|
|
|
if superclasses.include?( "Array") or superclasses.include?( "Parfait::List")
|
|
|
|
fill_array view
|
|
|
|
end
|
|
|
|
if superclasses.include?( "Hash") or superclasses.include?( "Parfait::Dictionary")
|
|
|
|
fill_hash view
|
|
|
|
end
|
|
|
|
view._object = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# and hash keys/values
|
|
|
|
def fill_hash hash
|
|
|
|
return
|
|
|
|
hash.each do |a,b|
|
|
|
|
next_level << a
|
|
|
|
next_level << b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# and array values
|
|
|
|
def fill_array array
|
|
|
|
return
|
|
|
|
array.each do |a|
|
|
|
|
next_level << a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-07-09 15:34:02 +02:00
|
|
|
end
|