Files
millimeters-of-aluminum/data/structure/structure_data.gd
2025-12-05 15:50:48 +01:00

64 lines
2.0 KiB
GDScript

class_name StructureData extends Resource
enum PieceType {STRUT, PLATE, CONNECTOR}
@export_group("Identity")
@export var piece_name: String = "Structure"
@export var type: PieceType = PieceType.STRUT
@export var base_mass: float = 10.0
@export var health_max: float = 100.0
@export var cost: Dictionary = {"Aluminium": 10.0}
@export_group("Visuals & Physics")
## The mesh to display for static pieces. Leave null for procedural pieces.
@export var mesh: Mesh
## The collision shape for physics. Leave null for procedural pieces.
@export var collision_shape: Shape3D
@export_group("Procedural Parameters")
# For procedural pieces, we store parameters instead of a mesh
@export var shape: String = "Cube"
@export var vertices: Array[Vector3] = [
Vector3(1.0, 1.0, 1.0),
Vector3(-1.0, 1.0, 1.0),
Vector3(-1.0, -1.0, 1.0),
Vector3(1.0, -1.0, 1.0),
Vector3(1.0, 1.0, -1.0),
Vector3(-1.0, 1.0, -1.0),
Vector3(-1.0, -1.0, -1.0),
Vector3(1.0, -1.0, -1.0)
]
# @export var procedural_params: Dictionary = {}
@export_group("Mounts")
## Array of Dictionaries defining attachment points.
## Format: { "position": Vector3, "normal": Vector3, "up": Vector3, "type": int }
@export var mounts: Array[Dictionary] = []
# Helper to get mounts transformed into world space for snapping calculations
func get_mounts_transformed(global_transform: Transform3D) -> Array:
var world_mounts = []
for mount in mounts:
# Default to identity rotation if normal/up are missing
var normal = mount.get("normal", Vector3.BACK) # Default -Z forward
var up = mount.get("up", Vector3.UP)
world_mounts.append({
"position": global_transform * mount.get("position", Vector3.ZERO),
"normal": global_transform.basis * normal,
"up": global_transform.basis * up,
"type": mount.get("type", 0)
})
return world_mounts
# Helper to add a mount dynamically (for procedural pieces)
func add_mount(pos: Vector3, normal: Vector3, up: Vector3 = Vector3.UP, type: int = 0):
mounts.append({
"position": pos,
"normal": normal,
"up": up,
"type": type
})