mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-25 00:54:19 +00:00
Sort some things with the shop but I'm not sure what the error currently means
This commit is contained in:
parent
432d82af55
commit
a6650e6140
8 changed files with 85 additions and 36 deletions
|
@ -88,9 +88,8 @@ func update_counter_icon():
|
||||||
else:
|
else:
|
||||||
store_collector_texturerect.texture = null
|
store_collector_texturerect.texture = null
|
||||||
|
|
||||||
func _on_ghost_requested(scene: PackedScene, texture: Texture2D):
|
func _on_ghost_requested(item: PurchasableItem):
|
||||||
ghost.scene_to_instantiate = scene
|
ghost.COMPAT_set_to_purchasable_item(item)
|
||||||
ghost.preview_texture = texture
|
|
||||||
ghost.process_mode = Node.PROCESS_MODE_INHERIT
|
ghost.process_mode = Node.PROCESS_MODE_INHERIT
|
||||||
ghost.show()
|
ghost.show()
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class_name ShopItem
|
||||||
## The item type to collect to purchase the item.
|
## The item type to collect to purchase the item.
|
||||||
##
|
##
|
||||||
## If null, counts the items' value.
|
## If null, counts the items' value.
|
||||||
@export var cost_tag: StringPath
|
@export var cost_tag: StringName
|
||||||
|
|
||||||
## The quantity of items to collect to purchase the item.
|
## The quantity of items to collect to purchase the item.
|
||||||
##
|
##
|
||||||
|
@ -24,8 +24,21 @@ class_name ShopItem
|
||||||
## The shape that the ghost should use to determine if the item's placement is valid.
|
## 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.
|
## Concave shapes might have problems interacting with the placeable area.
|
||||||
|
##
|
||||||
|
## May be null if the purchase does not involve the placement of an item.
|
||||||
@export var placement_shape: Shape2D
|
@export var placement_shape: Shape2D
|
||||||
|
|
||||||
|
## The texture that should be rendered when the ghost is placing this item.
|
||||||
|
##
|
||||||
|
## Will be made transparent and modulated to red by the ghost.
|
||||||
|
##
|
||||||
|
## May be null if the purchase does not involve the placement of an item.
|
||||||
|
@export var placement_texture: Texture2D
|
||||||
|
|
||||||
|
## The scene to instantiate when the purchase is complete.
|
||||||
|
##
|
||||||
|
## May be null if the purchase does not involve the placement of an item.
|
||||||
|
@export var placement_scene: PackedScene
|
||||||
|
|
||||||
## What to do when this item is purchased.
|
## What to do when this item is purchased.
|
||||||
signal on_purchase
|
signal on_purchase
|
||||||
|
|
6
game/shop_item.tscn
Normal file
6
game/shop_item.tscn
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://ct4sh7f8qnyob"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://game/shop_item.gd" id="1_8e5vp"]
|
||||||
|
|
||||||
|
[node name="ShopItem" type="Node"]
|
||||||
|
script = ExtResource("1_8e5vp")
|
|
@ -30,34 +30,65 @@ class_name Ghost
|
||||||
## The [Sprite2D] node previewing the scene.
|
## The [Sprite2D] node previewing the scene.
|
||||||
@onready var preview_sprite: Sprite2D = $PlacementShape/PreviewSprite
|
@onready var preview_sprite: Sprite2D = $PlacementShape/PreviewSprite
|
||||||
|
|
||||||
|
## The position the ghost should have when a new body starts being placed.
|
||||||
|
@onready var starting_position: Vector2 = position
|
||||||
|
|
||||||
var can_place: bool = false
|
## The rotation the ghost should have when a new body starts being placed.
|
||||||
|
@onready var starting_rotation_radians: float = rotation
|
||||||
|
|
||||||
|
|
||||||
|
## Whether this object can currently be placed.
|
||||||
|
var can_place: bool = false:
|
||||||
|
get:
|
||||||
|
return can_place
|
||||||
|
set(value):
|
||||||
|
if value != can_place:
|
||||||
|
can_place_changed.emit(value)
|
||||||
|
can_place = value
|
||||||
|
modulate = valid_color if value else invalid_color
|
||||||
|
|
||||||
|
## Emitted when [can_place] changes value.
|
||||||
|
signal can_place_changed(to: bool)
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Initialize the Area's collision mask
|
# Initialize the Area's collision mask
|
||||||
collision_mask = overlap_checker.collision_mask | placeable_area_checker.collision_mask | overlap_freer.collision_mask
|
collision_mask = overlap_checker.overlap_mask | placeable_area_checker.overlap_mask | overlap_freer.overlap_mask
|
||||||
|
|
||||||
|
|
||||||
## Update the value of [can_place].
|
## Update the value of [can_place].
|
||||||
func update_state():
|
func update_state():
|
||||||
# DIRTY HACK: Relies on the placeable area being perfectly surrounded by solid bodies.
|
# 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
|
can_place = overlap_checker.is_overlapping_with == null and placeable_area_checker.is_overlapping_with != null
|
||||||
|
|
||||||
|
## For retro-compatibility, configure this for the placement of a [PurchasableItem].
|
||||||
|
func COMPAT_set_to_purchasable_item(pi: PurchasableItem):
|
||||||
|
instantiator.scene_to_instantiate = pi.item_scene
|
||||||
|
placement_shape.shape = pi.get_node("ConverterPlacementBody").get_node("FullConverterShape").shape
|
||||||
|
placement_shape.scale = pi.item_scene.scale
|
||||||
|
preview_sprite.texture = pi.item_icon
|
||||||
|
position = starting_position
|
||||||
|
rotation = starting_rotation_radians
|
||||||
|
|
||||||
|
|
||||||
|
## Configure this for the placement of a [ShopItem].
|
||||||
func set_to_shop_item(si: ShopItem):
|
func set_to_shop_item(si: ShopItem):
|
||||||
pass
|
instantiator.scene_to_instantiate = si.placement_scene
|
||||||
|
placement_shape.shape = si.placement_shape # TODO: Hmmm. Not the best interface.
|
||||||
|
placement_shape.scale = si.placement_scene.scale
|
||||||
|
preview_sprite.texture = si.placement_texture
|
||||||
|
position = starting_position
|
||||||
|
rotation = starting_rotation_radians
|
||||||
|
|
||||||
|
## Emitted when [materialize] is called.
|
||||||
|
signal materialized(what: Node)
|
||||||
|
|
||||||
func materialize():
|
## Try to materialize the scene, returning it if the instantiation was successful, or null if it wasn't.
|
||||||
# Compatibility stub for Instantiator
|
##
|
||||||
|
## Remember to try the placement again if this returns null!
|
||||||
|
func materialize() -> Node:
|
||||||
if not can_place:
|
if not can_place:
|
||||||
return null
|
return null
|
||||||
var overlapping_bodies = get_overlapping_bodies()
|
overlap_freer.area_queue_free()
|
||||||
for body in overlapping_bodies:
|
|
||||||
if body is PhysicsBody2D:
|
|
||||||
if body.collision_layer & collision_mask_delete_placement:
|
|
||||||
body.queue_free()
|
|
||||||
var inst = instantiator.instantiate()
|
var inst = instantiator.instantiate()
|
||||||
# TODO: Remove this
|
materialized.emit(inst)
|
||||||
return inst
|
return inst
|
||||||
|
|
|
@ -13,13 +13,9 @@ collision_layer = 0
|
||||||
collision_mask = 4294967295
|
collision_mask = 4294967295
|
||||||
input_pickable = false
|
input_pickable = false
|
||||||
script = ExtResource("1_1bq64")
|
script = ExtResource("1_1bq64")
|
||||||
valid_color = null
|
|
||||||
invalid_color = null
|
|
||||||
collision_mask_prevent_placement = 16
|
|
||||||
collision_mask_delete_placement = 4
|
|
||||||
|
|
||||||
[node name="PlacementShape" parent="." instance=ExtResource("2_bo8dp")]
|
[node name="PlacementShape" parent="." instance=ExtResource("2_bo8dp")]
|
||||||
scale = Vector2(2.5, 2.5)
|
shape = null
|
||||||
|
|
||||||
[node name="PreviewSprite" type="Sprite2D" parent="PlacementShape"]
|
[node name="PreviewSprite" type="Sprite2D" parent="PlacementShape"]
|
||||||
modulate = Color(1, 1, 1, 0.5)
|
modulate = Color(1, 1, 1, 0.5)
|
||||||
|
|
|
@ -28,10 +28,14 @@ func get_all_overlapping_bodies() -> Array[Node2D]:
|
||||||
return bodies
|
return bodies
|
||||||
|
|
||||||
## Emitted when a body is about to be [queue_free]d.
|
## Emitted when a body is about to be [queue_free]d.
|
||||||
signal body_queueing_free(body: Node2D)
|
signal queueing_free(body: Node2D)
|
||||||
|
|
||||||
|
## Queue free the passed nodes.
|
||||||
|
func mass_queue_free(nodes: Array[Node2D]):
|
||||||
|
for node in nodes:
|
||||||
|
queueing_free.emit(node)
|
||||||
|
node.queue_free()
|
||||||
|
|
||||||
## Queue free all overlapping bodies.
|
## Queue free all overlapping bodies.
|
||||||
func area_queue_free() -> void:
|
func area_queue_free() -> void:
|
||||||
for body in get_all_overlapping_bodies():
|
mass_queue_free(get_all_overlapping_bodies())
|
||||||
body_queueing_free.emit(body)
|
|
||||||
body.queue_free()
|
|
||||||
|
|
|
@ -90,25 +90,25 @@ var has_bought: bool:
|
||||||
|
|
||||||
|
|
||||||
## Emitted when a purchase has started.
|
## Emitted when a purchase has started.
|
||||||
signal purchase_begin
|
signal purchase_begin(what: PurchasableItem)
|
||||||
|
|
||||||
## Emitted when a purchase is cancelled.
|
## Emitted when a purchase is cancelled.
|
||||||
signal purchase_cancel
|
signal purchase_cancel(what: PurchasableItem)
|
||||||
|
|
||||||
## Emitted when a purchase is completed.
|
## Emitted when a purchase is completed.
|
||||||
##
|
##
|
||||||
## Emitted by complete_purchase().
|
## Emitted by complete_purchase().
|
||||||
signal purchase_success
|
signal purchase_success(what: PurchasableItem)
|
||||||
|
|
||||||
|
|
||||||
func _on_buy_button_pressed():
|
func _on_buy_button_pressed():
|
||||||
if is_buying:
|
if is_buying:
|
||||||
is_buying = false
|
is_buying = false
|
||||||
purchase_cancel.emit()
|
purchase_cancel.emit(self)
|
||||||
else:
|
else:
|
||||||
is_buying = true
|
is_buying = true
|
||||||
purchase_begin.emit()
|
purchase_begin.emit(self)
|
||||||
|
|
||||||
func complete_purchase():
|
func complete_purchase():
|
||||||
is_buying = false
|
is_buying = false
|
||||||
purchase_success.emit()
|
purchase_success.emit(self)
|
||||||
|
|
|
@ -23,14 +23,14 @@ signal purchase_success(what: PurchasableItem)
|
||||||
## Array of all PurchasableItems that this ShopUI should control.
|
## Array of all PurchasableItems that this ShopUI should control.
|
||||||
@onready var purchasable_items: Array[Node] = find_children("*", "PurchasableItem")
|
@onready var purchasable_items: Array[Node] = find_children("*", "PurchasableItem")
|
||||||
|
|
||||||
signal ghost_requested(scene: PackedScene, texture: Texture2D)
|
signal ghost_requested(what: PurchasableItem)
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
for item in purchasable_items:
|
for item in purchasable_items:
|
||||||
item.purchase_begin.connect(_on_any_purchase_begin.bind(item))
|
item.purchase_begin.connect(_on_any_purchase_begin)
|
||||||
item.purchase_cancel.connect(_on_any_purchase_cancel.bind(item))
|
item.purchase_cancel.connect(_on_any_purchase_cancel)
|
||||||
item.purchase_success.connect(_on_any_purchase_success.bind(item))
|
item.purchase_success.connect(_on_any_purchase_success)
|
||||||
|
|
||||||
func _on_any_purchase_begin(what: Node):
|
func _on_any_purchase_begin(what: Node):
|
||||||
if not what is PurchasableItem:
|
if not what is PurchasableItem:
|
||||||
|
@ -38,7 +38,7 @@ func _on_any_purchase_begin(what: Node):
|
||||||
return
|
return
|
||||||
delete_button.disabled = true
|
delete_button.disabled = true
|
||||||
if what.item_scene:
|
if what.item_scene:
|
||||||
ghost_requested.emit(what.item_scene, what.item_icon)
|
ghost_requested.emit(what)
|
||||||
purchase_begin.emit(what)
|
purchase_begin.emit(what)
|
||||||
set_all_can_buy(false, what)
|
set_all_can_buy(false, what)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue