mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
Added support to load OptionButton items, from JSON data
This commit is contained in:
parent
64ecb2ba5a
commit
1c2530e57a
@ -13,6 +13,10 @@ config_version=4
|
|||||||
config/name="bcirpg_toolset"
|
config/name="bcirpg_toolset"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[global]
|
||||||
|
|
||||||
|
filters=false
|
||||||
|
|
||||||
[gui]
|
[gui]
|
||||||
|
|
||||||
common/drop_mouse_on_gui_input_disabled=true
|
common/drop_mouse_on_gui_input_disabled=true
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
extends Button
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
func _handle_user_input():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _on_Button_pressed():
|
||||||
|
_handle_user_input()
|
@ -1,6 +1,8 @@
|
|||||||
[gd_scene load_steps=2 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://screens/wizards/character_creation/SkillOptionButtonScript.gd" type="Script" id=1]
|
[ext_resource path="res://screens/wizards/character_creation/skills_option_button.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://screens/wizards/character_creation/specials_option_button.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://screens/wizards/character_creation/SaveCharButton.gd" type="Script" id=3]
|
||||||
|
|
||||||
[node name="Control" type="Control"]
|
[node name="Control" type="Control"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -568,6 +570,7 @@ text = "Slot 1:"
|
|||||||
margin_left = 44.0
|
margin_left = 44.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 20.0
|
margin_bottom = 20.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label2" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label2" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 27.0
|
margin_top = 27.0
|
||||||
@ -580,6 +583,7 @@ margin_left = 44.0
|
|||||||
margin_top = 24.0
|
margin_top = 24.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 44.0
|
margin_bottom = 44.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label3" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label3" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 51.0
|
margin_top = 51.0
|
||||||
@ -592,6 +596,7 @@ margin_left = 44.0
|
|||||||
margin_top = 48.0
|
margin_top = 48.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 68.0
|
margin_bottom = 68.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label4" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label4" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 75.0
|
margin_top = 75.0
|
||||||
@ -604,6 +609,7 @@ margin_left = 44.0
|
|||||||
margin_top = 72.0
|
margin_top = 72.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 92.0
|
margin_bottom = 92.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label5" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label5" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 99.0
|
margin_top = 99.0
|
||||||
@ -616,6 +622,7 @@ margin_left = 44.0
|
|||||||
margin_top = 96.0
|
margin_top = 96.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 116.0
|
margin_bottom = 116.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label6" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label6" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 123.0
|
margin_top = 123.0
|
||||||
@ -628,6 +635,7 @@ margin_left = 44.0
|
|||||||
margin_top = 120.0
|
margin_top = 120.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 140.0
|
margin_bottom = 140.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label7" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label7" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 147.0
|
margin_top = 147.0
|
||||||
@ -640,6 +648,7 @@ margin_left = 44.0
|
|||||||
margin_top = 144.0
|
margin_top = 144.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 164.0
|
margin_bottom = 164.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label8" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label8" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 171.0
|
margin_top = 171.0
|
||||||
@ -652,6 +661,7 @@ margin_left = 44.0
|
|||||||
margin_top = 168.0
|
margin_top = 168.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 188.0
|
margin_bottom = 188.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Label9" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
[node name="Label9" type="Label" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer"]
|
||||||
margin_top = 195.0
|
margin_top = 195.0
|
||||||
@ -664,9 +674,14 @@ margin_left = 44.0
|
|||||||
margin_top = 192.0
|
margin_top = 192.0
|
||||||
margin_right = 73.0
|
margin_right = 73.0
|
||||||
margin_bottom = 212.0
|
margin_bottom = 212.0
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Button" type="Button" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer"]
|
[node name="Button" type="Button" parent="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer"]
|
||||||
margin_top = 348.0
|
margin_top = 348.0
|
||||||
margin_right = 400.0
|
margin_right = 400.0
|
||||||
margin_bottom = 368.0
|
margin_bottom = 368.0
|
||||||
text = "Export Character To Module"
|
text = "Export Character To Module"
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[connection signal="pressed" from="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/Button" to="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SkillsVboxContainer/CenterContainer/GridContainer/SkillOptionButton" method="_on_Button_pressed"]
|
||||||
|
[connection signal="pressed" from="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/Button" to="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/Button" method="_on_Button_pressed"]
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
extends OptionButton
|
||||||
|
|
||||||
|
var json_path = "res://test_scripts/testnew.json"
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
_loadJSONToDict(json_path)
|
||||||
|
|
||||||
|
func _loadJSONToDict(filepath: String):
|
||||||
|
var file = File.new()
|
||||||
|
|
||||||
|
# Open the file for reading
|
||||||
|
var error = file.open(filepath, File.READ)
|
||||||
|
if error != OK:
|
||||||
|
print("Error opening file:", filepath)
|
||||||
|
|
||||||
|
# Read and parse the JSON content
|
||||||
|
var json_text = file.get_as_text()
|
||||||
|
file.close() # Close the file after reading
|
||||||
|
var moduleDict = parse_json(json_text)
|
||||||
|
|
||||||
|
# Check if parsing was successful
|
||||||
|
if moduleDict is Dictionary and moduleDict.size() > 0:
|
||||||
|
print(moduleDict)
|
||||||
|
var variables = moduleDict.get("items")
|
||||||
|
for variable in variables:
|
||||||
|
add_item(variable["value"])
|
||||||
|
return moduleDict
|
||||||
|
else:
|
||||||
|
print("Error parsing JSON content")
|
@ -0,0 +1,29 @@
|
|||||||
|
extends OptionButton
|
||||||
|
|
||||||
|
var json_path = "res://test_scripts/testnew.json"
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
_loadJSONToDict(json_path)
|
||||||
|
|
||||||
|
func _loadJSONToDict(filepath: String):
|
||||||
|
var file = File.new()
|
||||||
|
|
||||||
|
# Open the file for reading
|
||||||
|
var error = file.open(filepath, File.READ)
|
||||||
|
if error != OK:
|
||||||
|
print("Error opening file:", filepath)
|
||||||
|
|
||||||
|
# Read and parse the JSON content
|
||||||
|
var json_text = file.get_as_text()
|
||||||
|
file.close() # Close the file after reading
|
||||||
|
var moduleDict = parse_json(json_text)
|
||||||
|
|
||||||
|
# Check if parsing was successful
|
||||||
|
if moduleDict is Dictionary and moduleDict.size() > 0:
|
||||||
|
print(moduleDict)
|
||||||
|
var variables = moduleDict.get("items")
|
||||||
|
for variable in variables:
|
||||||
|
add_item(variable["value"])
|
||||||
|
return moduleDict
|
||||||
|
else:
|
||||||
|
print("Error parsing JSON content")
|
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"value": "item1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "item2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"variables": [
|
"items": [
|
||||||
{
|
{
|
||||||
"name": "variable1",
|
"name": "variable1",
|
||||||
"value": "value1"
|
"value": "value1"
|
||||||
|
11
Phase2/Godot_Toolset/Main/test_scripts/testnew.json
Normal file
11
Phase2/Godot_Toolset/Main/test_scripts/testnew.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"value": "item1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "item2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user