Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Oct 8, 2024
1 parent 1ba04ba commit 1ffdb33
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
7 changes: 5 additions & 2 deletions bin3d/addons/godot-rapier3d/faucet_3d.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
class_name Faucet3D
extends Fluid3D

var points_new: PackedVector3Array
@export var interval := 0.06
var velocities_new: PackedVector3Array
@export var max_particles: int = 1000
@export var width: int = 4
@export var height: int = 1
@export var depth: int = 4

var points_new: PackedVector3Array
var velocities_new: PackedVector3Array


func _ready():
points_new = create_box_points(width, height, depth)
velocities_new.resize(points_new.size())
Expand All @@ -18,6 +20,7 @@ func _ready():
velocities_new.fill(dir)
get_tree().create_timer(interval).timeout.connect(_on_timer_timeout)


func _on_timer_timeout():
get_tree().create_timer(interval).timeout.connect(_on_timer_timeout)
if len(points) > max_particles:
Expand Down
1 change: 1 addition & 0 deletions bin3d/addons/godot-rapier3d/fluid_3d_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func _ready():
#multimesh.mesh = load("res://addons/godot-rapier2d/circle_mesh.tres").duplicate()
multimesh.use_colors = true


func _process(_delta):
if fluid == null || multimesh == null || multimesh.mesh == null:
return
Expand Down
35 changes: 24 additions & 11 deletions bin3d/addons/godot-rapier3d/rapier_state_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
class_name Rapier3DState
extends Node

var state : Dictionary = {}
var state: Dictionary = {}


func _is_physics_object(node: Node) -> bool:
return node is CollisionObject3D or \
node is Joint3D
return node is CollisionObject3D or node is Joint3D


func _get_all_physics_nodes(p_node: Node, path: String = "/root/") -> Array[String]:
var results : Array[String] = []
var results: Array[String] = []
if path == "/root/" && _is_physics_object(p_node):
results.append(path + p_node.name)
path += p_node.name + "/"
Expand All @@ -21,29 +22,33 @@ func _get_all_physics_nodes(p_node: Node, path: String = "/root/") -> Array[Stri
results.append_array(_get_all_physics_nodes(node, path))
return results


## Save a node's physics state
func save_node(rid: RID, save_json: bool):
if save_json:
return JSON.parse_string(RapierPhysicsServer3D.export_json(rid))
else:
return RapierPhysicsServer3D.export_binary(rid)
return RapierPhysicsServer3D.export_binary(rid)


## Load a node's physics state
func load_node(rid: RID, data: PackedByteArray):
RapierPhysicsServer3D.import_binary(rid, data)


## Save the state of whole world (single space)
func save_state(save_json: bool = false) -> int:
var physics_nodes := _get_all_physics_nodes(get_tree().current_scene)
for node_path in physics_nodes:
var node := get_node(node_path)
var rid : RID
var rid: RID
if node is CollisionObject3D:
rid = node.get_rid()
for owner_id in node.get_shape_owners():
for owner_shape_id in node.shape_owner_get_shape_count(owner_id):
var shape_rid = node.shape_owner_get_shape(owner_id, owner_shape_id).get_rid()
state[node_path + "/" + str(owner_id) + "/" + str(owner_shape_id)] = save_node(shape_rid, save_json)
state[node_path + "/" + str(owner_id) + "/" + str(owner_shape_id)] = save_node(
shape_rid, save_json
)
if node is Joint3D:
rid = node.get_rid()
state[node_path] = save_node(rid, save_json)
Expand All @@ -52,18 +57,21 @@ func save_state(save_json: bool = false) -> int:
state["id"] = RapierPhysicsServer3D.get_global_id()
return hash(JSON.stringify(state))


## Load the state of whole world (single space)
func load_state() -> int:
var physics_nodes := _get_all_physics_nodes(get_tree().current_scene)
for node_path in physics_nodes:
var node := get_node(node_path)
var rid : RID
var rid: RID
if node is CollisionObject3D:
rid = node.get_rid()
for owner_id in node.get_shape_owners():
for owner_shape_id in node.shape_owner_get_shape_count(owner_id):
var shape_rid = node.shape_owner_get_shape(owner_id, owner_shape_id).get_rid()
var shape_state = state[node_path + "/" + str(owner_id) + "/" + str(owner_shape_id)]
var shape_state = state[
node_path + "/" + str(owner_id) + "/" + str(owner_shape_id)
]
load_node(shape_rid, JSON.parse_string(shape_state))
if node is Joint3D:
rid = node.get_rid()
Expand All @@ -74,19 +82,24 @@ func load_state() -> int:
RapierPhysicsServer3D.set_global_id(int(state["id"]))
return hash(JSON.stringify(state))


## Export the state to file
func export_state(file_name: String = "user://state.json"):
save_state(false)
FileAccess.open(file_name, FileAccess.WRITE).store_string(JSON.stringify(state, " "))


## Import the state from file
func import_state(file_name: String = "user://state.json"):
state = JSON.parse_string(FileAccess.open(file_name, FileAccess.READ).get_as_text())
load_state()


func _notification(what: int) -> void:
if what == NOTIFICATION_ENTER_TREE:
print("enter tree")
if what == NOTIFICATION_EXIT_TREE:
save_state(false)
FileAccess.open("user://save.json", FileAccess.WRITE).store_string(JSON.stringify(state, " "))
FileAccess.open("user://save.json", FileAccess.WRITE).store_string(
JSON.stringify(state, " ")
)

0 comments on commit 1ffdb33

Please sign in to comment.