Fix: Wizard - verify that inventory items are written to valid folders

This commit is contained in:
Balloonpopper
2022-11-27 00:01:51 +11:00
parent 0377cabce9
commit 36c199a5f5
5 changed files with 92 additions and 40 deletions

View File

@@ -218,7 +218,7 @@ margin_top = 56.0
margin_right = 295.0 margin_right = 295.0
margin_bottom = 80.0 margin_bottom = 80.0
rect_min_size = Vector2( 200, 0 ) rect_min_size = Vector2( 200, 0 )
hint_tooltip = "The global id for the character to be used in ESC scripts." hint_tooltip = "The directory on disk where the character scene will be saved."
text = "res://game/characters" text = "res://game/characters"
editable = false editable = false
caret_blink = true caret_blink = true
@@ -1219,7 +1219,6 @@ window_title = "Open a Directory"
mode = 2 mode = 2
[node name="InformationWindows" type="Control" parent="."] [node name="InformationWindows" type="Control" parent="."]
visible = false
margin_left = 50.0 margin_left = 50.0
margin_top = 50.0 margin_top = 50.0
margin_right = 1240.0 margin_right = 1240.0
@@ -1317,7 +1316,6 @@ popup_exclusive = true
dialog_text = "Please load a spritesheet to begin." dialog_text = "Please load a spritesheet to begin."
[node name="export_progress" type="WindowDialog" parent="InformationWindows"] [node name="export_progress" type="WindowDialog" parent="InformationWindows"]
visible = true
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
@@ -1372,8 +1370,10 @@ or below their feet.
* The CollisionShape child node defines the bounds of the character. You may * The CollisionShape child node defines the bounds of the character. You may
want to resize or change the shape assigned to this node. want to resize or change the shape assigned to this node.
* You may want to shift this node to a different directory in your codebase * You should move the character's sprite and collision shape down so the
(e.g. into a \"characters\" folder) to group it with other game characters." crosshairs are directly between their feet. This ensures that where you click
lines up with where the character walks to.
"
[node name="help_window" parent="InformationWindows" instance=ExtResource( 38 )] [node name="help_window" parent="InformationWindows" instance=ExtResource( 38 )]

View File

@@ -91,11 +91,13 @@ uppercase = true
[node name="Description" type="MarginContainer" parent="VBoxContainer"] [node name="Description" type="MarginContainer" parent="VBoxContainer"]
margin_top = 116.0 margin_top = 116.0
margin_right = 500.0 margin_right = 500.0
margin_bottom = 232.0 margin_bottom = 249.0
[node name="ObjectDescription" type="Label" parent="VBoxContainer/Description"] [node name="ObjectDescription" type="Label" parent="VBoxContainer/Description"]
visible = false
margin_top = 8.0
margin_right = 500.0 margin_right = 500.0
margin_bottom = 116.0 margin_bottom = 124.0
text = "The object creator is used to create background objects text = "The object creator is used to create background objects
that the player can interact with, but that will not become that the player can interact with, but that will not become
part of their inventory. part of their inventory.
@@ -106,22 +108,22 @@ is currently selected in the scene tree.
align = 1 align = 1
[node name="InventoryDescription" type="Label" parent="VBoxContainer/Description"] [node name="InventoryDescription" type="Label" parent="VBoxContainer/Description"]
visible = false
margin_right = 500.0 margin_right = 500.0
margin_bottom = 116.0 margin_bottom = 133.0
text = "The inventory item creator is used to create objects text = "The inventory item creator is used to create objects
that the player can pick up to add that the player can pick up to add
to their inventory. to their inventory.
NOTE: The node will be created in the inventory folder shown NOTE: The node will be created in the inventory
below. You can change this in Godot's settings under: folder shown below. All inventory items for your
\"Escoria/UI/Items autoregister path\"" game must live in the same folder.
"
align = 1 align = 1
[node name="Content" type="MarginContainer" parent="VBoxContainer"] [node name="Content" type="MarginContainer" parent="VBoxContainer"]
margin_top = 236.0 margin_top = 253.0
margin_right = 500.0 margin_right = 500.0
margin_bottom = 736.0 margin_bottom = 753.0
rect_min_size = Vector2( 0, 500 ) rect_min_size = Vector2( 0, 500 )
mouse_filter = 1 mouse_filter = 1
custom_constants/margin_right = 20 custom_constants/margin_right = 20
@@ -307,30 +309,36 @@ margin_bottom = 405.0
[node name="InventoryPathLabel" type="Label" parent="VBoxContainer/Content/GridContainer"] [node name="InventoryPathLabel" type="Label" parent="VBoxContainer/Content/GridContainer"]
visible = false visible = false
margin_top = 409.0 margin_top = 412.0
margin_right = 110.0 margin_right = 110.0
margin_bottom = 423.0 margin_bottom = 426.0
text = "Inventory path:" text = "Inventory path:"
[node name="InventoryPath" type="Label" parent="VBoxContainer/Content/GridContainer"] [node name="InventoryPath" type="Label" parent="VBoxContainer/Content/GridContainer"]
visible = false visible = false
margin_left = 114.0 margin_left = 114.0
margin_top = 409.0 margin_top = 412.0
margin_right = 354.0 margin_right = 354.0
margin_bottom = 423.0 margin_bottom = 426.0
text = "res://" text = "res://"
[node name="ChangePathButton" type="Button" parent="VBoxContainer/Content/GridContainer"]
visible = false
margin_top = 409.0
margin_right = 110.0
margin_bottom = 429.0
text = "Change Path"
[node name="BlankItem7" type="Control" parent="VBoxContainer/Content/GridContainer"] [node name="BlankItem7" type="Control" parent="VBoxContainer/Content/GridContainer"]
visible = false visible = false
margin_left = 114.0
margin_top = 409.0 margin_top = 409.0
margin_right = 354.0 margin_right = 110.0
margin_bottom = 423.0 margin_bottom = 409.0
[node name="Buttons" type="MarginContainer" parent="VBoxContainer"] [node name="Buttons" type="MarginContainer" parent="VBoxContainer"]
margin_top = 740.0 margin_top = 757.0
margin_right = 500.0 margin_right = 500.0
margin_bottom = 770.0 margin_bottom = 787.0
mouse_filter = 2 mouse_filter = 2
custom_constants/margin_bottom = 10 custom_constants/margin_bottom = 10
@@ -415,6 +423,16 @@ margin_top = 371.0
margin_right = 291.0 margin_right = 291.0
margin_bottom = 429.0 margin_bottom = 429.0
[node name="FileDialog" type="FileDialog" parent="Windows"]
visible = true
margin_left = 50.0
margin_top = 150.0
margin_right = 450.0
margin_bottom = 650.0
rect_min_size = Vector2( 400, 500 )
window_title = "Open a Directory"
mode = 2
[connection signal="toggled" from="VBoxContainer/Control/CenterContainer/HBoxContainer/BackgroundObjectCheckBox" to="." method="_on_BackgroundObjectCheckBox_toggled"] [connection signal="toggled" from="VBoxContainer/Control/CenterContainer/HBoxContainer/BackgroundObjectCheckBox" to="." method="_on_BackgroundObjectCheckBox_toggled"]
[connection signal="toggled" from="VBoxContainer/Control/CenterContainer/HBoxContainer/InventoryItemCheckBox" to="." method="_on_InventoryItemCheckBox_toggled"] [connection signal="toggled" from="VBoxContainer/Control/CenterContainer/HBoxContainer/InventoryItemCheckBox" to="." method="_on_InventoryItemCheckBox_toggled"]
[connection signal="text_changed" from="VBoxContainer/Content/GridContainer/ItemName" to="." method="background_on_ItemName_text_changed"] [connection signal="text_changed" from="VBoxContainer/Content/GridContainer/ItemName" to="." method="background_on_ItemName_text_changed"]
@@ -422,9 +440,11 @@ margin_bottom = 429.0
[connection signal="pressed" from="VBoxContainer/Content/GridContainer/StartsInteractiveCheckBox" to="." method="_on_StartsInteractiveCheckBox_pressed"] [connection signal="pressed" from="VBoxContainer/Content/GridContainer/StartsInteractiveCheckBox" to="." method="_on_StartsInteractiveCheckBox_pressed"]
[connection signal="item_selected" from="VBoxContainer/Content/GridContainer/DefaultActionOption" to="." method="_on_DefaultActionOption_item_selected"] [connection signal="item_selected" from="VBoxContainer/Content/GridContainer/DefaultActionOption" to="." method="_on_DefaultActionOption_item_selected"]
[connection signal="pressed" from="VBoxContainer/Content/GridContainer/ChangeImageButton" to="." method="load_button_pressed"] [connection signal="pressed" from="VBoxContainer/Content/GridContainer/ChangeImageButton" to="." method="load_button_pressed"]
[connection signal="pressed" from="VBoxContainer/Content/GridContainer/ChangePathButton" to="." method="_on_ChangePathButton_pressed"]
[connection signal="pressed" from="VBoxContainer/Buttons/CenterContainer/HBoxContainer/CreateButton" to="." method="_on_CreateButton_pressed"] [connection signal="pressed" from="VBoxContainer/Buttons/CenterContainer/HBoxContainer/CreateButton" to="." method="_on_CreateButton_pressed"]
[connection signal="pressed" from="VBoxContainer/Buttons/CenterContainer/HBoxContainer/ClearButton" to="." method="Item_on_ClearButton_pressed"] [connection signal="pressed" from="VBoxContainer/Buttons/CenterContainer/HBoxContainer/ClearButton" to="." method="Item_on_ClearButton_pressed"]
[connection signal="pressed" from="VBoxContainer/Buttons/CenterContainer/HBoxContainer/ExitButton" to="." method="Item_on_ExitButton_pressed"] [connection signal="pressed" from="VBoxContainer/Buttons/CenterContainer/HBoxContainer/ExitButton" to="." method="Item_on_ExitButton_pressed"]
[connection signal="file_selected" from="LoadObjectGraphic/LoadObjectFileDialog" to="." method="LoadObjectFileDialog_file_selected"] [connection signal="file_selected" from="LoadObjectGraphic/LoadObjectFileDialog" to="." method="LoadObjectFileDialog_file_selected"]
[connection signal="confirmed" from="Windows/ConfirmationDialog" to="." method="_on_ObjectConfirmationDialog_confirmed"] [connection signal="confirmed" from="Windows/ConfirmationDialog" to="." method="_on_ObjectConfirmationDialog_confirmed"]
[connection signal="confirmed" from="Windows/CreateCompleteDialog" to="." method="_on_CreateCompleteDialog_confirmed"] [connection signal="confirmed" from="Windows/CreateCompleteDialog" to="." method="_on_CreateCompleteDialog_confirmed"]
[connection signal="dir_selected" from="Windows/FileDialog" to="." method="_on_FileDialog_dir_selected"]

View File

@@ -209,6 +209,11 @@ func _on_ChangeRoomFolderButton_pressed() -> void:
func _on_RoomFolderDialog_dir_selected(dir: String) -> void: func _on_RoomFolderDialog_dir_selected(dir: String) -> void:
ProjectSettings.set_setting(ROOM_PATH_SETTING, dir) ProjectSettings.set_setting(ROOM_PATH_SETTING, dir)
var property_info = {
"name": ROOM_PATH_SETTING,
"type": TYPE_STRING
}
ProjectSettings.add_property_info(property_info)
get_node(ROOM_FOLDER_PATH).text = dir get_node(ROOM_FOLDER_PATH).text = dir

View File

@@ -41,5 +41,3 @@ func CharacterCreator_pressed() -> void:
func InventoryItem_pressed() -> void: func InventoryItem_pressed() -> void:
$Menu.visible = false $Menu.visible = false
$ItemCreator.visible = true $ItemCreator.visible = true
$ItemCreator.inventory_mode = false
$ItemCreator.item_creator_reset()

View File

@@ -22,7 +22,8 @@ const CREATE_BUTTON_NODE = "VBoxContainer/Buttons/CenterContainer/HBoxContainer
const ERROR_WINDOW_NODE = "Windows/ErrorDialog" const ERROR_WINDOW_NODE = "Windows/ErrorDialog"
const INVENTORY_PREV_NODE = "VBoxContainer/Content/GridContainer/Preview/InventoryPreview" const INVENTORY_PREV_NODE = "VBoxContainer/Content/GridContainer/Preview/InventoryPreview"
const OBJECT_PREV_NODE = "VBoxContainer/Content/GridContainer/Preview/ObjectPreview" const OBJECT_PREV_NODE = "VBoxContainer/Content/GridContainer/Preview/ObjectPreview"
const BACKGROUND_OBJ_NODE = "VBoxContainer/Control/CenterContainer/HBoxContainer/BackgroundObjectCheckBox"
const CHANGE_PATH_NODE = "VBoxContainer/Content/GridContainer/ChangePathButton"
var source_image:Image var source_image:Image
var image_stream_texture:StreamTexture var image_stream_texture:StreamTexture
@@ -39,7 +40,7 @@ func _ready() -> void:
# Capture the size of the window before we update its contents so we have # Capture the size of the window before we update its contents so we have
# the absolute size before it gets scaled contents applied to it # the absolute size before it gets scaled contents applied to it
preview_size = get_node(PREVIEW_NODE).rect_size preview_size = get_node(PREVIEW_NODE).rect_size
inventory_mode = false inventory_mode = not get_node(BACKGROUND_OBJ_NODE).pressed
item_creator_reset() item_creator_reset()
@@ -68,13 +69,15 @@ func item_creator_reset() -> void:
get_node(INVENTORY_PREV_NODE).visible = true get_node(INVENTORY_PREV_NODE).visible = true
get_node(OBJECT_PREV_NODE).visible = false get_node(OBJECT_PREV_NODE).visible = false
for loop in [INVENTORY_PATH_NODE, INVENTORY_PATH_LABEL_NODE, INVENTORY_PATH_SPACER_NODE]: for loop in [INVENTORY_PATH_NODE, INVENTORY_PATH_LABEL_NODE, INVENTORY_PATH_SPACER_NODE, \
CHANGE_PATH_NODE]:
get_node(loop).visible = true get_node(loop).visible = true
else: else:
get_node(CREATE_BUTTON_NODE).text = "Create Object" get_node(CREATE_BUTTON_NODE).text = "Create Object"
get_node(INVENTORY_PREV_NODE).visible = false get_node(INVENTORY_PREV_NODE).visible = false
get_node(OBJECT_PREV_NODE).visible = true get_node(OBJECT_PREV_NODE).visible = true
for loop in [INVENTORY_PATH_NODE, INVENTORY_PATH_LABEL_NODE, INVENTORY_PATH_SPACER_NODE]: for loop in [INVENTORY_PATH_NODE, INVENTORY_PATH_LABEL_NODE, INVENTORY_PATH_SPACER_NODE, \
CHANGE_PATH_NODE]:
get_node(loop).visible = false get_node(loop).visible = false
for loop in [OBJECT_HEADING_NODE, OBJECT_DESC_NODE]: for loop in [OBJECT_HEADING_NODE, OBJECT_DESC_NODE]:
@@ -82,7 +85,7 @@ func item_creator_reset() -> void:
for loop in [INVENTORY_HEADING_NODE, INVENTORY_DESC_NODE, INVENTORY_PATH_NODE]: for loop in [INVENTORY_HEADING_NODE, INVENTORY_DESC_NODE, INVENTORY_PATH_NODE]:
get_node(loop).visible = inventory_mode get_node(loop).visible = inventory_mode
$Windows/FileDialog.current_dir = ProjectSettings.get_setting("escoria/ui/inventory_items_path")
func resize_image() -> void: func resize_image() -> void:
# Calculate the scale to make the preview as big as possible in the preview window depending on # Calculate the scale to make the preview as big as possible in the preview window depending on
@@ -123,6 +126,14 @@ func LoadObjectFileDialog_file_selected(path: String) -> void:
func _on_CreateButton_pressed() -> void: func _on_CreateButton_pressed() -> void:
var inventory_path = ProjectSettings.get_setting("escoria/ui/inventory_items_path")
var directory_test = Directory.new();
if not directory_test.dir_exists(inventory_path):
get_node(ERROR_WINDOW_NODE).dialog_text = \
"Folder %s does not exist. Please create or change the destination" % inventory_path
get_node(ERROR_WINDOW_NODE).popup_centered()
return
if not image_has_been_loaded: if not image_has_been_loaded:
get_node(ERROR_WINDOW_NODE).dialog_text = \ get_node(ERROR_WINDOW_NODE).dialog_text = \
"No image has been loaded." "No image has been loaded."
@@ -201,19 +212,23 @@ func _on_CreateButton_pressed() -> void:
var packed_scene = PackedScene.new() var packed_scene = PackedScene.new()
packed_scene.pack(get_tree().edited_scene_root.get_node(item.name)) packed_scene.pack(get_tree().edited_scene_root.get_node(item.name))
var inventory_path = ProjectSettings.get_setting("escoria/ui/inventory_items_path")
ResourceSaver.save("%s/%s.tscn" % [inventory_path, get_node(ITEM_NAME_NODE).text], packed_scene)
# Flag suggestions from https://godotengine.org/qa/50437/how-to-turn-a-node-into-a-packedscene-via-gdscript # Flag suggestions from https://godotengine.org/qa/50437/how-to-turn-a-node-into-a-packedscene-via-gdscript
ResourceSaver.save("%s/%s.tscn" % [inventory_path, get_node(ITEM_NAME_NODE).text], packed_scene, \ var err = ResourceSaver.save("%s/%s.tscn" % [inventory_path, get_node(ITEM_NAME_NODE).text], packed_scene, \
ResourceSaver.FLAG_CHANGE_PATH|ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS) ResourceSaver.FLAG_CHANGE_PATH|ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS)
if err:
item.queue_free() get_node(ERROR_WINDOW_NODE).dialog_text = \
get_tree().edited_scene_root.get_node(item.name).queue_free() "Failed to save the item. Please make sure you can\n" + \
get_node("Windows/CreateCompleteDialog").dialog_text = \ "write to the destination folder" % inventory_path
"Inventory item %s/%s.tscn created." % [inventory_path, get_node(ITEM_NAME_NODE).text] get_node(ERROR_WINDOW_NODE).popup_centered()
print("Inventory item %s/%s.tscn created." % [inventory_path, get_node(ITEM_NAME_NODE).text]) return
get_node("Windows/CreateCompleteDialog").popup_centered() else:
item.queue_free()
get_tree().edited_scene_root.get_node(item.name).queue_free()
get_node("Windows/CreateCompleteDialog").dialog_text = \
"Inventory item %s/%s.tscn created." % [inventory_path, get_node(ITEM_NAME_NODE).text]
print("Inventory item %s/%s.tscn created." % [inventory_path, get_node(ITEM_NAME_NODE).text])
get_node("Windows/CreateCompleteDialog").popup_centered()
func Item_on_ClearButton_pressed() -> void: func Item_on_ClearButton_pressed() -> void:
@@ -282,3 +297,17 @@ func _on_InventoryItemCheckBox_toggled(button_pressed: bool) -> void:
inventory_mode = true inventory_mode = true
item_creator_reset() item_creator_reset()
func _on_ChangePathButton_pressed():
$"Windows/FileDialog".popup_centered()
func _on_FileDialog_dir_selected(dir: String) -> void:
ProjectSettings.set_setting("escoria/ui/inventory_items_path", dir)
var property_info = {
"name": "escoria/ui/inventory_items_path",
"type": TYPE_STRING
}
ProjectSettings.add_property_info(property_info)
get_node(INVENTORY_PATH_NODE).text = dir