extends SceneTree ## The greengrocer: do the pyramids build and SETTLE, does produce burst instead of ## shattering, does a collapse crush its own bottom layer, and does the floor get ## slippery. ## Godot --headless --path game --script dev/probe_grocer.gd func _initialize() -> void: var main: Node = (load("res://main.tscn") as PackedScene).instantiate() get_root().add_child(main) await process_frame main._load_level("grocer") for i in 10: await physics_frame var splat = main.get("_splat") var produce := _count("produce") print("site : ", main.get("_plan").level_name()) print("produce : %d glass: %d total smashables: %d" % [ produce, _count("glass"), get_nodes_in_group("smashable").size()]) # --- do the stacks hold? --- for i in 120: await physics_frame var moving := 0 var total := 0.0 for n in get_nodes_in_group("smashable"): var b := n as RigidBody3D if b == null or b.freeze: continue var v := b.linear_velocity.length() total += v if v > 0.15: moving += 1 print("after 2s : %d still moving, total %.2f m/s (stacks should be at rest)" % [ moving, total]) print("survived : %d produce (spawn crush would show up as losses)" % _count("produce")) # --- squash one: does it burst rather than shard? --- var before_l: float = splat.litres var debris_before := get_nodes_in_group("debris").size() var victim: Smashable = null for n in get_nodes_in_group("smashable"): if (n as Smashable).kind == "produce": victim = n break var at := victim.global_position victim.shatter(Vector3.UP) await process_frame print("squash one: litres %.2f -> %.2f debris %d -> %d (must NOT rise: fruit has no shards)" % [ before_l, splat.litres, debris_before, get_nodes_in_group("debris").size()]) # --- drop a melon on a pile: does the collapse crush? --- var n0 := _count("produce") for n in get_nodes_in_group("smashable"): var b := n as Smashable if b != null and b.kind == "produce": b.apply_central_impulse(Vector3(randf_range(-3, 3), 0, randf_range(-3, 3))) for i in 150: await physics_frame print("shoved all: %d -> %d produce %.1f litres from the collapse" % [ n0, _count("produce"), splat.litres]) # --- slippery? --- var player = main.get("_player") player.global_position = Vector3(at.x, 0.0, at.z) await process_frame print("slip here : %.2f (0 = dry floor)" % splat.slip_under_player()) print("hud : ", splat.hud_line()) # --- and none of it leaks to the office --- main._load_level("scranton") for i in 6: await physics_frame print("at office : litres %.1f (reset) produce %d" % [splat.litres, _count("produce")]) quit() func _count(kind: String) -> int: var n := 0 for s in get_nodes_in_group("smashable"): if (s as Smashable) != null and (s as Smashable).kind == kind: n += 1 return n