Skip to content

Improve resource dependencies & Add resource icons #2637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions addons/dialogic/Core/DialogicResourceUtil.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ static func get_unique_identifier_by_path(file_path:String) -> String:
return ""


static func get_resource_path_from_identifier(identifier:String, extension:String) -> String:
var value: Variant = get_directory(extension).get(identifier, '')
if value is String:
return value
return ""


## Returns the resource associated with the given unique identifier.
## The expected extension is needed to use the right directory.
static func get_resource_from_identifier(identifier:String, extension:String) -> Resource:
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Editor/Common/sidebar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func update_resource_list(resources_list: PackedStringArray = []) -> void:
resource_tree.clear()

var character_items: Array = get_directory_items.call(character_directory, filter, load("res://addons/dialogic/Editor/Images/Resources/character.svg"), resources_list)
var timeline_items: Array = get_directory_items.call(timeline_directory, filter, get_theme_icon("TripleBar", "EditorIcons"), resources_list)
var timeline_items: Array = get_directory_items.call(timeline_directory, filter, load("res://addons/dialogic/Editor/Images/Resources/timeline.svg"), resources_list)
var all_items := character_items + timeline_items

# BUILD TREE
Expand Down
115 changes: 115 additions & 0 deletions addons/dialogic/Editor/Images/Resources/timeline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions addons/dialogic/Editor/Images/Resources/timeline.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://j7ym07anlusi"
path="res://.godot/imported/timeline.svg-4b0b3233c6ce249f8277502cd9b13eaf.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/dialogic/Editor/Images/Resources/timeline.svg"
dest_files=["res://.godot/imported/timeline.svg-4b0b3233c6ce249f8277502cd9b13eaf.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
66 changes: 60 additions & 6 deletions addons/dialogic/Editor/Images/Toolbar/add-timeline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions addons/dialogic/Editor/Images/Toolbar/add-timeline.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ dest_files=["res://.godot/imported/add-timeline.svg-86961b528ebdf01f585931a15fea
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func _on_field_value_changed(property:String, value:Variant) -> void:


func _update_property() -> void:
field.resource_icon = get_theme_icon("TripleBar", "EditorIcons")
field.resource_icon = load("res://addons/dialogic/Editor/Images/Resources/timeline.svg")
button.icon = get_theme_icon("ExternalLink", "EditorIcons")

# Read the current value from the property.
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Audio/event_audio.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func from_text(string:String) -> void:
func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_info
"path" : {"property": "file_path", "default": "", "custom_stored":true},
"path" : {"property": "file_path", "default": "", "custom_stored":true, "ext_file":true},
"channel" : {"property": "channel_name", "default": "", "custom_stored":true},
"fade" : {"property": "fade_length", "default": 0.0},
"volume" : {"property": "volume", "default": 0.0},
Expand Down
4 changes: 2 additions & 2 deletions addons/dialogic/Modules/Background/event_background.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func get_shortcode() -> String:
func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_info
"scene" : {"property": "scene", "default": ""},
"arg" : {"property": "argument", "default": ""},
"scene" : {"property": "scene", "default": "", "ext_file":true},
"arg" : {"property": "argument", "default": "", "ext_file":true},
"fade" : {"property": "fade", "default": 0},
"transition" : {"property": "transition", "default": "",
"suggestions": get_transition_suggestions},
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Character/event_character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func get_shortcode_parameters() -> Dictionary:
{'value':Actions.JOIN},
'Leave':{'value':Actions.LEAVE},
'Update':{'value':Actions.UPDATE}}},
"character" : {"property": "character_identifier", "default": "", "custom_stored":true,},
"character" : {"property": "character_identifier", "default": "", "custom_stored":true, "ext_file":true},
"portrait" : {"property": "portrait", "default": "", "custom_stored":true,},
"transform" : {"property": "transform", "default": "center", "custom_stored":true,},

Expand Down
4 changes: 2 additions & 2 deletions addons/dialogic/Modules/Jump/event_jump.gd
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_info
"timeline" : {"property": "timeline_identifier", "default": null,
"suggestions": get_timeline_suggestions},
"suggestions": get_timeline_suggestions, "ext_file":true},
"label" : {"property": "label_name", "default": ""},
}

Expand All @@ -109,7 +109,7 @@ func build_event_editor() -> void:
'file_extension': '.dtl',
'mode' : 2,
'suggestions_func': get_timeline_suggestions,
'editor_icon' : ["TripleBar", "EditorIcons"],
'icon' : load("res://addons/dialogic/Editor/Images/Resources/timeline.svg"),
'empty_text' : '(this timeline)',
'autofocus' : true,
})
Expand Down
4 changes: 2 additions & 2 deletions addons/dialogic/Modules/Text/event_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ func is_string_full_event(string:String) -> bool:
func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_info
"character" : {"property": "character_identifier", "default": ""},
"portrait" : {"property": "portrait", "default": ""},
"character" : {"property": "character_identifier", "default": "", "ext_file":true},
"portrait" : {"property": "portrait", "default": ""},
}
#endregion

Expand Down
20 changes: 15 additions & 5 deletions addons/dialogic/Resources/CharacterResourceLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,25 @@ func _get_dependencies(path:String, _add_type:bool) -> PackedStringArray:
var depends_on: PackedStringArray = []
var character: DialogicCharacter = load(path)
for p in character.portraits.values():
if 'path' in p and p.path:
depends_on.append(p.path)
if 'scene' in p and p.scene:
depends_on.append(p.scene)
for i in p.get("export_overrides", []):
if typeof(p.export_overrides[i]) == TYPE_STRING and "://" in p.export_overrides[i]:
depends_on.append(p.export_overrides[i].trim_prefix('"').trim_suffix('"'))
return depends_on


func _rename_dependencies(path: String, renames: Dictionary) -> Error:
var character: DialogicCharacter = load(path)
for p in character.portraits:
if 'path' in character.portraits[p] and character.portraits[p].path in renames:
character.portraits[p].path = renames[character.portraits[p].path]
for p in character.portraits.values():
if 'scene' in p and p.scene in renames:
p.scene = renames[p.scene]

for i in p.get("export_overrides", []):
if typeof(p.export_overrides[i]) == TYPE_STRING and "://" in p.export_overrides[i]:
var i_path := str(p.export_overrides[i]).trim_prefix('"').trim_suffix('"')
if i_path in renames:
p.export_overrides[i] = '"'+renames[i_path]+'"'

ResourceSaver.save(character, path)
return OK
21 changes: 21 additions & 0 deletions addons/dialogic/Resources/TimelineResourceLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,24 @@ func _load(path: String, _original_path: String, _use_sub_threads: bool, _cache_
var tml := DialogicTimeline.new()
tml.from_text(file.get_as_text())
return tml


func _get_dependencies(path: String, _add_types: bool) -> PackedStringArray:
var deps := PackedStringArray()

var tml: DialogicTimeline = load(path)
tml.process()

for ev in tml.events:
deps += ev.get_dependencies()

var clean_deps := PackedStringArray()

for i in deps:
var clean := i
if clean.begins_with("res://"):
clean = ResourceUID.id_to_text(ResourceLoader.get_resource_uid(clean))
if not clean.is_empty() and not clean in clean_deps:
clean_deps.append(clean)

return clean_deps
1 change: 1 addition & 0 deletions addons/dialogic/Resources/character.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@tool
@icon("uid://bbea0efx0ybu7")
extends "res://addons/dialogic/Resources/dialogic_identifiable_resource.gd"
class_name DialogicCharacter

Expand Down
Loading