diff --git a/game/shop_item.gd b/game/shop_item.gd new file mode 100644 index 0000000..de5aea8 --- /dev/null +++ b/game/shop_item.gd @@ -0,0 +1,31 @@ +extends Node +class_name ShopItem + + +## The name of the item to display in the shop. +@export var title_text: String + +## The description of the item to display in the shop. +@export var description_text: String + +## The cost of the item to display in the shop. +@export var cost_text: String + +## The item type to collect to purchase the item. +## +## If null, counts the items' value. +@export var cost_tag: StringPath + +## The quantity of items to collect to purchase the item. +## +## If cost_tag is null, counts the items' value. +@export var cost_quantity: int + +## The shape that the ghost should use to determine if the item's placement is valid. +## +## Concave shapes might have problems interacting with the placeable area. +@export var placement_shape: Shape2D + + +## What to do when this item is purchased. +signal on_purchase diff --git a/interface/ghost/ghost.gd b/interface/ghost/ghost.gd index edaa3fe..0b418ca 100644 --- a/interface/ghost/ghost.gd +++ b/interface/ghost/ghost.gd @@ -30,47 +30,25 @@ class_name Ghost ## The [Sprite2D] node previewing the scene. @onready var preview_sprite: Sprite2D = $PlacementShape/PreviewSprite -## The collision mask of objects that should prevent this object's placement. -@export_flags_2d_physics var collision_mask_prevent_placement: int -## The collision mask of objects that should be deleted on this object's placement. -@export_flags_2d_physics var collision_mask_delete_placement: int - -## The texture that the preview sprite should display. -@export var preview_texture: Texture2D: - get: - return preview_texture - set(value): - preview_texture = value - # Quick priority fix - if preview_sprite: - preview_sprite.texture = value +var can_place: bool = false func _ready(): - collision_mask = collision_mask_prevent_placement | collision_mask_delete_placement - preview_sprite.texture = preview_texture - - -func _physics_process(_delta: float): - # Update collision - update_can_place() - - -var can_place: bool: - get: - return can_place - set(value): - can_place = value - modulate = valid_color if value else invalid_color + # Initialize the Area's collision mask + collision_mask = overlap_checker.collision_mask | placeable_area_checker.collision_mask | overlap_freer.collision_mask ## Update the value of [can_place]. -# DIRTY HACK: Relies on the placeable area being perfectly surrounded by solid bodies. -func update_can_place() -> void: +func update_state(): + # DIRTY HACK: Relies on the placeable area being perfectly surrounded by solid bodies. can_place = overlap_checker.is_overlapping_with == null and placeable_area_checker.is_overlapping_with != null +func set_to_shop_item(si: ShopItem): + pass + + func materialize(): # Compatibility stub for Instantiator if not can_place: diff --git a/interface/ghost/ghost.tscn b/interface/ghost/ghost.tscn index 2f074d8..b66079b 100644 --- a/interface/ghost/ghost.tscn +++ b/interface/ghost/ghost.tscn @@ -13,6 +13,8 @@ collision_layer = 0 collision_mask = 4294967295 input_pickable = false script = ExtResource("1_1bq64") +valid_color = null +invalid_color = null collision_mask_prevent_placement = 16 collision_mask_delete_placement = 4 @@ -37,3 +39,4 @@ z_index = 10 [connection signal="area_exited" from="." to="PlaceableAreaChecker" method="update_is_overlapping_with"] [connection signal="body_entered" from="." to="OverlapChecker" method="update_is_overlapping_with"] [connection signal="body_exited" from="." to="OverlapChecker" method="update_is_overlapping_with"] +[connection signal="overlap_changing" from="OverlapChecker" to="." method="update_state"] diff --git a/interface/ghost/placeable_area_checker.gd b/interface/ghost/placeable_area_checker.gd index a51f387..f06d750 100644 --- a/interface/ghost/placeable_area_checker.gd +++ b/interface/ghost/placeable_area_checker.gd @@ -2,6 +2,12 @@ extends Node class_name PlaceableAreaChecker +## Layers to consider when checking overlap with [PhysicBody2D]. +## +## Ignored during the actual collision check, just used to expand it in the Ghost's initialization phase. +@export_flags_2d_physics var overlap_mask: int + + ## The [Area2D] this script should act on. @onready var target: Area2D = get_parent()