forked from akjava/godot-simple-gemini-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
59 lines (49 loc) · 1.66 KB
/
main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
extends Control
var settings_path = "res://settings.json"
var chat_button : Button
var chat_scene : Control
var red_crystal_texture = preload("res://assets/ForestDetails/06.png")
var red_crystal_item: Sprite2D
@export var inventory : Inventory
func _ready():
_update_ui()
chat_button = find_child("EnterChatButton")
print('initialized')
chat_button.connect("pressed", Callable(self, "_on_button_pressed").bind(chat_button))
chat_button.visible = false
chat_scene = $Chat
chat_scene.visible = false
inventory = $Inventory
func _on_button_pressed(button):
chat_scene.visible = true
func _update_ui():
if FileAccess.file_exists(settings_path):
find_child("KeyContainer").visible = false
find_child("ButtonContainer").visible = true
else:
find_child("KeyContainer").visible = true
find_child("ButtonContainer").visible = false
func _on_set_api_button_pressed():
var key = find_child("KeyEdit").text
if key.is_empty():
return
var json_text = JSON.stringify({"api_key":key})
var file = FileAccess.open(settings_path,FileAccess.WRITE)
file.store_string(json_text)
file.close()
chat_scene.read_settings_file()
_update_ui()
func _on_chat_area_body_entered(body):
if body.name == 'baseCharacter':
chat_button.visible = true
print('collision ', body) # Replace with function body.
func _on_chat_area_body_exited(body):
if body.name == 'baseCharacter':
chat_button.visible = false
print('collision ', body) # Replace with function body.
func add_red_crystal_to_inventory():
inventory = $Inventory
red_crystal_item = Sprite2D.new()
red_crystal_item.name ="Red Crystal"
red_crystal_item.texture = red_crystal_texture
inventory.add_item(red_crystal_item)