-
Notifications
You must be signed in to change notification settings - Fork 7
/
Character_Load.gd
77 lines (52 loc) · 1.92 KB
/
Character_Load.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#CHARACTER_LOAD:
# Script for loading a character file into the character object from file
extends Control
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
onready var pSingleton = get_node("/root/PlayerCharacter").pc
func _ready() -> void:
theme=load(settings.themeFile)
$Title/But_loadCharacter.grab_focus()
func _on_But_loadCharacter_pressed() -> void:
$LoadCharacter_FileDialog.popup()
func _prep_PlayerCharacter_Template(loadedCSVData):
print(loadedCSVData)
pSingleton.name = loadedCSVData[0]
pSingleton.profession = loadedCSVData[1]
pSingleton.strength = loadedCSVData[2]
pSingleton.intellect = loadedCSVData[3]
pSingleton.willpower = loadedCSVData[4]
pSingleton.charm = loadedCSVData[5]
pSingleton.armor = loadedCSVData[6]
pSingleton.quote = loadedCSVData[7]
print("P Singleton")
print(pSingleton)
func load_csv_data(path):
var file = File.new()
var error = file.open(path, File.READ) # Open the file for reading
if error != OK:
print("Error opening CSV file:", error)
return
var data = []
while !file.eof_reached():
var line = file.get_csv_line()
data.append(line)
file.close()
return data
#DKM TEMP: we need to load the character item, not display to field
func _on_LoadCharacter_FileDialog_file_selected(path: String) -> void:
print(path)
var charFile = File.new()
charFile.open(path, 1)
var pc = get_node("/root/PlayerCharacter")
var csv_data = load_csv_data(path)
print(csv_data)
_prep_PlayerCharacter_Template(csv_data[1])
# pc.playerCharacterSingleton.pcText = charFile.get_as_text()
# $TextEdit.text = pc.playerCharacterSingleton.pcText
#func _ready():
# # Replace "your_file.csv" with the actual path to your CSV file
# var csv_data = load_csv_data("res://your_file.csv")
# # Process the loaded data (data is a 2D array)
# # You can access data like this:
# # for row in csv_data:
# # print(row[0]) # Access first element in each row