2023-07-27 11:39:38 -07:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
|
|
|
const USER_CONFIG_PATH = "user://dialogue_manager_user_config.json"
|
|
|
|
const CACHE_PATH = "user://dialogue_manager_cache.json"
|
|
|
|
|
|
|
|
# Token types
|
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
const TOKEN_FUNCTION = &"function"
|
|
|
|
const TOKEN_DICTIONARY_REFERENCE = &"dictionary_reference"
|
|
|
|
const TOKEN_DICTIONARY_NESTED_REFERENCE = &"dictionary_nested_reference"
|
|
|
|
const TOKEN_GROUP = &"group"
|
|
|
|
const TOKEN_ARRAY = &"array"
|
|
|
|
const TOKEN_DICTIONARY = &"dictionary"
|
|
|
|
const TOKEN_PARENS_OPEN = &"parens_open"
|
|
|
|
const TOKEN_PARENS_CLOSE = &"parens_close"
|
|
|
|
const TOKEN_BRACKET_OPEN = &"bracket_open"
|
|
|
|
const TOKEN_BRACKET_CLOSE = &"bracket_close"
|
|
|
|
const TOKEN_BRACE_OPEN = &"brace_open"
|
|
|
|
const TOKEN_BRACE_CLOSE = &"brace_close"
|
|
|
|
const TOKEN_COLON = &"colon"
|
|
|
|
const TOKEN_COMPARISON = &"comparison"
|
|
|
|
const TOKEN_ASSIGNMENT = &"assignment"
|
|
|
|
const TOKEN_OPERATOR = &"operator"
|
|
|
|
const TOKEN_COMMA = &"comma"
|
|
|
|
const TOKEN_DOT = &"dot"
|
|
|
|
const TOKEN_CONDITION = &"condition"
|
|
|
|
const TOKEN_BOOL = &"bool"
|
|
|
|
const TOKEN_NOT = &"not"
|
|
|
|
const TOKEN_AND_OR = &"and_or"
|
|
|
|
const TOKEN_STRING = &"string"
|
|
|
|
const TOKEN_NUMBER = &"number"
|
|
|
|
const TOKEN_VARIABLE = &"variable"
|
|
|
|
const TOKEN_COMMENT = &"comment"
|
|
|
|
|
|
|
|
const TOKEN_ERROR = &"error"
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
# Line types
|
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
const TYPE_UNKNOWN = &"unknown"
|
|
|
|
const TYPE_RESPONSE = &"response"
|
|
|
|
const TYPE_TITLE = &"title"
|
|
|
|
const TYPE_CONDITION = &"condition"
|
|
|
|
const TYPE_MUTATION = &"mutation"
|
|
|
|
const TYPE_GOTO = &"goto"
|
|
|
|
const TYPE_DIALOGUE = &"dialogue"
|
|
|
|
const TYPE_ERROR = &"error"
|
2023-07-27 11:39:38 -07:00
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
const TYPE_ELSE = &"else"
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
# Line IDs
|
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
const ID_NULL = &""
|
|
|
|
const ID_ERROR = &"error"
|
|
|
|
const ID_ERROR_INVALID_TITLE = &"invalid title"
|
|
|
|
const ID_ERROR_TITLE_HAS_NO_BODY = &"title has no body"
|
|
|
|
const ID_END = &"end"
|
|
|
|
const ID_END_CONVERSATION = &"end!"
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
# Errors
|
|
|
|
|
|
|
|
const ERR_ERRORS_IN_IMPORTED_FILE = 100
|
|
|
|
const ERR_FILE_ALREADY_IMPORTED = 101
|
|
|
|
const ERR_DUPLICATE_IMPORT_NAME = 102
|
|
|
|
const ERR_EMPTY_TITLE = 103
|
|
|
|
const ERR_DUPLICATE_TITLE = 104
|
|
|
|
const ERR_NESTED_TITLE = 105
|
|
|
|
const ERR_TITLE_INVALID_CHARACTERS = 106
|
|
|
|
const ERR_UNKNOWN_TITLE = 107
|
|
|
|
const ERR_INVALID_TITLE_REFERENCE = 108
|
|
|
|
const ERR_TITLE_REFERENCE_HAS_NO_CONTENT = 109
|
|
|
|
const ERR_INVALID_EXPRESSION = 110
|
|
|
|
const ERR_UNEXPECTED_CONDITION = 111
|
|
|
|
const ERR_DUPLICATE_ID = 112
|
|
|
|
const ERR_MISSING_ID = 113
|
|
|
|
const ERR_INVALID_INDENTATION = 114
|
|
|
|
const ERR_INVALID_CONDITION_INDENTATION = 115
|
|
|
|
const ERR_INCOMPLETE_EXPRESSION = 116
|
|
|
|
const ERR_INVALID_EXPRESSION_FOR_VALUE = 117
|
|
|
|
const ERR_UNKNOWN_LINE_SYNTAX = 118
|
|
|
|
const ERR_TITLE_BEGINS_WITH_NUMBER = 119
|
|
|
|
const ERR_UNEXPECTED_END_OF_EXPRESSION = 120
|
|
|
|
const ERR_UNEXPECTED_FUNCTION = 121
|
|
|
|
const ERR_UNEXPECTED_BRACKET = 122
|
|
|
|
const ERR_UNEXPECTED_CLOSING_BRACKET = 123
|
|
|
|
const ERR_MISSING_CLOSING_BRACKET = 124
|
|
|
|
const ERR_UNEXPECTED_OPERATOR = 125
|
|
|
|
const ERR_UNEXPECTED_COMMA = 126
|
|
|
|
const ERR_UNEXPECTED_COLON = 127
|
|
|
|
const ERR_UNEXPECTED_DOT = 128
|
|
|
|
const ERR_UNEXPECTED_BOOLEAN = 129
|
|
|
|
const ERR_UNEXPECTED_STRING = 130
|
|
|
|
const ERR_UNEXPECTED_NUMBER = 131
|
|
|
|
const ERR_UNEXPECTED_VARIABLE = 132
|
|
|
|
const ERR_INVALID_INDEX = 133
|
|
|
|
const ERR_UNEXPECTED_ASSIGNMENT = 134
|
2024-04-08 14:42:12 -07:00
|
|
|
const ERR_UNKNOWN_USING = 135
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
## Get the error message
|
|
|
|
static func get_error_message(error: int) -> String:
|
|
|
|
match error:
|
|
|
|
ERR_ERRORS_IN_IMPORTED_FILE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.import_errors")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_FILE_ALREADY_IMPORTED:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.already_imported")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_DUPLICATE_IMPORT_NAME:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.duplicate_import")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_EMPTY_TITLE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.empty_title")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_DUPLICATE_TITLE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.duplicate_title")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_NESTED_TITLE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.nested_title")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_TITLE_INVALID_CHARACTERS:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.invalid_title_string")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_TITLE_BEGINS_WITH_NUMBER:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.invalid_title_number")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNKNOWN_TITLE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unknown_title")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_INVALID_TITLE_REFERENCE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.jump_to_invalid_title")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_TITLE_REFERENCE_HAS_NO_CONTENT:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.title_has_no_content")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_INVALID_EXPRESSION:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.invalid_expression")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_CONDITION:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_condition")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_DUPLICATE_ID:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.duplicate_id")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_MISSING_ID:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.missing_id")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_INVALID_INDENTATION:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.invalid_indentation")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_INVALID_CONDITION_INDENTATION:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.condition_has_no_content")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_INCOMPLETE_EXPRESSION:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.incomplete_expression")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_INVALID_EXPRESSION_FOR_VALUE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.invalid_expression_for_value")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_FILE_NOT_FOUND:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.file_not_found")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_END_OF_EXPRESSION:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_end_of_expression")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_FUNCTION:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_function")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_BRACKET:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_bracket")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_CLOSING_BRACKET:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_closing_bracket")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_MISSING_CLOSING_BRACKET:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.missing_closing_bracket")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_OPERATOR:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_operator")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_COMMA:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_comma")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_COLON:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_colon")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_DOT:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_dot")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_BOOLEAN:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_boolean")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_STRING:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_string")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_NUMBER:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_number")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_VARIABLE:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_variable")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_INVALID_INDEX:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.invalid_index")
|
2023-07-27 11:39:38 -07:00
|
|
|
ERR_UNEXPECTED_ASSIGNMENT:
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unexpected_assignment")
|
|
|
|
ERR_UNKNOWN_USING:
|
|
|
|
return translate(&"errors.unknown_using")
|
2023-07-27 11:39:38 -07:00
|
|
|
|
2024-04-08 14:42:12 -07:00
|
|
|
return translate(&"errors.unknown")
|
2023-07-27 11:39:38 -07:00
|
|
|
|
|
|
|
|
|
|
|
static func translate(string: String) -> String:
|
2024-04-08 14:42:12 -07:00
|
|
|
var base_path = new().get_script().resource_path.get_base_dir()
|
|
|
|
|
|
|
|
var language: String = TranslationServer.get_tool_locale()
|
|
|
|
var translations_path: String = "%s/l10n/%s.po" % [base_path, language]
|
|
|
|
var fallback_translations_path: String = "%s/l10n/%s.po" % [base_path, TranslationServer.get_tool_locale().substr(0, 2)]
|
|
|
|
var en_translations_path: String = "%s/l10n/en.po" % base_path
|
|
|
|
var translations: Translation = load(translations_path if FileAccess.file_exists(translations_path) else (fallback_translations_path if FileAccess.file_exists(fallback_translations_path) else en_translations_path))
|
2023-07-27 11:39:38 -07:00
|
|
|
return translations.get_message(string)
|