mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
Added the ability to load from any csv file, for characters.
This commit is contained in:
parent
347e48080b
commit
d3f7c4f576
@ -38,6 +38,7 @@ func _prep_PlayerCharacter_Template():
|
|||||||
pSingleton.strength = Strength.text
|
pSingleton.strength = Strength.text
|
||||||
pSingleton.intellect = Intellect.text
|
pSingleton.intellect = Intellect.text
|
||||||
pSingleton.willpower = Willpower.text
|
pSingleton.willpower = Willpower.text
|
||||||
|
pSingleton.weapon = Weapon.text
|
||||||
pSingleton.charm = Charm.text
|
pSingleton.charm = Charm.text
|
||||||
pSingleton.armor = Armor.text
|
pSingleton.armor = Armor.text
|
||||||
pSingleton.quote = Quote.text
|
pSingleton.quote = Quote.text
|
||||||
@ -74,8 +75,7 @@ func _on_But_SaveChar_pressed():
|
|||||||
|
|
||||||
var input_data = [
|
var input_data = [
|
||||||
["Name", "Profession", "Strength", "Intellect", "Willpower", "Charm", "Weapon", "Armor", "Quote"],
|
["Name", "Profession", "Strength", "Intellect", "Willpower", "Charm", "Weapon", "Armor", "Quote"],
|
||||||
[pSingleton.name, pSingleton.profession, pSingleton.strength, pSingleton.intellect,
|
[pSingleton.name, pSingleton.profession, pSingleton.strength, pSingleton.intellect, pSingleton.willpower, pSingleton.charm, pSingleton.weapon, pSingleton.armor, pSingleton.quote],
|
||||||
pSingleton.willpower, pSingleton.charm, pSingleton.weapon, pSingleton.armor, pSingleton.quote],
|
|
||||||
]
|
]
|
||||||
|
|
||||||
save_data_to_csv(input_data, file_path)
|
save_data_to_csv(input_data, file_path)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
|
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
|
||||||
|
onready var pSingleton = get_node("/root/PlayerCharacter").pc
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
theme=load(settings.themeFile)
|
theme=load(settings.themeFile)
|
||||||
@ -14,11 +15,63 @@ func _on_But_loadCharacter_pressed() -> void:
|
|||||||
$LoadCharacter_FileDialog.popup()
|
$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
|
#DKM TEMP: we need to load the character item, not display to field
|
||||||
func _on_LoadCharacter_FileDialog_file_selected(path: String) -> void:
|
func _on_LoadCharacter_FileDialog_file_selected(path: String) -> void:
|
||||||
print(path)
|
print(path)
|
||||||
var charFile = File.new()
|
var charFile = File.new()
|
||||||
charFile.open(path, 1)
|
charFile.open(path, 1)
|
||||||
var pc = get_node("/root/PlayerCharacter")
|
var pc = get_node("/root/PlayerCharacter")
|
||||||
pc.playerCharacterSingleton.pcText = charFile.get_as_text()
|
|
||||||
$TextEdit.text = pc.playerCharacterSingleton.pcText
|
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
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://userInterface/Title.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://UserInterface/Title.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://userInterface/But_ChangeScene.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://UserInterface/But_ChangeScene.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://Screens/Character_Load.gd" type="Script" id=3]
|
[ext_resource path="res://Screens/Character_Load.gd" type="Script" id=3]
|
||||||
|
|
||||||
[node name="Control" type="Control"]
|
[node name="Control" type="Control"]
|
||||||
|
Loading…
Reference in New Issue
Block a user