Add PropertyListHelper in all simple cases

This commit is contained in:
kobewi
2024-02-14 02:11:45 +01:00
parent b2f425fe68
commit e95e954c68
15 changed files with 213 additions and 436 deletions

View File

@ -676,63 +676,6 @@ bool AudioStreamRandomizer::is_monophonic() const {
return false;
}
bool AudioStreamRandomizer::_get(const StringName &p_name, Variant &r_ret) const {
if (AudioStream::_get(p_name, r_ret)) {
return true;
}
Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() == 2 && components[0].begins_with("stream_") && components[0].trim_prefix("stream_").is_valid_int()) {
int index = components[0].trim_prefix("stream_").to_int();
if (index < 0 || index >= (int)audio_stream_pool.size()) {
return false;
}
if (components[1] == "stream") {
r_ret = get_stream(index);
return true;
} else if (components[1] == "weight") {
r_ret = get_stream_probability_weight(index);
return true;
} else {
return false;
}
}
return false;
}
bool AudioStreamRandomizer::_set(const StringName &p_name, const Variant &p_value) {
if (AudioStream::_set(p_name, p_value)) {
return true;
}
Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() == 2 && components[0].begins_with("stream_") && components[0].trim_prefix("stream_").is_valid_int()) {
int index = components[0].trim_prefix("stream_").to_int();
if (index < 0 || index >= (int)audio_stream_pool.size()) {
return false;
}
if (components[1] == "stream") {
set_stream(index, p_value);
return true;
} else if (components[1] == "weight") {
set_stream_probability_weight(index, p_value);
return true;
} else {
return false;
}
}
return false;
}
void AudioStreamRandomizer::_get_property_list(List<PropertyInfo> *p_list) const {
AudioStream::_get_property_list(p_list); // Define the trivial scalar properties.
p_list->push_back(PropertyInfo(Variant::NIL, "Streams", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
for (int i = 0; i < audio_stream_pool.size(); i++) {
p_list->push_back(PropertyInfo(Variant::OBJECT, vformat("stream_%d/stream", i), PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"));
p_list->push_back(PropertyInfo(Variant::FLOAT, vformat("stream_%d/weight", i), PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"));
}
}
void AudioStreamRandomizer::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_stream", "index", "stream", "weight"), &AudioStreamRandomizer::add_stream, DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("move_stream", "index_from", "index_to"), &AudioStreamRandomizer::move_stream);
@ -764,9 +707,17 @@ void AudioStreamRandomizer::_bind_methods() {
BIND_ENUM_CONSTANT(PLAYBACK_RANDOM_NO_REPEATS);
BIND_ENUM_CONSTANT(PLAYBACK_RANDOM);
BIND_ENUM_CONSTANT(PLAYBACK_SEQUENTIAL);
PoolEntry defaults;
base_property_helper.set_prefix("stream_");
base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), defaults.stream, &AudioStreamRandomizer::set_stream, &AudioStreamRandomizer::get_stream);
base_property_helper.register_property(PropertyInfo(Variant::FLOAT, "weight", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), defaults.weight, &AudioStreamRandomizer::set_stream_probability_weight, &AudioStreamRandomizer::get_stream_probability_weight);
}
AudioStreamRandomizer::AudioStreamRandomizer() {}
AudioStreamRandomizer::AudioStreamRandomizer() {
property_helper.setup_for_instance(base_property_helper, this);
}
void AudioStreamPlaybackRandomizer::start(double p_from_pos) {
playing = playback;