diff --git a/document.tscn b/document.tscn index f33ebe8..c8bd599 100644 --- a/document.tscn +++ b/document.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://qs3uqv4jnev3"] +[gd_scene load_steps=8 format=3 uid="uid://qs3uqv4jnev3"] [ext_resource type="Script" path="res://scripts/physics_drag.gd" id="1_i3q73"] [ext_resource type="Script" path="res://scripts/document.gd" id="1_t74iv"] +[ext_resource type="PackedScene" uid="uid://hoo8ttycwy87" path="res://explosion.tscn" id="2_no6u6"] [ext_resource type="Script" path="res://scripts/toggle_gravity.gd" id="3_loy23"] [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ok5r2"] @@ -25,6 +26,7 @@ document = NodePath("Document") address_box = NodePath("Control/PanelContainer/VBoxContainer/TextEdit") enable_links = NodePath("Control/PanelContainer/VBoxContainer/CheckBox2") +explosion = ExtResource("2_no6u6") [node name="Document" type="Node2D" parent="." node_paths=PackedStringArray("http_request", "address_box", "back_button", "accumulate_mode_toggle")] position = Vector2(10, 10) diff --git a/explosion.tscn b/explosion.tscn new file mode 100644 index 0000000..730dfe5 --- /dev/null +++ b/explosion.tscn @@ -0,0 +1,42 @@ +[gd_scene load_steps=6 format=3 uid="uid://hoo8ttycwy87"] + +[sub_resource type="Gradient" id="Gradient_msw8v"] +offsets = PackedFloat32Array(1) +colors = PackedColorArray(1, 1, 1, 1) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_lv6us"] +gradient = SubResource("Gradient_msw8v") + +[sub_resource type="Curve" id="Curve_iar3t"] +_data = [Vector2(0, 0.983376), 0.0, 0.0, 0, 0, Vector2(1, 0.0274936), 0.0, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="Gradient" id="Gradient_nq8be"] +offsets = PackedFloat32Array(0, 0.556338) +colors = PackedColorArray(0.827266, 0.539993, 0, 1, 0.833762, 0.129184, 0, 1) + +[sub_resource type="Curve" id="Curve_p88se"] +min_value = -1.0 +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.990385, 1), 0.0, 0.0, 0, 0] +point_count = 2 + +[node name="Explosion" type="CPUParticles2D"] +emitting = false +amount = 100 +lifetime = 0.2 +one_shot = true +explosiveness = 0.92 +texture = SubResource("GradientTexture2D_lv6us") +spread = 180.0 +initial_velocity_min = 506.02 +initial_velocity_max = 644.58 +angular_velocity_min = -360.0 +angular_velocity_max = 661.4 +angle_max = 360.0 +scale_amount_min = 0.1 +scale_amount_max = 0.3 +scale_amount_curve = SubResource("Curve_iar3t") +color_ramp = SubResource("Gradient_nq8be") +hue_variation_min = -0.14 +hue_variation_max = 0.11 +hue_variation_curve = SubResource("Curve_p88se") diff --git a/scripts/document.gd b/scripts/document.gd index 1c2526e..d8ebfee 100644 --- a/scripts/document.gd +++ b/scripts/document.gd @@ -34,6 +34,7 @@ rigid_body.add_child(link) var shape = CollisionShape2D.new() + shape.name = 'Shape' shape.shape = RectangleShape2D.new() shape.shape.size = fragment.rect.size shape.translate(fragment.rect.size / 2) @@ -63,12 +64,9 @@ var parser = Parser.new(source) var dom_tree = DOM.build_dom_tree(parser) + dom_tree.debug_print() var layout_tree = Layout.build_layout_tree(dom_tree) layout_tree.layout(1000) - - if not accumulate_mode_toggle.button_pressed: - for child in get_children(): - remove_child(child) _create_block(self, layout_tree) func _load_page(address: String): @@ -78,6 +76,10 @@ back_button.disabled = false current_page = address + if not accumulate_mode_toggle.button_pressed: + for child in get_children(): + remove_child(child) + print('Load ', address) http_request.cancel_request() http_request.request(address) diff --git a/scripts/dom.gd b/scripts/dom.gd index e88890f..3dab393 100644 --- a/scripts/dom.gd +++ b/scripts/dom.gd @@ -60,6 +60,8 @@ return true if tag_name in DESCRIPTION_LIST_ITEM and top_of_stack in DESCRIPTION_LIST_ITEM: return true + if tag_name == 'li' and top_of_stack == 'li': + return true return false static func build_dom_tree(parser: Parser) -> DomNode: diff --git a/scripts/layout.gd b/scripts/layout.gd index b1018d7..85d26a6 100644 --- a/scripts/layout.gd +++ b/scripts/layout.gd @@ -6,9 +6,14 @@ 'body', 'h1', 'p', + 'address', + 'dl', 'dt', 'dd', + + 'ul', + 'li', ] const NON_LAYOUT_NODES = [ diff --git a/scripts/physics_drag.gd b/scripts/physics_drag.gd index 155bca8..932c22f 100644 --- a/scripts/physics_drag.gd +++ b/scripts/physics_drag.gd @@ -4,8 +4,32 @@ @export var address_box: TextEdit @export var enable_links: CheckBox +@export var explosion: PackedScene + var selected_body: RigidBody2D = null var drag_position: Vector2 = Vector2.ZERO +var did_move: bool = false +var time_down + +func _apply_explosive_force(node: Node, position: Vector2): + if node is RigidBody2D: + var body = node as RigidBody2D + var shape = body.get_node('Shape').shape as RectangleShape2D + var center = body.global_position + shape.size / 2 + var direction = (center - position).normalized() + var distance = center.distance_to(position) + var force = direction * (9999999 / (distance*distance)) + body.apply_impulse(force, center) + for child in node.get_children(): + _apply_explosive_force(child, position) + +func _explode(position: Vector2): + var explosion = explosion.instantiate() as CPUParticles2D + explosion.position = position + explosion.emitting = true + explosion.finished.connect(func (): remove_child(explosion)) + add_child(explosion) + _apply_explosive_force(self, position) func _on_mouse_down(event: InputEventMouseButton): var space_state = get_world_2d().direct_space_state @@ -17,6 +41,12 @@ selected_body = result[0]['collider'] drag_position = selected_body.global_transform.inverse() * event.position + if event.button_index == 2: + _explode(event.position) + + did_move = false + time_down = Time.get_ticks_msec() + func follow_link(href: String): if not href.begins_with('http'): var address = address_box.text.strip_edges().trim_prefix('/') @@ -30,9 +60,10 @@ if selected_body == null: return - var link = selected_body.get_node('Link') - if link != null and enable_links.button_pressed: - follow_link(link.href) + if not did_move or (Time.get_ticks_msec() - time_down) < 200: + var link = selected_body.get_node('Link') + if link != null and enable_links.button_pressed: + follow_link(link.href) selected_body = null func _process(delta: float): @@ -50,3 +81,5 @@ _on_mouse_down(event as InputEventMouseButton) else: _on_mouse_up(event as InputEventMouseButton) + elif event is InputEventMouseMotion: + did_move = true diff --git a/scripts/style.gd b/scripts/style.gd index 2fbba30..2ef8f40 100644 --- a/scripts/style.gd +++ b/scripts/style.gd @@ -21,11 +21,13 @@ style.margin_bottom = 20 'a': style.text_color = Color.BLUE - 'p', 'dl': + 'p', 'dl', 'ul': style.margin_top = 10 style.margin_bottom = 10 'dd': style.margin_left = 40 + 'li': + style.margin_left = 20 return style var font_size: float = 16