Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions addons/storyquest_bootstrap/copier.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const QUEST_FILENAME := "quest.tres"
## Map from UID to already-copied resource
var orig_uid_to_copy: Dictionary[String, Resource]

## Root directory of instantiated SQ
## Name of root directory of quest, e.g. [code]"stella"[/code]
var quest_name: String

## Root directory of copied StoryQuest,
## i.e. [code]STORYQUESTS_PATH.path_join(quest_name)[/code]
var target_path: String

var _title: String
Expand All @@ -22,6 +26,7 @@ var _depth: int = 0


func _init(filename: String, title: String, description: String) -> void:
quest_name = filename
target_path = STORYQUESTS_PATH.path_join(filename)
self._title = title
self._description = description
Expand Down Expand Up @@ -160,8 +165,12 @@ func copy(uid: String, resource: Resource) -> Resource:
return orig_uid_to_copy[uid]

var subpath := resource.resource_path.right(-TEMPLATE_PATH.length())
subpath = subpath.replace(TEMPLATE_PREFIX + "_", "")
var copy_path := target_path.path_join(subpath)
var subdir := subpath.get_base_dir()
var filename := subpath.get_file()

subdir = subdir.replace(TEMPLATE_PREFIX + "_", "")
filename = filename.replace(TEMPLATE_PREFIX, quest_name)
var copy_path := target_path.path_join(subdir).path_join(filename)

_debug(["Copying", uid, resource.resource_path, "to", copy_path])
_depth += 1
Expand Down
49 changes: 35 additions & 14 deletions addons/storyquest_bootstrap/new_storyquest_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ signal cancel
var _title: String
var _description: String
var _filename: String
var _invalid_char_regex: RegEx

@onready var create_button: Button = %CreateButton
@onready var panel: Panel = %Panel
@onready var title_edit: LineEdit = %TitleEdit
@onready var folder_edit: LineEdit = %FolderEdit
@onready var full_path_label: Label = %FullPathLabel
@onready var errors_label: RichTextLabel = %ErrorsLabel
@onready var folder_res_label: Label = %FolderResLabel
@onready var description_edit: TextEdit = %DescriptionEdit
@onready var progress_bar: ProgressBar = %ProgressBar

Expand All @@ -32,6 +34,10 @@ func _ready() -> void:
"default_color", get_theme_color("warning_color", "Editor")
)

_invalid_char_regex = RegEx.new()
var error := _invalid_char_regex.compile("\\W+", true)
assert(error == OK, error_string(error))


func _on_create_button_pressed() -> void:
title_edit.editable = false
Expand All @@ -56,30 +62,45 @@ func _make_filename(title: String) -> String:
#
# TODO: Replace e.g. ö with oe, ß with ss, ı with i, ñ with n, etc.
# TODO: Transliterate non-Latin scripts
var regex := RegEx.new()
var error := regex.compile("\\W+", true)
assert(error == OK, error_string(error))
var subbed := regex.sub(snaked, "_", true)
var subbed := _invalid_char_regex.sub(snaked, "_", true)

# Now remove leading or trailing underscores. This may
# Now remove leading or trailing underscores. This may mean the resulting
# filename is empty.
var stripped := subbed.lstrip("_").rstrip("_")

return stripped
# Limit the generated filename to a reasonable length.
return stripped.left(folder_edit.max_length)


func _on_title_edit_text_changed(new_text: String) -> void:
_title = new_text
_filename = _make_filename(_title)
folder_edit.text = _make_filename(_title)
_on_folder_edit_text_changed(folder_edit.text)


func _on_folder_edit_text_changed(new_text: String) -> void:
_filename = new_text
full_path_label.text = storyquests_path.path_join(_filename)
_revalidate()


func _on_description_edit_text_changed() -> void:
_description = description_edit.text


func _revalidate() -> void:
var errors: PackedStringArray

errors.append_array(validate_title.call(_title))

var matches := _invalid_char_regex.search_all(_filename)
if matches:
for match: RegExMatch in matches:
errors.append("⚠ ‘%s’ is not allowed in the folder name" % match.get_string(0))
if _filename.to_lower() != _filename:
errors.append("⚠ Folder name must be lower-case")
if _title:
errors.append_array(validate_filename.call(_filename))

create_button.disabled = errors.size()
folder_res_label.text = storyquests_path.path_join(_filename)
errors_label.text = "\n".join(errors)


func _on_description_edit_text_changed() -> void:
_description = description_edit.text
create_button.disabled = errors.size() > 0
16 changes: 15 additions & 1 deletion addons/storyquest_bootstrap/new_storyquest_dialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
bg_color = Color(0, 0, 0, 1)

[node name="StoryQuestDialogue" type="Window"]
oversampling_override = 1.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - but Godot really really wants to set this whenever I open and save the scene.

title = "Create StoryQuest"
initial_position = 1
size = Vector2i(600, 400)
Expand Down Expand Up @@ -55,7 +56,19 @@ placeholder_text = "My Quest"
layout_mode = 2
text = "Folder Name:"

[node name="FolderResLabel" type="Label" parent="PanelContainer/VBoxContainer/GridContainer"]
[node name="FolderEdit" type="LineEdit" parent="PanelContainer/VBoxContainer/GridContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
placeholder_text = "My Quest"
max_length = 20
emoji_menu_enabled = false

[node name="FullPathLabelLabel" type="Label" parent="PanelContainer/VBoxContainer/GridContainer"]
layout_mode = 2
text = "Full Path:"

[node name="FullPathLabel" type="Label" parent="PanelContainer/VBoxContainer/GridContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
Expand Down Expand Up @@ -99,5 +112,6 @@ text = "Create"

[connection signal="close_requested" from="." to="." method="_on_close_requested"]
[connection signal="text_changed" from="PanelContainer/VBoxContainer/GridContainer/TitleEdit" to="." method="_on_title_edit_text_changed"]
[connection signal="text_changed" from="PanelContainer/VBoxContainer/GridContainer/FolderEdit" to="." method="_on_folder_edit_text_changed"]
[connection signal="text_changed" from="PanelContainer/VBoxContainer/DescriptionEdit" to="." method="_on_description_edit_text_changed"]
[connection signal="pressed" from="PanelContainer/VBoxContainer/MarginContainer/CreateButton" to="." method="_on_create_button_pressed"]