Skip to content
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

Unique numeric ID for DialogicCharacter resources #2314

Open
juliohq opened this issue Jun 26, 2024 · 5 comments
Open

Unique numeric ID for DialogicCharacter resources #2314

juliohq opened this issue Jun 26, 2024 · 5 comments

Comments

@juliohq
Copy link
Contributor

juliohq commented Jun 26, 2024

Is your feature request related to a problem? Please describe.
I'm working on a project where I have custom resources for characters (a set of .tres files where each one has a unique numeric ID for referring to them) and a Dialogic character resource for each (.dch files from the DialogicCharacter class).

It would be interesting to get my custom character resources from the Dialogic character resources. I could, for example, store all my character resources into a dictionary with their IDs as the keys and then I could do something like that:

Dialogic.get_subsystem("Text").speaker_updated.connect(_speaker_updated)


func _speaker_updated(character: DialogicCharacter) -> void:
        var my_character: Character = characters.get(character.id)

Describe the solution you'd like
Export an id property for the Dialogic Character resource and add some validation to make sure they're unique.

Describe alternatives you've considered
I could use the DialogicCharacter resource UUID somehow, though I found it not to be very reliable.

Additional context
N/A

@Jowan-Spooner
Copy link
Collaborator

yeah unfortunately I don't think UUID's are quite there yet.

I'm wondering why this cannot be achieved relatively easily with the unique identifiers strings we have right now. Each character is assigned a unique name anyways (see the Reference Manager), could you potentially use that in your character system? character.get_character_name() would be the easiest way to get the unique identifier (in alpha 15 WIP).

Alternatively the translation id (of which each character get's one) is also unique, though it only works with translations enabled so it's not as useful I think.

Just trying to think whether adding another unique identifier is necessary. Ensuring something is unique across a project isn't super simple.

@juliohq
Copy link
Contributor Author

juliohq commented Jun 27, 2024

I could workaround it using a dictionary that maps DialogicCharacter to my custom Character resources though I think it would be really nice if I could add arbitrary data to DialogicCharacter resources myself, I tried using metadata but for some reason they don't get saved to the .tres file, maybe Dialogic is doing something I'm not aware of?

@Jowan-Spooner
Copy link
Collaborator

Arbitrary data should be saved to the character.custom_info dictionary. Dialogic uses it for some stuff, but you should be able to add stuff to it as well. An extension could even expose a field to the character editor if it's really necessary to edit this in the UI.

@juliohq
Copy link
Contributor Author

juliohq commented Jun 27, 2024

An extension could even expose a field to the character editor if it's really necessary to edit this in the UI.

Is there any tutorial/guide that explains exactly how to do that or do I need to do what is explained here?

@Jowan-Spooner
Copy link
Collaborator

Is there any tutorial/guide that explains exactly how to do that or do I need to do what is explained here?

No unfortunately there aren't any docs on how to do this. But you can look at the Styles module which adds a section to the character editor and stores it's data in the custom_info of the character. The main things are:

  • creat a scene that extends DialogicCharacterEditorMainSection
    Could have a script like this:
@tool
extends DialogicCharacterEditorMainSection

## Character editor tab that allows setting a custom style fot the character.

func _init() -> void:
	hint_text = 'This is a custom ID that I use to get this character.'

func _get_title() -> String:
	return "Custom ID"


func _load_character(character:DialogicCharacter) -> void:
	%LineEdit.text = str(character.custom_info.get('id', ''))


func _save_changes(character:DialogicCharacter) -> DialogicCharacter:
	character.custom_info['id'] = %LineEdit.text
	return character

  • have an indexer that lists that scene:
@tool
extends DialogicIndexer

func _get_character_editor_sections() -> Array:
	return [this_folder.path_join('character_settings_scene.tscn')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants