-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from Phazorknight/vending-machine
Initial attempt at a basic vending machine, located in the breakroom
- Loading branch information
Showing
9 changed files
with
288 additions
and
10 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[remap] | ||
|
||
importer="oggvorbisstr" | ||
type="AudioStreamOggVorbis" | ||
uid="uid://6thelsn58odx" | ||
path="res://.godot/imported/vending_machine_sfx.ogg-3f07f398ea4fff5864b2a68ca3092113.oggvorbisstr" | ||
|
||
[deps] | ||
|
||
source_file="res://addons/cogito/Assets/Audio/vending_machine_sfx.ogg" | ||
dest_files=["res://.godot/imported/vending_machine_sfx.ogg-3f07f398ea4fff5864b2a68ca3092113.oggvorbisstr"] | ||
|
||
[params] | ||
|
||
loop=false | ||
loop_offset=0 | ||
bpm=0 | ||
beat_count=0 | ||
bar_beats=4 |
Binary file added
BIN
+21.9 KB
addons/cogito/Assets/Graphics/CogitoHealthPotion_vending_machine_sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions
35
addons/cogito/Assets/Graphics/CogitoHealthPotion_vending_machine_sprite.png.import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://s3qcosabxkgd" | ||
path.bptc="res://.godot/imported/CogitoHealthPotion_vending_machine_sprite.png-7f92801afb8bb7f2ce1d7674dbff7483.bptc.ctex" | ||
metadata={ | ||
"imported_formats": ["s3tc_bptc"], | ||
"vram_texture": true | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/cogito/Assets/Graphics/CogitoHealthPotion_vending_machine_sprite.png" | ||
dest_files=["res://.godot/imported/CogitoHealthPotion_vending_machine_sprite.png-7f92801afb8bb7f2ce1d7674dbff7483.bptc.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=2 | ||
compress/high_quality=true | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=2 | ||
compress/channel_pack=0 | ||
mipmaps/generate=true | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
extends Node3D | ||
|
||
##How much stock the vendor starts with | ||
@export var starting_amount : int = 3 | ||
@export var object_to_spawn : PackedScene | ||
@export var spawn_delay : float = 1.5 | ||
@export var spawn_rotation : Vector3 = Vector3.ZERO | ||
@export var purchased_hint_text : String = "Purchased a Health Potion" | ||
@export var have_stock_text : String = "In Stock" | ||
@export var stock_empty_text : String = "Sold Out" | ||
@export_group("Sound Settings") | ||
@export var dispensing_sound : AudioStream | ||
|
||
@onready var cogito_button = $GenericButton | ||
@onready var currency_check : CurrencyCheck = $GenericButton/CurrencyCheck | ||
@onready var spawn_point : Marker3D = $Spawnpoint | ||
@onready var stock_label = $StaticBody3D/StockLabel | ||
@onready var stock_counter : Label3D = $StaticBody3D/StockCounter | ||
|
||
var player_interaction_component : PlayerInteractionComponent | ||
var currency_attribute : CogitoCurrency | ||
|
||
var amount_remaining : int | ||
var is_dispensing : bool | ||
|
||
|
||
func _ready(): | ||
add_to_group("save_object_state") | ||
amount_remaining = starting_amount | ||
_update_vendor_state() | ||
cogito_button.allows_repeated_interaction = amount_remaining > 1 | ||
# spawn delay must be shorter than the press cooldown or spawn count could be affected | ||
if spawn_delay >= cogito_button.press_cooldown_time: | ||
spawn_delay = cogito_button.press_cooldown_time - 0.1 | ||
printerr("spawn_delay exceeded button press cooldown time. It has been set to " + str(spawn_delay)) | ||
currency_check.connect("transaction_success", Callable(self, "_on_transaction_success")) | ||
var player_node = CogitoSceneManager._current_player_node | ||
player_interaction_component = (player_node as CogitoPlayer).player_interaction_component | ||
for attribute in player_node.find_children("", "CogitoCurrency", false): | ||
if attribute is CogitoCurrency and attribute.currency_name == currency_check.currency_name: | ||
currency_attribute = attribute | ||
break | ||
|
||
|
||
func _on_transaction_success() -> void: | ||
# communicate the event | ||
player_interaction_component.send_hint(currency_attribute.currency_icon, purchased_hint_text) | ||
|
||
# update vendor | ||
amount_remaining -= 1 | ||
_update_vendor_state() | ||
|
||
# dispense object | ||
is_dispensing = true | ||
_delayed_object_spawn() | ||
|
||
|
||
func _delayed_object_spawn() -> void: | ||
if dispensing_sound: | ||
Audio.play_sound_3d(dispensing_sound).global_position = spawn_point.global_position | ||
|
||
await get_tree().create_timer(spawn_delay).timeout | ||
is_dispensing = false | ||
|
||
var spawned_object = object_to_spawn.instantiate() | ||
spawned_object.position = spawn_point.global_position | ||
spawned_object.rotation = spawn_rotation | ||
get_tree().current_scene.add_child(spawned_object) | ||
|
||
|
||
func _update_vendor_state() -> void: | ||
# when only 1 is left have the button handle it's own behavior | ||
if amount_remaining == 0: | ||
cogito_button.allows_repeated_interaction = false | ||
stock_label.text = stock_empty_text | ||
elif stock_label.text != have_stock_text: | ||
stock_label.text = have_stock_text | ||
|
||
stock_counter.text = str(amount_remaining) | ||
|
||
|
||
func set_state(): | ||
starting_amount = amount_remaining | ||
_update_vendor_state() | ||
|
||
if is_dispensing: | ||
_delayed_object_spawn() | ||
|
||
|
||
func save(): | ||
var state_dict = { | ||
"node_path" : self.get_path(), | ||
"amount_remaining" : amount_remaining, | ||
"is_dispensing" : is_dispensing, | ||
"pos_x" : position.x, | ||
"pos_y" : position.y, | ||
"pos_z" : position.z, | ||
"rot_x" : rotation.x, | ||
"rot_y" : rotation.y, | ||
"rot_z" : rotation.z, | ||
|
||
} | ||
return state_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
addons/cogito/DemoScenes/DemoPrefabs/vending_machine.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
[gd_scene load_steps=11 format=3 uid="uid://vlqfhilpj650"] | ||
|
||
[ext_resource type="Script" path="res://addons/cogito/CogitoObjects/cogito_vendor.gd" id="1_lj27e"] | ||
[ext_resource type="PackedScene" uid="uid://0fj068bj0csc" path="res://addons/cogito/PackedScenes/Pickups/pickup_health_potion.tscn" id="2_1u2dl"] | ||
[ext_resource type="PackedScene" uid="uid://cs6raqlyejqul" path="res://addons/cogito/DemoScenes/DemoPrefabs/generic_button.tscn" id="2_wxk3g"] | ||
[ext_resource type="AudioStream" uid="uid://6thelsn58odx" path="res://addons/cogito/Assets/Audio/vending_machine_sfx.ogg" id="3_7lknv"] | ||
[ext_resource type="Texture2D" uid="uid://s3qcosabxkgd" path="res://addons/cogito/Assets/Graphics/CogitoHealthPotion_vending_machine_sprite.png" id="4_wgwa5"] | ||
|
||
[sub_resource type="BoxShape3D" id="BoxShape3D_hgrek"] | ||
size = Vector3(1.15, 0.3, 0.8) | ||
|
||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_6qw18"] | ||
albedo_color = Color(0.3, 0.3, 0.3, 1) | ||
|
||
[sub_resource type="QuadMesh" id="QuadMesh_2himx"] | ||
size = Vector2(0.75, 0.9) | ||
|
||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vtrh8"] | ||
shading_mode = 0 | ||
albedo_color = Color(0.25, 0.5, 0.283333, 1) | ||
|
||
[sub_resource type="QuadMesh" id="QuadMesh_ng26b"] | ||
material = SubResource("StandardMaterial3D_vtrh8") | ||
size = Vector2(0.25, 0.25) | ||
|
||
[node name="VendingMachine" type="Node3D"] | ||
script = ExtResource("1_lj27e") | ||
object_to_spawn = ExtResource("2_1u2dl") | ||
spawn_rotation = Vector3(90, 0, 0) | ||
dispensing_sound = ExtResource("3_7lknv") | ||
|
||
[node name="StaticBody3D" type="StaticBody3D" parent="."] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) | ||
|
||
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.85, 0) | ||
shape = SubResource("BoxShape3D_hgrek") | ||
|
||
[node name="CSGCombiner3D" type="CSGCombiner3D" parent="StaticBody3D"] | ||
operation = 2 | ||
use_collision = true | ||
|
||
[node name="MeshInstance3D" type="CSGBox3D" parent="StaticBody3D/CSGCombiner3D"] | ||
size = Vector3(1.15, 2, 0.8) | ||
material = SubResource("StandardMaterial3D_6qw18") | ||
|
||
[node name="CSGBox3D" type="CSGBox3D" parent="StaticBody3D/CSGCombiner3D"] | ||
transform = Transform3D(1, 0, 0, 0, 0.990268, -0.139173, 0, 0.139173, 0.990268, -0.1, -0.3893, 0.345541) | ||
operation = 2 | ||
size = Vector3(0.8, 0.4, 0.6) | ||
material = SubResource("StandardMaterial3D_6qw18") | ||
|
||
[node name="CSGBox3D3" type="CSGBox3D" parent="StaticBody3D/CSGCombiner3D"] | ||
transform = Transform3D(1, 0, 0, 0, 0.965926, -0.258819, 0, 0.258819, 0.965926, -0.1, 0.453041, -0.00217443) | ||
operation = 2 | ||
size = Vector3(0.8, 0.595776, 0.582227) | ||
material = SubResource("StandardMaterial3D_6qw18") | ||
|
||
[node name="CSGBox3D2" type="CSGBox3D" parent="StaticBody3D/CSGCombiner3D"] | ||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, -0.1, 0.0707678, 0.184345) | ||
operation = 2 | ||
size = Vector3(0.8, 0.385535, 1.24217) | ||
material = SubResource("StandardMaterial3D_6qw18") | ||
|
||
[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3D"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.1, 0.4, 0.405) | ||
mesh = SubResource("QuadMesh_2himx") | ||
|
||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="StaticBody3D"] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.425, 0.5, 0.405) | ||
mesh = SubResource("QuadMesh_ng26b") | ||
|
||
[node name="StockLabel" type="Label3D" parent="StaticBody3D"] | ||
transform = Transform3D(0.35, 0, 0, 0, 0.35, 0, 0, 0, 0.35, 0.42558, 0.570185, 0.41) | ||
double_sided = false | ||
modulate = Color(0, 0, 0, 1) | ||
text = "In Stock" | ||
outline_size = 0 | ||
|
||
[node name="StockCounter" type="Label3D" parent="StaticBody3D"] | ||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0.42558, 0.457513, 0.41) | ||
double_sided = false | ||
modulate = Color(0, 0, 0, 1) | ||
text = "3" | ||
font_size = 42 | ||
outline_size = 6 | ||
|
||
[node name="SpawnedItemIcon" type="Sprite3D" parent="StaticBody3D"] | ||
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, -0.1, 0.4, 0.41) | ||
cast_shadow = 0 | ||
double_sided = false | ||
alpha_cut = 1 | ||
texture = ExtResource("4_wgwa5") | ||
|
||
[node name="GenericButton" parent="." instance=ExtResource("2_wxk3g")] | ||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0.425, 1.2, 0.45) | ||
usable_interaction_text = "Buy Health Potion" | ||
press_cooldown_time = 3.0 | ||
has_been_used_hint = "Out of stock" | ||
unusable_interaction_text = "Sold Out" | ||
|
||
[node name="CurrencyCheck" parent="GenericButton" index="6"] | ||
currency_cost = 5 | ||
currency_text_joiner = " | " | ||
|
||
[node name="Spawnpoint" type="Marker3D" parent="."] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.1, 1.40788, 0.0261086) | ||
|
||
[editable path="GenericButton"] |