Skip to content

Commit

Permalink
Rand.color and Rand.uuid_v4
Browse files Browse the repository at this point in the history
  • Loading branch information
filipworksdev committed Feb 4, 2022
1 parent e737289 commit 48168db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 0 additions & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
hints["interface/editor/unfocused_low_processor_mode_sleep_usec"] = PropertyInfo(Variant::REAL, "interface/editor/unfocused_low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
_initial_set("interface/editor/separate_distraction_mode", false);
_initial_set("interface/editor/automatically_open_screenshots", true);
_initial_set("interface/editor/hide_console_window", true); // GOBLIN ENGINE
_initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
_initial_set("interface/editor/quit_confirmation", true);

Expand Down
22 changes: 21 additions & 1 deletion modules/goblin/rand.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "rand.h"
#include "core/os/os.h"
#include "modules/regex/regex.h"
#include "core/crypto/crypto.h"

#include <stdlib.h>

Expand Down Expand Up @@ -233,7 +234,24 @@ Variant Rand::roll_notation(const String dice_notation) {
}

Color Rand::color() {
return Color();
Color color;
color.set_hsv(randf(), randf_range(0.0, 1.0), randf_range(0.0, 1.0));
return color;
}

String Rand::uuid_v4() {
Ref<Crypto> crypto = Ref<Crypto>(Crypto::create());
PoolByteArray data = crypto->generate_random_bytes(16);

data.set(6, (data[6] & 0x0f) | 0x40);
data.set(8, (data[8] & 0x3f) | 0x80);

PoolByteArray::Read r = data.read();
return String::hex_encode_buffer(&r[0], 16)
.insert(8, "-")
.insert(13, "-")
.insert(18, "-")
.insert(23, "-");
}

void Rand::_bind_methods() {
Expand All @@ -245,6 +263,8 @@ void Rand::_bind_methods() {
ClassDB::bind_method(D_METHOD("decision", "probability"), &Rand::decision);
ClassDB::bind_method(D_METHOD("roll", "count", "faces"), &Rand::roll);
ClassDB::bind_method(D_METHOD("roll_notation", "dice_notation"), &Rand::roll_notation);
ClassDB::bind_method(D_METHOD("color"), &Rand::color);
ClassDB::bind_method(D_METHOD("uuid_v4"), &Rand::uuid_v4);

ADD_PROPERTY_DEFAULT("seed", 0);
ADD_PROPERTY_DEFAULT("state", 0);
Expand Down
1 change: 1 addition & 0 deletions modules/goblin/rand.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Rand : public RandomNumberGenerator {
Variant roll(uint32_t count, uint32_t sides);
Variant roll_notation(const String notation);
Color color();
String uuid_v4();

Rand();
~Rand() {};
Expand Down

0 comments on commit 48168db

Please sign in to comment.