mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-21 15:24:18 +00:00
Start work on ShopItem
This commit is contained in:
parent
8b490f9fb8
commit
432d82af55
4 changed files with 49 additions and 31 deletions
31
game/shop_item.gd
Normal file
31
game/shop_item.gd
Normal file
|
@ -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
|
|
@ -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:
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue