EXPERIMENTAL: add_port() now sets a default value for the port type

This commit is contained in:
Lera Elvoé 2024-06-14 16:58:47 +03:00
parent 1d6365c4bd
commit 0a564722f2
No known key found for this signature in database
2 changed files with 13 additions and 0 deletions

View file

@ -109,6 +109,9 @@ func add_port(type: DeckType.Types,
descriptor: String = "", descriptor: String = "",
usage: Port.UsageType = Port.UsageType.BOTH) -> Port: usage: Port.UsageType = Port.UsageType.BOTH) -> Port:
var port := Port.new(type, label, ports.size(), port_type, index_of_type, descriptor, usage) var port := Port.new(type, label, ports.size(), port_type, index_of_type, descriptor, usage)
# WARNING: EXPERIMENTAL
port.set_value_no_signal(DeckType.DEFAULT_VALUES[type])
ports.append(port) ports.append(port)
port_added.emit(ports.size() - 1) port_added.emit(ports.size() - 1)
port.value_updated.connect( port.value_updated.connect(

View file

@ -12,6 +12,15 @@ enum Types{
ANY, ANY,
} }
const DEFAULT_VALUES := {
Types.BOOL: false,
Types.NUMERIC: 0.0,
Types.STRING: "",
Types.ARRAY: [],
Types.DICTIONARY: {},
Types.ANY: null,
}
const CONVERSION_MAP := { const CONVERSION_MAP := {
Types.BOOL: [Types.NUMERIC, Types.STRING, Types.ANY], Types.BOOL: [Types.NUMERIC, Types.STRING, Types.ANY],
Types.NUMERIC: [Types.BOOL, Types.STRING, Types.ANY], Types.NUMERIC: [Types.BOOL, Types.STRING, Types.ANY],
@ -56,6 +65,7 @@ static func convert_value(value: Variant, to: Types) -> Variant:
static func type_str(type: Types) -> String: static func type_str(type: Types) -> String:
return str(Types.keys()[type]) return str(Types.keys()[type])
## Validates whether the given Dictionary is a "Vector", AKA that it has an X and a Y key. ## Validates whether the given Dictionary is a "Vector", AKA that it has an X and a Y key.
static func is_valid_vector(dict : Variant): static func is_valid_vector(dict : Variant):