lib/atome/genesis/particles/utility.rb in atome-0.5.7.3.6 vs lib/atome/genesis/particles/utility.rb in atome-0.5.7.3.9
- old
+ new
@@ -27,126 +27,228 @@
end
end
# new({ particle: :broadcast })
-def delete_recursive(atome_id, force = false)
+
+def delete_recursive(atome_id, force=false)
return if grab(atome_id).tag && (grab(atome_id).tag[:persistent] || grab(atome_id).tag[:system]) unless force
parent_id_found = grab(atome_id).attach
parent_found = grab(parent_id_found)
- new_array = parent_found.attached.dup
+ new_array = parent_found.fasten.dup
new_array.delete(atome_id)
- parent_found.instance_variable_set('@attached', new_array)
- grab(atome_id).attached.each do |atome_id_found|
+ parent_found.instance_variable_set('@fasten', new_array)
+ grab(atome_id).fasten.each do |atome_id_found|
delete_recursive(atome_id_found, force)
end
grab(atome_id).render(:delete, { :recursive => true })
grab(atome_id).touch(:remove)
Universe.delete(grab(atome_id).aid)
end
new({ particle: :delete, category: :utility, type: :boolean, render: false }) do |params|
+ if params == true
- basic_system_object = %i[view eDen black_matter intuition copy atome
- user_view view_color shape_color
-box_color invisible_color text_color circle_color back_selection
-text_selection nil
-]
-
- unless basic_system_object.include?(id) || id.nil?
-
- if params == true
- # We use the tag persistent to exclude color of system object and other default colors
- unless @tag && (@tag[:persistent] || @tag[:system])
- # if we are on a matrix we delete cells found & group found
- cells.delete(true)
- group.delete(true)
- # now we detach the atome from it's parent
- # now we init rendering
- render(:delete, params)
- # the machine delete the current atome from the universe
- id_found = @id.to_sym
- if @attach
- parent_found = grab(@attach)
- parent_found.attached.delete(id_found)
- end
- @affect&.each do |affected_atome|
- affected_found = grab(affected_atome)
- affected_found.apply.delete(id_found)
- affected_found.refresh
- end
-
- # Universe.delete(@aid)
- end
- elsif params.instance_of? Hash
+ # We use the tag persistent to exclude color of system object and other default colors
+ unless @tag && (@tag[:persistent] || @tag[:system])
# if we are on a matrix we delete cells found & group found
cells.delete(true)
group.delete(true)
- if params[:recursive]
- unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
- attached.each do |atttached_atomes|
- delete_recursive(atttached_atomes)
- end
- # touch(:remove)
- # render(:delete, params)
- # Universe.delete(@aid)
+ # now we detach the atome from it's parent
+ # now we init rendering
+ render(:delete, params)
+ # the machine delete the current atome from the universe
+ id_found = @id.to_sym
+ if @attach
+ parent_found = grab(@attach)
+ parent_found.fasten.delete(id_found)
+ end
+ @affect&.each do |affected_atome|
+ affected_found = grab(affected_atome)
+ affected_found.apply.delete(id_found)
+ affected_found.refresh
+ end
+ Universe.delete(@aid)
+ end
+ # elsif params == :force
+ # cells.delete(true)
+ # group.delete(true)
+ # # now we detach the atome from it's parent
+ # # now we init rendering
+ # render(:delete, params)
+ # # the machine delete the current atome from the universe
+ # id_found = @id.to_sym
+ # if @attach
+ # parent_found = grab(@attach)
+ # parent_found.fasten.delete(id_found)
+ # end
+ # @affect&.each do |affected_atome|
+ # affected_found = grab(affected_atome)
+ # affected_found.apply.delete(id_found)
+ # affected_found.refresh
+ # end
+ # Universe.delete(@aid)
+ elsif params.instance_of? Hash
+ # if we are on a matrix we delete cells found & group found
+ cells.delete(true)
+ group.delete(true)
+ if params[:recursive]
+ unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
+ fasten.each do |atttached_atomes|
+ delete_recursive(atttached_atomes)
end
- elsif params[:force]
- attached.each do |atttached_atomes|
- # alert "attached : #{attached}"
- delete_recursive(atttached_atomes, true)
- end
- # touch(:remove)
- # render(:delete, params)
- # Universe.delete(@aid)
- else
- # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
- # with id my_monitor
- params.each do |param, value|
- atome[param][value] = nil
- end
+ touch(:remove)
+ render(:delete, params)
+ Universe.delete(@aid)
end
+ elsif params[:force]
+ fasten.each do |atttached_atomes|
+ # alert "fasten : #{fasten}"
+ delete_recursive(atttached_atomes, true)
+ end
+ touch(:remove)
+ render(:delete, params)
+ # alert "Universe : #{Universe.atomes[@aid]}"
+ # alert "length = #{Universe.atomes.length}"
+ Universe.delete(@aid)
+ # alert "Universe : #{Universe.atomes.length}"
- elsif Universe.atome_list.include?(params)
- # we check if the params passed is an atome to treat it in a different way
- puts "write code here : #{apply} , #{attached}"
else
- send(params, 0) unless params == :id
- end
- touch(:remove)
- drag(false)
- drop(false)
- on(false)
- keyboard(false)
- resize(:remove)
- overflow(:remove)
-
- render(:delete, params)
- Universe.delete(@aid)
-
- exclusions = %i[@history @renderers @type @tag @html]
-
- instance_variables.each do |i_var|
- unless exclusions.include?(i_var)
- instance_variable_set(i_var, nil)
+ # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
+ # with id my_monitor
+ params.each do |param, value|
+ atome[param][value] = nil
end
end
- instance_variable_set('@renderers', [])
+ elsif Universe.atome_list.include?(params)
+ # we check if the params passed is an atome to treat it in a different way
+ puts "write code here : #{apply} , #{fasten}"
+ else
+ send(params, 0) unless params == :id
end
-
end
+
+# def delete_recursive(atome_id, force = false)
+# return if grab(atome_id).tag && (grab(atome_id).tag[:persistent] || grab(atome_id).tag[:system]) unless force
+#
+# parent_id_found = grab(atome_id).attach
+# parent_found = grab(parent_id_found)
+# new_array = parent_found.fasten.dup
+# new_array.delete(atome_id)
+# parent_found.instance_variable_set('@fasten', new_array)
+# grab(atome_id).fasten.each do |atome_id_found|
+# delete_recursive(atome_id_found, force)
+# end
+# grab(atome_id).render(:delete, { :recursive => true })
+# grab(atome_id).touch(:remove)
+# Universe.delete(grab(atome_id).aid)
+# end
+
+# new({ particle: :delete, category: :utility, type: :boolean, render: false }) do |params|
+#
+# basic_system_object = %i[view eDen black_matter intuition copy atome
+# user_view view_color shape_color
+# box_color invisible_color text_color circle_color back_selection
+# text_selection nil
+# ]
+#
+# unless basic_system_object.include?(id) || id.nil?
+# if params == true
+# # We use the tag persistent to exclude color of system object and other default colors
+# unless @tag && (@tag[:persistent] || @tag[:system])
+# # if we are on a matrix we delete cells found & group found
+# cells.delete(true)
+# group.delete(true)
+# # now we detach the atome from it's parent
+# # now we init rendering
+# render(:delete, params)
+# # the machine delete the current atome from the universe
+# id_found = @id.to_sym
+# if @attach
+# parent_found = grab(@attach)
+# parent_found.fasten.delete(id_found)
+# end
+# @affect&.each do |affected_atome|
+# affected_found = grab(affected_atome)
+# affected_found.apply.delete(id_found)
+# affected_found.refresh
+# end
+# # Universe.delete(@aid)
+# end
+# elsif params.instance_of? Hash
+# # if we are on a matrix we delete cells found & group found
+# cells.delete(true)
+# group.delete(true)
+# if params[:recursive]
+# unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
+# fasten.each do |atttached_atomes|
+# delete_recursive(atttached_atomes)
+# end
+# # touch(:remove)
+# # render(:delete, params)
+# # Universe.delete(@aid)
+# end
+# elsif params[:force]
+# fasten.each do |atttached_atomes|
+# # alert "fasten : #{fasten}"
+# delete_recursive(atttached_atomes, true)
+# end
+# # touch(:remove)
+# # render(:delete, params)
+# # Universe.delete(@aid)
+#
+# else
+#
+# # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
+# # with id my_monitor
+# #
+# params.each do |param, value|
+# atome[param][value] = nil
+# end
+# end
+#
+# elsif Universe.atome_list.include?(params)
+# # we check if the params passed is an atome to treat it in a different way
+# puts "write code here : #{apply} , #{fasten}"
+# else
+# send(params, 0) unless params == :id
+# end
+# touch(:remove)
+# drag(false)
+# drop(false)
+# on(false)
+# keyboard(false)
+# resize(:remove)
+# overflow(:remove)
+#
+# render(:delete, params)
+# Universe.delete(@aid)
+#
+# exclusions = %i[@history @renderers @type @tag @html]
+#
+# instance_variables.each do |i_var|
+# unless exclusions.include?(i_var)
+# instance_variable_set(i_var, nil)
+# end
+# end
+#
+# instance_variable_set('@renderers', [])
+# end
+#
+# end
+
new({ particle: :clear, category: :utility, type: :boolean })
new({ post: :clear }) do
- attached_found = []
- attached.each do |attached_id_found|
- attached_found << attached_id_found
+ fasten_found = []
+ fasten.each do |fasten_id_found|
+ fasten_found << fasten_id_found
end
- attached_found.each do |child_id_found|
+ fasten_found.each do |child_id_found|
child_found = grab(child_id_found)
# we exclude system objects
child_found&.delete(true) unless child_found.tag && child_found.tag[:system]
end
end
@@ -221,22 +323,22 @@
copy_number = if @duplicate
@duplicate.length
else
0
end
- attached_atomes = []
- attached_found = attached.dup
- attached_found.each do |child_id_found|
+ fasten_atomes = []
+ fasten_found = fasten.dup
+ fasten_found.each do |child_id_found|
child_found = grab(child_id_found)
if child_found
new_child = child_found.duplicate({})
- attached_atomes << new_child.id
+ fasten_atomes << new_child.id
end
end
- params[:attached] = attached_atomes
+ params[:fasten] = fasten_atomes
infos_found = infos.dup
- keys_to_delete = %i[history callback duplicate copy paste touch_code html attached aid]
+ keys_to_delete = %i[history callback duplicate copy paste touch_code html fasten aid]
keys_to_delete.each { |key| infos_found.delete(key) }
new_atome_id = "#{@id}_copy_#{copy_number}".to_sym
infos_found[:id] = new_atome_id
infos_found = infos_found.merge(params)
new_atome = Atome.new(infos_found)
@@ -329,5 +431,11 @@
new({ particle: :state, category: :utility, type: :symbol })
new({ particle: :record, category: :utility, type: :hash })
new({ particle: :preview, category: :utility, type: :hash })
+# new(particle: :update) do |params| # specific to buttons molecule for now
+# old_data= data
+# delete({recursive: true})
+# new_content=old_data.merge(params)
+# buttons(new_content)
+# end