reactions
This commit is contained in:
parent
2f559639fb
commit
5e20eeb8bf
74 changed files with 891 additions and 19 deletions
|
|
@ -14,7 +14,7 @@ func _mouse_enter() -> void:
|
|||
func _mouse_exit() -> void:
|
||||
mouse_in = false
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
if dragged == false:
|
||||
return
|
||||
var camera: Camera3D = get_viewport().get_camera_3d()
|
||||
|
|
|
|||
|
|
@ -2,9 +2,15 @@ extends Node
|
|||
|
||||
@export var rotated: Node3D
|
||||
@export var proximity_radius: float
|
||||
@onready var start_rotation = rotated.quaternion
|
||||
@export var modification_curve: Curve
|
||||
var start_rotation
|
||||
var reciever: InteractionReciever
|
||||
|
||||
func _ready() -> void:
|
||||
print(self.get_path(), rotated)
|
||||
print_stack()
|
||||
start_rotation = rotated.quaternion
|
||||
|
||||
func _on_interaction_area_interaction_reciever_entered(rec: InteractionReciever) -> void:
|
||||
if reciever == null:
|
||||
reciever = rec
|
||||
|
|
@ -23,5 +29,6 @@ func _process(_delta: float) -> void:
|
|||
var camera: Camera3D = get_viewport().get_camera_3d()
|
||||
var rotation_direction : float = -sign(camera.basis.x.dot(reciever.global_position - rotated.global_position))
|
||||
var result_quaternion: Quaternion = Quaternion(-camera.basis.z,PI + 1.5707963267948966 * rotation_direction)
|
||||
var calculated_angle: Quaternion = start_rotation.slerp(result_quaternion,clamp(proximity_radius/rotated.global_position.distance_to(reciever.global_position),0,1))
|
||||
var distance_without_y: float = Vector2(rotated.global_position.x,rotated.global_position.z).distance_to(Vector2(reciever.global_position.x,reciever.global_position.z))
|
||||
var calculated_angle: Quaternion = start_rotation.slerp(result_quaternion,modification_curve.sample(clamp(proximity_radius/distance_without_y,0,1)))
|
||||
rotated.quaternion = calculated_angle
|
||||
|
|
|
|||
23
src/reaction_registry.gd
Normal file
23
src/reaction_registry.gd
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
extends Node
|
||||
|
||||
const REACTIONS_DIRECTORY = "res://assets/reactions/"
|
||||
|
||||
var reactions: Array[Reaction]
|
||||
|
||||
func _ready() -> void:
|
||||
for file in ResourceLoader.list_directory(REACTIONS_DIRECTORY):
|
||||
reactions.append(load(REACTIONS_DIRECTORY + file))
|
||||
|
||||
func react(input_substances: Array[Substance], temperature: float) -> Array[Substance]:
|
||||
var filter_func: Callable = func(reaction: Reaction) -> bool:
|
||||
if reaction.reaction_temperature != -1:
|
||||
return (reaction.input_substances == input_substances) and temperature >= reaction.reaction_temperature
|
||||
else:
|
||||
return reaction.input_substances == input_substances
|
||||
|
||||
var filtered: Array[Reaction] = reactions.filter(filter_func)
|
||||
|
||||
if len(filtered) > 0:
|
||||
return filtered[0].output_substances.duplicate()
|
||||
else:
|
||||
return []
|
||||
1
src/reaction_registry.gd.uid
Normal file
1
src/reaction_registry.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://j6vy1offobyq
|
||||
7
src/resources/draggable.gd
Normal file
7
src/resources/draggable.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
extends Resource
|
||||
|
||||
class_name Draggable
|
||||
|
||||
@export var scene_to_spawn: PackedScene
|
||||
@export var icon: Texture2D
|
||||
1
src/resources/draggable.gd.uid
Normal file
1
src/resources/draggable.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b3i73cilpra74
|
||||
7
src/resources/reaction.gd
Normal file
7
src/resources/reaction.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends Resource
|
||||
|
||||
class_name Reaction
|
||||
|
||||
@export var input_substances: Array[Substance]
|
||||
@export var output_substances: Array[Substance]
|
||||
@export var reaction_temperature: float = -1
|
||||
1
src/resources/reaction.gd.uid
Normal file
1
src/resources/reaction.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dwks86y6383p4
|
||||
6
src/resources/reagent.gd
Normal file
6
src/resources/reagent.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends Resource
|
||||
|
||||
class_name Reagent
|
||||
|
||||
@export var substance: Substance
|
||||
@export var storage: PackedScene
|
||||
1
src/resources/reagent.gd.uid
Normal file
1
src/resources/reagent.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bditqax8ibmxw
|
||||
13
src/resources/substance.gd
Normal file
13
src/resources/substance.gd
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
extends Resource
|
||||
|
||||
class_name Substance
|
||||
|
||||
@export var formula: StringName
|
||||
@export var scientific_name: StringName
|
||||
@export var melting_point: float
|
||||
@export var boiling_point: float
|
||||
@export var color: Color
|
||||
@export var prefer_scientific_name: bool
|
||||
|
||||
func get_formula() -> StringName:
|
||||
return scientific_name if prefer_scientific_name else formula
|
||||
1
src/resources/substance.gd.uid
Normal file
1
src/resources/substance.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b8q5buwgvppyh
|
||||
13
src/ui/drag_and_drop.gd
Normal file
13
src/ui/drag_and_drop.gd
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
extends Button
|
||||
|
||||
|
||||
@export var draggable: Draggable
|
||||
|
||||
func _on_button_down() -> void:
|
||||
var scene = draggable.scene_to_spawn.instantiate()
|
||||
if scene is DraggableObject:
|
||||
scene.dragged = true
|
||||
scene.mouse_in = true
|
||||
get_tree().current_scene.add_child(scene)
|
||||
var camera = get_viewport().get_camera_3d()
|
||||
scene.global_position = camera.project_position(get_global_mouse_position(),1.8)
|
||||
1
src/ui/drag_and_drop.gd.uid
Normal file
1
src/ui/drag_and_drop.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ds5u02jdtxyd4
|
||||
34
src/ui/popup_container.gd
Normal file
34
src/ui/popup_container.gd
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
extends Control
|
||||
|
||||
@export var show_animation_time: float = 0.25
|
||||
@export var text: String = ""
|
||||
|
||||
var tween: Tween
|
||||
@onready var default_left_anchor: float = anchor_left
|
||||
@onready var default_right_anchor: float = anchor_right
|
||||
|
||||
func _ready() -> void:
|
||||
mouse_entered.connect(show_menu)
|
||||
mouse_exited.connect(hide_menu)
|
||||
$Label.text = text
|
||||
|
||||
func show_menu() -> void:
|
||||
if tween:
|
||||
tween.kill()
|
||||
|
||||
tween = create_tween()
|
||||
tween.tween_property(self,"anchor_right",default_right_anchor + abs(default_left_anchor),show_animation_time)
|
||||
tween.parallel()
|
||||
tween.tween_property(self,"anchor_left",default_right_anchor,show_animation_time)
|
||||
|
||||
func hide_menu() -> void:
|
||||
if tween:
|
||||
tween.kill()
|
||||
|
||||
tween = create_tween()
|
||||
tween.tween_property(self,"anchor_right",default_right_anchor,show_animation_time)
|
||||
tween.parallel()
|
||||
tween.tween_property(self,"anchor_left",default_left_anchor,show_animation_time)
|
||||
|
||||
func add_element(node: Node):
|
||||
$ScrollContainer/VBoxContainer.add_child(node)
|
||||
1
src/ui/popup_container.gd.uid
Normal file
1
src/ui/popup_container.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c4tsyohkw45p4
|
||||
17
src/ui/reagent_drag_and_drop.gd
Normal file
17
src/ui/reagent_drag_and_drop.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
extends Button
|
||||
|
||||
|
||||
var reagent: Reagent
|
||||
|
||||
func _ready() -> void:
|
||||
text = reagent.substance.get_formula()
|
||||
|
||||
func _on_button_down() -> void:
|
||||
return
|
||||
var scene = reagent.scene.instantiate()
|
||||
if scene is DraggableObject:
|
||||
scene.dragged = true
|
||||
scene.mouse_in = true
|
||||
get_tree().current_scene.add_child(scene)
|
||||
var camera = get_viewport().get_camera_3d()
|
||||
scene.global_position = camera.project_position(get_global_mouse_position(),1.8)
|
||||
1
src/ui/reagent_drag_and_drop.gd.uid
Normal file
1
src/ui/reagent_drag_and_drop.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b2w4adq02ywrl
|
||||
12
src/ui/reagents_gen.gd
Normal file
12
src/ui/reagents_gen.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
extends Node
|
||||
|
||||
const dnd_button = preload("res://scenes/reactives_drag_and_drop.tscn")
|
||||
const reagent_dir = "res://assets/reagents/"
|
||||
|
||||
func _ready() -> void:
|
||||
for file in ResourceLoader.list_directory(reagent_dir):
|
||||
var button = dnd_button.instantiate()
|
||||
button.reagent = load(reagent_dir+file)
|
||||
get_parent().add_element.call_deferred(button)
|
||||
|
||||
|
||||
1
src/ui/reagents_gen.gd.uid
Normal file
1
src/ui/reagents_gen.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c5pv2idedy1oy
|
||||
Loading…
Add table
Add a link
Reference in a new issue