From 529f8935d62e3b40a8c1c6137c48d50185404e5e Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 6 Oct 2019 00:25:12 +0200 Subject: [PATCH] Added seed to the player. --- entities/entity.h | 4 ++-- entities/player.cpp | 39 +++++++++++++++++++++++++++++++++++++++ entities/player.h | 12 +++++++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/entities/entity.h b/entities/entity.h index bba88ae..6e34e14 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -582,8 +582,8 @@ public: Dictionary to_dict(); void from_dict(const Dictionary &dict); - Dictionary _to_dict(); - void _from_dict(const Dictionary &dict); + virtual Dictionary _to_dict(); + virtual void _from_dict(const Dictionary &dict); Entity(); ~Entity(); diff --git a/entities/player.cpp b/entities/player.cpp index 3ed42b2..70ff604 100644 --- a/entities/player.cpp +++ b/entities/player.cpp @@ -2,6 +2,22 @@ #include "../inventory/bag.h" +int Player::gets_seed() { + return _s_seed; +} +void Player::sets_seed(int value) { + _s_seed = value; + + SEND_RPC(rpc("setc_seed", value), setc_seed(value)); +} + +int Player::getc_seed() { + return _c_seed; +} +void Player::setc_seed(int value) { + _c_seed = value; +} + void Player::_setup() { Entity::_setup(); @@ -15,8 +31,31 @@ void Player::_setup() { } } +Dictionary Player::_to_dict() { + Dictionary dict = Entity::_to_dict(); + + dict["seed"] = _s_seed; + + return dict; +} + +void Player::_from_dict(const Dictionary &dict) { + Entity::_from_dict(dict); + + sets_seed(dict.get("seed", _s_seed)); +} + Player::Player() { + //_seed = 0; don't it will be random by default like this + _c_seed = _s_seed; } void Player::_bind_methods() { + ClassDB::bind_method(D_METHOD("gets_seed"), &Player::gets_seed); + ClassDB::bind_method(D_METHOD("sets_seed", "value"), &Player::sets_seed); + ADD_PROPERTY(PropertyInfo(Variant::INT, "sseed"), "sets_seed", "gets_seed"); + + ClassDB::bind_method(D_METHOD("getc_seed"), &Player::getc_seed); + ClassDB::bind_method(D_METHOD("setc_seed", "value"), &Player::setc_seed); + ADD_PROPERTY(PropertyInfo(Variant::INT, "cseed"), "setc_seed", "getc_seed"); } diff --git a/entities/player.h b/entities/player.h index 4523564..f197d4a 100644 --- a/entities/player.h +++ b/entities/player.h @@ -9,15 +9,25 @@ class Player : public Entity { GDCLASS(Player, Entity); public: + int gets_seed(); + void sets_seed(int value); + + int getc_seed(); + void setc_seed(int value); + void _setup(); + Dictionary _to_dict(); + void _from_dict(const Dictionary &dict); + Player(); protected: static void _bind_methods(); private: - + int _s_seed; + int _c_seed; };